"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RolesEditor = void 0;
var react_1 = __importStar(require("react"));
var ramda_1 = require("ramda");
var Typography_1 = __importDefault(require("@mui/material/Typography"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var mdm_sdk_1 = require("@reltio/mdm-sdk");
var SmallIconButton_1 = require("../SmallIconButton");
var Delete_1 = __importDefault(require("@mui/icons-material/Delete"));
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var RolesInput_1 = require("../RolesInput/RolesInput");
var RolesEditor_module_css_1 = __importDefault(require("./RolesEditor.module.css"));
var RolesEditor = function (_a) {
    var values = _a.values, onChange = _a.onChange, onDelete = _a.onDelete, state = _a.state;
    var entity = (0, MdmModuleContext_1.useMdmEntity)();
    var entityUri = entity.uri;
    var edited = state === 'edited';
    var handleChange = (0, react_1.useCallback)(function (values) {
        var roles = (values === null || values === void 0 ? void 0 : values.map((0, ramda_1.prop)('value'))) || [];
        onChange({
            value: roles,
            attributeType: mdm_sdk_1.EntityAttrTypes.roles,
            uri: entityUri
        });
    }, [entityUri, onChange]);
    var handleDelete = (0, react_1.useCallback)(function () {
        onDelete({ uri: entityUri, attributeType: mdm_sdk_1.EntityAttrTypes.roles });
    }, [entityUri, onDelete]);
    return (react_1.default.createElement("div", { className: RolesEditor_module_css_1.default.container, "data-reltio-id": "reltio-attribute-value" },
        react_1.default.createElement(RolesInput_1.RolesInput, { value: values, onChange: handleChange }),
        edited && (react_1.default.createElement(Typography_1.default, { variant: "caption", className: RolesEditor_module_css_1.default.editedLabel },
            "(",
            ui_i18n_1.default.text('edited'),
            ")")),
        !!onDelete && (react_1.default.createElement(SmallIconButton_1.SmallIconButton, { "data-reltio-id": "reltio-roles-delete-button", className: RolesEditor_module_css_1.default.deleteButton, icon: Delete_1.default, onClick: handleDelete, size: "L" }))));
};
exports.RolesEditor = RolesEditor;
