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 SubTableFieldInterface extends __WEBPACK_EXTERNAL_MODULE__data_source_collection_field_interface_CollectionFieldInterface_mjs__.CollectionFieldInterface {
    schemaInitialize(schema, param) {
        let { field, readPretty } = param;
        const association = "".concat(field.collectionName, ".").concat(field.name);
        schema['type'] = 'void';
        schema['x-component'] = 'TableField';
        schema['properties'] = {
            block: {
                type: 'void',
                'x-decorator': 'TableFieldProvider',
                'x-acl-action': "".concat(field.target, ":list"),
                'x-decorator-props': {
                    collection: field.target,
                    association: association,
                    resource: association,
                    action: 'list',
                    params: {
                        paginate: false
                    },
                    showIndex: true,
                    dragSort: false
                },
                properties: {
                    actions: {
                        type: 'void',
                        'x-initializer': 'subTable:configureActions',
                        'x-component': 'TableField.ActionBar',
                        'x-component-props': {}
                    },
                    [field.name]: {
                        type: 'array',
                        'x-initializer': 'table:configureColumns',
                        'x-component': 'TableV2',
                        'x-use-component-props': 'useTableFieldProps',
                        'x-component-props': {
                            rowSelection: {
                                type: 'checkbox'
                            }
                        }
                    }
                }
            }
        };
    }
    constructor(...args){
        super(...args), _define_property(this, "name", 'subTable'), _define_property(this, "type", 'object'), _define_property(this, "group", 'relation'), _define_property(this, "order", 2), _define_property(this, "title", '{{t("Sub-table")}}'), _define_property(this, "isAssociation", true), _define_property(this, "default", {
            type: 'hasMany',
            uiSchema: {
                type: 'void',
                'x-component': 'TableField',
                'x-component-props': {}
            }
        }), _define_property(this, "availableTypes", [
            'hasMany'
        ]), _define_property(this, "initialize", (values)=>{
            if (!values.target) values.target = "t_".concat((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
            if (!values.foreignKey) values.foreignKey = "f_".concat((0, __WEBPACK_EXTERNAL_MODULE__tachybase_schema__.uid)());
        }), _define_property(this, "properties", {
            ...__WEBPACK_EXTERNAL_MODULE__properties_index_mjs__.defaultProps,
            subtable: {
                type: 'void',
                'x-component': 'SubFieldDataSourceProvider',
                properties: {
                    actions: {
                        type: 'void',
                        'x-component': 'ActionBar',
                        'x-component-props': {},
                        properties: {
                            delete: {
                                type: 'void',
                                title: '{{ t("Delete") }}',
                                'x-component': 'Action',
                                'x-component-props': {
                                    useAction: '{{ ds.useBulkDestroyAction }}',
                                    confirm: {
                                        title: "{{t('Delete record')}}",
                                        content: "{{t('Are you sure you want to delete it?')}}"
                                    }
                                }
                            },
                            create: {
                                type: 'void',
                                title: '{{ t("Add new") }}',
                                'x-component': 'AddSubFieldAction',
                                'x-component-props': {
                                    type: 'primary'
                                }
                            }
                        }
                    },
                    children: {
                        type: 'array',
                        title: '{{t("Fields")}}',
                        'x-decorator': 'FormItem',
                        'x-component': 'Table.Array',
                        'x-component-props': {
                            pagination: false,
                            expandable: {
                                childrenColumnName: '__nochildren__'
                            },
                            rowKey: 'name',
                            rowSelection: {
                                type: 'checkbox'
                            },
                            useSelectedRowKeys: '{{ ds.useSelectedRowKeys }}',
                            useDataSource: '{{ ds.useDataSource }}'
                        },
                        properties: {
                            column1: {
                                type: 'void',
                                title: '{{ t("Field display name") }}',
                                'x-component': 'Table.Column',
                                properties: {
                                    'uiSchema.title': {
                                        type: 'number',
                                        'x-component': 'Input',
                                        'x-read-pretty': true
                                    }
                                }
                            },
                            column2: {
                                type: 'void',
                                title: '{{ t("Field name") }}',
                                'x-component': 'Table.Column',
                                properties: {
                                    name: {
                                        'x-component': 'Input',
                                        'x-read-pretty': true
                                    }
                                }
                            },
                            column3: {
                                type: 'void',
                                title: '{{ t("Field interface") }}',
                                'x-component': 'Table.Column',
                                properties: {
                                    interface: {
                                        'x-component': 'Input',
                                        'x-read-pretty': true
                                    }
                                }
                            },
                            column4: {
                                type: 'void',
                                title: '{{ t("Actions") }}',
                                'x-component': 'Table.Column',
                                properties: {
                                    actions: {
                                        type: 'void',
                                        'x-component': 'Space',
                                        'x-component-props': {
                                            split: '|'
                                        },
                                        properties: {
                                            update: {
                                                type: 'void',
                                                title: '{{ t("Edit") }}',
                                                'x-component': 'EditSubFieldAction',
                                                'x-component-props': {}
                                            },
                                            delete: {
                                                type: 'void',
                                                title: '{{ t("Delete") }}',
                                                'x-component': 'Action.Link',
                                                'x-component-props': {
                                                    useAction: '{{ ds.useDestroyAction }}',
                                                    confirm: {
                                                        title: "{{t('Delete record')}}",
                                                        content: "{{t('Are you sure you want to delete it?')}}"
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        });
    }
}
export { SubTableFieldInterface };
