import {
  COOKIE_CONSENT_STORAGE_KEY,
  normalizeConsentRaw,
  type ConsentParseResult,
  type StoredAnalyticsConsent
} from "@ben-to/privacy/cookie-consent";

export const readAnalyticsConsent = (): ConsentParseResult => {
  try {
    return normalizeConsentRaw(localStorage.getItem(COOKIE_CONSENT_STORAGE_KEY));
  } catch {
    return "unknown";
  }
};

export const writeAnalyticsConsent = (value: StoredAnalyticsConsent): void => {
  try {
    localStorage.setItem(COOKIE_CONSENT_STORAGE_KEY, value);
  } catch {
    /* stockage indisponible (mode privé strict, etc.) */
  }
};
