'use client' import { DemandResponsibleMultiSelect, type DemandResponsibleOption, } from '@/components/campaign/demand/DemandResponsibleMultiSelect' import { AsyncSearchCombobox } from '@/components/campaign/shared/AsyncSearchCombobox' import type { RelationOption } from '@/components/campaign/shared/RelationMultiSelect' import { Button } from '@/components/ui/button' import { Field, FieldDescription, FieldError, FieldLabel } from '@/components/ui/field' import { NativeSelect, NativeSelectOption } from '@/components/ui/native-select' import { Textarea } from '@/components/ui/textarea' import { CAMPAIGN_DEMAND_ACTIVITY_DESCRIPTION, CAMPAIGN_DEMAND_ACTIVITY_DIALOG_DESCRIPTION, CAMPAIGN_DEMAND_ACTIVITY_EMPTY_LABEL, CAMPAIGN_DEMAND_ACTIVITY_LABEL, CAMPAIGN_DEMAND_BODY_DESCRIPTION, CAMPAIGN_DEMAND_BODY_LABEL, CAMPAIGN_DEMAND_BODY_MAX_LENGTH, CAMPAIGN_DEMAND_BODY_PLACEHOLDER, CAMPAIGN_DEMAND_KIND_LABEL, CAMPAIGN_DEMAND_RESPONSIBLES_DESCRIPTION, CAMPAIGN_DEMAND_RESPONSIBLES_LABEL, campaignDemandKindLabels, campaignDemandKinds, } from '@/lib/schemas/campaignDemand' import { cn } from '@/lib/utils' import type { CampaignFormActionState } from '@/utilities/campaignFormActionError' import { fieldError } from '@/utilities/campaignFormFields' export type DemandActivityValue = { id: number; label: string } type DemandFieldsProps = { idPrefix: string disabled?: boolean state: CampaignFormActionState activity: DemandActivityValue | null onActivityChange: (value: DemandActivityValue | null) => void searchActivities: (query: string) => Promise /** Present on `/demandas/nova`: the municipality selector gates the activity search. */ municipality?: { options: RelationOption[] value: string onValueChange: (value: string) => void } /** C143 — explicit-responsible picker; `aside` splits a right column (nova). */ responsibles?: { currentUser: { id: number; name: string } | null search: (query: string) => Promise layout: 'aside' | 'stacked' } } /** * Shared demand-create fields (D11): Tipo, Atividade and the single free-text * description, used by the wizard final step (fixed municipality, stacked) and * by `DemandForm` (selectable municipality, two-column grid). */ export const DemandFields = ({ idPrefix, disabled, state, activity, onActivityChange, searchActivities, municipality, responsibles, }: DemandFieldsProps) => { const municipalityReady = municipality ? municipality.value !== '' : true const activityField = ( {CAMPAIGN_DEMAND_ACTIVITY_LABEL} {municipality && !municipalityReady ? ( ) : ( municipalityReady : undefined} queryTooShortMessage={ municipality ? 'Selecione o município para buscar atividades.' : undefined } search={searchActivities} onChange={onActivityChange} /> )} {municipality && !municipalityReady ? 'Opcional. Escolha o município antes de vincular uma atividade.' : CAMPAIGN_DEMAND_ACTIVITY_DESCRIPTION} {fieldError(state.fieldErrors, 'activity') ? ( {fieldError(state.fieldErrors, 'activity')} ) : null} ) const kindField = ( {CAMPAIGN_DEMAND_KIND_LABEL} {campaignDemandKinds.map((kind) => ( {campaignDemandKindLabels[kind]} ))} ) const coreFields = ( <> {municipality ? (
{kindField} Município { municipality.onValueChange(event.target.value) onActivityChange(null) }} className="min-h-11 w-full" > Selecione o município… {municipality.options.map((option) => ( {option.name} ))} {fieldError(state.fieldErrors, 'municipality') ? ( {fieldError(state.fieldErrors, 'municipality')} ) : null}
) : ( kindField )} {activityField} {CAMPAIGN_DEMAND_BODY_LABEL} {CAMPAIGN_DEMAND_BODY_DESCRIPTION}