"use client";

/**
 * Returns the current sessionId for cart identity: present for guests, undefined when authenticated.
 * Use this when calling Convex carts.get and cart mutations so a single place defines identity.
 *
 * - Guest: pass the returned sessionId to carts.get, carts.addItem, carts.updateItem, etc.
 * - Authenticated: do not pass sessionId; Convex uses the signed-in user.
 *
 * Session implementation: docs/session-implementation-plan.md. Guest cart is stored in cookie
 * _store_session (30 days). On login, SessionCartMerge runs carts.merge({ sessionId }) and
 * clears the guest cookie.
 */
import { useCartSession } from "@/lib/session";

export function useCartSessionId(): string | undefined {
  const { sessionId, isGuest } = useCartSession();
  return isGuest ? sessionId : undefined;
}
