<template>
    <view
        :class="utils.bem('sidebar-item', { selected, disabled }) + ' ' + (selected ? 'active-class' : '') + ' ' + (disabled ? 'disabled-class' : '') + ' custom-class'"
        hover-class="van-sidebar-item--hover"
        hover-stay-time="70"
        @tap="onClick"
    >
        <view class="van-sidebar-item__text">
            <van-info v-if="info !== null || dot" :dot="dot" :info="info" custom-style="right: 4px" />
            <view v-if="title">{{ title }}</view>
            <slot v-else name="title" />
        </view>
    </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 {
            selected: ''
        };
    },
    classes: ['active-class', 'disabled-class'],
    '../sidebar/index': {
        type: 'ancestor',
        name: 'sidebar',
        current: 'sidebar-item'
    },
    props: {
        dot: Boolean,
        info: null,
        title: String,
        disabled: Boolean
    },
    methods: {
        onClick() {
            const { parent } = this;
            if (!parent || this.disabled) {
                return;
            }
            const index = parent.children.indexOf(this);
            parent.setActive(index).then(() => {
                this.$emit('click', index);
                parent.$emit('change', index);
            });
        },
        setActive(selected) {
            return this.setData({
                selected
            });
        }
    }
};
</script>
<style>
@import './index.css';
</style>
