"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const components_1 = require("@bluebase/components");
const core_1 = require("@bluebase/core");
const react_native_1 = require("react-native");
const helpers_1 = require("./helpers");
const react_1 = tslib_1.__importDefault(require("react"));
const DrawerLayout = core_1.getComponent('DrawerLayout');
const DrawerNavigationView = (props) => () => {
    const { navigationState } = props;
    const { routes } = navigationState;
    return (react_1.default.createElement(react_native_1.ScrollView, null,
        react_1.default.createElement(react_native_1.SafeAreaView, null,
            react_1.default.createElement(components_1.DrawerSection, null,
                react_1.default.createElement(components_1.NavigationActions, null, ({ navigate, state }) => routes.map((r) => {
                    const title = helpers_1.getTitle(r.options);
                    const icon = helpers_1.getIcon(r.options);
                    return (react_1.default.createElement(components_1.DrawerItem, { key: r.routeName, title: title, icon: icon, onPress: () => navigate(r.routeName, state.params) }));
                }))))));
};
exports.DrawerView = (props) => {
    const { screen: Screen, navigationOptions, navigator, styles } = props, rest = tslib_1.__rest(props, ["screen", "navigationOptions", "navigator", "styles"]);
    const { contentOptions, routes, type } = navigator, other = tslib_1.__rest(navigator, ["contentOptions", "routes", "type"]);
    const stylesheet = styles;
    // const Component = Screen; // || DrawerViewContent;
    // Resolve active tab index
    const currentRouteName = props.navigation.state.routeName;
    const currentIndex = navigator.routes.findIndex(route => route.name === currentRouteName);
    // Navigation State
    const navigationState = {
        index: currentIndex,
        routes: navigator.routes.map((route, index) => {
            const options = route.navigationOptions;
            return {
                index,
                options,
                path: route.path,
                routeName: route.name,
            };
        })
    };
    // debugger;
    return (react_1.default.createElement(components_1.View, { style: stylesheet.root },
        react_1.default.createElement(DrawerLayout, Object.assign({}, other, { renderNavigationView: DrawerNavigationView(Object.assign({}, props, { navigationState })) }), Screen ? react_1.default.createElement(Screen, Object.assign({}, rest)) : rest.children)));
};
exports.DrawerView.defaultStyles = (theme) => ({
    root: {
        backgroundColor: theme.palette.background.default,
        flex: 1,
    }
});
