<?php
/// file: app/View/admin/services/form.php

declare(strict_types=1);

/** @var array<string, mixed>|null $service */
/** @var array<string, string> $errors */
$s = $service ?? [];
$isEdit = isset($s['id']);
$action = $isEdit ? url('/admin/services/edit/' . (int) $s['id']) : url('/admin/services/create');
?>
<h1 class="text-2xl font-semibold text-white"><?= $isEdit ? 'Edit service' : 'New service' ?></h1>
<?php foreach ($errors as $msg): ?><p class="mt-4 text-sm text-red-400"><?= e((string) $msg) ?></p><?php endforeach; ?>
<form method="post" action="<?= e($action) ?>" class="mt-8 max-w-3xl space-y-4">
    <?= \App\Core\Csrf::field() ?>
    <div class="grid gap-4 md:grid-cols-2">
        <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) ($s['title'] ?? '')) ?>" required></div>
        <div><label class="text-xs text-silver-500">Slug</label><input name="slug" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($s['slug'] ?? '')) ?>" required></div>
    </div>
    <div><label class="text-xs text-silver-500">Short description</label><textarea name="short_description" rows="2" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" required><?= e((string) ($s['short_description'] ?? '')) ?></textarea></div>
    <div><label class="text-xs text-silver-500">Detail</label><textarea name="detail" rows="4" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" required><?= e((string) ($s['detail'] ?? '')) ?></textarea></div>
    <div><label class="text-xs text-silver-500">Process</label><textarea name="process" rows="3" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" required><?= e((string) ($s['process'] ?? '')) ?></textarea></div>
    <div><label class="text-xs text-silver-500">Deliverables</label><textarea name="deliverables" rows="3" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" required><?= e((string) ($s['deliverables'] ?? '')) ?></textarea></div>
    <div><label class="text-xs text-silver-500">Ideal client</label><textarea name="ideal_client" rows="3" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" required><?= e((string) ($s['ideal_client'] ?? '')) ?></textarea></div>
    <div class="grid gap-4 md:grid-cols-2">
        <div><label class="text-xs text-silver-500">Sort</label><input name="sort_order" type="number" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($s['sort_order'] ?? '0')) ?>"></div>
        <div><label class="text-xs text-silver-500">Status</label><select name="status" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white"><option value="published" <?= (($s['status'] ?? '') === 'published') ? 'selected' : '' ?>>published</option><option value="draft" <?= (($s['status'] ?? '') === 'draft') ? 'selected' : '' ?>>draft</option></select></div>
    </div>
    <button type="submit" class="rounded-full bg-white px-6 py-2 text-xs font-semibold text-carbon">Save</button>
</form>
