<?php

namespace App\Enums;

enum ChampionshipStatusEnum: int
{
    case UPCOMING = 1;
    case REGISTRATION_OPEN = 2;
    case ONGOING = 3;
    case FINISHED = 4;
    case CANCELLED = 5;

    public static function labels(): array
    {
        return [
            self::UPCOMING->value => __('Upcoming'),
            self::REGISTRATION_OPEN->value => __('Registration Open'),
            self::ONGOING->value => __('Ongoing'),
            self::FINISHED->value => __('Finished'),
            self::CANCELLED->value => __('Cancelled'),
        ];
    }

    public static function label(self|int|null $value): string
    {
        $key = $value instanceof self ? $value->value : $value;
        return self::labels()[$key] ?? '';
    }

    public static function values(): array
    {
        return array_column(self::cases(), 'value');
    }

    public static function options(): array
    {
        return collect(self::cases())->map(fn ($case) => [
            'value' => $case->value,
            'label' => self::label($case),
        ])->all();
    }

    public static function badge(int|null $value): string
    {
        $label = self::label($value);
        $color = match ($value) {
            self::UPCOMING->value => 'info',
            self::REGISTRATION_OPEN->value => 'primary',
            self::ONGOING->value => 'warning',
            self::FINISHED->value => 'success',
            self::CANCELLED->value => 'danger',
            default => 'light',
        };
        return '<span class="badge bg-' . $color . '">' . $label . '</span>';
    }
}
