define([
  "exports",
  "./../dom.js",
  "./../common/inputmanager.js",
  "./../common/usersettings/usersettings.js",
  "./../common/globalize.js",
  "./../common/datetime.js",
  "./../common/playback/playbackmanager.js",
  "./../emby-apiclient/events.js",
  "./../emby-apiclient/connectionmanager.js",
  "./../layoutmanager.js",
  "./../approuter.js",
  "./../maintabsmanager.js",
  "./../viewmanager/viewmanager.js",
  "./../backdrop/backdrop.js",
  "./../common/servicelocator.js",
  "./../navdrawer/navdrawer.js",
  "./../navdrawer/navdrawercontent.js",
  "./../common/input/api.js",
  "./../emby-elements/emby-button/paper-icon-button-light.js",
  "./../common/methodtimer.js",
], function (
  _exports,
  _dom,
  _inputmanager,
  _usersettings,
  _globalize,
  _datetime,
  _playbackmanager,
  _events,
  _connectionmanager,
  _layoutmanager,
  _approuter,
  _maintabsmanager,
  _viewmanager,
  _backdrop,
  _servicelocator,
  _navdrawer,
  _navdrawercontent,
  _api,
  _paperIconButtonLight,
  _methodtimer,
) {
  Object.defineProperty(_exports, "__esModule", { value: !0 }),
    (_exports.default = void 0),
    require(["material-icons", "css!modules/appheader/appheader.css"]);
  var headerHomeButton,
    headerMenuButton,
    headerBackButton,
    headerCastButton,
    headerHelpButton,
    headerSearchButton,
    headerSettingsButton,
    headerUserButton,
    selectedPlayerText,
    headerRight,
    currentServerId,
    isUserAdmin,
    headerMiddle,
    _scrollingElement,
    boundLayoutModeChangeFn,
    skinHeaderElement = document.querySelector(".skinHeader"),
    skinBodyElement = document.querySelector(".skinBody"),
    hasPhysicalBackButton =
      _servicelocator.appHost.supports("physicalbackbutton"),
    supportsFullscreenMediaQueries = _servicelocator.appHost.supports(
      "fullscreenmediaqueries",
    ),
    backgroundContainer = document.querySelector(".backgroundContainer"),
    decodingAttribute = _dom.default.supportsAsyncDecodedImages()
      ? ' decoding="async"'
      : "",
    TranslateProperty = CSS.supports("translate", "40px 100px")
      ? "translate"
      : CSS.supports("transform", "scale(1)")
      ? "transform"
      : "-webkit-transform",
    userSignedIn = !1,
    currentDrawerState = 0,
    SupportsExternalLinks =
      _servicelocator.appHost.supports("externallinks") &&
      _servicelocator.appHost.supports("targetblank");
  function updateClock() {
    var clock = this.clockElement;
    clock &&
      (clock.innerHTML = _datetime.default
        .getDisplayTime(new Date())
        .toLowerCase());
  }
  function onLocalUserSignedOut(e) {
    (userSignedIn = !1),
      headerSearchButton.classList.add("hide"),
      updateUserInHeader(null),
      setRemoteControlVisibility();
  }
  function ensureHeaderSettingsButton() {
    (headerUserButton =
      headerUserButton || document.querySelector(".headerUserButton")),
      (headerSettingsButton =
        headerSettingsButton ||
        document.querySelector(".headerSettingsButton"));
  }
  function updateUserInHeader(user) {
    var userImageUrl;
    ensureHeaderSettingsButton(),
      user &&
        user.PrimaryImageTag &&
        (userImageUrl = (function (user, apiClient, options) {
          return (
            ((options = options || {}).type = "Primary"),
            user.PrimaryImageTag
              ? ((options.tag = user.PrimaryImageTag),
                apiClient.getUserImageUrl(user.Id, options))
              : null
          );
        })(user, _connectionmanager.default.getApiClient(user.ServerId), {
          height: Math.round(0.56 * skinHeaderElement.offsetHeight),
        })),
      (headerUserButton.innerHTML = userImageUrl
        ? '<img draggable="false"' +
          decodingAttribute +
          ' class="headerUserButtonImage paper-icon-button-img" src="' +
          userImageUrl +
          '" />'
        : '<i class="md-icon">&#xE7FD;</i>'),
      (isUserAdmin = user
        ? (headerUserButton.classList.remove("hide"),
          _layoutmanager.default.tv
            ? headerSettingsButton.classList.add("hide")
            : headerSettingsButton.classList.remove("hide"),
          user.Policy.IsAdministrator)
        : (headerUserButton.classList.add("hide"),
          headerSettingsButton.classList.add("hide"),
          !1));
  }
  function onUserUpdated(e, apiClient, data) {
    apiClient.getCurrentUserId() === data.Id &&
      apiClient.serverId() === currentServerId &&
      updateUserInHeader(data);
  }
  function resetPremiereButton() {
    _servicelocator.appHost.supports("premiereinheader") &&
      _connectionmanager.default.currentApiClient() &&
      _connectionmanager.default.currentApiClient().serverId() &&
      require(["registrationServices", "emby-button"], function (
        registrationServices,
      ) {
        registrationServices
          .validateFeature("themes", { viewOnly: !0, showDialog: !1 })
          .then(removePremiereButton, addPremiereButton);
      });
  }
  function onPremiereButtonClick() {
    require(["registrationServices"], function (registrationServices) {
      registrationServices
        .validateFeature("themes", { viewOnly: !0 })
        .then(resetPremiereButton);
    });
  }
  function addPremiereButton() {
    var html =
      '<button is="emby-button" class="raised raised-mini button-submit btnHeaderPremiere headerButton headerSectionItem" style="padding-top:.5em;padding-bottom:.5em;">' +
      _globalize.default.translate("HeaderBecomeProjectSupporter") +
      "</button>";
    document.querySelector(".btnHeaderPremiere") ||
      (document
        .querySelector(".headerRight")
        .insertAdjacentHTML("afterbegin", html),
      document
        .querySelector(".btnHeaderPremiere")
        .addEventListener("click", onPremiereButtonClick));
  }
  function removePremiereButton() {
    var btn = document.querySelector(".btnHeaderPremiere");
    btn && btn.remove();
  }
  function onLocalUserSignedIn(e, serverId, userId) {
    (currentServerId = serverId),
      (userSignedIn = !0),
      _connectionmanager.default
        .getApiClient(serverId)
        .getUser(userId)
        .then(updateUserInHeader),
      resetPremiereButton(),
      setRemoteControlVisibility(),
      setSearchVisibility({});
  }
  function onHeaderMenuButtonClick() {
    _navdrawer.default.open();
  }
  function onHomeClick() {
    _approuter.default.goHome();
  }
  function onBackClick(e) {
    _inputmanager.default.trigger("back", {
      sourceElement: _viewmanager.default.currentView(),
      originalEvent: e,
    });
  }
  function onSearchClick(e) {
    _inputmanager.default.trigger("search", {
      sourceElement: _viewmanager.default.currentView(),
      originalEvent: e,
    });
  }
  function onUserButtonClick() {
    _approuter.default.showUserMenu({ positionTo: this, positionY: "bottom" });
  }
  function onSettingsButtonClick() {
    var manageServerRouteUrl = _approuter.default.getRouteUrl("manageserver");
    if (!isUserAdmin || !_approuter.default.getRouteInfo(manageServerRouteUrl))
      return onUserButtonClick.call(this);
    _approuter.default.show(manageServerRouteUrl);
  }
  function onCastButtonClick() {
    var btn = this;
    require(["playerSelectionMenu"], function (playerSelectionMenu) {
      playerSelectionMenu.show(btn);
    });
  }
  function onLayoutModeChange() {
    !_layoutmanager.default.tv && _dom.default.allowBackdropFilter()
      ? skinHeaderElement.classList.add("skinHeader-withbackdropfilter")
      : skinHeaderElement.classList.remove("skinHeader-withbackdropfilter"),
      ensureHeaderSettingsButton(),
      _layoutmanager.default.tv || headerUserButton.classList.contains("hide")
        ? headerSettingsButton.classList.add("hide")
        : headerSettingsButton.classList.remove("hide"),
      _layoutmanager.default.tv
        ? (headerRight.classList.add("secondaryText"),
          skinHeaderElement.classList.add("appHeader-tv"))
        : (headerRight.classList.remove("secondaryText"),
          skinHeaderElement.classList.remove("appHeader-tv")),
      (headerMiddle = headerMiddle || document.querySelector(".headerMiddle")),
      _layoutmanager.default.tv
        ? headerMiddle.classList.add("headerMiddle-tv")
        : headerMiddle.classList.remove("headerMiddle-tv"),
      this.destroyClock(),
      this.loadClock(),
      setRemoteControlVisibility();
  }
  function updateCastIcon() {
    var info,
      btnCast = headerCastButton;
    btnCast &&
      ((info = _playbackmanager.default.getPlayerInfo()) && !info.isLocalPlayer
        ? ((btnCast.innerHTML = "&#xE308;"),
          (selectedPlayerText.innerHTML = info.deviceName || info.name))
        : ((btnCast.innerHTML = "&#xE307;"),
          (selectedPlayerText.innerHTML = "")));
  }
  function onNewPlayQueueStart(e, player, state) {
    !(function (state) {
      return (
        _layoutmanager.default.tv &&
        state.NowPlayingItem &&
        "Audio" === state.NowPlayingItem.MediaType
      );
    })(state) ||
      state.IsBackgroundPlayback ||
      _approuter.default.showNowPlaying();
  }
  function setRemoteControlVisibility() {
    _servicelocator.appHost.supports("remotecontrol") &&
    !_layoutmanager.default.tv &&
    userSignedIn
      ? (headerCastButton.classList.remove("hide"),
        selectedPlayerText.classList.remove("hide"))
      : (headerCastButton.classList.add("hide"),
        selectedPlayerText.classList.add("hide"));
  }
  function setSearchVisibility(viewDetail) {
    !userSignedIn ||
    !1 === viewDetail.searchButton ||
    "search" ===
      (null == (viewDetail = viewDetail.params) ? void 0 : viewDetail.type) ||
    (!_layoutmanager.default.tv && [1, 2, 3].includes(currentDrawerState))
      ? headerSearchButton.classList.add("hide")
      : headerSearchButton.classList.remove("hide");
  }
  function allowDrawer(detail) {
    if (!1 !== detail.drawer && userSignedIn) {
      if (detail.hideDrawerWithOtherUserIdParam) {
        detail = detail.params;
        if (detail && detail.userId && detail.serverId) {
          var apiClient = _connectionmanager.default.getApiClient(
            detail.serverId,
          );
          if (apiClient && apiClient.getCurrentUserId() !== detail.userId)
            return;
        }
      }
      return 1;
    }
  }
  function updateWindowScroll(detail, view) {
    (elem = _scrollingElement) ||
      ((elem = document.scrollingElement || document.documentElement),
      (_scrollingElement = elem));
    var elem;
    enableWindowScroll(detail)
      ? (elem.classList.remove("noScrollY"),
        elem.classList.add("overflowYScroll"),
        skinBodyElement.classList.add("skinBody-withWindowScroll"),
        skinHeaderElement.classList.add("headroom-scrolling"),
        skinHeaderElement.classList.remove("headroom-hidden"))
      : (elem.classList.add("noScrollY"),
        elem.classList.remove("overflowYScroll"),
        skinBodyElement.classList.remove("skinBody-withWindowScroll"));
  }
  function onNavDrawerStateChange(e, drawerState) {
    3 === (currentDrawerState = drawerState)
      ? (headerHomeButton.classList.add("headerHomeButton-withdockeddrawer"),
        headerMenuButton.classList.add("headerMenuButton-withdockeddrawer"),
        backgroundContainer.classList.add(
          "backgroundContainer-withdockeddrawer",
        ),
        skinBodyElement.classList.add(
          "skinBody-withMiniDrawer",
          "skinBody-withDockedDrawer",
        ),
        skinBodyElement.classList.remove("skinBody-withFullDrawer"),
        skinHeaderElement.classList.remove("skinHeader-withfulldrawer"),
        skinHeaderElement.classList.add(
          "skinHeader-withminidrawer",
          "skinHeader-withdockeddrawer",
        ))
      : 2 === drawerState
      ? (headerHomeButton.classList.add("headerHomeButton-withdockeddrawer"),
        headerMenuButton.classList.add("headerMenuButton-withdockeddrawer"),
        backgroundContainer.classList.add(
          "backgroundContainer-withdockeddrawer",
        ),
        skinBodyElement.classList.add(
          "skinBody-withFullDrawer",
          "skinBody-withDockedDrawer",
        ),
        skinBodyElement.classList.remove("skinBody-withMiniDrawer"),
        skinHeaderElement.classList.add(
          "skinHeader-withfulldrawer",
          "skinHeader-withdockeddrawer",
        ),
        skinHeaderElement.classList.remove("skinHeader-withminidrawer"))
      : 1 === drawerState
      ? 3 === _navdrawer.default.closeState
        ? (headerHomeButton.classList.add("headerHomeButton-withdockeddrawer"),
          headerMenuButton.classList.add("headerMenuButton-withdockeddrawer"),
          backgroundContainer.classList.add(
            "backgroundContainer-withdockeddrawer",
          ),
          skinBodyElement.classList.remove("skinBody-withFullDrawer"),
          skinHeaderElement.classList.remove("skinHeader-withfulldrawer"),
          skinBodyElement.classList.add(
            "skinBody-withMiniDrawer",
            "skinBody-withDockedDrawer",
          ),
          skinHeaderElement.classList.add(
            "skinHeader-withminidrawer",
            "skinHeader-withdockeddrawer",
          ))
        : (headerHomeButton.classList.remove(
            "headerHomeButton-withdockeddrawer",
          ),
          headerMenuButton.classList.remove(
            "headerMenuButton-withdockeddrawer",
          ),
          backgroundContainer.classList.remove(
            "backgroundContainer-withdockeddrawer",
          ),
          skinBodyElement.classList.remove(
            "skinBody-withFullDrawer",
            "skinBody-withMiniDrawer",
            "skinBody-withDockedDrawer",
          ),
          skinHeaderElement.classList.remove(
            "skinHeader-withfulldrawer",
            "skinHeader-withminidrawer",
            "skinHeader-withdockeddrawer",
          ))
      : (skinBodyElement.classList.remove(
          "skinBody-withFullDrawer",
          "skinBody-withMiniDrawer",
          "skinBody-withDockedDrawer",
        ),
        skinHeaderElement.classList.remove(
          "skinHeader-withfulldrawer",
          "skinHeader-withminidrawer",
          "skinHeader-withdockeddrawer",
        ),
        backgroundContainer.classList.remove(
          "backgroundContainer-withdockeddrawer",
        ),
        headerHomeButton.classList.remove("headerHomeButton-withdockeddrawer"),
        headerMenuButton.classList.remove("headerMenuButton-withdockeddrawer")),
      setSearchVisibility(_viewmanager.default.currentViewInfo() || {});
  }
  function onViewShow(e) {
    var instance,
      detail = e.detail;
    detail.clearBackdrop && _backdrop.default.clear(),
      (function (detail) {
        var drawerStyle;
        allowDrawer(detail) &&
        !_layoutmanager.default.tv &&
        ("docked" ===
          (drawerStyle = detail.settingsTheme
            ? "docked"
            : _usersettings.default.drawerStyle()) ||
          "docked-mini" === drawerStyle)
          ? (_layoutmanager.default.tv && (drawerStyle = "docked-mini"),
            (detail.drawerInline = !0),
            _navdrawer.default.open(!0, "docked-mini" === drawerStyle))
          : ((_navdrawer.default.closeState = null),
            _navdrawer.default.close());
      })(detail),
      (function (detail) {
        !1 === (detail = detail.backButton) ||
        !_approuter.default.canGoBack() ||
        (hasPhysicalBackButton && !0 !== detail && !_layoutmanager.default.tv)
          ? headerBackButton.classList.add("hide")
          : !supportsFullscreenMediaQueries ||
            !0 === detail ||
            _layoutmanager.default.tv
          ? headerBackButton.classList.remove(
              "headerBackButton-showfullscreen",
              "hide",
            )
          : (headerBackButton.classList.add("headerBackButton-showfullscreen"),
            headerBackButton.classList.remove("hide"));
      })(detail),
      (function (detail) {
        userSignedIn && !1 !== detail.homeButton
          ? headerHomeButton.classList.remove("hide")
          : headerHomeButton.classList.add("hide");
      })(detail),
      setSearchVisibility(detail),
      (function (detail) {
        !_layoutmanager.default.tv && userSignedIn && allowDrawer(detail)
          ? headerMenuButton.classList.remove("hide")
          : headerMenuButton.classList.add("hide");
      })(detail),
      (function (detail) {
        (detail = detail.helpUrl) && SupportsExternalLinks
          ? ((headerHelpButton.href = detail),
            headerHelpButton.classList.remove("hide"))
          : headerHelpButton.classList.add("hide");
      })(detail),
      (function (detail) {
        !_layoutmanager.default.tv && detail.adjustHeaderForEmbeddedScroll
          ? skinHeaderElement.classList.add("adjustHeaderForEmbeddedScroll")
          : skinHeaderElement.classList.remove("adjustHeaderForEmbeddedScroll");
      })(detail),
      (function (detail) {
        !1 === detail.secondaryHeaderFeatures
          ? headerRight.classList.add("hide")
          : headerRight.classList.remove("hide");
      })(detail, e.target),
      (function (header, detail) {
        detail.defaultTitle
          ? header.setDefaultTitle()
          : null != (detail = detail.title) &&
            header.setTitle(_globalize.default.translate(detail));
      })(this, detail, e.target),
      (instance = (instance = this).pageTitleElement) &&
        (_layoutmanager.default.tv ||
        headerBackButton.classList.contains("hide")
          ? instance.classList.add("pageTitle-marginstart")
          : instance.classList.remove("pageTitle-marginstart")),
      _navdrawer.default.onViewShow(e),
      !detail.isRestored && enableWindowScroll(detail) && window.scrollTo(0, 0);
  }
  function enableWindowScroll(detail) {
    return !0 === detail.windowScroll;
  }
  function removeTransformFromHeader() {
    skinHeaderElement.style[TranslateProperty] = "none";
  }
  function onViewBeforeShow(e) {
    var detail = e.detail,
      e = e.target,
      skinHeader =
        (detail.headerTabs || _maintabsmanager.default.setTabs(null),
        skinHeaderElement);
    !1 !== detail.headerBackground &&
      skinHeader.classList.add("skinHeader-withBackground"),
      (detail.adjustHeaderForEmbeddedScroll && !0 !== detail.windowScroll) ||
        removeTransformFromHeader(),
      updateWindowScroll(detail, e),
      !1 === detail.headerBackground &&
        skinHeader.classList.remove("skinHeader-withBackground"),
      this.setTransparent(detail.transparentHeader);
  }
  function render(instance) {
    var Help, headerLeft, Back, Home, Menu;
    (instance.element = skinHeaderElement),
      (headerLeft = skinHeaderElement.querySelector(".headerLeft")),
      (Menu = _globalize.default.translate("Menu")),
      (Home = _globalize.default.translate("Home")),
      (Back = _globalize.default.translate("Back")),
      (Help = _globalize.default.translate("Help")),
      (headerLeft.innerHTML =
        '\n            <button type="button" is="paper-icon-button-light" class="headerBackButton headerButton headerSectionItem hide-mouse-idle-tv hide" tabindex="-1" title="'
          .concat(Back, '" aria-label="')
          .concat(
            Back,
            '">\n                <i class="md-icon autortl">&#xE5C4;</i>\n            </button>\n            <button type="button" is="paper-icon-button-light" class="headerHomeButton headerButton headerSectionItem hide-mouse-idle-tv hide md-icon" tabindex="-1" title="',
          )
          .concat(Home, '" aria-label="')
          .concat(
            Home,
            '">\n                &#xE88A;\n            </button>\n            <button type="button" is="paper-icon-button-light" class="headerMenuButton headerButton headerSectionItem hide md-icon" title="',
          )
          .concat(Menu, '" aria-label="')
          .concat(
            Menu,
            '">\n                &#xE5D2;\n            </button>\n            <h2 class="pageTitle headerSectionItem">&nbsp;</h2>\n\n            <a type="button" is="emby-linkbutton" class="paper-icon-button-light headerHelpButton headerButton headerSectionItem hide secondaryText" title="',
          )
          .concat(Help, '" aria-label="')
          .concat(
            Help,
            '" target="_blank" href="#">\n                <i class="md-icon autortl-arabic">&#xe887;</i>\n            </a>\n        ',
          )),
      (headerLeft = _globalize.default.translate("ManageEmbyServer")),
      (Back = _globalize.default.translate("Settings")),
      (Home = _globalize.default.translate("Search")),
      (Menu = _globalize.default.translate("PlayOnAnotherDevice")),
      (skinHeaderElement.querySelector(".headerRight").innerHTML =
        '\n            <div class="headerSelectedPlayer headerSectionItem hide">\n\n            </div>\n            <button type="button" is="paper-icon-button-light" class="headerCastButton headerButton headerSectionItem md-icon hide" title="'
          .concat(Menu, '" aria-label="')
          .concat(
            Menu,
            '">\n                &#xE307;\n            </button>\n            <button type="button" is="paper-icon-button-light" class="headerSearchButton headerButton headerSectionItem md-icon hide" title="',
          )
          .concat(Home, '" aria-label="')
          .concat(
            Home,
            '">\n                &#xE8B6;\n            </button>\n            <button type="button" is="paper-icon-button-light" class="headerUserButton headerButton headerSectionItem hide" title="',
          )
          .concat(Back, '" aria-label="')
          .concat(
            Back,
            '">\n                <i class="md-icon largeIcon">&#xE7FD;</i>\n            </button>\n            <button type="button" is="paper-icon-button-light" class="headerSettingsButton headerButton headerSectionItem md-icon hide" title="',
          )
          .concat(headerLeft, '" aria-label="')
          .concat(
            headerLeft,
            '">\n                &#xE8B8;\n            </button>\n            <div class="headerClock headerSectionItem hide"></div>\n        ',
          )),
      (function (instance) {
        var parent = instance.element;
        (headerBackButton = parent.querySelector(".headerBackButton")),
          (headerHomeButton = parent.querySelector(".headerHomeButton")),
          (headerMenuButton = parent.querySelector(".headerMenuButton")),
          (headerCastButton = parent.querySelector(".headerCastButton")),
          (headerHelpButton = parent.querySelector(".headerHelpButton")),
          (headerSearchButton = parent.querySelector(".headerSearchButton")),
          (selectedPlayerText = parent.querySelector(".headerSelectedPlayer")),
          (headerRight = parent.querySelector(".headerRight")),
          headerBackButton.addEventListener("click", onBackClick),
          headerHomeButton.addEventListener("click", onHomeClick),
          headerSearchButton.addEventListener("click", onSearchClick),
          headerCastButton.addEventListener("click", onCastButtonClick),
          parent
            .querySelector(".headerUserButton")
            .addEventListener("click", onUserButtonClick),
          parent
            .querySelector(".headerSettingsButton")
            .addEventListener("click", onSettingsButtonClick),
          headerMenuButton.addEventListener("click", onHeaderMenuButtonClick),
          (boundLayoutModeChangeFn = onLayoutModeChange.bind(instance)),
          _events.default.on(
            _layoutmanager.default,
            "modechange",
            boundLayoutModeChangeFn,
          ),
          _events.default.on(
            _playbackmanager.default,
            "playerchange",
            updateCastIcon,
          ),
          _events.default.on(
            _playbackmanager.default,
            "playqueuestart",
            onNewPlayQueueStart,
          ),
          _events.default.on(
            _connectionmanager.default,
            "localusersignedin",
            onLocalUserSignedIn,
          ),
          _events.default.on(
            _connectionmanager.default,
            "localusersignedout",
            onLocalUserSignedOut,
          ),
          _events.default.on(_api.default, "UserUpdated", onUserUpdated),
          document.addEventListener(
            "viewbeforeshow",
            onViewBeforeShow.bind(instance),
          ),
          document.addEventListener("viewshow", onViewShow.bind(instance)),
          (instance.pageTitleElement = parent.querySelector(".pageTitle")),
          resetPremiereButton(),
          _events.default.on(
            _connectionmanager.default,
            "resetregistrationinfo",
            resetPremiereButton,
          );
      })(instance),
      setRemoteControlVisibility(),
      onLayoutModeChange.call(instance),
      _events.default.on(
        _navdrawer.default,
        "drawer-state-change",
        onNavDrawerStateChange,
      ),
      _events.default.on(
        _navdrawercontent.default,
        "dynamic-title",
        function (e, title) {
          this.setTitle(title);
        }.bind(instance),
      );
  }
  function AppHeader() {}
  (AppHeader.prototype.init = function () {
    return render(this);
  }),
    (AppHeader.prototype.stopClockInterval = function () {
      var interval = this.clockInterval;
      interval && (interval.destroy(), (this.clockInterval = null));
    }),
    (AppHeader.prototype.startClockInterval = function () {
      this.clockInterval = new _methodtimer.default({
        onInterval: updateClock.bind(this),
        timeoutMs: 5e4,
        type: "interval",
      });
    }),
    (AppHeader.prototype.loadClock = function () {
      var elem;
      _layoutmanager.default.tv
        ? ((elem = document.querySelector(".headerClock")).classList.remove(
            "hide",
          ),
          (this.clockElement = elem),
          this.stopClockInterval(),
          this.startClockInterval(),
          updateClock.call(this))
        : this.destroyClock();
    });
  var defaultDocumentTitle = document.title || "Emby";
  (AppHeader.prototype.setDefaultTitle = function () {
    var pageTitleElement = this.pageTitleElement;
    pageTitleElement &&
      (pageTitleElement.classList.add(
        "pageTitleWithLogo",
        "pageTitleWithDefaultLogo",
      ),
      (pageTitleElement.style.backgroundImage = null),
      (pageTitleElement.innerHTML = "")),
      (document.title = defaultDocumentTitle);
  }),
    (AppHeader.prototype.setTitle = function (title) {
      var html, pageTitleElement;
      null == title
        ? this.setDefaultTitle()
        : ((html = (function (title) {
            return title
              ? "string" != typeof title
                ? title.Name || ""
                : title
              : "";
          })((title = "-" === title ? "" : title))),
          (pageTitleElement = this.pageTitleElement) &&
            (pageTitleElement.classList.remove(
              "pageTitleWithLogo",
              "pageTitleWithDefaultLogo",
            ),
            (pageTitleElement.style.backgroundImage = null),
            (pageTitleElement.innerHTML = html || "")),
          (document.title = title
            ? "string" == typeof title
              ? title
              : title.Name || defaultDocumentTitle
            : defaultDocumentTitle));
    }),
    (AppHeader.prototype.setLogoTitle = function (options) {
      var pageTitleElement;
      if (!(url = options.url))
        for (
          var items = options.items, i = 0, length = items.length;
          i < length;
          i++
        ) {
          var url,
            item = items[i];
          if (
            (url = (function (
              item,
              apiClient,
              options,
              preferredLogoImageTypes,
            ) {
              return apiClient.getLogoImageUrl(
                item,
                (options = options || {}),
                preferredLogoImageTypes,
              );
            })(
              item,
              _connectionmanager.default.getApiClient(item),
              {},
              options.preferredLogoImageTypes,
            ))
          )
            break;
        }
      url
        ? ((document.title = options.titleText || defaultDocumentTitle),
          ((pageTitleElement = this.pageTitleElement).style.backgroundImage =
            "url('" + url + "')"),
          pageTitleElement.classList.add("pageTitleWithLogo"),
          pageTitleElement.classList.remove("pageTitleWithDefaultLogo"),
          (pageTitleElement.innerHTML = ""))
        : this.setTitle(options.titleText);
    }),
    (AppHeader.prototype.setTransparent = function (transparent) {
      transparent
        ? skinHeaderElement.classList.add("semiTransparent")
        : skinHeaderElement.classList.remove("semiTransparent");
    }),
    (AppHeader.prototype.hasFocus = function () {
      var activeElement = document.activeElement;
      return !!activeElement && this.element.contains(activeElement);
    }),
    (AppHeader.prototype.ensureVisible = function () {
      removeTransformFromHeader();
    }),
    (AppHeader.prototype.destroyClock = function () {
      this.stopClockInterval();
      var elem = this.clockElement;
      elem && elem.classList.add("hide"), (this.clockElement = null);
    }),
    (AppHeader.prototype.destroy = function () {
      var instance;
      this.destroyClock(),
        (instance = (instance = this).element) &&
          (instance
            .querySelector(".headerBackButton")
            .removeEventListener("click", onBackClick),
          instance
            .querySelector(".headerHomeButton")
            .removeEventListener("click", onHomeClick),
          instance
            .querySelector(".headerSearchButton")
            .removeEventListener("click", onSearchClick),
          instance
            .querySelector(".headerCastButton")
            .removeEventListener("click", onCastButtonClick),
          instance
            .querySelector(".headerUserButton")
            .removeEventListener("click", onUserButtonClick),
          instance
            .querySelector(".headerSettingsButton")
            .removeEventListener("click", onSettingsButtonClick),
          instance
            .querySelector(".headerMenuButton")
            .removeEventListener("click", onHeaderMenuButtonClick)),
        _events.default.off(
          _layoutmanager.default,
          "modechange",
          boundLayoutModeChangeFn,
        ),
        _events.default.off(
          _playbackmanager.default,
          "playerchange",
          updateCastIcon,
        ),
        _events.default.off(
          _playbackmanager.default,
          "playqueuestart",
          onNewPlayQueueStart,
        ),
        _events.default.off(
          _connectionmanager.default,
          "localusersignedin",
          onLocalUserSignedIn,
        ),
        _events.default.off(
          _connectionmanager.default,
          "localusersignedout",
          onLocalUserSignedOut,
        ),
        _events.default.off(_api.default, "UserUpdated", onUserUpdated),
        _events.default.off(
          _connectionmanager.default,
          "resetregistrationinfo",
          resetPremiereButton,
        ),
        document.removeEventListener("viewbeforeshow", onViewBeforeShow),
        document.removeEventListener("viewshow", onViewShow),
        (this.element = null);
    });
  var _default = new AppHeader();
  _exports.default = _default;
});
