import type { ModuleId } from '@/shared/types/app';
import type { DirectorRiskArea } from '@/business/director-dashboard/types';
import { DirectorScaleButton } from '@/components/director-dashboard/DirectorScaleButton';
import {
  directorNavigateIcon,
  directorRiskIcon,
  directorRiskSeverityClasses,
} from '@/components/director-dashboard/directorDashboardViewConfig';

interface DirectorRiskListProps {
  readonly risks: readonly DirectorRiskArea[];
  readonly onOpenModule: (module: ModuleId) => void;
  readonly onOpenAcknowledgments?: () => void;
  readonly onOpenQuizResults?: () => void;
}

export function DirectorRiskList({
  risks,
  onOpenModule,
  onOpenAcknowledgments,
  onOpenQuizResults,
}: DirectorRiskListProps) {
  const RiskIcon = directorRiskIcon;
  const NavigateIcon = directorNavigateIcon;

  function handleRiskClick(risk: DirectorRiskArea) {
    if (risk.action === 'openAcknowledgments' && onOpenAcknowledgments) {
      onOpenAcknowledgments();
      return;
    }

    if (risk.action === 'openQuizResults' && onOpenQuizResults) {
      onOpenQuizResults();
      return;
    }

    onOpenModule(risk.module);
  }

  return (
    <div className="bg-white rounded-2xl border border-violet-100 shadow-sm p-5">
      <h3 className="font-semibold text-gray-800 mb-4 flex items-center gap-2">
        <RiskIcon size={18} className="text-amber-500" />
        Risk Areas
      </h3>
      <div className="space-y-3">
        {risks.map((risk) => (
          <DirectorScaleButton
            key={`${risk.module}-${risk.issue}`}
            type="button"
            onClick={() => handleRiskClick(risk)}
            className={`flex h-auto w-full items-center justify-between gap-3 rounded-xl border p-4 text-left ${directorRiskSeverityClasses[risk.severity]}`}
          >
            <div className="flex min-w-0 items-center gap-3">
              <span className={`px-2 py-1 rounded-lg text-[10px] font-bold uppercase ${directorRiskSeverityClasses[risk.severity]}`}>
                {risk.severity}
              </span>
              <p className="min-w-0 break-words text-sm font-medium text-gray-700">{risk.issue}</p>
            </div>
            <NavigateIcon size={14} className="shrink-0 text-gray-400" />
          </DirectorScaleButton>
        ))}
      </div>
    </div>
  );
}
