import { CheckCircle2, AlertTriangle, XCircle, ShieldCheck } from 'lucide-react';
import StatusPill from '@/components/workshop/StatusPill';
import { ossiguardService, SAFETY_BANNER } from '@/services/ossiguardService';

export default function OssiguardValidation({ profile, project, limb }) {
  const result = ossiguardService.validateProject(project, profile, limb);

  return (
    <div className="space-y-4">
      <div className="rounded-lg border border-violet-400/30 bg-violet-400/5 p-3 text-xs text-violet-200">
        <ShieldCheck className="mr-1.5 inline h-4 w-4" />
        {SAFETY_BANNER}
      </div>

      <div className="flex items-center gap-2">
        <StatusPill tone={result.level === 'blocked' ? 'red' : result.level === 'warning' ? 'amber' : 'green'}>
          {result.status}
        </StatusPill>
        <span className="text-sm text-slate-400">
          {result.level === 'blocked'
            ? 'Mandatory Ossiguard checks failing — Ready for External CAD and Print Ready are blocked.'
            : result.level === 'warning'
            ? 'Ossiguard checks have warnings — review before proceeding.'
            : 'All Ossiguard validation checks passed.'}
        </span>
      </div>

      {result.issueObjects.length === 0 ? (
        <p className="flex items-center gap-2 text-sm text-emerald-300">
          <CheckCircle2 className="h-4 w-4" /> No issues detected.
        </p>
      ) : (
        <ul className="space-y-1.5">
          {result.issueObjects.map((issue, i) => (
            <li key={i} className="flex items-start gap-2 text-sm">
              {issue.level === 'blocked' ? (
                <XCircle className="mt-0.5 h-4 w-4 shrink-0 text-red-400" />
              ) : issue.level === 'warning' ? (
                <AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-amber-400" />
              ) : (
                <CheckCircle2 className="mt-0.5 h-4 w-4 shrink-0 text-emerald-400" />
              )}
              <span className={issue.level === 'blocked' ? 'text-red-300' : issue.level === 'warning' ? 'text-amber-200' : 'text-emerald-300'}>
                {issue.text}
              </span>
            </li>
          ))}
        </ul>
      )}
    </div>
  );
}