import { useMemo } from "react";
import { useTranslation } from "react-i18next";
import { datetime } from "../../../collection-manager/interfaces/properties/operators.mjs";
import { useFlag } from "../../../flag-provider/index.mjs";
import { getDateExact } from "../../../schema-component/antd/date-picker/util.mjs";
const useExactDateVariableContext = ()=>{
    const exactDateTimeCtx = useMemo(()=>getDateExact(), []);
    return {
        exactDateTimeCtx
    };
};
const useExactDateVariable = function() {
    let { schema, targetFieldSchema } = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : {};
    var _collectionField_uiSchema;
    const { collectionField } = useFlag();
    const { dateOnly, utc, accuracy, picker } = (null == collectionField ? void 0 : null == (_collectionField_uiSchema = collectionField.uiSchema) ? void 0 : _collectionField_uiSchema['x-component-props']) || {};
    const { t } = useTranslation();
    const exactDateTimeSettings = useMemo(()=>{
        const getDateKeys = (key)=>{
            if (!picker) {
                if ('now' === key) return 'nowLocal';
                if ('today' === key) return 'todayDate';
                if ('yesterday' === key) return 'yesterdayDate';
                if ('tomorrow' === key) return 'tomorrowDate';
            }
            if (dateOnly) {
                if ('now' === key) return null;
                return "".concat(key, "Date");
            }
            return "".concat(key).concat(utc || accuracy ? 'Utc' : 'Local');
        };
        const dateOptions = [
            {
                key: 'now',
                value: getDateKeys('now'),
                label: t('Now'),
                operators: datetime
            },
            {
                key: 'today',
                value: getDateKeys('today'),
                label: t('Today'),
                operators: datetime
            },
            {
                key: 'yesterday',
                value: getDateKeys('yesterday'),
                label: t('Yesterday'),
                operators: datetime
            },
            {
                key: 'tomorrow',
                value: getDateKeys('tomorrow'),
                label: t('Tomorrow'),
                operators: datetime
            }
        ].filter((v)=>v.value);
        return {
            label: t('Date variables'),
            value: '$nExactDate',
            key: '$nExactDate',
            children: dateOptions
        };
    }, [
        null == schema ? void 0 : schema['x-component'],
        targetFieldSchema
    ]);
    const { exactDateTimeCtx } = useExactDateVariableContext();
    return {
        exactDateTimeSettings,
        exactDateTimeCtx,
        shouldDisplayExactDate: !!collectionField
    };
};
export { useExactDateVariable, useExactDateVariableContext };
