import React__default from 'react';
import { D as DurationPeriod, c as DayOfMonthSelect, b as MonthlyDayOfWeekSelect, a as WeeklySelect, i as isMonthly, M as MonthlySelect, t as typeInitialStateMap } from './DayOfMonthSelect-es.js';
import { T as Text } from './Text-es.js';
import 'classnames';
import { Select, Option as SelectOption } from './Select/index.mjs';
import { InputNumber } from './InputNumber/index.mjs';
import { I as InputGroup } from './InputGroup-es.js';
import { C as Content } from './Content-es.js';

function CurrentRecurrenceComponent({ recurrenceRule, disabled = false, onChange, }) {
    switch (recurrenceRule.type) {
        case DurationPeriod.Week: {
            const onChangeWeekDays = (next) => {
                onChange(Object.assign(Object.assign({}, recurrenceRule), { weekDays: next }));
            };
            return (React__default.createElement(WeeklySelect, { disabled: disabled, selectedDays: recurrenceRule.weekDays, onChange: onChangeWeekDays }));
        }
        case DurationPeriod.WeekDayOfMonth: {
            const onChangeWeekDayOfMonth = (next) => {
                onChange(Object.assign(Object.assign({}, recurrenceRule), { dayOfWeek: next }));
            };
            return (React__default.createElement(MonthlyDayOfWeekSelect, { disabled: disabled, onChange: onChangeWeekDayOfMonth, selectedWeeks: recurrenceRule.dayOfWeek }));
        }
        case DurationPeriod.DayOfMonth: {
            const onChangeDayOfMonth = (next) => {
                onChange(Object.assign(Object.assign({}, recurrenceRule), { date: next }));
            };
            return (React__default.createElement(DayOfMonthSelect, { disabled: disabled, selectedDays: recurrenceRule.date, onChange: onChangeDayOfMonth }));
        }
        default:
            return React__default.createElement(React__default.Fragment, null);
    }
}

var styles = {"container":"v2xMxsPFwcM-","fullWidthWrapper":"cfDwOgEkPHQ-","spinning":"s4XnDjTR4Uw-"};

/**
 * @deprecated RecurringSelect will be removed in the next major version
 */
function RecurringSelect({ value, disabled = false, onChange, }) {
    const disabledTextVariation = disabled ? "disabled" : undefined;
    // we must dynamically populate the select option based on which is selected
    // because there is no single "month" option, it must always be one of these two
    const monthlySelectOptionValue = value.type === DurationPeriod.WeekDayOfMonth
        ? DurationPeriod.WeekDayOfMonth
        : DurationPeriod.DayOfMonth;
    const hasExtraFrequencyDescriptor = value.type === DurationPeriod.WeekDayOfMonth ||
        value.type === DurationPeriod.DayOfMonth ||
        value.type === DurationPeriod.Week;
    return (React__default.createElement(Content, null,
        React__default.createElement("div", { className: styles.container },
            React__default.createElement(Text, { variation: disabledTextVariation }, "Every"),
            React__default.createElement("div", { className: styles.fullWidthWrapper },
                React__default.createElement(InputGroup, { flowDirection: "horizontal" },
                    React__default.createElement(InputNumber, { disabled: disabled, name: "schedule-recurrence-interval", value: value.interval, min: 1, maxLength: 3, onChange: onChangeInterval }),
                    React__default.createElement(Select, { disabled: disabled, value: value.type, onChange: onChangeType, name: "schedule-recurrence-type" },
                        React__default.createElement(SelectOption, { value: DurationPeriod.Day }, "Day(s)"),
                        React__default.createElement(SelectOption, { value: DurationPeriod.Week }, "Week(s)"),
                        React__default.createElement(SelectOption, { value: monthlySelectOptionValue }, "Month(s)"),
                        React__default.createElement(SelectOption, { value: DurationPeriod.Year }, "Year(s)")))),
            hasExtraFrequencyDescriptor && (React__default.createElement(Text, { variation: disabledTextVariation }, "on"))),
        isMonthly(value) && (React__default.createElement(MonthlySelect, { disabled: disabled, onChange: onChangeType, selectedMonthOption: value.type })),
        React__default.createElement(CurrentRecurrenceComponent, { disabled: disabled, recurrenceRule: value, onChange: onChange })));
    function onChangeInterval(interval) {
        onChange(Object.assign(Object.assign({}, value), { interval }));
    }
    function onChangeType(type) {
        onChange(Object.assign({ interval: value.interval }, typeInitialStateMap[type]));
    }
}

export { RecurringSelect as R };
