<?php
require 'inc/auth_check.php';
require 'inc/header.php';

$about = $mysqli->query("SELECT * FROM about WHERE id=1")->fetch_assoc();
$msg = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $heading = $_POST['heading'] ?? '';
    $subheading = $_POST['subheading'] ?? '';
    $content = $_POST['content'] ?? '';
    $stmt = $mysqli->prepare("UPDATE about SET heading=?, subheading=?, content=? WHERE id=1");
    $stmt->bind_param('sss', $heading, $subheading, $content);
    $stmt->execute();
    $stmt->close();
    $msg = 'Berhasil disimpan';
    $about = $mysqli->query("SELECT * FROM about WHERE id=1")->fetch_assoc();
}
?>

<h2 class="text-xl font-bold mb-4">Edit About</h2>
<?php if($msg): ?><div class="mb-4 text-green-600"><?php echo e($msg); ?></div><?php endif; ?>

<form method="post" class="bg-white p-4 shadow rounded">
  <label class="block mb-2">Heading</label>
  <input name="heading" value="<?php echo e($about['heading']); ?>" class="w-full p-2 border mb-3">
  <label class="block mb-2">Subheading</label>
  <input name="subheading" value="<?php echo e($about['subheading']); ?>" class="w-full p-2 border mb-3">
  <label class="block mb-2">Content</label>
  <textarea name="content" class="w-full p-2 border mb-3"><?php echo e($about['content']); ?></textarea>

  <button class="bg-teal-600 text-white py-2 px-4 rounded">Simpan</button>
</form>

</div></body></html>
