import * as __WEBPACK_EXTERNAL_MODULE__data_source_collection_template_CollectionTemplate_mjs__ from "../../data-source/collection-template/CollectionTemplate.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__components_PreviewFields_mjs__ from "./components/PreviewFields.mjs";
import * as __WEBPACK_EXTERNAL_MODULE__components_PreviewTable_mjs__ from "./components/PreviewTable.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 ViewCollectionTemplate extends __WEBPACK_EXTERNAL_MODULE__data_source_collection_template_CollectionTemplate_mjs__.CollectionTemplate {
    constructor(...args){
        super(...args), _define_property(this, "name", 'view'), _define_property(this, "title", '{{t("Connect to database view")}}'), _define_property(this, "order", 4), _define_property(this, "color", 'yellow'), _define_property(this, "default", {
            fields: []
        }), _define_property(this, "divider", true), _define_property(this, "configurableProperties", {
            title: {
                type: 'string',
                title: '{{ t("Collection display name") }}',
                required: true,
                'x-decorator': 'FormItem',
                'x-component': 'Input'
            },
            databaseView: {
                title: '{{t("Connect to database view")}}',
                type: 'single',
                required: true,
                'x-decorator': 'FormItem',
                'x-component': 'Select',
                'x-reactions': [
                    '{{useAsyncDataSource(loadDBViews)}}'
                ],
                'x-disabled': '{{ !createOnly }}'
            },
            name: {
                type: 'string',
                title: '{{t("Collection name")}}',
                required: true,
                'x-disabled': '{{ !createOnly }}',
                'x-decorator': 'FormItem',
                'x-component': 'Input',
                'x-validator': 'uid',
                description: "{{t('Randomly generated and can be modified. Support letters, numbers and underscores, must start with an letter.')}}",
                'x-reactions': {
                    dependencies: [
                        'databaseView'
                    ],
                    when: '{{isPG}}',
                    fulfill: {
                        state: {
                            initialValue: '{{$deps[0]&&$deps[0].match(/^([^_]+)_(.*)$/)?.[2]}}'
                        }
                    },
                    otherwise: {
                        state: {
                            value: null
                        }
                    }
                }
            },
            schema: {
                type: 'string',
                'x-hidden': true,
                'x-reactions': {
                    dependencies: [
                        'databaseView'
                    ],
                    when: '{{isPG}}',
                    fulfill: {
                        state: {
                            value: "{{$deps[0].split('_')?.[0]}}"
                        }
                    },
                    otherwise: {
                        state: {
                            value: null
                        }
                    }
                }
            },
            viewName: {
                type: 'string',
                'x-hidden': true,
                'x-reactions': {
                    dependencies: [
                        'databaseView'
                    ],
                    when: '{{isPG}}',
                    fulfill: {
                        state: {
                            value: '{{$deps[0].match(/^([^_]+)_(.*)$/)?.[2]}}'
                        }
                    },
                    otherwise: {
                        state: {
                            value: '{{$deps[0]}}'
                        }
                    }
                }
            },
            writableView: {
                type: 'boolean',
                'x-content': '{{t("Allow add new, update and delete actions")}}',
                'x-decorator': 'FormItem',
                'x-component': 'Checkbox',
                default: false
            },
            sources: {
                type: 'array',
                title: '{{ t("Source collections") }}',
                'x-decorator': 'FormItem',
                'x-component': 'Select',
                'x-component-props': {
                    multiple: true
                },
                'x-reactions': [
                    '{{useAsyncDataSource(loadCollections)}}'
                ],
                'x-disabled': true
            },
            fields: {
                type: 'array',
                'x-component': __WEBPACK_EXTERNAL_MODULE__components_PreviewFields_mjs__.PreviewFields,
                'x-visible': '{{ createOnly }}',
                'x-reactions': {
                    dependencies: [
                        'name'
                    ],
                    fulfill: {
                        schema: {
                            'x-component-props': '{{$form.values}}'
                        }
                    }
                }
            },
            preview: {
                type: 'object',
                'x-visible': '{{ createOnly }}',
                'x-component': __WEBPACK_EXTERNAL_MODULE__components_PreviewTable_mjs__.PreviewTable,
                'x-reactions': {
                    dependencies: [
                        'name',
                        'fields'
                    ],
                    fulfill: {
                        schema: {
                            'x-component-props': '{{$form.values}}'
                        }
                    }
                }
            },
            ...(0, __WEBPACK_EXTERNAL_MODULE__properties_index_mjs__.getConfigurableProperties)('category', 'description')
        });
    }
}
export { ViewCollectionTemplate };
