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;
};
import React, { useState } from 'react';
import { EMOJI_COLORS, getEmojiSet, getColoredEmojiCode, CATEGORIES } from '@universal-login/commons';
import { getStyleForTopLevelComponent } from '../../core/utils/getStyleForTopLevelComponent';
import { Emoji } from '../commons/Emoji';
import '../styles/emoji.sass';
import '../styles/emojiDefaults.sass';
import '../styles/colors.css';
export var EmojiKeyboard = function (_a) {
    var onEmojiClick = _a.onEmojiClick, className = _a.className;
    var _b = __read(useState(0), 2), category = _b[0], setCategory = _b[1];
    var _c = __read(useState(undefined), 2), palette = _c[0], setPalette = _c[1];
    var renderKeyboard = function () {
        return getEmojiSet(category).map(function (emojiCode, index) { return renderInputEmoji(emojiCode, index); });
    };
    var renderInputEmoji = function (emojiCode, index) { return (React.createElement("li", { className: "emoji-item", key: "securityCodeWithFakes_" + emojiCode },
        React.createElement("button", { id: "btn-" + emojiCode, onClick: function () { return palette === index ? setPalette(undefined) : setPalette(index); }, className: "emoji-keyboard-button" },
            React.createElement(Emoji, { code: emojiCode })),
        palette === index
            ? React.createElement("ul", { className: "emoji-keyboard-color-row" }, renderColors(emojiCode))
            : null)); };
    var renderColors = function (emojiCode) { return (EMOJI_COLORS.map(function (colorString, colorIndex) { return (React.createElement("li", { key: "li-color-" + colorIndex, className: "emoji-keyboard-color-item" },
        React.createElement("button", { style: { backgroundColor: colorString }, id: "btn-color-" + colorIndex, onClick: function () { return onColorClick(getColoredEmojiCode(emojiCode, colorIndex)); }, className: "emoji-keyboard-color-button" }))); })); };
    var onColorClick = function (coloredEmojiCode) {
        onEmojiClick(coloredEmojiCode);
        setPalette(undefined);
    };
    var renderCategories = function () { return (CATEGORIES.map(function (_a, index) {
        var name = _a.name;
        return (React.createElement("li", { key: "li-category-" + name, className: "emoji-category-item " + (category === index ? 'active' : '') },
            React.createElement("button", { onClick: function () { return setCategory(index); }, className: "emoji-category-button emoji-category-" + name.toLowerCase() }, name)));
    })); };
    return (React.createElement("div", { className: "universal-login-emojis" },
        React.createElement("div", { className: getStyleForTopLevelComponent(className) },
            React.createElement("div", { className: "emoji-keyboard" },
                React.createElement("ul", { className: "emoji-category-row" }, renderCategories()),
                React.createElement("div", { className: "emoji-keyboard-row" },
                    React.createElement("button", { disabled: category === 0, onClick: function () { return setCategory(category - 1); }, className: "emoji-keyboard-arrow-button emoji-keyboard-prev" }),
                    React.createElement("ul", { className: "emojis-keyboard-batch" }, renderKeyboard()),
                    React.createElement("button", { disabled: category === 4, onClick: function () { return setCategory(category + 1); }, className: "emoji-keyboard-arrow-button emoji-keyboard-next" }))))));
};
//# sourceMappingURL=EmojiKeyboard.js.map