import React__default, { useId } from 'react';
import { R as RadioGroup, a as RadioOption } from './RadioGroup-es.js';
import { T as Text } from './Text-es.js';

var styles$3 = {"container":"-R-TvZ9aU9g-","spinning":"SYARPwvkeO0-"};

var checkboxStyles = {"checkboxWrapper":"HgFD6w2VXzo-","dayCheckboxInput":"XGjk9DHJAmw-","dayCheckbox":"zulupkPyEs8-","spinning":"jjJFVaCX4Zk-"};

/**
 * @deprecated RecurringSelect will be removed in the next major version
 */
var WeekDay;
(function (WeekDay) {
    WeekDay[WeekDay["Sunday"] = 0] = "Sunday";
    WeekDay[WeekDay["Monday"] = 1] = "Monday";
    WeekDay[WeekDay["Tuesday"] = 2] = "Tuesday";
    WeekDay[WeekDay["Wednesday"] = 3] = "Wednesday";
    WeekDay[WeekDay["Thursday"] = 4] = "Thursday";
    WeekDay[WeekDay["Friday"] = 5] = "Friday";
    WeekDay[WeekDay["Saturday"] = 6] = "Saturday";
})(WeekDay || (WeekDay = {}));
/**
 * @deprecated RecurringSelect will be removed in the next major version
 */
var DurationPeriod;
(function (DurationPeriod) {
    DurationPeriod["Day"] = "Day";
    DurationPeriod["Week"] = "Week";
    DurationPeriod["DayOfMonth"] = "DayOfMonth";
    DurationPeriod["WeekDayOfMonth"] = "WeekDayOfMonth";
    DurationPeriod["Year"] = "Year";
    DurationPeriod["Visit"] = "Visit";
})(DurationPeriod || (DurationPeriod = {}));
const typeInitialStateMap = {
    [DurationPeriod.Day]: {
        type: DurationPeriod.Day,
    },
    [DurationPeriod.Week]: {
        type: DurationPeriod.Week,
        weekDays: new Set(),
    },
    [DurationPeriod.DayOfMonth]: {
        type: DurationPeriod.DayOfMonth,
        date: new Set(),
    },
    [DurationPeriod.WeekDayOfMonth]: {
        type: DurationPeriod.WeekDayOfMonth,
        dayOfWeek: [
            new Set(),
            new Set(),
            new Set(),
            new Set(),
        ],
    },
    [DurationPeriod.Year]: {
        type: DurationPeriod.Year,
    },
};
const isMonthly = (rule) => rule.type === DurationPeriod.WeekDayOfMonth ||
    rule.type === DurationPeriod.DayOfMonth;

const weekDays = [0, 1, 2, 3, 4, 5, 6];
function WeeklySelect({ onChange, selectedDays, disabled, }) {
    const onChangeWeekDays = (event) => {
        const day = Number(event.currentTarget.value);
        const next = new Set(Array.from(selectedDays));
        if (selectedDays.has(day)) {
            next.delete(day);
        }
        else {
            next.add(day);
        }
        onChange(next);
    };
    return (React__default.createElement("div", { className: styles$3.container }, weekDays.map(weekDay => {
        const isSelected = selectedDays.has(weekDay);
        const inputId = useId();
        return (React__default.createElement("div", { key: `${weekDay}`, className: checkboxStyles.checkboxWrapper },
            React__default.createElement("input", { className: checkboxStyles.dayCheckboxInput, disabled: disabled, type: "checkbox", onChange: onChangeWeekDays, id: `weekly-select-${weekDay}${inputId}`, "aria-checked": isSelected, checked: isSelected, value: weekDay }),
            React__default.createElement("label", { className: checkboxStyles.dayCheckbox, htmlFor: `weekly-select-${weekDay}${inputId}` }, `${WeekDay[weekDay].substr(0, 1).toUpperCase()}`)));
    })));
}

var styles$2 = {"radioContainer":"cr0irYOHA5k-","spinning":"CAeHbpYJvRk-"};

function MonthlySelect({ disabled, onChange, selectedMonthOption, }) {
    return (React__default.createElement("div", { className: styles$2.radioContainer },
        React__default.createElement(RadioGroup, { ariaLabel: "Monthly Frequency Selector", onChange: onChange, value: selectedMonthOption },
            React__default.createElement(RadioOption, { disabled: disabled, value: DurationPeriod.DayOfMonth, label: "Day of month" }),
            React__default.createElement(RadioOption, { disabled: disabled, value: DurationPeriod.WeekDayOfMonth, label: "Day of week" }))));
}

var styles$1 = {"container":"Qup9qglgfQ8-","parentContainer":"FxW4kmZLd44-","spinning":"_3B10vRc7B6c-"};

function MonthlyDayOfWeekSelect({ disabled, selectedWeeks, onChange, }) {
    const orderString = ["1st", "2nd", "3rd", "4th"];
    return (React__default.createElement("div", { className: styles$1.parentContainer }, selectedWeeks.map((week, index) => {
        const onChangeWeek = (weekDay) => {
            const next = [...selectedWeeks];
            next.splice(index, 1, weekDay);
            onChange(next);
        };
        return (React__default.createElement("div", { className: styles$1.container, key: `${index}${week}` },
            React__default.createElement(Text, null, `${orderString[index]}`),
            React__default.createElement("div", null,
                React__default.createElement(WeeklySelect, { disabled: disabled, selectedDays: week, onChange: onChangeWeek }))));
    })));
}

var styles = {"container":"_4d0IFF7M5S0-","spinning":"TEqEHU-NbhU-"};

const daysInMonth = [...Array.from({ length: 31 }, (_, i) => i + 1), "LAST"];
function DayOfMonthSelect({ selectedDays, disabled, onChange, }) {
    return (React__default.createElement("div", { className: styles.container }, daysInMonth.map(day => {
        const isSelected = selectedDays.has(day);
        const inputId = useId();
        return (React__default.createElement("div", { key: `${day}`, className: checkboxStyles.checkboxWrapper },
            React__default.createElement("input", { className: checkboxStyles.dayCheckboxInput, disabled: disabled, type: "checkbox", id: `${day}-${inputId}`, onChange: handleChangeDayOfMonth, "aria-checked": isSelected, checked: isSelected, value: day }),
            React__default.createElement("label", { className: checkboxStyles.dayCheckbox, htmlFor: `${day}-${inputId}` }, `${day === "LAST" ? "Last day" : day}`)));
    })));
    function handleChangeDayOfMonth(event) {
        const day = event.currentTarget.value === "LAST"
            ? event.currentTarget.value
            : +event.currentTarget.value;
        const next = new Set(selectedDays);
        if (selectedDays.has(day)) {
            next.delete(day);
        }
        else {
            next.add(day);
        }
        onChange(next);
    }
}

export { DurationPeriod as D, MonthlySelect as M, WeekDay as W, WeeklySelect as a, MonthlyDayOfWeekSelect as b, DayOfMonthSelect as c, isMonthly as i, typeInitialStateMap as t };
