<?php include ADMIN_PATH . '/templates/header.php'; ?>

<div class="content-wrapper">
<section class="content pt-3">
<div class="container-fluid pb-5">

<div class="d-flex flex-wrap justify-content-between align-items-start gap-3 mb-4">
    <div>
        <h3 class="mb-1 fw-bold"><i class="bi bi-files me-2 text-primary"></i><?= __('pages.title','Pages') ?></h3>
        <p class="text-muted mb-0 small"><?= __('pages.subtitle','Manage your store static pages') ?></p>
    </div>
    <a href="/admin/pages/create" class="btn btn-primary">
        <i class="bi bi-plus-lg me-1"></i><?= __('pages.add','Add Page') ?>
    </a>
</div>

<div class="card border-0 shadow-sm">
    <div class="card-header bg-white border-bottom d-flex justify-content-between align-items-center py-3">
        <h6 class="mb-0 fw-semibold"><i class="bi bi-list-ul me-2 text-muted"></i><?= __('pages.list','Pages List') ?></h6>
        <span class="badge bg-secondary rounded-pill"><?= count($pages??[]) ?></span>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light">
                    <tr>
                        <th class="ps-3"><?= __('products.title','Title') ?></th>
                        <th><?= __('pages.slug','Slug') ?></th>
                        <th><?= __('pages.status','Status') ?></th>
                        <th class="text-end pe-3"><?= __('actions.actions','Actions') ?></th>
                    </tr>
                </thead>
                <tbody>
                <?php if(empty($pages)): ?>
                    <tr><td colspan="4" class="text-center py-5 text-muted">
                        <i class="bi bi-file-earmark-x display-4 d-block mb-2 opacity-50"></i>
                        <?= __('pages.empty','No pages found.') ?>
                    </td></tr>
                <?php else: foreach($pages as $page): ?>
                <tr>
                    <td class="ps-3 fw-semibold"><?= htmlspecialchars($page['title']) ?></td>
                    <td><code class="small bg-light px-2 py-1 rounded">/<?= htmlspecialchars($page['slug']) ?></code></td>
                    <td>
                        <?php if($page['status']==='published'): ?>
                            <span class="badge bg-success-subtle text-success border border-success-subtle">
                                <i class="bi bi-check-circle me-1"></i><?= __('pages.status.published','Published') ?>
                            </span>
                        <?php else: ?>
                            <span class="badge bg-secondary-subtle text-secondary border border-secondary-subtle">
                                <i class="bi bi-pencil me-1"></i><?= __('pages.status.draft','Draft') ?>
                            </span>
                        <?php endif; ?>
                    </td>
                    <td class="text-end pe-3">
                        <a href="/admin/pages/edit/<?= (int)$page['id'] ?>" class="btn btn-sm btn-outline-primary"><i class="bi bi-pencil"></i></a>
                        <form method="POST" action="/admin/pages/delete/<?= (int)$page['id'] ?>" class="d-inline"
                              onsubmit="return confirm('<?= __('pages.confirm_delete','Delete this page?') ?>')">
                            <?= \Core\System\Csrf::field() ?>
                            <button type="submit" class="btn btn-sm btn-outline-danger"><i class="bi bi-trash3"></i></button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

</div></section></div>
<?php include ADMIN_PATH . '/templates/footer.php'; ?>