import { useLocalStorage } from './useLocalStorage';

const STORAGE_KEY = 'user_postal_code';

/**
 * Persist and normalize postal code across public pages.
 * Normalizes: uppercase, strip spaces.
 */
export function usePostalCode() {
  const [postalCode, setRaw] = useLocalStorage(STORAGE_KEY, '');

  const setPostalCode = (value: string) => {
    setRaw(value.replace(/\s/g, '').toUpperCase());
  };

  return {
    postalCode,
    setPostalCode,
    hasPostalCode: postalCode.length > 0,
  };
}
