"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
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 = __importStar(require("react"));
var TutorialContent_1 = require("./TutorialContent");
var TutorialTopicIntro_1 = require("../Tutorial/TutorialTopicIntro");
var TutorialInfo_1 = require("../Tutorial/TutorialInfo");
var TutorialQuestion_1 = require("../Tutorial/TutorialQuestion");
var TutorialTopicCompleted_1 = require("../Tutorial/TutorialTopicCompleted");
var TokenTutorialStyledComponents_1 = require("./TokenTutorialStyledComponents");
var QUIZ_SECTION;
(function (QUIZ_SECTION) {
    QUIZ_SECTION["INTRO"] = "intro";
    QUIZ_SECTION["TUTORIAL"] = "tutorial";
    QUIZ_SECTION["QUIZ"] = "quiz";
    QUIZ_SECTION["COMPLETED"] = "completed";
})(QUIZ_SECTION = exports.QUIZ_SECTION || (exports.QUIZ_SECTION = {}));
var TokenTutorialQuiz = /** @class */ (function (_super) {
    __extends(TokenTutorialQuiz, _super);
    function TokenTutorialQuiz(props) {
        var _this = _super.call(this, props) || this;
        _this.prev = function () {
            switch (_this.state.activeSection) {
                case QUIZ_SECTION.TUTORIAL:
                    if (_this.state.slideIdx === 0) {
                        _this.setState({ activeSection: QUIZ_SECTION.INTRO, slideIdx: 0 });
                    }
                    else {
                        _this.setState({ slideIdx: _this.state.slideIdx - 1 });
                    }
                    break;
                case QUIZ_SECTION.QUIZ:
                    _this.setState({
                        activeSection: QUIZ_SECTION.TUTORIAL,
                        slideIdx: 0,
                    });
                    break;
                default:
                    _this.setState({ activeSection: QUIZ_SECTION.INTRO, slideIdx: 0 });
            }
        };
        _this.next = function () {
            switch (_this.state.activeSection) {
                case QUIZ_SECTION.INTRO:
                    _this.setState({ slideIdx: 0, activeSection: QUIZ_SECTION.TUTORIAL });
                    break;
                case QUIZ_SECTION.TUTORIAL:
                    if (_this.state.slideIdx + 1 < TutorialContent_1.TutorialContent[_this.state.topicIdx].tutorials.length) {
                        _this.setState({ slideIdx: _this.state.slideIdx + 1 });
                    }
                    else {
                        _this.setState({ slideIdx: _this.state.quizSlide, activeSection: QUIZ_SECTION.QUIZ });
                    }
                    break;
                case QUIZ_SECTION.QUIZ:
                    if (_this.state.slideIdx + 1 < TutorialContent_1.TutorialContent[_this.state.topicIdx].questions.length) {
                        _this.setState({
                            slideIdx: _this.state.slideIdx + 1,
                            quizSlide: _this.state.quizSlide + 1,
                        });
                        _this.props.handleSaveQuizState(TutorialContent_1.TutorialContent[_this.state.topicIdx].quizId, _this.state.slideIdx, false);
                    }
                    else {
                        _this.setState({ slideIdx: 0, activeSection: QUIZ_SECTION.COMPLETED });
                        _this.props.handleSaveQuizState(TutorialContent_1.TutorialContent[_this.state.topicIdx].quizId, _this.state.slideIdx, true);
                    }
                    break;
                default:
                    _this.setState({ slideIdx: 0, activeSection: QUIZ_SECTION.INTRO });
            }
        };
        _this.skipTutorial = function () {
            _this.setState({ slideIdx: _this.state.quizSlide, activeSection: QUIZ_SECTION.QUIZ });
        };
        _this.nextTopic = function () {
            _this.props.skipTutorial
                ? _this.setState({
                    topicIdx: _this.state.topicIdx + 1,
                    slideIdx: 0,
                    activeSection: QUIZ_SECTION.QUIZ,
                    quizSlide: 0,
                })
                : _this.setState({
                    topicIdx: _this.state.topicIdx + 1,
                    slideIdx: 0,
                    activeSection: QUIZ_SECTION.INTRO,
                    quizSlide: 0,
                });
        };
        var _a = _this.props, topicIdx = _a.topicIdx, activeSection = _a.activeSection, quizSlide = _a.quizSlide;
        _this.state = {
            topicIdx: topicIdx,
            slideIdx: 0,
            activeSection: activeSection,
            quizSlide: quizSlide,
        };
        return _this;
    }
    TokenTutorialQuiz.prototype.render = function () {
        var _this = this;
        var _a = this.state, topicIdx = _a.topicIdx, slideIdx = _a.slideIdx, activeSection = _a.activeSection;
        var lastTopic = topicIdx === this.props.totalTopics ? true : false;
        switch (activeSection) {
            case QUIZ_SECTION.INTRO:
                return (React.createElement(TokenTutorialStyledComponents_1.TutorialContain, null,
                    React.createElement(TutorialTopicIntro_1.TutorialTopicIntro, { headerText: TutorialContent_1.TutorialContent[topicIdx].tutorialIntro.header, infoText: TutorialContent_1.TutorialContent[topicIdx].tutorialIntro.content, onClickNext: function () { return _this.next(); }, onClickSkipTutorial: function () { return _this.skipTutorial(); }, activeSlide: 0, totalSlides: 1 })));
            case QUIZ_SECTION.TUTORIAL:
                return (React.createElement(TokenTutorialStyledComponents_1.TutorialContain, null,
                    React.createElement(TutorialInfo_1.TutorialInfo, { content: TutorialContent_1.TutorialContent[topicIdx].tutorials[slideIdx].content, onClickPrev: function () { return _this.prev(); }, onClickNext: function () { return _this.next(); }, activeSlide: slideIdx + 1, totalSlides: TutorialContent_1.TutorialContent[topicIdx].tutorials.length })));
            case QUIZ_SECTION.QUIZ:
                return (React.createElement(TokenTutorialStyledComponents_1.TutorialContain, null,
                    React.createElement(TutorialQuestion_1.TutorialQuestion, { quizName: TutorialContent_1.TutorialContent[topicIdx].name, quizId: TutorialContent_1.TutorialContent[topicIdx].quizId, question: TutorialContent_1.TutorialContent[topicIdx].questions[slideIdx].question, options: TutorialContent_1.TutorialContent[topicIdx].questions[slideIdx].options, answer: TutorialContent_1.TutorialContent[topicIdx].questions[slideIdx].answer, onClickPrev: function () { return _this.prev(); }, onClickNext: function () { return _this.next(); }, activeSlide: slideIdx + 1, totalSlides: TutorialContent_1.TutorialContent[topicIdx].questions.length })));
            case QUIZ_SECTION.COMPLETED:
                return (React.createElement(TokenTutorialStyledComponents_1.TutorialContain, null,
                    React.createElement(TutorialTopicCompleted_1.TutorialTopicCompleted, { completedHeader: TutorialContent_1.TutorialContent[topicIdx].completed.header, completedText: TutorialContent_1.TutorialContent[topicIdx].completed.content, continueBtnText: TutorialContent_1.TutorialContent[topicIdx].completed.btnText, lastTopic: lastTopic, onClickNextTopic: function () { return _this.nextTopic(); }, handleClose: this.props.handleClose })));
            default:
                return React.createElement(React.Fragment, null);
        }
    };
    return TokenTutorialQuiz;
}(React.Component));
exports.TokenTutorialQuiz = TokenTutorialQuiz;
//# sourceMappingURL=TokenTutorialQuiz.js.map