// Tiny sessionStorage handoff so a vendor's balance on #vendors can land on
// #bills pre-filtered to that vendor, without teaching the hash router
// (lib/useHashView.ts) a query-param shape for a plain static ViewName route
// — mechanical mirror of invoices/customerFilterHandoff.ts (see that file's
// header for why this isn't a hash query param instead): best-effort, never
// fatal if storage is unavailable, and consumed exactly once so a later
// plain navigation to #bills doesn't keep re-applying a stale filter.

const KEY = "bills:pendingVendorFilter";

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

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