<script setup lang='ts'>
import { sceneBookingApi } from '@/api/api/sceneBooking';

const dateArray = ref([] as any)


const getFutureDates = (numDays: number) => {
  const datesArray = [];
  const today = new Date();
  const dateFormat = 'yyyy-MM-dd 星期X'; // 新增星期格式

  for (let i = 0; i <= numDays; i++) {
    const futureDate = new Date(today.getTime());
    futureDate.setDate(today.getDate() + i);
    const formattedDate = formatDate(futureDate, dateFormat);
    datesArray.push({
      date: formattedDate
    });
  }

  return datesArray;
}

const formatDate = (date: any, format: any) => {
  const year = date.getFullYear();
  const month = String(date.getMonth() + 1).padStart(2, '0');
  const day = String(date.getDate()).padStart(2, '0');
  const weekDay = getWeekDay(date);

  return format.replace('yyyy', year)
    .replace('MM', month)
    .replace('dd', day)
    .replace('X', weekDay);
}

const getWeekDay = (date: any) => {
  const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
  return daysOfWeek[date.getDay()];
}

// 获取禁止预约日期，并加上字段
const getDisableDate = async () => {
  const res = await sceneBookingApi.getDisableDateAPi()
  if (res.data.code === 0) {
    // 遍历禁止日期
    res.data.forEach((item: any) => {
      dateArray.value.forEach((dateItem: any) => {
        if (item === dateItem.date) {
          dateItem.disable = true
        }
      })
    })
  }
}

// const bookingTimeList = ref([] as any)

// 获得可预约时间段
// const getBookingTime = async () => {
//   const res = await sceneBookingApi.getBookingTimeAPI()

// }

onBeforeMount(() => {
  dateArray.value = getFutureDates(13)
  getDisableDate()
  // console.log(getFutureDates(13))
})
</script>

<template>
  <div class='time-box'>

  </div>
</template>

<style lang='less' scoped>
.time-box {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0px;
  left: 0px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: gray;
  margin: 0;
  box-sizing: border-box;
}
</style>