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

declare(strict_types=1);

/** @var array<string, mixed>|null $career */
/** @var array<string, string> $errors */
$c = $career ?? [];
$isEdit = isset($c['id']);
$action = $isEdit ? url('/admin/careers/edit/' . (int) $c['id']) : url('/admin/careers/create');
?>
<h1 class="text-2xl font-semibold text-white"><?= $isEdit ? 'Edit role' : 'New role' ?></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-2xl 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) ($c['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) ($c['slug'] ?? '')) ?>" required></div>
    </div>
    <div class="grid gap-4 md:grid-cols-2">
        <div><label class="text-xs text-silver-500">Location</label><input name="location" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($c['location'] ?? '')) ?>"></div>
        <div><label class="text-xs text-silver-500">Type</label><input name="type" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" value="<?= e((string) ($c['type'] ?? 'Full-time')) ?>"></div>
    </div>
    <div><label class="text-xs text-silver-500">Description</label><textarea name="description" rows="5" class="mt-1 w-full rounded border border-white/10 bg-charcoal px-3 py-2 text-white" required><?= e((string) ($c['description'] ?? '')) ?></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) ($c['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="open" <?= (($c['status'] ?? '') === 'open') ? 'selected' : '' ?>>open</option><option value="closed" <?= (($c['status'] ?? '') === 'closed') ? 'selected' : '' ?>>closed</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>
