<?php
/**
 * Terminal report template registry.
 *
 * Maps a template key (stored in settings['report_template']) to its label,
 * description and renderer function. Consumed by the Settings picker and by
 * the print/PDF renderers.
 *
 * Every renderer has the signature:
 *     function (array $data, string $mode): string   // $mode = 'print' | 'pdf'
 * and returns a complete HTML document string.
 */

require_once __DIR__ . '/ges_standard.php';
require_once __DIR__ . '/classic.php';
require_once __DIR__ . '/modern.php';
require_once __DIR__ . '/compact.php';

function reportTemplateRegistry(): array
{
    return [
        'ges_standard' => [
            'label'       => 'GES Standard',
            'description' => 'Official Ghana Education Service report card: crested letterhead, pupil particulars, per-subject position and class average, conduct and attitude, class teacher and head teacher remarks, signatures, school stamp and a Key to Grades panel.',
            'render'      => 'renderReport_ges_standard',
        ],
        'classic' => [
            'label'       => 'Classic',
            'description' => 'The traditional black-and-white terminal report. Formal, high-contrast, prints cleanly on any printer.',
            'render'      => 'renderReport_classic',
        ],
        'modern' => [
            'label'       => 'Modern',
            'description' => 'Clean navy-accented design with a banded title, tidy info grid and colour-coded grades.',
            'render'      => 'renderReport_modern',
        ],
        'compact' => [
            'label'       => 'Compact',
            'description' => 'Tighter spacing and smaller type to fit more subjects on a single page. Ideal for large subject lists.',
            'render'      => 'renderReport_compact',
        ],
    ];
}

/**
 * Return the renderer callable for a template key, falling back to the
 * GES standard format.
 */
function resolveReportRenderer(?string $key): callable
{
    $registry = reportTemplateRegistry();
    $key = $key !== null && isset($registry[$key]) ? $key : 'ges_standard';
    return $registry[$key]['render'];
}
