Files
RDO/dist/assets/js/RDODetails-tkR9ftO-.js
2026-02-20 07:25:32 -03:00

6 lines
15 KiB
JavaScript

import{j as e}from"./query-vendor-BLVqILA6.js";import{r as n,c as R,d as O}from"./router-vendor-D4by-_6Z.js";import{T}from"./ThemeToggle-Cryh6OOS.js";import{s as l}from"./index-doec96Hx.js";import{T as y,R as S,o as E,F as k,W as p,U as j,n as u,m as i,l as L,k as $,j as A,x as P,c as v,b as U,v as z}from"./ui-vendor-CyRvbSfR.js";import"./react-vendor-CqRd3GwO.js";import"./supabase-vendor-CnnNSQLo.js";import"./state-vendor-DHadhBU5.js";const B=s=>{const[b,x]=n.useState(null),[d,g]=n.useState(!0),[r,m]=n.useState(null),o=n.useCallback(async()=>{if(s)try{g(!0),m(null);const{data:c,error:h}=await l.from("rdos").select(`
*,
obra:obras(*),
criador:usuarios!rdos_criado_por_fkey(*)
`).eq("id",s).single();if(h)throw h;if(!c)throw new Error("RDO não encontrado");const[{data:a},{data:t},{data:w},{data:f},{data:_},{data:C},{data:q}]=await Promise.all([l.from("rdo_atividades").select("*").eq("rdo_id",s).order("ordem"),l.from("rdo_mao_obra").select("*").eq("rdo_id",s),l.from("rdo_equipamentos").select("*").eq("rdo_id",s),l.from("rdo_ocorrencias").select("*").eq("rdo_id",s),l.from("rdo_anexos").select("*").eq("rdo_id",s),l.from("rdo_inspecoes_solda").select("*").eq("rdo_id",s),l.from("rdo_verificacoes_torque").select("*").eq("rdo_id",s)]),D={...c,atividades:a||[],mao_obra:t||[],equipamentos:w||[],ocorrencias:f||[],anexos:_||[],inspecoes_solda:C||[],verificacoes_torque:q||[]};x(D)}catch(c){m(c.message||"Erro ao carregar RDO")}finally{g(!1)}},[s]);return n.useEffect(()=>{o()},[o]),{rdo:b,loading:d,error:r,refetch:o}},F=s=>{switch(s){case"rascunho":return"bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300";case"enviado":return"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300";case"aprovado":return"bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300";case"rejeitado":return"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300";default:return"bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300"}},G=s=>{switch(s){case"rascunho":return e.jsx(z,{className:"w-4 h-4"});case"enviado":return e.jsx(U,{className:"w-4 h-4"});case"aprovado":return e.jsx(v,{className:"w-4 h-4"});default:return e.jsx(k,{className:"w-4 h-4"})}},N=s=>s.toLowerCase().includes("crítica")||s.toLowerCase().includes("grave")?"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300":s.toLowerCase().includes("atenção")||s.toLowerCase().includes("alerta")?"bg-yellow-100 dark:bg-yellow-900/30 text-yellow-700 dark:text-yellow-300":"bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300";function Y(){const{obraId:s,rdoId:b}=R(),x=O(),[d,g]=n.useState("geral"),{rdo:r,loading:m,error:o,refetch:c}=B(b),h=[{id:"geral",label:"Geral",icon:k},{id:"atividades",label:"Atividades",icon:p},{id:"recursos",label:"Recursos",icon:j},{id:"ocorrencias",label:"Ocorrências",icon:y},{id:"fotos",label:"Fotos",icon:u}];return m?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900",children:e.jsxs("div",{className:"flex flex-col items-center gap-4",children:[e.jsx("div",{className:"animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Carregando detalhes do RDO..."})]})}):o||!r?e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-gray-50 dark:bg-gray-900",children:e.jsxs("div",{className:"bg-white dark:bg-gray-800 p-8 rounded-2xl shadow-lg border border-red-200 dark:border-red-900/30 max-w-md w-full text-center",children:[e.jsx(y,{className:"w-12 h-12 text-red-500 mx-auto mb-4"}),e.jsx("h2",{className:"text-xl font-bold text-gray-900 dark:text-white mb-2",children:"Erro ao carregar RDO"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400 mb-6",children:o||"RDO não encontrado."}),e.jsxs("div",{className:"flex gap-3 justify-center",children:[e.jsx("button",{onClick:()=>x(-1),className:"px-4 py-2 bg-gray-200 dark:bg-gray-700 rounded-lg text-gray-800 dark:text-white hover:bg-gray-300 dark:hover:bg-gray-600 transition-colors",children:"Voltar"}),e.jsxs("button",{onClick:c,className:"px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors flex items-center gap-2",children:[e.jsx(S,{className:"w-4 h-4"})," Tentar Novamente"]})]})]})}):e.jsxs("div",{className:"min-h-screen bg-gradient-to-br from-blue-50 via-white to-purple-50 dark:from-gray-900 dark:via-gray-800 dark:to-gray-900",children:[e.jsx("div",{className:"bg-white/80 dark:bg-gray-800/80 backdrop-blur-md border-b border-gray-200/50 dark:border-gray-700/50 sticky top-0 z-10 transition-all",children:e.jsx("div",{className:"px-6 py-4",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>x(`/obra/${s}`),className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl transition-colors",title:"Voltar para a obra",children:e.jsx(E,{className:"w-5 h-5 text-gray-600 dark:text-gray-400"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-xl font-bold text-gray-900 dark:text-white",children:["RDO - ",new Date(r.data_relatorio).toLocaleDateString("pt-BR")]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:r.obra?.nome||"Obra não identificada"})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:`flex items-center gap-2 px-3 py-1 rounded-lg text-sm font-medium ${F(r.status)}`,children:[G(r.status),r.status.charAt(0).toUpperCase()+r.status.slice(1)]}),e.jsx(T,{})]})]})})}),e.jsx("div",{className:"px-6 py-4 overflow-x-auto",children:e.jsx("div",{className:"flex gap-2 min-w-max",children:h.map(a=>{const t=a.icon;return e.jsxs("button",{onClick:()=>g(a.id),className:`flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-medium transition-colors whitespace-nowrap ${d===a.id?"bg-blue-600 text-white shadow-md":"bg-white/70 dark:bg-gray-800/70 text-gray-600 dark:text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700"}`,children:[e.jsx(t,{className:"w-4 h-4"}),a.label]},a.id)})})}),e.jsxs("div",{className:"px-6 pb-8 max-w-7xl mx-auto",children:[d==="geral"&&e.jsxs(i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-6",children:[e.jsxs("div",{className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Informações Básicas"}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Data"}),e.jsxs("p",{className:"text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx(L,{className:"w-4 h-4"}),new Date(r.data_relatorio).toLocaleDateString("pt-BR")]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Responsável"}),e.jsxs("p",{className:"text-gray-900 dark:text-white flex items-center gap-2",children:[e.jsx($,{className:"w-4 h-4"}),r.criador?.nome||"Carregando..."]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm text-gray-600 dark:text-gray-400",children:"Clima"}),e.jsx("p",{className:"text-gray-900 dark:text-white",children:r.condicoes_climaticas})]})]})]}),r.observacoes_gerais&&e.jsxs("div",{className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4",children:"Observações Gerais"}),e.jsx("p",{className:"text-gray-700 dark:text-gray-300 leading-relaxed whitespace-pre-wrap",children:r.observacoes_gerais})]})]}),d==="atividades"&&e.jsx(i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-4",children:r.atividades&&r.atividades.length>0?r.atividades.map((a,t)=>e.jsx(i.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},transition:{delay:t*.05},className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg hover:border-blue-200/50 transition-colors",children:e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsx("span",{className:"px-2 py-1 bg-blue-100 dark:bg-blue-900/30 text-blue-700 dark:text-blue-300 rounded-lg text-xs font-medium",children:a.tipo_atividade})}),e.jsx("h4",{className:"font-medium text-gray-900 dark:text-white mb-1",children:a.descricao}),a.localizacao&&e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400 flex items-center gap-1",children:[e.jsx(A,{className:"w-3 h-3"}),a.localizacao]})]}),a.percentual_concluido!=null&&e.jsxs("div",{className:"text-right min-w-[80px]",children:[e.jsxs("div",{className:"text-2xl font-bold text-gray-900 dark:text-white mb-1",children:[a.percentual_concluido,"%"]}),e.jsx("div",{className:"w-full h-2 bg-gray-200 dark:bg-gray-600 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-green-500 transition-all duration-500",style:{width:`${a.percentual_concluido}%`},role:"progressbar","aria-label":"Progresso da atividade"})})]})]})},a.id)):e.jsxs("div",{className:"text-center p-8 bg-white/50 dark:bg-gray-800/50 rounded-2xl",children:[e.jsx(p,{className:"w-12 h-12 text-gray-400 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-500",children:"Nenhuma atividade registrada."})]})}),d==="recursos"&&e.jsxs(i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-6",children:[e.jsxs("div",{className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2",children:[e.jsx(j,{className:"w-5 h-5"}),"Mão de Obra"]}),e.jsx("div",{className:"space-y-3",children:r.mao_obra&&r.mao_obra.length>0?r.mao_obra.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-700/50 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:a.funcao}),e.jsxs("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:["Qtd: ",a.quantidade]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("p",{className:"font-medium text-gray-900 dark:text-white",children:[a.horas_trabalhadas,"h"]}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:"trabalhadas"})]})]},a.id)):e.jsx("p",{className:"text-gray-500 italic text-sm",children:"Nenhuma mão de obra registrada."})})]}),e.jsxs("div",{className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-6 border border-gray-200/50 dark:border-gray-700/50 shadow-lg",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-4 flex items-center gap-2",children:[e.jsx(P,{className:"w-5 h-5"}),"Equipamentos"]}),e.jsx("div",{className:"space-y-3",children:r.equipamentos&&r.equipamentos.length>0?r.equipamentos.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-700/50 rounded-xl hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"font-medium text-gray-900 dark:text-white",children:a.nome_equipamento}),a.tipo&&e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:a.tipo})]}),e.jsx("div",{className:"text-right",children:e.jsxs("p",{className:"font-medium text-gray-900 dark:text-white",children:[a.horas_utilizadas,"h uso"]})})]},a.id)):e.jsx("p",{className:"text-gray-500 italic text-sm",children:"Nenhum equipamento registrado."})})]})]}),d==="ocorrencias"&&e.jsx(i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-4",children:r.ocorrencias&&r.ocorrencias.length>0?r.ocorrencias.map((a,t)=>e.jsx(i.div,{initial:{opacity:0,x:-10},animate:{opacity:1,x:0},transition:{delay:t*.05},className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-4 border border-gray-200/50 dark:border-gray-700/50 shadow-lg",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`p-2 rounded-lg ${N(a.gravidade||"normal")}`,children:e.jsx(y,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:`px-2 py-1 rounded-lg text-xs font-medium ${N(a.gravidade||"normal")}`,children:(a.gravidade||"Geral").toUpperCase()}),e.jsx("span",{className:"text-sm text-gray-600 dark:text-gray-400 bg-gray-100 dark:bg-gray-700 px-2 py-0.5 rounded",children:a.tipo_ocorrencia})]}),e.jsx("p",{className:"text-gray-900 dark:text-white mt-2",children:a.descricao}),a.acao_tomada&&e.jsxs("div",{className:"mt-2 text-sm text-gray-600 dark:text-gray-400 border-l-2 border-gray-300 pl-3",children:[e.jsx("span",{className:"font-semibold",children:"Ação tomada:"})," ",a.acao_tomada]})]})]})},a.id)):e.jsxs("div",{className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-8 border border-gray-200/50 dark:border-gray-700/50 shadow-lg text-center",children:[e.jsx(v,{className:"w-12 h-12 text-green-500 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Nenhuma ocorrência registrada neste dia"})]})}),d==="fotos"&&e.jsx(i.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},className:"space-y-4",children:r.anexos&&r.anexos.filter(a=>a.tipo_arquivo?.startsWith("image/")||!0).length>0?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-4",children:r.anexos.map((a,t)=>e.jsxs(i.div,{initial:{opacity:0,scale:.9},animate:{opacity:1,scale:1},transition:{delay:t*.05},className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl overflow-hidden border border-gray-200/50 dark:border-gray-700/50 shadow-lg hover:shadow-xl transition-all duration-300 group relative",children:[e.jsx("div",{className:"aspect-square overflow-hidden bg-gray-100 dark:bg-gray-700",children:a.url_storage?e.jsx("img",{src:a.url_storage,alt:a.descricao||`Foto ${t+1}`,className:"w-full h-full object-cover hover:scale-110 transition-transform duration-500"}):e.jsx("div",{className:"w-full h-full flex items-center justify-center text-gray-400",children:e.jsx(u,{className:"w-8 h-8"})})}),a.descricao&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/60 p-2 opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx("p",{className:"text-white text-xs truncate",children:a.descricao})})]},t))}):e.jsxs("div",{className:"bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl p-8 border border-gray-200/50 dark:border-gray-700/50 shadow-lg text-center",children:[e.jsx(u,{className:"w-12 h-12 text-gray-400 dark:text-gray-500 mx-auto mb-3"}),e.jsx("p",{className:"text-gray-600 dark:text-gray-400",children:"Nenhuma foto encontrada neste RDO"})]})})]})]})}export{Y as default};