import * as __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__ from "react/jsx-runtime";
import "react";
import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE_antd_style__ from "antd-style";
import * as __WEBPACK_EXTERNAL_MODULE_react_i18next__ from "react-i18next";
import * as __WEBPACK_EXTERNAL_MODULE__index_mjs__ from "../index.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__ from "./DateFormat/ExpiresRadio.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__ from "./SchemaSettings.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      .ant-radio-wrapper {\n        display: flex;\n        margin: 5px 0px;\n      }\n    "
    ]);
    _templateObject = function() {
        return data;
    };
    return data;
}
function _templateObject1() {
    const data = _tagged_template_literal([
        "\n      margin-bottom: 0px;\n    "
    ]);
    _templateObject1 = function() {
        return data;
    };
    return data;
}
function _templateObject2() {
    const data = _tagged_template_literal([
        "\n      color: red;\n      .ant-radio-wrapper {\n        display: flex;\n        margin: 5px 0px;\n      }\n    "
    ]);
    _templateObject2 = function() {
        return data;
    };
    return data;
}
const useStyles = (0, __WEBPACK_EXTERNAL_MODULE_antd_style__.createStyles)((param)=>{
    let { css } = param;
    return {
        radio: css(_templateObject()),
        margin: css(_templateObject1()),
        redRadio: css(_templateObject2())
    };
});
const SchemaSettingsDateFormat = function(props) {
    var _fieldSchema_xcomponentprops, _fieldSchema_xcomponentprops1, _collectionField_uiSchema_xcomponentprops, _collectionField_uiSchema, _fieldSchema_xcomponentprops2, _collectionField_uiSchema_xcomponentprops1, _collectionField_uiSchema1, _collectionField_uiSchema_xcomponentprops2, _collectionField_uiSchema2;
    const { styles } = useStyles();
    const { fieldSchema } = props;
    const field = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useField)();
    const { dn } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useDesignable)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    const { getCollectionJoinField } = (0, __WEBPACK_EXTERNAL_MODULE__index_mjs__.useCollectionManager_deprecated)();
    const collectionField = getCollectionJoinField(null == fieldSchema ? void 0 : fieldSchema['x-collection-field']) || {};
    const isShowTime = null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops ? void 0 : _fieldSchema_xcomponentprops.showTime;
    const dateFormatDefaultValue = (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops1 = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops1 ? void 0 : _fieldSchema_xcomponentprops1.dateFormat) || (null == collectionField ? void 0 : null === (_collectionField_uiSchema = collectionField.uiSchema) || void 0 === _collectionField_uiSchema ? void 0 : null === (_collectionField_uiSchema_xcomponentprops = _collectionField_uiSchema['x-component-props']) || void 0 === _collectionField_uiSchema_xcomponentprops ? void 0 : _collectionField_uiSchema_xcomponentprops.dateFormat) || 'YYYY-MM-DD';
    const timeFormatDefaultValue = (null == fieldSchema ? void 0 : null === (_fieldSchema_xcomponentprops2 = fieldSchema['x-component-props']) || void 0 === _fieldSchema_xcomponentprops2 ? void 0 : _fieldSchema_xcomponentprops2.timeFormat) || (null == collectionField ? void 0 : null === (_collectionField_uiSchema1 = collectionField.uiSchema) || void 0 === _collectionField_uiSchema1 ? void 0 : null === (_collectionField_uiSchema_xcomponentprops1 = _collectionField_uiSchema1['x-component-props']) || void 0 === _collectionField_uiSchema_xcomponentprops1 ? void 0 : _collectionField_uiSchema_xcomponentprops1.timeFormat) || 'HH:mm:ss';
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__.SchemaSettingsModalItem, {
        title: t('Date display format'),
        schema: {
            type: 'object',
            properties: {
                dateFormat: {
                    type: 'string',
                    title: '{{t("Date format")}}',
                    'x-component': __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.ExpiresRadio,
                    'x-decorator': 'FormItem',
                    'x-decorator-props': {},
                    'x-component-props': {
                        className: styles.radio,
                        defaultValue: 'dddd',
                        formats: [
                            'MMMM Do YYYY',
                            'YYYY-MM-DD',
                            'MM/DD/YY',
                            'YYYY/MM/DD',
                            'DD/MM/YYYY'
                        ]
                    },
                    default: dateFormatDefaultValue,
                    enum: [
                        {
                            label: (0, __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.DateFormatCom)({
                                format: 'MMMM Do YYYY'
                            }),
                            value: 'MMMM Do YYYY'
                        },
                        {
                            label: (0, __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.DateFormatCom)({
                                format: 'YYYY-MM-DD'
                            }),
                            value: 'YYYY-MM-DD'
                        },
                        {
                            label: (0, __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.DateFormatCom)({
                                format: 'MM/DD/YY'
                            }),
                            value: 'MM/DD/YY'
                        },
                        {
                            label: (0, __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.DateFormatCom)({
                                format: 'YYYY/MM/DD'
                            }),
                            value: 'YYYY/MM/DD'
                        },
                        {
                            label: (0, __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.DateFormatCom)({
                                format: 'DD/MM/YYYY'
                            }),
                            value: 'DD/MM/YYYY'
                        },
                        {
                            label: 'custom',
                            value: 'custom'
                        }
                    ]
                },
                showTime: {
                    default: void 0 === isShowTime ? null == collectionField ? void 0 : null === (_collectionField_uiSchema2 = collectionField.uiSchema) || void 0 === _collectionField_uiSchema2 ? void 0 : null === (_collectionField_uiSchema_xcomponentprops2 = _collectionField_uiSchema2['x-component-props']) || void 0 === _collectionField_uiSchema_xcomponentprops2 ? void 0 : _collectionField_uiSchema_xcomponentprops2.showTime : isShowTime,
                    type: 'boolean',
                    'x-decorator': 'FormItem',
                    'x-component': 'Checkbox',
                    'x-content': '{{t("Show time")}}',
                    'x-reactions': [
                        "{{(field) => {\n              field.query('.timeFormat').take(f => {\n                f.display = field.value ? 'visible' : 'none';\n              });\n            }}}"
                    ]
                },
                timeFormat: {
                    type: 'string',
                    title: '{{t("Time format")}}',
                    'x-component': __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.ExpiresRadio,
                    'x-decorator': 'FormItem',
                    'x-decorator-props': {
                        className: styles.margin
                    },
                    'x-component-props': {
                        className: styles.redRadio,
                        defaultValue: 'h:mm a',
                        formats: [
                            'hh:mm:ss a',
                            'HH:mm:ss'
                        ],
                        timeFormat: true
                    },
                    default: timeFormatDefaultValue,
                    enum: [
                        {
                            label: (0, __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.DateFormatCom)({
                                format: 'hh:mm:ss a'
                            }),
                            value: 'hh:mm:ss a'
                        },
                        {
                            label: (0, __WEBPACK_EXTERNAL_MODULE__DateFormat_ExpiresRadio_mjs__.DateFormatCom)({
                                format: 'HH:mm:ss'
                            }),
                            value: 'HH:mm:ss'
                        },
                        {
                            label: 'custom',
                            value: 'custom'
                        }
                    ]
                }
            }
        },
        onSubmit: (data)=>{
            const schema = {
                ['x-uid']: fieldSchema['x-uid']
            };
            schema['x-component-props'] = fieldSchema['x-component-props'] || {};
            fieldSchema['x-component-props'] = {
                ...fieldSchema['x-component-props'] || {},
                ...data
            };
            schema['x-component-props'] = fieldSchema['x-component-props'];
            field.componentProps = fieldSchema['x-component-props'];
            const parts = field.path.entire.split('.');
            parts.pop();
            const modifiedString = parts.join('.');
            field.query("".concat(modifiedString, ".*[0:].").concat(fieldSchema.name)).forEach((f)=>{
                if (f.props.name === fieldSchema.name) f.setComponentProps({
                    ...data
                });
            });
            dn.emit('patch', {
                schema
            });
            dn.refresh();
        }
    });
};
export { SchemaSettingsDateFormat };
