{"version":3,"file":"useTimelineEditImpacts.mjs","names":[],"sources":["../../../src/hooks/editing/useTimelineEditImpacts.ts"],"sourcesContent":["import { useCallback, useMemo } from 'react';\nimport type {\n  TimelineEditImpact,\n  TimelineEditImpacts,\n  TimelineEditOperation,\n  TimelineEngine,\n} from '@techsquidtv/canvas-timeline-core';\nimport { useTimelineExternalStore } from '#react/hooks/core/useTimelineExternalStore';\n\nconst emptyTimelineEditImpacts: readonly TimelineEditImpact[] = Object.freeze([]);\nconst editImpactEvents = ['edit:impacts', 'state:settled'] as const;\nconst getTimelineEditImpacts = (engine: TimelineEngine) => engine.getEditImpacts();\n\n/** Result returned by `useTimelineEditImpacts`. */\nexport interface UseTimelineEditImpactsResult {\n  /** Active edit impacts for the current preview or live edit interaction, or null when none are active. */\n  activeEdit: TimelineEditImpacts | null;\n  /** Clip-level consequences for the current preview or live edit interaction. */\n  impacts: readonly TimelineEditImpact[];\n  /** Current preview or live edit operation, or null when no edit impacts are active. */\n  operation: TimelineEditOperation | null;\n  /** Clip currently driving the active edit, or null when no clip-driven impacts are active. */\n  sourceClipId: string | null;\n  /** Track containing the source clip, or null when no clip-driven impacts are active. */\n  sourceTrackId: string | null;\n  /** Whether the active preview or live edit currently affects any clips. */\n  hasImpacts: boolean;\n  /** Returns the active edit impact for one affected clip. */\n  getImpactForClip: (clipId: string) => TimelineEditImpact | null;\n}\n\n/**\n * Subscribes to affected-clip consequences produced by command previews and\n * active timeline interactions.\n *\n * This is a focused live hook: it can update when command previews change and\n * during drag or trim gestures. Use it for custom headless UI affordances that\n * show which clips are trimmed, split, or removed by the active edit.\n *\n * @returns Current edit impacts and helpers for custom editor UI.\n */\nexport function useTimelineEditImpacts(): UseTimelineEditImpactsResult {\n  const activeEdit = useTimelineExternalStore(editImpactEvents, getTimelineEditImpacts);\n\n  const impacts = useMemo(() => activeEdit?.impacts ?? emptyTimelineEditImpacts, [activeEdit]);\n  const impactByClipId = useMemo(() => {\n    const lookup = new Map<string, TimelineEditImpact>();\n    for (const impact of impacts) {\n      lookup.set(impact.clipId, impact);\n    }\n    return lookup;\n  }, [impacts]);\n  const getImpactForClip = useCallback(\n    (clipId: string) => impactByClipId.get(clipId) ?? null,\n    [impactByClipId]\n  );\n\n  return {\n    activeEdit,\n    impacts,\n    operation: activeEdit?.operation ?? null,\n    sourceClipId: activeEdit?.sourceClipId ?? null,\n    sourceTrackId: activeEdit?.sourceTrackId ?? null,\n    hasImpacts: impacts.length > 0,\n    getImpactForClip,\n  };\n}\n"],"mappings":";;;AASA,MAAM,2BAA0D,OAAO,OAAO,CAAC,CAAC;AAChF,MAAM,mBAAmB,CAAC,gBAAgB,eAAe;AACzD,MAAM,0BAA0B,WAA2B,OAAO,eAAe;;;;;;;;;;;AA8BjF,SAAgB,yBAAuD;CACrE,MAAM,aAAa,yBAAyB,kBAAkB,sBAAsB;CAEpF,MAAM,UAAU,cAAc,YAAY,WAAW,0BAA0B,CAAC,UAAU,CAAC;CAC3F,MAAM,iBAAiB,cAAc;EACnC,MAAM,yBAAS,IAAI,IAAgC;EACnD,KAAK,MAAM,UAAU,SACnB,OAAO,IAAI,OAAO,QAAQ,MAAM;EAElC,OAAO;CACT,GAAG,CAAC,OAAO,CAAC;CACZ,MAAM,mBAAmB,aACtB,WAAmB,eAAe,IAAI,MAAM,KAAK,MAClD,CAAC,cAAc,CACjB;CAEA,OAAO;EACL;EACA;EACA,WAAW,YAAY,aAAa;EACpC,cAAc,YAAY,gBAAgB;EAC1C,eAAe,YAAY,iBAAiB;EAC5C,YAAY,QAAQ,SAAS;EAC7B;CACF;AACF"}