import React from 'react';
import { Globe } from 'lucide-react';
import { enumLabel } from '../../../utils/i18n-enums';
import type { FindingAccent } from '../sections/FindingCard';
import { FindingCard } from '../sections/FindingCard';

function domainAccent(trust: number): FindingAccent {
  if (trust >= 70) return 'success';
  if (trust >= 40) return 'warning';
  return 'critical';
}

export function renderDomainDetail(data: any) {
  if (!data) return null;
  const trust = data.trust_score ?? 0;
  const verdictText = enumLabel(data.verdict || '') || 'Unknown';
  const isRo = (typeof document !== 'undefined' && document.documentElement.lang || '').toLowerCase().startsWith('ro');
  return (
    <FindingCard
      icon={Globe}
      accent={domainAccent(trust)}
      eyebrow={isRo ? `Domeniu · trust ${trust}` : `Domain · trust ${trust}`}
      headline={typeof data.domain === 'string' ? data.domain : data.domain?.name || (isRo ? 'Necunoscut' : 'Unknown')}
      quote={data.category}
      source={
        <span>{verdictText}</span>
      }
    />
  );
}

export function renderDomainSummary(data: any) {
  if (!data) return null;
  const trust = parseFloat(data.trust_score);
  const validTrust = !isNaN(trust) && trust >= 0;
  return (
    <span style={{ fontSize: 12, color: 'var(--fg-secondary)' }}>
      {data.domain && typeof data.domain === 'string' ? `${data.domain} · ` : ''}
      {validTrust ? `Trust ${trust}%` : 'Trust N/A'}
    </span>
  );
}
