'use client';

import { useTranslations } from 'next-intl';
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) {
  const t = useTranslations('organizations');

  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={t('copyInvitationLink')}
      title={t('copyInvitationLinkTitle')}
    >
      {copied ? <Check className="w-4 h-4" /> : <Copy className="w-4 h-4" />}
    </button>
  );
}
