import TyComponent from '../common/component'

TyComponent({
    source: true,
    externalClasses: [
        'active-class',
        'disabled-class',
    ],
    relations: {
        '../ht-sidebar/index': {
            type: 'ancestor'
        }
    },
    properties: {
        dot: Boolean,
        info: null,
        title: String,
        icon: String,
        disabled: Boolean
    },

    methods: {
        onClick() {
            const {
                parent
            } = this;
            if (!parent || this.data.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
            });
        }
    }
});
