<?php

use ChurchCRM\dto\SystemURLs;

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

<div class="container-fluid">
    <div class="d-flex justify-content-end mb-3">
        <a href="<?= SystemURLs::getRootPath() ?>/admin/website/events/create" class="btn btn-primary">
            <i class="fa-solid fa-plus me-1"></i> <?= gettext('Add Event') ?>
        </a>
    </div>

    <div class="card shadow-sm">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-vcenter card-table">
                    <thead>
                        <tr>
                            <th><?= gettext('Title') ?></th>
                            <th><?= gettext('Date') ?></th>
                            <th><?= gettext('Time') ?></th>
                            <th><?= gettext('Category') ?></th>
                            <th><?= gettext('Featured') ?></th>
                            <th><?= gettext('Actions') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (empty($events)): ?>
                        <tr>
                            <td colspan="6" class="text-center text-secondary py-4">
                                <?= gettext('No events found.') ?>
                            </td>
                        </tr>
                        <?php else: ?>
                        <?php foreach ($events as $event): ?>
                        <tr>
                            <td><strong><?= $event['evt_title'] ?></strong></td>
                            <td><?= $event['evt_date'] ? date('M j, Y', strtotime($event['evt_date'])) : '-' ?></td>
                            <td><?= $event['evt_time'] ?: '-' ?></td>
                            <td><span class="badge" style="background:<?= $event['evt_color'] ?>"><?= $event['evt_category'] ?: 'General' ?></span></td>
                            <td>
                                <?php if ($event['evt_featured']): ?>
                                    <span class="badge bg-success"><?= gettext('Yes') ?></span>
                                <?php else: ?>
                                    <span class="badge bg-secondary"><?= gettext('No') ?></span>
                                <?php endif; ?>
                            </td>
                            <td class="text-nowrap">
                                <a href="<?= SystemURLs::getRootPath() ?>/admin/website/events/edit/<?= $event['evt_id'] ?>" class="btn btn-sm btn-outline-primary">
                                    <i class="fa-solid fa-pen"></i>
                                </a>
                                <a href="<?= SystemURLs::getRootPath() ?>/admin/website/events/delete/<?= $event['evt_id'] ?>"
                                   class="btn btn-sm btn-outline-danger"
                                   onclick="return confirm('<?= gettext('Delete this event?') ?>')">
                                    <i class="fa-solid fa-trash"></i>
                                </a>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                        <?php endif; ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

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