<?php require_once __DIR__ . '/_sidebar.php'; ?>
<main class="flex-1 py-16 md:py-0 md:pl-64">
    <div class="max-w-3xl mx-auto px-4 py-8 md:py-16">
        <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4 mb-10">
            <div>
                <h1 class="text-4xl font-bold text-premium-charcoal"><?= htmlspecialchars($pageTitle) ?></h1>
                <p class="mt-2 text-architectural-gray">Manage admin login credentials and user details.</p>
            </div>
            <a href="<?= htmlspecialchars($baseUrl) ?>/admin/users" class="inline-flex items-center gap-2 rounded-lg border border-slate-300 bg-white px-5 py-3 text-sm font-medium text-premium-charcoal hover:bg-slate-100 transition">
                <span class="material-symbols-outlined">arrow_back</span> Back to Users
            </a>
        </div>

        <form method="post" action="<?= htmlspecialchars($baseUrl . $formAction) ?>" class="space-y-8 bg-white p-8 rounded-3xl shadow-lg border border-slate-200">
            <?= CSRF::input() ?>
            <?php if (!empty($user)): ?>
                <input type="hidden" name="id" value="<?= htmlspecialchars($user['id']) ?>">
            <?php endif; ?>

            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2" for="name">Name</label>
                <input id="name" name="name" type="text" value="<?= htmlspecialchars($user['name'] ?? '') ?>" required class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm" />
            </div>

            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2" for="email">Email</label>
                <input id="email" name="email" type="email" value="<?= htmlspecialchars($user['email'] ?? '') ?>" required class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm" />
            </div>

            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2" for="password">Password</label>
                <input id="password" name="password" type="password" <?= empty($user) ? 'required' : '' ?> class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm" />
                <?php if (!empty($user)): ?>
                    <p class="mt-2 text-sm text-slate-500">Leave blank to keep the current password.</p>
                <?php endif; ?>
            </div>

            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2" for="phone">Phone</label>
                <input id="phone" name="phone" type="text" value="<?= htmlspecialchars($user['phone'] ?? '') ?>" class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm" />
            </div>

            <div>
                <label class="block text-sm font-medium text-slate-700 mb-2" for="status">Status</label>
                <select id="status" name="status" class="w-full rounded-2xl border border-slate-300 px-4 py-3 text-sm">
                    <option value="Active" <?= (!empty($user) && $user['status'] === 'Active') ? 'selected' : '' ?>>Active</option>
                    <option value="Inactive" <?= (!empty($user) && $user['status'] === 'Inactive') ? 'selected' : '' ?>>Inactive</option>
                </select>
            </div>

            <div class="flex justify-end">
                <button type="submit" class="inline-flex items-center justify-center rounded-full btn-primary px-8 py-4 text-sm font-semibold">Save User</button>
            </div>
        </form>
        </div>
    </div>
</main>
</div>
