'use strict';

var React = require('react');
var DayOfMonthSelect = require('./DayOfMonthSelect-cjs.js');
var Text = require('./Text-cjs.js');
require('classnames');
var Select = require('./Select-cjs.js');
var InputNumber_index = require('./InputNumber/index.cjs');
var InputGroup = require('./InputGroup-cjs.js');
var Content = require('./Content-cjs.js');

function CurrentRecurrenceComponent({ recurrenceRule, disabled = false, onChange, }) {
    switch (recurrenceRule.type) {
        case DayOfMonthSelect.DurationPeriod.Week: {
            const onChangeWeekDays = (next) => {
                onChange(Object.assign(Object.assign({}, recurrenceRule), { weekDays: next }));
            };
            return (React.createElement(DayOfMonthSelect.WeeklySelect, { disabled: disabled, selectedDays: recurrenceRule.weekDays, onChange: onChangeWeekDays }));
        }
        case DayOfMonthSelect.DurationPeriod.WeekDayOfMonth: {
            const onChangeWeekDayOfMonth = (next) => {
                onChange(Object.assign(Object.assign({}, recurrenceRule), { dayOfWeek: next }));
            };
            return (React.createElement(DayOfMonthSelect.MonthlyDayOfWeekSelect, { disabled: disabled, onChange: onChangeWeekDayOfMonth, selectedWeeks: recurrenceRule.dayOfWeek }));
        }
        case DayOfMonthSelect.DurationPeriod.DayOfMonth: {
            const onChangeDayOfMonth = (next) => {
                onChange(Object.assign(Object.assign({}, recurrenceRule), { date: next }));
            };
            return (React.createElement(DayOfMonthSelect.DayOfMonthSelect, { disabled: disabled, selectedDays: recurrenceRule.date, onChange: onChangeDayOfMonth }));
        }
        default:
            return React.createElement(React.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 === DayOfMonthSelect.DurationPeriod.WeekDayOfMonth
        ? DayOfMonthSelect.DurationPeriod.WeekDayOfMonth
        : DayOfMonthSelect.DurationPeriod.DayOfMonth;
    const hasExtraFrequencyDescriptor = value.type === DayOfMonthSelect.DurationPeriod.WeekDayOfMonth ||
        value.type === DayOfMonthSelect.DurationPeriod.DayOfMonth ||
        value.type === DayOfMonthSelect.DurationPeriod.Week;
    return (React.createElement(Content.Content, null,
        React.createElement("div", { className: styles.container },
            React.createElement(Text.Text, { variation: disabledTextVariation }, "Every"),
            React.createElement("div", { className: styles.fullWidthWrapper },
                React.createElement(InputGroup.InputGroup, { flowDirection: "horizontal" },
                    React.createElement(InputNumber_index.InputNumber, { disabled: disabled, name: "schedule-recurrence-interval", value: value.interval, min: 1, maxLength: 3, onChange: onChangeInterval }),
                    React.createElement(Select.Select, { disabled: disabled, value: value.type, onChange: onChangeType, name: "schedule-recurrence-type" },
                        React.createElement(Select.SelectOption, { value: DayOfMonthSelect.DurationPeriod.Day }, "Day(s)"),
                        React.createElement(Select.SelectOption, { value: DayOfMonthSelect.DurationPeriod.Week }, "Week(s)"),
                        React.createElement(Select.SelectOption, { value: monthlySelectOptionValue }, "Month(s)"),
                        React.createElement(Select.SelectOption, { value: DayOfMonthSelect.DurationPeriod.Year }, "Year(s)")))),
            hasExtraFrequencyDescriptor && (React.createElement(Text.Text, { variation: disabledTextVariation }, "on"))),
        DayOfMonthSelect.isMonthly(value) && (React.createElement(DayOfMonthSelect.MonthlySelect, { disabled: disabled, onChange: onChangeType, selectedMonthOption: value.type })),
        React.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 }, DayOfMonthSelect.typeInitialStateMap[type]));
    }
}

exports.RecurringSelect = RecurringSelect;
