import React, { useRef, useLayoutEffect } from 'react'; import { format, isValid } from 'date-fns'; import type { Project } from '../../types'; import '../../styles/reports.css'; interface AnalyticalReportProps { project: Project; logoUrl?: string; } const ProgressFill: React.FC<{ progress: number }> = ({ progress }) => { const fillRef = useRef(null); useLayoutEffect(() => { if (fillRef.current) { fillRef.current.style.setProperty('--progress', `${progress}%`); } }, [progress]); return
; }; export const AnalyticalReport: React.FC = ({ project, logoUrl }) => { const inspections = project.inspections || []; const sumWeight = inspections.reduce((acc, curr) => acc + (curr.weightKg || 0), 0); const totalWeight = project.weightKg || 0; const progress = totalWeight > 0 ? Math.min(Math.round((sumWeight / totalWeight) * 100), 100) : 0; // Período const startDate = project.startDate ? new Date(project.startDate) : null; const endDate = project.endDate ? new Date(project.endDate) : null; const periodStr = (startDate && isValid(startDate) && endDate && isValid(endDate)) ? `${format(startDate, 'MM/yyyy')} – ${format(endDate, 'MM/yyyy')}` : '--/----'; return (
{logoUrl ? ( Logo ) : (
)}
RELATÓRIO ANALÍTICO DE OBRA
Detalhamento de Inspeções, Aplicativos e Esquemas de Pintura
Data: {format(new Date(), 'dd/MM/yyyy')}
Obra: {project.name.toUpperCase()}
Evolução Real
{progress}%
Peso Medido (kgf)
{sumWeight.toLocaleString('pt-BR')}
de {totalWeight.toLocaleString('pt-BR')} total
Responsável
{project.technician || '________________'}
Técnico Encarregado
Período de Obra
{periodStr}
Cronograma Previsto

ESQUEMA DE PINTURA REQUERIDO

Especificação técnica por demão
{project.paintingSchemes?.map((s, idx) => ( ))} {(!project.paintingSchemes || project.paintingSchemes.length === 0) && ( )}
Etapa Produto Cor EPS (μm)
{s.coat || s.type} {s.name.toUpperCase()} {s.color || '--'} {s.epsMin}-{s.epsMax} μm
Nenhum esquema definido

INSPEÇÕES REALIZADAS

{inspections.slice(0, 15).map((insp, idx) => ( ))} {inspections.length === 0 && ( )}
Data Peça / Área Peso Status
{insp.date ? format(new Date(insp.date), 'dd/MM/yy') : '--'} {insp.pieceDescription} {insp.weightKg?.toLocaleString('pt-BR')} {insp.appearance === 'approved' ? 'OK' : 'REJ'}
Sem registros

REGISTROS DE APLICAÇÃO

{project.applicationRecords?.slice(0, 15).map((record, idx) => ( ))} {(!project.applicationRecords || project.applicationRecords.length === 0) && ( )}
Data Etapa EPS Seca Pintor
{record.date ? format(new Date(record.date), 'dd/MM/yy') : '--'} {record.coatStage} {record.dryThicknessCalc || '--'} μm {record.operator?.split(' ')[0]}
Sem registros
); };