/* global componentsOptions, Service, APP_JSON */
import Page from 'bili-small-app/runtime/page';
Page.componentsOptions = componentsOptions;
Service.componentsOptions = componentsOptions;

const systemInfo = bl.getSystemInfoSync();
const config = APP_JSON;
const pages = config.pages;
const globalConfig = config.window;
const tabBar = config.tabBar;

pages.forEach((item) => {
    Page.componentsOptions[item.path].enablePullDownRefresh = typeof item.enablePullDownRefresh !== 'undefined' ? item.enablePullDownRefresh : (globalConfig && globalConfig.enablePullDownRefresh || false);

    // 兼容安卓5.46及以下app.json读取逻辑的错误
    if (systemInfo.platform === 'android' && systemInfo.SDKVersion < '2.4.0') {
        Page.componentsOptions[item.path].hasNavigationBar = item.hasNavigationBar || (globalConfig && globalConfig.hasNavigationBar || false);
    } else {
        Page.componentsOptions[item.path].hasNavigationBar = typeof item.hasNavigationBar !== 'undefined' ? item.hasNavigationBar : (globalConfig && globalConfig.hasNavigationBar || false);
    }
});

if (tabBar) {
    tabBar.list.forEach(tabBarItem => {
        if (Page.componentsOptions[tabBarItem.pagePath]) {
            Page.componentsOptions[tabBarItem.pagePath].hasNavigationBar = true;
        }
    });
}
