'use client' import { ExternalLinkIcon } from 'lucide-react' import Link from 'next/link' import { useActionState, useMemo, useState } from 'react' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/Alert' import { Badge } from '@/components/ui/Badge' import { Button } from '@/components/ui/button' import { Checkbox } from '@/components/ui/Checkbox' import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field' import { Input } from '@/components/ui/input' import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select' import { Spinner } from '@/components/ui/Spinner' import { Textarea } from '@/components/ui/textarea' import { activityKindLabels, activityOriginLabels, activityOrigins, type ActivityKind, type ActivityOrigin, } from '@/lib/schemas/activity' import type { CampaignFormActionState } from '@/utilities/campaignFormActionError' import { fieldError } from '@/utilities/campaignFormFields' import type { TourStopRole } from '@/utilities/visit/visitPlannerViews' import { MAX_TOUR_NAME_LENGTH, MAX_TOUR_STOPS, tourStopRoleDescriptions, tourStopRoleLabels, } from '@/utilities/visit/visitPlannerViews' /** The composition came from the numbers; the coordination changes it per stop. */ const DEFAULT_STOP_ORIGIN: ActivityOrigin = 'dado' /** * One candidate stop, already reduced to what the decision needs. Numbers arrive * formatted and the dossier href arrives built: the canonical serializers drag * the município catalog with them, and this is a client component (the B14 * lesson — 21 kB of First Load JS for one link). */ export type TourStopOption = { municipalityID: number slug: string name: string role: TourStopRole suggested: boolean /** Activity kind the stop generates, derived from its role. */ kind: ActivityKind metCount: number conditionCount: number unmetConditionLabels: string[] deficitLabel: string contraindicationReason: string | null dossierHref: string } const StopRow = ({ stop, checked, origin, onToggle, onOriginChange, }: { stop: TourStopOption checked: boolean origin: ActivityOrigin onToggle: (checked: boolean) => void onOriginChange: (origin: ActivityOrigin) => void }) => { const checkboxId = `tour-stop-${stop.slug}` const originId = `tour-origin-${stop.slug}` return (
  • onToggle(next === true)} className="mt-1.5" />
    {tourStopRoleLabels[stop.role]} {stop.metCount} de {stop.conditionCount} condições

    {tourStopRoleDescriptions[stop.role]}

    Faltam {stop.deficitLabel} votos para a meta. {stop.unmetConditionLabels.length > 0 ? ` Ainda não atende: ${stop.unmetConditionLabels.join(', ')}.` : ' Atende as cinco condições.'}

    {stop.contraindicationReason ? (

    {stop.contraindicationReason}

    ) : null}
    Ver dossiê
    {checked ? ( Origem desta parada onOriginChange(event.target.value as ActivityOrigin)} className="min-h-11 w-full" > {activityOrigins.map((value) => ( {activityOriginLabels[value]} ))} ) : null}
  • ) } /** * Interactions 2 and 3 of the composer: review the proposed composition * (âncora + satélites + semente, all pre-selected) and generate the drafts. * * It is a SUGGESTION and it says so — the numbers rank, the coordination * decides, and nothing is written until this form is submitted (P25: no * automatic allocation without a human in the loop). */ export const TourComposerForm = ({ region, stops, defaultTourName, formAction, }: { region: string stops: TourStopOption[] defaultTourName: string formAction: ( state: CampaignFormActionState, formData: FormData, ) => Promise }) => { const [state, submitAction, isPending] = useActionState(formAction, {}) const [selectedSlugs, setSelectedSlugs] = useState(() => stops.filter((stop) => stop.suggested).map((stop) => stop.slug), ) const [origins, setOrigins] = useState>({}) const selectedSet = useMemo(() => new Set(selectedSlugs), [selectedSlugs]) const stopsJson = useMemo( () => JSON.stringify( stops .filter((stop) => selectedSet.has(stop.slug)) .map((stop) => ({ municipality: stop.municipalityID, kind: stop.kind, origin: origins[stop.slug] ?? DEFAULT_STOP_ORIGIN, })), ), [stops, selectedSet, origins], ) const overCap = selectedSlugs.length > MAX_TOUR_STOPS const canSubmit = selectedSlugs.length > 0 && !overCap const toggleStop = (slug: string, checked: boolean) => setSelectedSlugs((current) => checked ? [...current, slug] : current.filter((entry) => entry !== slug), ) return (

    Paradas propostas em {region}

    {selectedSlugs.length} selecionada{selectedSlugs.length === 1 ? '' : 's'}
      {stops.map((stop) => ( toggleStop(stop.slug, checked)} onOriginChange={(origin) => setOrigins((current) => ({ ...current, [stop.slug]: origin })) } /> ))}
    Nome do giro Cada rascunho recebe este nome mais o município — assim o giro se lê como um conjunto na lista de Atividades. {fieldError(state.fieldErrors, 'tourName') ? ( {fieldError(state.fieldErrors, 'tourName')} ) : null} Nota de janela política