<?php

use App\Models\ConfigurationModel;

if (!function_exists('selected_teacher_semester')) {
    function selected_teacher_semester(): string
    {
        $session = session();
        $selected = trim((string) ($session->get('teacher_scores_selected_semester') ?? ''));
        if ($selected !== '') {
            return ucfirst(strtolower($selected));
        }

        $fallback = trim((string) ($session->get('semester') ?? ''));
        if ($fallback !== '') {
            return ucfirst(strtolower($fallback));
        }

        $config = new ConfigurationModel();
        $configSemester = trim((string) ($config->getConfig('semester') ?? ''));
        if ($configSemester !== '') {
            return ucfirst(strtolower($configSemester));
        }

        return 'Fall';
    }
}
