<template>
    <div class="dv-feature-layer-switch-item"
         @click.stop="handleClick"
         :class="{active: active}"
         @mouseleave="onMouseOut"
         @mouseenter="onMouseEnter">
        <div class="dv-feature-layer-switch-item-icon-wrap">
            <slot name="icon"></slot>
        </div>
        <slot></slot>
        <div ref="subMenu" class="dv-feature-layer-switch-item-sub-menu" v-if="$slots.subMenu" v-show="showSubMenu">
            <slot name="subMenu"></slot>
        </div>
        <div class="active-sub-menu" v-if="activeSubMenuName">{{activeSubMenuName}}</div>
    </div>
</template>

<script>
    export default {
        name: 'DvFeatureLayerSwitchItem',
        props: {
            active: {
                type: Boolean,
                default: false
            },
            activeSubMenuName: {
                type: String
            }
        },
        data () {
          return {
            showSubMenu: false
          };
        },
        methods: {
            onMouseEnter () {
                this.showSubMenu = true;
            },
            onMouseOut () {
                this.showSubMenu = false;
            },
            handleClick () {
                this.$emit('click');
            }
        }
    };
</script>
