<?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.

namespace local_kid\output;

use local_kid\local\eval_repository;

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

/**
 * Landing screen for the "Évaluations" main-menu entry: pick which active
 * evaluation to fill in, then (via eval_grid_page's summary mode) which
 * student. Deliberately excludes the referentiel CRUD actions (add/edit/
 * toggle/sync) that belong only to Administration > Évaluations
 * (evaluations_admin_page).
 */
class evaluations_picker_page implements \renderable, \templatable {

    protected int $promotionid;

    public function __construct(int $promotionid) {
        $this->promotionid = $promotionid;
    }

    public function export_for_template(\renderer_base $output): array {
        $items = [];
        foreach (eval_repository::get_for_promotion($this->promotionid) as $eval) {
            if (!$eval->active) {
                continue;
            }
            $items[] = [
                'titre' => format_string($eval->titre),
                'meta' => $eval->sourcetype === 'moodle_devoir'
                    ? get_string('eval_sourcetype_devoir', 'local_kid')
                    : get_string('eval_sourcetype_manual', 'local_kid'),
                'openurl' => (new \moodle_url('/local/kid/pages/evaluations.php', ['evalid' => $eval->id]))->out(false),
            ];
        }

        return [
            'introlabel' => get_string('picker_intro_evaluations', 'local_kid'),
            'hasitems' => !empty($items),
            'items' => $items,
            'message' => get_string('picker_empty_evaluations', 'local_kid'),
        ];
    }
}
