"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 KeepTypingSuggestion_1 = require("./KeepTypingSuggestion");
var errors_1 = require("../../../core/utils/errors");
var SingleSuggestion_1 = require("./SingleSuggestion");
var TakenOrInvalidSuggestion_1 = require("./TakenOrInvalidSuggestion");
var InvalidForConnectionSuggestion_1 = require("./InvalidForConnectionSuggestion");
var classFor_1 = require("../../utils/classFor");
var SuggestionGroup_1 = require("./SuggestionGroup");
exports.SuggestionComponent = function (_a) {
    var onCreateClick = _a.onCreateClick, onConnectClick = _a.onConnectClick, actions = _a.actions, suggestion = _a.suggestion;
    actions.includes(commons_1.WalletSuggestionAction.connect) && commons_1.ensureNotFalsy(onConnectClick, errors_1.MissingParameter, 'onConnectClick');
    actions.includes(commons_1.WalletSuggestionAction.create) && commons_1.ensureNotFalsy(onCreateClick, errors_1.MissingParameter, 'onCreateClick');
    var _b = __read(react_1.useState(''), 2), selectedSuggestion = _b[0], setSelectedSuggestion = _b[1];
    var handleConnectClick = function (ensName) {
        setSelectedSuggestion(ensName);
        onConnectClick(ensName);
    };
    var handleCreateClick = function (ensName) {
        setSelectedSuggestion(ensName);
        onCreateClick(ensName);
    };
    switch (suggestion.kind) {
        case 'None':
            return null;
        case 'KeepTyping':
            return react_1.default.createElement(KeepTypingSuggestion_1.KeepTypingSuggestion, null);
        case 'TakenOrInvalid':
            return react_1.default.createElement(TakenOrInvalidSuggestion_1.TakenOrInvalidSuggestion, null);
        case 'InvalidForConnection':
            return react_1.default.createElement(InvalidForConnectionSuggestion_1.InvalidForConnectionSuggestion, null);
        case 'Connection':
            return (react_1.default.createElement("ul", { className: classFor_1.classForComponent('suggestions-list') },
                react_1.default.createElement("li", { className: classFor_1.classForComponent('suggestions-item') },
                    react_1.default.createElement(SingleSuggestion_1.SingleSuggestion, { hint: 'Do you want to connect to this account?', operationType: 'connect', onClick: handleConnectClick, suggestion: suggestion.name, selectedSuggestion: selectedSuggestion }))));
        case 'Creation':
            return (react_1.default.createElement("ul", { className: classFor_1.classForComponent('suggestions-list') },
                react_1.default.createElement("li", { className: classFor_1.classForComponent('suggestions-item') },
                    react_1.default.createElement(SingleSuggestion_1.SingleSuggestion, { hint: 'This username is available', operationType: 'create new', onClick: handleCreateClick, suggestion: suggestion.name, selectedSuggestion: selectedSuggestion }))));
        case 'Available':
            var createSuggestions = suggestion.suggestions.filter(function (element) { return element.kind === 'Creation'; });
            var connectSuggestions = suggestion.suggestions.filter(function (element) { return element.kind === 'Connection'; });
            return (react_1.default.createElement("div", { className: classFor_1.classForComponent('suggestions-wrapper') },
                createSuggestions.length !== 0 &&
                    react_1.default.createElement(SuggestionGroup_1.SuggestionGroup, { suggestions: createSuggestions, label: 'New user?', selectedSuggestion: selectedSuggestion, type: 'create new', onClick: handleCreateClick }),
                connectSuggestions.length !== 0 &&
                    react_1.default.createElement(SuggestionGroup_1.SuggestionGroup, { suggestions: connectSuggestions, label: 'Already have an account', selectedSuggestion: selectedSuggestion, type: 'connect', onClick: handleConnectClick })));
    }
};
exports.default = exports.SuggestionComponent;
//# sourceMappingURL=SuggestionComponent.js.map