<script setup>
import { ref, computed, useSlots } from 'vue'
import useStyle from '../hooks/useStyle'
import useSlotConfig from '../hooks/useSlotConfig'

defineOptions({
  name: 'VDatePicker'
})

const root = ref(null)

const props = defineProps({
  field: {
    type: Object,
    required: true
  }
})

const model = defineModel({ type: [Date, Array, Number, String] })
const slots = useSlots()

const slotConfig = useSlotConfig(props.field)

const { style } = useStyle(props)

defineExpose({
  root,
  focus(...rest) {
    root.value.focus(...rest)
  },
  handleOpen() {
    root.value.handleOpen()
  },
  handleClose() {
    root.value.handleClose()
  }
})
</script>

<template>
  <el-date-picker ref="root" v-model="model" v-bind="field" :style="style">
    <template v-if="slotConfig.default && slots[slotConfig.default]" #default="cell">
      <slot :name="slotConfig.default" v-bind="cell"></slot>
    </template>
    <template v-if="slotConfig.rangeSeparator && slots[slotConfig.rangeSeparator]" #range-separator>
      <slot :name="slotConfig.rangeSeparator"></slot>
    </template>
  </el-date-picker>
</template>

<style scoped>
</style>