{#
    Schedule block for an offer. Kind-specific icon + tint, two-line layout
    (date / time), optional "+ N Alternativtermine" badge.

    Kinds — derived in OfferSchedule.php from the offer's OfferDate rows:
      ongoing    : no dates → "Laufendes Angebot"
      single     : 1 one-off date
      recurring  : at least one date has an RRULE
      series     : multiple plain dates
#}

{% set icons = {
    single: 'lucide:calendar',
    series: 'lucide:calendar-days',
    recurring: 'lucide:repeat',
    ongoing: 'lucide:clock',
} %}

{% set tone = {
    single: 'bg-gray-100 dark:bg-white/5 text-gray-900 dark:text-gray-100',
    series: 'bg-amber-50 dark:bg-amber-400/10 text-amber-900 dark:text-amber-100',
    recurring: 'bg-blue-50 dark:bg-blue-400/10 text-blue-900 dark:text-blue-100',
    ongoing: 'bg-green-50 dark:bg-green-400/10 text-green-900 dark:text-green-100',
} %}
{% set iconTone = {
    single: 'text-gray-700 dark:text-gray-200',
    series: 'text-amber-700 dark:text-amber-300',
    recurring: 'text-blue-700 dark:text-blue-300',
    ongoing: 'text-green-700 dark:text-green-300',
} %}

<div class="flex items-start gap-2.5 rounded-lg px-3 py-2 {{ tone[kind] }}">
    <span class="grid h-8 w-8 flex-none place-items-center rounded-md bg-white/80 dark:bg-white/10 {{ iconTone[kind] }}">
        <twig:ux:icon :name="icons[kind]" class="h-4 w-4" />
    </span>

    <div class="flex min-w-0 flex-1 flex-col gap-0.5">
        {# ---- Date line ---- #}
        <span class="text-[13px] font-semibold leading-tight">
            {%- if kind == 'ongoing' -%}
                {{ 'offerSchedule.ongoing'|trans({}, 'cms') }}

            {%- elseif kind == 'recurring' -%}
                {{ recurrencePhrase ? (recurrencePhrase|capitalize) : 'offerSchedule.recurring'|trans({}, 'cms') }}

            {%- elseif kind == 'series' and seriesIsRange and firstBegin and lastBegin -%}
                {# Range: "Mo. – Fr., 04. – 08.MM." within a month,
                   or "Mo. – Fr., 30.06. – 04.07." across a month boundary. #}
                {{- firstBegin|format_datetime(pattern='E', locale: locale) ~ ' – ' ~ lastBegin|format_datetime(pattern='E', locale: locale) -}}
                {{- ', ' -}}
                {%- if seriesSpansMonths -%}
                    {{- firstBegin|format_datetime(pattern='dd.MM.', locale: locale) ~ ' – ' ~ lastBegin|format_datetime(pattern='dd.MM.', locale: locale) -}}
                {%- else -%}
                    {{- firstBegin|format_datetime(pattern='dd.', locale: locale) ~ ' – ' ~ lastBegin|format_datetime(pattern='dd.MM.', locale: locale) -}}
                {%- endif -%}

            {%- elseif kind == 'series' and firstBegin -%}
                {# First date + " + N weitere" #}
                {{- firstBegin|format_datetime(pattern='E, dd.MM.', locale: locale) -}}
                {%- if occurrenceCount > 1 %}
                    <span class="font-medium text-current/70">{{ 'offerSchedule.furtherCount'|trans({count: occurrenceCount - 1}, 'cms') }}</span>
                {%- endif -%}

            {%- elseif firstBegin -%}
                {# single #}
                {{- firstBegin|format_datetime(pattern='E, dd.MM.', locale: locale) -}}
            {%- endif -%}
        </span>

        {# ---- Time line ---- #}
        {% if kind != 'ongoing' and firstBegin and firstEnd %}
            <span class="text-[12px] font-medium leading-tight opacity-80">
                {%- if kind == 'series' and seriesIsRange and uniformTimeOfDay -%}
                    {{ 'offerSchedule.eachAt'|trans({}, 'cms') }}
                    {{- ' ' ~ firstBegin|format_datetime(pattern='HH:mm', locale: locale) ~ ' – ' ~ firstEnd|format_datetime(pattern='HH:mm', locale: locale) ~ ' Uhr' -}}
                {%- elseif kind == 'series' and uniformTimeOfDay -%}
                    {{ 'offerSchedule.eachAt'|trans({}, 'cms') }}
                    {{- ' ' ~ firstBegin|format_datetime(pattern='HH:mm', locale: locale) ~ ' – ' ~ firstEnd|format_datetime(pattern='HH:mm', locale: locale) ~ ' Uhr' -}}
                {%- elseif firstBegin|date('Ymd') == firstEnd|date('Ymd') -%}
                    {{- firstBegin|format_datetime(pattern='HH:mm', locale: locale) ~ ' – ' ~ firstEnd|format_datetime(pattern='HH:mm', locale: locale) ~ ' Uhr' -}}
                {%- else -%}
                    {{- firstBegin|format_datetime(pattern='HH:mm', locale: locale) ~ ' – ' ~ firstEnd|format_datetime(pattern='dd.MM. HH:mm', locale: locale) -}}
                {%- endif -%}
            </span>
        {% endif %}

        {# ---- Alternatives badge ---- #}
        {% if alternativesCount > 0 %}
            <span class="mt-1 inline-flex items-center gap-1 text-[11px] font-semibold text-primary-700 dark:text-primary-300">
                <twig:ux:icon name="lucide:arrow-right-left" class="h-3 w-3" />
                {{ 'offerSchedule.alternatives'|trans({count: alternativesCount}, 'cms') }}
            </span>
        {% endif %}
    </div>
</div>
