<template>
  <ul v-show="visible" :class="wrapperClass">
    <li>
      <slot name="content">
        <span class="group-title">{{ label }}</span>
      </slot>
    </li>
    <li class="group-container">
      <ul class="group-wrapper">
        <slot></slot>
      </ul>
    </li>
  </ul>
</template>

<script>
import { LIB_NAME } from '../../../../src/util'

export default {
  name: 'xOptionGroup',
  props: {
    // 分组名称
    label: String // eslint-disable-line
  },
  data() {
    return {
      wrapperClass: `${LIB_NAME}-option-group`,
      visible: true
    }
  },
  created() {
    this.$on('keywordChange', this.handleKeywordChange)
  },
  methods: {
    handleKeywordChange(val) {
      this.visible = !this.$children.every(o => !o.visible)
    }
  }
}
</script>
