define([
  "exports",
  "./../modules/emby-apiclient/connectionmanager.js",
  "./../modules/layoutmanager.js",
  "./../modules/cardbuilder/cardbuilder.js",
  "./../modules/tabbedview/basetab.js",
  "./../modules/emby-elements/emby-itemscontainer/emby-itemscontainer.js",
  "./../modules/emby-elements/emby-scroller/emby-scroller.js",
], function (
  _exports,
  _connectionmanager,
  _layoutmanager,
  _cardbuilder,
  _basetab,
  _embyItemscontainer,
  _embyScroller,
) {
  function enableScrollX(section) {
    return "resume" === section || _layoutmanager.default.tv;
  }
  function TvSuggestionsTab(view, params) {
    _basetab.default.apply(this, arguments),
      (this.view = view),
      (this.params = params),
      (this.apiClient = _connectionmanager.default.getApiClient(
        params.serverId,
      )),
      (function (view) {
        for (
          var containers = view.querySelectorAll(".autoScrollSection"),
            i = 0,
            length = containers.length;
          i < length;
          i++
        ) {
          var section = containers[i],
            html = void 0,
            sectionType = section.getAttribute("data-section"),
            commands =
              "resume" === sectionType
                ? ' data-commands="removefromresume"'
                : "";
          (html = enableScrollX(sectionType)
            ? '<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"' +
              commands +
              ' class="itemsContainer scrollSlider focuscontainer-x" data-monitor="videoplayback,markplayed" data-virtualscrolllayout="horizontal-grid"></div></div>'
            : '<div is="emby-itemscontainer"' +
              commands +
              ' class="itemsContainer padded-left padded-left-page padded-right vertical-wrap focuscontainer-x" data-monitor="videoplayback,markplayed"></div>'),
            section.insertAdjacentHTML("beforeend", html);
        }
      })(view),
      (this.resumeItemsContainer = view.querySelector(
        ".resumeSection .itemsContainer",
      )),
      (this.resumeItemsContainer.fetchData = function (query) {
        var apiClient = this.apiClient,
          parentId = this.params.parentId;
        return apiClient.getResumableItems(
          apiClient.getCurrentUserId(),
          Object.assign(
            {
              IncludeItemTypes: "Episode",
              Fields:
                this.getRequestedItemFields() + ",PrimaryImageAspectRatio",
              ParentId: parentId,
              ImageTypeLimit: 1,
              EnableImageTypes: this.getRequestedImageTypes(),
            },
            query,
          ),
        );
      }.bind(this)),
      (this.resumeItemsContainer.getListOptions = function () {
        return {
          renderer: _cardbuilder.default,
          options: {
            preferThumb: !0,
            shape: "backdrop",
            scalable: !0,
            fields: this.enableFocusPreview() ? [] : ["ParentName", "Name"],
            centerText: !0,
            overlayPlayButton: !0,
            cardLayout: !1,
            focusTransformTitleAdjust: !0,
            animateProgressBar: !0,
          },
          virtualScrollLayout: "horizontal-grid",
        };
      }.bind(this)),
      (this.resumeItemsContainer.parentContainer =
        view.querySelector(".resumeSection")),
      this.addFocusBehavior(this.resumeItemsContainer),
      (this.latestItemsContainer = view.querySelector(
        ".latestSection .itemsContainer",
      )),
      (this.latestItemsContainer.fetchData = function (query) {
        var parentId = this.params.parentId;
        return this.apiClient.getLatestItems(
          Object.assign({
            IncludeItemTypes: "Episode",
            Limit: 30,
            Fields: this.getRequestedItemFields() + ",PrimaryImageAspectRatio",
            ParentId: parentId,
            ImageTypeLimit: 1,
            EnableImageTypes: this.getRequestedImageTypes(),
            GroupItems: !1,
          }),
          query,
        );
      }.bind(this)),
      (this.latestItemsContainer.getListOptions = function () {
        return {
          renderer: _cardbuilder.default,
          options: {
            preferThumb: !0,
            shape: "backdrop",
            scalable: !0,
            fields: this.enableFocusPreview() ? [] : ["ParentName", "Name"],
            centerText: !0,
            overlayPlayButton: !0,
            cardLayout: !1,
            focusTransformTitleAdjust: !0,
          },
          virtualScrollLayout: enableScrollX("latest")
            ? "horizontal-grid"
            : "vertical-grid",
        };
      }.bind(this)),
      (this.latestItemsContainer.parentContainer =
        view.querySelector(".latestSection")),
      this.addFocusBehavior(this.latestItemsContainer),
      params.parentId &&
        (this.resumeItemsContainer.setAttribute(
          "data-parentid",
          params.parentId,
        ),
        this.latestItemsContainer.setAttribute(
          "data-parentid",
          params.parentId,
        ));
  }
  Object.defineProperty(_exports, "__esModule", { value: !0 }),
    (_exports.default = void 0),
    Object.assign(TvSuggestionsTab.prototype, _basetab.default.prototype),
    (TvSuggestionsTab.prototype.supportsFocusPreview = function () {
      return !0;
    }),
    (TvSuggestionsTab.prototype.enableFocusPreview = function () {
      return _layoutmanager.default.tv && this.supportsFocusPreview();
    }),
    (TvSuggestionsTab.prototype.onResume = function (options) {
      _basetab.default.prototype.onResume.apply(this, arguments);
      var promises = [],
        instance =
          (promises.push(this.resumeItemsContainer.resume(options)),
          promises.push(this.latestItemsContainer.resume(options)),
          this);
      Promise.all(promises).then(function () {
        options.autoFocus && instance.autoFocus(),
          instance.fillFocusPreviewIfNeeded();
      });
    }),
    (TvSuggestionsTab.prototype.onPause = function () {
      _basetab.default.prototype.onPause.apply(this, arguments),
        this.resumeItemsContainer.pause(),
        this.latestItemsContainer.pause();
    }),
    (TvSuggestionsTab.prototype.destroy = function () {
      _basetab.default.prototype.destroy.apply(this, arguments),
        (this.view = null),
        (this.params = null),
        (this.apiClient = null),
        (this.resumeItemsContainer = null),
        (this.latestItemsContainer = null);
    }),
    (_exports.default = TvSuggestionsTab);
});
