import { useState, useEffect } from 'react';
import PHXFuncGetLoggedInfo from '../getLoginInfo';
import { PHXClientQueryV3 } from '../GRPC/PHXGrpcClientV3';
import { getActiveAndNextSchoolYearV3 } from '../../../query/school-year-v3';
function PHXGetPrevCurrentNextYearV3() {
    const schoolInfo = PHXFuncGetLoggedInfo();
    const [listSchoolYear, setListSchoolYear] = useState([]);
    const [schoolYearData, setSchoolYearData] = useState();
    const currentDate = new Date();
    currentDate.setFullYear(currentDate.getFullYear() + 1);
    const nextYearDate = currentDate.toISOString().slice(0, 10);
    // Lấy năm trước đó
    const prevYear = new Date();
    prevYear.setFullYear(prevYear.getFullYear() - 1);
    const prevYearDate = prevYear.toISOString().slice(0, 10);
    useEffect(() => {
        PHXClientQueryV3({
            query: getActiveAndNextSchoolYearV3,
            variables: {
                endAt: prevYearDate,
                startAt: nextYearDate,
                school_id: schoolInfo === null || schoolInfo === void 0 ? void 0 : schoolInfo.school_id,
            },
        }).then((res) => {
            setSchoolYearData(res.data);
        });
    }, []);
    useEffect(() => {
        if ((schoolYearData === null || schoolYearData === void 0 ? void 0 : schoolYearData.school_year) && schoolYearData.school_year.length > 0) {
            // @ts-ignore
            const arraySchoolYear = (schoolYearData === null || schoolYearData === void 0 ? void 0 : schoolYearData.school_year) || [];
            setListSchoolYear(arraySchoolYear);
        }
        else {
            setListSchoolYear([]);
        }
    }, [schoolYearData]);
    return listSchoolYear;
}
export default PHXGetPrevCurrentNextYearV3;
//# sourceMappingURL=getPrevCurrentNextSchoolYearV3.js.map