{"version":3,"file":"useTimelineHistory.mjs","names":[],"sources":["../../../src/hooks/selection/useTimelineHistory.ts"],"sourcesContent":["import { useTimelineExternalStore } from '#react/hooks/core/useTimelineExternalStore';\nimport { timelineCommandFail, timelineCommandOk } from '@techsquidtv/canvas-timeline-core';\nimport type { TimelineCommandResult } from '@techsquidtv/canvas-timeline-core';\nimport { useTimelineEngine } from '#react/hooks/core/useTimelineEngine';\nimport { useCallback } from 'react';\nconst historyEvents = ['history:change'] as const;\n\n/** Result returned by `useTimelineHistory`. */\nexport interface UseTimelineHistoryResult {\n  /** Whether an undo snapshot is available. */\n  canUndo: boolean;\n  /** Whether a redo snapshot is available. */\n  canRedo: boolean;\n  /** Restores the previous timeline history snapshot. */\n  undo: () => TimelineCommandResult;\n  /** Reapplies the next timeline history snapshot. */\n  redo: () => TimelineCommandResult;\n}\n\n/**\n * Provides canonical undo/redo history access for timeline editor chrome.\n *\n * @returns Undo/redo availability and commands.\n */\nexport function useTimelineHistory(): UseTimelineHistoryResult {\n  const engine = useTimelineEngine();\n  const availability = useTimelineExternalStore(historyEvents, (engine) => ({\n    canUndo: engine.canUndo,\n    canRedo: engine.canRedo,\n  }));\n\n  const undo = useCallback(() => {\n    if (!engine.canUndo) {\n      return timelineCommandFail('unsupported');\n    }\n    engine.undo();\n    return timelineCommandOk();\n  }, [engine]);\n\n  const redo = useCallback(() => {\n    if (!engine.canRedo) {\n      return timelineCommandFail('unsupported');\n    }\n    engine.redo();\n    return timelineCommandOk();\n  }, [engine]);\n\n  return {\n    ...availability,\n    undo,\n    redo,\n  };\n}\n"],"mappings":";;;;;AAKA,MAAM,gBAAgB,CAAC,gBAAgB;;;;;;AAmBvC,SAAgB,qBAA+C;CAC7D,MAAM,SAAS,kBAAkB;CACjC,MAAM,eAAe,yBAAyB,gBAAgB,YAAY;EACxE,SAAS,OAAO;EAChB,SAAS,OAAO;CAClB,EAAE;CAEF,MAAM,OAAO,kBAAkB;EAC7B,IAAI,CAAC,OAAO,SACV,OAAO,oBAAoB,aAAa;EAE1C,OAAO,KAAK;EACZ,OAAO,kBAAkB;CAC3B,GAAG,CAAC,MAAM,CAAC;CAEX,MAAM,OAAO,kBAAkB;EAC7B,IAAI,CAAC,OAAO,SACV,OAAO,oBAAoB,aAAa;EAE1C,OAAO,KAAK;EACZ,OAAO,kBAAkB;CAC3B,GAAG,CAAC,MAAM,CAAC;CAEX,OAAO;EACL,GAAG;EACH;EACA;CACF;AACF"}