import DropdownUtil from "../../Utils/Dropdown";
import Dropdown from "../Dropdown/Dropdown";
import Input, { InputType } from "../Input/Input";
import EventInterval from "../../../Types/Events/EventInterval";
import Recurring from "../../../Types/Events/Recurring";
import PositiveNumber from "../../../Types/PositiveNumber";
import Typeof from "../../../Types/Typeof";
import React, { useState } from "react";
const RecurringFieldElement = (props) => {
    const [recurring, setRecurring] = useState(props.initialValue ? Recurring.fromJSON(props.initialValue) : undefined);
    const updateRecurring = (restrictionTimes) => {
        setRecurring(Recurring.fromJSON(restrictionTimes.toJSON()));
        if (props.onChange) {
            props.onChange(restrictionTimes);
        }
    };
    return (React.createElement("div", null,
        React.createElement("div", { className: "flex space-x-3" },
            React.createElement(Input, { value: recurring === null || recurring === void 0 ? void 0 : recurring.intervalCount.toString(), type: InputType.NUMBER, placeholder: "1", onChange: (value) => {
                    let valueNumber = value;
                    if (typeof valueNumber === Typeof.String) {
                        valueNumber = parseInt(valueNumber.toString());
                    }
                    let tempRecurring = recurring;
                    if (!tempRecurring) {
                        tempRecurring = new Recurring();
                    }
                    tempRecurring.intervalCount = new PositiveNumber(valueNumber);
                    updateRecurring(tempRecurring);
                } }),
            React.createElement(Dropdown, { value: DropdownUtil.getDropdownOptionFromEnumForValue(EventInterval, (recurring === null || recurring === void 0 ? void 0 : recurring.intervalType) || EventInterval.Day), options: DropdownUtil.getDropdownOptionsFromEnum(EventInterval), onChange: (value) => {
                    let tempRecurring = recurring;
                    if (!tempRecurring) {
                        tempRecurring = new Recurring();
                    }
                    tempRecurring.intervalType = value;
                    updateRecurring(tempRecurring);
                } })),
        props.error && (React.createElement("p", { "data-testid": "error-message", className: "mt-1 text-sm text-red-400" }, props.error))));
};
export default RecurringFieldElement;
//# sourceMappingURL=RecurringFieldElement.js.map