import { system } from "@minecraft/server";

system.runInterval(() => {
    // code
}, 24000);

export { holiDates, now, getDateRangeInfo, getFormattedDateTime };

function getFormattedDateTime() {
    const now = new Date();
    const formatted = `${now.getMonth() + 1}/${now.getDate()}/${now.getFullYear()}`;
    return formatted;
}

function getDateRangeInfo(currentDate, targetDate, range) {
    const current = new Date(currentDate);
    const target = new Date(targetDate);

    current.setFullYear(2000);
    target.setFullYear(2000);

    const timeDiff = current.getTime() - target.getTime();
    const absTimeDiff = Math.abs(timeDiff);

    const rangesInMs = {
        milliseconds: range.milliseconds || 0,
        seconds: (range.seconds || 0) * 1000,
        minutes: (range.minutes || 0) * 1000 * 60,
        hours: (range.hours || 0) * 1000 * 60 * 60,
        days: (range.days || 0) * 1000 * 60 * 60 * 24,
        weeks: (range.weeks || 0) * 1000 * 60 * 60 * 24 * 7,
        months: (range.months || 0) * 1000 * 60 * 60 * 24 * 30
    };

    const totalRangeMs = Object.values(rangesInMs).reduce((sum, val) => sum + val, 0);

    const timeUnits = {
        days: Math.floor(absTimeDiff / (1000 * 60 * 60 * 24)),
        hours: Math.floor((absTimeDiff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),
        minutes: Math.floor((absTimeDiff % (1000 * 60 * 60)) / (1000 * 60)),
        seconds: Math.floor((absTimeDiff % (1000 * 60)) / 1000)
    };

    return {
        isInRange: absTimeDiff <= totalRangeMs,
        timeDifference: {
            milliseconds: absTimeDiff,
            ...timeUnits
        },
        direction: timeDiff < 0 ? 'before' : timeDiff > 0 ? 'after' : 'same',
        isPast: timeDiff > 0,
        isFuture: timeDiff < 0,
        isSame: timeDiff === 0
    };
}

const holiDates = {
    easter: new Date(2000, 3, 22),
    festive: new Date(2000, 11, 26),
    halloween: new Date(2000, 10, 1),
    summer: new Date(2000, 7, 5),
};

const now = new Date();

