import * as __WEBPACK_EXTERNAL_MODULE__tachybase_schema__ from "@tachybase/schema";
import * as __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_interface_CollectionFieldInterface_mjs__ from "../../data-source/collection-field-interface/CollectionFieldInterface.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__properties_index_mjs__ 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;
}
class LinkToFieldInterface extends __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_interface_CollectionFieldInterface_mjs__.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, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
                if (!values.foreignKey) values.foreignKey = "f_".concat((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
                if (!values.otherKey) values.otherKey = "f_".concat((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
                if (!values.sourceKey) values.sourceKey = 'id';
                if (!values.targetKey) values.targetKey = 'id';
            }
        }), _define_property(this, "properties", {
            ...__WEBPACK_EXTERNAL_MODULE__properties_index_mjs__.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: []
        });
    }
}
export { LinkToFieldInterface };
