"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useValidatorGroups = exports.useCeloPreloadData = void 0;
const react_1 = require("react");
const preload_1 = require("./preload");
function useCeloPreloadData() {
    const [state, setState] = (0, react_1.useState)(preload_1.getCurrentCeloPreloadData);
    (0, react_1.useEffect)(() => {
        const sub = (0, preload_1.getCeloPreloadDataUpdates)().subscribe(data => {
            setState(data);
        });
        return () => sub.unsubscribe();
    }, []);
    return state;
}
exports.useCeloPreloadData = useCeloPreloadData;
function useValidatorGroups(search) {
    const { validatorGroups } = useCeloPreloadData();
    return (0, react_1.useMemo)(() => {
        if (validatorGroups.length === 0 || !search) {
            return validatorGroups;
        }
        const lowercaseSearch = search.toLowerCase();
        return validatorGroups.filter(vg => vg.name.toLowerCase().includes(lowercaseSearch) ||
            vg.address.toLowerCase().includes(lowercaseSearch));
    }, [validatorGroups, search]);
}
exports.useValidatorGroups = useValidatorGroups;
//# sourceMappingURL=react.js.map