"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var useElapsedTime_exports = {};
__export(useElapsedTime_exports, {
  useElapsedTime: () => useElapsedTime
});
module.exports = __toCommonJS(useElapsedTime_exports);
var import_react = require("react");
function formatElapsedTime(ms) {
  const seconds = Math.floor(ms / 1e3);
  const tenths = Math.floor(ms % 1e3 / 100);
  if (seconds < 60) {
    return `${seconds}.${tenths}s`;
  }
  const minutes = Math.floor(seconds / 60);
  const remainingSeconds = seconds % 60;
  if (minutes < 60) {
    return `${minutes}m ${remainingSeconds}s`;
  }
  const hours = Math.floor(minutes / 60);
  const remainingMinutes = minutes % 60;
  return `${hours}h ${remainingMinutes}m ${remainingSeconds}s`;
}
function useElapsedTime({
  isActive,
  intervalMs = 100
}) {
  const [elapsedMs, setElapsedMs] = (0, import_react.useState)(0);
  const startTimeRef = (0, import_react.useRef)(null);
  const intervalRef = (0, import_react.useRef)(null);
  (0, import_react.useEffect)(() => {
    if (isActive) {
      startTimeRef.current = Date.now();
      setElapsedMs(0);
      intervalRef.current = setInterval(() => {
        if (startTimeRef.current !== null) {
          setElapsedMs(Date.now() - startTimeRef.current);
        }
      }, intervalMs);
    } else {
      if (intervalRef.current) {
        clearInterval(intervalRef.current);
        intervalRef.current = null;
      }
      startTimeRef.current = null;
      setElapsedMs(0);
    }
    return () => {
      if (intervalRef.current) {
        clearInterval(intervalRef.current);
        intervalRef.current = null;
      }
    };
  }, [isActive, intervalMs]);
  return {
    elapsedMs,
    formatted: formatElapsedTime(elapsedMs)
  };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useElapsedTime
});
