"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__, {
    CronSet: ()=>CronSet
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const index_js_namespaceObject = require("../../../collection-manager/index.js");
const external_hooks_index_js_namespaceObject = require("../../hooks/index.js");
const external_input_index_js_namespaceObject = require("../input/index.js");
const external_Cron_js_namespaceObject = require("./Cron.js");
var external_Cron_js_default = /*#__PURE__*/ __webpack_require__.n(external_Cron_js_namespaceObject);
const CronSetInternal = (props)=>{
    var _getField;
    const { onChange, value } = props;
    const { getField } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const uiSchemaOptions = null === (_getField = getField(null == fieldSchema ? void 0 : fieldSchema.name)) || void 0 === _getField ? void 0 : _getField.uiSchema.enum;
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const [customizeOption, setCustomizeOption] = (0, external_react_namespaceObject.useState)({
        label: "{{t('Custom')}}",
        value: '@daily'
    });
    const options = (0, external_react_namespaceObject.useMemo)(()=>(props.options || []).concat(uiSchemaOptions || []).concat([
            customizeOption
        ]).map((item)=>({
                ...item,
                label: compile(item.label)
            })), [
        props.options,
        customizeOption
    ]);
    (0, external_react_namespaceObject.useEffect)(()=>{
        if (null == value) return;
        const item = options.find((o)=>o.value === value);
        if (!item) setCustomizeOption({
            ...customizeOption,
            value
        });
    }, [
        options,
        value
    ]);
    const isCustomize = (0, external_react_namespaceObject.useMemo)(()=>value === customizeOption.value, [
        value,
        customizeOption
    ]);
    const onCronChange = function(value) {
        let customize = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
        if (customize) setCustomizeOption({
            ...customizeOption,
            value
        });
        onChange(value);
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("fieldset", {
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select, {
                popupMatchSelectWidth: false,
                allowClear: true,
                ...props,
                value: value,
                options: options,
                onChange: (value)=>onCronChange(value)
            }),
            isCustomize ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_Cron_js_default(), {
                value: value,
                onChange: (v)=>onCronChange(v, true),
                allowedDropdowns: [
                    'period',
                    'week-days',
                    'months',
                    'month-days'
                ],
                allowedPeriods: [
                    'year',
                    'month',
                    'week',
                    'day'
                ]
            }) : null
        ]
    });
};
const ReadPretty = (props)=>{
    var _getField;
    const { value } = props;
    const compile = (0, external_hooks_index_js_namespaceObject.useCompile)();
    const fieldSchema = (0, schema_namespaceObject.useFieldSchema)();
    const { getField } = (0, index_js_namespaceObject.useCollection_deprecated)();
    const uiSchemaOptions = null === (_getField = getField(null == fieldSchema ? void 0 : fieldSchema.name)) || void 0 === _getField ? void 0 : _getField.uiSchema.enum;
    const options = (0, external_react_namespaceObject.useMemo)(()=>(props.options || []).concat(uiSchemaOptions || []), [
        props.options
    ]);
    const label = (0, external_react_namespaceObject.useMemo)(()=>{
        var _options_find;
        return value && (null == options ? void 0 : null === (_options_find = options.find((o)=>o.value === value)) || void 0 === _options_find ? void 0 : _options_find.label);
    }, [
        options,
        value
    ]);
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_input_index_js_namespaceObject.EllipsisWithTooltip, {
        ellipsis: true,
        children: value && (label ? compile(label) : /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_Cron_js_default().ReadPretty, {
            ...props
        }))
    });
};
const CronSet = (0, schema_namespaceObject.connect)(CronSetInternal, (0, schema_namespaceObject.mapReadPretty)(ReadPretty));
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
});
