<?php
include ('includes/header.php');

$table_name = 'user';
$page = 'user.php';
$res = $db->select($table_name, '*', '', '');

if(isset($_POST['submit'])){
	unset($_POST['submit']);
	$updateData = $_POST;
	$db->update($table_name, $updateData, 'id = :id', [':id' => 1]);
	session_regenerate_id();
	$_SESSION['loggedin'] = true;
	$_SESSION['name'] = $_POST['username'];
	echo "<script>window.location.href='".$page."?status=1'</script>";
}
?>

<div class="yt-page-header">
  <div class="yt-page-title">
    <h1><i class="fas fa-user-cog" style="color:var(--yt-red);margin-right:8px"></i>Update Credentials</h1>
  </div>
</div>

<div style="max-width:520px">
  <div class="yt-card">
    <div class="yt-card-header">
      <span class="yt-card-title"><i class="fas fa-lock"></i> Alterar credenciais de acesso</span>
    </div>
    <div class="yt-card-body">

      <!-- Info atual -->
      <div style="display:flex;align-items:center;gap:14px;padding:14px 0 20px;border-bottom:1px solid var(--yt-border);margin-bottom:24px">
        <div style="width:52px;height:52px;border-radius:50%;background:var(--yt-red);display:flex;align-items:center;justify-content:center;font-size:22px;font-weight:700;color:#fff;flex-shrink:0">
          <?= strtoupper(substr($res[0]['username'] ?? 'A', 0, 1)) ?>
        </div>
        <div>
          <div style="font-weight:500;font-size:15px"><?= htmlspecialchars($res[0]['username'] ?? '') ?></div>
          <div style="font-size:12px;color:var(--yt-text-muted);margin-top:2px">Administrador do painel</div>
        </div>
      </div>

      <form method="post">
        <div class="yt-form-grid">
          <div class="yt-form-group full">
            <label>Novo Username</label>
            <input type="text" name="username" value="<?= htmlspecialchars($res[0]['username'] ?? '') ?>" placeholder="Username">
          </div>
          <div class="yt-form-group full">
            <label>Nova Password</label>
            <input type="text" name="password" value="<?= htmlspecialchars($res[0]['password'] ?? '') ?>" placeholder="Password">
          </div>
        </div>

        <div style="background:rgba(255,180,0,.07);border:1px solid rgba(255,180,0,.2);border-radius:8px;padding:12px 14px;margin:20px 0;display:flex;gap:10px;align-items:flex-start">
          <i class="fas fa-exclamation-triangle" style="color:#ffb400;margin-top:2px;flex-shrink:0"></i>
          <p style="font-size:13px;color:var(--yt-text-muted);margin:0">
            Após salvar, você será redirecionado automaticamente com as novas credenciais.
          </p>
        </div>

        <div class="yt-form-footer">
          <button type="submit" name="submit" class="yt-btn-red">
            <i class="fas fa-check"></i> Atualizar Credenciais
          </button>
        </div>
      </form>
    </div>
  </div>
</div>

<?php include ('includes/footer.php'); ?>