<?php use function App\Core\e; $section = 'sayfalar'; ?>
<div class="panel zpanel zpanel-app">
    <?php require BASE_PATH . '/app/Views/zpanel/_sidebar.php'; ?>
    <section class="panel-body zpanel-main" data-zpanel-page>
        <div class="zpanel-head">
            <div><p class="eyebrow">Genel</p><h1>Sayfa Yonetimi</h1><p class="muted">WordPress benzeri sade sayfa listesi, menu/footer gorunurlugu ve yayin akisi.</p></div>
            <a class="pill primary" href="/zpanel/sayfa-ekle">Yeni Sayfa</a>
        </div>
        <form class="zpanel-filters" method="get">
            <input name="q" value="<?= e($_GET['q'] ?? '') ?>" placeholder="Baslik veya slug ara">
            <select name="language"><option value="">Tum diller</option><?php foreach (['tr','en','de','fr'] as $lang): ?><option value="<?= e($lang) ?>" <?= ($_GET['language'] ?? '') === $lang ? 'selected' : '' ?>><?= e($lang) ?></option><?php endforeach; ?></select>
            <select name="status"><option value="">Tum durumlar</option><?php foreach (['draft','published','hidden','trashed'] as $status): ?><option value="<?= e($status) ?>" <?= ($_GET['status'] ?? '') === $status ? 'selected' : '' ?>><?= e($status) ?></option><?php endforeach; ?></select>
            <button class="pill primary">Filtrele</button>
        </form>
        <section class="zpanel-card"><div class="table-scroll"><table class="zpanel-table">
            <thead><tr><th>Baslik</th><th>Slug</th><th>Dil</th><th>Durum</th><th>Menude</th><th>Footer'da</th><th>Sira</th><th>Son guncelleme</th><th>Aksiyon</th></tr></thead><tbody>
            <?php foreach (($pages ?? []) as $page): ?>
                <tr>
                    <td><strong><?= e($page['title'] ?? '-') ?></strong><span class="muted block"><?= e($page['seo_title'] ?? '') ?></span></td>
                    <td><?= e($page['slug'] ?? '') ?></td><td><?= e($page['language'] ?? '') ?></td><td><span class="status-pill status-<?= e($page['status'] ?? '') ?>"><?= e($page['status'] ?? '') ?></span></td><td><?= !empty($page['show_in_menu']) || !empty($page['show_in_header']) ? 'Evet' : 'Hayir' ?></td><td><?= !empty($page['show_in_footer']) ? 'Evet' : 'Hayir' ?></td><td><?= e((string) ($page['sort_order'] ?? 0)) ?></td><td><?= e($page['updated_at'] ?? '') ?></td>
                    <td class="action-row">
                        <a href="/zpanel/sayfa-duzenle/<?= e($page['id'] ?? '') ?>">Duzenle</a>
                        <?php if (($page['status'] ?? '') === 'published'): ?><a href="/sayfa/<?= e($page['slug'] ?? '') ?>" target="_blank" rel="noopener noreferrer">Goruntule</a><?php endif; ?>
                        <?php foreach ([['/api/zpanel/pages/publish','Yayinla'],['/api/zpanel/pages/hide','Gizle'],['/api/zpanel/pages/trash','Cope al'],['/api/zpanel/pages/restore','Taslak yap']] as $action): ?>
                            <form data-zpanel-form action="<?= e($action[0]) ?>" method="post" data-confirm="<?= e($action[1]) ?>?"><input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>"><input type="hidden" name="id" value="<?= e($page['id'] ?? '') ?>"><button type="submit"><?= e($action[1]) ?></button></form>
                        <?php endforeach; ?>
                        <form data-zpanel-form action="/api/zpanel/pages/delete" method="post" data-confirm="Bu sayfa kalici olarak silinsin mi? Bu islem geri alinamaz."><input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>"><input type="hidden" name="id" value="<?= e($page['id'] ?? '') ?>"><button class="danger" type="submit">Sil</button></form>
                    </td>
                </tr>
            <?php endforeach; ?>
            <?php if (empty($pages)): ?><tr><td colspan="9">Sayfa bulunamadi.</td></tr><?php endif; ?>
            </tbody></table></div></section>
    </section>
</div>
