import { useState, useEffect } from 'react';
import PHXFuncGetLoggedInfo from '../getLoginInfo';
import { PHXClientQueryV3 } from '../GRPC/PHXGrpcClientV3';
import { getActiveAndNextSchoolYearV3 } from '../../../query/school-year-v3';
function PHXGetActiveYearAndNextYearV3() {
    const schoolInfo = PHXFuncGetLoggedInfo();
    const [listSchoolYear, setListSchoolYear] = useState([]);
    const [schoolYearData, setSchoolYearData] = useState();
    const currentDate = new Date();
    currentDate.setFullYear(currentDate.getFullYear() + 1);
    const timeYearActive = new Date().toISOString().slice(0, 10);
    const nextYearDate = currentDate.toISOString().slice(0, 10);
    useEffect(() => {
        PHXClientQueryV3({
            query: getActiveAndNextSchoolYearV3,
            variables: {
                endAt: timeYearActive,
                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 PHXGetActiveYearAndNextYearV3;
//# sourceMappingURL=getActiveAndNextSchoolYearV3.js.map