"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__, {
    DateFormatCom: ()=>DateFormatCom,
    ExpiresRadio: ()=>ExpiresRadio
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
const external_react_namespaceObject = require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_ahooks_namespaceObject = require("ahooks");
const external_antd_namespaceObject = require("antd");
const external_antd_style_namespaceObject = require("antd-style");
const external_dayjs_namespaceObject = require("dayjs");
var external_dayjs_default = /*#__PURE__*/ __webpack_require__.n(external_dayjs_namespaceObject);
const external_index_js_namespaceObject = require("../../index.js");
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      width: 100%;\n      & > .ant-space-item {\n        flex: 1;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
const ExpiresRadio_rslib_entry_date = external_dayjs_default()();
const useStyles = (0, external_antd_style_namespaceObject.createStyles)((param)=>{
    let { css } = param;
    return {
        space: css(_templateObject())
    };
});
const DateFormatCom = (props)=>{
    const date = external_dayjs_default()();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)("div", {
        style: {
            display: 'inline-flex'
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                children: props.format
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(DateTimeFormatPreview, {
                content: date.format(props.format)
            })
        ]
    });
};
const DateTimeFormatPreview = (param)=>{
    let { content } = param;
    const { token } = (0, external_index_js_namespaceObject.useToken)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
        style: {
            display: 'inline-block',
            background: token.colorBgTextHover,
            marginLeft: token.marginMD,
            lineHeight: '1',
            padding: token.paddingXXS,
            borderRadius: token.borderRadiusOuter
        },
        children: content
    });
};
const InternalExpiresRadio = (props)=>{
    const { styles } = useStyles();
    const { onChange, defaultValue, formats, timeFormat } = props;
    const [isCustom, { setFalse, setTrue }] = (0, external_ahooks_namespaceObject.useBoolean)(props.value && !formats.includes(props.value));
    const targetValue = props.value && !formats.includes(props.value) ? props.value : defaultValue;
    const [customFormatPreview, setCustomFormatPreview] = (0, external_react_namespaceObject.useState)(targetValue ? ExpiresRadio_rslib_entry_date.format(targetValue) : null);
    const onSelectChange = (v)=>{
        if ('custom' === v.target.value) {
            setTrue();
            onChange(targetValue);
        } else {
            setFalse();
            onChange(v.target.value);
        }
    };
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
        className: styles.space,
        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Radio.Group, {
            value: isCustom ? 'custom' : props.value,
            onChange: onSelectChange,
            children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Space, {
                direction: "vertical",
                children: props.options.map((v)=>{
                    if ('custom' === v.value) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Radio, {
                        value: v.value,
                        children: [
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Input, {
                                style: {
                                    width: '150px'
                                },
                                defaultValue: targetValue,
                                onChange: (e)=>{
                                    e.target.value ? setCustomFormatPreview(ExpiresRadio_rslib_entry_date.format(e.target.value)) : setCustomFormatPreview(null);
                                    if (isCustom) onChange(e.target.value);
                                }
                            }),
                            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(DateTimeFormatPreview, {
                                content: customFormatPreview
                            })
                        ]
                    }, v.value);
                    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Radio, {
                        value: v.value,
                        "aria-label": v.value,
                        children: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)("span", {
                            role: "button",
                            "aria-label": v.value,
                            children: v.label
                        })
                    }, v.value);
                })
            })
        })
    });
};
const ExpiresRadio = (0, schema_namespaceObject.connect)(InternalExpiresRadio, (0, schema_namespaceObject.mapProps)({
    dataSource: 'options'
}));
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
});
