'use client'

/**
 * Per-user warning acknowledgements (Task 10, confirmed decision):
 * acknowledging a warning hides it FOR THAT USER ONLY — other participants
 * still see it until they acknowledge it themselves.
 *
 * Stored in localStorage for the UI-first phase.
 * TODO(backend): move to a warning_acknowledgements table (warning_id,
 * user_id) so acknowledgements follow the user across devices.
 */

const key = (userId: string) => `hha-ack-${userId}`

export function getAckedWarnings(userId: string): Set<string> {
  try {
    const raw = localStorage.getItem(key(userId))
    return new Set(raw ? (JSON.parse(raw) as string[]) : [])
  } catch {
    return new Set()
  }
}

export function ackWarning(userId: string, warningId: string): void {
  try {
    const acked = getAckedWarnings(userId)
    acked.add(warningId)
    localStorage.setItem(key(userId), JSON.stringify([...acked]))
  } catch {
    // storage unavailable — the warning simply reappears next visit
  }
}
