import { computed } from 'vue'
const now = computed(() => new Date())
export function disabledDateAge(time) {
    const year = now.value.getFullYear() - 100
    const minDate = new Date(Date.UTC(year, 0))
    const maxDate = new Date(now.value.getTime())
    const isBeforeMin = time.getTime() < minDate.getTime()
    const isAfterMax = time.getTime() > maxDate.getTime()
    return isBeforeMin || isAfterMax
}

export function disabledDate2020Start(time) {
    return 2020 - time.getFullYear() > 0 || time.getTime() > Date.now()
}

export function disabledDate(time, month = 0) {
    const minDate = new Date(Date.UTC(1901, 0));
    const currentDate = new Date(now.value.getTime());
    const year = currentDate.getFullYear();
    const monthValue = currentDate.getMonth();
    const newMonth = monthValue - month;
    const adjustedYear = year + Math.floor(newMonth / 12);
    const adjustedMonth = ((newMonth % 12) + 12) % 12;
    const maxDate = new Date(Date.UTC(adjustedYear, adjustedMonth + 1, 0));
    return time.getTime() < minDate.getTime() || time.getTime() > maxDate.getTime();
}

export function disabledDayRange(time, beforeDays = 0, afterDays = 0) {
    const currentTime = now.value.getTime();
    const minDate = beforeDays > 0
        ? new Date(currentTime - beforeDays * 86400000)
        : new Date(Date.UTC(1901, 0, 1));

    const maxDate = afterDays > 0
        ? new Date(currentTime + afterDays * 86400000)
        : new Date(currentTime);

    minDate.setHours(0, 0, 0, 0);
    maxDate.setHours(23, 59, 59, 999);
    const checkDate = new Date(time);
    checkDate.setHours(0, 0, 0, 0);

    return checkDate.getTime() < minDate.getTime() ||
        checkDate.getTime() > maxDate.getTime();
}