<section class="hero-grid data-actions">
    <a class="card export-card purple" href="<?= h(url('export-json')) ?>">
        <span class="export-icon">{ }</span><div><p class="eyebrow">Portable planner package</p><h2>Export JSON</h2><small>Financial records plus non-secret configuration</small></div><b>↓</b>
    </a>
    <a class="card export-card blue" href="<?= h(url('export-html', ['month' => $month])) ?>">
        <span class="export-icon">&lt;/&gt;</span><div><p class="eyebrow"><?= h($month) ?></p><h2>Export HTML</h2><small>Styled, printable monthly report</small></div><b>↓</b>
    </a>
    <a class="card export-card pink" href="<?= h(url('export-pdf', ['month' => $month])) ?>">
        <span class="export-icon">PDF</span><div><p class="eyebrow"><?= h($month) ?></p><h2>Export PDF</h2><small>Compact monthly summary and target progress</small></div><b>↓</b>
    </a>
</section>

<section class="content-grid data-grid">
    <article class="card">
        <div class="card-heading"><div><p class="eyebrow">Bring a planner home</p><h2>Import package</h2></div></div>
        <form method="post" enctype="multipart/form-data" class="stack-form" data-confirm="Import this planner package? Replacing data cannot be undone without a backup.">
            <?= csrf_field() ?><input type="hidden" name="action" value="data.import">
            <label class="file-drop">Planner JSON file<input type="file" name="planner_file" accept="application/json,.json" required><span>Choose a <code>neon-ledger/budget-planner</code> package</span></label>
            <label class="check-row"><input type="checkbox" name="replace_existing" value="1"><span><strong>Replace existing financial data</strong><small>Otherwise matching record IDs are skipped and new records are merged.</small></span></label>
            <button class="button primary" type="submit">Import planner data</button>
        </form>
    </article>
    <article class="card">
        <div class="card-heading"><div><p class="eyebrow">Database mode</p><h2><?= h(strtoupper($databaseDriver)) ?> is active</h2></div><span class="status-badge success">Connected</span></div>
        <?php if ($databaseDriver === 'sqlite'): ?>
            <p class="muted">SQLite remains the zero-configuration default. Use this one-time transfer to copy every planner table to an existing MySQL or MariaDB database and switch modes.</p>
            <form method="post" class="form-grid" data-confirm="Copy all SQLite records and switch this planner to MySQL/MariaDB?">
                <?= csrf_field() ?><input type="hidden" name="action" value="database.migrate">
                <label>Host<input type="text" name="host" value="127.0.0.1" required></label>
                <label>Port<input type="number" name="port" value="3306" required></label>
                <label>Database<input type="text" name="database" required placeholder="budget_planner"></label>
                <label>Username<input type="text" name="username" required autocomplete="username"></label>
                <label class="span-2">Password<input type="password" name="password" autocomplete="current-password"></label>
                <button class="button primary span-2" type="submit">Copy data and switch database</button>
            </form>
        <?php else: ?>
            <div class="database-facts"><div><span>Host</span><strong><?= h($databaseConfig['mysql']['host'] ?? '') ?></strong></div><div><span>Database</span><strong><?= h($databaseConfig['mysql']['database'] ?? '') ?></strong></div><div><span>Charset</span><strong><?= h($databaseConfig['mysql']['charset'] ?? 'utf8mb4') ?></strong></div></div>
            <p class="form-note">The original SQLite file remains in storage as a fallback snapshot. Switching back is done by changing <code>config/database.json</code>.</p>
        <?php endif; ?>
    </article>
</section>

<article class="card portability-note">
    <span class="metric-icon orange">i</span>
    <div><h2>Portable by design</h2><p>JSON exports omit administrator credentials, 2FA secrets, and the Mailgun API key. HTML and PDF exports contain only the selected month’s financial summary.</p></div>
</article>
