1import{u as P,l as N,j as e,P as _,S as $,b as M,k as F}from"./index--siChAZm.js";import{u as V,r as g}from"./react-vendor-B-clOVnp.js";import{a1 as H,a as A,J as q,r as O,t as J,p as U,c as G}from"./icons-BCLA8W0j.js";const K={pendente_orquestracao:{label:"Pendente",cor:"#f59e0b"},ativa:{label:"Ativa",cor:"#10b981"},encerrada:{label:"Encerrada",cor:"#64748b"},cancelada:{label:"Cancelada",cor:"#ef4444"}};function E(t){return t?new Date(t).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"2-digit"}):""}function ee(){const{token:t}=P(),n=V(),[r,x]=g.useState([]),[i,f]=g.useState(!0),[c,u]=g.useState(""),[y,j]=g.useState(null),[p,R]=g.useState("ativas");g.useEffect(()=>{t&&(f(!0),N(t).then(a=>{x(Array.isArray(a)?a:[]),u("")}).catch(()=>u("Não foi possÃvel carregar as escalas.")).finally(()=>f(!1)))},[t]);async function B(){try{const a=await N(t);x(Array.isArray(a)?a:[]),u("")}catch{u("Não foi possÃvel carregar as escalas.")}finally{f(!1)}}async function I(a,s){if(a.preventDefault(),a.stopPropagation(),!!await M("Cancelar esta escala para todos?")){j(s);try{await F(t,s),await B()}catch(o){alert(o.message)}finally{j(null)}}}const v=a=>["cancelada","encerrada","rejeitada"].includes(a.status),S=r.filter(a=>!v(a)),C=r.filter(v),k=p==="ativas"?S:C,T=k.reduce((a,s)=>{const o=s.contratanteId||s.empresaId||"sem-empresa",d=s.contratanteNome||s.empresaNome||"Sem empresa";return a[o]||(a[o]={empresaId:o,empresa:d,escalas:[]}),a[o].escalas.push(s),a},{}),z=Object.values(T).sort((a,s)=>a.empresa.localeCompare(s.empresa));return e.jsxs("div",{style:{maxWidth:820,margin:"0 auto",padding:"0 4px"},children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",marginBottom:20,gap:12},children:[e.jsxs("div",{children:[e.jsx("h1",{style:{margin:"0 0 4px",fontSize:18,fontWeight:800,color:"#0f172a"},children:"Escalas"}),e.jsx("p",{style:{margin:0,fontSize:13,color:"#64748b"},children:i?"Carregando...":`${r.length} escala${r.length!==1?"s":""} cadastrada${r.length!==1?"s":""}`})]}),e.jsxs("button",{onClick:()=>n("/assessor/criar-escala"),style:{display:"inline-flex",alignItems:"center",gap:6,background:"#031D44",color:"#fff",border:"none",borderRadius:9,padding:"9px 16px",fontSize:13,fontWeight:700,cursor:"pointer",whiteSpace:"nowrap",flexShrink:0,boxShadow:"0 2px 8px rgba(3,29,68,.22)",transition:"opacity 0.15s"},onMouseEnter:a=>a.currentTarget.style.opacity="0.87",onMouseLeave:a=>a.currentTarget.style.opacity="1",children:[e.jsx(H,{size:14})," Nova Escala"]})]}),!i&&!c&&r.length>0&&e.jsx("div",{style:{display:"flex",gap:4,marginBottom:18,padding:4,background:"#f1f5f9",borderRadius:10,width:"fit-content"},children:[{id:"ativas",label:"Ativas e pendentes",count:S.length},{id:"canceladas",label:"Canceladas e encerradas",count:C.length}].map(a=>e.jsxs("button",{type:"button",onClick:()=>R(a.id),style:{padding:"8px 14px",borderRadius:8,border:"none",cursor:"pointer",fontSize:13,fontWeight:700,background:p===a.id?"#fff":"transparent",color:p===a.id?"#031D44":"#64748b",boxShadow:p===a.id?"0 1px 3px rgba(0,0,0,0.08)":"none"},children:[a.label,e.jsx("span",{style:{marginLeft:6,fontSize:11,padding:"1px 7px",borderRadius:10,background:p===a.id?"#031D44":"#cbd5e1",color:p===a.id?"#fff":"#475569"},children:a.count})]},a.id))}),i&&e.jsx(_,{variant:"grid",qtd:3,cols:1}),!i&&c&&e.jsx("div",{style:{textAlign:"center",padding:"40px 0",color:"#ef4444"},children:e.jsx("p",{style:{margin:0,fontSize:14},children:c})}),!i&&!c&&r.length===0&&e.jsxs("div",{style:{textAlign:"center",padding:"48px 0",color:"#94a3b8"},children:[e.jsx(A,{size:36,style:{marginBottom:10,opacity:.35}}),e.jsx("p",{style:{margin:0,fontSize:14},children:"Nenhuma escala cadastrada ainda."}),e.jsx("button",{onClick:()=>n("/assessor/criar-escala"),style:{marginTop:16,background:"#031D44",color:"#fff",border:"none",borderRadius:9,padding:"9px 20px",fontSize:13,fontWeight:700,cursor:"pointer"},children:"Criar primeira escala"})]}),!i&&!c&&r.length>0&&k.length===0&&e.jsxs("div",{style:{textAlign:"center",padding:"48px 0",color:"#94a3b8"},children:[e.jsx(A,{size:36,style:{marginBottom:10,opacity:.35}}),e.jsx("p",{style:{margin:0,fontSize:14},children:p==="ativas"?"Nenhuma escala ativa ou pendente.":"Nenhuma escala cancelada ou encerrada."})]}),!i&&!c&&z.length>0&&e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:28},children:z.map(a=>e.jsxs("section",{children:[e.jsxs("button",{onClick:()=>n(`/assessor/contratante/${a.empresaId}`),style:{display:"flex",alignItems:"center",gap:8,width:"100%",background:"none",border:"none",padding:"0 0 10px",cursor:"pointer",borderBottom:"2px s
1olid #031D44",marginBottom:10,textAlign:"left"},children:[e.jsx("div",{style:{width:28,height:28,borderRadius:7,background:"#031D44",display:"flex",alignItems:"center",justifyContent:"center",flexShrink:0},children:e.jsx(q,{size:14,color:"#fff"})}),e.jsx("span",{style:{fontWeight:800,fontSize:14,color:"#031D44",flex:1},children:a.empresa}),e.jsxs("span",{style:{fontSize:11,color:"#94a3b8",fontWeight:500},children:[a.escalas.length," escala",a.escalas.length!==1?"s":""]}),e.jsx(O,{size:14,color:"#94a3b8"})]}),e.jsx("div",{style:{display:"flex",flexDirection:"column",gap:10},children:a.escalas.map(s=>{const o=K[s.status]||{label:s.status,cor:"#94a3b8"},d=s.dias?.length||0,w=s.dias?.filter(l=>l.freelancerId&&["confirmado","trabalhado","finalizado"].includes(l.status)).length||0,m=d>0?Math.round(w/d*100):0,W=(Number(s.valorDiaria)||0)*(Number(s.vagas)||0)*d,D=Q(s.horarioInicio,s.horarioFim),L=D>0?(Number(s.valorDiaria)||0)/D:0;return e.jsxs("div",{onClick:()=>n(`/escalas/${s._id}`),style:{background:"#fff",border:"1px solid #e2e8f0",borderRadius:14,padding:"16px 18px",boxShadow:"0 1px 4px rgba(0,0,0,0.06)",cursor:"pointer",transition:"box-shadow 0.15s"},onMouseEnter:l=>l.currentTarget.style.boxShadow="0 4px 14px rgba(3,29,68,.12)",onMouseLeave:l=>l.currentTarget.style.boxShadow="0 1px 4px rgba(0,0,0,0.06)",children:[e.jsxs("div",{style:{display:"flex",alignItems:"flex-start",justifyContent:"space-between",gap:8},children:[e.jsxs("div",{style:{flex:1},children:[e.jsx("span",{style:{fontWeight:700,fontSize:14,color:"#0f172a"},children:s.funcao}),e.jsxs("div",{style:{display:"flex",gap:12,marginTop:5,fontSize:12,color:"#94a3b8",flexWrap:"wrap"},children:[e.jsxs("span",{children:[e.jsx(J,{size:11,style:{verticalAlign:"middle",marginRight:2}}),E(s.dataInicio)," â ",E(s.dataFim)]}),s.endereco&&e.jsxs("span",{children:[e.jsx(U,{size:11,style:{verticalAlign:"middle",marginRight:2}}),s.endereco]})]})]}),e.jsx("span",{style:{fontSize:11,fontWeight:700,padding:"3px 9px",borderRadius:99,background:o.cor+"18",color:o.cor,whiteSpace:"nowrap",flexShrink:0},children:o.label})]}),d>0&&e.jsxs("div",{style:{marginTop:14},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",fontSize:12,color:"#64748b",marginBottom:5},children:[e.jsx("span",{children:"Dias preenchidos"}),e.jsxs("span",{style:{fontWeight:700},children:[w," / ",d]})]}),e.jsx("div",{style:{height:6,background:"#f1f5f9",borderRadius:99,overflow:"hidden"},children:e.jsx("div",{style:{height:"100%",borderRadius:99,width:`${m}%`,background:m===100?"#10b981":m>=50?"#031D44":"#f59e0b",transition:"width 0.3s"}})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(160px, 1fr))",gap:10,marginTop:14},children:[e.jsx(h,{label:"Total de dias",value:`${d}`}),e.jsx(h,{label:"Valor por diária",value:b(s.valorDiaria)}),e.jsx(h,{label:"Total da escala",value:b(W)}),e.jsx(h,{label:"Valor por hora",value:b(L)})]}),e.jsxs("div",{style:{display:"flex",gap:8,marginTop:12,justifyContent:"flex-end",flexWrap:"wrap"},children:[e.jsxs("button",{className:"btn btn-secondary btn-sm",onClick:l=>{l.stopPropagation(),n(`/escalas/${s._id}`)},children:[e.jsx(G,{size:14}),"Ver detalhes"]}),s.status!=="cancelada"&&e.jsx("button",{className:"btn btn-danger btn-sm",onClick:l=>I(l,s._id),disabled:y===s._id,style:{display:"inline-flex",alignItems:"center",gap:6},children:y===s._id?e.jsxs(e.Fragment,{children:[e.jsx($,{size:14})," Cancelandoâ¦"]}):"Cancelar"})]})]},s._id)})})]},a.empresaId))}),e.jsx("style",{children:` 2 @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } 3 `})]})}function Q(t,n){if(!t||!n)return 0;const[r,x]=String(t).split(":").map(Number),[i,f]=String(n).split(":").map(Number);if([r,x,i,f].some(Number.isNaN))return 0;const c=i*60+f-(r*60+x);return c>0?c/60:0}function b(t){return(Number(t)||0).toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}function h({label:t,value:n}){return e.jsxs("div",{style:{padding:"10px 12px",borderRadius:12,background:"#f8fafc",border:"1px solid #e2e8f0"},children:[e.jsx("div",{style:{fontSize:11,color:"#64748b",marginBottom:4},children:t}),e.jsx("div",{style:{fontSize:14,fontWeight:800,color:"#0f172a"},children:n})]})}export{ee as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.