<template>
  <ul class="el-dropdown-group__wrap">
    <li class="el-dropdown-group__title" v-if="showTitle">{{ label }}</li>
    <li>
      <ul class="el-dropdown-group">
        <slot></slot>
      </ul>
    </li>
  </ul>
</template>

<script type="text/babel">
import Emitter from 'modesign-ui/src/mixins/emitter';

export default {
  mixins: [Emitter],

  name: 'ElDropdownGroup',

  componentName: 'ElDropdownGroup',

  props: {
    label: String,
    disabled: {
      type: Boolean,
      default: true
    },
    showTitle: {
      type: Boolean,
      default: false
    }
  },

  data() {
    return {};
  },

  watch: {
    disabled(val) {
      this.broadcast('ElDropdownItem', 'handleGroupDisabled', val);
    }
  },

  methods: {
    queryChange() {
      this.visible = this.$children &&
          Array.isArray(this.$children) &&
          this.$children.some(option => option.visible === true);
    }
  },

  created() {
    this.$on('queryChange', this.queryChange);
  },

  mounted() {
    if (this.disabled) {
      this.broadcast('ElDropdownItem', 'handleGroupDisabled', this.disabled);
    }
  }
};
</script>
