<?php
require_once __DIR__ . '/../includes/functions.php';
$error='';
if($_SERVER['REQUEST_METHOD']==='POST'){
    checkCsrf();
    $password=(string)($_POST['password']??'');
    if(!adminConfigured()){
        if(strlen($password)<10) $error='Use at least 10 characters for the admin password.';
        else {setSetting('admin_password_hash',password_hash($password,PASSWORD_DEFAULT));$_SESSION['phantom_admin']=true;header('Location: index.php');exit;}
    } elseif(password_verify($password,(string)setting('admin_password_hash'))){$_SESSION['phantom_admin']=true;header('Location: index.php');exit;} else $error='Incorrect password.';
}
?>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Admin — PhantomNET</title><link rel="stylesheet" href="../assets/css/style.css"></head><body class="admin-body"><main class="login-card"><a class="brand" href="../index.php"><span class="brand-mark">P</span><span><strong>PhantomNET</strong><small>Admin</small></span></a><h1><?= adminConfigured()?'Admin login':'Create admin password' ?></h1><p><?= adminConfigured()?'Enter your password to manage releases.':'First run detected. Create a strong password for the admin area.' ?></p><?php if($error): ?><div class="alert"><?= htmlspecialchars($error) ?></div><?php endif; ?><form method="post"><input type="hidden" name="csrf" value="<?= htmlspecialchars(csrfToken()) ?>"><label>Password<input type="password" name="password" required autofocus></label><button class="primary-btn" type="submit"><?= adminConfigured()?'Sign in':'Create admin' ?></button></form></main></body></html>
