/**
 * Cart UI types. Align with Convex carts.get enriched items.
 * See docs/cart-ui-implementation-plan.md and convex/carts.ts.
 *
 * Convention: shared cart content is presentational (receives items and callbacks).
 * Data fetching and mutations (carts.get, carts.updateItem, etc.) live at provider
 * or page/container level so drawer, sheet, and page all use the same source of truth.
 */

/** Enriched cart line item (from Convex or mapped for UI). */
export type CartEnrichedItem = {
  variantId: string;
  productId: string;
  quantity: number;
  priceSnapshot: number;
  productName: string;
  variantName: string;
  imageUrl?: string;
  stockQuantity?: number;
  /** For PDP link: /shop/{parentCategorySlug}/{childCategorySlug}/{slug} */
  productSlug?: string;
  parentCategorySlug?: string;
  childCategorySlug?: string;
};

/** Cart with items and optional totals (e.g. from carts.get). */
export type CartWithItems = {
  id: string;
  items: CartEnrichedItem[];
  subtotal?: number;
};

/** Props for shared CartContent (presentational). */
export type CartContentProps = {
  items: CartEnrichedItem[];
  subtotal: number;
  onUpdateQuantity: (variantId: string, quantity: number) => void;
  onRemove: (variantId: string) => void;
  isEmpty: boolean;
  onCheckout?: () => void;
  onViewFullCart?: () => void;
  /** Dismiss the overlay on any navigation (drawer/sheet pass closeCart; page leaves undefined). */
  onClose?: () => void;
  isLoading?: boolean;
  error?: Error | null;
  /** When true, do not render the "Cart" header (e.g. page uses CartPageLayout heading). */
  hideHeading?: boolean;
  /** "page" = full cart page (two-column on lg); "overlay" = drawer/sheet. */
  layout?: "page" | "overlay";
};

/** Props for CartLineItems (card-based item list). */
export type CartLineItemsProps = {
  items: CartEnrichedItem[];
  onUpdateQuantity: (variantId: string, quantity: number) => void;
  onRemove: (variantId: string) => void;
};

/** Props for CartOrderSummary (dl/dt/dd). */
export type CartOrderSummaryProps = {
  subtotal: number;
};
