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 { ensureNotFalsy, WalletSuggestionAction } from '@universal-login/commons';
import { KeepTypingSuggestion } from './KeepTypingSuggestion';
import { MissingParameter } from '../../../core/utils/errors';
import { SingleSuggestion } from './SingleSuggestion';
import { TakenOrInvalidSuggestion } from './TakenOrInvalidSuggestion';
import { InvalidForConnectionSuggestion } from './InvalidForConnectionSuggestion';
import { classForComponent } from '../../utils/classFor';
import { SuggestionGroup } from './SuggestionGroup';
export var SuggestionComponent = function (_a) {
    var onCreateClick = _a.onCreateClick, onConnectClick = _a.onConnectClick, actions = _a.actions, suggestion = _a.suggestion;
    actions.includes(WalletSuggestionAction.connect) && ensureNotFalsy(onConnectClick, MissingParameter, 'onConnectClick');
    actions.includes(WalletSuggestionAction.create) && ensureNotFalsy(onCreateClick, MissingParameter, 'onCreateClick');
    var _b = __read(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.createElement(KeepTypingSuggestion, null);
        case 'TakenOrInvalid':
            return React.createElement(TakenOrInvalidSuggestion, null);
        case 'InvalidForConnection':
            return React.createElement(InvalidForConnectionSuggestion, null);
        case 'Connection':
            return (React.createElement("ul", { className: classForComponent('suggestions-list') },
                React.createElement("li", { className: classForComponent('suggestions-item') },
                    React.createElement(SingleSuggestion, { hint: 'Do you want to connect to this account?', operationType: 'connect', onClick: handleConnectClick, suggestion: suggestion.name, selectedSuggestion: selectedSuggestion }))));
        case 'Creation':
            return (React.createElement("ul", { className: classForComponent('suggestions-list') },
                React.createElement("li", { className: classForComponent('suggestions-item') },
                    React.createElement(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.createElement("div", { className: classForComponent('suggestions-wrapper') },
                createSuggestions.length !== 0 &&
                    React.createElement(SuggestionGroup, { suggestions: createSuggestions, label: 'New user?', selectedSuggestion: selectedSuggestion, type: 'create new', onClick: handleCreateClick }),
                connectSuggestions.length !== 0 &&
                    React.createElement(SuggestionGroup, { suggestions: connectSuggestions, label: 'Already have an account', selectedSuggestion: selectedSuggestion, type: 'connect', onClick: handleConnectClick })));
    }
};
export default SuggestionComponent;
//# sourceMappingURL=SuggestionComponent.js.map