"use client";

import { Logger } from "@/utils";

const log = new Logger("LibBrowserPersistentStorage");
let storagePersistenceRequested = false;

export async function requestBrowserPersistentStorageOnce(): Promise<void> {
  if (storagePersistenceRequested) return;
  storagePersistenceRequested = true;
  if (typeof navigator === "undefined") return;
  if (!navigator.storage?.persist) return;

  try {
    const persisted = await navigator.storage.persist();
    log.debug("[persistent-storage] requested", { persisted });
  } catch (error) {
    log.debug("[persistent-storage] request skipped", { error });
  }
}
