/**
 * MIT License
 *
 * Copyright (c) 2020 ManBang Group
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 */

import threshApp, { injectRoute } from './core/ThreshApp'
import Widget from './core/Widget'
import createElement from './core/createElement'
import basicWidgets, { Page } from './core/basicWidget'
import RenderManager from './manager/RenderManager'
import UtilManager from './manager/UtilManager'
import UIManager from './manager/UIManager'
import BridgeManager from './manager/BridgeManager'
import eventManager from './manager/EventManager'
import TimerManager from './manager/TimerManager'
import coolink from './coolink/api'
import { ToastInfo, Positioned } from './types/widget'
import cooInfo, { setCooInfo } from './shared/cooInfo';
import FileManager from './manager/FileManager'
import mpWeb from './coolink/MpWeb'

let cooApp;

if (mpWeb.isBrowser()) {
  // browser
  cooApp = coolink;
  let g: any = window as any;
  g.javaCallMpWeb = mpWeb.processNativeCallBack;
} else {
  // mini-app
  cooApp = threshApp;
  RenderManager.getMediaQuery(cooApp.jsVersion);
  eventManager.registerBuiltInEvents();
  
}

export default cooApp;
export {
  coolink,
  Widget,
  UtilManager as Util,
  BridgeManager as Bridge,
  UIManager as ui,
  TimerManager as Timer,
  eventManager as Event,
  basicWidgets,
  createElement,
  injectRoute,
  ToastInfo,
  Positioned,
  cooInfo,
  setCooInfo,
  FileManager,
}
