var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellReservation/data/resourceWallLocalStorage.ts
var resourceWallLocalStorage_exports = {};
__export(resourceWallLocalStorage_exports, {
  dedupeResourceWallIdsPreserveOrder: () => dedupeResourceWallIdsPreserveOrder,
  isVenueWallAppearanceThemeNonEmpty: () => isVenueWallAppearanceThemeNonEmpty,
  parseResourceWallLocalStorage: () => parseResourceWallLocalStorage,
  readResourceWallPersistedSliceFromDisk: () => readResourceWallPersistedSliceFromDisk
});
module.exports = __toCommonJS(resourceWallLocalStorage_exports);
var import_materials = require("@pisell/materials");
var import_reservationConstants = require("../reservationConstants");
function sanitizeVenueWallResourceLayout(raw) {
  if (raw == null || typeof raw !== "object") return void 0;
  const o = raw;
  const clampInt = (v, min, max, d) => {
    const n = typeof v === "number" ? v : Number(v);
    if (!Number.isFinite(n)) return d;
    return Math.max(min, Math.min(max, Math.round(n)));
  };
  const heroRaw = typeof o.heroMaxWidthRatio === "number" ? o.heroMaxWidthRatio : Number(o.heroMaxWidthRatio);
  const heroMaxWidthRatio = Number.isFinite(heroRaw) ? Math.max(0.4, Math.min(0.8, heroRaw)) : import_materials.DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST.heroMaxWidthRatio;
  const layoutKey = typeof o.layoutKey === "string" && o.layoutKey.length > 0 ? o.layoutKey : import_materials.DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST.layoutKey;
  return {
    layoutKey,
    customCols: clampInt(
      o.customCols,
      1,
      6,
      import_materials.DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST.customCols
    ),
    customRows: clampInt(
      o.customRows,
      1,
      6,
      import_materials.DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST.customRows
    ),
    pageDurationSec: clampInt(
      o.pageDurationSec,
      3,
      60,
      import_materials.DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST.pageDurationSec
    ),
    boardingSoonBeforeMin: clampInt(
      o.boardingSoonBeforeMin,
      1,
      60,
      import_materials.DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST.boardingSoonBeforeMin
    ),
    heroMaxWidthRatio
  };
}
function isVenueWallAppearanceThemeNonEmpty(t) {
  const slotHasData = (s) => {
    if (!s) return false;
    if (s.occupiedCardColor || s.availableCardColor) return true;
    const o = s.statusToneOverrides;
    return o != null && Object.keys(o).length > 0;
  };
  return slotHasData(t.light) || slotHasData(t.dark);
}
function dedupeResourceWallIdsPreserveOrder(ids) {
  const seen = /* @__PURE__ */ new Set();
  const out = [];
  for (const raw of ids) {
    const t = String(raw).trim();
    if (!t || seen.has(t)) continue;
    seen.add(t);
    out.push(t);
  }
  return out;
}
function parseResourceWallLocalStorage(raw, whitelist) {
  const empty = { filterValuePatches: {} };
  if (!raw) return empty;
  try {
    const parsed = JSON.parse(raw);
    if (Array.isArray(parsed)) {
      return {
        resourceIds: parsed.map(String),
        resourceWallResourceIdsInFile: true,
        filterValuePatches: {}
      };
    }
    if (!parsed || typeof parsed !== "object") return empty;
    const o = parsed;
    const hasRidKey = Object.prototype.hasOwnProperty.call(
      o,
      "resource_wall_resource_ids"
    );
    const ridRaw = o.resource_wall_resource_ids;
    const resourceIds = !hasRidKey ? void 0 : Array.isArray(ridRaw) ? ridRaw.map(String) : [];
    const patches = {};
    const fv = o.filter_values;
    if (fv && typeof fv === "object") {
      for (const k of whitelist) {
        if (k === "resource_wall_resource_ids") continue;
        if (Object.prototype.hasOwnProperty.call(fv, k)) {
          patches[k] = fv[k];
        }
      }
    }
    const legacyTones = o.venueWallStatusToneOverrides;
    const diskTheme = o.venueWallAppearanceTheme;
    let venueWallAppearanceTheme = diskTheme && typeof diskTheme === "object" ? diskTheme : void 0;
    if (!venueWallAppearanceTheme && legacyTones && typeof legacyTones === "object" && Object.keys(legacyTones).length > 0) {
      venueWallAppearanceTheme = {
        light: { statusToneOverrides: legacyTones },
        dark: { statusToneOverrides: legacyTones }
      };
    }
    const rawMode = o.venueWallAppearanceMode;
    const venueWallAppearanceMode = rawMode === "light" || rawMode === "dark" ? rawMode : void 0;
    const venueWallResourceLayout = sanitizeVenueWallResourceLayout(
      o.venueWallResourceLayout
    );
    return {
      resourceIds,
      resourceWallResourceIdsInFile: hasRidKey,
      filterValuePatches: patches,
      venueWallAppearanceTheme,
      venueWallAppearanceMode,
      venueWallResourceLayout
    };
  } catch {
    return empty;
  }
}
function readResourceWallPersistedSliceFromDisk(bodyViewStorageKey) {
  const key = `${import_reservationConstants.PISELL_RESERVATION_RESOURCE_WALL_FILTER_STORAGE_PREFIX}:${bodyViewStorageKey ?? "default"}`;
  let raw = null;
  try {
    if (typeof localStorage !== "undefined") {
      raw = localStorage.getItem(key);
    }
  } catch {
    raw = null;
  }
  const ls = parseResourceWallLocalStorage(
    raw,
    import_reservationConstants.RESERVATION_RESOURCE_WALL_PERSISTED_FILTER_VALUE_KEYS
  );
  return {
    venueWallAppearanceTheme: ls.venueWallAppearanceTheme != null && isVenueWallAppearanceThemeNonEmpty(ls.venueWallAppearanceTheme) ? ls.venueWallAppearanceTheme : {},
    venueWallAppearanceMode: ls.venueWallAppearanceMode === "light" || ls.venueWallAppearanceMode === "dark" ? ls.venueWallAppearanceMode : "light",
    venueWallResourceLayout: ls.venueWallResourceLayout ?? import_materials.DEFAULT_RESOURCE_WALL_LAYOUT_PERSIST
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  dedupeResourceWallIdsPreserveOrder,
  isVenueWallAppearanceThemeNonEmpty,
  parseResourceWallLocalStorage,
  readResourceWallPersistedSliceFromDisk
});
