"use strict";
var __read = (this && this.__read) || function (o, n) {
    var m = typeof Symbol === "function" && o[Symbol.iterator];
    if (!m) return o;
    var i = m.call(o), r, ar = [], e;
    try {
        while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
    }
    catch (error) { e = { error: error }; }
    finally {
        try {
            if (r && !r.done && (m = i["return"])) m.call(i);
        }
        finally { if (e) throw e.error; }
    }
    return ar;
};
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
var react_1 = __importStar(require("react"));
var commons_1 = require("@universal-login/commons");
var getStyleForTopLevelComponent_1 = require("../../core/utils/getStyleForTopLevelComponent");
var Emoji_1 = require("../commons/Emoji");
require("../styles/emoji.sass");
require("../styles/emojiDefaults.sass");
require("../styles/colors.css");
exports.EmojiKeyboard = function (_a) {
    var onEmojiClick = _a.onEmojiClick, className = _a.className;
    var _b = __read(react_1.useState(0), 2), category = _b[0], setCategory = _b[1];
    var _c = __read(react_1.useState(undefined), 2), palette = _c[0], setPalette = _c[1];
    var renderKeyboard = function () {
        return commons_1.getEmojiSet(category).map(function (emojiCode, index) { return renderInputEmoji(emojiCode, index); });
    };
    var renderInputEmoji = function (emojiCode, index) { return (react_1.default.createElement("li", { className: "emoji-item", key: "securityCodeWithFakes_" + emojiCode },
        react_1.default.createElement("button", { id: "btn-" + emojiCode, onClick: function () { return palette === index ? setPalette(undefined) : setPalette(index); }, className: "emoji-keyboard-button" },
            react_1.default.createElement(Emoji_1.Emoji, { code: emojiCode })),
        palette === index
            ? react_1.default.createElement("ul", { className: "emoji-keyboard-color-row" }, renderColors(emojiCode))
            : null)); };
    var renderColors = function (emojiCode) { return (commons_1.EMOJI_COLORS.map(function (colorString, colorIndex) { return (react_1.default.createElement("li", { key: "li-color-" + colorIndex, className: "emoji-keyboard-color-item" },
        react_1.default.createElement("button", { style: { backgroundColor: colorString }, id: "btn-color-" + colorIndex, onClick: function () { return onColorClick(commons_1.getColoredEmojiCode(emojiCode, colorIndex)); }, className: "emoji-keyboard-color-button" }))); })); };
    var onColorClick = function (coloredEmojiCode) {
        onEmojiClick(coloredEmojiCode);
        setPalette(undefined);
    };
    var renderCategories = function () { return (commons_1.CATEGORIES.map(function (_a, index) {
        var name = _a.name;
        return (react_1.default.createElement("li", { key: "li-category-" + name, className: "emoji-category-item " + (category === index ? 'active' : '') },
            react_1.default.createElement("button", { onClick: function () { return setCategory(index); }, className: "emoji-category-button emoji-category-" + name.toLowerCase() }, name)));
    })); };
    return (react_1.default.createElement("div", { className: "universal-login-emojis" },
        react_1.default.createElement("div", { className: getStyleForTopLevelComponent_1.getStyleForTopLevelComponent(className) },
            react_1.default.createElement("div", { className: "emoji-keyboard" },
                react_1.default.createElement("ul", { className: "emoji-category-row" }, renderCategories()),
                react_1.default.createElement("div", { className: "emoji-keyboard-row" },
                    react_1.default.createElement("button", { disabled: category === 0, onClick: function () { return setCategory(category - 1); }, className: "emoji-keyboard-arrow-button emoji-keyboard-prev" }),
                    react_1.default.createElement("ul", { className: "emojis-keyboard-batch" }, renderKeyboard()),
                    react_1.default.createElement("button", { disabled: category === 4, onClick: function () { return setCategory(category + 1); }, className: "emoji-keyboard-arrow-button emoji-keyboard-next" }))))));
};
//# sourceMappingURL=EmojiKeyboard.js.map