<?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/videos/create" class="btn btn-primary">
            <i class="fa-solid fa-plus me-1"></i> <?= gettext('Add Video') ?>
        </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('Category') ?></th>
                            <th><?= gettext('Date') ?></th>
                            <th><?= gettext('Featured') ?></th>
                            <th><?= gettext('Actions') ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php if (empty($videos)): ?>
                        <tr>
                            <td colspan="5" class="text-center text-secondary py-4">
                                <?= gettext('No videos found.') ?>
                            </td>
                        </tr>
                        <?php else: ?>
                        <?php foreach ($videos as $video): ?>
                        <tr>
                            <td>
                                <strong><?= $video['vid_title'] ?></strong>
                                <?php if ($video['vid_description']): ?>
                                <br><small class="text-secondary"><?= substr($video['vid_description'], 0, 80) ?: '' ?></small>
                                <?php endif; ?>
                            </td>
                            <td><?= $video['vid_category'] ?: '-' ?></td>
                            <td><?= $video['vid_date'] ? date('M j, Y', strtotime($video['vid_date'])) : '-' ?></td>
                            <td>
                                <?php if ($video['vid_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/videos/edit/<?= $video['vid_id'] ?>" class="btn btn-sm btn-outline-primary">
                                    <i class="fa-solid fa-pen"></i>
                                </a>
                                <a href="<?= SystemURLs::getRootPath() ?>/admin/website/videos/delete/<?= $video['vid_id'] ?>"
                                   class="btn btn-sm btn-outline-danger"
                                   onclick="return confirm('<?= gettext('Delete this video?') ?>')">
                                    <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'; ?>
