// Tiny sessionStorage handoff so a vendor's page can land on
// #purchase-orders already filtered to that vendor — a straight copy of
// bills/vendorFilterHandoff.ts (see that file for why a handoff rather than a
// hash query param): best-effort, never fatal if storage is unavailable,
// consumed exactly once so a later plain navigation to #purchase-orders
// doesn't keep reapplying a stale filter.

const KEY = "purchaseOrders:pendingVendorFilter";

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

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