<script setup>
import moment from 'moment'
import {ref} from 'vue'

const props=defineProps({
    show:{
        type:Boolean,
        default:false
    }
})
const emits=defineEmits(['update:show','select'])

function handleClose(){
    emits('update:show',false)
}

const minDate=new Date(1970, 0, 1)
const maxDate=moment().add(10,'years')._d
const currentDate=ref(moment().format('YYYY-MM-DD').split('-'))

function handleConfirmDate({selectedValues, selectedOptions}){
    // console.log(selectedValues, selectedOptions);
    emits('select',selectedValues.join('-'))
    handleClose()
}

</script>

<template>
    <van-popup 
        :show="props.show"
        position="bottom"
        round
        @click-overlay="handleClose"
        @click-close-icon="handleClose"
    >
        <van-date-picker
            v-model="currentDate"
            title="选择日期"
            :min-date="minDate"
            :max-date="maxDate"
            @confirm="handleConfirmDate"
            @cancel="handleClose"
        />
    </van-popup>
</template>