import * as react from 'react';
import { ReactNode } from 'react';
import * as _platform_modules_commerce_cart from '@platform-modules/commerce-cart';
import { Cart, CartAction, PriceSnapshot } from '@platform-modules/commerce-cart';
export { Cart, CartAction, CartLine, PriceSnapshot, isCartValidationError, isMixedCurrencyError } from '@platform-modules/commerce-cart';

/**
 * Injected, DB-free async data seam for browser-side cart ops (§1).
 * The host wires each method to an API route it owns; the route runs
 * applyToCart(store, cartId, action)/store.load/store.merge server-side and
 * enforces the price/currency/stock/authz floors. HTTP is the one production
 * transport; an in-process core wrapper + a mock are test doubles. The browser
 * island never holds a CartStore/db handle.
 */
interface CartClient {
    /** Load the session's cart — the host route resolves identity from session/cookie. */
    getCart(): Promise<Cart>;
    /** Persist an action — host route returns the server-authoritative Cart (the reconcile target). */
    apply(action: CartAction): Promise<Cart>;
    /** Guest→user cart merge on sign-in → authoritative Cart. */
    merge(guestCartId: string): Promise<Cart>;
}

interface CartMutations {
    addLine(input: {
        variantId: string;
        qty: number;
        price: PriceSnapshot;
        vendorId?: string | null;
    }): Promise<Cart>;
    setQty(lineId: string, qty: number): Promise<Cart>;
    removeLine(lineId: string): Promise<Cart>;
    clear(): Promise<Cart>;
    merge(guestCartId: string): Promise<Cart>;
    pending: boolean;
    error: Error | null;
}

declare function CartProvider({ client, initialCart, children, }: {
    client: CartClient;
    initialCart?: Cart;
    children: ReactNode;
}): react.JSX.Element;

declare function useCart(): {
    cart: _platform_modules_commerce_cart.Cart | null;
    loading: boolean;
    error: Error | null;
    reload: () => void;
    itemCount: number;
    subtotal: bigint | null;
    byVendor: {
        vendorId: string | null;
        lines: _platform_modules_commerce_cart.CartLine[];
        subtotal: bigint;
    }[] | null;
};

declare function useCartActions(): CartMutations;

/** Thrown when a cart hook is used outside <CartProvider> (§2). */
declare class CartProviderError extends Error {
    readonly name = "CartProviderError";
    constructor(hook: string);
}
declare function isCartProviderError(e: unknown): e is CartProviderError;
/** Thrown by reviveCart on malformed serialized wire input (§5). */
declare class CartWireError extends Error {
    readonly name = "CartWireError";
    constructor(message: string);
}
declare function isCartWireError(e: unknown): e is CartWireError;

/** Wire JSON → typed Cart. Reconstructs every bigint field (subtotal + lines[].price.amount). NO date leg. §5 */
declare function reviveCart(raw: unknown): Cart;

export { type CartClient, CartProvider, CartProviderError, CartWireError, isCartProviderError, isCartWireError, reviveCart, useCart, useCartActions };
