"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 __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
    if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
    return cooked;
};
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
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 styleConstants_1 = require("../styleConstants");
var icons_1 = require("../icons");
var TabsStyled_1 = require("./TabsStyled");
var Tabs = /** @class */ (function (_super) {
    __extends(Tabs, _super);
    function Tabs(props) {
        var _this = _super.call(this, props) || this;
        _this.handleClick = function (index) {
            if (_this.props.preventTabChange &&
                (_this.props.preventTabChange === true || !window.confirm(_this.props.preventTabChange))) {
                return;
            }
            _this.setState({ activeIndex: index });
            if (_this.props.onActiveTabChange) {
                _this.props.onActiveTabChange(index);
            }
        };
        _this.toggleResponsiveVisible = function () {
            _this.setState({ isResponsiveTabsetVisible: !_this.state.isResponsiveTabsetVisible });
        };
        _this.state = {
            activeIndex: props.activeIndex || 0,
            isResponsiveTabsetVisible: false,
        };
        return _this;
    }
    Tabs.getDerivedStateFromProps = function (nextProps, prevState) {
        return __assign(__assign({}, prevState), { activeIndex: typeof nextProps.activeIndex === "number" ? nextProps.activeIndex : prevState.activeIndex });
    };
    Tabs.prototype.renderTabs = function () {
        var _this = this;
        return React.Children.map(this.props.children, function (child, index) {
            return React.cloneElement(child, {
                index: index,
                isActive: _this.state.activeIndex === index,
                isResponsiveAndVisible: _this.state.isResponsiveTabsetVisible,
                onClick: _this.handleClick,
                TabComponent: _this.props.TabComponent,
            });
        });
    };
    Tabs.prototype.renderContent = function () {
        var children = this.props.children;
        var activeIndex = this.state.activeIndex;
        if (children[activeIndex]) {
            return children[activeIndex].props.children;
        }
    };
    Tabs.prototype.render = function () {
        var TabsNavComponent = this.props.TabsNavComponent || TabsStyled_1.StyledNav;
        var TabComponentOrnamental = styled_components_1.default(this.props.TabComponent || "span")(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n      cursor: default;\n    "], ["\n      cursor: default;\n    "])));
        var arrowColor = this.state.isResponsiveTabsetVisible ? styleConstants_1.colors.accent.CIVIL_BLUE : styleConstants_1.colors.accent.CIVIL_GRAY_2;
        return (React.createElement("div", null,
            React.createElement(TabsNavComponent, null,
                React.createElement(TabsStyled_1.TabContainer, null,
                    this.props.TabsNavBefore && React.createElement(TabComponentOrnamental, null, this.props.TabsNavBefore),
                    this.renderTabs(),
                    this.props.TabsNavAfter && React.createElement(TabComponentOrnamental, null, this.props.TabsNavAfter)),
                React.createElement(TabsStyled_1.StyledResponsiveTabsToggleButton, { isExpanded: this.state.isResponsiveTabsetVisible, onClick: this.toggleResponsiveVisible },
                    React.createElement(icons_1.ExpandDownArrow, { color: arrowColor, opacity: 1 }))),
            React.createElement("div", null, this.renderContent())));
    };
    return Tabs;
}(React.Component));
exports.Tabs = Tabs;
var templateObject_1;
//# sourceMappingURL=Tabs.js.map