<?php require_once __DIR__ . '/includes/admin_bootstrap.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  $items = ugfx_read_json($ugfx['storage']['pages'], []);
  $title = trim($_POST['title'] ?? '');
  $items[] = [
    'id' => time(),
    'title' => $title,
    'slug' => ugfx_slugify(trim($_POST['slug'] ?? '') ?: $title),
    'excerpt' => trim($_POST['excerpt'] ?? ''),
    'content' => trim($_POST['content'] ?? ''),
    'published' => isset($_POST['published']) ? 1 : 0
  ];
  ugfx_write_json($ugfx['storage']['pages'], $items);
}
$items = ugfx_read_json($ugfx['storage']['pages'], []);
$adminTitle='Pages'; include __DIR__ . '/includes/admin_header.php'; ?>
<div class="row g-4">
  <div class="col-lg-6"><div class="ugfx-card p-4"><div class="ugfx-micro-label">CUSTOM PAGE CREATOR</div><h3>Add page</h3><form method="post" class="row g-3"><div class="col-12"><input class="form-control" name="title" placeholder="Page title" required></div><div class="col-12"><input class="form-control" name="slug" placeholder="Optional slug"></div><div class="col-12"><textarea class="form-control" name="excerpt" rows="2" placeholder="Short summary"></textarea></div><div class="col-12"><textarea class="form-control" name="content" rows="7" placeholder="Page content" required></textarea></div><div class="col-md-6 d-flex align-items-center"><div class="form-check"><input class="form-check-input" type="checkbox" name="published" checked id="published"><label class="form-check-label" for="published">Published</label></div></div><div class="col-12"><button class="btn ugfx-btn-primary">Save page</button></div></form></div></div>
  <div class="col-lg-6"><div class="ugfx-card p-4"><div class="ugfx-micro-label">CURRENT PAGES</div><h3>Published and draft pages</h3><?php foreach (array_reverse($items) as $item): ?><div class="ugfx-card p-3 mb-3"><strong><?= htmlspecialchars($item['title'] ?? 'Page') ?></strong><div class="text-secondary small">Slug: <?= htmlspecialchars($item['slug'] ?? '') ?> · <?= !empty($item['published']) ? 'Published' : 'Draft' ?></div><div class="mt-2 text-secondary"><?= htmlspecialchars($item['excerpt'] ?? '') ?></div></div><?php endforeach; ?></div></div>
</div>
<?php include __DIR__ . '/includes/admin_footer.php'; ?>
