"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const core_1 = require("@bluebase/core");
const react_native_1 = require("react-native");
const AppGrid_1 = require("../AppGrid");
const react_1 = tslib_1.__importDefault(require("react"));
const components_1 = require("@bluebase/components");
const BlueBaseImageBackground = core_1.getComponent('BlueBaseImageBackground');
const EmptyState = core_1.getComponent('LauncherEmptyState', 'EmptyState');
class LauncherScreen extends react_1.default.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {
            plugins: [],
        };
    }
    async componentWillMount() {
        const BB = this.context;
        const enabledPlugins = await BB.Plugins.getAllEnabled();
        const plugins = enabledPlugins.filter(p => !!p.indexRoute);
        this.setState({ plugins });
    }
    render() {
        const { styles } = this.props;
        const { plugins } = this.state;
        if (!plugins || plugins.length === 0) {
            return (react_1.default.createElement(components_1.View, { testID: "view", style: { flex: 1 } },
                react_1.default.createElement(EmptyState, null)));
        }
        return (react_1.default.createElement(BlueBaseImageBackground, { style: {
                flex: 1,
            }, resizeMode: "contain", source: 'launcher' },
            react_1.default.createElement(react_native_1.ScrollView, { style: styles.root },
                react_1.default.createElement(AppGrid_1.AppGrid, { plugins: plugins }))));
    }
}
LauncherScreen.contextType = core_1.BlueBaseContext;
LauncherScreen.defaultStyles = (theme) => ({
    root: {
        flex: 1,
        paddingHorizontal: theme.spacing.unit * 2,
    },
});
exports.LauncherScreen = LauncherScreen;
