"use strict";
var __webpack_require__ = {};
(()=>{
    __webpack_require__.n = function(module) {
        var getter = module && module.__esModule ? function() {
            return module['default'];
        } : function() {
            return module;
        };
        __webpack_require__.d(getter, {
            a: getter
        });
        return getter;
    };
})();
(()=>{
    __webpack_require__.d = function(exports1, definition) {
        for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
            enumerable: true,
            get: definition[key]
        });
    };
})();
(()=>{
    __webpack_require__.o = function(obj, prop) {
        return Object.prototype.hasOwnProperty.call(obj, prop);
    };
})();
(()=>{
    __webpack_require__.r = function(exports1) {
        if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
            value: 'Module'
        });
        Object.defineProperty(exports1, '__esModule', {
            value: true
        });
    };
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
    DatePicker: ()=>DatePicker,
    DatePickerProvider: ()=>DatePickerProvider,
    useDatePickerContext: ()=>useDatePickerContext,
    default: ()=>DatePicker_rslib_entry_
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
var external_react_default = /*#__PURE__*/ __webpack_require__.n(external_react_namespaceObject);
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_dayjs_namespaceObject = require("dayjs");
var external_dayjs_default = /*#__PURE__*/ __webpack_require__.n(external_dayjs_namespaceObject);
const external_react_i18next_namespaceObject = require("react-i18next");
const external_ReadPretty_js_namespaceObject = require("./ReadPretty.js");
const external_util_js_namespaceObject = require("./util.js");
const DatePickerContext = /*#__PURE__*/ external_react_default().createContext({
    utc: true
});
const useDatePickerContext = ()=>external_react_default().useContext(DatePickerContext);
const DatePickerProvider = DatePickerContext.Provider;
const InternalDatePicker = (0, schema_namespaceObject.connect)(external_antd_namespaceObject.DatePicker, (0, schema_namespaceObject.mapProps)((0, external_util_js_namespaceObject.mapDatePicker)()), (0, schema_namespaceObject.mapReadPretty)(external_ReadPretty_js_namespaceObject.ReadPretty.DatePicker));
const InternalRangePicker = (0, schema_namespaceObject.connect)(external_antd_namespaceObject.DatePicker.RangePicker, (0, schema_namespaceObject.mapProps)((0, external_util_js_namespaceObject.mapRangePicker)()), (0, schema_namespaceObject.mapReadPretty)(external_ReadPretty_js_namespaceObject.ReadPretty.DateRangePicker));
const DatePicker = (props)=>{
    const { utc = true } = useDatePickerContext();
    const value = Array.isArray(props.value) ? props.value[0] : props.value;
    props = {
        utc,
        ...props
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(InternalDatePicker, {
        ...props,
        value: value
    });
};
DatePicker.ReadPretty = external_ReadPretty_js_namespaceObject.ReadPretty.DatePicker;
DatePicker.RangePicker = function(props) {
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { utc = true } = useDatePickerContext();
    if ('range' === props.valueType) {
        const originOnChange = props.onChange;
        const originValue = props.value;
        props = {
            ...props
        };
        if (originValue) props.value = [
            originValue[0].value,
            external_dayjs_default()(originValue[1].value).add(-1, 'd').toISOString()
        ];
        props.onChange = (value)=>{
            if (!value || !value.length) {
                originOnChange(null);
                return;
            }
            originOnChange([
                {
                    value: external_dayjs_default()(value[0]).toISOString(),
                    inclusive: true
                },
                {
                    value: external_dayjs_default()(value[1]).add(1, 'd').toISOString(),
                    inclusive: false
                }
            ]);
        };
    }
    const rangesValue = (0, external_util_js_namespaceObject.getDateRanges)();
    const presets = [
        {
            label: t('Today'),
            value: rangesValue.today
        },
        {
            label: t('Last week'),
            value: rangesValue.lastWeek
        },
        {
            label: t('This week'),
            value: rangesValue.thisWeek
        },
        {
            label: t('Next week'),
            value: rangesValue.nextWeek
        },
        {
            label: t('Last month'),
            value: rangesValue.lastMonth
        },
        {
            label: t('This month'),
            value: rangesValue.thisMonth
        },
        {
            label: t('Next month'),
            value: rangesValue.nextMonth
        },
        {
            label: t('Last quarter'),
            value: rangesValue.lastQuarter
        },
        {
            label: t('This quarter'),
            value: rangesValue.thisQuarter
        },
        {
            label: t('Next quarter'),
            value: rangesValue.nextQuarter
        },
        {
            label: t('Last year'),
            value: rangesValue.lastYear
        },
        {
            label: t('This year'),
            value: rangesValue.thisYear
        },
        {
            label: t('Next year'),
            value: rangesValue.nextYear
        },
        {
            label: t('Last 7 days'),
            value: rangesValue.last7Days
        },
        {
            label: t('Next 7 days'),
            value: rangesValue.next7Days
        },
        {
            label: t('Last 30 days'),
            value: rangesValue.last30Days
        },
        {
            label: t('Next 30 days'),
            value: rangesValue.next30Days
        },
        {
            label: t('Last 90 days'),
            value: rangesValue.last90Days
        },
        {
            label: t('Next 90 days'),
            value: rangesValue.next90Days
        }
    ];
    props = {
        utc,
        presets,
        ...props
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(InternalRangePicker, {
        ...props
    });
};
const DatePicker_rslib_entry_ = DatePicker;
var __webpack_export_target__ = exports;
for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
    value: true
});
