'use strict';

var React = require('react');
var RadioGroup = require('./RadioGroup-cjs.js');
var Text = require('./Text-cjs.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
 */
exports.WeekDay = void 0;
(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";
})(exports.WeekDay || (exports.WeekDay = {}));
/**
 * @deprecated RecurringSelect will be removed in the next major version
 */
exports.DurationPeriod = void 0;
(function (DurationPeriod) {
    DurationPeriod["Day"] = "Day";
    DurationPeriod["Week"] = "Week";
    DurationPeriod["DayOfMonth"] = "DayOfMonth";
    DurationPeriod["WeekDayOfMonth"] = "WeekDayOfMonth";
    DurationPeriod["Year"] = "Year";
    DurationPeriod["Visit"] = "Visit";
})(exports.DurationPeriod || (exports.DurationPeriod = {}));
const typeInitialStateMap = {
    [exports.DurationPeriod.Day]: {
        type: exports.DurationPeriod.Day,
    },
    [exports.DurationPeriod.Week]: {
        type: exports.DurationPeriod.Week,
        weekDays: new Set(),
    },
    [exports.DurationPeriod.DayOfMonth]: {
        type: exports.DurationPeriod.DayOfMonth,
        date: new Set(),
    },
    [exports.DurationPeriod.WeekDayOfMonth]: {
        type: exports.DurationPeriod.WeekDayOfMonth,
        dayOfWeek: [
            new Set(),
            new Set(),
            new Set(),
            new Set(),
        ],
    },
    [exports.DurationPeriod.Year]: {
        type: exports.DurationPeriod.Year,
    },
};
const isMonthly = (rule) => rule.type === exports.DurationPeriod.WeekDayOfMonth ||
    rule.type === exports.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.createElement("div", { className: styles$3.container }, weekDays.map(weekDay => {
        const isSelected = selectedDays.has(weekDay);
        const inputId = React.useId();
        return (React.createElement("div", { key: `${weekDay}`, className: checkboxStyles.checkboxWrapper },
            React.createElement("input", { className: checkboxStyles.dayCheckboxInput, disabled: disabled, type: "checkbox", onChange: onChangeWeekDays, id: `weekly-select-${weekDay}${inputId}`, "aria-checked": isSelected, checked: isSelected, value: weekDay }),
            React.createElement("label", { className: checkboxStyles.dayCheckbox, htmlFor: `weekly-select-${weekDay}${inputId}` }, `${exports.WeekDay[weekDay].substr(0, 1).toUpperCase()}`)));
    })));
}

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

function MonthlySelect({ disabled, onChange, selectedMonthOption, }) {
    return (React.createElement("div", { className: styles$2.radioContainer },
        React.createElement(RadioGroup.RadioGroup, { ariaLabel: "Monthly Frequency Selector", onChange: onChange, value: selectedMonthOption },
            React.createElement(RadioGroup.RadioOption, { disabled: disabled, value: exports.DurationPeriod.DayOfMonth, label: "Day of month" }),
            React.createElement(RadioGroup.RadioOption, { disabled: disabled, value: exports.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.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.createElement("div", { className: styles$1.container, key: `${index}${week}` },
            React.createElement(Text.Text, null, `${orderString[index]}`),
            React.createElement("div", null,
                React.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.createElement("div", { className: styles.container }, daysInMonth.map(day => {
        const isSelected = selectedDays.has(day);
        const inputId = React.useId();
        return (React.createElement("div", { key: `${day}`, className: checkboxStyles.checkboxWrapper },
            React.createElement("input", { className: checkboxStyles.dayCheckboxInput, disabled: disabled, type: "checkbox", id: `${day}-${inputId}`, onChange: handleChangeDayOfMonth, "aria-checked": isSelected, checked: isSelected, value: day }),
            React.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);
    }
}

exports.DayOfMonthSelect = DayOfMonthSelect;
exports.MonthlyDayOfWeekSelect = MonthlyDayOfWeekSelect;
exports.MonthlySelect = MonthlySelect;
exports.WeeklySelect = WeeklySelect;
exports.isMonthly = isMonthly;
exports.typeInitialStateMap = typeInitialStateMap;
