"use client";

import { useState } from "react";

export function CopyTextButton({
  text,
  label = "Copy",
}: {
  text: string;
  label?: string;
}) {
  const [copied, setCopied] = useState(false);

  return (
    <button
      type="button"
      onClick={async () => {
        try {
          await navigator.clipboard.writeText(text);
          setCopied(true);
          window.setTimeout(() => setCopied(false), 2000);
        } catch {
          setCopied(false);
        }
      }}
      className="inline-flex items-center gap-1.5 border border-[var(--archi-line)] bg-white px-3 py-1.5 text-xs font-medium transition hover:border-[var(--archi-gold)]/40"
    >
      {copied ? "Copied" : label}
    </button>
  );
}
