{"version":3,"sources":["../src/components/Toast/ToastContainer/usePausableTimer.ts"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { useEventCallback } from '@fluentui/react-utilities';\n\nexport type UsePausableTimerOptions = {\n  /**\n   * Total timer duration in milliseconds. A negative value disables the timer.\n   */\n  timeout: number;\n  /**\n   * Whether the timer is currently counting down. Toggling preserves elapsed time.\n   */\n  running: boolean;\n  /**\n   * Called when the timer naturally elapses while running.\n   */\n  onTimeout: () => void;\n  /**\n   * Changing this value resets the timer, discarding elapsed time.\n   */\n  resetKey?: unknown;\n};\n\n/**\n * A pausable countdown timer backed by the Web Animations API.\n *\n * The native `Animation.pause()` / `Animation.play()` semantics preserve elapsed\n * time across pause/resume — equivalent to a CSS animation's `animation-play-state`,\n * but without any DOM node or stylesheet. This matches the original `react-toast`\n * `<Timer>` behavior, where hovering doesn't restart the countdown.\n */\nexport const usePausableTimer = ({ timeout, running, onTimeout, resetKey }: UsePausableTimerOptions): void => {\n  const { targetDocument } = useFluent_unstable();\n  const animationRef = React.useRef<Animation | null>(null);\n  const handleTimeout = useEventCallback(onTimeout);\n\n  React.useEffect(() => {\n    if (timeout < 0 || !targetDocument?.defaultView?.Animation) {\n      return;\n    }\n\n    const animation = new targetDocument.defaultView.Animation(\n      new targetDocument.defaultView.KeyframeEffect(null, null, timeout),\n      targetDocument.timeline,\n    );\n    animation.onfinish = handleTimeout;\n    animationRef.current = animation;\n\n    return () => {\n      animation.onfinish = null;\n      animation.cancel();\n      animationRef.current = null;\n    };\n  }, [timeout, targetDocument, handleTimeout, resetKey]);\n\n  React.useEffect(() => {\n    const animation = animationRef.current;\n    if (!animation) {\n      return;\n    }\n    if (running) {\n      animation.play();\n    } else {\n      animation.pause();\n    }\n  }, [running, resetKey]);\n};\n"],"names":["usePausableTimer","timeout","running","onTimeout","resetKey","targetDocument","useFluent_unstable","animationRef","React","useRef","handleTimeout","useEventCallback","useEffect","defaultView","Animation","animation","KeyframeEffect","timeline","onfinish","current","cancel","play","pause"],"mappings":"AAAA;;;;;+BAiCaA;;;eAAAA;;;;iEA/BU;qCACY;gCACF;AA6B1B,MAAMA,mBAAmB,CAAC,EAAEC,OAAO,EAAEC,OAAO,EAAEC,SAAS,EAAEC,QAAQ,EAA2B;IACjG,MAAM,EAAEC,cAAc,EAAE,GAAGC,IAAAA,uCAAkB;IAC7C,MAAMC,eAAeC,OAAMC,MAAM,CAAmB;IACpD,MAAMC,gBAAgBC,IAAAA,gCAAgB,EAACR;IAEvCK,OAAMI,SAAS,CAAC;QACd,IAAIX,UAAU,KAAK,CAACI,gBAAgBQ,aAAaC,WAAW;YAC1D;QACF;QAEA,MAAMC,YAAY,IAAIV,eAAeQ,WAAW,CAACC,SAAS,CACxD,IAAIT,eAAeQ,WAAW,CAACG,cAAc,CAAC,MAAM,MAAMf,UAC1DI,eAAeY,QAAQ;QAEzBF,UAAUG,QAAQ,GAAGR;QACrBH,aAAaY,OAAO,GAAGJ;QAEvB,OAAO;YACLA,UAAUG,QAAQ,GAAG;YACrBH,UAAUK,MAAM;YAChBb,aAAaY,OAAO,GAAG;QACzB;IACF,GAAG;QAAClB;QAASI;QAAgBK;QAAeN;KAAS;IAErDI,OAAMI,SAAS,CAAC;QACd,MAAMG,YAAYR,aAAaY,OAAO;QACtC,IAAI,CAACJ,WAAW;YACd;QACF;QACA,IAAIb,SAAS;YACXa,UAAUM,IAAI;QAChB,OAAO;YACLN,UAAUO,KAAK;QACjB;IACF,GAAG;QAACpB;QAASE;KAAS;AACxB"}