type InputDate = {
    startDate: string;
    endDate: string;
    label?: string;
}

/**
 * Generates a list of year ranges based on the number of past and future years specified.
 * @param numberOfYears The number of past and future years to include separately.
 * @returns An array of objects with start year, end year, and label.
 */
export function generateYearRanges(numberOfYears: number, month: number): InputDate[] {
    const startDate = "10-01" //start date of each financial year
    const endDate = "09-30" // end date of each financial year

    // Get the base year
    const baseYear = new Date().getFullYear();

    // Determine the current year based on the month
    let currentYear: number;
    if (month < 10) { // October is month 10
        currentYear = baseYear - 1;
    } else {
        currentYear = baseYear;
    }


    // Initialize the result array
    const yearRanges: InputDate[] = [];

    // Add past years beyond numberOfYears as one group
    if (numberOfYears > 0) {
        yearRanges.push({
            startDate: "",
            endDate: `${(currentYear - numberOfYears)}-${endDate}`,
            label: `< ${currentYear - numberOfYears}`
        });
    }

    // Add individual past years
    for (let i = numberOfYears - 1; i >= 0; i--) {
        const startYear = currentYear - i - 1;
        const endYear = currentYear - i;
        yearRanges.push({ startDate: `${startYear}-${startDate}`, endDate: `${endYear}-${endDate}`, label: `${startYear} - ${endYear}` });
    }

    // Add current year
    yearRanges.push({
        startDate: `${currentYear}-${startDate}`,
        endDate: `${(currentYear + 1)}-${endDate}`,
        label: `${currentYear} - ${currentYear + 1} (current year)`
    });

    // Add individual future years
    for (let i = 0; i < numberOfYears; i++) {
        const startYear = currentYear + i + 1;
        const endYear = currentYear + i + 2;
        yearRanges.push({ startDate: `${startYear}-${startDate}`, endDate: `${endYear}-${endDate}`, label: `${startYear} - ${endYear}` });
    }

    // Add future years beyond numberOfYears as one group
    if (numberOfYears > 0) {
        yearRanges.push({
            startDate: `${(currentYear + numberOfYears + 1)}-${startDate}`,
            endDate: "",
            label: `> ${currentYear + numberOfYears + 1}`
        });
    }

    return yearRanges;
}