"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useAttributeValuePermissions = void 0;
var react_1 = require("react");
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var ConfigPermissionsContext_1 = require("../contexts/ConfigPermissionsContext");
var AlwaysVisibleAttributesContext_1 = require("../contexts/AlwaysVisibleAttributesContext");
var useAttributeValuePermissions = function (_a) {
    var attributeType = _a.attributeType, attributeValue = _a.attributeValue, isReltioCrosswalk = _a.isReltioCrosswalk, mode = _a.mode;
    var _b = (0, ConfigPermissionsContext_1.useAttributeValueConfigPermissions)(attributeValue.uri), configCanCreate = _b.canCreate, configCanUpdate = _b.canUpdate, configCanDelete = _b.canDelete;
    var alwaysVisibleAttributes = (0, react_1.useContext)(AlwaysVisibleAttributesContext_1.AlwaysVisibleAttributesContext);
    var isAlwaysVisible = (0, react_1.useMemo)(function () { return alwaysVisibleAttributes === null || alwaysVisibleAttributes === void 0 ? void 0 : alwaysVisibleAttributes.includes(attributeType.uri); }, [attributeType.uri, alwaysVisibleAttributes]);
    var canCreate = configCanCreate && (0, mdm_sdk_1.checkCanCreateAttribute)({ attributeType: attributeType, mode: mode });
    var canEdit = configCanUpdate &&
        (0, mdm_sdk_1.checkCanEditAttribute)({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
    var canDelete = configCanDelete &&
        (0, mdm_sdk_1.checkCanDeleteAttribute)({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
    return { canCreate: canCreate, canEdit: canEdit, canDelete: canDelete };
};
exports.useAttributeValuePermissions = useAttributeValuePermissions;
