"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useGetUserTarget = void 0;
const tslib_1 = require("tslib");
const react_1 = require("react");
const getLoginInfo_1 = tslib_1.__importDefault(require("../../Func/getLoginInfo"));
const PHXGrpcClientV3_1 = require("../../Func/GRPC/PHXGrpcClientV3");
const query_1 = require("../query");
const remove_vn_tones_1 = require("../../SelectWithAction/remove-vn-tones");
const useGetUserTarget = () => {
    const [listUserTarget, setListUserTarget] = (0, react_1.useState)([]);
    const [loading, setLoading] = (0, react_1.useState)(false);
    const [searchQuery, setSearchQuery] = (0, react_1.useState)('');
    const handleFilter = (value) => {
        setSearchQuery(value || '');
    };
    const userInfo = (0, getLoginInfo_1.default)();
    const fetchInitData = async () => {
        setLoading(true);
        try {
            const { data } = await (0, PHXGrpcClientV3_1.PHXClientQueryV3)({
                query: query_1.GET_USER_SEGMENT_TARGET,
                variables: {
                    schoolId: userInfo.school_id,
                    query: `%${(0, remove_vn_tones_1.normalizeVietnameseText)(searchQuery)}%`,
                },
            });
            setListUserTarget(data.user_segment_target);
        }
        catch (error) {
            console.log(error);
        }
        finally {
            setLoading(false);
        }
    };
    (0, react_1.useEffect)(() => {
        fetchInitData();
    }, [searchQuery]);
    return {
        listUserTarget,
        loading,
        searchQuery,
        fetchInitData,
        handleFilter,
    };
};
exports.useGetUserTarget = useGetUserTarget;
//# sourceMappingURL=UseGetUserTarget.js.map