<?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.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.

namespace theme_iilmp\output;

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

/**
 * IILMP core renderer.
 *
 * The theme is otherwise SCSS-only; this is the single renderer override, kept as
 * thin as possible (one method, delegating to Boost) so it stays upgrade-safe.
 *
 * @package   theme_iilmp
 * @copyright 2026 RUFORUM
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
class core_renderer extends \theme_boost\output\core_renderer {

    /**
     * Personalise the dashboard header.
     *
     * Boost builds the page <h1> from {@see \moodle_page::$heading}, which
     * my/index.php sets to the static "Dashboard". On the dashboard we replace it
     * with the signed-in user's first name; the theme's SCSS wraps that h1 with a
     * "Welcome back" eyebrow and a supporting line, so the header reads
     * "Welcome back / {firstname} / Your courses, calendar, and activity …".
     *
     * Everything else (other pages, guests, module/user headers) falls straight
     * through to Boost unchanged.
     *
     * @param array|null $headerinfo Heading information.
     * @param int $headinglevel What 'h' level to make the heading.
     * @return string A rendered context header.
     */
    public function context_header($headerinfo = null, $headinglevel = 1): string {
        global $USER;

        if ($this->page->pagelayout === 'mydashboard'
                && empty($headerinfo)
                && isloggedin() && !isguestuser()
                && !empty($USER->firstname)) {
            $headerinfo = ['heading' => format_string($USER->firstname)];
        }

        return parent::context_header($headerinfo, $headinglevel);
    }
}
