<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

/**
 * Renderable/templatable data for the dashboard's "Vue globale" sub-tab —
 * administrators only, one row per promotion, no promotion pre-selected.
 *
 * @package    local_kid
 */

namespace local_kid\output;

use local_kid\local\dashboard_repository;

defined('MOODLE_INTERNAL') || die();

class dashboard_global_page implements \renderable, \templatable {

    public function export_for_template(\renderer_base $output): array {
        $data = dashboard_repository::global_overview();

        return [
            'promotioncount' => $data['promotioncount'],
            'activecount' => $data['activecount'],
            'totalstudents' => $data['totalstudents'],
            'haspromotions' => !empty($data['promotions']),
            'adminpromotionsurl' => (new \moodle_url('/local/kid/pages/admin.php', ['tab' => 'promotions']))->out(false),
            'promotions' => array_map(fn($p) => [
                'name' => $p['name'],
                'statuslabel' => $p['active']
                    ? get_string('promotion_status_active', 'local_kid')
                    : get_string('promotion_status_inactive', 'local_kid'),
                'statusclass' => $p['active'] ? 'fr-badge fr-badge--success' : 'fr-badge',
                'cohortlinked' => $p['cohortlinked'],
                'studentcount' => $p['studentcount'],
                'evalstocomplete' => $p['evalstocomplete'],
                'stagestocomplete' => $p['stagestocomplete'],
                'capptocomplete' => $p['capptocomplete'],
                'cappfinalised' => $p['cappfinalised'],
                'openurl' => $p['openurl'],
            ], $data['promotions']),
        ];
    }
}
