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

2 lines
25 KiB
JavaScript

var Y=Object.defineProperty;var K=(p,t,a)=>t in p?Y(p,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):p[t]=a;var T=(p,t,a)=>K(p,typeof t!="symbol"?t+"":t,a);import{j as e}from"./query-vendor-BLVqILA6.js";import{r as h,c as X,d as Z,L as ee}from"./router-vendor-D4by-_6Z.js";import{u as te,o as ae,s as B}from"./form-vendor-vQotxSmE.js";import{a as re}from"./zod-7IfHMaWP.js";import{t as A,n as G,X as se,j as oe,R as ie,o as ne,F as de,A as q,m as I,W as le,h as P,P as V,p as ce,U as ue,q as ge,r as me,s as he,u as pe}from"./ui-vendor-CyRvbSfR.js";import{T as xe}from"./ThemeToggle-Cryh6OOS.js";import{u as be,a as ye,b as fe}from"./configStore-DS-p50om.js";import{s as w}from"./index-doec96Hx.js";import{D as we}from"./state-vendor-DHadhBU5.js";import"./react-vendor-CqRd3GwO.js";import"./supabase-vendor-CnnNSQLo.js";const ve=({onCapture:p,onClose:t})=>{const a=h.useRef(null),s=h.useRef(null),[r,n]=h.useState(null),[u,f]=h.useState(null),[l,c]=h.useState(!0),[O,R]=h.useState("environment"),D=h.useCallback(async()=>{try{r&&r.getTracks().forEach(g=>g.stop()),c(!0);const d=await navigator.mediaDevices.getUserMedia({video:{facingMode:O}});n(d),a.current&&(a.current.srcObject=d),c(!1)}catch{A.error("Não foi possível acessar a câmera. Verifique as permissões."),c(!1)}},[O]);h.useEffect(()=>(D(),"geolocation"in navigator&&navigator.geolocation.getCurrentPosition(d=>{f({lat:d.coords.latitude,lng:d.coords.longitude})},d=>{A.warning("Localização não permitida. A foto ficará sem coordenadas.")}),()=>{r&&r.getTracks().forEach(d=>d.stop())}),[D]);const k=()=>{R(d=>d==="user"?"environment":"user")},N=()=>{if(!a.current||!s.current)return;const d=a.current,g=s.current,m=g.getContext("2d");if(!m)return;g.width=d.videoWidth,g.height=d.videoHeight,m.drawImage(d,0,0,g.width,g.height);const b=20,v=Math.max(16,g.width/25),C=v*1.5*3+b*2;m.fillStyle="rgba(0, 0, 0, 0.6)",m.fillRect(0,g.height-C,g.width,C),m.fillStyle="#ffffff",m.font=`${v}px sans-serif`,m.textBaseline="bottom";const $=new Date().toLocaleString("pt-BR");if(m.fillText($,b,g.height-C+b+v),u){const _=`Lat: ${u.lat.toFixed(5)} | Lng: ${u.lng.toFixed(5)}`;m.fillText(_,b,g.height-C+b+(v+10)*2)}else m.fillText("Localização não disponível",b,g.height-C+b+(v+10)*2);m.font=`bold ${v*.8}px sans-serif`,m.fillStyle="#dddddd",m.fillText("RDO App - Registro Fotográfico",b,g.height-b),g.toBlob(_=>{if(_){const U=new File([_],`foto_rdo_${Date.now()}.jpg`,{type:"image/jpeg"});p(U)}},"image/jpeg",.85)};return e.jsxs("div",{className:"fixed inset-0 z-50 bg-black flex flex-col",children:[e.jsxs("div",{className:"flex justify-between items-center p-4 bg-black/50 absolute top-0 w-full z-10",children:[e.jsxs("h3",{className:"text-white font-semibold flex items-center gap-2",children:[e.jsx(G,{className:"w-5 h-5"})," Nova Foto"]}),e.jsx("button",{onClick:t,className:"p-2 bg-gray-800 rounded-full text-white",title:"Fechar câmera","aria-label":"Fechar câmera",children:e.jsx(se,{className:"w-6 h-6"})})]}),e.jsxs("div",{className:"flex-1 relative flex items-center justify-center bg-black overflow-hidden",children:[l&&e.jsx("p",{className:"text-white absolute",children:"Iniciando câmera..."}),e.jsx("video",{ref:a,autoPlay:!0,playsInline:!0,className:"w-full h-full object-cover"}),e.jsx("canvas",{ref:s,className:"hidden"}),e.jsxs("div",{className:"absolute bottom-24 left-4 right-4 text-white text-xs opacity-70 bg-black/40 p-2 rounded pointer-events-none",children:[e.jsx("p",{children:new Date().toLocaleTimeString()}),u&&e.jsxs("p",{className:"flex items-center gap-1 mt-1",children:[e.jsx(oe,{className:"w-3 h-3"}),u.lat.toFixed(4),", ",u.lng.toFixed(4)]})]})]}),e.jsxs("div",{className:"p-6 bg-black flex justify-around items-center",children:[e.jsx("button",{onClick:k,className:"p-3 bg-gray-800 rounded-full text-white hover:bg-gray-700 transition",title:"Trocar câmera","aria-label":"Trocar câmera",children:e.jsx(ie,{className:"w-6 h-6"})}),e.jsx("button",{onClick:N,className:"w-16 h-16 bg-white rounded-full border-4 border-gray-300 hover:scale-105 transition shadow-lg",title:"Tirar foto","aria-label":"Tirar foto"}),e.jsx("div",{className:"w-12"})," "]})]})},je=()=>{const[p,t]=h.useState(!1),[a,s]=h.useState(null),r=async()=>{try{const{data:l,error:c}=await w.from("tipos_atividade").select("*").eq("ativo",!0).order("nome");if(c)throw c;return l||[]}catch(l){throw l}},n=async()=>{try{const{data:l,error:c}=await w.from("condicoes_climaticas").select("*").eq("ativo",!0).order("nome");if(c)throw c;return l||[]}catch(l){throw l}},u=async()=>{try{const{data:l,error:c}=await w.from("funcionarios").select("*").eq("ativo",!0).order("nome");if(c)throw c;return l||[]}catch(l){throw l}},f=async()=>{try{t(!0),s(null),await Promise.all([r(),n(),u()])}catch(l){const c=l instanceof Error?l.message:"Erro desconhecido";s(c)}finally{t(!1)}};return h.useEffect(()=>{f()},[]),{loading:p,error:a,loadAllData:f,loadTiposAtividade:r,loadCondicoesClimaticas:n,loadFuncionarios:u}};class ke extends we{constructor(){super("RDO_Offline_DB");T(this,"pendingRDOs");T(this,"syncQueue");T(this,"cache");this.version(1).stores({pendingRDOs:"++id, uuid, status, createdAt",syncQueue:"++id, table, type, timestamp",cache:"key"})}}const j=new ke;class W{static detectConflict(t,a){if(!t.updated_at||!a.updated_at)return!1;const s=new Date(t.updated_at).getTime(),r=new Date(a.updated_at).getTime();return Math.abs(s-r)>1e3}static resolveLastWriteWins(t){return{resolved:!0,data:t.localTimestamp>t.remoteTimestamp?t.localVersion:t.remoteVersion,strategy:"last-write-wins",requiresManualReview:!1}}static resolveMerge(t){const a={...t.remoteVersion},s=[];for(const r in t.localVersion){const n=t.localVersion[r],u=t.remoteVersion[r];JSON.stringify(n)!==JSON.stringify(u)&&(t.localTimestamp>t.remoteTimestamp&&(a[r]=n),s.push(r))}return{resolved:!0,data:a,strategy:"merge",requiresManualReview:s.length>3}}static requireManualResolution(t){return{resolved:!1,data:t.localVersion,strategy:"manual",requiresManualReview:!0}}static resolve(t){switch(t.strategy){case"last-write-wins":return this.resolveLastWriteWins(t);case"merge":return this.resolveMerge(t);case"manual":return this.requireManualResolution(t);default:return this.resolveLastWriteWins(t)}}static createConflict(t,a,s,r="last-write-wins"){return{id:a.id,table:t,localVersion:a,remoteVersion:s,localTimestamp:a.updated_at?new Date(a.updated_at).getTime():Date.now(),remoteTimestamp:s.updated_at?new Date(s.updated_at).getTime():Date.now(),strategy:r}}}class H{static saveUnresolvedConflict(t){const a=this.getUnresolvedConflicts();a.push({...t,savedAt:Date.now()}),localStorage.setItem(this.STORAGE_KEY,JSON.stringify(a))}static getUnresolvedConflicts(){const t=localStorage.getItem(this.STORAGE_KEY);return t?JSON.parse(t):[]}static removeConflict(t){const s=this.getUnresolvedConflicts().filter(r=>r.id!==t);localStorage.setItem(this.STORAGE_KEY,JSON.stringify(s))}static clearAll(){localStorage.removeItem(this.STORAGE_KEY)}static count(){return this.getUnresolvedConflicts().length}}T(H,"STORAGE_KEY","rdo_unresolved_conflicts");const S={maxRetries:5,initialDelay:1e3,maxDelay:3e4,backoffMultiplier:2};class Ne{constructor(){T(this,"isSyncing",!1);T(this,"syncListeners",[]);window.addEventListener("online",()=>this.processQueue())}onSyncStatusChange(t){return this.syncListeners.push(t),()=>{this.syncListeners=this.syncListeners.filter(a=>a!==t)}}notifyListeners(t){this.syncListeners.forEach(a=>a(t))}get isOnline(){return navigator.onLine}async processQueue(){if(!(!this.isOnline||this.isSyncing))try{this.isSyncing=!0,this.notifyListeners({status:"syncing",message:"Sincronizando dados...",progress:0}),await this.processSyncQueue(),await this.processPendingRDOs(),this.notifyListeners({status:"success",message:"Sincronização concluída",progress:100})}catch(t){this.notifyListeners({status:"error",message:`Erro: ${t instanceof Error?t.message:"Desconhecido"}`,progress:0})}finally{this.isSyncing=!1}}async processSyncQueue(){const t=await j.syncQueue.orderBy("timestamp").toArray();if(t.length!==0)for(const[a,s]of t.entries()){const r=(a+1)/t.length*50;this.notifyListeners({status:"syncing",message:`Sincronizando operação ${a+1}/${t.length}`,progress:r}),await this.syncOperation(s)}}async syncOperation(t){let a=0,s=S.initialDelay;for(;a<=S.maxRetries;)try{await this.executeSyncOperation(t),await j.syncQueue.delete(t.id);return}catch(r){if(a++,a>S.maxRetries)throw await j.syncQueue.update(t.id,{retryCount:a}),r;await this.sleep(Math.min(s,S.maxDelay)),s*=S.backoffMultiplier}}async executeSyncOperation(t){const{type:a,table:s,data:r}=t;switch(a){case"INSERT":{const{error:n}=await w.from(s).insert(r);if(n)throw n;break}case"UPDATE":{r.id&&await this.checkAndResolveConflict(s,r);const{error:n}=await w.from(s).update(r).eq("id",r.id);if(n)throw n;break}case"DELETE":{const{error:n}=await w.from(s).delete().eq("id",r.id);if(n)throw n;break}}}async checkAndResolveConflict(t,a){const{data:s,error:r}=await w.from(t).select("*").eq("id",a.id).single();if(!(r||!s)&&W.detectConflict(a,s)){const n=W.createConflict(t,a,s,"last-write-wins"),u=W.resolve(n);u.requiresManualReview?H.saveUnresolvedConflict(n):Object.assign(a,u.data)}}async processPendingRDOs(){const t=await j.pendingRDOs.where("status").equals("pending").toArray();if(t.length!==0)for(const[a,s]of t.entries()){const r=50+(a+1)/t.length*50;this.notifyListeners({status:"syncing",message:`Sincronizando RDO ${a+1}/${t.length}`,progress:r}),await this.syncRDO(s)}}async syncRDO(t){let a=0,s=S.initialDelay;for(;a<=S.maxRetries;)try{await j.pendingRDOs.update(t.id,{status:"syncing"}),this.validateRDOPayload(t.payload);const{payload:r}=t,n={...r.rdo};delete n.atividades,delete n.mao_obra,delete n.equipamentos,delete n.ocorrencias,delete n.fotos;const{data:u,error:f}=await w.from("rdos").upsert(n).select().single();if(f)throw f;if(!u)throw new Error("Não foi possível recuperar o RDO inserido");const l=u.id,c=[],O=r.atividades;if(Array.isArray(O)&&O.length){const k=O.map(N=>({...N,rdo_id:l}));c.push(w.from("rdo_atividades").upsert(k))}const R=r.mao_obra;if(Array.isArray(R)&&R.length){const k=R.map(N=>({...N,rdo_id:l}));c.push(w.from("rdo_mao_obra").upsert(k))}const D=r.fotos;if(Array.isArray(D)&&D.length){const k=D.map(async d=>{const g=`${Date.now()}_${d.name.replace(/[^a-zA-Z0-9.]/g,"_")}`,m=`${l}/${g}`,{error:b}=await w.storage.from("rdo-photos").upload(m,d);if(b)throw b;const{data:{publicUrl:v}}=w.storage.from("rdo-photos").getPublicUrl(m);return{rdo_id:l,nome_arquivo:d.name,tipo_arquivo:d.type,tamanho_bytes:d.size,url_storage:v}}),N=await Promise.all(k);c.push(w.from("rdo_anexos").upsert(N))}await Promise.all(c),await j.pendingRDOs.delete(t.id);return}catch(r){if(a++,a>S.maxRetries)throw await j.pendingRDOs.update(t.id,{status:"failed"}),r;await this.sleep(Math.min(s,S.maxDelay)),s*=S.backoffMultiplier}}validateRDOPayload(t){if(!t.rdo)throw new Error('Payload inválido: campo "rdo" ausente');const a=t.rdo;if(!a.obra_id)throw new Error('Payload inválido: "obra_id" ausente');if(!a.data_relatorio)throw new Error('Payload inválido: "data_relatorio" ausente')}sleep(t){return new Promise(a=>setTimeout(a,t))}async forceSync(){await this.processQueue()}async getSyncStats(){const t=await j.pendingRDOs.count(),a=await j.syncQueue.count(),s=H.count();return{pendingRDOs:t,pendingOperations:a,unresolvedConflicts:s,isOnline:this.isOnline,isSyncing:this.isSyncing}}}const Se=new Ne,Oe=ae({data_relatorio:B().min(1,"Data é obrigatória"),condicoes_climaticas:B().min(1,"Condições climáticas são obrigatórias"),observacoes_gerais:B().optional()});function Fe(){const{id:p}=X(),t=Z(),{items:a}=be(),{items:s}=ye(),{items:r}=fe(),{loading:n,error:u}=je(),[f,l]=h.useState({basicas:!0,atividades:!0,maoObra:!0,equipamentos:!1,inspecaoQualidade:!0,ocorrencias:!1,anexos:!1}),[c,O]=h.useState([]),[R,D]=h.useState([]),[k,N]=h.useState([]),[d,g]=h.useState([]),[m,b]=h.useState(!1),[v,z]=h.useState([]),{register:C,handleSubmit:$,formState:{errors:_}}=te({resolver:re(Oe),defaultValues:{data_relatorio:new Date().toISOString().split("T")[0]}}),U=o=>{l(i=>({...i,[o]:!i[o]}))},M=(o,i)=>{o(y=>[...y,i])},F=(o,i)=>{o(y=>y.filter(L=>L.id!==i))},J=async o=>{const i=A.loading("Processando RDO..."),y={rdo:{...o,obra_id:p,status:"pendente"},atividades:c.map(x=>({tipo_atividade:x.tipo,descricao:x.descricao,localizacao:x.localizacao})),mao_obra:R.map(x=>({funcao:x.funcao,quantidade:x.quantidade,horas_trabalhadas:x.horas})),fotos:v};try{if(navigator.onLine){const x=crypto.randomUUID(),L=await j.pendingRDOs.add({uuid:x,payload:y,createdAt:new Date().toISOString(),status:"pending",updatedAt:new Date().toISOString()});await Se.processQueue();const Q=await j.pendingRDOs.get(L);if(Q&&Q.status==="failed")throw new Error("Falha na sincronização");Q?A.success("RDO salvo e sincronizando em segundo plano.",{id:i}):A.success("RDO sincronizado com sucesso!",{id:i})}else throw new Error("Offline")}catch(x){x.message==="Offline"?(await j.pendingRDOs.add({uuid:crypto.randomUUID(),payload:y,createdAt:new Date().toISOString(),status:"pending",updatedAt:new Date().toISOString()}),A.info("Sem internet. RDO salvo no dispositivo.",{id:i,duration:5e3})):A.warning("RDO salvo localmente, mas houve erro na sincronização. Tentaremos novamente depois.",{id:i,duration:5e3})}t(`/obra/${p}`)},E=({title:o,icon:i,section:y,count:x})=>e.jsxs("button",{type:"button",onClick:()=>U(y),className:"w-full flex items-center justify-between p-4 bg-white/70 dark:bg-gray-800/70 backdrop-blur-md rounded-2xl border border-gray-200/50 dark:border-gray-700/50 shadow-lg hover:shadow-xl transition-all duration-300",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-blue-100 dark:bg-blue-900/30 rounded-lg",children:e.jsx(i,{className:"w-5 h-5 text-blue-600 dark:text-blue-400"})}),e.jsxs("h3",{className:"font-semibold text-gray-900 dark:text-white",children:[o," ",x!==void 0&&`(${x})`]})]}),f[y]?e.jsx(he,{className:"w-5 h-5 text-gray-400"}):e.jsx(pe,{className:"w-5 h-5 text-gray-400"})]});return 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.jsxs("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",children:[e.jsxs("div",{className:"px-4 sm:px-6 py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(ee,{to:`/obra/${p}`,className:"p-2 hover:bg-gray-100 dark:hover:bg-gray-700 rounded-xl",title:"Voltar para a obra",children:e.jsx(ne,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-gray-900 dark:text-white",children:"Criar RDO"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-300",children:"Obra: Edifício Aurora"})]})]}),e.jsx(xe,{})]}),n&&e.jsx("div",{className:"mx-4 mb-4 p-3 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg",children:e.jsx("p",{className:"text-blue-700 dark:text-blue-300 text-sm",children:"🔄 Carregando dados do Supabase..."})}),u&&e.jsx("div",{className:"mx-4 mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg",children:e.jsxs("p",{className:"text-red-700 dark:text-red-300 text-sm",children:["❌ Erro ao carregar dados: ",u]})})]}),e.jsxs("form",{onSubmit:$(J),className:"p-4 sm:p-6 space-y-4",children:[e.jsx(E,{title:"Informações Básicas",icon:de,section:"basicas"}),e.jsx(q,{children:f.basicas&&e.jsxs(I.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},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 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Data"}),e.jsx("input",{type:"date",...C("data_relatorio"),defaultValue:new Date().toISOString().split("T")[0],className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl"}),_.data_relatorio&&e.jsx("p",{className:"text-red-500 text-sm mt-1",children:_.data_relatorio.message})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Clima"}),e.jsx("select",{...C("condicoes_climaticas"),"aria-label":"Condições Climáticas",title:"Selecione as condições climáticas",className:"w-full p-3 bg-white dark:bg-gray-700 border border-gray-300 dark:border-gray-600 rounded-xl text-gray-900 dark:text-white",children:s.map(o=>e.jsx("option",{value:o.nome,className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:o.nome},o.id))})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-gray-900 dark:text-white mb-2",children:"Observações Gerais"}),e.jsx("textarea",{...C("observacoes_gerais"),rows:3,className:"w-full p-3 bg-white/50 dark:bg-gray-700/50 border border-gray-300 dark:border-gray-600 rounded-xl"})]})]})}),e.jsx(E,{title:"Atividades Executadas",icon:le,section:"atividades",count:c.length}),e.jsx(q,{children:f.atividades&&e.jsxs(I.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},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 space-y-4",children:[c.map((o,i)=>e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg space-y-2",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("span",{className:"font-medium text-sm",children:["Atividade ",i+1]}),e.jsx("button",{type:"button",onClick:()=>F(O,o.id),title:"Remover atividade",children:e.jsx(P,{className:"w-4 h-4 text-red-500"})})]}),e.jsxs("select",{className:"w-full p-2 border rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-white border-gray-300 dark:border-gray-600",defaultValue:"","aria-label":"Tipo de Atividade",title:"Selecione o tipo de atividade",children:[e.jsx("option",{value:"",disabled:!0,className:"text-gray-500 dark:text-gray-400",children:"Selecione o tipo"}),a.map(y=>e.jsx("option",{value:y.nome,className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:y.nome},y.id))]}),e.jsx("input",{type:"text",placeholder:"Localização (Ex: Eixo A, 1º Pavimento)",className:"w-full p-2 border rounded"}),e.jsx("textarea",{placeholder:"Descrição detalhada da atividade",rows:2,className:"w-full p-2 border rounded"})]},o.id)),e.jsxs("button",{type:"button",onClick:()=>{alert("Botão Adicionar Atividade clicado!");const o={id:Date.now().toString(),tipo:"",descricao:"",localizacao:""};M(O,o)},className:"w-full flex items-center justify-center gap-2 py-2 px-4 bg-blue-100 text-blue-700 rounded-xl",children:[e.jsx(V,{className:"w-5 h-5"})," Adicionar Atividade"]})]})}),e.jsx(E,{title:"Inspeção de Qualidade",icon:ce,section:"inspecaoQualidade",count:k.length+d.length}),e.jsx(q,{children:f.inspecaoQualidade&&e.jsxs(I.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},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 space-y-4",children:[e.jsx("h4",{className:"font-semibold",children:"Inspeção de Solda"}),k.map((o,i)=>e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg grid grid-cols-3 gap-2 items-center",children:[e.jsx("input",{type:"text",placeholder:`Junta #${i+1}`,className:"col-span-1 p-2 border rounded"}),e.jsxs("select",{className:"col-span-1 p-2 border rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-white border-gray-300 dark:border-gray-600","aria-label":"Status da Solda",title:"Selecione o status da solda",children:[e.jsx("option",{className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:"Aprovado"}),e.jsx("option",{className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:"Reprovado"}),e.jsx("option",{className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:"Pendente"})]}),e.jsx("button",{type:"button",onClick:()=>F(N,o.id),className:"justify-self-end",title:"Remover inspeção de solda",children:e.jsx(P,{className:"w-4 h-4 text-red-500"})})]},o.id)),e.jsxs("button",{type:"button",onClick:()=>{alert("Botão Adicionar Inspeção de Solda clicado!");const o={id:Date.now().toString(),junta:"",status:"pendente"};M(N,o)},className:"w-full text-sm flex items-center justify-center gap-2 py-2 px-4 bg-gray-100 text-gray-700 rounded-xl",children:[e.jsx(V,{className:"w-4 h-4"})," Adicionar Inspeção de Solda"]}),e.jsx("h4",{className:"font-semibold mt-4",children:"Verificação de Torque de Parafusos"}),d.map((o,i)=>e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg grid grid-cols-3 gap-2 items-center",children:[e.jsx("input",{type:"text",placeholder:`Parafuso/Lote #${i+1}`,className:"col-span-1 p-2 border rounded"}),e.jsxs("select",{className:"col-span-1 p-2 border rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-white border-gray-300 dark:border-gray-600","aria-label":"Status do Torque",title:"Selecione o status do torque",children:[e.jsx("option",{className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:"Conforme"}),e.jsx("option",{className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:"Não Conforme"})]}),e.jsx("button",{type:"button",onClick:()=>F(g,o.id),className:"justify-self-end",title:"Remover verificação de torque",children:e.jsx(P,{className:"w-4 h-4 text-red-500"})})]},o.id)),e.jsxs("button",{type:"button",onClick:()=>{alert("Botão Adicionar Verificação de Torque clicado!");const o={id:Date.now().toString(),parafuso:"",torque_aplicado:0,status:"conforme"};M(g,o)},className:"w-full text-sm flex items-center justify-center gap-2 py-2 px-4 bg-gray-100 text-gray-700 rounded-xl",children:[e.jsx(V,{className:"w-4 h-4"})," Adicionar Verificação de Torque"]})]})}),e.jsx(E,{title:"Mão de Obra",icon:ue,section:"maoObra",count:R.length}),e.jsx(q,{children:f.maoObra&&e.jsxs(I.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},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 space-y-4",children:[R.map(o=>e.jsxs("div",{className:"p-3 bg-gray-50 dark:bg-gray-700/50 rounded-lg grid grid-cols-4 gap-2 items-center",children:[e.jsxs("select",{className:"col-span-2 p-2 border rounded bg-white dark:bg-gray-700 text-gray-900 dark:text-white border-gray-300 dark:border-gray-600","aria-label":"Função da Mão de Obra",title:"Selecione a função",children:[e.jsx("option",{value:"",disabled:!0,className:"text-gray-500 dark:text-gray-400",children:"Selecione a função"}),r.map(i=>e.jsx("option",{value:i.nome,className:"bg-white dark:bg-gray-700 text-gray-900 dark:text-white",children:i.nome},i.id))]}),e.jsx("input",{type:"number",placeholder:"Qtd",className:"p-2 border rounded"}),e.jsx("button",{type:"button",onClick:()=>F(D,o.id),className:"justify-self-end",title:"Remover mão de obra",children:e.jsx(P,{className:"w-4 h-4 text-red-500"})})]},o.id)),e.jsxs("button",{type:"button",onClick:()=>M(D,{id:Date.now().toString(),funcao:"",quantidade:1,horas:8}),className:"w-full flex items-center justify-center gap-2 py-2 px-4 bg-blue-100 text-blue-700 rounded-xl",children:[e.jsx(V,{className:"w-5 h-5"})," Adicionar Mão de Obra"]})]})}),e.jsx(E,{title:"Registros Fotográficos",icon:G,section:"anexos",count:v.length}),e.jsx(q,{children:f.anexos&&e.jsx(I.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},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 space-y-4",children:e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[v.map((o,i)=>e.jsxs("div",{className:"relative group aspect-square rounded-lg overflow-hidden border border-gray-200 dark:border-gray-700",children:[e.jsx("img",{src:URL.createObjectURL(o),alt:`Foto ${i+1}`,className:"w-full h-full object-cover"}),e.jsx("button",{type:"button",onClick:()=>z(y=>y.filter((x,L)=>L!==i)),className:"absolute top-1 right-1 p-1 bg-red-500 rounded-full text-white opacity-0 group-hover:opacity-100 transition-opacity",title:"Remover foto","aria-label":"Remover foto",children:e.jsx(P,{className:"w-4 h-4"})}),e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-black/50 text-white text-xs p-1 truncate",children:o.name})]},i)),e.jsxs("button",{type:"button",onClick:()=>b(!0),className:"flex flex-col items-center justify-center gap-2 aspect-square rounded-lg border-2 border-dashed border-gray-300 dark:border-gray-600 hover:border-blue-500 dark:hover:border-blue-400 text-gray-500 hover:text-blue-500 transition-colors bg-gray-50 dark:bg-gray-800/50",children:[e.jsx(G,{className:"w-8 h-8"}),e.jsx("span",{className:"text-sm font-medium",children:"Tirar Foto"})]})]})})}),e.jsxs("div",{className:"flex gap-4 pt-4",children:[e.jsxs("button",{type:"button",className:"flex-1 py-3 px-4 rounded-xl bg-gray-600 text-white hover:bg-gray-700 flex items-center justify-center gap-2",children:[e.jsx(ge,{className:"w-5 h-5"})," Salvar Rascunho"]}),e.jsxs("button",{type:"submit",className:"flex-1 py-3 px-4 rounded-xl bg-blue-600 text-white hover:bg-blue-700 flex items-center justify-center gap-2",children:[e.jsx(me,{className:"w-5 h-5"})," Enviar RDO"]})]})]}),m&&e.jsx(ve,{onCapture:o=>{z(i=>[...i,o]),b(!1)},onClose:()=>b(!1)})]})}export{Fe as default};