import { useEffect, useState } from 'react';
import PHXFuncGetLoggedInfo from '../../Func/getLoginInfo';
import { PHXClientQueryV3 } from '../../Func/GRPC/PHXGrpcClientV3';
import { GET_USER_SEGMENT_TARGET } from '../query';
import { normalizeVietnameseText } from '../../SelectWithAction/remove-vn-tones';
export const useGetUserTarget = () => {
    const [listUserTarget, setListUserTarget] = useState([]);
    const [loading, setLoading] = useState(false);
    const [searchQuery, setSearchQuery] = useState('');
    const handleFilter = (value) => {
        setSearchQuery(value || '');
    };
    const userInfo = PHXFuncGetLoggedInfo();
    const fetchInitData = async () => {
        setLoading(true);
        try {
            const { data } = await PHXClientQueryV3({
                query: GET_USER_SEGMENT_TARGET,
                variables: {
                    schoolId: userInfo.school_id,
                    query: `%${normalizeVietnameseText(searchQuery)}%`,
                },
            });
            setListUserTarget(data.user_segment_target);
        }
        catch (error) {
            console.log(error);
        }
        finally {
            setLoading(false);
        }
    };
    useEffect(() => {
        fetchInitData();
    }, [searchQuery]);
    return {
        listUserTarget,
        loading,
        searchQuery,
        fetchInitData,
        handleFilter,
    };
};
//# sourceMappingURL=UseGetUserTarget.js.map