<?php

use ChurchCRM\dto\SystemURLs;

include SystemURLs::getDocumentRoot() . '/Include/Header.php';
?>

<div class="container-fluid">
    <div class="card shadow-sm">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-vcenter card-table">
                    <thead>
                        <tr>
                            <th><?= gettext('Content Key') ?></th>
                            <th><?= gettext('Title') ?></th>
                            <th><?= gettext('Content Preview') ?></th>
                            <th><?= gettext('Actions') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (empty($content)): ?>
                        <tr>
                            <td colspan="4" class="text-center text-secondary py-4">
                                <?= gettext('No content found.') ?>
                            </td>
                        </tr>
                        <?php else: ?>
                        <?php foreach ($content as $item): ?>
                        <tr>
                            <td><code><?= $item['cct_key'] ?></code></td>
                            <td><strong><?= $item['cct_title'] ?></strong></td>
                            <td>
                                <small class="text-secondary"><?= substr(strip_tags($item['cct_content']), 0, 120) ?: '' ?></small>
                            </td>
                            <td class="text-nowrap">
                                <a href="<?= SystemURLs::getRootPath() ?>/admin/website/content/edit/<?= $item['cct_key'] ?>" class="btn btn-sm btn-outline-primary">
                                    <i class="fa-solid fa-pen"></i> <?= gettext('Edit') ?>
                                </a>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

<?php include SystemURLs::getDocumentRoot() . '/Include/Footer.php'; ?>
