/**
 * DevExtreme (esm/renovation/ui/scheduler/appointment_edit_form/edit_form/layout.js)
 * Version: 22.2.7 (build 23185-0311)
 * Build date: Tue Jul 04 2023
 *
 * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _extends from "@babel/runtime/helpers/esm/extends";
var _excluded = ["allDayEditorTemplate", "allowTimeZoneEditing", "allowUpdating", "appointmentData", "dataAccessors", "descriptionEditorTemplate", "endDateEditorTemplate", "firstDayOfWeek", "repeatEditorTemplate", "startDateEditorTemplate", "timeZoneEditorTemplate"];
import {
    createComponentVNode,
    normalizeProps
} from "inferno";
import {
    InfernoEffect,
    InfernoComponent
} from "@devextreme/runtime/inferno";
import {
    Form
} from "../../../form/wrapper/form";
import {
    getFormLayoutConfig
} from "./layout_items/formLayout";
import {
    FormContext
} from "../../form_context";
import {
    StartDateEditor
} from "./editors/startDateEditor";
import {
    EndDateEditor
} from "./editors/endDateEditor";
import {
    TimeZoneEditor
} from "./editors/timeZoneEditor";
import {
    SwitchEditor
} from "./editors/switchEditor";
import {
    DescriptionEditor
} from "./editors/descriptionEditor";
var FormColCount = {
    lg: 2,
    xs: 1
};
export var viewFunction = _ref => {
    var {
        formContextValue: formContextValue,
        formItems: formItems
    } = _ref;
    return createComponentVNode(2, Form, {
        formData: formContextValue.formData,
        items: formItems,
        showValidationSummary: true,
        scrollingEnabled: true,
        colCountByScreen: FormColCount,
        showColonAfterLabel: false,
        colCount: "auto",
        labelLocation: "top"
    })
};
export var EditFormProps = {
    startDateEditorTemplate: StartDateEditor,
    endDateEditorTemplate: EndDateEditor,
    timeZoneEditorTemplate: TimeZoneEditor,
    allDayEditorTemplate: SwitchEditor,
    repeatEditorTemplate: SwitchEditor,
    descriptionEditorTemplate: DescriptionEditor
};
import {
    convertRulesToOptions
} from "../../../../../core/options/utils";
var getTemplate = TemplateProp => TemplateProp && (TemplateProp.defaultProps ? props => normalizeProps(createComponentVNode(2, TemplateProp, _extends({}, props))) : TemplateProp);
export class EditForm extends InfernoComponent {
    constructor(props) {
        super(props);
        this.__getterCache = {};
        this.state = {
            isAllDay: void 0
        };
        this.updateState = this.updateState.bind(this);
        this.startDateChange = this.startDateChange.bind(this);
        this.endDateChange = this.endDateChange.bind(this);
        this.startDateTimeZoneChange = this.startDateTimeZoneChange.bind(this);
        this.endDateTimeZoneChange = this.endDateTimeZoneChange.bind(this);
        this.allDayChange = this.allDayChange.bind(this);
        this.repeatChange = this.repeatChange.bind(this);
        this.descriptionChange = this.descriptionChange.bind(this)
    }
    get formContextValue() {
        if (this.context[FormContext.id]) {
            return this.context[FormContext.id]
        }
        return FormContext.defaultValue
    }
    createEffects() {
        return [new InfernoEffect(this.updateState, [])]
    }
    updateState() {
        if (void 0 === this.state.isAllDay) {
            this.setState(__state_argument => ({
                isAllDay: !!this.formContextValue.formData.allDay
            }))
        }
    }
    startDateChange(date) {
        this.formContextValue.formData.startDate = date
    }
    endDateChange(date) {
        this.formContextValue.formData.endDate = date
    }
    startDateTimeZoneChange(timeZone) {
        this.formContextValue.formData.startDateTimeZone = timeZone
    }
    endDateTimeZoneChange(timeZone) {
        this.formContextValue.formData.endDateTimeZone = timeZone
    }
    allDayChange(value) {
        this.setState(__state_argument => ({
            isAllDay: value
        }));
        this.formContextValue.formData.allDay = value
    }
    repeatChange(value) {
        this.formContextValue.formData.repeat = value
    }
    descriptionChange(value) {
        this.formContextValue.formData.description = value
    }
    get formItems() {
        if (void 0 !== this.__getterCache.formItems) {
            return this.__getterCache.formItems
        }
        return this.__getterCache.formItems = (() => {
            var {
                formData: formData
            } = this.formContextValue;
            var StartDateTemplate = this.props.startDateEditorTemplate;
            var EndDateTemplate = this.props.endDateEditorTemplate;
            var TimeZoneTemplate = this.props.timeZoneEditorTemplate;
            var AllDayTemplate = this.props.allDayEditorTemplate;
            var RepeatTemplate = this.props.repeatEditorTemplate;
            var DescriptionTemplate = this.props.descriptionEditorTemplate;
            var {
                recurrenceRule: recurrenceRule
            } = this.formContextValue.formData;
            var isRecurrence = !!recurrenceRule;
            var {
                appointmentData: appointmentData
            } = this.props;
            var {
                firstDayOfWeek: firstDayOfWeek
            } = this.props;
            var {
                endDateTimeZone: endDateTimeZone,
                startDateTimeZone: startDateTimeZone
            } = appointmentData;
            var allDay = !!this.state.isAllDay;
            return getFormLayoutConfig(this.props.dataAccessors.expr, formData, this.props.allowTimeZoneEditing, createComponentVNode(2, StartDateTemplate, {
                value: appointmentData.startDate,
                dateChange: this.startDateChange,
                startDate: formData.startDate,
                endDate: formData.endDate,
                firstDayOfWeek: firstDayOfWeek,
                isAllDay: allDay
            }), createComponentVNode(2, EndDateTemplate, {
                value: this.props.appointmentData.endDate,
                dateChange: this.endDateChange,
                startDate: formData.startDate,
                endDate: formData.endDate,
                firstDayOfWeek: this.props.firstDayOfWeek,
                isAllDay: allDay
            }), createComponentVNode(2, TimeZoneTemplate, {
                value: startDateTimeZone,
                valueChange: this.startDateTimeZoneChange,
                date: this.props.appointmentData.startDate
            }), createComponentVNode(2, TimeZoneTemplate, {
                value: endDateTimeZone,
                valueChange: this.endDateTimeZoneChange,
                date: this.props.appointmentData.endDate
            }), createComponentVNode(2, AllDayTemplate, {
                value: allDay,
                valueChange: this.allDayChange
            }), createComponentVNode(2, RepeatTemplate, {
                value: isRecurrence,
                valueChange: this.repeatChange
            }), createComponentVNode(2, DescriptionTemplate, {
                value: this.props.appointmentData.description,
                valueChange: this.descriptionChange
            }))
        })()
    }
    get restAttributes() {
        var _this$props = this.props,
            restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
        return restProps
    }
    componentWillUpdate(nextProps, nextState, context) {
        super.componentWillUpdate();
        if (this.context[FormContext.id] !== context[FormContext.id] || this.props.startDateEditorTemplate !== nextProps.startDateEditorTemplate || this.props.endDateEditorTemplate !== nextProps.endDateEditorTemplate || this.props.timeZoneEditorTemplate !== nextProps.timeZoneEditorTemplate || this.props.allDayEditorTemplate !== nextProps.allDayEditorTemplate || this.props.repeatEditorTemplate !== nextProps.repeatEditorTemplate || this.props.descriptionEditorTemplate !== nextProps.descriptionEditorTemplate || this.props.appointmentData !== nextProps.appointmentData || this.props.firstDayOfWeek !== nextProps.firstDayOfWeek || this.state.isAllDay !== nextState.isAllDay || this.props.dataAccessors !== nextProps.dataAccessors || this.props.allowTimeZoneEditing !== nextProps.allowTimeZoneEditing) {
            this.__getterCache.formItems = void 0
        }
    }
    render() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props, {
                startDateEditorTemplate: getTemplate(props.startDateEditorTemplate),
                endDateEditorTemplate: getTemplate(props.endDateEditorTemplate),
                timeZoneEditorTemplate: getTemplate(props.timeZoneEditorTemplate),
                allDayEditorTemplate: getTemplate(props.allDayEditorTemplate),
                repeatEditorTemplate: getTemplate(props.repeatEditorTemplate),
                descriptionEditorTemplate: getTemplate(props.descriptionEditorTemplate)
            }),
            isAllDay: this.state.isAllDay,
            formContextValue: this.formContextValue,
            startDateChange: this.startDateChange,
            endDateChange: this.endDateChange,
            startDateTimeZoneChange: this.startDateTimeZoneChange,
            endDateTimeZoneChange: this.endDateTimeZoneChange,
            allDayChange: this.allDayChange,
            repeatChange: this.repeatChange,
            descriptionChange: this.descriptionChange,
            formItems: this.formItems,
            restAttributes: this.restAttributes
        })
    }
}
EditForm.defaultProps = EditFormProps;
var __defaultOptionRules = [];
export function defaultOptions(rule) {
    __defaultOptionRules.push(rule);
    EditForm.defaultProps = Object.create(Object.prototype, _extends(Object.getOwnPropertyDescriptors(EditForm.defaultProps), Object.getOwnPropertyDescriptors(convertRulesToOptions(__defaultOptionRules))))
}
