"use client";
import React from "react";
import { Button, type ButtonProps } from "./ui/button";
import { toast } from "sonner";
import type { title } from "process";

function CopyToClip({
  text,
  target,
  buttonProps,
  children,
}: {
  text: string;
  target?: string;
  buttonProps?: ButtonProps;
  children?: React.ReactNode;
}) {
  const handleclick = () => {
    navigator.clipboard.writeText(text);
    toast(<p>Copied {target ? <b>{target}</b> : ""} to clipboard</p>);
  };
  return (
    <Button {...buttonProps} onClick={handleclick}>
      {children}
    </Button>
  );
}

export default CopyToClip;
