"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 __spread = (this && this.__spread) || function () {
    for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
    return ar;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var EmojiPlaceholders_1 = require("./EmojiPlaceholders");
var react_1 = __importDefault(require("react"));
var EmojiKeyboard_1 = require("./EmojiKeyboard");
var EmojiPanelWithFakes_1 = require("./EmojiPanelWithFakes");
var commons_1 = require("@universal-login/commons");
exports.EmojiInput = function (_a) {
    var value = _a.value, onChange = _a.onChange, publicKey = _a.publicKey, className = _a.className;
    var onEmojiAdd = function (code) {
        if (value.length < commons_1.SECURITY_CODE_LENGTH) {
            onChange(__spread(value, [code]));
        }
    };
    var onEmojiRemove = function (index) {
        if (value.length >= 0) {
            onChange(removeAtIndex(value, index));
        }
    };
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(EmojiPlaceholders_1.EmojiPlaceholders, { enteredCode: value, publicKey: publicKey, onEmojiClick: onEmojiRemove, className: className }),
        publicKey
            ? (react_1.default.createElement(EmojiPanelWithFakes_1.EmojiPanelWithFakes, { publicKey: publicKey, onEmojiClick: onEmojiAdd, className: className }))
            : react_1.default.createElement(EmojiKeyboard_1.EmojiKeyboard, { onEmojiClick: onEmojiAdd, className: className })));
};
function removeAtIndex(array, index) {
    return __spread(array.slice(0, index), array.slice(index + 1));
}
//# sourceMappingURL=EmojiInput.js.map