<?php

declare(strict_types=1);

namespace Plugin\tnt_coupons\src\Helper;

use function str_starts_with;
use function strtolower;

/**
 * Pure, side-effect-free source of the localized weekday multi-select labels shown on the
 * coupon settings page ("Nur an Wochentagen anzeigen"). The stored value is unchanged — a
 * comma-separated list of ISO-8601 weekday numbers (1=Mon … 7=Sun), parsed by
 * {@see WeekdayScheduleTrigger::fromConfig()} — this helper only supplies the UI labels.
 *
 * Language is picked from the backend admin language: English when the admin locale starts
 * with "en" (e.g. "en-GB"), German otherwise (the shop default, e.g. "de-DE").
 */
final class WeekdayLabels
{
    /** ISO weekday number => [German short, English short]. */
    private const DAYS = [
        1 => ['Mo', 'Mon'],
        2 => ['Di', 'Tue'],
        3 => ['Mi', 'Wed'],
        4 => ['Do', 'Thu'],
        5 => ['Fr', 'Fri'],
        6 => ['Sa', 'Sat'],
        7 => ['So', 'Sun'],
    ];

    /**
     * @return bool true when the admin UI language is English
     */
    public static function isEnglish(string $adminLanguage): bool
    {
        return str_starts_with(strtolower($adminLanguage), 'en');
    }

    /**
     * Ordered list of the seven weekdays with a localized short label, Monday first.
     *
     * @return list<array{n: int, label: string}>
     */
    public static function days(bool $english): array
    {
        $out = [];
        foreach (self::DAYS as $n => $labels) {
            $out[] = ['n' => $n, 'label' => $english ? $labels[1] : $labels[0]];
        }

        return $out;
    }

    public static function heading(bool $english): string
    {
        return $english ? 'Show only on weekdays' : 'Nur an Wochentagen anzeigen';
    }

    public static function help(bool $english): string
    {
        return $english
            ? 'Select the days the banner may show. No selection = every day. Applies on top of the time window above.'
            : 'Tage wählen, an denen das Banner erscheinen darf. Keine Auswahl = an allen Tagen. '
                . 'Wirkt zusätzlich zum obigen Zeitraum.';
    }
}
