// Tiny sessionStorage handoff so a customer's balance on #customers can land
// on #invoices pre-filtered to that customer, without teaching the hash
// router (lib/useHashView.ts) a query-param shape for a plain static
// ViewName route — same technique EntryDetail.tsx uses for its
// "just reversed" banner (markJustReversed/consumeJustReversed): best-effort,
// never fatal if storage is unavailable, and consumed exactly once so a
// later plain navigation to #invoices doesn't keep re-applying a stale filter.

const KEY = "invoices:pendingCustomerFilter";

export function setPendingCustomerFilter(customerId: string): void {
  try {
    window.sessionStorage.setItem(KEY, customerId);
  } catch {
    // best-effort only
  }
}

export function consumePendingCustomerFilter(): string | null {
  try {
    const value = window.sessionStorage.getItem(KEY);
    if (value) {
      window.sessionStorage.removeItem(KEY);
      return value;
    }
  } catch {
    // best-effort only
  }
  return null;
}
