<template>
    <TabPane :label="currentLayoutModel.caption" :name="currentLayoutModel.name" tab="tabpanel1" :class="curClassName" :style="curStyle">
        <template v-if="containerModel.length > 0">
            <template v-for="name of containerModel">
                <slot :name="name"></slot>
            </template>
        </template>
    </TabPane>
</template>

<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';

@Component({})
export default class AppTabPage extends Vue {
    /**
    * 名称
    *
    * @type {string}
    * @memberof AppTabPage
    */
    @Prop() public name!: string;

    /**
     * 布局模型详情
     *
     * @type {string}
     * @memberof AppTabPage
     */
    @Prop() public layoutModelDetails: any;

    /**
     * 当前布局模型
     *
     * @type {*}
     * @memberof AppTabPage
     */
    public currentLayoutModel: any;

    /**
     * 插槽对象
     *
     * @memberof AppTabPage
     */
    public containerModel: any[] = [];

    /**
     * 组件初始化
     *
     * @memberof AppTabPage
     */
    public created() {
        this.init();
    }

    /**
     * 初始化子项
     *
     * @memberof AppTabPage
     */
    public init() {
        this.currentLayoutModel = this.layoutModelDetails[this.name];
        if (this.currentLayoutModel && this.currentLayoutModel.details && this.currentLayoutModel.details.length > 0) {
            this.currentLayoutModel.details.forEach((key: string) => {
                this.containerModel.push(key);
            })
        }
    }

    /**
     * 当前容器样式类
     * 
     * @memberof AppTabPage
     */
    get curClassName() {
        return {
            'app-tab-page': true,
            [this.name]: true,
            [this.currentLayoutModel.sysCss]: this.currentLayoutModel.sysCss ? true : false
        }
    }

    /**
     * 当前容器样式
     *
     * @memberof AppTabPage
     */
    get curStyle() {
        if (this.currentLayoutModel) {
            return this.currentLayoutModel.getElementStyle();
        }
        return '';
    }

}
</script>
<style lang='less'>
@import './app-tab-page.less';
</style>