import { jsx } from "react/jsx-runtime";
import "react";
import { FormItem, FormLayout } from "@tachybase/components";
import { registerValidateRules } from "@tachybase/schema";
import { CollectionFieldInterface } from "../../data-source/collection-field-interface/CollectionFieldInterface.mjs";
import { defaultProps, operators } from "./properties/index.mjs";
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;
}
registerValidateRules({
    json (value) {
        try {
            JSON.parse(value);
            return true;
        } catch (error) {
            return {
                type: 'error',
                message: error.message
            };
        }
    }
});
class JsonFieldInterface extends CollectionFieldInterface {
    constructor(...args){
        super(...args), _define_property(this, "name", 'json'), _define_property(this, "type", 'object'), _define_property(this, "group", 'advanced'), _define_property(this, "order", 4), _define_property(this, "title", '{{t("JSON")}}'), _define_property(this, "sortable", true), _define_property(this, "default", {
            type: 'json',
            uiSchema: {
                type: 'object',
                'x-component': 'Input.JSON',
                'x-component-props': {
                    autoSize: {
                        minRows: 5
                    }
                },
                default: null
            }
        }), _define_property(this, "availableTypes", [
            'json',
            'array',
            'jsonb',
            'text',
            'circle',
            'lineString',
            'point',
            'polygon'
        ]), _define_property(this, "hasDefaultValue", true), _define_property(this, "properties", {
            ...defaultProps,
            jsonb: {
                type: 'boolean',
                title: 'JSONB',
                'x-decorator': (param)=>{
                    let { children } = param;
                    return /*#__PURE__*/ jsx(FormLayout, {
                        children: /*#__PURE__*/ jsx(FormItem, {
                            children: children
                        })
                    });
                },
                'x-component': 'Checkbox',
                'x-hidden': "{{ !isDialect('postgres') }}",
                'x-disabled': "{{ disabledJSONB }}"
            }
        }), _define_property(this, "filterable", {
            operators: operators.string
        });
    }
}
export { JsonFieldInterface };
