
import MobileApp from "@web-atoms/web-controls/dist/mobile-app/MobileApp";
import DesktopApp from "@web-atoms/web-controls/dist/desktop-app/DesktopApp";
import PageNavigator from "@web-atoms/web-controls/dist/PageNavigator";
import PopupService from "@web-atoms/core/dist/web/services/PopupService";
import AppMenu from "./menu/AppMenu";
import HomePage from "./pages/home/HomePage";
import WebApp from "@web-atoms/core/dist/web/WebApp";
import Pack from "@web-atoms/core/dist/Pack";

import "./styles/GlobalStyle";
import { AtomControl } from "@web-atoms/core/dist/web/controls/AtomControl";
import ThisApp from "./common/ThisApp";
import XNode from "@web-atoms/core/dist/core/XNode";
import AppCommands from "./commands/AppCommands";
import Command from "@web-atoms/core/dist/core/Command";

const AppClass = (/android|iPhone/i.test(navigator.userAgent)
    ? MobileApp
    : DesktopApp) as typeof AtomControl;

@Pack
export default class AppIndex extends AppClass {

    public async init() {

        PopupService.lastTarget =  this.element;

        AppCommands.install(this);

        (this.app as WebApp).installStyleSheet({
            href: "https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.4.0/css/all.min.css",
            integrity: "sha256-HtsXJanqjKTc8vVQjO4YMhiqFoXkfBsjBWcX91T1jr8=",
            crossOrigin: "anonymous"
        });

        await (ThisApp.isMobile
            ? this.mobileInit()
            : this.desktopInit());


        if (!Command.invokeRoute()) {
            AppCommands.home.dispatch();
        }
    }


    async mobileInit() {
        const app = this as any as MobileApp;
        app.drawer = AppMenu;
    }

    async desktopInit() {
        const app = this as any as DesktopApp;
        app.menuRenderer = () => <AppMenu/>;

        const year = (new Date()).getFullYear();

        app.statusBarRenderer = () => <div data-layout="row">
            <div
                data-align-self="stretch"
                data-flex="stretch-full"
                text={`© NeuroSpeech Technologies Pvt Ltd (India), 2012-${year}`}/>
            <i class="fa-brands fa-github"/>
            <a
                text="github.com/web-atoms"
                href="https://github.com/web-atoms/core"
                target="_blank"/>
        </div>;
    }
}