import config from '@/config'

const pickerMixin = {
  model: {
    prop: 'value',
    event: 'change',
  },
  data() {
    return {
      picker: undefined,
    }
  },
  provide() {
    return {
      RegisterPicker: (picker) => {
        // 把内部picker暴露给外层组件
        this.picker = picker
      },
    }
  },
  computed: {
    pickerMixinProps() {
      return {
        single: this.single,
        singleColumn: this.singleColumn,
        value: this.value,
        readOnly: this.readOnly,
        disabledKeys: this.disabledKeys,
        required: this.required,
      }
    },
  },
  methods: {
    openPicker() {
      this.picker.openPicker()
    },
    dummyForDoc() {
      /**
       * 用户取消选择
       */
      this.$emit('cancel')
    },
  },
  inheritAttrs: false,
  props: {
    /**
     * 单选
     */
    single: {
      type: Boolean,
      default: false,
    },
    /**
     * 没有右侧的已选中列表，直接在备选列表选择多个值
     */
    singleColumn: {
      type: Boolean,
      default: false,
    },
    /**
     * 表单项的值
     */
    value: {
      type: [Array, String],
      default: undefined,
    },
    /**
     * 只读
     */
    readOnly: {
      type: Boolean,
      default: false,
    },
    /**
     * 禁用的候选项
     * @since 8.0.8
     */
    disabledKeys: {
      type: Array,
      default: () => [],
    },
    /**
     * @ignore
     */
    dblClickTransfer: {
      type: Boolean,
      default: () => config.common.picker.dblClickTransfer,
    },
    /**
     * 必填。只控制了没选值时，对话框的确定按钮不可点击；input框的校验请使用通用的rules属性
     * @since 0.19
     */
    required: {
      type: Boolean,
      default: false,
    },
  },
}
export default pickerMixin
