"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectionPopup = void 0;
var react_1 = __importDefault(require("react"));
var classnames_1 = __importDefault(require("classnames"));
var ui_i18n_1 = __importDefault(require("ui-i18n"));
var Popover_1 = __importDefault(require("@mui/material/Popover"));
var InfoIcon_1 = require("../InfoIcon");
var SearchInput_1 = require("../SearchInput");
var useCssVariableStyles_1 = require("../hooks/useCssVariableStyles/useCssVariableStyles");
var styles_1 = require("@mui/styles");
var SelectionPopup_module_css_1 = __importDefault(require("./SelectionPopup.module.css"));
var SelectionPopup = function (_a) {
    var _b;
    var title = _a.title, className = _a.className, onSearch = _a.onSearch, hideSearchInput = _a.hideSearchInput, inputPlaceholder = _a.inputPlaceholder, _c = _a.headerPlacement, headerPlacement = _c === void 0 ? 'top' : _c, containerWidth = _a.containerWidth, _d = _a.containerHeight, containerHeight = _d === void 0 ? 553 : _d, searchInputOnKeyDown = _a.searchInputOnKeyDown, children = _a.children, searchInputRef = _a.searchInputRef, _e = _a.anchorOrigin, anchorOrigin = _e === void 0 ? {
        vertical: 'top',
        horizontal: 'right'
    } : _e, _f = _a.transformOrigin, transformOrigin = _f === void 0 ? {
        vertical: 'top',
        horizontal: 'right'
    } : _f, additionalInfo = _a.additionalInfo, toolbar = _a.toolbar, otherProps = __rest(_a, ["title", "className", "onSearch", "hideSearchInput", "inputPlaceholder", "headerPlacement", "containerWidth", "containerHeight", "searchInputOnKeyDown", "children", "searchInputRef", "anchorOrigin", "transformOrigin", "additionalInfo", "toolbar"]);
    var currentTheme = (0, styles_1.useTheme)();
    var variableStyles = (0, useCssVariableStyles_1.useCssVariableStyles)({
        '--container-height': "".concat(containerHeight, "px")
    });
    var header = (react_1.default.createElement(react_1.default.Fragment, null,
        toolbar,
        title && !toolbar && (react_1.default.createElement("div", { className: SelectionPopup_module_css_1.default.header },
            title,
            additionalInfo && react_1.default.createElement(InfoIcon_1.InfoIcon, { className: SelectionPopup_module_css_1.default.infoIcon, tooltipTitle: additionalInfo }))),
        !hideSearchInput && (react_1.default.createElement(SearchInput_1.SearchInput, { onSearch: onSearch, autofocus: true, onKeyDown: searchInputOnKeyDown, inputRef: searchInputRef, classes: { root: SelectionPopup_module_css_1.default.searchInputContainer }, placeholder: inputPlaceholder || ui_i18n_1.default.text('Search & add attributes'), height: 40 }))));
    return (react_1.default.createElement(Popover_1.default, __assign({ anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, "data-mui-color-scheme": (_b = currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.palette) === null || _b === void 0 ? void 0 : _b.mode }, otherProps),
        react_1.default.createElement("div", { className: (0, classnames_1.default)(SelectionPopup_module_css_1.default.container, className), style: __assign(__assign({}, variableStyles), { width: containerWidth }) },
            headerPlacement === 'top' && header,
            react_1.default.createElement("div", { className: SelectionPopup_module_css_1.default.list }, children),
            headerPlacement === 'bottom' && header)));
};
exports.SelectionPopup = SelectionPopup;
