/*
 * @Author: 张宁 18339727226@163.com
 * @Date: 2024-05-27 08:45:53
 * @LastEditors: 张宁 18339727226@163.com
 * @LastEditTime: 2024-06-03 09:15:30
 * @FilePath: \welcome-system-screen\src\stores\time\time.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ref } from "vue";
import { defineStore } from "pinia";
import {getCurrentDate} from "../../utils/common"
// import { storeToRefs } from 'pinia';
// 创建一个Date对象，它将自动获取当前时间
const now = new Date();
// 获取当前日期
const dates = getCurrentDate();

export const useTimeStore = defineStore("time", () => {
  const years:Ref<any> = ref(now.getFullYear());
  const months:Ref<any> = ref(now.getMonth() + 1);
  const days:Ref<any>=ref(now.getDate());
  const nowDays:Ref<any> = ref(dates);
  const setYears = (year:any) => {
    years.value = year;
  };
  const setMounths = (month: any) => {
    months.value = month;
  }
  const setDays= (day: any) => {
    days.value = day;
  }
  const setNowDays = () => {
    years.value = ''
    months.value = ''
  }
   // 根据年、月、日的切换，展示不同的标题  --- 具体问问产品怎么展示 -----待修改
  const computDate = computed(() => {
    let dates = '当日'
    if (years.value) {
      dates = years.value + '年'
      if (months.value) {
        dates += months.value + '月'
      }if (days.value) {
        dates =  '当日'
      }
    } 
    return dates
  })
  const nowTitle = computed(() => {
    let titles = '当日'
    if (years.value) {
        titles = '当年'
        if(months.value) {
            titles = '当月'
        }if (days.value) {
          titles = '当日'
        }
    }
    return titles
  })

  return { years, months,days,nowDays, setYears, setMounths,setDays,setNowDays,computDate,nowTitle };
});
