import { slugify } from "../../lib/slugify.js";
const SIDEBAR_PREFERENCES_VERSION = 2;
function normalizeSidebarSettings(settings) {
  if (!settings || typeof settings !== "object") {
    return { version: SIDEBAR_PREFERENCES_VERSION, groupOrder: [], groupLabels: {}, itemLabels: {}, hiddenItems: [], itemOrder: {} };
  }
  const version = typeof settings.version === "number" ? settings.version : SIDEBAR_PREFERENCES_VERSION;
  const groupOrder = Array.isArray(settings.groupOrder) ? settings.groupOrder.filter((v) => typeof v === "string") : [];
  const groupLabels = normalizeRecord(settings.groupLabels);
  const itemLabels = normalizeRecord(settings.itemLabels);
  const hiddenItems = normalizeStringArray(settings.hiddenItems);
  const itemOrder = normalizeStringArrayRecord(settings.itemOrder);
  return {
    version,
    groupOrder,
    groupLabels,
    itemLabels,
    hiddenItems,
    itemOrder
  };
}
function normalizeRecord(record) {
  if (!record || typeof record !== "object") return {};
  const out = {};
  for (const [key, value] of Object.entries(record)) {
    if (typeof value !== "string") continue;
    out[key] = value;
  }
  return out;
}
function normalizeStringArrayRecord(record) {
  if (!record || typeof record !== "object") return {};
  const out = {};
  for (const [key, value] of Object.entries(record)) {
    const arr = normalizeStringArray(value);
    if (arr.length > 0) out[key] = arr;
  }
  return out;
}
function normalizeStringArray(values) {
  if (!Array.isArray(values)) return [];
  const seen = /* @__PURE__ */ new Set();
  const out = [];
  for (const value of values) {
    if (typeof value !== "string") continue;
    const trimmed = value.trim();
    if (!trimmed || seen.has(trimmed)) continue;
    seen.add(trimmed);
    out.push(trimmed);
  }
  return out;
}
function slugifySidebarId(source) {
  return slugify(source, { allowedChars: "" }) || "group";
}
export {
  SIDEBAR_PREFERENCES_VERSION,
  normalizeSidebarSettings,
  slugifySidebarId
};
//# sourceMappingURL=sidebarPreferences.js.map
