const CONFLICT_SCOPES = ["mine", "all"];
const MAX_EVENT_CATEGORIES = 8;
const MAX_ACTIVITY_TYPES = 6;
const DEFAULT_CALENDAR_PREFERENCES = {
  showWeekends: false,
  conflictWarnings: true,
  conflictScope: "mine",
  showCrmActivities: true,
  aiSummaries: true,
  eventCategories: [],
  activityTypes: []
};
const CALENDAR_PREFERENCES_STORAGE_PREFIX = "om.customers.calendar.preferences.v1";
function calendarPreferencesStorageKey(scopeKey) {
  return `${CALENDAR_PREFERENCES_STORAGE_PREFIX}:${scopeKey}`;
}
function normalizeCalendarTagList(value, max) {
  if (!Array.isArray(value)) return [];
  const seen = /* @__PURE__ */ new Set();
  const result = [];
  for (const entry of value) {
    if (typeof entry !== "string") continue;
    const trimmed = entry.trim();
    if (!trimmed || seen.has(trimmed)) continue;
    seen.add(trimmed);
    result.push(trimmed);
    if (result.length >= max) break;
  }
  return result;
}
function readConflictScope(value, fallback) {
  return value === "mine" || value === "all" ? value : fallback;
}
function mergeCalendarPreferences(stored) {
  if (!stored || typeof stored !== "object") return { ...DEFAULT_CALENDAR_PREFERENCES };
  const record = stored;
  const readBoolean = (key, fallback) => typeof record[key] === "boolean" ? record[key] : fallback;
  return {
    showWeekends: readBoolean("showWeekends", DEFAULT_CALENDAR_PREFERENCES.showWeekends),
    conflictWarnings: readBoolean("conflictWarnings", DEFAULT_CALENDAR_PREFERENCES.conflictWarnings),
    conflictScope: readConflictScope(record.conflictScope, DEFAULT_CALENDAR_PREFERENCES.conflictScope),
    showCrmActivities: readBoolean("showCrmActivities", DEFAULT_CALENDAR_PREFERENCES.showCrmActivities),
    aiSummaries: readBoolean("aiSummaries", DEFAULT_CALENDAR_PREFERENCES.aiSummaries),
    eventCategories: normalizeCalendarTagList(record.eventCategories, MAX_EVENT_CATEGORIES),
    activityTypes: normalizeCalendarTagList(record.activityTypes, MAX_ACTIVITY_TYPES)
  };
}
function parseStoredCalendarPreferences(raw) {
  if (!raw) return { ...DEFAULT_CALENDAR_PREFERENCES };
  try {
    return mergeCalendarPreferences(JSON.parse(raw));
  } catch {
    return { ...DEFAULT_CALENDAR_PREFERENCES };
  }
}
function calendarPreferencesEqual(first, second) {
  return first.showWeekends === second.showWeekends && first.conflictWarnings === second.conflictWarnings && first.conflictScope === second.conflictScope && first.showCrmActivities === second.showCrmActivities && first.aiSummaries === second.aiSummaries && first.eventCategories.length === second.eventCategories.length && first.eventCategories.every((value, index) => value === second.eventCategories[index]) && first.activityTypes.length === second.activityTypes.length && first.activityTypes.every((value, index) => value === second.activityTypes[index]);
}
export {
  CALENDAR_PREFERENCES_STORAGE_PREFIX,
  CONFLICT_SCOPES,
  DEFAULT_CALENDAR_PREFERENCES,
  MAX_ACTIVITY_TYPES,
  MAX_EVENT_CATEGORIES,
  calendarPreferencesEqual,
  calendarPreferencesStorageKey,
  mergeCalendarPreferences,
  normalizeCalendarTagList,
  parseStoredCalendarPreferences
};
//# sourceMappingURL=preferences.js.map
