define([
  "exports",
  "./../common/servicelocator.js",
  "./../layoutmanager.js",
  "./../common/globalize.js",
  "./../cardbuilder/cardbuilder.js",
  "./../common/usersettings/usersettings.js",
  "./../emby-apiclient/connectionmanager.js",
  "./../common/appsettings.js",
  "./../registrationservices/registrationservices.js",
  "./../approuter.js",
  "./../emby-elements/emby-button/emby-button.js",
  "./../emby-elements/emby-button/paper-icon-button-light.js",
  "./../emby-elements/emby-itemscontainer/emby-itemscontainer.js",
  "./../emby-elements/emby-scroller/emby-scroller.js",
], function (
  _exports,
  _servicelocator,
  _layoutmanager,
  _globalize,
  _cardbuilder,
  _usersettings,
  _connectionmanager,
  _appsettings,
  _registrationservices,
  _approuter,
  _embyButton,
  _paperIconButtonLight,
  _embyItemscontainer,
  _embyScroller,
) {
  function resume(elem, options) {
    for (
      var elems = elem.querySelectorAll(".itemsContainer"),
        promises = [],
        i = 0,
        length = elems.length;
      i < length;
      i++
    )
      promises.push(elems[i].resume(options));
    elem = Promise.all(promises);
    return options && !1 === options.returnPromise ? promises[0] : elem;
  }
  function getUserViews(apiClient, userId) {
    return apiClient
      .getUserViews({}, userId || apiClient.getCurrentUserId())
      .then(function (result) {
        return result.Items;
      });
  }
  function getLibraryButtonsListOptions(items) {
    return {
      renderer: _cardbuilder.default,
      options: {
        fields: ["Name"],
        centerText: !1,
        transition: !1,
        hoverPlayButton: !1,
        sideFooter: !0,
        image: !1,
        smallSideFooter: !0,
        multiSelect: !1,
        focusTransformTitleAdjust: !0,
      },
      virtualScrollLayout: "horizontal-grid",
    };
  }
  function getAppInfoListOptions(items) {
    return {
      renderer: _cardbuilder.default,
      options: {
        shape: "autooverflow",
        fields: ["Name"],
        contextMenu: !1,
        action: "custom",
        multiSelect: !1,
        focusTransformTitleAdjust: !0,
      },
      virtualScrollLayout: "horizontal-grid",
    };
  }
  function getDownloadListOptions(items) {
    var fields = [];
    return (
      fields.push("Name"),
      fields.push("ProductionYear"),
      fields.push("ParentName"),
      {
        renderer: _cardbuilder.default,
        options: {
          preferThumb: "auto",
          inheritThumb: !1,
          shape: "autooverflow",
          fields: fields,
          showDetailsMenu: !0,
          overlayPlayButton: !0,
          context: "home",
          lines: 2,
          focusTransformTitleAdjust: !0,
        },
        virtualScrollLayout: "horizontal-grid",
      }
    );
  }
  function getLibraryCardsListOptions(items) {
    var fields = [];
    return (
      fields.push("Name"),
      {
        renderer: _cardbuilder.default,
        options: {
          shape: "backdrop",
          fields: fields,
          transition: !1,
          hoverPlayButton: !1,
          focusTransformTitleAdjust: !0,
        },
        virtualScrollLayout: "horizontal-grid",
      }
    );
  }
  function loadLibraryTiles(elem, apiClient, index, useSmallButtons) {
    var serverId,
      html = "",
      itemsContainerClass =
        ((html =
          (html +=
            '<div class="sectionTitleContainer sectionTitleContainer-cards">') +
          ('<h2 class="sectionTitle sectionTitle-cards padded-left padded-left-page padded-right">' +
            _globalize.default.translate("HeaderMyMedia") +
            "</h2>")),
        "itemsContainer scrollSlider focuscontainer-x"),
      index =
        (!_layoutmanager.default.tv &&
          index < 2 &&
          (itemsContainerClass += " itemsContainer-finepointerwrap"),
        useSmallButtons &&
          (itemsContainerClass +=
            " itemsContainer-sideFooters itemsContainer-smallSideFooters"),
        (html =
          (html =
            html +
            "</div>" +
            ('<div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right" data-mousewheel="false" data-focusscroll="true"><div is="emby-itemscontainer" class="' +
              itemsContainerClass +
              '">')) +
          "</div>" +
          "</div>"),
        elem.classList.add("hide"),
        (elem.innerHTML = html),
        useSmallButtons &&
          (_layoutmanager.default.tv
            ? elem.classList.add("padded-bottom")
            : elem.classList.add("verticalSection-extrabottompadding")),
        elem.querySelector(".itemsContainer"));
    (index.fetchData =
      ((serverId = apiClient.serverId()),
      function () {
        var apiClient = _connectionmanager.default.getApiClient(serverId);
        return getUserViews(apiClient, apiClient.getCurrentUserId());
      })),
      (index.getListOptions = useSmallButtons
        ? getLibraryButtonsListOptions
        : getLibraryCardsListOptions),
      (index.parentContainer = elem),
      useSmallButtons
        ? index.classList.remove("cardSizeSmaller")
        : index.classList.add("cardSizeSmaller");
  }
  Object.defineProperty(_exports, "__esModule", { value: !0 }),
    (_exports.default = void 0),
    (_exports.default = {
      loadSections: function (options) {
        for (
          var elem = options.element,
            apiClient = options.apiClient,
            user = options.user,
            requestedItemFields = options.requestedItemFields,
            enableFocusPreview = options.enableFocusPreview,
            requestedImageTypes = options.requestedImageTypes,
            sections = _usersettings.default.getHomeScreenSections(),
            html = "",
            i = 0,
            length = sections.length;
          i < length;
          i++
        )
          (html +=
            '<div class="verticalSection verticalSection-cards section' +
            i +
            ' focusable" data-focusabletype="nearest"></div>'),
            0 === i &&
              (html +=
                '<div class="verticalSection verticalSection-cards section-downloads hide focusable" data-focusabletype="nearest"></div><div class="verticalSection verticalSection-cards section-appinfo hide focusable" data-focusabletype="nearest"></div>');
        (elem.innerHTML = html), elem.classList.add("homeSectionsContainer");
        var promises = [];
        for (i = 0, length = sections.length; i < length; i++)
          promises.push(
            (function (
              page,
              apiClient,
              user,
              requestedItemFields,
              enableFocusPreview,
              requestedImageTypes,
              allSections,
              index,
            ) {
              var section = allSections[index],
                elem =
                  (apiClient.getCurrentUserId(),
                  page.querySelector(".section" + index));
              switch (section) {
                case "latestmedia":
                  return (function (
                    elem,
                    apiClient,
                    user,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  ) {
                    return getUserViews(
                      apiClient,
                      apiClient.getCurrentUserId(),
                    ).then(function (userViews) {
                      elem.classList.remove(
                        "verticalSection",
                        "verticalSection-cards",
                      ),
                        elem.classList.remove("focusable"),
                        elem.removeAttribute("data-focusabletype");
                      for (
                        var excludeViewTypes = [
                            "playlists",
                            "livetv",
                            "boxsets",
                            "channels",
                          ],
                          i = 0,
                          length = userViews.length;
                        i < length;
                        i++
                      ) {
                        var frag,
                          item = userViews[i];
                        user.Configuration.LatestItemsExcludes.includes(
                          item.Id,
                        ) ||
                          (item.Guid &&
                            user.Configuration.LatestItemsExcludes.includes(
                              item.Guid,
                            )) ||
                          excludeViewTypes.includes(
                            item.CollectionType || [],
                          ) ||
                          ((frag = document.createElement("div")).classList.add(
                            "hide",
                          ),
                          frag.classList.add(
                            "verticalSection",
                            "verticalSection-cards",
                          ),
                          frag.classList.add("focusable"),
                          frag.setAttribute("data-focusabletype", "nearest"),
                          elem.appendChild(frag),
                          (function (
                            elem,
                            apiClient,
                            parent,
                            requestedItemFields,
                            requestedImageTypes,
                            enableFocusPreview,
                          ) {
                            var html = "";
                            (html +=
                              '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left padded-left-page padded-right">'),
                              _layoutmanager.default.tv
                                ? (html +=
                                    '<h2 class="sectionTitle sectionTitle-cards">' +
                                    _globalize.default.translate(
                                      "LatestFromLibrary",
                                      parent.Name,
                                    ) +
                                    "</h2>")
                                : (html =
                                    (html =
                                      (html =
                                        html +
                                        ('<a is="emby-sectiontitle" href="' +
                                          _approuter.default.getRouteUrl(
                                            parent,
                                            { section: "latest" },
                                          )) +
                                        '" class="more button-link  button-link-color-inherit sectionTitleTextButton"><h2 class="sectionTitle sectionTitle-cards">') +
                                      _globalize.default.translate(
                                        "LatestFromLibrary",
                                        parent.Name,
                                      )) + "</h2></a>");
                            html += "</div>";
                            var monitor =
                                "music" === parent.CollectionType ||
                                "audiobooks" === parent.CollectionType
                                  ? "markplayed"
                                  : "videoplayback,markplayed",
                              monitor =
                                ((html =
                                  (html +=
                                    '<div data-parentid="' +
                                    parent.Id +
                                    '" is="emby-scroller" data-mousewheel="false" data-focusscroll="true" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-monitor="' +
                                    monitor +
                                    '" data-virtualscrolllayout="horizontal-grid">') +
                                  "</div></div>"),
                                (elem.innerHTML = html),
                                elem.querySelector(".itemsContainer"));
                            (monitor.fetchData = (function (
                              serverId,
                              parentId,
                              collectionType,
                              requestedItemFields,
                              requestedImageTypes,
                            ) {
                              return function (query) {
                                var apiClient =
                                    _connectionmanager.default.getApiClient(
                                      serverId,
                                    ),
                                  fields =
                                    requestedItemFields +
                                    ",PrimaryImageAspectRatio,ProductionYear";
                                return (
                                  (collectionType &&
                                    "tvshows" !== collectionType) ||
                                    (fields += ",Status,EndDate"),
                                  apiClient.getLatestItems({
                                    Limit: 16,
                                    Fields: fields,
                                    ImageTypeLimit: 1,
                                    EnableImageTypes: requestedImageTypes,
                                    ParentId: parentId,
                                  })
                                );
                              };
                            })(
                              apiClient.serverId(),
                              parent.Id,
                              parent.CollectionType,
                              requestedItemFields,
                              requestedImageTypes,
                            )),
                              (monitor.getListOptions = (function (
                                viewType,
                                enableFocusPreview,
                              ) {
                                return function (items) {
                                  var fields = [],
                                    lines = null;
                                  return (
                                    enableFocusPreview ||
                                      ("photos" !== viewType &&
                                        fields.push("Name"),
                                      ("movies" !== viewType &&
                                        "tvshows" !== viewType &&
                                        "musicvideos" !== viewType &&
                                        viewType) ||
                                        fields.push("ProductionYear"),
                                      ("music" !== viewType &&
                                        "audiobooks" !== viewType &&
                                        "tvshows" !== viewType &&
                                        "musicvideos" !== viewType &&
                                        viewType) ||
                                        fields.push("ParentName"),
                                      (lines =
                                        "musicvideos" !== viewType && viewType
                                          ? 2
                                          : 3)),
                                    {
                                      renderer: _cardbuilder.default,
                                      options: {
                                        shape: "autooverflow",
                                        preferThumb:
                                          "audiobooks" !== viewType &&
                                          "music" !== viewType
                                            ? null
                                            : "auto",
                                        showUnplayedIndicator: !1,
                                        showChildCountIndicator: !0,
                                        context: "home",
                                        overlayPlayButton:
                                          "photos" !== viewType,
                                        fields: fields,
                                        lines: lines,
                                        focusTransformTitleAdjust: !0,
                                      },
                                      virtualScrollLayout: "horizontal-grid",
                                    }
                                  );
                                };
                              })(
                                (parent.Type, parent.CollectionType),
                                enableFocusPreview,
                              )),
                              (monitor.parentContainer = elem);
                          })(
                            frag,
                            apiClient,
                            item,
                            requestedItemFields,
                            requestedImageTypes,
                            enableFocusPreview,
                          ));
                      }
                    });
                  })(
                    elem,
                    apiClient,
                    user,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  );
                case "smalllibrarytiles":
                  return loadLibraryTiles(elem, apiClient, index, !1);
                case "librarybuttons":
                  return loadLibraryTiles(elem, apiClient, index, !0);
                case "resume":
                  return (function (
                    elem,
                    apiClient,
                    allSections,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  ) {
                    var html = "",
                      html =
                        ((html =
                          (html =
                            '<h2 class="sectionTitle sectionTitle-cards padded-left padded-left-page padded-right">' +
                            _globalize.default.translate(
                              "HeaderContinueWatching",
                            ) +
                            '</h2><div is="emby-scroller" data-mousewheel="false" data-focusscroll="true" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-monitor="videoplayback,markplayed" data-virtualscrolllayout="horizontal-grid">') +
                          "</div></div>"),
                        elem.classList.add("hide"),
                        (elem.innerHTML = html),
                        elem.querySelector(".itemsContainer"));
                    (html.fetchData = (function (
                      serverId,
                      allSections,
                      requestedItemFields,
                      requestedImageTypes,
                    ) {
                      return function (query) {
                        var apiClient =
                            _connectionmanager.default.getApiClient(serverId),
                          query = Object.assign(
                            {
                              Recursive: !0,
                              Fields:
                                requestedItemFields +
                                ",PrimaryImageAspectRatio,ProductionYear",
                              ImageTypeLimit: 1,
                              EnableImageTypes: requestedImageTypes,
                              MediaTypes: "Video",
                              IncludeNextUp:
                                !allSections.includes("nextup") && null,
                            },
                            query,
                          );
                        return apiClient.getResumableItems(
                          apiClient.getCurrentUserId(),
                          query,
                        );
                      };
                    })(
                      apiClient.serverId(),
                      allSections,
                      requestedItemFields,
                      requestedImageTypes,
                    )),
                      (html.getListOptions = (function (enableFocusPreview) {
                        return function (items) {
                          var fields = [],
                            lines = null;
                          return (
                            enableFocusPreview ||
                              (fields.push("Name"),
                              fields.push("ProductionYear"),
                              fields.push("ParentName"),
                              (lines = 2)),
                            {
                              renderer: _cardbuilder.default,
                              options: {
                                preferThumb: !0,
                                shape: "backdrop",
                                fields: fields,
                                showDetailsMenu: !0,
                                overlayPlayButton: !0,
                                context: "home",
                                centerText: !0,
                                cardLayout: !1,
                                lines: lines,
                                focusTransformTitleAdjust: !0,
                                animateProgressBar: !0,
                              },
                              virtualScrollLayout: "horizontal-grid",
                              commandOptions: { removeFromResume: !0 },
                            }
                          );
                        };
                      })(enableFocusPreview)),
                      (html.parentContainer = elem);
                  })(
                    elem,
                    apiClient,
                    allSections,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  );
                case "resumeaudio":
                  return (function (
                    elem,
                    apiClient,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  ) {
                    var html = "",
                      html =
                        ((html =
                          (html =
                            '<h2 class="sectionTitle sectionTitle-cards padded-left padded-left-page padded-right">' +
                            _globalize.default.translate(
                              "HeaderContinueListening",
                            ) +
                            '</h2><div is="emby-scroller" data-mousewheel="false" data-focusscroll="true" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-monitor="audioplayback,markplayed" data-virtualscrolllayout="horizontal-grid">') +
                          "</div></div>"),
                        elem.classList.add("hide"),
                        (elem.innerHTML = html),
                        elem.querySelector(".itemsContainer"));
                    (html.fetchData = (function (
                      serverId,
                      requestedItemFields,
                      requestedImageTypes,
                    ) {
                      return function (query) {
                        var apiClient =
                            _connectionmanager.default.getApiClient(serverId),
                          query = Object.assign(
                            {
                              Recursive: !0,
                              Fields:
                                requestedItemFields +
                                ",PrimaryImageAspectRatio,ProductionYear",
                              ImageTypeLimit: 1,
                              EnableImageTypes: requestedImageTypes,
                              MediaTypes: "Audio",
                            },
                            query,
                          );
                        return apiClient.getResumableItems(
                          apiClient.getCurrentUserId(),
                          query,
                        );
                      };
                    })(
                      apiClient.serverId(),
                      requestedItemFields,
                      requestedImageTypes,
                    )),
                      (html.getListOptions = (function (enableFocusPreview) {
                        return function (items) {
                          var fields = [];
                          return (
                            enableFocusPreview ||
                              (fields.push("Name"),
                              fields.push("Album"),
                              fields.push("ParentName")),
                            {
                              renderer: _cardbuilder.default,
                              options: {
                                preferThumb: "auto",
                                shape: "auto",
                                fields: fields,
                                showDetailsMenu: !0,
                                overlayPlayButton: !0,
                                context: "home",
                                centerText: !0,
                                cardLayout: !1,
                                albumFirst: !0,
                                focusTransformTitleAdjust: !0,
                                animateProgressBar: !0,
                              },
                              virtualScrollLayout: "horizontal-grid",
                              commandOptions: { removeFromResume: !0 },
                            }
                          );
                        };
                      })(enableFocusPreview)),
                      (html.parentContainer = elem);
                  })(
                    elem,
                    apiClient,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  );
                case "activerecordings":
                  return (function (
                    elem,
                    activeRecordingsOnly,
                    apiClient,
                    requestedItemFields,
                    enableFocusPreview,
                  ) {
                    var title = activeRecordingsOnly
                        ? _globalize.default.translate("HeaderActiveRecordings")
                        : _globalize.default.translate(
                            "HeaderLatestRecordings",
                          ),
                      html = "",
                      title =
                        ((html =
                          (html =
                            (html =
                              '<div class="sectionTitleContainer sectionTitleContainer-cards"><h2 class="sectionTitle sectionTitle-cards padded-left padded-left-page padded-right">' +
                              title +
                              "</h2>") +
                            '</div><div is="emby-scroller" data-mousewheel="false" data-focusscroll="true" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-monitor="RecordingStarted,RecordingEnded" data-virtualscrolllayout="horizontal-grid">') +
                          "</div></div>"),
                        elem.classList.add("hide"),
                        (elem.innerHTML = html),
                        elem.querySelector(".itemsContainer"));
                    (title.fetchData = (function (
                      serverId,
                      activeRecordingsOnly,
                      requestedItemFields,
                    ) {
                      return function (query) {
                        var apiClient =
                          _connectionmanager.default.getApiClient(serverId);
                        return apiClient.getLiveTvRecordings(
                          Object.assign(
                            {
                              userId: apiClient.getCurrentUserId(),
                              Fields:
                                requestedItemFields +
                                ",PrimaryImageAspectRatio,ProductionYear",
                              IsLibraryItem: !!activeRecordingsOnly && null,
                              IsInProgress: !!activeRecordingsOnly || null,
                            },
                            query,
                          ),
                        );
                      };
                    })(
                      apiClient.serverId(),
                      activeRecordingsOnly,
                      requestedItemFields,
                    )),
                      (title.getListOptions = (function (enableFocusPreview) {
                        return function (items) {
                          var fields = [],
                            lines = null;
                          return (
                            enableFocusPreview ||
                              (fields.push("Name"),
                              fields.push("ProductionYear"),
                              fields.push("ParentName"),
                              (lines = 2)),
                            {
                              renderer: _cardbuilder.default,
                              options: {
                                shape: "autooverflow",
                                fields: fields,
                                showDetailsMenu: !0,
                                lines: lines,
                                preferThumb: !0,
                                cardLayout: !1,
                                focusTransformTitleAdjust: !0,
                              },
                              virtualScrollLayout: "horizontal-grid",
                            }
                          );
                        };
                      })(enableFocusPreview)),
                      (title.parentContainer = elem),
                      (title.maxTotalRecordCount = 24);
                  })(
                    elem,
                    !0,
                    apiClient,
                    requestedItemFields,
                    enableFocusPreview,
                  );
                case "nextup":
                  return (function (
                    elem,
                    apiClient,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  ) {
                    var html = "";
                    (html +=
                      '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left padded-left-page padded-right">'),
                      _layoutmanager.default.tv
                        ? (html +=
                            '<h2 class="sectionTitle sectionTitle-cards">' +
                            _globalize.default.translate("HeaderNextUp") +
                            "</h2>")
                        : (html =
                            (html =
                              (html =
                                html +
                                ('<a is="emby-sectiontitle" href="' +
                                  _approuter.default.getRouteUrl("nextup", {
                                    serverId: apiClient.serverId(),
                                  })) +
                                '" class="button-link  button-link-color-inherit sectionTitleTextButton"><h2 class="sectionTitle sectionTitle-cards">') +
                              _globalize.default.translate("HeaderNextUp")) +
                            "</h2></a>");
                    (html =
                      (html +=
                        '</div><div is="emby-scroller" data-mousewheel="false" data-focusscroll="true" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-monitor="videoplayback,markplayed" data-virtualscrolllayout="horizontal-grid">') +
                      "</div></div>"),
                      elem.classList.add("hide"),
                      (elem.innerHTML = html);
                    html = elem.querySelector(".itemsContainer");
                    (html.fetchData = (function (
                      serverId,
                      requestedItemFields,
                      requestedImageTypes,
                    ) {
                      return function (query) {
                        var apiClient =
                          _connectionmanager.default.getApiClient(serverId);
                        return apiClient.getNextUpEpisodes(
                          Object.assign(
                            {
                              LegacyNextUp: !0,
                              Fields:
                                requestedItemFields +
                                ",PrimaryImageAspectRatio,ProductionYear,SeriesInfo,DateCreated",
                              ImageTypeLimit: 1,
                              EnableImageTypes: requestedImageTypes,
                              UserId: apiClient.getCurrentUserId(),
                            },
                            query,
                          ),
                        );
                      };
                    })(
                      apiClient.serverId(),
                      requestedItemFields,
                      requestedImageTypes,
                    )),
                      (html.getListOptions = (function (enableFocusPreview) {
                        return function () {
                          var fields = [];
                          return (
                            enableFocusPreview ||
                              (fields.push("Name"), fields.push("ParentName")),
                            {
                              renderer: _cardbuilder.default,
                              options: {
                                preferThumb: !0,
                                shape: "backdrop",
                                fields: fields,
                                overlayPlayButton: !0,
                                context: "home",
                                centerText: !0,
                                cardLayout: !1,
                                focusTransformTitleAdjust: !0,
                              },
                              virtualScrollLayout: "horizontal-grid",
                              commandOptions: { removeFromNextUp: !0 },
                            }
                          );
                        };
                      })(enableFocusPreview)),
                      (html.parentContainer = elem);
                  })(
                    elem,
                    apiClient,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  );
                case "livetv":
                  return (function (
                    elem,
                    apiClient,
                    user,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  ) {
                    return user.Policy.EnableLiveTvAccess
                      ? ((user = []).push(
                          _registrationservices.default
                            .validateFeature("livetv", {
                              viewOnly: !0,
                              showDialog: !1,
                            })
                            .then(
                              function () {
                                return Promise.resolve(!0);
                              },
                              function () {
                                return Promise.resolve(!1);
                              },
                            ),
                        ),
                        Promise.all(user).then(function (responses) {
                          var html = "";
                          responses[0]
                            ? (elem.classList.remove(
                                "padded-left",
                                "padded-left-page",
                              ),
                              elem.classList.remove("padded-right"),
                              elem.classList.remove("padded-bottom"),
                              elem.classList.remove(
                                "verticalSection",
                                "verticalSection-cards",
                              ),
                              elem.classList.remove("focusable"),
                              elem.removeAttribute("data-focusabletype"),
                              (html =
                                (html =
                                  (html =
                                    (html =
                                      (html =
                                        (html +=
                                          '<div class="verticalSection verticalSection-cards focusable" data-focusabletype="nearest"><div class="sectionTitleContainer sectionTitleContainer-cards padded-left padded-left-page padded-right">') +
                                        '<h2 class="sectionTitle sectionTitle-cards">' +
                                        _globalize.default.translate("LiveTV") +
                                        '</h2></div><div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right" data-mousewheel="false" data-focusscroll="true" data-scrollbuttons="false"><div class="scrollSlider padded-bottom focuscontainer-x flex align-items-center">') +
                                      '<a style="margin:.5em 0 .5em .4em;" is="emby-linkbutton" href="' +
                                      _approuter.default.getRouteUrl("livetv", {
                                        serverId: apiClient.serverId(),
                                        section: "programs",
                                      }) +
                                      '" class="raised justify-content-center"><i class="md-icon button-icon button-icon-left">&#xe639;</i><span>' +
                                      _globalize.default.translate("Programs") +
                                      "</span></a>") +
                                    '<a style="margin:.5em 0 .5em .8em;" is="emby-linkbutton" href="' +
                                    _approuter.default.getRouteUrl("livetv", {
                                      serverId: apiClient.serverId(),
                                      section: "guide",
                                    }) +
                                    '" class="raised justify-content-center"><i class="md-icon button-icon button-icon-left autortl">&#xe1b2;</i><span>' +
                                    _globalize.default.translate("Guide") +
                                    "</span></a>") +
                                  '<a style="margin:.5em 0 .5em .8em;" is="emby-linkbutton" href="' +
                                  _approuter.default.getRouteUrl("recordedtv", {
                                    serverId: apiClient.serverId(),
                                  }) +
                                  '" class="raised justify-content-center"><i class="md-icon button-icon button-icon-left">folder</i><span>' +
                                  _globalize.default.translate("Recordings") +
                                  "</span></a>") +
                                '<a style="margin:.5em 0 .5em .8em;" is="emby-linkbutton" href="' +
                                _approuter.default.getRouteUrl("livetv", {
                                  serverId: apiClient.serverId(),
                                  section: "dvrschedule",
                                }) +
                                '" class="raised justify-content-center"><i class="md-icon button-icon button-icon-left">&#xe916;</i><span>' +
                                _globalize.default.translate("Schedule") +
                                '</span></a></div></div></div></div><div class="verticalSection verticalSection-cards focusable" data-focusabletype="nearest"><div class="sectionTitleContainer sectionTitleContainer-cards padded-left padded-left-page padded-right">'),
                              _layoutmanager.default.tv
                                ? (html +=
                                    '<h2 class="sectionTitle sectionTitle-cards">' +
                                    _globalize.default.translate(
                                      "HeaderOnNow",
                                    ) +
                                    "</h2>")
                                : (html =
                                    (html =
                                      html +
                                      ('<a is="emby-sectiontitle" href="' +
                                        _approuter.default.getRouteUrl(
                                          "livetv",
                                          {
                                            serverId: apiClient.serverId(),
                                            section: "onnow",
                                          },
                                        )) +
                                      '" class="more button-link  button-link-color-inherit sectionTitleTextButton"><h2 class="sectionTitle sectionTitle-cards">') +
                                    _globalize.default.translate(
                                      "HeaderOnNow",
                                    ) +
                                    "</h2></a>"),
                              (elem.innerHTML = html =
                                (html =
                                  (html += "</div>") +
                                  '<div is="emby-scroller" data-mousewheel="false" data-focusscroll="true" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-refreshinterval="300000" data-virtualscrolllayout="horizontal-grid">' +
                                  "</div>") +
                                "</div>" +
                                "</div>"),
                              ((responses =
                                elem.querySelector(
                                  ".itemsContainer",
                                )).parentContainer = elem),
                              (responses.fetchData = (function (
                                serverId,
                                requestedItemFields,
                                requestedImageTypes,
                              ) {
                                return function (query) {
                                  var apiClient =
                                    _connectionmanager.default.getApiClient(
                                      serverId,
                                    );
                                  return (
                                    (query = Object.assign(
                                      {
                                        userId: apiClient.getCurrentUserId(),
                                        IsAiring: !0,
                                        ImageTypeLimit: 1,
                                        EnableImageTypes: requestedImageTypes,
                                        Fields:
                                          requestedItemFields +
                                          ",ProgramPrimaryImageAspectRatio",
                                        EnableUserData: !1,
                                      },
                                      query,
                                    )),
                                    _usersettings.default.addLiveTvChannelSortingToQuery(
                                      query,
                                      _globalize.default,
                                    ),
                                    apiClient.getLiveTvChannels(query)
                                  );
                                };
                              })(
                                apiClient.serverId(),
                                requestedItemFields,
                                requestedImageTypes,
                              )),
                              (responses.getListOptions = (function (
                                enableFocusPreview,
                              ) {
                                return function (items) {
                                  var fields = [];
                                  return (
                                    enableFocusPreview ||
                                      (fields.push("CurrentProgramName"),
                                      fields.push("CurrentProgramParentName"),
                                      fields.push("CurrentProgramTime")),
                                    {
                                      renderer: _cardbuilder.default,
                                      options: {
                                        preferThumb: "auto",
                                        inheritThumb: !1,
                                        shape: "autooverflow",
                                        fields: fields,
                                        showCurrentProgramImage: !0,
                                        showAirDateTime: !1,
                                        overlayPlayButton: !0,
                                        defaultShape: "portrait",
                                        action: "programlink",
                                        multiSelect: !1,
                                        focusTransformTitleAdjust: !0,
                                      },
                                      virtualScrollLayout: "horizontal-grid",
                                      commandOptions: { createRecording: !1 },
                                    }
                                  );
                                };
                              })(enableFocusPreview)))
                            : (elem.classList.add("hide"),
                              elem.classList.remove("focusable"),
                              elem.classList.add(
                                "padded-left",
                                "padded-left-page",
                              ),
                              elem.classList.add("padded-right"),
                              elem.classList.add("padded-bottom"),
                              (html =
                                (html =
                                  html +
                                  ('<h2 class="sectionTitle">' +
                                    _globalize.default.translate(
                                      "LiveTvRequiresUnlock",
                                    )) +
                                  '</h2><button is="emby-button" type="button" class="raised button-submit block btnUnlock">') +
                                "<span>" +
                                _globalize.default.translate(
                                  "HeaderBecomeProjectSupporter",
                                ) +
                                "</span>"),
                              (elem.innerHTML = html += "</button>"),
                              (function (elem, apiClient) {
                                apiClient
                                  .getLiveTvChannels({
                                    userId: apiClient.getCurrentUserId(),
                                    limit: 1,
                                    ImageTypeLimit: 1,
                                    EnableTotalRecordCount: !1,
                                    EnableImages: !1,
                                    EnableUserData: !1,
                                  })
                                  .then(function (result) {
                                    result.Items.length
                                      ? (elem.classList.add("focusable"),
                                        elem.classList.remove("hide"))
                                      : (elem.classList.add("hide"),
                                        elem.classList.remove("focusable"));
                                  });
                              })(elem, apiClient)),
                            (function (elem) {
                              var btnUnlock = elem.querySelector(".btnUnlock");
                              btnUnlock &&
                                btnUnlock.addEventListener(
                                  "click",
                                  function (e) {
                                    _registrationservices.default
                                      .validateFeature("livetv", {
                                        viewOnly: !0,
                                      })
                                      .then(function () {
                                        elem
                                          .closest(".homeSectionsContainer")
                                          .dispatchEvent(
                                            new CustomEvent("settingschange", {
                                              cancelable: !1,
                                            }),
                                          );
                                      });
                                  },
                                );
                            })(elem);
                        }))
                      : (elem.classList.add("hide"),
                        elem.classList.remove("focusable"),
                        Promise.resolve());
                  })(
                    elem,
                    apiClient,
                    user,
                    requestedItemFields,
                    requestedImageTypes,
                    enableFocusPreview,
                  );
                default:
                  return (elem.innerHTML = ""), Promise.resolve();
              }
            })(
              elem,
              apiClient,
              user,
              requestedItemFields,
              enableFocusPreview,
              requestedImageTypes,
              sections,
              i,
            ),
          ),
            0 === i &&
              (promises.push(
                (function (elem, apiClient) {
                  elem.classList.add("hide");
                  var html = "";
                  (html =
                    (html =
                      (html =
                        (html +=
                          '<div class="sectionTitleContainer sectionTitleContainer-cards padded-left padded-left-page padded-right">') +
                        '<a is="emby-sectiontitle" href="' +
                        _approuter.default.getRouteUrl("downloads") +
                        '" class="more button-link  button-link-color-inherit sectionTitleTextButton"><h2 class="sectionTitle sectionTitle-cards">') +
                      _globalize.default.translate("Downloads")) + "</h2></a>"),
                    _layoutmanager.default.tv ||
                      (html +=
                        '<a is="emby-linkbutton" href="' +
                        _approuter.default.getRouteUrl("managedownloads") +
                        '" class="sectionTitleIconButton"><i class="md-icon">&#xE8B8;</i></a>');
                  (html =
                    (html +=
                      '</div><div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right" data-mousewheel="false" data-focusscroll="true"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x" data-virtualscrolllayout="horizontal-grid">') +
                    "</div></div>"),
                    (elem.innerHTML = html);
                  html = elem.querySelector(".itemsContainer");
                  (html.fetchData = (function (serverId) {
                    return function () {
                      var apiClient;
                      return _servicelocator.appHost.supports("sync")
                        ? (apiClient =
                            _connectionmanager.default.getApiClient(serverId))
                            .getCurrentUser()
                            .then(function (user) {
                              return user.Policy.EnableContentDownloading &&
                                apiClient.getLatestOfflineItems
                                ? apiClient.getLatestOfflineItems({
                                    Limit: 20,
                                    Filters: "IsNotFolder",
                                  })
                                : Promise.resolve([]);
                            })
                        : Promise.resolve([]);
                    };
                  })(apiClient.serverId())),
                    (html.getListOptions = getDownloadListOptions),
                    (html.parentContainer = elem);
                })(elem.querySelector(".section-downloads"), apiClient),
              ),
              promises.push(
                (function (elem, apiClient) {
                  elem.classList.add("hide"),
                    (elem.innerHTML = (function () {
                      var html = "";
                      return (html =
                        (html =
                          (html =
                            (html +=
                              '<div class="sectionTitleContainer sectionTitleContainer-cards">') +
                            '<h2 class="sectionTitle sectionTitle-cards padded-left padded-left-page padded-right">Discover Emby Premiere</h2></div>') +
                          '<p class="sectionTitle-cards padded-left padded-left-page padded-right">Enjoy Emby DVR, get free access to Emby apps, and more.</p><div is="emby-scroller" data-mousewheel="false" data-focusscroll="true" class="padded-top-focusscale padded-bottom-focusscale padded-left padded-left-page padded-right"><div is="emby-itemscontainer" class="itemsContainer scrollSlider focuscontainer-x">') +
                        "</div></div>");
                    })()),
                    (function (elem) {
                      elem = elem.querySelector(".itemsContainer");
                      elem &&
                        elem.addEventListener("action-null", function (e) {
                          e.target.closest(".card") &&
                            _registrationservices.default.showPremiereInfo();
                        });
                    })(elem);
                  var itemsContainer = elem.querySelector(".itemsContainer");
                  return (
                    (itemsContainer.fetchData = function () {
                      var apiClient = this,
                        cacheKey = "lastappinfopresent5",
                        lastDatePresented = parseInt(
                          _appsettings.default.get(cacheKey) || "0",
                        );
                      if (!lastDatePresented)
                        return (
                          _appsettings.default.set(cacheKey, Date.now()),
                          Promise.resolve([])
                        );
                      if (Date.now() - lastDatePresented < 1728e5)
                        return Promise.resolve([]);
                      return _registrationservices.default
                        .validateFeature("dvr", {
                          showDialog: !1,
                          viewOnly: !0,
                        })
                        .then(
                          function () {
                            return (
                              _appsettings.default.set(cacheKey, Date.now()), []
                            );
                          },
                          function () {
                            return (
                              _appsettings.default.set(cacheKey, Date.now()),
                              (function (apiClient) {
                                var items = [];
                                return (
                                  items.push({
                                    Name: "",
                                    Id: "PremiereInfo1",
                                    ImageUrl:
                                      "https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater1.png",
                                    PrimaryImageAspectRatio: 16 / 9,
                                    ServerId: apiClient.serverId(),
                                  }),
                                  items.push({
                                    Name: "",
                                    Id: "PremiereInfo2",
                                    ImageUrl:
                                      "https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater2.png",
                                    PrimaryImageAspectRatio: 16 / 9,
                                    ServerId: apiClient.serverId(),
                                  }),
                                  items.push({
                                    Name: "",
                                    Id: "PremiereInfo3",
                                    ImageUrl:
                                      "https://raw.githubusercontent.com/MediaBrowser/Emby.Resources/master/apps/theater3.png",
                                    PrimaryImageAspectRatio: 16 / 9,
                                    ServerId: apiClient.serverId(),
                                  }),
                                  Promise.resolve({
                                    Items: items,
                                    TotalRecordCount: items.length,
                                  })
                                );
                              })(apiClient)
                            );
                          },
                        );
                    }.bind(apiClient)),
                    (itemsContainer.getListOptions = getAppInfoListOptions),
                    (itemsContainer.parentContainer = elem),
                    Promise.resolve()
                  );
                })(elem.querySelector(".section-appinfo"), apiClient),
              ));
        return Promise.all(promises).then(function () {
          return resume(elem, { refresh: !0, returnPromise: !1 });
        });
      },
      pause: function (elem) {
        for (
          var elems = elem.querySelectorAll(".itemsContainer"),
            i = 0,
            length = elems.length;
          i < length;
          i++
        )
          elems[i].pause();
      },
      resume: resume,
    });
});
