"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_1 = tslib_1.__importDefault(require("react"));
class SettingsPageList extends react_1.default.PureComponent {
    componentWillMount() {
        const { name } = this.props;
        if (name) {
            this.HeaderComponent = core_1.getComponent(`${name}RootPageHeader`, 'Noop');
            this.FooterComponent = core_1.getComponent(`${name}RootPageFooter`, 'Noop');
        }
    }
    render() {
        const HeaderComponent = this.HeaderComponent || components_1.Noop;
        const FooterComponent = this.FooterComponent || components_1.Noop;
        return (react_1.default.createElement(react_1.default.Fragment, null,
            react_1.default.createElement(HeaderComponent, null),
            react_1.default.createElement(components_1.List, null,
                react_1.default.createElement(components_1.NavigationActions, null, ({ navigate }) => (this.props.pages || []).map(page => {
                    const options = core_1.resolveThunk(page.navigationOptions || {});
                    const title = getTitle(options);
                    const left = getIcon(options);
                    const onPress = () => navigate(page.name);
                    return (react_1.default.createElement(components_1.List.Item, { key: page.name, onPress: onPress, title: title, left: left }));
                }))),
            react_1.default.createElement(FooterComponent, null)));
    }
}
exports.SettingsPageList = SettingsPageList;
function getTitle(options) {
    return options.drawerLabel || options.title || options.headerTitle;
}
function getIcon(options) {
    const icon = options.drawerIcon;
    if (!icon) {
        return;
    }
    if (typeof icon === 'function') {
        return icon();
    }
    if (icon && typeof icon.type === 'string') {
        return react_1.default.createElement(components_1.List.Icon, Object.assign({}, icon));
    }
}
