// @ts-nocheck
import Vue from 'vue'
import zhCN from 'ant-design-vue/es/locale-provider/zh_CN'
import { ConfigProvider } from 'ant-design-vue'
import store from '@/common/store'
function pickValues(Picker, props) {
  const p = new Promise(function(resolve, reject) {
    // eslint-disable-next-line vue/require-name-property
    const vm = new Vue({
      mounted() {
        // 直接打开选择对话框
        this.$refs.picker.openPicker()
      },
      destroyed() {
        // 移除DOM结构
        this.$root.$el.parentNode.removeChild(this.$root.$el)
      },
      render: (h) => {
        return (
          <ConfigProvider style={{ display: 'none' }} locale={zhCN}>
            <Picker
              props={props}
              ref='picker'
              onChange={function(val) {
                resolve(val)
                vm.$destroy()
              }}
              onCancel={function(val) {
                resolve(undefined)
                vm.$destroy()
              }}
            />
          </ConfigProvider>
        )
      },
      store,
    }).$mount()
    document.body.appendChild(vm.$el)
  })
  return p
}

export default pickValues
