/** * useOffer Hook - Single offer workflow with checkout session management * * Behavior copied from useOffersQuery but simplified for a single offer: * 1. Fetches offer data * 2. Auto-initializes checkout session when mainOrderId is provided * 3. Fetches order summary with variant options * 4. Updates line items when variant/quantity changes * 5. Pays with payOffer */ import { Offer } from '../../core/resources/offers'; export type { Offer }; /** * Line item displayed in the UI */ export interface OfferLineItem { id: string; variantId: string; variantName: string; productId: string; productName: string; productDescription: string | null; imageUrl: string | null; quantity: number; unitAmount: number; currency: string; } /** * Available variant option for a product */ export interface AvailableVariant { variantId: string; variantName: string; sku: string | null; imageUrl: string | null; unitAmount: number; currency: string; isDefault: boolean; } /** * User selection for a line item */ export interface LineItemSelection { variantId: string; quantity: number; } /** * Summary derived from offer with user selections */ export interface OfferPreviewSummary { items: OfferLineItem[]; currency: string; totalAmount: number; totalAdjustedAmount: number; } export interface UseOfferQueryOptions { /** * The offer ID to fetch (required) */ offerId: string; /** * Whether to fetch the offer automatically * @default true */ enabled?: boolean; /** * Main order ID - when provided, auto-inits checkout session */ mainOrderId?: string; } export interface UseOfferQueryResult { /** The fetched offer */ offer: Offer | null; /** Loading state */ isLoading: boolean; /** Whether order summary is being updated */ isUpdatingSummary: boolean; /** Fetch error */ error: Error | null; /** Preview summary with current selections */ summary: OfferPreviewSummary | null; /** Line items with current selections */ lineItems: OfferLineItem[]; /** Get available variants for a product */ getAvailableVariants: (productId: string) => AvailableVariant[]; /** Select a variant for a product */ selectVariant: (productId: string, variantId: string) => void; /** Update variant for a product (same as selectVariant) */ updateVariant: (productId: string, variantId: string) => void; /** Update quantity for a product */ updateQuantity: (productId: string, quantity: number) => void; /** Current selections per product */ selections: Record; /** Pay for the offer */ payOffer: (orderId?: string) => Promise<{ checkoutUrl: string; }>; /** Payment in progress */ isPaying: boolean; /** Payment error */ paymentError: Error | null; /** Checkout session ID (set after init) */ checkoutSessionId: string | null; /** Whether checkout session is initializing */ isInitializing: boolean; /** Whether variant is loading for a product */ isLoadingVariant: (productId: string) => boolean; } export declare function useOfferQuery(options: UseOfferQueryOptions): UseOfferQueryResult;