import type { CommunityServiceWorkflow } from '@/components/community-service/types';
import { CommunityFilters } from '@/components/community-service/CommunityFilters';
import { CommunityResults } from '@/components/community-service/CommunityResults';
import { CommunityServiceHeader } from '@/components/community-service/CommunityServiceHeader';
import { CommunityStatsGrid } from '@/components/community-service/CommunityStatsGrid';
import { StatePanel } from '@/components/ui/state-panel';

interface CommunityServiceViewProps {
  readonly workflow: CommunityServiceWorkflow;
}

export function CommunityServiceView({ workflow }: CommunityServiceViewProps) {
  return (
    <div className="space-y-6">
      <CommunityServiceHeader />
      {workflow.isLoading && (
        <StatePanel tone="slate" loading>
          Loading community organizations...
        </StatePanel>
      )}
      {workflow.error && (
        <StatePanel tone="red" role="alert">
          Community organizations could not be loaded from the backend.
        </StatePanel>
      )}
      {!workflow.isLoading && !workflow.error && (
        <>
      <CommunityFilters workflow={workflow} />
      <CommunityStatsGrid workflow={workflow} />
      <CommunityResults workflow={workflow} />
        </>
      )}
    </div>
  );
}
