1import{c as Z,n as ee,r as m,s as k,j as e,m as L,B as x,h as se,L as b}from"./index-CWJ-XTna.js";import{D as ae}from"./DashboardLayout-D3_1jWvB.js";import{I as te}from"./input-Dctq5cvL.js";import{T as le,a as re,b as ie,c as u,d as ne,e as p}from"./table-BhPadfIG.js";import{S as R,a as I,b as B,c as P,d as n,C as O}from"./select-BIWRZzEu.js";import{S as oe}from"./search-B9tfCcvZ.js";import{P as ce}from"./plus-C5XMo8wr.js";import{P as U}from"./pencil-BwRFu1Nt.js";import{C as H}from"./chevron-down-CAdUPOQ7.js";import"./use-mobile-BNKwfm0U.js";import"./triangle-alert-CGtwFhMA.js";import"./loader-circle-BVd4I_gm.js";import"./user-plus-BUcaUJZ3.js";import"./chart-column-2lRxiU-0.js";import"./globe-DsqqBd51.js";import"./ticket-B9XKSI7n.js";import"./index-B6RwP5Dn.js";const de=Z("ChevronsUpDown",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]),S={published:{label:"Publicado",class:"badge-published"},draft:{label:"Rascunho",class:"badge-draft"},finished:{label:"Finalizado",class:"badge-finished"},cancelled:{label:"Cancelado",class:"badge-finished"},encerrado:{label:"Encerrado",class:"badge-finished"}},g=o=>o.status==="draft"?!1:new Date(o.start_date)<new Date;function Ee(){const{user:o}=ee(),[N,Q]=m.useState([]),[J,K]=m.useState(!0),[E,V]=m.useState(""),[f,$]=m.useState("all"),[v,q]=m.useState("all"),[w,F]=m.useState("date"),[y,z]=m.useState("asc"),W=[...new Set(N.map(s=>s.location_name).filter(s=>!!s))];m.useEffect(()=>{o&&X()},[o]);const X=async()=>{try{const{data:s,error:a}=await k.from("events").select("*").eq("user_id",o?.id).order("created_at",{ascending:!1});if(a)throw a;let i=[];if(o?.email){const{data:r}=await k.from("event_collaborators").select("event_id, role").eq("email",o.email).eq("status","accepted");if(r&&r.length>0){const T=r.map(d=>d.event_id),c=new Set((s||[]).map(d=>d.id)),G=T.filter(d=>!c.has(d));if(G.length>0){const{data:d}=await k.from("events").select("*").in("id",G);if(d){const Y=new Map(r.map(j=>[j.event_id,j.role]));i=d.map(j=>({...j,isCollaborator:!0,collaboratorRole:Y.get(j.id)}))}}}}const t=[...s||[],...i],l=t.map(r=>r.id);let h={};if(l.length>0){const{data:r,error:T}=await k.from("tickets").select("event_id, quantity, quantity_sold").in("event_id",l);!T&&r&&r.forEach(c=>{h[c.event_id]||(h[c.event_id]={sold:0,total:0}),h[c.event_id].sold+=c.quantity_sold,h[c.event_id].total+=c.quantity})}Q(t.map(r=>({...r,tickets_sold:h[r.id]?.sold||0,tickets_total:h[r.id]?.total||0})))}catch(s){console.error("Error fetching events:",s)}finally{K(!1)}},C=s=>{w===s?z(a=>a==="asc"?"desc":"asc"):(F(s),z("asc"))},_=({col:s})=>w!==s?e.jsx(de,{size:14,className:"text-muted-foreground/50"}):y==="asc"?e.jsx(O,{size:14,className:"text-primary"}):e.jsx(H,{size:14,className:"text-primary"}),D=N.filter(s=>{const a=s.name.toLowerCase().includes(E.toLowerCase()),i=g(s),t=f==="all"||f==="encerrado"&&i||!i&&s.status===f,l=v==="all"||s.location_name===v;return a&&t&&l}).sort((s,a)=>{const i=g(s),t=g(a);if(i&&!t)return 1;if(!i&&t)return-1;const l=y==="asc"?1:-1;switch(w){case"status":return l*(s.status||"").localeCompare(a.status||"","pt-BR");case"name":return l*(s.name||"").localeCompare(a.name||"","pt-BR");case"date":return l*(new Date(s.start_date).getTime()-new Date(a.start_date).getTime());case"location":return l*(s.location_name||"").localeCompare(a.location_name||"","pt-BR");default:return 0}}),M=s=>new Date(s).toLocaleDateString("pt-BR",{day:"2-digit",month:"2-digit",year:"numeric"}),A={gerente:"Gerente",checkin:"Check-in",visualizacao:"Visualização",coordenador_checkin:"Coord. Check-In",pdv:"PDV",auditor:"Auditor"};return e.jsx(ae,{children:e.jsxs(L.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.4},className:"space-y-6",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("h1",{className:"font-heading text-xl lg:text-2xl font-bold",children:"Meus Eventos"})}),e.jsxs("div",{className:"flex flex-col sm:flex-row sm:flex-wrap gap-2 sm:gap-4 bg-card p-3 sm:p-4 rounded-xl border border-border",children:[e.jsxs("div",{className:"flex-1 min-w-0 sm:min-w-[200px]",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1 hidden sm:block",children:"Buscar pelo nome do evento"}),e.jsxs("div",{className:"relative",children:[e.jsx(oe,{className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground",size:18}),e.jsx(te,{placeholder:"Buscar pelo nome do evento",value:E,onChange:s=>V(s.target.value),className:"pl-10"})]})]}),e.jsxs("div",{className:"grid grid-cols-2 sm:flex gap-2 sm:gap-3",children:[e.jsxs("div",{className:"min-w-0 sm:min-w-[140px]",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1 hidden sm:block",children:"Filtrar por"}),e.jsxs(R,{value:f,onValueChange:$,children:[e.jsx(I,{className:"w-full sm:w-[180px]",children:e.jsx(B,{placeholder:"Todos os eventos"})}),e.jsxs(P,{children:[e.jsx(n,{value:"all",children:"Todos os eventos"}),e.jsx(n,{value:"published",children:"Publicado"}),e.jsx(n,{value:"draft",children:"Rascunho"}),e.jsx(n,{value:"finished",children:"Finalizado"}),e.jsx(n,{value:"encerrado",children:"Encerrado"})]})]})]}),e.jsxs("div",{className:"min-w-0 sm:min-w-[140px]",children:[e.jsx("p",{className:"text-xs text-muted-foreground mb-1 hidden sm:block",children:"Cidade"}),e.jsxs(R,{value:v,onValueChange:q,children:[e.jsx(I,{className:"w-full sm:w-[180px]",children:e.jsx(B,{placeholder:"Todas as cidades"})}),e.jsxs(P,{children:[e.jsx(n,{value:"all",children:"Todas as cidades"}),W.map(s=>e.jsx(n,{value:s,children:s},s))]})]})]})]}),(E||f!=="all"||v!=="all")&&e.jsx("div",{className:"flex sm:items-end",children:e.jsx(x,{variant:"outline",size:"sm",className:"w-full sm:w-auto
1sm:h-10",onClick:()=>{V(""),$("all"),q("all")},children:"Limpar filtros"})})]}),e.jsx("div",{className:"bg-card rounded-xl border border-border overflow-hidden",children:J?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-t-2 border-b-2 border-wine"})}):D.length===0?e.jsxs("div",{className:"text-center py-12 px-4",children:[e.jsx(se,{size:48,className:"mx-auto text-muted-foreground/50 mb-4"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:N.length===0?"Você ainda não criou nenhum evento.":"Nenhum evento encontrado com os filtros aplicados."}),N.length===0&&e.jsx(b,{to:"/dashboard/eventos/criar",children:e.jsxs(x,{variant:"wine",children:[e.jsx(ce,{size:18}),"Criar primeiro evento"]})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"hidden md:block",children:e.jsxs(le,{children:[e.jsx(re,{children:e.jsxs(ie,{className:"bg-muted/50",children:[e.jsx(u,{className:"font-heading font-semibold cursor-pointer select-none hover:text-primary transition-colors",onClick:()=>C("status"),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:["Status ",e.jsx(_,{col:"status"})]})}),e.jsx(u,{className:"font-heading font-semibold cursor-pointer select-none hover:text-primary transition-colors",onClick:()=>C("name"),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:["Evento ",e.jsx(_,{col:"name"})]})}),e.jsx(u,{className:"font-heading font-semibold cursor-pointer select-none hover:text-primary transition-colors",onClick:()=>C("date"),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:["Quando ",e.jsx(_,{col:"date"})]})}),e.jsx(u,{className:"font-heading font-semibold cursor-pointer select-none hover:text-primary transition-colors",onClick:()=>C("location"),children:e.jsxs("span",{className:"inline-flex items-center gap-1",children:["Onde ",e.jsx(_,{col:"location"})]})}),e.jsx(u,{className:"font-heading font-semibold",children:"Ingressos"}),e.jsx(u,{className:"font-heading font-semibold text-right",children:"Ações"})]})}),e.jsx(ne,{children:D.map((s,a)=>{const i=s.tickets_total>0?s.tickets_sold/s.tickets_total*100:0,t=g(s),l=t?"encerrado":s.status;return e.jsxs(L.tr,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{delay:a*.03},className:`group hover:bg-muted/30 transition-colors ${t?"opacity-60":""}`,children:[e.jsx(p,{children:e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:S[l]?.class||"badge-draft",children:S[l]?.label||l}),s.isCollaborator&&e.jsx("span",{className:"text-xs text-primary font-medium",children:A[s.collaboratorRole||""]||"Colaborador"})]})}),e.jsx(p,{children:e.jsx("p",{className:"font-medium truncate max-w-[250px]",children:s.name})}),e.jsx(p,{children:e.jsx("span",{className:"text-muted-foreground",children:M(s.start_date)})}),e.jsx(p,{children:e.jsx("span",{className:"text-muted-foreground",children:s.location_name||"â"})}),e.jsx(p,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-20 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-emerald-500 rounded-full transition-all",style:{width:`${Math.min(i,100)}%`}})}),e.jsx("span",{className:"text-sm font-medium",children:s.tickets_sold}),e.jsxs("span",{className:"text-xs text-muted-foreground",children:["/ ",s.tickets_total]})]})}),e.jsx(p,{className:"text-right",children:e.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[e.jsx(b,{to:`/dashboard/eventos/${s.id}`,children:e.jsx(x,{variant:"outline",size:"sm",children:t?"Ver detalhes":"Gerenciar"})}),!t&&!s.isCollaborator&&e.jsx(b,{to:`/dashboard/eventos/${s.id}/editar`,children:e.jsx(x,{variant:"ghost",size:"sm",children:e.jsx(U,{size:14})})})]})})]},s.id)})})]})}),e.jsxs("div",{className:"md:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5 border-b border-border bg-muted/30",children:[e.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:"Ordenar por:"}),e.jsxs(R,{value:w,onValueChange:s=>F(s),children:[e.jsx(I,{className:"h-8 text-xs flex-1",children:e.jsx(B,{})}),e.jsxs(P,{children:[e.jsx(n,{value:"date",children:"Data"}),e.jsx(n,{value:"name",children:"Nome"}),e.jsx(n,{value:"status",children:"Status"}),e.jsx(n,{value:"location",children:"Local"})]})]}),e.jsx(x,{variant:"outline",size:"sm",className:"h-8 px-2 shrink-0",onClick:()=>z(s=>s==="asc"?"desc":"asc"),"aria-label":y==="asc"?"Crescente":"Decrescente",children:y==="asc"?e.jsx(O,{size:14}):e.jsx(H,{size:14})})]}),e.jsx("div",{className:"divide-y divide-border",children:D.map((s,a)=>{const i=s.tickets_total>0?s.tickets_sold/s.tickets_total*100:0,t=g(s),l=t?"encerrado":s.status;return e.jsxs(L.div,{initial:{opacity:0,y:10}
1,animate:{opacity:1,y:0},transition:{delay:a*.03},className:`p-4 ${t?"opacity-60":""}`,children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"font-semibold text-sm break-words",children:s.name}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[M(s.start_date),s.location_name&&` · ${s.location_name}`]})]}),e.jsxs("div",{className:"flex flex-col items-end gap-1 shrink-0",children:[e.jsx("span",{className:S[l]?.class||"badge-draft",children:S[l]?.label||l}),s.isCollaborator&&e.jsx("span",{className:"text-[10px] text-primary font-medium",children:A[s.collaboratorRole||""]||"Colaborador"})]})]}),e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("div",{className:"flex-1 h-2 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-emerald-500 rounded-full transition-all",style:{width:`${Math.min(i,100)}%`}})}),e.jsxs("span",{className:"text-xs font-medium whitespace-nowrap",children:[s.tickets_sold,"/",s.tickets_total," ingressos"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(b,{to:`/dashboard/eventos/${s.id}`,className:"flex-1",children:e.jsx(x,{variant:"outline",size:"sm",className:"w-full",children:t?"Ver detalhes":"Gerenciar"})}),!t&&!s.isCollaborator&&e.jsx(b,{to:`/dashboard/eventos/${s.id}/editar`,children:e.jsx(x,{variant:"ghost",size:"sm",className:"px-3",children:e.jsx(U,{size:14})})})]})]},s.id)})})]})]})})]})})}export{Ee as default}; 2//# sourceMappingURL=DashboardPage-CgUAkJXc.js.map
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.