"use client";

import { useState } from "react";
import { Check, Copy } from "react-feather";

export default function CopyBusinessIdButton({ businessId }: { businessId: string }) {
  const [copied, setCopied] = useState(false);

  const handleCopy = async () => {
    try {
      await navigator.clipboard.writeText(businessId);
      setCopied(true);
      window.setTimeout(() => setCopied(false), 2000);
    } catch {
      setCopied(false);
    }
  };

  return (
    <button
      type="button"
      className="btn-first small-btn btn-first-pink code-copy-button rounded-pill copyVariation h-32 m-0"
      onClick={handleCopy}
      aria-label={copied ? "Business ID copied" : "Copy business ID"}
    >
      {copied ? <Check className="feather feather-check" /> : <Copy className="feather feather-copy" />}
    </button>
  );
}