'use client';

import { useTranslations } from 'next-intl';
import { isDetailTypeSelected } from '@/components/treatment/treatmentDetailRules';
import { CaseSentLabel } from '@/components/ui/treatment/CaseSentLabel';
import { labNotSentBadgeClass, labSentBadgeClass } from '@/components/treatment/treatmentStatusStyles';
import type { LinkedOrganizationOption, PastTreatmentDetail } from '@/types/treatment';

interface DetailLabSendBadgeProps {
  detail: Pick<
    PastTreatmentDetail,
    'treatmentType' | 'sentAt' | 'sends' | 'destinationOrganizationId'
  >;
  labDependentCodes: Set<string>;
  orgs?: LinkedOrganizationOption[];
  className?: string;
}

export function DetailLabSendBadge({
  detail,
  labDependentCodes,
  orgs,
  className = '',
}: DetailLabSendBadgeProps) {
  const t = useTranslations('treatment');

  if (!isDetailTypeSelected(detail) || !labDependentCodes.has(detail.treatmentType)) {
    return null;
  }

  if (detail.sentAt) {
    return (
      <CaseSentLabel
        treatmentCase={detail}
        orgs={orgs}
        className={`${labSentBadgeClass} ${className}`.trim()}
      />
    );
  }

  return (
    <span className={`${labNotSentBadgeClass} ${className}`.trim()}>{t('detailNotSentToLab')}</span>
  );
}
