"use strict";
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
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;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var React = __importStar(require("react"));
var styled_components_1 = __importDefault(require("styled-components"));
var StyledNav = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n  position: relative;\n  height: 76px;\n  margin: 0 auto;\n  width: 100%;\n  & > ul {\n    justify-content: space-between;\n  }\n"], ["\n  position: relative;\n  height: 76px;\n  margin: 0 auto;\n  width: 100%;\n  & > ul {\n    justify-content: space-between;\n  }\n"])));
var StyledContainer = styled_components_1.default.ul(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n  display: flex;\n  list-style: none;\n  margin: 0 auto;\n  padding: 0;\n"], ["\n  display: flex;\n  list-style: none;\n  margin: 0 auto;\n  padding: 0;\n"])));
var MainSection = styled_components_1.default.div(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n  background-color: #fff;\n  padding: 45px 115px;\n"], ["\n  background-color: #fff;\n  padding: 45px 115px;\n"])));
var ButtonSection = styled_components_1.default.div(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n  border-top: 1px solid rgb(233, 233, 234);\n  display: flex;\n  flex-direction: row;\n  justify-content: flex-end;\n  padding: 25px;\n  & > button {\n    margin-left: 15px;\n  }\n"], ["\n  border-top: 1px solid rgb(233, 233, 234);\n  display: flex;\n  flex-direction: row;\n  justify-content: flex-end;\n  padding: 25px;\n  & > button {\n    margin-left: 15px;\n  }\n"])));
var StepProcessTopNav = /** @class */ (function (_super) {
    __extends(StepProcessTopNav, _super);
    function StepProcessTopNav(props) {
        var _this = _super.call(this, props) || this;
        _this.setStartPosition = function (position) {
            _this.setState({ startPosition: position });
        };
        _this.scrollToTop = function () {
            if (_this.navContainer) {
                _this.navContainer.scrollIntoView(true);
            }
        };
        _this.goNext = function () {
            _this.scrollToTop();
            var newIndex = _this.state.activeIndex + 1;
            if (_this.props.onActiveTabChange) {
                _this.props.onActiveTabChange(newIndex);
            }
            _this.setState({ activeIndex: newIndex });
        };
        _this.goPrevious = function () {
            _this.scrollToTop();
            var newIndex = _this.state.activeIndex - 1;
            if (_this.props.onActiveTabChange) {
                _this.props.onActiveTabChange(newIndex);
            }
            _this.setState({ activeIndex: newIndex });
        };
        _this.handleClick = function (index) {
            if (_this.props.onActiveTabChange) {
                _this.props.onActiveTabChange(index);
            }
            _this.setState({ activeIndex: index });
        };
        _this.state = {
            activeIndex: props.activeIndex || 0,
        };
        return _this;
    }
    StepProcessTopNav.prototype.componentDidUpdate = function (prevProps, prevState) {
        if (typeof this.props.activeIndex === "undefined") {
            return;
        }
        if (this.state.activeIndex !== prevState.activeIndex) {
            return;
        }
        if (this.props.activeIndex !== prevProps.activeIndex) {
            this.setState({ activeIndex: this.props.activeIndex });
        }
        else if (prevProps.activeIndex !== prevState.activeIndex && this.props.activeIndex !== this.state.activeIndex) {
            this.setState({ activeIndex: this.props.activeIndex });
        }
    };
    StepProcessTopNav.prototype.renderTabs = function () {
        var _this = this;
        return React.Children.map(this.props.children, function (child, index) {
            return React.cloneElement(child, {
                index: index,
                startPosition: _this.state.startPosition,
                isCurrent: _this.state.activeIndex === index,
                isActive: _this.state.activeIndex >= index,
                onClick: _this.handleClick,
                setStartPosition: index === 0 ? _this.setStartPosition : undefined,
            });
        });
    };
    StepProcessTopNav.prototype.renderContent = function () {
        var children = this.props.children;
        var activeIndex = this.state.activeIndex;
        if (children[activeIndex]) {
            return children[activeIndex].props.children;
        }
    };
    StepProcessTopNav.prototype.renderButtons = function () {
        var children = this.props.children;
        var activeIndex = this.state.activeIndex;
        if (children[activeIndex] && children[activeIndex].props.renderButtons) {
            return children[activeIndex].props.renderButtons({
                goNext: this.goNext,
                goPrevious: this.goPrevious,
                index: this.state.activeIndex,
                stepsLength: children.length,
            });
        }
    };
    StepProcessTopNav.prototype.render = function () {
        var _this = this;
        return (React.createElement("div", null,
            React.createElement(StyledNav, { ref: function (el) { return (_this.navContainer = el); } },
                React.createElement(StyledContainer, null, this.renderTabs())),
            React.createElement(MainSection, null, this.renderContent()),
            React.createElement(ButtonSection, null, this.renderButtons())));
    };
    return StepProcessTopNav;
}(React.Component));
exports.StepProcessTopNav = StepProcessTopNav;
var templateObject_1, templateObject_2, templateObject_3, templateObject_4;
//# sourceMappingURL=StepProcessTopNav.js.map