import type { CreateFromSourceTemplateConfig } from '../template/MasterDocumentTemplate.types'; import type { AvailableSourceItem, IMasterDocumentAdapter, PendingSourceLine } from '../adapter/MasterDocumentAdapter.types'; /** Modo de invocación. `create` = caso A (nace el documento); `append` = caso B (DRAFT existente). */ export type CreateFromSourceMode = 'create' | 'append'; /** Pasos del asistente. `origin` solo aplica en modo create con `allowFreeCapture`. */ export type CreateFromSourceStep = 'origin' | 'sources' | 'lines' | 'confirm'; /** Elección del selector de origen (paso 0). */ export type OriginChoice = 'source' | 'free'; export interface UseCreateFromSourceOptions { open: boolean; mode: CreateFromSourceMode; config: CreateFromSourceTemplateConfig; adapter: IMasterDocumentAdapter; /** Requerido en modo `append`. */ documentId?: string; /** Centro de operación del contexto (header en caso A, del documento en caso B). */ operationCenterId?: string; /** * Tercero fijado del header (modo `append`): filtra los orígenes y llega * read-only. En modo `create` es undefined (el usuario elige libremente). */ lockedThirdPartyId?: string; /** Permisos del usuario. `null` ⇒ sin gating (mostrar todo). */ userPermissions?: string[] | null; onCreated?: (documentId: string) => void; onAppended?: (addedLineIds: string[]) => void; onFreeCapture?: (route: string) => void; } export interface UseCreateFromSourceResult { step: CreateFromSourceStep; originChoice: OriginChoice | null; candidates: AvailableSourceItem[]; candidatesLoading: boolean; candidatesError?: string; selectedSourceIds: string[]; /** sourceId → motivo de incompatibilidad (deshabilitado). Vacío ⇒ compatible. */ incompatibleReasons: Record; pendingLines: PendingSourceLine[]; linesLoading: boolean; linesError?: string; selectedLineIds: string[]; quantities: Record; lineErrors: Record; defaults: Record; /** Valores de los campos de header (`createHeaderFields`) capturados en modo create. */ headerValues: Record; /** Opciones de catálogo cargadas por `defaultsStep.fields[].optionsEntity`. */ selectOptions: Record>; submitting: boolean; submitError?: string; canMultiSelect: boolean; canFreeCapture: boolean; canSeeFinancial: boolean; /** True cuando la selección actual permite avanzar del paso vigente. */ canAdvance: boolean; /** True cuando existe el paso de confirmación. */ hasConfirmStep: boolean; /** True cuando existe el paso 0 (selector de origen). */ hasOriginStep: boolean; /** True cuando hay un paso anterior al que volver desde el paso vigente. */ canGoBack: boolean; setOriginChoice: (choice: OriginChoice) => void; toggleSource: (sourceId: string) => void; toggleLine: (lineId: string, selected: boolean) => void; setQuantity: (lineId: string, quantity: number) => void; setDefault: (key: string, value: unknown) => void; setHeaderValue: (key: string, value: unknown) => void; next: () => void; back: () => void; submit: () => void; } /** * useCreateFromSource — orquesta el asistente "crear/continuar documento desde * origen(es)". Estado plano (sin React Query) para no exigir un * `QueryClientProvider` alrededor del flujo core de MasterDocument, igual que * `useCrossing`. Los datos se obtienen vía los fetchers inyectados en el adapter. */ export declare function useCreateFromSource(opts: UseCreateFromSourceOptions): UseCreateFromSourceResult; //# sourceMappingURL=useCreateFromSource.d.ts.map