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__tachybase_utils_client__ from "@tachybase/utils/client";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE_cronstrue__ from "cronstrue";
import * as __WEBPACK_EXTERNAL_MODULE_react_js_cron__ from "react-js-cron";
import * as __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__ from "../../../api-client/index.mjs";
import "react-js-cron/dist/styles.css";
function _tagged_template_literal(strings, raw) {
    if (!raw) raw = strings.slice(0);
    return Object.freeze(Object.defineProperties(strings, {
        raw: {
            value: Object.freeze(raw)
        }
    }));
}
function _templateObject() {
    const data = _tagged_template_literal([
        "\n      .react-js-cron {\n        padding: 0.5em 0.5em 0 0.5em;\n        border: 1px dashed #ccc;\n        .react-js-cron-field {\n          flex-shrink: 0;\n          margin-bottom: 0.5em;\n\n          > span {\n            flex-shrink: 0;\n            margin: 0 0.5em 0 0;\n          }\n\n          > .react-js-cron-select {\n            margin: 0 0.5em 0 0;\n          }\n        }\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        input: css(_templateObject())
    };
});
const Input = (props)=>{
    const { onChange, ...rest } = props;
    const { styles } = useStyles();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("fieldset", {
        className: styles.input,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_react_js_cron__.Cron, {
            setValue: onChange,
            locale: window['cronLocale'],
            ...rest
        })
    });
};
const ReadPretty = (props)=>{
    const api = (0, __WEBPACK_EXTERNAL_MODULE__api_client_index_mjs__.useAPIClient)();
    const locale = api.auth.getLocale();
    const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
        try {
            return __WEBPACK_EXTERNAL_MODULE_cronstrue__["default"].toString(props.value, {
                locale,
                use24HourTimeFormat: true
            });
        } catch  {
            (0, __WEBPACK_EXTERNAL_MODULE__tachybase_utils_client__.error)("The '".concat(props.value, "' is not a valid cron expression"));
            return props.value;
        }
    }, [
        props.value
    ]);
    return props.value ? /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
        children: value
    }) : null;
};
const Cron = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)(Input, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapReadPretty)(ReadPretty));
Cron.ReadPretty = ReadPretty;
const Cron_rslib_entry_ = Cron;
export { Cron, Cron_rslib_entry_ as default };
