/**
 * DevExtreme (esm/renovation/ui/scheduler/appointment_edit_form/edit_form/editors/dateEditor.js)
 * Version: 23.1.6 (build 23316-0110)
 * Build date: Sun Nov 12 2023
 *
 * Copyright (c) 2012 - 2023 Developer Express Inc. ALL RIGHTS RESERVED
 * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
 */
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
var _excluded = ["disabled", "firstDayOfWeek", "isAllDay", "value", "valueChange"];
import {
    createComponentVNode
} from "inferno";
import {
    InfernoEffect,
    InfernoComponent
} from "@devextreme/runtime/inferno";
import {
    DateBox
} from "../../../../editors/drop_down_editors/date_box";
import {
    getFirstDayOfWeek
} from "../../utils";
export var viewFunction = _ref => {
    var {
        calendarOptions: calendarOptions,
        date: date,
        props: {
            disabled: disabled
        },
        type: type,
        updateDate: updateDate
    } = _ref;
    return createComponentVNode(2, DateBox, {
        width: "100%",
        useMaskBehavior: true,
        value: date,
        valueChange: updateDate,
        type: type,
        calendarOptions: calendarOptions,
        disabled: disabled
    })
};
export var DateEditorProps = {};
import {
    convertRulesToOptions
} from "../../../../../../core/options/utils";
export class DateEditor extends InfernoComponent {
    constructor(props) {
        super(props);
        this.__getterCache = {};
        this.state = {
            date: void 0
        };
        this.initDate = this.initDate.bind(this);
        this.updateDate = this.updateDate.bind(this)
    }
    createEffects() {
        return [new InfernoEffect(this.initDate, [])]
    }
    initDate() {
        if (!this.state.date) {
            this.setState(__state_argument => ({
                date: this.props.value
            }))
        }
    }
    updateDate(date) {
        this.setState(__state_argument => ({
            date: this.props.valueChange(date)
        }))
    }
    get calendarOptions() {
        if (void 0 !== this.__getterCache.calendarOptions) {
            return this.__getterCache.calendarOptions
        }
        return this.__getterCache.calendarOptions = (() => ({
            firstDayOfWeek: getFirstDayOfWeek(this.props.firstDayOfWeek)
        }))()
    }
    get type() {
        return this.props.isAllDay ? "date" : "datetime"
    }
    get restAttributes() {
        var _this$props = this.props,
            restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
        return restProps
    }
    componentWillUpdate(nextProps, nextState, context) {
        super.componentWillUpdate();
        if (this.props.firstDayOfWeek !== nextProps.firstDayOfWeek) {
            this.__getterCache.calendarOptions = void 0
        }
    }
    render() {
        var props = this.props;
        return viewFunction({
            props: _extends({}, props),
            date: this.state.date,
            updateDate: this.updateDate,
            calendarOptions: this.calendarOptions,
            type: this.type,
            restAttributes: this.restAttributes
        })
    }
}
DateEditor.defaultProps = DateEditorProps;
var __defaultOptionRules = [];
export function defaultOptions(rule) {
    __defaultOptionRules.push(rule);
    DateEditor.defaultProps = Object.create(Object.prototype, _extends(Object.getOwnPropertyDescriptors(DateEditor.defaultProps), Object.getOwnPropertyDescriptors(convertRulesToOptions(__defaultOptionRules))))
}
