import {
    App, applyPolyfills,
    InitPromise, MenuAction,
    ShareManager,
    SmsShareButton, TelegramShareButton,
    Theme,
    ThemeManager,
    Translator,
    WhatsappShareButton
} from "./lib/pwa-lib";
import {LoginSite, RegistrationSite} from "./lib/pwa-user-management";

import "./lib/pwa-lib"
import "./lib/pwa-core"
import "./lib/pwa-assets"
import "./lib/pwa-code-management"
import "./lib/pwa-user-management"

import {SettingsManager, SettingsSite} from "./lib/pwa-core";

import {InstallManager, Matomo, SoundManager} from "./lib/pwa-assets";
import {MenuSite} from "../module/Application/pwa/js/site/MenuSite";
import {WordRotatorSettingFragment} from "../module/Application/pwa/js/Fragment/WordRotatorSettingFragment";

import {PrivacyPolicySite} from "../module/Application/pwa/js/site/PrivacyPolicySite";
import {CreditsSite} from "../module/Application/pwa/js/site/CreditsSite";

applyPolyfills();


import './settings'

ThemeManager.addTheme(new Theme('red', ''));
ThemeManager.addTheme(new Theme("blue", "blue"));
ThemeManager.addTheme(new Theme("black", "black"));
ThemeManager.addTheme(new Theme("green", "green"));
ThemeManager.addTheme(new Theme("pink", "pink"));
ThemeManager.addTheme(new Theme("dark", "dark"));

ShareManager.addShareButton(new WhatsappShareButton('img/whatsapp.svg'));
ShareManager.addShareButton(new SmsShareButton('img/sms.svg'));
ShareManager.addShareButton(new TelegramShareButton('img/telegram.svg'));
// ShareManager.addShareButton(new CopyShareButton('img/copy.svg'));

let app = new App();
// app.addDeepLink("policy", PrivatePolicySite.name);

// bridge für Android
window["ThemeManager"] = ThemeManager;
window["ThemeManager"]["addChangeListener"] = ThemeManager.addChangeListener;
window["app"] = app;
window["app"]["refreshCurrentSite"] = app.refreshCurrentSite;
window["Translator"] = Translator;
window["Translator"]["setLanguage"] = Translator.setLanguage;

SettingsSite.setTemplate("html/application/setting-template.html");
// SettingsSite.shouldAddSettingsAction = false;

RegistrationSite.addAction = false;
LoginSite.addLoginAction = false;

InitPromise.resolve(app).then(async function(){
    SettingsSite.settingsAction.showFor = MenuAction.SHOW_ALWAYS;

    let settingsManager = SettingsManager.getInstance();

    let soundManager = SoundManager.getInstance();
    soundManager.play(SoundManager.CHANNELS.MUSIC, {audio: "sound/brightAndBeautifull__.mp3", loop: true, volume: 0.6, muted: !settingsManager.getSetting("play-music", true)});

    app.start(MenuSite);
    Translator.setLanguage("de");

    InstallManager.setCanInstallListener(e => {
        console.log("can install!", e);
    });
});
