/* 
Disable shit
return null != val ? this.set("enableLogoAsTitle", val.toString(), !1) : !!(val = this.get("enableCinemaMode", !1)) && "false" !== val

Enable shit
return null != val ? this.set("drawerstyle", val.toString(), !1) : "false" !== (val = this.get("enableBackdrops", !1))
*/
define([
  "exports",
  "./../appsettings.js",
  "./../../emby-apiclient/events.js",
], function (_exports, _appsettings, _events) {
  function UserSettings() {}
  function getHomeSection(instance, index) {
    index =
      instance.get("homesection" + index) ||
      instance.getDefaultHomeScreenSection(index);
    return (
      "folders" === index
        ? (index = instance.getDefaultHomeScreenSection(0))
        : "onnow" === index
        ? (index = "livetv")
        : ("librarytiles" !== index &&
            "smalllibrarytiles-automobile" !== index &&
            "librarytiles-automobile" !== index) ||
          (index = "smalllibrarytiles"),
      index
    );
  }
  Object.defineProperty(_exports, "__esModule", { value: !0 }),
    (_exports.default = void 0),
    (UserSettings.prototype.setUserInfo = function (userId, apiClient) {
      var self;
      return (
        this.saveTimeout && clearTimeout(this.saveTimeout),
        (this.currentUserId = userId),
        (this.currentApiClient = apiClient),
        userId
          ? ((self = this),
            apiClient
              .getDisplayPreferences("usersettings", userId, "emby")
              .then(function (result) {
                (result.CustomPrefs = result.CustomPrefs || {}),
                  (self.displayPrefs = result),
                  _events.default.trigger(self, "load");
              }))
          : ((this.displayPrefs = null), Promise.resolve())
      );
    }),
    (UserSettings.prototype.getData = function () {
      return this.displayPrefs;
    }),
    (UserSettings.prototype.importFrom = function (instance) {
      this.displayPrefs = instance.getData();
    }),
    (UserSettings.prototype.set = function (name, value, enableOnServer) {
      var currentValue,
        userId = this.currentUserId;
      if (userId)
        return (
          (currentValue = this.get(name, enableOnServer)),
          (userId = _appsettings.default.set(
            name,
            (value = null == value ? null : value),
            userId,
          )),
          !1 !== enableOnServer &&
            this.displayPrefs &&
            ((this.displayPrefs.CustomPrefs[name] =
              null == value ? value : value.toString()),
            (enableOnServer = this).saveTimeout &&
              clearTimeout(enableOnServer.saveTimeout),
            (enableOnServer.saveTimeout = setTimeout(
              function () {
                (this.saveTimeout = null),
                  this.currentApiClient.updateDisplayPreferences(
                    "usersettings",
                    this.displayPrefs,
                    this.currentUserId,
                    "emby",
                  );
              }.bind(enableOnServer),
              50,
            ))),
          currentValue !== value &&
            _events.default.trigger(this, "change", [name, value]),
          userId
        );
      throw new Error("userId cannot be null");
    }),
    (UserSettings.prototype.remove = function (name, enableOnServer) {
      return this.set(name, null, enableOnServer);
    }),
    (UserSettings.prototype.get = function (name, enableOnServer) {
      var userId = this.currentUserId;
      return userId
        ? !1 !== enableOnServer && this.displayPrefs
          ? this.displayPrefs.CustomPrefs[name]
          : _appsettings.default.get(name, userId)
        : null;
    }),
    (UserSettings.prototype.serverConfig = function (config) {
      var apiClient = this.currentApiClient;
      return config
        ? apiClient.updateUserConfiguration(this.currentUserId, config)
        : apiClient.getUser(this.currentUserId).then(function (user) {
            return user.Configuration;
          });
    }),
    (UserSettings.prototype.enableCinemaMode = function (val) {
      return null != val
        ? this.set("enableCinemaMode", val.toString(), !1)
        : !(val = this.get("enableCinemaMode", !1)) || "false" !== val;
    }),
    (UserSettings.prototype.enableNextVideoInfoOverlay = function (val) {
      return null != val
        ? this.set("enableNextVideoInfoOverlay", val.toString())
        : "false" !== (val = this.get("enableNextVideoInfoOverlay"));
    }),
    (UserSettings.prototype.getEnableLogoAsTitle = function (displayLanguage) {
      var val = this.get("enableLogoAsTitle");
      return val
        ? "true" === val
        : displayLanguage && displayLanguage.toLowerCase().startsWith("jp");
    }),
    (UserSettings.prototype.setEnableLogoAsTitle = function (val) {
      return this.set("enableLogoAsTitle", val.toString());
    }),
    (UserSettings.prototype.enableThemeSongs = function (val) {
      return null != val
        ? this.set("enableThemeVideos", val.toString(), !1)
        : !!(val = this.get("enableThemeVideos", !1)) && "false" !== val;
    }),
    (UserSettings.prototype.enableThemeVideos = function (val) {
      return null != val
        ? this.set("enableThemeVideos", val.toString(), !1)
        : !!(val = this.get("enableThemeVideos", !1)) && "false" !== val;
    }),
    (UserSettings.prototype.hideMediaTransportButtons = function (val) {
      return null != val
        ? this.set("hideMediaTransportButtons", val.toString(), !1)
        : this.get("hideMediaTransportButtons", !1) || "auto";
    }),
    (UserSettings.prototype.enableHomescreenFocusPreviews = function (val) {
      return null != val
        ? this.set("enableHomescreenFocusPreviews", val.toString(), !0)
        : "true" === (val = this.get("enableHomescreenFocusPreviews", !0));
    }),
    (UserSettings.prototype.enableBackdrops = function (val) {
      return null != val
        ? this.set("enableBackdrops", val.toString(), !0)
        : "false" !== this.get("enableBackdrops", !0);
    }),
    (UserSettings.prototype.enableRatingInfoOnPlaybackStart = function (val) {
      return null != val
        ? this.set("enableRatingInfoOnPlaybackStart", val.toString(), !0)
        : "false" !== (val = this.get("enableRatingInfoOnPlaybackStart", !0));
    }),
    (UserSettings.prototype.language = function (val) {
      return null != val
        ? this.set("language", val.toString(), !1)
        : this.get("language", !1);
    }),
    (UserSettings.prototype.dateTimeLocale = function (val) {
      return null != val
        ? this.set("datetimelocale", val.toString(), !1)
        : this.get("datetimelocale", !1);
    }),
    (UserSettings.prototype.skipBackLength = function (val) {
      return null != val
        ? this.set("skipBackLength", val.toString())
        : parseInt(this.get("skipBackLength") || "10000");
    }),
    (UserSettings.prototype.skipForwardLength = function (val) {
      return null != val
        ? this.set("skipForwardLength", val.toString())
        : parseInt(this.get("skipForwardLength") || "10000");
    }),
    (UserSettings.prototype.settingsTheme = function (val) {
      return null != val
        ? this.set("settingsTheme", val, !0)
        : this.get("settingsTheme", !0) || "blueradiance";
    }),
    (UserSettings.prototype.theme = function (val) {
      return null != val
        ? this.set("appTheme", val, !0)
        : this.get("appTheme", !0) || "blueradiance";
    }),
    (UserSettings.prototype.accentColor = function (val) {
      return null != val
        ? this.set("accentColor", val, !0)
        : this.get("accentColor", !0) || "purple";
    }),
    (UserSettings.prototype.screensaver = function (val) {
      return null != val
        ? this.set("screensaver", val, !1)
        : this.get("screensaver", !1) || null;
    }),
    (UserSettings.prototype.soundEffects = function (val) {
      return null != val
        ? this.set("soundeffects", val, !1)
        : this.get("soundeffects", !1) || null;
    }),
    (UserSettings.prototype.osdContentSection = function (val) {
      return null != val
        ? this.set("osdcontentsection", val, !1)
        : this.get("osdcontentsection", !1);
    }),
    (UserSettings.prototype.drawerStyle = function (val) {
      return null != val
        ? this.set("drawerstyle", val, !1)
        : this.get("drawerstyle", !1) || "docked";
    }),
    (UserSettings.prototype.settingsDrawerStyle = function (val) {
      return null != val
        ? this.set("settingsdrawerstyle", val, !1)
        : this.get("settingsdrawerstyle", !1) || "docked";
    }),
    (UserSettings.prototype.nowPlayingAudioBackgroundStyle = function (val) {
      return null != val
        ? this.set("nowPlayingAudioBackgroundStyle", val, !0)
        : this.get("nowPlayingAudioBackgroundStyle", !0) || "blur";
    }),
    (UserSettings.prototype.nowPlayingVideoBackgroundStyle = function (val) {
      return null != val
        ? this.set("nowPlayingVideoBackgroundStyle", val, !0)
        : this.get("nowPlayingVideoBackgroundStyle", !0) || "backdrop";
    }),
    (UserSettings.prototype.stillWatchingTimeMs = function (val) {
      return null != val
        ? this.set("stillwatchingms", val, !0)
        : parseInt(this.get("stillwatchingms", !0) || "14400000");
    }),
    (UserSettings.prototype.tvHome = function (val) {
      return null != val
        ? this.set("tvhome", val, !0)
        : this.get("tvhome", !0) || "vertical";
    }),
    (UserSettings.prototype.itemSortBy = function (itemId, val) {
      itemId = "sortitems-" + itemId + "-by";
      return null != val
        ? this.set(itemId, val, !1)
        : this.get(itemId, !1) || "";
    }),
    (UserSettings.prototype.itemSortOrder = function (itemId, val) {
      itemId = "sortitems-" + itemId + "-order";
      return null != val
        ? this.set(itemId, val, !1)
        : this.get(itemId, !1) || "Ascending";
    }),
    (UserSettings.prototype.enableStillWatching = function (val) {
      return null != val
        ? this.stillWatchingTimeMs(val ? 144e5 : 0)
        : 0 < this.stillWatchingTimeMs();
    }),
    (UserSettings.prototype.getSubtitleAppearanceSettings = function (key) {
      key = key || "localplayersubtitleappearance3";
      key = JSON.parse(this.get(key, !1) || "{}");
      return (
        key.dropShadow || (key.dropShadow = "dropshadow"),
        key.textBackground || (key.textBackground = "transparent"),
        key.textBackgroundOpacity || (key.textBackgroundOpacity = "1"),
        key.textColor || (key.textColor = "#ffffff"),
        key.verticalPosition || (key.verticalPosition = "10"),
        key
      );
    }),
    (UserSettings.prototype.setSubtitleAppearanceSettings = function (
      value,
      key,
    ) {
      return this.set(
        (key = key || "localplayersubtitleappearance3"),
        JSON.stringify(value),
        !1,
      );
    }),
    (UserSettings.prototype.setFilter = function (key, value, enableOnServer) {
      return this.set(key, value, !0 === enableOnServer);
    }),
    (UserSettings.prototype.getFilter = function (key, enableOnServer) {
      key = this.get(key, !0 === enableOnServer);
      return "null" === key || "" === key ? null : key;
    }),
    (UserSettings.prototype.getDefaultHomeScreenSection = function (index) {
      switch (index) {
        case 0:
          return "smalllibrarytiles";
        case 1:
          return "resume";
        case 2:
          return "resumeaudio";
        case 3:
          return "livetv";
        case 4:
          return "none";
        case 5:
          return "latestmedia";
        default:
          return "none";
      }
    }),
    (UserSettings.prototype.homeSection0 = function (val) {
      return null != val
        ? this.set("homesection0", val.toString(), !0)
        : getHomeSection(this, 0);
    }),
    (UserSettings.prototype.homeSection1 = function (val) {
      return null != val
        ? this.set("homesection1", val.toString(), !0)
        : getHomeSection(this, 1);
    }),
    (UserSettings.prototype.homeSection2 = function (val) {
      return null != val
        ? this.set("homesection2", val.toString(), !0)
        : getHomeSection(this, 2);
    }),
    (UserSettings.prototype.homeSection3 = function (val) {
      return null != val
        ? this.set("homesection3", val.toString(), !0)
        : getHomeSection(this, 3);
    }),
    (UserSettings.prototype.homeSection4 = function (val) {
      return null != val
        ? this.set("homesection4", val.toString(), !0)
        : getHomeSection(this, 4);
    }),
    (UserSettings.prototype.homeSection5 = function (val) {
      return null != val
        ? this.set("homesection5", val.toString(), !0)
        : getHomeSection(this, 5);
    }),
    (UserSettings.prototype.homeSection6 = function (val) {
      return null != val
        ? this.set("homesection6", val.toString(), !0)
        : getHomeSection(this, 6);
    }),
    (UserSettings.prototype.getHomeScreenSections = function (includeBlanks) {
      for (var sections = [], i = 0; i < 7; i++) {
        var section = getHomeSection(this, i);
        ("none" === section && !includeBlanks) || sections.push(section);
      }
      return sections;
    }),
    (UserSettings.prototype.enableVideoUnderUI = function (val) {
      return null != val
        ? this.set("enableVideoUnderUI", val.toString(), !1)
        : "true" === this.get("enableVideoUnderUI", !1);
    }),
    (UserSettings.prototype.guideChannelStyle = function (val) {
      return null != val
        ? this.set("guideChannelStyle", val.toString(), !0)
        : this.get("guideChannelStyle", !0) || "image";
    }),
    (UserSettings.prototype.showChannelNumberInGuide = function (val) {
      return null != val
        ? this.set("showChannelNumberInGuide", val.toString(), !0)
        : "false" !== this.get("showChannelNumberInGuide", !0);
    }),
    (UserSettings.prototype.showFullMediaInfoOnDetailScreen = function (val) {
      return null != val
        ? this.set("showFullMediaInfoOnDetailScreen", val.toString(), !0)
        : "false" !== this.get("showFullMediaInfoOnDetailScreen", !0);
    }),
    (UserSettings.prototype.seriesDisplay = function (val) {
      return null != val
        ? this.set("seriesDisplay", val.toString(), !0)
        : this.get("seriesDisplay", !0) || "episodessingleseason";
    }),
    (UserSettings.prototype.cardSize = function (val) {
      return null != val
        ? this.set("cardSize", val.toString(), !1)
        : this.get("cardSize", !1) || "normal";
    }),
    (UserSettings.prototype.videoOrientation = function (val) {
      return null != val
        ? this.set("videoOrientation", val.toString(), !1)
        : this.get("videoOrientation", !1) || "auto";
    }),
    (UserSettings.prototype.getLiveTvChannelSortSettingsKey = function () {
      return "livetv-channelorder";
    }),
    (UserSettings.prototype.getLiveTvChannelSortOrders = function (globalize) {
      for (
        var selectedOrder,
          sortBy = [],
          currentOrder =
            (sortBy.push({
              name: globalize.translate("HeaderDefaultChannelOrder"),
              value: "DefaultChannelOrder",
              defaultSortOrder: "Ascending",
              menuSortKey: "0",
            }),
            sortBy.push({
              name: globalize.translate("ChannelNumber"),
              value: "ChannelNumber,SortName",
              defaultSortOrder: "Ascending",
            }),
            sortBy.push({
              name: globalize.translate("DatePlayed"),
              value: "DatePlayed,ChannelNumber,SortName",
              defaultSortOrder: "Descending",
            }),
            sortBy.push({
              name: globalize.translate("Title"),
              value: "SortName",
              defaultSortOrder: "Ascending",
            }),
            sortBy.push({
              name: globalize.translate("HeaderFavoritesThenByDefault"),
              value: "IsFavorite,DefaultChannelOrder",
              defaultSortOrder: "Ascending",
            }),
            sortBy.push({
              name: globalize.translate("HeaderFavoritesThenByChannelNumber"),
              value: "IsFavorite,ChannelNumber,SortName",
              defaultSortOrder: "Ascending",
            }),
            sortBy.push({
              name: globalize.translate("HeaderFavoritesThenByTitle"),
              value: "IsFavorite,SortName",
              defaultSortOrder: "Ascending",
            }),
            this.getFilter(this.getLiveTvChannelSortSettingsKey(), !0)),
          i = 0,
          length = sortBy.length;
        i < length;
        i++
      ) {
        var order = sortBy[i];
        if (order.value === currentOrder) {
          selectedOrder = order;
          break;
        }
      }
      return (
        ((selectedOrder = selectedOrder || sortBy[0]).selected = !0), sortBy
      );
    }),
    (UserSettings.prototype.addLiveTvChannelSortingToQuery = function (
      query,
      globalize,
    ) {
      for (
        var selectedOrder,
          orders = this.getLiveTvChannelSortOrders(globalize),
          i = 0,
          length = orders.length;
        i < length;
        i++
      ) {
        var order = orders[i];
        if (order.selected) {
          selectedOrder = order;
          break;
        }
      }
      (query.SortBy = selectedOrder.value),
        (query.SortOrder = selectedOrder.defaultSortOrder);
    }),
    (_exports.default = UserSettings);
});
