"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const components_1 = require("@bluebase/components");
const react_1 = tslib_1.__importDefault(require("react"));
const helpers_1 = require("./helpers");
class TabBar extends react_1.default.Component {
    render() {
        const { bottomNavigation, navigation, navigator } = this.props;
        const { routes } = navigator;
        // Resolve active tab index
        const currentRouteName = navigation.state.routeName;
        const currentIndex = navigator.routes.findIndex(route => route.name === currentRouteName);
        const onChange = (_e, i) => navigation.push(routes[i].name, navigation.state.params);
        const Component = bottomNavigation === true ? components_1.BottomNavigation : components_1.Tabs;
        return (react_1.default.createElement(Component, { value: currentIndex, onChange: onChange, style: { zIndex: 1100 } }, navigator.routes.map((route, index) => this.renderTab(route, index, this.props))));
    }
    renderTab(route, index, props) {
        const { bottomNavigation } = props;
        const Component = bottomNavigation === true ? components_1.BottomNavigationAction : components_1.Tab;
        const options = route.navigationOptions;
        const icon = helpers_1.getIcon(options);
        const title = helpers_1.getTitle(options);
        return (react_1.default.createElement(Component, { icon: icon, label: title, value: index, key: index }));
    }
}
exports.TabBar = TabBar;
