import { useEffect, useState } from 'react';
import memoizeOne from 'memoize-one';
import { getAllUsersForTenant } from '@reltio/mdm-sdk';
import { useMdmServicesPath, useMdmTenant } from '../../contexts/MdmModuleContext';
var getAllUsersForTenantMemoized = memoizeOne(function (tenant, servicesPath) { return getAllUsersForTenant({ tenant: tenant, servicesPath: servicesPath }); });
export var useUsers = function () {
    var _a = useState([]), users = _a[0], setUsers = _a[1];
    var tenant = useMdmTenant();
    var servicesPath = useMdmServicesPath();
    var onError = function (e) {
        console.warn('Users error', e);
        setUsers([]);
    };
    useEffect(function () {
        getAllUsersForTenantMemoized(tenant, servicesPath)
            .then(function (users) { return setUsers(users); })
            .catch(onError);
    }, [tenant, servicesPath]);
    return users;
};
