"use client";
import { useState as l, useRef as u, useCallback as c } from "react";
import { toast as t } from "../node_modules/sonner/dist/index.js";
function d({
  text: o,
  copyMessage: r = "Copied to clipboard!"
}) {
  const [n, i] = l(!1), e = u(null), a = c(() => {
    if (typeof navigator > "u" || !navigator.clipboard) {
      t.error("Clipboard API not available in this environment.");
      return;
    }
    navigator.clipboard.writeText(o).then(() => {
      t.success(r), i(!0), e.current && (clearTimeout(e.current), e.current = null), e.current = setTimeout(() => {
        i(!1);
      }, 2e3);
    }).catch(() => {
      t.error("Failed to copy to clipboard.");
    });
  }, [o, r]);
  return { isCopied: n, handleCopy: a };
}
export {
  d as useCopyToClipboard
};
