'use client';

import { Check, Copy } from 'lucide-react';
import {
  canShareOrganizationInviteLink,
  type InvitationLinkTarget,
} from '@/components/invitations/organizationInviteLinks';

type CopyInvitationLinkButtonProps = {
  invitation: InvitationLinkTarget;
  copied: boolean;
  copying: boolean;
  onCopy: () => void;
};

export function CopyInvitationLinkButton({
  invitation,
  copied,
  copying,
  onCopy,
}: CopyInvitationLinkButtonProps) {
  if (!canShareOrganizationInviteLink(invitation)) {
    return <span className="text-xs text-text-muted">—</span>;
  }

  return (
    <button
      type="button"
      className="p-2 rounded-md text-text-secondary hover:bg-background-card/80 hover:text-text-primary disabled:opacity-50"
      disabled={copying}
      onClick={onCopy}
      aria-label="Copy invitation link"
      title="Copy invitation link (generates a new link if needed)"
    >
      {copied ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
    </button>
  );
}
