import { ref, onMounted } from "vue";

/**
 * 获取当前日期并格式化为 YYYY-MM-DD 星期几
 */
export const useTodayTime = () => {
  const todayTime = ref<string>("");

  const getTodayTime = () => {
    const date = new Date();
    const year = date.getFullYear();
    const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始
    const day = String(date.getDate()).padStart(2, '0');
    const weekDay = date.toLocaleDateString('zh-CN', { weekday: 'long' }); // 星期几

    todayTime.value = `${year}-${month}-${day}`;
  };

  onMounted(() => {
    getTodayTime();
  });

  return {
    todayTime,
    getTodayTime,
  };
};