"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useUsers = void 0;
var react_1 = require("react");
var memoize_one_1 = __importDefault(require("memoize-one"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var MdmModuleContext_1 = require("../../contexts/MdmModuleContext");
var getAllUsersForTenantMemoized = (0, memoize_one_1.default)(function (tenant, servicesPath) { return (0, mdm_sdk_1.getAllUsersForTenant)({ tenant: tenant, servicesPath: servicesPath }); });
var useUsers = function () {
    var _a = (0, react_1.useState)([]), users = _a[0], setUsers = _a[1];
    var tenant = (0, MdmModuleContext_1.useMdmTenant)();
    var servicesPath = (0, MdmModuleContext_1.useMdmServicesPath)();
    var onError = function (e) {
        console.warn('Users error', e);
        setUsers([]);
    };
    (0, react_1.useEffect)(function () {
        getAllUsersForTenantMemoized(tenant, servicesPath)
            .then(function (users) { return setUsers(users); })
            .catch(onError);
    }, [tenant, servicesPath]);
    return users;
};
exports.useUsers = useUsers;
