import { useState } from "react";
import { useEventCallback } from "../../../../_vendor/usehooks-ts/dist-index.js";
function useCodeBlock({
  defaultExpanded = true,
  defaultCodeExpanded = false,
  onExpandChange,
  onCodeExpandChange,
  scrollToBottom
}) {
  const [isExpanded, setIsExpanded] = useState(defaultExpanded);
  const [codeExpanded, setCodeExpanded] = useState(defaultCodeExpanded);
  const [copied, setCopied] = useState(false);
  const handleExpand = useEventCallback(() => {
    const newValue = !isExpanded;
    setIsExpanded(newValue);
    onExpandChange?.(newValue);
  });
  const handleCodeExpand = useEventCallback(() => {
    const newValue = !codeExpanded;
    setCodeExpanded(newValue);
    onCodeExpandChange?.(newValue);
    scrollToBottom?.({
      wait: 100
    });
  });
  const handleCopy = useEventCallback(async (code) => {
    try {
      await navigator.clipboard.writeText(code);
      setCopied(true);
      setTimeout(() => setCopied(false), 2e3);
    } catch (error) {
      console.error("Failed to copy code:", error);
    }
  });
  return {
    isExpanded,
    codeExpanded,
    copied,
    handleExpand,
    handleCodeExpand,
    handleCopy
  };
}
export {
  useCodeBlock
};
//# sourceMappingURL=use-code-block.js.map
