1import{a0 as k,a5 as q,r as l,d as f,j as e,I as v,f as b,a7 as A,B as D,g as y}from"./index-FWKSGZPO.js";import{C as o,c as x}from"./card-DTQVPU97.js";import{S as R}from"./save-BrOyRopU.js";function B(){const w=k(),{data:n,isLoading:S}=q(),[r,C]=l.useState(()=>new Date().toISOString().slice(0,10)),[m,_]=l.useState({}),[L,j]=l.useState(!0),[h,p]=l.useState({}),[g,N]=l.useState(null),I=async s=>{const t=h[s];if(t==null)return;N(s);const{error:a}=await f.from("locations").update({total_spots:t}).eq("id",s);if(N(null),a){y.error("Falha ao salvar",{description:a.message});return}y.success("Vagas atualizadas"),p(d=>{const{[s]:c,...u}=d;return u}),w.invalidateQueries({queryKey:["tiers"]})};l.useEffect(()=>{j(!0),f.from("bookings").select("location_id,start_date,end_date,status").lte("start_date",r).gte("end_date",r).in("status",["confirmed","pending"]).then(({data:s})=>{const t={};for(const a of s??[]){const d=a.location_id;t[d]=(t[d]??0)+1}_(t),j(!1)})},[r]);const i=l.useMemo(()=>{const s={total:0,used:0};for(const t of n??[])s.total+=t.total_spots||0,s.used+=m[t.id]||0;return s},[n,m]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 flex-wrap",children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Vagas"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("label",{className:"text-sm text-muted-foreground",children:"Data"}),e.jsx(v,{type:"date",value:r,onChange:s=>C(s.target.value),className:"w-44"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(o,{children:e.jsxs(x,{className:"p-5",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Capacidade total"}),e.jsx("div",{className:"text-2xl font-bold",children:i.total})]})}),e.jsx(o,{children:e.jsxs(x,{className:"p-5",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Reservadas na data"}),e.jsx("div",{className:"text-2xl font-bold",children:i.used})]})}),e.jsx(o,{children:e.jsxs(x,{className:"p-5",children:[e.jsx("div",{className:"text-sm text-muted-foreground",children:"Livres na data"}),e.jsx("div",{className:"text-2xl font-bold",children:Math.max(i.total-i.used,0)})]})})]}),S||L?e.jsx("div",{className:"flex justify-center py-10",children:e.jsx(b,{className:"h-5 w-5 animate-spin"})}):e.jsx(o,{children:e.jsx(x,{className:"p-0",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-muted/50 text-left",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Local"}),e.jsx("th",{className:"p-3",children:"Aeroporto"}),e.jsx("th",{className:"p-3",children:"Tier"}),e.jsx("th",{className:"p-3 text-right",children:"Total"}),e.jsx("th",{className:"p-3 text-right",children:"Reservadas"}),e.jsx("th",{className:"p-3 text-right",children:"Livres"}),e.jsx("th",{className:"p-3",children:"Ocupação"})]})}),e.jsxs("tbody",{children:[(n??[]).map(s=>{const t=m[s.id]??0,a=h[s.id]??s.total_spots??0,d=Math.max(a-t,0),c=a?Math.min(100,Math.round(t/a*100)):0,u=c>=90?"bg-destructive":c>=70?"bg-amber-500":"bg-emerald-500";return e.jsxs("tr",{className:"border-t",children:[e.jsx("td",{className:"p-3 font-medium",children:s.name}),e.jsx("td",{className:"p-3",children:s.airport_code}),e.jsx("td",{className:"p-3",children:A[s.category]??s.category}),e.jsx("td",{className:"p-3 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(v,{type:"number",value:a,onChange:M=>p(E=>({...E,[s.id]:Number(M.target.value)})),className:"h-8 w-20 text-right text-sm"}),e.jsx(D,{size:"sm",variant:"outline",disabled:h[s.id]==null||g===s.id,onClick:()=>I(s.id),children:g===s.id?e.jsx(b,{className:"h-3 w-3 animate-spin"}):e.jsx(R,{className:"h-3 w-3"})})]})}),e.jsx("td",{className:"p-3 text-right",children:t}),e.jsx("td",{className:"p-3 text-right",children:d}),e.jsxs("td",{className:"p-3 w-48",children:[e.jsx("div",{className:"h-2 w-full rounded-full bg-muted",children:e.jsx("div",{className:`h-2 rounded-full ${u}`,style:{width:`${c}%`}})}),e.jsxs("div",{className:"mt-1 text-xs text-muted-foreground",children:[c,"%"]})]})]},s.id)}),(n??[]).length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"p-6 text-center text-muted-foreground",children:"Sem locais cadastrados."})})]})]})})})]})}export{B 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.