!(function (window) {
  var env = {};
  window.env = env;
  checkPlatform(env);
  var isCN = checkIsChinese();
  var isRU = checkIsRU();
  initTitle(isCN);
  var remove_logo_domains = ['127.0.0.2'];
  //   var remove_logo_domains = ['www.xxxxxxxxx.com', '127.0.0.1'];
  if (removeLogo(remove_logo_domains)) {
    initEmptySplash();
  } else {
    initSplash(isCN, isRU);
  }
  function hideLoading() {
    var url = window.location.href;
    if (url.indexOf('?') > -1) {
      console.log('hide splash');

      var splash = document.getElementsByClassName('splash')[0];

      setTimeout(function () {
        document.body.style.backgroundColor = 'white';
        splash.style.display = 'none';
        splash.style.zIndex = 0;
      });
      console.log('no hideLoading');
      var loading = document.getElementsByClassName('full-screen-center')[0];
      setTimeout(function () {
        loading.style.zIndex = 1003;
      });
      return;
    }
    console.log('hideLoading');
    var loading = document.getElementsByClassName('full-screen-center')[0];
    setTimeout(function () {
      loading.style.zIndex = 0;
    });
  }
  //   hideLoading();

  function initTitle(isCN) {
    document.title = isCN ? '杏聆荟' : 'Flyinsono';
    if (window.__wxjs_environment === 'miniprogram') {
      document.title = ' ';
    }
  }

  function removeLogo(remove_logo_domains) {
    // 如果当前域名在移除列表中，则移除logo
    if (remove_logo_domains && remove_logo_domains.length) {
      var domain = window.location.hostname;
      console.log('domain', domain);
      if (remove_logo_domains.indexOf(domain) > -1) {
        console.log('remove logo');
        return true;
      }
    }
    // console.log('no remove logo');
    return false;
  }

  function initSplash(isCN, isRU) {
    var splash = document.getElementsByClassName('splash')[0];
    if (!splash) return;
    splash.classList.add('splash_lab');
  }

  function initEmptySplash() {
    var splash = document.getElementsByClassName('splash')[0];
    if (!splash) return;
    splash.classList.add('splash_empty');
    var loading = document.getElementsByClassName('full-screen-center')[0];
    loading.style.position = 'absolute';
  }

  function checkPlatform(target) {
    // injectWinTest();
    var shell = window['FisShellApi'];

    if (shell) {
      target.platform = 'shell';
      shell.getPlatformName().then(function (res) {
        target.platform = res;
      });
    } else {
      target.platform = 'Web';
    }
  }

  /// inject `FisShellApi` for debug
  function injectWinTest() {
    window['FisShellApi'] = {
      writeLog: async (text) => {
        console.log(text);
      },
      getPlatformName: async () => 'Win',
      setTitle: async (title) => {
        console.log(`Set title - ${title}`);
      },
    };
  }

  function checkIsChinese() {
    var lang = navigator.language.split('-')[0].toLocaleLowerCase();
    // var storeLocale = localStorage['flutter.store_app_locale'];
    // if (storeLocale != null && storeLocale.length) {
    //     try {
    //         var arr = JSON.parse(storeLocale);
    //         if (arr && arr.length === 2) {
    //             lang = arr[0].toLocaleLowerCase();
    //         }
    //     } catch (error) { }
    // }
    return lang === 'zh';
  }

  function checkIsRU() {
    var lang = navigator.language.split('-')[0].toLocaleLowerCase();
    // var storeLocale = localStorage['flutter.store_app_locale'];
    // if (storeLocale != null && storeLocale.length) {
    //     try {
    //         var arr = JSON.parse(storeLocale);
    //         if (arr && arr.length === 2) {
    //             lang = arr[0].toLocaleLowerCase();
    //         }
    //     } catch (error) { }
    // }
    return lang === 'ru';
  }
  // 监听storage 关闭当前标签页
  window.addEventListener('storage', function (event) {
    if (event.key === 'closeOtherTabs' && event.newValue === 'true') {
      window.close();
    }
  });
  // 关闭其他标签页
  window.closeOtherTabs = function () {
    localStorage.setItem('closeOtherTabs', 'true');
    setTimeout(function () {
      localStorage.setItem('closeOtherTabs', 'false');
    }, 100);
  };

  // define for fis_lib_media_rt
  window.getIframe = function (id) {
    return document.getElementById(id);
  };
})(window);
