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_ahooks__ from "ahooks";
import * as __WEBPACK_EXTERNAL_MODULE_antd__ from "antd";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE_dayjs__ from "dayjs";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../../index.mjs";
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 = (0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])();
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        space: css(_templateObject())
    };
});
const DateFormatCom = (props)=>{
    const date = (0, __WEBPACK_EXTERNAL_MODULE_dayjs__["default"])();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)("div", {
        style: {
            display: 'inline-flex'
        },
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                children: props.format
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(DateTimeFormatPreview, {
                content: date.format(props.format)
            })
        ]
    });
};
const DateTimeFormatPreview = (param)=>{
    let { content } = param;
    const { token } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useToken)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.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, __WEBPACK_EXTERNAL_MODULE_ahooks__.useBoolean)(props.value && !formats.includes(props.value));
    const targetValue = props.value && !formats.includes(props.value) ? props.value : defaultValue;
    const [customFormatPreview, setCustomFormatPreview] = (0, __WEBPACK_EXTERNAL_MODULE_react__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
        className: styles.space,
        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Radio.Group, {
            value: isCustom ? 'custom' : props.value,
            onChange: onSelectChange,
            children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Space, {
                direction: "vertical",
                children: props.options.map((v)=>{
                    if ('custom' === v.value) return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Radio, {
                        value: v.value,
                        children: [
                            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(DateTimeFormatPreview, {
                                content: customFormatPreview
                            })
                        ]
                    }, v.value);
                    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Radio, {
                        value: v.value,
                        "aria-label": v.value,
                        children: /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)("span", {
                            role: "button",
                            "aria-label": v.value,
                            children: v.label
                        })
                    }, v.value);
                })
            })
        })
    });
};
const ExpiresRadio = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.connect)(InternalExpiresRadio, (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.mapProps)({
    dataSource: 'options'
}));
export { DateFormatCom, ExpiresRadio };
