<section class="report-toolbar">
    <div>
        <p class="eyebrow"><?= e(trans('common.administrator')) ?></p>
        <h1><?= e(trans('admin.programme_heading')) ?></h1>
        <p class="support-copy"><?= e(trans('admin.programme_copy')) ?></p>
    </div>
    <div class="toolbar-actions">
        <a class="primary-button" href="<?= e(base_url('/admin/programmes/create')) ?>"><?= e(trans('admin.programme_add')) ?></a>
    </div>
</section>

<section class="card table-card admin-section-stack">
    <form method="get" action="<?= e(base_url('/admin/programmes')) ?>" class="inline-form-grid filter-grid">
        <label>
            <span><?= e(trans('common.ui_language')) ?></span>
            <select name="lang">
                <?php foreach ($languages as $languageCode => $languageLabel): ?>
                    <option value="<?= e($languageCode) ?>" <?= current_locale() === $languageCode ? 'selected' : '' ?>><?= e($languageLabel) ?></option>
                <?php endforeach; ?>
            </select>
        </label>
        <label>
            <span><?= e(trans('admin.filter_area')) ?></span>
            <select name="area">
                <option value=""><?= e(trans('common.all_areas')) ?></option>
                <?php foreach ($areas as $areaCode => $area): ?>
                    <option value="<?= e($areaCode) ?>" <?= $filters['area'] === $areaCode ? 'selected' : '' ?>><?= e($areaCode . ' - ' . area_name($areaCode)) ?></option>
                <?php endforeach; ?>
            </select>
        </label>
        <label class="wide-field">
            <span><?= e(trans('admin.filter_search')) ?></span>
            <input type="text" name="search" value="<?= e($filters['search']) ?>" placeholder="<?= e(trans('admin.programme_search_placeholder')) ?>">
        </label>
        <div class="filter-actions">
            <button class="ghost-button" type="submit"><?= e(trans('common.apply')) ?></button>
        </div>
    </form>

    <div class="table-wrap">
        <table>
            <thead>
                <tr>
                    <th><?= e(trans('common.area')) ?></th>
                    <th><?= e(trans('admin.table_programme')) ?></th>
                    <th><?= e(trans('admin.programme_code')) ?></th>
                    <th><?= e(trans('common.order')) ?></th>
                    <th><?= e(trans('common.status')) ?></th>
                    <th><?= e(trans('common.actions')) ?></th>
                </tr>
            </thead>
            <tbody>
                <?php if ($items === []): ?>
                    <tr><td colspan="6"><?= e(trans('admin.programme_empty')) ?></td></tr>
                <?php endif; ?>
                <?php foreach ($items as $item): ?>
                    <tr>
                        <td><?= e($item['area_code']) ?></td>
                        <td><?= e($item['title']) ?></td>
                        <td><?= e((string) ($item['programme_code'] ?? '')) ?></td>
                        <td><?= e((string) $item['sort_order']) ?></td>
                        <td><span class="status-badge <?= (int) $item['is_active'] === 1 ? 'is-active' : 'is-inactive' ?>"><?= e((int) $item['is_active'] === 1 ? trans('common.active') : trans('common.inactive')) ?></span></td>
                        <td class="actions-cell">
                            <a class="text-link" href="<?= e(base_url('/admin/programmes/edit?id=' . $item['id'])) ?>"><?= e(trans('common.edit')) ?></a>
                            <form method="post" action="<?= e(base_url('/admin/programmes/delete')) ?>" onsubmit="return confirm(<?= js_value(trans('admin.delete_programme_confirm')) ?>);">
                                <input type="hidden" name="_csrf" value="<?= e(csrf_token()) ?>">
                                <input type="hidden" name="id" value="<?= e((string) $item['id']) ?>">
                                <button class="text-link destructive-link" type="submit"><?= e(trans('common.delete')) ?></button>
                            </form>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</section>