"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__, {
    PercentFieldInterface: ()=>PercentFieldInterface
});
const schema_namespaceObject = require("@tachybase/schema");
const CollectionFieldInterface_js_namespaceObject = require("../../data-source/collection-field-interface/CollectionFieldInterface.js");
const index_js_namespaceObject = require("../../i18n/index.js");
const external_properties_index_js_namespaceObject = require("./properties/index.js");
function _define_property(obj, key, value) {
    if (key in obj) Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
    });
    else obj[key] = value;
    return obj;
}
(0, schema_namespaceObject.registerValidateRules)({
    percentMode (value, rule) {
        const { maxValue, minValue } = rule;
        if (maxValue) {
            if (value > maxValue) return {
                type: 'error',
                message: "".concat(index_js_namespaceObject.i18n.t('The field value cannot be greater than ')).concat(100 * maxValue, "%")
            };
        }
        if (minValue) {
            if (value < minValue) return {
                type: 'error',
                message: "".concat(index_js_namespaceObject.i18n.t('The field value cannot be less than ')).concat(100 * minValue, "%")
            };
        }
        return true;
    },
    percentFormats (value, rule) {
        const { percentFormat } = rule;
        if (value && 'Integer' === percentFormat && false === /^-?[1-9]\d*$/.test((100 * value).toString())) return {
            type: 'error',
            message: "".concat(index_js_namespaceObject.i18n.t('The field value is not an integer number'))
        };
        return true;
    }
});
class PercentFieldInterface extends CollectionFieldInterface_js_namespaceObject.CollectionFieldInterface {
    schemaInitialize(schema, param) {
        let { field, block, readPretty, action } = param;
        const props = schema['x-component-props'] = schema['x-component-props'] || {};
        schema['x-component-props'].style = {
            ...props.style || {},
            width: '100%'
        };
    }
    constructor(...args){
        super(...args), _define_property(this, "name", 'percent'), _define_property(this, "type", 'object'), _define_property(this, "group", 'basic'), _define_property(this, "order", 8), _define_property(this, "title", '{{t("Percent")}}'), _define_property(this, "sortable", true), _define_property(this, "default", {
            type: 'float',
            uiSchema: {
                type: 'string',
                'x-component': 'Percent',
                'x-component-props': {
                    stringMode: true,
                    step: '1',
                    addonAfter: '%'
                }
            }
        }), _define_property(this, "availableTypes", [
            'float',
            'double',
            'decimal'
        ]), _define_property(this, "hasDefaultValue", true), _define_property(this, "properties", {
            ...external_properties_index_js_namespaceObject.defaultProps,
            unique: external_properties_index_js_namespaceObject.unique,
            'uiSchema.x-component-props.step': {
                type: 'string',
                title: '{{t("Precision")}}',
                'x-component': 'Select',
                'x-decorator': 'FormItem',
                default: '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%'
                    }
                ]
            }
        }), _define_property(this, "filterable", {
            operators: external_properties_index_js_namespaceObject.operators.number
        }), _define_property(this, "titleUsable", true), _define_property(this, "validateSchema", (fieldSchema)=>({
                maxValue: {
                    type: 'number',
                    title: '{{ t("Maximum") }}',
                    'x-decorator': 'FormItem',
                    'x-component': 'Percent',
                    'x-component-props': {
                        addonAfter: '%'
                    },
                    'x-reactions': "{{(field) => {\n          const targetValue = field.query('.minimum').value();\n          field.selfErrors =\n            !!targetValue && !!field.value && targetValue > field.value ? '".concat(index_js_namespaceObject.i18n.t('Maximum must greater than minimum'), "' : ''\n        }}}")
                },
                minValue: {
                    type: 'number',
                    title: '{{ t("Minimum") }}',
                    'x-decorator': 'FormItem',
                    'x-component': 'Percent',
                    'x-component-props': {
                        addonAfter: '%'
                    },
                    'x-reactions': {
                        dependencies: [
                            '.maximum'
                        ],
                        fulfill: {
                            state: {
                                selfErrors: "{{!!$deps[0] && !!$self.value && $deps[0] < $self.value ? '".concat(index_js_namespaceObject.i18n.t('Minimum must less than maximum'), "' : ''}}")
                            }
                        }
                    }
                },
                percentFormat: {
                    type: 'string',
                    title: '{{ t("Format") }}',
                    'x-decorator': 'FormItem',
                    'x-component': 'Select',
                    'x-component-props': {
                        allowClear: true
                    },
                    enum: [
                        {
                            label: '{{ t("Integer") }}',
                            value: 'Integer'
                        }
                    ]
                },
                pattern: {
                    type: 'string',
                    title: '{{ t("Regular expression") }}',
                    'x-decorator': 'FormItem',
                    'x-component': 'Input',
                    'x-component-props': {
                        prefix: '/',
                        suffix: '/'
                    }
                }
            }));
    }
}
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
});
