"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__, {
    LinkToFieldInterface: ()=>LinkToFieldInterface
});
const schema_namespaceObject = require("@tachybase/schema");
const CollectionFieldInterface_js_namespaceObject = require("../../data-source/collection-field-interface/CollectionFieldInterface.js");
const 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;
}
class LinkToFieldInterface extends CollectionFieldInterface_js_namespaceObject.CollectionFieldInterface {
    schemaInitialize(schema, param) {
        let { readPretty, block, targetCollection } = param;
        if ((null == targetCollection ? void 0 : targetCollection.titleField) && schema['x-component-props']) {
            schema['x-component-props'].fieldNames = schema['x-component-props'].fieldNames || {
                value: targetCollection.filterTargetKey || 'id'
            };
            schema['x-component-props'].fieldNames.label = targetCollection.titleField;
        }
        if ([
            'Table',
            'Kanban'
        ].includes(block)) {
            schema['x-component-props'] = schema['x-component-props'] || {};
            schema['x-component-props']['ellipsis'] = true;
            schema['x-component-props']['size'] = 'small';
        }
    }
    constructor(...args){
        super(...args), _define_property(this, "name", 'linkTo'), _define_property(this, "type", 'object'), _define_property(this, "group", 'relation'), _define_property(this, "order", 1), _define_property(this, "title", '{{t("Link to")}}'), _define_property(this, "description", '{{t("Link to description")}}'), _define_property(this, "isAssociation", true), _define_property(this, "default", {
            type: 'belongsToMany',
            uiSchema: {
                'x-component': 'AssociationField',
                'x-component-props': {
                    multiple: true,
                    fieldNames: {
                        label: 'id',
                        value: 'id'
                    }
                }
            },
            reverseField: {
                interface: 'linkTo',
                type: 'belongsToMany',
                uiSchema: {
                    'x-component': 'AssociationField',
                    'x-component-props': {
                        multiple: true,
                        fieldNames: {
                            label: 'id',
                            value: 'id'
                        }
                    }
                }
            }
        }), _define_property(this, "initialize", (values)=>{
            if ('belongsToMany' === values.type) {
                if (!values.through) values.through = "t_".concat((0, schema_namespaceObject.uid)());
                if (!values.foreignKey) values.foreignKey = "f_".concat((0, schema_namespaceObject.uid)());
                if (!values.otherKey) values.otherKey = "f_".concat((0, schema_namespaceObject.uid)());
                if (!values.sourceKey) values.sourceKey = 'id';
                if (!values.targetKey) values.targetKey = 'id';
            }
        }), _define_property(this, "properties", {
            ...index_js_namespaceObject.defaultProps,
            target: {
                type: 'string',
                title: '{{t("Related collection")}}',
                required: true,
                'x-reactions': [
                    '{{useAsyncDataSource(loadCollections)}}'
                ],
                'x-decorator': 'FormItem',
                'x-component': 'Select',
                'x-disabled': '{{ !createOnly }}'
            },
            'uiSchema.x-component-props.multiple': {
                type: 'boolean',
                'x-content': '{{t("Allow linking to multiple records")}}',
                'x-decorator': 'FormItem',
                'x-component': 'Checkbox'
            }
        }), _define_property(this, "filterable", {
            nested: true,
            children: []
        });
    }
}
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
});
