"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = require("react");
const getLoginInfo_1 = tslib_1.__importDefault(require("../getLoginInfo"));
const PHXGrpcClientV3_1 = require("../GRPC/PHXGrpcClientV3");
const school_year_v3_1 = require("../../../query/school-year-v3");
function PHXGetPrevCurrentNextYearV3() {
    const schoolInfo = (0, getLoginInfo_1.default)();
    const [listSchoolYear, setListSchoolYear] = (0, react_1.useState)([]);
    const [schoolYearData, setSchoolYearData] = (0, react_1.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);
    (0, react_1.useEffect)(() => {
        (0, PHXGrpcClientV3_1.PHXClientQueryV3)({
            query: school_year_v3_1.getActiveAndNextSchoolYearV3,
            variables: {
                endAt: prevYearDate,
                startAt: nextYearDate,
                school_id: schoolInfo === null || schoolInfo === void 0 ? void 0 : schoolInfo.school_id,
            },
        }).then((res) => {
            setSchoolYearData(res.data);
        });
    }, []);
    (0, react_1.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;
}
exports.default = PHXGetPrevCurrentNextYearV3;
//# sourceMappingURL=getPrevCurrentNextSchoolYearV3.js.map