"use strict";
const appId = "hotels";
const appName = "Hotels App";
const getWindow = () => {
  try {
    window.parent.document;
    return window.parent;
  } catch (err) {
    return window;
  }
};
let host = null;
let parentHistory = null;
let logger = null;
const browserWindow = getWindow();
browserWindow.__TEST__ = browserWindow.__TEST__ ?? {
  logs: []
};
window.emui = window.emui || { uuid: crypto.randomUUID() };
window.emui.app = {
  uuid: window.emui.uuid,
  init: async (options) => {
    browserWindow.__TEST__.logs.push(`${appId} initializing`);
    host = options.host;
    parentHistory = options.history;
    logger = options.logger;
    return Promise.resolve();
  },
  mount: async () => {
    browserWindow.__TEST__.logs.push(`${appId} mounting`);
    const mainElement = document.createElement("main");
    const pageHeaderEle = document.createElement("h1");
    pageHeaderEle.textContent = appName;
    pageHeaderEle.id = "header";
    mainElement.appendChild(pageHeaderEle);
    const versionEle = document.createElement("p");
    versionEle.textContent = "Version: Latest";
    versionEle.id = "version";
    mainElement.appendChild(versionEle);
    document.body.appendChild(mainElement);
    browserWindow.__TEST__.logs.push(`${appId} mounted`);
    return Promise.resolve();
  },
  unmount: () => {
    browserWindow.__TEST__.logs.push(`${appId} unmounting`);
    const mainEle = document.getElementsByTagName("main")[0];
    if (mainEle) mainEle.remove();
    browserWindow.__TEST__.logs.push(`${appId} unmounted`);
    return Promise.resolve();
  }
};
browserWindow.emui?.registerApp?.({ appId, app: window.emui.app });
