@namespace Lumeo

<DatePicker Mode="DatePicker.DatePickerMode.Range" NumberOfMonths="2"
            RangeStart="@StartDate" RangeStartChanged="@StartDateChanged"
            RangeEnd="@EndDate" RangeEndChanged="@EndDateChanged"
            MinDate="@MinDate" MaxDate="@MaxDate"
            IsDateDisabled="@IsDateDisabled" DateClass="@DateClass"
            DateTooltip="@DateTooltip" DateBadge="@DateBadge"
            Placeholder="@EffectivePlaceholder" Format="@Format"
            Presets="@_datePickerPresets"
            Disabled="@Disabled"
            Clearable="@Clearable"
            Class="@Class"
            FirstDayOfWeek="@FirstDayOfWeek" ShowWeekNumbers="@ShowWeekNumbers"
            @attributes="AdditionalAttributes" />

@inject Lumeo.Services.Localization.ILumeoLocalizer L

@code {
    [Parameter] public DateOnly? StartDate { get; set; }
    [Parameter] public EventCallback<DateOnly?> StartDateChanged { get; set; }
    [Parameter] public DateOnly? EndDate { get; set; }
    [Parameter] public EventCallback<DateOnly?> EndDateChanged { get; set; }
    [Parameter] public DateOnly? MinDate { get; set; }
    [Parameter] public DateOnly? MaxDate { get; set; }
    /// <summary>Custom predicate to disable specific dates (e.g. booked
    /// rooms). Returns <c>true</c> for dates that should not be selectable.</summary>
    [Parameter] public Func<DateTime, bool>? IsDateDisabled { get; set; }
    /// <summary>Custom CSS classes per day cell — forwarded to inner Calendar.</summary>
    [Parameter] public Func<DateTime, string>? DateClass { get; set; }
    /// <summary>Per-date tooltip text rendered as the day cell's <c>title</c>.</summary>
    [Parameter] public Func<DateTime, string?>? DateTooltip { get; set; }
    /// <summary>Per-date indicator slot rendered absolutely positioned in the
    /// bottom-right of the day cell.</summary>
    [Parameter] public Func<DateTime, RenderFragment?>? DateBadge { get; set; }
    [Parameter] public string? Placeholder { get; set; }

    private string EffectivePlaceholder => Placeholder ?? L["DateRange.Placeholder"];
    /// <summary>
    /// Date format. When null (default) the inner <see cref="DatePicker"/> falls back
    /// to the effective culture's <c>ShortDatePattern</c> — so a <c>de-DE</c> user sees
    /// <c>15.03.2026</c> and an <c>en-US</c> user sees <c>3/15/2026</c> automatically.
    /// </summary>
    [Parameter] public string? Format { get; set; }
    [Parameter] public List<DateRangePreset>? Presets { get; set; }
    [Parameter] public bool Disabled { get; set; }
    [Parameter] public bool Clearable { get; set; } = true;
    [Parameter] public DayOfWeek? FirstDayOfWeek { get; set; }
    [Parameter] public bool ShowWeekNumbers { get; set; }
    [Parameter] public string? Class { get; set; }
    [Parameter(CaptureUnmatchedValues = true)] public Dictionary<string, object>? AdditionalAttributes { get; set; }

    private List<DatePicker.DatePickerPreset>? _datePickerPresets =>
        Presets?.Select(p => new DatePicker.DatePickerPreset(p.Label, p.Start)).ToList();

    public class DateRangePreset
    {
        public string Label { get; set; } = "";
        public DateOnly Start { get; set; }
        public DateOnly End { get; set; }
    }
}
