"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DataTenantBadge = void 0;
var react_1 = __importDefault(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var ramda_1 = require("ramda");
var Typography_1 = __importDefault(require("@mui/material/Typography"));
var Tooltip_1 = __importDefault(require("@mui/material/Tooltip"));
var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
var styles_1 = require("./styles");
var addDataTenantPrefix = function (label) { return "DT:".concat((0, ramda_1.slice)(0, 1, label)); };
var DataTenantBadge = function (_a) {
    var dataTenantId = _a.dataTenantId, className = _a.className;
    var styles = (0, styles_1.useStyles)({ dataTenantId: dataTenantId });
    var dataTenants = (0, MdmModuleContext_1.useMdmDataTenants)();
    var dataTenant = (0, ramda_1.pipe)((0, ramda_1.defaultTo)([]), (0, ramda_1.find)((0, ramda_1.propEq)('id', dataTenantId)))(dataTenants);
    var label = (0, ramda_1.pipe)((0, ramda_1.propOr)('', 'label'), ramda_1.toUpper, (0, ramda_1.ifElse)((0, ramda_1.startsWith)('DT:'), (0, ramda_1.slice)(0, 4), addDataTenantPrefix))(dataTenant);
    var content = (react_1.default.createElement("div", { className: (0, classnames_1.default)(styles.root, className) },
        react_1.default.createElement(Typography_1.default, { variant: "body2" }, label)));
    var showTooltip = !!(dataTenant === null || dataTenant === void 0 ? void 0 : dataTenant.label);
    if (!showTooltip) {
        return content;
    }
    return (react_1.default.createElement(Tooltip_1.default, { "data-reltio-id": "reltio-data-tenant-bage-tooltip", title: dataTenant.label }, content));
};
exports.DataTenantBadge = DataTenantBadge;
