import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_dayjs__ from "dayjs";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__ReadPretty_mjs__ from "./ReadPretty.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__util_mjs__ from "./util.mjs";
const DatePickerContext = /*#__PURE__*/ __WEBPACK_EXTERNAL_MODULE_react__["default"].createContext({
    utc: true
});
const useDatePickerContext = ()=>__WEBPACK_EXTERNAL_MODULE_react__["default"].useContext(DatePickerContext);
const DatePickerProvider = DatePickerContext.Provider;
const InternalDatePicker = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)(__WEBPACK_EXTERNAL_MODULE_antd__.DatePicker, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapProps)((0, __WEBPACK_EXTERNAL_MODULE__util_mjs__.mapDatePicker)()), (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)(__WEBPACK_EXTERNAL_MODULE__ReadPretty_mjs__.ReadPretty.DatePicker));
const InternalRangePicker = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)(__WEBPACK_EXTERNAL_MODULE_antd__.DatePicker.RangePicker, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapProps)((0, __WEBPACK_EXTERNAL_MODULE__util_mjs__.mapRangePicker)()), (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)(__WEBPACK_EXTERNAL_MODULE__ReadPretty_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(InternalDatePicker, {
        ...props,
        value: value
    });
};
DatePicker.ReadPretty = __WEBPACK_EXTERNAL_MODULE__ReadPretty_mjs__.ReadPretty.DatePicker;
DatePicker.RangePicker = function(props) {
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.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,
            (0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])(originValue[1].value).add(-1, 'd').toISOString()
        ];
        props.onChange = (value)=>{
            if (!value || !value.length) {
                originOnChange(null);
                return;
            }
            originOnChange([
                {
                    value: (0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])(value[0]).toISOString(),
                    inclusive: true
                },
                {
                    value: (0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])(value[1]).add(1, 'd').toISOString(),
                    inclusive: false
                }
            ]);
        };
    }
    const rangesValue = (0, __WEBPACK_EXTERNAL_MODULE__util_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(InternalRangePicker, {
        ...props
    });
};
const DatePicker_rslib_entry_ = DatePicker;
export { DatePicker, DatePickerProvider, DatePicker_rslib_entry_ as default, useDatePickerContext };
