import { Signal } from "@preact/signals-core"; import { ApiError } from "@swishapp/api-client"; import type { EditItemListsSuccessResponse, EditItemVariantSuccessResponse, SaveItemSuccessResponse, UnsaveItemSuccessResponse } from "../intents/types"; import { SwishApp } from "../swish"; import { ItemContext } from "./item-context-signal"; export type ItemMatch = "variant" | "product" | "auto"; export interface ItemStateCallbacks { onSave?: (data: SaveItemSuccessResponse["data"]) => void; onUnsave?: (data: UnsaveItemSuccessResponse["data"]) => void; onListsUpdate?: (data: EditItemListsSuccessResponse["data"]) => void; onVariantUpdate?: (data: EditItemVariantSuccessResponse["data"]) => void; } export interface ItemStateOptions extends ItemStateCallbacks { /** * How to interpret the API response when deciding `saved`: * - `"variant"`: only count the item as saved if the variant matches. * - `"product"`: count any saved variant of the product as saved. Also * causes `save()` to ignore `variantId` so the saved item is not pinned * to whichever variant the consumer happened to render. * - `"auto"` (default): variant-match when a `variantId` is in the context, * product-match otherwise. */ match?: ItemMatch; } export declare const itemStateSignal: (swish: SwishApp) => (context: Signal, optionsInput?: ItemStateOptions) => import("@preact/signals-core").ReadonlySignal<{ error: ApiError | null; status: "saving" | "saved" | "unsaved"; savedItemId: string | null; savedItemIds: string[]; loading: boolean; submitting: boolean; saved: boolean; saving: boolean; unsaving: boolean; }> & { save: () => Promise; unsave: () => Promise; updateLists: () => Promise; updateVariant: () => Promise; /** @deprecated Use `updateLists` instead. */ update: () => Promise; toggle: () => Promise; setOptions: (next: ItemStateOptions) => void; /** @deprecated Use `setOptions` instead. */ setCallbacks: (next: ItemStateOptions) => void; dispose: () => void; };