import { FileManager } from '@syncfusion/ej2-filemanager';
import { ComponentBase, getProps, gh, isExecute, vueDefineComponent } from '@syncfusion/ej2-vue-base';
import { getValue, isNullOrUndefined } from '@syncfusion/ej2-base';

const properties = ['isLazyUpdate', 'plugins', 'ajaxSettings', 'allowDragAndDrop', 'allowMultiSelection', 'contextMenuSettings', 'cssClass', 'detailsViewSettings', 'enableHtmlSanitizer', 'enablePersistence', 'enableRtl', 'enableVirtualization', 'height', 'locale', 'navigationPaneSettings', 'path', 'popupTarget', 'rootAliasName', 'searchSettings', 'selectedItems', 'showFileExtension', 'showHiddenItems', 'showItemCheckBoxes', 'showThumbnail', 'sortBy', 'sortOrder', 'toolbarSettings', 'uploadSettings', 'view', 'width', 'beforeDownload', 'beforeImageLoad', 'beforePopupClose', 'beforePopupOpen', 'beforeSend', 'created', 'destroyed', 'failure', 'fileDragStart', 'fileDragStop', 'fileDragging', 'fileDropped', 'fileLoad', 'fileOpen', 'fileSelect', 'fileSelection', 'menuClick', 'menuOpen', 'popupClose', 'popupOpen', 'success', 'toolbarClick', 'toolbarCreate', 'uploadListCreate'];
const modelProps = [];
const testProp = getProps({ props: properties });
const props = testProp[0];
const watch = testProp[1];
const emitProbs = Object.keys(watch);
emitProbs.push('modelchanged', 'update:modelValue');
for (let props of modelProps) {
    emitProbs.push('update:' + props);
}
/**
 * Represents the Essential JS 2 VueJS FileManager Component.
 * ```vue
 * <ejs-filemanager showThumbnail='false'></ejs-filemanager>
 * ```
 */
let FileManagerComponent = vueDefineComponent({
    name: 'FileManagerComponent',
    mixins: [ComponentBase],
    props: props,
    watch: watch,
    emits: emitProbs,
    provide() { return { custom: this.custom }; },
    data() {
        return {
            ej2Instance: new FileManager({}),
            propKeys: properties,
            models: modelProps,
            hasChildDirective: false,
            hasInjectedModules: true,
            tagMapper: {},
            tagNameMapper: {},
            isVue3: !isExecute,
            templateCollection: {},
        };
    },
    created() {
        this.bindProperties();
        this.ej2Instances._setProperties = this.ej2Instances.setProperties;
        this.ej2Instances.setProperties = this.setProperties;
        this.ej2Instances.clearTemplate = this.clearTemplate;
        this.updated = this.updated;
    },
    render(createElement) {
        let h = !isExecute ? gh : createElement;
        let slots = null;
        if (!isNullOrUndefined(this.$slots.default)) {
            slots = !isExecute ? this.$slots.default() : this.$slots.default;
        }
        return h('div', slots);
    },
    methods: {
        clearTemplate(templateNames) {
            if (!templateNames) {
                templateNames = Object.keys(this.templateCollection || {});
            }
            if (templateNames.length && this.templateCollection) {
                for (let tempName of templateNames) {
                    let elementCollection = this.templateCollection[tempName];
                    if (elementCollection && elementCollection.length) {
                        for (let ele of elementCollection) {
                            let destroy = getValue('__vue__.$destroy', ele);
                            if (destroy) {
                                ele.__vue__.$destroy();
                            }
                            if (ele.innerHTML) {
                                ele.innerHTML = '';
                            }
                        }
                        delete this.templateCollection[tempName];
                    }
                }
            }
        },
        setProperties(prop, muteOnChange) {
            if (this.isVue3) {
                this.models = !this.models ? this.ej2Instances.referModels : this.models;
            }
            if (this.ej2Instances && this.ej2Instances._setProperties) {
                this.ej2Instances._setProperties(prop, muteOnChange);
            }
            if (prop && this.models && this.models.length) {
                Object.keys(prop).map((key) => {
                    this.models.map((model) => {
                        if ((key === model) && !(/datasource/i.test(key))) {
                            if (this.isVue3) {
                                this.ej2Instances.vueInstance.$emit('update:' + key, prop[key]);
                            }
                            else {
                                this.$emit('update:' + key, prop[key]);
                                this.$emit('modelchanged', prop[key]);
                            }
                        }
                    });
                });
            }
        },
        custom() {
            this.updated();
        },
        clearSelection() {
            return this.ej2Instances.clearSelection();
        },
        createFolder(name) {
            return this.ej2Instances.createFolder(name);
        },
        deleteFiles(ids) {
            return this.ej2Instances.deleteFiles(ids);
        },
        disableMenuItems(items) {
            return this.ej2Instances.disableMenuItems(items);
        },
        disableToolbarItems(items) {
            return this.ej2Instances.disableToolbarItems(items);
        },
        downloadFiles(ids) {
            return this.ej2Instances.downloadFiles(ids);
        },
        enableToolbarItems(items) {
            return this.ej2Instances.enableToolbarItems(items);
        },
        filterFiles(filterData) {
            return this.ej2Instances.filterFiles(filterData);
        },
        getMenuItemIndex(item) {
            return this.ej2Instances.getMenuItemIndex(item);
        },
        getSelectedFiles() {
            return this.ej2Instances.getSelectedFiles();
        },
        getToolbarItemIndex(item) {
            return this.ej2Instances.getToolbarItemIndex(item);
        },
        openFile(id) {
            return this.ej2Instances.openFile(id);
        },
        refreshFiles() {
            return this.ej2Instances.refreshFiles();
        },
        refreshLayout() {
            return this.ej2Instances.refreshLayout();
        },
        renameFile(id, name) {
            return this.ej2Instances.renameFile(id, name);
        },
        selectAll() {
            return this.ej2Instances.selectAll();
        },
        uploadFiles() {
            return this.ej2Instances.uploadFiles();
        },
    }
});
const FileManagerPlugin = {
    name: 'ejs-filemanager',
    install(Vue) {
        Vue.component(FileManagerPlugin.name, FileManagerComponent);
    }
};

export { FileManagerComponent, FileManagerPlugin };
export * from '@syncfusion/ej2-filemanager';
//# sourceMappingURL=ej2-vue-filemanager.es2015.js.map
