<template>
    <div v-if="hackReset" style="width: 100%">
        <EditorContainer :theme="{}" v-if="typeof editors === 'string'">
            <component :is="item" v-for="(item,index) in pluginsBelongKeys[`mainToolEditorType${editors}`]"
                       :key="index"></component>
        </EditorContainer>
        <div v-else>
            <template v-for="(editor,index) in editors">
                <TabTitle v-if="typeof editor ==='string'" :key="index">{{editor}}</TabTitle>
                <EditorContainer v-else :key="index"
                                 :theme="{isObjectType:editor.type==='array'||editor.type==='object'}"
                                 v-show="vShow(editor)"
                >
                    <!--<Label style="width: 100%;" v-if="editor.text" :theme="{isObjectType:editor.type==='array'||editor.type==='object'}">-->
                        <!--<span>{{editor.text}}</span>-->
                    <!--</Label>-->
                    <EditorBoxContainer style="width: 100%;text-align: left;">
                        <template>
                            <component :instanceInfo="instanceInfo" :editor="editor" :is="innerItem"
                                       v-for="(innerItem,innerIndex) in pluginsBelongKeys[`mainToolEditorType${upperFirst(camelCase(editor.type))}`]"
                                       :key="innerIndex"
                                       ></component>
                        </template>
                    </EditorBoxContainer>
                </EditorContainer>
            </template>
        </div>
    </div>
</template>

<script>
    import * as components from './style';
    import {SVC} from '../../service';
    import * as _ from 'lodash';
    import eventbus from '../../service/eventbus';

    export default {
        components: {
            ...components
        },
        position: 'mainToolEditorManager',
        name: 'main-tool-editor-manager',
        computed: {
            applicationState() {
                return this.$store.state.application;
            },
            viewportState() {
                return this.$store.state.viewport;
            },
            currentEditInstanceKey() {
                this.hackReset = false
                this.$nextTick(() => {
                    this.hackReset = true
                });
                return this.$store.state.viewport.currentEditInstanceKey;
            },
            editors() {

                const instanceKey = this.currentEditInstanceKey;
                if (!this.viewportState.instances.has(instanceKey)) {
                    return null;
                }

                this.instanceInfo = this.viewportState.instances.get(instanceKey);
                return this.applicationState.componentSetting.get(
                    this.instanceInfo.gaeaKey
                ).editors;
            }
        },
        data() {
            return {
                instanceInfo: null,
                pluginsBelongKeys: SVC.pluginsBelongKeys,
                hackReset: true,
                hideField: ""
            };
        },
        methods: {
            upperFirst: _.upperFirst,
            camelCase: _.camelCase,
            vShow(data) {
                if (data.isShow === "hide" || data.field === this.hideField) {
                    return false;
                } else {
                    return true;
                }
            }
        },
        created() {


            eventbus.$on("computIsShow", (data) => {
                this.hideField = data.com;//如果渲染的组件为传过来的组件则隐藏
            });

        }
    };
</script>

<style scoped>
    .hjBhxn{
        display: block;
    }
    .eftufS {
        padding-bottom: 0px;
    }
</style>
