"use client";
import * as React from 'react';

function useCopyToClipboard({
  timeout = 2e3
}) {
  const [isCopied, setIsCopied] = React.useState(false);
  const copyToClipboard = (value) => {
    if (typeof window === "undefined" || !navigator.clipboard?.writeText) {
      return;
    }
    if (!value) {
      return;
    }
    navigator.clipboard.writeText(value).then(() => {
      setIsCopied(true);
      setTimeout(() => {
        setIsCopied(false);
      }, timeout);
    });
  };
  return { isCopied, copyToClipboard };
}

export { useCopyToClipboard };
