"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 usePhraseCycler_exports = {};
__export(usePhraseCycler_exports, {
  usePhraseCycler: () => usePhraseCycler
});
module.exports = __toCommonJS(usePhraseCycler_exports);
var import_react = require("react");
var import_processingPhrases = require("../constants/processingPhrases.js");
var import_tips = require("../constants/tips.js");
function getRandomPhraseOrTip(disableTips = false) {
  if (disableTips) {
    return (0, import_processingPhrases.getRandomPhrase)();
  }
  const showTip = Math.random() < 1 / 3;
  return showTip ? (0, import_tips.getRandomTip)() : (0, import_processingPhrases.getRandomPhrase)();
}
function usePhraseCycler({
  isActive,
  intervalMs = 8e3,
  disableTips = false
}) {
  const [phrase, setPhrase] = (0, import_react.useState)(() => getRandomPhraseOrTip(disableTips));
  const intervalRef = (0, import_react.useRef)(null);
  const nextPhrase = (0, import_react.useCallback)(() => {
    let newPhrase = getRandomPhraseOrTip(disableTips);
    let attempts = 0;
    while (newPhrase === phrase && attempts < 3) {
      newPhrase = getRandomPhraseOrTip(disableTips);
      attempts++;
    }
    setPhrase(newPhrase);
  }, [phrase, disableTips]);
  (0, import_react.useEffect)(() => {
    if (isActive) {
      setPhrase(getRandomPhraseOrTip(disableTips));
      intervalRef.current = setInterval(() => {
        setPhrase(getRandomPhraseOrTip(disableTips));
      }, intervalMs);
    } else {
      if (intervalRef.current) {
        clearInterval(intervalRef.current);
        intervalRef.current = null;
      }
    }
    return () => {
      if (intervalRef.current) {
        clearInterval(intervalRef.current);
        intervalRef.current = null;
      }
    };
  }, [isActive, intervalMs, disableTips]);
  return { phrase, nextPhrase };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  usePhraseCycler
});
