<?php
/// file: app/View/admin/seo/index.php

declare(strict_types=1);

/** @var list<array<string, mixed>> $rows */
/** @var array<string, mixed>|null $editRow */
?>
<h1 class="text-2xl font-semibold text-white">SEO meta</h1>
<div class="mt-8 overflow-x-auto">
    <table class="min-w-full text-left text-sm text-silver-300">
        <thead class="border-b border-white/10 text-xs uppercase text-silver-500">
            <tr><th class="py-3 pr-4">Page key</th><th class="py-3 pr-4">Title</th><th class="py-3">Edit</th></tr>
        </thead>
        <tbody>
        <?php foreach ($rows as $r): ?>
            <tr class="border-b border-white/5">
                <td class="py-3 pr-4 text-white"><?= e((string) $r['page_key']) ?></td>
                <td class="py-3 pr-4"><?= e((string) $r['title']) ?></td>
                <td class="py-3"><a class="text-electric-300" href="<?= e(url('/admin/seo?edit=' . rawurlencode((string) $r['page_key']))) ?>">Edit</a></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
</div>

<?php $e = $editRow; ?>
<h2 class="mt-12 text-lg text-white"><?= $e ? 'Edit' : 'Create / update' ?> record</h2>
<form method="post" action="<?= e(url('/admin/seo')) ?>" class="mt-6 max-w-3xl space-y-4">
    <?= \App\Core\Csrf::field() ?>
    <div><label class="text-xs text-silver-500">Page key</label><input name="page_key" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($e['page_key'] ?? '')) ?>" required></div>
    <div><label class="text-xs text-silver-500">Title</label><input name="title" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($e['title'] ?? '')) ?>"></div>
    <div><label class="text-xs text-silver-500">Description</label><textarea name="description" rows="2" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white"><?= e((string) ($e['description'] ?? '')) ?></textarea></div>
    <div><label class="text-xs text-silver-500">OG title</label><input name="og_title" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($e['og_title'] ?? '')) ?>"></div>
    <div><label class="text-xs text-silver-500">OG description</label><textarea name="og_description" rows="2" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white"><?= e((string) ($e['og_description'] ?? '')) ?></textarea></div>
    <div><label class="text-xs text-silver-500">OG image path</label><input name="og_image" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($e['og_image'] ?? '')) ?>"></div>
    <div><label class="text-xs text-silver-500">Robots</label><input name="robots" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($e['robots'] ?? 'index,follow')) ?>"></div>
    <div><label class="text-xs text-silver-500">Structured data JSON</label><textarea name="structured_json" rows="4" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white font-mono text-xs"><?= e((string) ($e['structured_json'] ?? '')) ?></textarea></div>
    <button type="submit" class="rounded-full bg-white px-6 py-2 text-xs font-semibold text-carbon">Save</button>
</form>
