export const CART_COOKIE_NAME = "cart_id";

export function getCartIdClient(): string | null {
  const match = document.cookie.match(new RegExp(`(?:^|; )${CART_COOKIE_NAME}=([^;]*)`));
  return match ? decodeURIComponent(match[1]) : null;
}

export function setCartIdClient(id: string) {
  document.cookie = `${CART_COOKIE_NAME}=${encodeURIComponent(id)}; path=/; max-age=${60 * 60 * 24 * 30}; SameSite=Lax`;
}

export function clearCartIdClient() {
  document.cookie = `${CART_COOKIE_NAME}=; path=/; max-age=0`;
}
