<?php
/**
 * TAHWISSA — First admin setup
 * ─────────────────────────────
 * 1. Open in browser: http://localhost/tahwissa/admin/init_admin.php
 * 2. Note the credentials shown below.
 * 3. DELETE or RENAME this file immediately after.
 */
require_once __DIR__ . '/../config/db.php';

$username = 'admin';
$password = 'Tahwissa@2025';   // ← Change this before deploying

$hash = password_hash($password, PASSWORD_BCRYPT, ['cost'=>12]);

try {
    $stmt = db()->prepare("INSERT INTO admins (username, password_hash) VALUES (:u, :h) ON DUPLICATE KEY UPDATE password_hash = :h2");
    $stmt->execute([':u'=>$username, ':h'=>$hash, ':h2'=>$hash]);
    echo '<pre style="font:16px monospace;padding:32px;background:#f0faf5;border-radius:12px;max-width:480px;margin:40px auto">';
    echo "✅ تم إنشاء حساب المدير بنجاح.\n\n";
    echo "اسم المستخدم : $username\n";
    echo "كلمة المرور : $password\n\n";
    echo "⚠️  يجب حذف هذا الملف فوراً:\n";
    echo "    admin/init_admin.php\n\n";
    echo '<a href="../admin/login.php" style="color:#2D6A4F;font-weight:bold">← انتقل للوحة التحكم</a>';
    echo '</pre>';
} catch (PDOException $e) {
    echo '<pre style="color:red">خطأ: ' . htmlspecialchars($e->getMessage()) . '</pre>';
}
