'use client' import { useState } from 'react' import { useRouter } from 'next/navigation' import { ArrowLeft, FileText, Building2, MapPin, Users, Loader2, AlertCircle, } from 'lucide-react' const TRIBUNAIS = [ { value: 'STF', label: 'STF - Supremo Tribunal Federal' }, { value: 'STJ', label: 'STJ - Superior Tribunal de Justiça' }, { value: 'TST', label: 'TST - Tribunal Superior do Trabalho' }, { value: 'TSE', label: 'TSE - Tribunal Superior Eleitoral' }, { value: 'STM', label: 'STM - Superior Tribunal Militar' }, { value: 'TRF1', label: 'TRF1 - 1ª Região' }, { value: 'TRF2', label: 'TRF2 - 2ª Região (RJ, ES)' }, { value: 'TRF3', label: 'TRF3 - 3ª Região (SP, MS)' }, { value: 'TRF4', label: 'TRF4 - 4ª Região (RS, PR, SC)' }, { value: 'TRF5', label: 'TRF5 - 5ª Região (PE, AL, CE, PB, RN, SE)' }, { value: 'TRF6', label: 'TRF6 - 6ª Região (MG)' }, { value: 'TJSP', label: 'TJSP - São Paulo' }, { value: 'TJRJ', label: 'TJRJ - Rio de Janeiro' }, { value: 'TJMG', label: 'TJMG - Minas Gerais' }, { value: 'TJRS', label: 'TJRS - Rio Grande do Sul' }, { value: 'TJPR', label: 'TJPR - Paraná' }, { value: 'TJSC', label: 'TJSC - Santa Catarina' }, { value: 'TJBA', label: 'TJBA - Bahia' }, { value: 'TJPE', label: 'TJPE - Pernambuco' }, { value: 'TJCE', label: 'TJCE - Ceará' }, { value: 'TJDF', label: 'TJDF - Distrito Federal' }, { value: 'TJGO', label: 'TJGO - Goiás' }, { value: 'TJMA', label: 'TJMA - Maranhão' }, { value: 'TJPA', label: 'TJPA - Pará' }, { value: 'TJMT', label: 'TJMT - Mato Grosso' }, { value: 'TJMS', label: 'TJMS - Mato Grosso do Sul' }, { value: 'TJES', label: 'TJES - Espírito Santo' }, { value: 'TJAL', label: 'TJAL - Alagoas' }, { value: 'TJAM', label: 'TJAM - Amazonas' }, { value: 'TJPB', label: 'TJPB - Paraíba' }, { value: 'TJPI', label: 'TJPI - Piauí' }, { value: 'TJRN', label: 'TJRN - Rio Grande do Norte' }, { value: 'TJSE', label: 'TJSE - Sergipe' }, { value: 'TJTO', label: 'TJTO - Tocantins' }, { value: 'TJAC', label: 'TJAC - Acre' }, { value: 'TJAP', label: 'TJAP - Amapá' }, { value: 'TJRO', label: 'TJRO - Rondônia' }, { value: 'TJRR', label: 'TJRR - Roraima' }, ] export default function NovoProcessoPage() { const router = useRouter() const [saving, setSaving] = useState(false) const [error, setError] = useState(null) const [form, setForm] = useState({ numeroProcesso: '', tribunal: '', vara: '', comarca: '', parteAutora: '', parteRe: '', }) // Máscara CNJ: 0000000-00.0000.0.00.0000 function formatCNJ(value: string): string { const digits = value.replace(/\D/g, '').slice(0, 20) if (digits.length <= 7) return digits if (digits.length <= 9) return `${digits.slice(0, 7)}-${digits.slice(7)}` if (digits.length <= 13) return `${digits.slice(0, 7)}-${digits.slice(7, 9)}.${digits.slice(9)}` if (digits.length <= 14) return `${digits.slice(0, 7)}-${digits.slice(7, 9)}.${digits.slice(9, 13)}.${digits.slice(13)}` if (digits.length <= 16) return `${digits.slice(0, 7)}-${digits.slice(7, 9)}.${digits.slice(9, 13)}.${digits.slice(13, 14)}.${digits.slice(14)}` return `${digits.slice(0, 7)}-${digits.slice(7, 9)}.${digits.slice(9, 13)}.${digits.slice(13, 14)}.${digits.slice(14, 16)}.${digits.slice(16)}` } function handleNumeroChange(e: React.ChangeEvent) { const formatted = formatCNJ(e.target.value) setForm(f => ({ ...f, numeroProcesso: formatted })) } async function handleSubmit(e: React.FormEvent) { e.preventDefault() setError(null) if (!form.numeroProcesso || !form.tribunal) { setError('Número do processo e tribunal são obrigatórios') return } // Valida formato CNJ const cnjRegex = /^\d{7}-\d{2}\.\d{4}\.\d{1}\.\d{2}\.\d{4}$/ if (!cnjRegex.test(form.numeroProcesso)) { setError('Número do processo inválido. Complete o formato CNJ: 0000000-00.0000.0.00.0000') return } setSaving(true) try { const res = await fetch('/api/processos', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(form), }) const data = await res.json() if (!res.ok) { setError(data.error || 'Erro ao cadastrar processo') return } router.push('/dashboard/publicacoes') } catch (e) { setError('Erro de conexão') } finally { setSaving(false) } } return (
{/* Header */}

Adicionar Processo para Monitorar

Cadastre um processo para acompanhar publicações nos Diários Oficiais

{/* Form */}
{error && (
{error}
)} {/* Número do Processo */}

Dados do Processo

Formato: NNNNNNN-DD.AAAA.J.TR.OOOO

{/* Localização */}

Localização (opcional)

setForm(f => ({ ...f, vara: e.target.value }))} placeholder="Ex: 1ª Vara Cível" className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-white outline-none focus:border-indigo-500/40 placeholder:text-zinc-600" />
setForm(f => ({ ...f, comarca: e.target.value }))} placeholder="Ex: São Paulo" className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-white outline-none focus:border-indigo-500/40 placeholder:text-zinc-600" />
{/* Partes */}

Partes (opcional)

setForm(f => ({ ...f, parteAutora: e.target.value }))} placeholder="Nome do autor" className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-white outline-none focus:border-indigo-500/40 placeholder:text-zinc-600" />
setForm(f => ({ ...f, parteRe: e.target.value }))} placeholder="Nome do réu" className="w-full rounded-lg border border-white/10 bg-white/5 px-4 py-2.5 text-white outline-none focus:border-indigo-500/40 placeholder:text-zinc-600" />
{/* Submit */}
) }