import { useContext, useMemo } from 'react';
import { checkCanCreateAttribute, checkCanDeleteAttribute, checkCanEditAttribute } from '@reltio/mdm-sdk';
import { useAttributeValueConfigPermissions } from '../contexts/ConfigPermissionsContext';
import { AlwaysVisibleAttributesContext } from '../contexts/AlwaysVisibleAttributesContext';
export var useAttributeValuePermissions = function (_a) {
    var attributeType = _a.attributeType, attributeValue = _a.attributeValue, isReltioCrosswalk = _a.isReltioCrosswalk, mode = _a.mode;
    var _b = useAttributeValueConfigPermissions(attributeValue.uri), configCanCreate = _b.canCreate, configCanUpdate = _b.canUpdate, configCanDelete = _b.canDelete;
    var alwaysVisibleAttributes = useContext(AlwaysVisibleAttributesContext);
    var isAlwaysVisible = useMemo(function () { return alwaysVisibleAttributes === null || alwaysVisibleAttributes === void 0 ? void 0 : alwaysVisibleAttributes.includes(attributeType.uri); }, [attributeType.uri, alwaysVisibleAttributes]);
    var canCreate = configCanCreate && checkCanCreateAttribute({ attributeType: attributeType, mode: mode });
    var canEdit = configCanUpdate &&
        checkCanEditAttribute({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
    var canDelete = configCanDelete &&
        checkCanDeleteAttribute({ attributeType: attributeType, attributeValue: attributeValue, mode: mode, isReltioCrosswalk: isReltioCrosswalk, isAlwaysVisible: isAlwaysVisible });
    return { canCreate: canCreate, canEdit: canEdit, canDelete: canDelete };
};
