<?php
session_start();
require __DIR__ . '/includes/admin_lib.php';


$aboutFile = __DIR__ . '/../data/about.txt';

$saved = (isset($_GET['saved']) && $_GET['saved'] == '1');

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  if (!$CAN_EDIT) die("<h1>Access Denied</h1><p>You do not have permission to edit About.</p>");
  $content = trim($_POST['content'] ?? '');
  if (file_exists($aboutFile)) @copy($aboutFile, $aboutFile . ".bak");
  file_put_contents($aboutFile, $content . "\n");
  smurf_redirect_self(['saved'=>1]);
}

$current = file_exists($aboutFile) ? file_get_contents($aboutFile) : "";
include __DIR__ . '/includes/admin_header.php';
?>
<section class="content-card">
  <h1 class="admin-title">ℹ️ Edit About Page</h1>

  <?php if (!empty($saved)): ?>
    <div class="msg success">Saved.</div>
  <?php endif; ?>

  <form method="POST" class="form">
    <label>About content (shown on /about.php)</label>
    <textarea name="content" class="input-field" rows="14" <?= $CAN_EDIT ? '' : 'disabled' ?>><?= smurf_h($current) ?></textarea>

    <?php if ($CAN_EDIT): ?>
      <button class="admin-btn primary" type="submit" style="margin-top:12px;">Save</button>
    <?php else: ?>
      <p style="opacity:.7;margin-top:10px;">View-only mode — editing disabled.</p>
    <?php endif; ?>
  </form>
</section>
<?php include __DIR__ . '/includes/admin_footer.php'; ?>
