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__ from "antd";
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__SchemaSettings_mjs__ from "./SchemaSettings.mjs";
const UnitConversion = (param)=>{
    let { unitConversionType } = param;
    const form = (0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.useForm)();
    const { t } = (0, __WEBPACK_EXTERNAL_MODULE_react_i18next__.useTranslation)();
    return /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsxs)(__WEBPACK_EXTERNAL_MODULE_antd__.Select, {
        defaultValue: unitConversionType || '*',
        style: {
            width: 160
        },
        onChange: (value)=>{
            form.setValuesIn('unitConversionType', value);
        },
        children: [
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Select.Option, {
                value: "*",
                children: t('Multiply by')
            }),
            /*#__PURE__*/ (0, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE_antd__.Select.Option, {
                value: "/",
                children: t('Divide by')
            })
        ]
    });
};
const SchemaSettingsNumberFormat = function(props) {
    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 { 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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.jsx)(__WEBPACK_EXTERNAL_MODULE__SchemaSettings_mjs__.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, __WEBPACK_EXTERNAL_MODULE_react_jsx_runtime__.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();
        }
    });
};
export { SchemaSettingsNumberFormat };
