<?php
require_once __DIR__.'/includes/config.php';
require_login();
require_admin();
$msg='';
if($_SERVER['REQUEST_METHOD']==='POST'){
    $username = trim($_POST['username'] ?? 'popplay');
    $password = (string)($_POST['password'] ?? 'popplay');
    if ($username === '') $username = 'popplay';
    if ($password === '') $password = 'popplay';
    $db=db();
    $stmt=$db->prepare('UPDATE users SET username=:u,password=:p WHERE id=1');
    $stmt->bindValue(':u',$username,SQLITE3_TEXT);
    $stmt->bindValue(':p',password_hash($password, PASSWORD_DEFAULT),SQLITE3_TEXT);
    $stmt->execute();
    $msg='Dados salvos.';
}
$row=db()->querySingle('SELECT * FROM users WHERE id=1',true) ?: ['username'=>'popplay','password'=>''];
include __DIR__.'/includes/header.php';
?>
<div class="card"><h3>Usuário do painel</h3><?php if($msg): ?><p class="ok"><?=h($msg)?></p><?php endif; ?><form method="post"><label>Usuário</label><input name="username" value="<?=h($row['username'])?>"><label>Nova senha</label><input name="password" type="password" placeholder="Digite a nova senha"><button class="btn">Salvar</button></form></div>
<?php include __DIR__.'/includes/footer.php'; ?>
