<?php

if (! function_exists('format_percentage')) {
    function format_percentage(?float $value, int $decimals = 0): string
    {
        $value ??= 0.0;

        return number_format($value, $decimals) . '%';
    }
}

if (! function_exists('format_score')) {
    function format_score(null|float|int|string $value, int $decimals = 2): string
    {
        if ($value === null || $value === '') {
            return '-';
        }

        return number_format((float) $value, $decimals);
    }
}

if (! function_exists('status_label')) {
    function status_label(?string $status): string
    {
        $status = strtoupper((string) $status);

        return match ($status) {
            'ALMOST_READY', 'ALMOST READY' => 'Almost Ready',
            'ALMOST' => 'Almost',
            'ATTENDANCE' => 'Attendance',
            'ATTENDANCE_ALERT' => 'Attendance Alert',
            'ABSENT_EXCUSED' => 'Absent motivat',
            'ABSENT UNEXCUSED', 'ABSENT_UNEXCUSED' => 'Absent nemotivat',
            'PRESENT' => 'Prezent',
            'RECOVERY' => 'Recuperare',
            'INACTIVE' => 'Inactiv',
            'OVERDUE' => 'Overdue',
            'PROMOTION_READY' => 'Promotion Ready',
            'EVALUATION_OVERDUE' => 'Evaluation Overdue',
            'UNREAD' => 'Unread',
            'READ' => 'Read',
            'COMPLETED' => 'Completed',
            'CANCELLED' => 'Cancelled',
            'SCHEDULED' => 'Scheduled',
            'READY' => 'Ready',
            'HOLD' => 'Hold',
            default => ucwords(strtolower(str_replace('_', ' ', $status))),
        };
    }
}

if (! function_exists('status_badge_classes')) {
    function status_badge_classes(?string $status): string
    {
        $status = strtoupper((string) $status);

        return match ($status) {
            'READY', 'PROMOTION_READY' => 'bg-emerald-50 text-emerald-700 ring-emerald-600/20',
            'ALMOST_READY', 'ALMOST READY', 'ALMOST', 'SCHEDULED', 'ABSENT_EXCUSED' => 'bg-amber-50 text-amber-700 ring-amber-600/20',
            'HOLD', 'ATTENDANCE', 'ATTENDANCE_ALERT', 'ABSENT_UNEXCUSED', 'ABSENT UNEXCUSED' => 'bg-rose-50 text-rose-700 ring-rose-600/20',
            'PRESENT', 'COMPLETED' => 'bg-emerald-50 text-emerald-700 ring-emerald-600/20',
            'RECOVERY', 'ACTIVE', 'UNREAD' => 'bg-sky-50 text-sky-700 ring-sky-600/20',
            'OVERDUE', 'EVALUATION_OVERDUE', 'PAUSE', 'READ' => 'bg-slate-100 text-slate-700 ring-slate-500/20',
            'INACTIVE', 'LEFT', 'CANCELLED' => 'bg-zinc-100 text-zinc-700 ring-zinc-500/20',
            default => 'bg-slate-100 text-slate-700 ring-slate-500/20',
        };
    }
}

if (! function_exists('level_chip_style')) {
    function level_chip_style(?string $hexColor): string
    {
        $hexColor = $hexColor ?: '#94a3b8';

        if (strlen($hexColor) === 7) {
            return "border-color: {$hexColor}; color: {$hexColor}; background-color: {$hexColor}14;";
        }

        return '';
    }
}

if (! function_exists('gender_label')) {
    function gender_label(?string $gender): string
    {
        return match ((string) $gender) {
            'male' => 'Baiat',
            'female' => 'Fata',
            default => '-',
        };
    }
}

if (! function_exists('yes_no_label')) {
    function yes_no_label(bool|int|string|null $value): string
    {
        return (int) $value === 1 ? 'Da' : 'Nu';
    }
}

if (! function_exists('day_of_week_label')) {
    function day_of_week_label(int|string|null $day): string
    {
        return match ((int) $day) {
            1 => 'Luni',
            2 => 'Marti',
            3 => 'Miercuri',
            4 => 'Joi',
            5 => 'Vineri',
            6 => 'Sambata',
            7 => 'Duminica',
            default => '-',
        };
    }
}

if (! function_exists('session_status_options')) {
    function session_status_options(): array
    {
        return [
            'scheduled' => 'Scheduled',
            'completed' => 'Completed',
            'cancelled' => 'Cancelled',
            'recovery' => 'Recovery',
        ];
    }
}

if (! function_exists('attendance_record_options')) {
    function attendance_record_options(): array
    {
        return [
            'present' => 'Prezent',
            'absent_excused' => 'Absent motivat',
            'absent_unexcused' => 'Absent nemotivat',
            'recovery' => 'Recuperare',
        ];
    }
}

if (! function_exists('nav_item_classes')) {
    function nav_item_classes(bool $active): string
    {
        return $active
            ? 'bg-indigo-600 text-white shadow-soft'
            : 'text-slate-600 hover:bg-slate-100 hover:text-slate-900';
    }
}
