const STORAGE_KEY = 'admin-onboarding-package-v1';

export function getSelectedPackageId(): number | null {
  if (typeof window === 'undefined') {
    return null;
  }

  try {
    const raw = window.localStorage.getItem(STORAGE_KEY);
    if (!raw) {
      return null;
    }
    const value = Number(raw);
    return Number.isFinite(value) ? value : null;
  } catch {
    return null;
  }
}

export function setSelectedPackageId(id: number | null): void {
  if (typeof window === 'undefined') {
    return;
  }

  try {
    if (!id) {
      window.localStorage.removeItem(STORAGE_KEY);
      return;
    }
    window.localStorage.setItem(STORAGE_KEY, String(id));
  } catch {
    // Ignore storage errors.
  }
}
