"use client"; import type { Ajuda, Anexo, Pergunta, Resposta } from "@prisma/client"; import { Controller, useFormContext } from "react-hook-form"; import { AjudaButton } from "@/components/ajuda/AjudaButton"; import { AnexoField } from "@/components/form/AnexoField"; import { Badge } from "@/components/ui/badge"; import { Checkbox } from "@/components/ui/checkbox"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; import { Textarea } from "@/components/ui/textarea"; type PerguntaComAjuda = Pergunta & { ajuda: Ajuda | null; anexos?: Anexo[]; respostas?: Resposta[]; }; type Props = { briefingId: string; pergunta: PerguntaComAjuda; index: number; readOnly?: boolean; }; type FormValues = { perguntas: Record< string, { texto?: string; selecionadas?: string[]; complemento?: string; } >; }; function getOpcoes(pergunta: PerguntaComAjuda) { return Array.isArray(pergunta.opcoes) ? pergunta.opcoes.filter((opcao): opcao is string => typeof opcao === "string") : []; } export function PerguntaField({ briefingId, pergunta, index, readOnly = false }: Props) { const form = useFormContext(); const fieldName = `perguntas.${pergunta.id}`; const opcoes = getOpcoes(pergunta); const texto = form.watch(`${fieldName}.texto`) ?? ""; return (
{index + 1}
{pergunta.dica ?

{pergunta.dica}

: null}
form.setValue(`${fieldName}.texto`, value, { shouldDirty: true }) } />
{pergunta.tipo === "TEXTAREA" ? ( <>
{["Nao se aplica", "A definir"].map((atalho) => ( ))}