<?php
/** @var array $currentUser */
/** @var Settings $settings */

$appTitle = $settings->get('app_title', t('app.title'));
$appLogo  = $settings->get('app_logo', '');

$libraries = [
    ['name' => 'Font Awesome',    'version' => '6.7.2',  'license' => 'Font Awesome Free License', 'url' => 'https://fontawesome.com/'],
    ['name' => 'Chart.js',        'version' => '4.x',    'license' => 'MIT',                       'url' => 'https://www.chartjs.org/'],
    ['name' => 'D3.js',           'version' => '7.x',    'license' => 'ISC',                       'url' => 'https://d3js.org/'],
    ['name' => 'Observable Plot', 'version' => '0.6.x',  'license' => 'ISC',                       'url' => 'https://observablehq.com/plot/'],
    ['name' => 'highlight.js',    'version' => '11.9.0', 'license' => 'BSD-3-Clause',              'url' => 'https://highlightjs.org/'],
    ['name' => 'sql-formatter',   'version' => '14.x',   'license' => 'MIT',                       'url' => 'https://github.com/sql-formatter-org/sql-formatter'],
    ['name' => 'Parsedown',       'version' => '1.7.4',  'license' => 'MIT',                       'url' => 'https://github.com/erusev/parsedown'],
    ['name' => 'Parsedown Extra', 'version' => '0.8.1',  'license' => 'MIT',                       'url' => 'https://github.com/erusev/parsedown-extra'],
    ['name' => 'Mermaid',         'version' => '11.x',   'license' => 'MIT',                       'url' => 'https://mermaid.js.org/'],
];

$pageTitle = t('about.title');
include WEBROOT_PATH . '/includes/header.php';
?>

<div class="page-header">
    <h1><?= t('about.title') ?></h1>
</div>

<div class="card" style="margin-bottom:1.2rem">
    <div style="display:flex;align-items:center;gap:1.2rem;flex-wrap:wrap">
        <?php if ($appLogo): ?>
        <img src="<?= htmlspecialchars($appLogo) ?>" alt="<?= htmlspecialchars($appTitle) ?>"
             style="max-height:64px;max-width:200px;object-fit:contain">
        <?php endif; ?>
        <div>
            <h2 style="margin:0 0 .2rem;font-size:1.15rem"><?= htmlspecialchars($appTitle) ?></h2>
            <div style="font-size:.85rem;color:var(--color-text-muted)">
                <?= t('about.version') ?> : <strong><?= APP_VERSION ?></strong>
            </div>
            <div style="font-size:.85rem;color:var(--color-text-muted)">
                PHP <?= PHP_VERSION ?> &middot; SQLite <?= (new SQLite3(':memory:'))->version()['versionString'] ?>
            </div>
        </div>
    </div>
</div>

<div class="card" style="margin-bottom:1.2rem">
    <h2 style="font-size:1rem;margin:0 0 .6rem"><?= t('about.libraries') ?></h2>
    <table class="data-table" style="font-size:.85rem">
        <thead>
            <tr>
                <th><?= t('about.lib_name') ?></th>
                <th><?= t('about.lib_version') ?></th>
                <th><?= t('about.lib_license') ?></th>
            </tr>
        </thead>
        <tbody>
        <?php foreach ($libraries as $lib): ?>
            <tr>
                <td><a href="<?= htmlspecialchars($lib['url']) ?>" target="_blank" rel="noopener"><?= htmlspecialchars($lib['name']) ?></a></td>
                <td><?= htmlspecialchars($lib['version']) ?></td>
                <td><?= htmlspecialchars($lib['license']) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>

<div class="card">
    <h2 style="font-size:1rem;margin:0 0 .6rem"><?= t('about.license_title') ?></h2>
    <div style="font-size:.84rem;line-height:1.65;color:var(--color-text)">
        <p style="margin:0 0 .6rem">
            Copyright &copy; <?= date('Y') ?> <?= htmlspecialchars($appTitle) ?>. <?= t('about.license_rights') ?>
        </p>
        <p style="margin:0 0 .6rem"><?= t('about.license_grant') ?></p>
        <p style="margin:0 0 .6rem"><?= t('about.license_conditions') ?></p>
        <ul style="margin:0 0 .6rem;padding-left:1.4rem">
            <li><?= t('about.license_cond_attribution') ?></li>
            <li><?= t('about.license_cond_no_derivs') ?></li>
            <li><?= t('about.license_cond_commercial') ?></li>
        </ul>
        <p style="margin:0 0 .6rem"><?= t('about.license_disclaimer') ?></p>
        <p style="margin:0;font-size:.78rem;color:var(--color-text-muted)"><?= t('about.license_compat') ?></p>
    </div>
</div>

<?php include WEBROOT_PATH . '/includes/footer.php'; ?>
