<template>
  <n-options-children ref="options" v-model="isFocus" v-bind="{disabled, state, pasterOptions, parents, options, constructed, maxHeight, autoClose: false, builders, multiple}"
                      @click="onOptionSelect" @parent-click="onParentClick" @select-all="onSelectAll">
    <n-form-refer class="n-select-children" v-model="isFocus" v-bind="{name, values, state, multiple, size, border, disabled, placeholder,clearable, builder: builders.value}"
                  @u-update="onReferUpdateValues"></n-form-refer>
  </n-options-children>
</template>
<script>
import NOptionsChildren from '@uif/next/lib/components/options-children'
import NSelect from '@uif/next/lib/components/select'
import {prop} from '@uif/next/lib/utils/tools'
import {optionsSelectAll, parseConstructionOptions} from '_common/formUtils'
export default {
  inheritAttrs: false,
  name: 'n-select-children',
  extends: {...NSelect, created: undefined},
  components: {
    NOptionsChildren
  },
  props: {
    // 父选项
    parents: prop.array(),
    // 自动获取最后一级作为 options
    constructed: prop.boolean()
  },
  created () {
    this.state.cacheOptions(this.values)
    const options = this.constructed ? parseConstructionOptions(this.options) : this.options
    this.state.updateOptions(options)
    this.onPropValueUpdate()
  },
  methods: {
    onParentClick (parent, state) {
      this.$emit('parent-click', parent, state)
    },
    onSelectAll (options, isSelected) {
      optionsSelectAll(this.nValue, options, isSelected)
      this.state.updateValuesByValue(this.values, this.nValue)
      this.$emit('u-update', this.nValue)
    }
  }
}
</script>
