"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__, {
    ViewCollectionTemplate: ()=>ViewCollectionTemplate
});
const CollectionTemplate_js_namespaceObject = require("../../data-source/collection-template/CollectionTemplate.js");
const PreviewFields_js_namespaceObject = require("./components/PreviewFields.js");
const PreviewTable_js_namespaceObject = require("./components/PreviewTable.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 ViewCollectionTemplate extends CollectionTemplate_js_namespaceObject.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': PreviewFields_js_namespaceObject.PreviewFields,
                'x-visible': '{{ createOnly }}',
                'x-reactions': {
                    dependencies: [
                        'name'
                    ],
                    fulfill: {
                        schema: {
                            'x-component-props': '{{$form.values}}'
                        }
                    }
                }
            },
            preview: {
                type: 'object',
                'x-visible': '{{ createOnly }}',
                'x-component': PreviewTable_js_namespaceObject.PreviewTable,
                'x-reactions': {
                    dependencies: [
                        'name',
                        'fields'
                    ],
                    fulfill: {
                        schema: {
                            'x-component-props': '{{$form.values}}'
                        }
                    }
                }
            },
            ...(0, index_js_namespaceObject.getConfigurableProperties)('category', 'description')
        });
    }
}
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
});
