<?php
/**
 * Admin — Change Password
 * Path: admin/change-password.php
 */
require_once 'layout-header.php';

$msg_success = '';
$msg_error   = '';

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['form_action']) && $_POST['form_action'] === 'change_password') {
    $current = $_POST['current_password'] ?? '';
    $new     = $_POST['new_password'] ?? '';
    $confirm = $_POST['confirm_password'] ?? '';

    $result = change_admin_password($current, $new, $confirm);
    if ($result['success']) {
        $msg_success = 'পাসওয়ার্ড সফলভাবে পরিবর্তন হয়েছে! পরের লগইনে নতুন পাসওয়ার্ড ব্যবহার করুন।';
    } else {
        $msg_error = $result['error'];
    }
}
?>

<main class="flex-1 p-6 md:p-8 space-y-6">

    <div class="border-b border-slate-800/80 pb-5">
        <h1 class="text-2xl font-black text-white uppercase tracking-wider">Change Password</h1>
        <p class="text-xs text-slate-400 mt-1">এডমিন প্যানেলের লগইন পাসওয়ার্ড পরিবর্তন করুন</p>
    </div>

    <?php if ($msg_success): ?>
    <div class="p-4 bg-emerald-950/40 border border-emerald-800 text-emerald-200 text-xs rounded-xl flex items-center max-w-lg">
        <i class="fa-solid fa-circle-check mr-3"></i> <?php echo htmlspecialchars($msg_success); ?>
    </div>
    <?php endif; ?>
    <?php if ($msg_error): ?>
    <div class="p-4 bg-red-950/40 border border-red-800 text-red-200 text-xs rounded-xl flex items-center max-w-lg">
        <i class="fa-solid fa-triangle-exclamation mr-3"></i> <?php echo htmlspecialchars($msg_error); ?>
    </div>
    <?php endif; ?>

    <form method="post" class="bg-slate-900 border border-slate-800/80 rounded-2xl p-6 space-y-5 max-w-lg">
        <input type="hidden" name="form_action" value="change_password">

        <div>
            <label class="block text-xs font-bold uppercase text-slate-400 mb-2">বর্তমান পাসওয়ার্ড *</label>
            <input type="password" name="current_password" required autocomplete="current-password"
                class="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-3 text-sm text-slate-100 focus:ring-2 focus:ring-sky-500">
        </div>
        <div>
            <label class="block text-xs font-bold uppercase text-slate-400 mb-2">নতুন পাসওয়ার্ড * <span class="text-slate-600 normal-case">(কমপক্ষে ৬ অক্ষর)</span></label>
            <input type="password" name="new_password" required minlength="6" autocomplete="new-password"
                class="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-3 text-sm text-slate-100 focus:ring-2 focus:ring-sky-500">
        </div>
        <div>
            <label class="block text-xs font-bold uppercase text-slate-400 mb-2">নতুন পাসওয়ার্ড আবার *</label>
            <input type="password" name="confirm_password" required minlength="6" autocomplete="new-password"
                class="w-full bg-slate-950 border border-slate-800 rounded-xl px-4 py-3 text-sm text-slate-100 focus:ring-2 focus:ring-sky-500">
        </div>

        <p class="text-[11px] text-slate-500 leading-relaxed">
            <i class="fa-solid fa-circle-info mr-1 text-sky-500"></i>
            ডিফল্ট পাসওয়ার্ড ছিল <code class="text-sky-400">admin123</code>। পরিবর্তনের পর শুধু নতুন পাসওয়ার্ড দিয়ে লগইন করতে পারবেন।
        </p>

        <button type="submit" class="w-full bg-sky-500 hover:bg-sky-600 text-slate-950 font-black py-3.5 rounded-xl text-xs uppercase">
            <i class="fa-solid fa-key mr-2"></i> Update Password
        </button>
    </form>

</main>

<?php require_once 'layout-footer.php'; ?>
