import type { CommunityServiceWorkflow } from '@/components/community-service/types';
import { CommunityEmptyResults } from '@/components/community-service/CommunityEmptyResults';
import { CommunityOrganizationCard } from '@/components/community-service/CommunityOrganizationCard';

interface CommunityResultsProps {
  readonly workflow: CommunityServiceWorkflow;
}

export function CommunityResults({ workflow }: CommunityResultsProps) {
  return (
    <div className="space-y-4">
      <div className="flex items-center justify-between">
        <p className="text-sm text-slate-400">
          {workflow.filteredOrganizations.length} organization{workflow.filteredOrganizations.length !== 1 ? 's' : ''} found
        </p>
      </div>

      {workflow.filteredOrganizations.map((organization) => (
        <CommunityOrganizationCard
          key={organization.id}
          organization={organization}
          expanded={workflow.expandedOrganizationId === organization.id}
          saved={workflow.savedOrganizationIds.has(organization.id)}
          onToggleExpanded={() => workflow.toggleExpandedOrganization(organization.id)}
          onToggleSaved={() => workflow.toggleSavedOrganization(organization.id)}
        />
      ))}

      {workflow.filteredOrganizations.length === 0 && <CommunityEmptyResults />}
    </div>
  );
}
