"use strict";
var __webpack_require__ = {};
(()=>{
    __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__, {
    SchemaSettingsNumberFormat: ()=>SchemaSettingsNumberFormat
});
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
require("react");
const schema_namespaceObject = require("@tachybase/schema");
const external_antd_namespaceObject = require("antd");
const external_react_i18next_namespaceObject = require("react-i18next");
const external_index_js_namespaceObject = require("../index.js");
const external_SchemaSettings_js_namespaceObject = require("./SchemaSettings.js");
const UnitConversion = (param)=>{
    let { unitConversionType } = param;
    const form = (0, schema_namespaceObject.useForm)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(external_antd_namespaceObject.Select, {
        defaultValue: unitConversionType || '*',
        style: {
            width: 160
        },
        onChange: (value)=>{
            form.setValuesIn('unitConversionType', value);
        },
        children: [
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select.Option, {
                value: "*",
                children: t('Multiply by')
            }),
            /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_antd_namespaceObject.Select.Option, {
                value: "/",
                children: t('Divide by')
            })
        ]
    });
};
const SchemaSettingsNumberFormat = function(props) {
    const { fieldSchema } = props;
    const field = (0, schema_namespaceObject.useField)();
    const { dn } = (0, external_index_js_namespaceObject.useDesignable)();
    const { t } = (0, external_react_i18next_namespaceObject.useTranslation)();
    const { getCollectionJoinField } = (0, external_index_js_namespaceObject.useCollectionManager_deprecated)();
    const collectionField = getCollectionJoinField(null == fieldSchema ? void 0 : fieldSchema['x-collection-field']) || {};
    const { formatStyle, unitConversion, unitConversionType, separator, step, addonBefore, addonAfter } = fieldSchema['x-component-props'] || {};
    const { step: prescition } = (null == collectionField ? void 0 : collectionField.uiSchema['x-component-props']) || {};
    return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_SchemaSettings_js_namespaceObject.SchemaSettingsModalItem, {
        title: t('Format'),
        schema: {
            type: 'object',
            properties: {
                formatStyle: {
                    type: 'string',
                    default: formatStyle || 'normal',
                    enum: [
                        {
                            value: 'normal',
                            label: t('Normal')
                        },
                        {
                            value: 'scientifix',
                            label: t('Scientifix notation')
                        }
                    ],
                    'x-decorator': 'FormItem',
                    'x-component': 'Select',
                    title: "{{t('Style')}}"
                },
                unitConversion: {
                    type: 'number',
                    'x-decorator': 'FormItem',
                    'x-component': 'InputNumber',
                    title: "{{t('Unit conversion')}}",
                    default: unitConversion,
                    'x-component-props': {
                        style: {
                            width: '100%'
                        },
                        addonBefore: /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(UnitConversion, {
                            unitConversionType: unitConversionType
                        })
                    }
                },
                separator: {
                    type: 'string',
                    default: separator || '0,0.00',
                    enum: [
                        {
                            value: '0,0.00',
                            label: t('100,000.00')
                        },
                        {
                            value: '0.0,00',
                            label: t('100.000,00')
                        },
                        {
                            value: '0 0,00',
                            label: t('100 000.00')
                        },
                        {
                            value: '0.00',
                            label: t('100000.00')
                        }
                    ],
                    'x-decorator': 'FormItem',
                    'x-component': 'Select',
                    title: "{{t('Separator')}}"
                },
                step: {
                    type: 'string',
                    title: '{{t("Precision")}}',
                    'x-component': 'Select',
                    'x-decorator': 'FormItem',
                    default: step || prescition || '1',
                    enum: [
                        {
                            value: '1',
                            label: '1'
                        },
                        {
                            value: '0.1',
                            label: '1.0'
                        },
                        {
                            value: '0.01',
                            label: '1.00'
                        },
                        {
                            value: '0.001',
                            label: '1.000'
                        },
                        {
                            value: '0.0001',
                            label: '1.0000'
                        },
                        {
                            value: '0.00001',
                            label: '1.00000'
                        }
                    ]
                },
                addonBefore: {
                    type: 'string',
                    title: '{{t("Prefix")}}',
                    'x-component': 'Input',
                    'x-decorator': 'FormItem',
                    default: addonBefore
                },
                addonAfter: {
                    type: 'string',
                    title: '{{t("Suffix")}}',
                    'x-component': 'Input',
                    'x-decorator': 'FormItem',
                    default: addonAfter
                }
            }
        },
        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();
        }
    });
};
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
});
