<template>
    <view :class="'custom-class ' + utils.bem('tab__pane', { active, inactive: !active })" :style="shouldShow ? '' : 'display: none;'">
        <slot v-if="shouldRender" />
    </view>
</template>
<script module="utils" lang="wxs" src="@/node_modules/@vant/weapp/dist/wxs/utils.wxs"></script>
<script>
import { VantComponent } from '../common/component';
export default {
    data() {
        return {
            active: false,
            shouldRender: '',
            shouldShow: ''
        };
    },
    '../tabs/index': {
        name: 'tabs',
        type: 'ancestor',
        current: 'tab'
    },
    props: {
        dot: {
            type: Boolean
        },
        info: {
            type: null
        },
        title: {
            type: String
        },
        disabled: {
            type: Boolean
        },
        titleStyle: {
            type: String
        },
        name: {
            type: [Number, String],
            default: ''
        }
    },
    methods: {
        getComputedName() {
            if (this.name !== '') {
                return this.name;
            }
            return this.index;
        },
        updateRender(active, parent) {
            const { data: parentData } = parent;
            this.inited = this.inited || active;
            this.setData({
                active,
                shouldRender: this.inited || !parentData.lazyRender,
                shouldShow: active || parentData.animated
            });
        },
        update() {
            if (this.parent) {
                this.parent.updateTabs();
            }
        }
    },
    watch: {
        dot: {
            handler: function () {
                if (this.parent) {
                    this.parent.updateTabs();
                }
            },

            immediate: true
        },

        info: {
            handler: function () {
                if (this.parent) {
                    this.parent.updateTabs();
                }
            },

            immediate: true
        },

        title: {
            handler: function () {
                if (this.parent) {
                    this.parent.updateTabs();
                }
            },

            immediate: true
        },

        disabled: {
            handler: function () {
                if (this.parent) {
                    this.parent.updateTabs();
                }
            },

            immediate: true
        },

        titleStyle: {
            handler: function () {
                if (this.parent) {
                    this.parent.updateTabs();
                }
            },

            immediate: true
        }
    }
};
</script>
<style>
@import './index.css';
</style>
