"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    getDateRanges: ()=>getDateRanges,
    mapDatePicker: ()=>mapDatePicker,
    mapRangePicker: ()=>mapRangePicker,
    moment2str: ()=>moment2str
});
const client_namespaceObject = require("@tachybase/utils/client");
const toStringByPicker = (value, picker, timezone)=>{
    if (!client_namespaceObject.dayjs.isDayjs(value)) return value;
    if ('local' === timezone) {
        const offset = new Date().getTimezoneOffset();
        return (0, client_namespaceObject.dayjs)(toStringByPicker(value, picker, 'gmt')).add(offset, 'minutes').toISOString();
    }
    if ('year' === picker) return value.format('YYYY') + '-01-01T00:00:00.000Z';
    if ('month' === picker) return value.format('YYYY-MM') + '-01T00:00:00.000Z';
    if ('quarter' === picker) return value.startOf('quarter').format('YYYY-MM') + '-01T00:00:00.000Z';
    if ('week' === picker) return value.startOf('week').add(1, 'day').format('YYYY-MM-DD') + 'T00:00:00.000Z';
    return value.format('YYYY-MM-DDTHH:mm:ss.SSS') + 'Z';
};
const toGmtByPicker = (value, picker)=>{
    if (!value || !client_namespaceObject.dayjs.isDayjs(value)) return value;
    return toStringByPicker(value, picker, 'gmt');
};
const toLocalByPicker = (value, picker)=>{
    if (!value || !client_namespaceObject.dayjs.isDayjs(value)) return value;
    return toStringByPicker(value, picker, 'local');
};
const moment2str = function(value) {
    let options = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
    const { showTime, gmt, picker, utc = true } = options;
    if (!value) return value;
    if (!utc) {
        const format = showTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD';
        return value.format(format);
    }
    if (showTime) return gmt ? (0, client_namespaceObject.toGmt)(value) : (0, client_namespaceObject.toLocal)(value);
    if ('boolean' == typeof gmt) return gmt ? toGmtByPicker(value, picker) : toLocalByPicker(value, picker);
    return toGmtByPicker(value, picker);
};
const mapDatePicker = function() {
    return (props)=>{
        const format = (0, client_namespaceObject.getDefaultFormat)(props);
        const onChange = props.onChange;
        return {
            ...props,
            format: format,
            value: (0, client_namespaceObject.str2moment)(props.value, props),
            onChange: (value)=>{
                if (onChange) {
                    if (!props.showTime && value) value = value.startOf('day');
                    onChange(moment2str(value, props));
                }
            }
        };
    };
};
const mapRangePicker = function() {
    return (props)=>{
        const format = (0, client_namespaceObject.getDefaultFormat)(props);
        const onChange = props.onChange;
        return {
            ...props,
            format: format,
            value: (0, client_namespaceObject.str2moment)(props.value, props),
            onChange: (value)=>{
                if (onChange) onChange(value ? [
                    moment2str(getRangeStart(value[0], props), props),
                    moment2str(getRangeEnd(value[1], props), props)
                ] : []);
            }
        };
    };
};
function getRangeStart(value, options) {
    const { showTime } = options;
    if (showTime) return value;
    return value.startOf('day');
}
function getRangeEnd(value, options) {
    const { showTime } = options;
    if (showTime) return value;
    return value.endOf('day');
}
const getStart = (offset, unit)=>(0, client_namespaceObject.dayjs)().add(offset, 'isoWeek' === unit ? 'week' : unit).startOf(unit);
const getEnd = (offset, unit)=>(0, client_namespaceObject.dayjs)().add(offset, 'isoWeek' === unit ? 'week' : unit).endOf(unit);
const getDateRanges = ()=>({
        now: ()=>(0, client_namespaceObject.dayjs)().toISOString(),
        today: ()=>[
                getStart(0, 'day'),
                getEnd(0, 'day')
            ],
        yesterday: ()=>[
                getStart(-1, 'day'),
                getEnd(-1, 'day')
            ],
        tomorrow: ()=>[
                getStart(1, 'day'),
                getEnd(1, 'day')
            ],
        thisWeek: ()=>[
                getStart(0, 'isoWeek'),
                getEnd(0, 'isoWeek')
            ],
        lastWeek: ()=>[
                getStart(-1, 'isoWeek'),
                getEnd(-1, 'isoWeek')
            ],
        nextWeek: ()=>[
                getStart(1, 'isoWeek'),
                getEnd(1, 'isoWeek')
            ],
        thisIsoWeek: ()=>[
                getStart(0, 'isoWeek'),
                getEnd(0, 'isoWeek')
            ],
        lastIsoWeek: ()=>[
                getStart(-1, 'isoWeek'),
                getEnd(-1, 'isoWeek')
            ],
        nextIsoWeek: ()=>[
                getStart(1, 'isoWeek'),
                getEnd(1, 'isoWeek')
            ],
        thisMonth: ()=>[
                getStart(0, 'month'),
                getEnd(0, 'month')
            ],
        lastMonth: ()=>[
                getStart(-1, 'month'),
                getEnd(-1, 'month')
            ],
        nextMonth: ()=>[
                getStart(1, 'month'),
                getEnd(1, 'month')
            ],
        thisQuarter: ()=>[
                getStart(0, 'quarter'),
                getEnd(0, 'quarter')
            ],
        lastQuarter: ()=>[
                getStart(-1, 'quarter'),
                getEnd(-1, 'quarter')
            ],
        nextQuarter: ()=>[
                getStart(1, 'quarter'),
                getEnd(1, 'quarter')
            ],
        thisYear: ()=>[
                getStart(0, 'year'),
                getEnd(0, 'year')
            ],
        lastYear: ()=>[
                getStart(-1, 'year'),
                getEnd(-1, 'year')
            ],
        nextYear: ()=>[
                getStart(1, 'year'),
                getEnd(1, 'year')
            ],
        last7Days: ()=>[
                getStart(-6, 'days'),
                getEnd(0, 'days')
            ],
        next7Days: ()=>[
                getStart(1, 'day'),
                getEnd(7, 'days')
            ],
        last30Days: ()=>[
                getStart(-29, 'days'),
                getEnd(0, 'days')
            ],
        next30Days: ()=>[
                getStart(1, 'day'),
                getEnd(30, 'days')
            ],
        last90Days: ()=>[
                getStart(-89, 'days'),
                getEnd(0, 'days')
            ],
        next90Days: ()=>[
                getStart(1, 'day'),
                getEnd(90, 'days')
            ]
    });
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
});
