1import{u as Me,fw as Le,as as A,ae as G,Y as Ee,r as d,B as te,cx as Oe,dj as ae,cK as ne,w as de,e7 as oe,j as r,T as le,V as Se,L as v,aM as Te,m as Ie,cw as b,a1 as Ae,ad as w}from"./index-B29x19vy.js";import{I as Ge}from"./input-DlI5hdWK.js";import{C as Pe}from"./CategorySidebar-C93mORAH.js";import{b as Fe}from"./useOrders-CAG7KzoZ.js";import{u as De}from"./useOrderUnread-CI49YmcE.js";import{M as ce,O as qe,S as Be,N as Ve,B as $e,a as Ue}from"./BMCatalog-D-BFDOfR.js";import"./categoryIcons-C0gqmBE7.js";import"./ClaudeIcon-ChfFkQMx.js";import"./tag-BJ6GvW45.js";import"./filter-BgMTjCWL.js";import"./card-DQJgYeUh.js";import"./badge-DY9NB_ci.js";import"./tabs-rCK9TmoK.js";import"./MobileCategoryFlyout-BSEoP2q9.js";import"./chevrons-right-YSUJ5mRv.js";import"./serviceLinks-CLQrAwD3.js";import"./WalletTrigger-0dHdGigP.js";import"./useProducts-RfX_7PvA.js";import"./UnifiedOrderCard-BbFDJBlK.js";import"./circle-check-big-Bf3_DD3q.js";import"./truck-BZ7qSGvF.js";import"./index-DLoVuXKm.js";import"./index-9BqJAWWA.js";import"./chevron-up-CDA9uoHs.js";import"./euro-HdxgOg6I.js";import"./banknote-BE8IakVv.js";import"./layout-grid--6B1Y24e.js";import"./coins-DdUDFfyw.js";import"./smmPlatform-34tCK8Z5.js";import"./createReactComponent-CIt0eOV3.js";const M=[{key:"all",label:"Todos"},{key:"active",label:"Em andamento"},{key:"completed",label:"ConcluÃdos"},{key:"cancelled",label:"Cancelados"}],ie=["pending","paid","shipped"],ue=["delivered"],me=["cancelled","refunded"],Ke=["pending"],Qe=["completed"],Re=["failed","cancelled","refunded"],We=["pending","processing","in_progress","partial"],ze=["completed"],Ye=["cancelled","failed","refunded"],He=["waiting","received"],Je=["completed","finished"],Xe=["cancelled","timeout","banned"],xe=["awaiting_payment","paid","alfa_pending","alfa_paid"],Ze=["delivered"],er=["refunded","failed","expired"],pe=["pending","in_review"],rr=["approved"],sr=["rejected","cancelled","refunded"],tr=15*60*1e3;function ge(t){var i,p,u;const l=((i=t.items)==null?void 0:i.find(y=>!y.is_upsell))||((p=t.items)==null?void 0:p[0]);return!l||(((u=t.items)==null?void 0:u.length)||0)!==1||(Number(l.quantity)||1)!==1?null:[t.buyer_id,t.store_id,t.status,t.payment_status,t.payment_method,l.product_id,l.unit_price].join("|")}function he(t){const l=[];return t.forEach(i=>{const p=ge(i),u=new Date(i.created_at).getTime(),y=p&&l.find(m=>{const L=m[0];return ge(L)===p&&Math.abs(new Date(L.created_at).getTime()-u)<=tr});y?y.push(i):l.push([i])}),l}const Ar=()=>{var ee;const{user:t}=Me(),{data:l=[],isLoading:i}=Fe(),{data:p={}}=De(),{data:u=[],isLoading:y}=Le(),{data:m=[],isLoading:L}=A({queryKey:["my-smm-orders",t==null?void 0:t.id],enabled:!!t,queryFn:async()=>{const{data:e,error:s}=await G.from("smm_orders").select("id, global_order_no, product_title_snapshot, link, quantity, price_paid, price_paid_millicents, payment_method, payment_status, status, created_at").eq("user_id",t.id).order("created_at",{ascending:!1}).limit(50);if(s)throw s;return e||[]},refetchInterval:3e4}),{data:g=[],isLoading:B}=A({queryKey:["my-nv-activations",t==null?void 0:t.id],enabled:!!t,queryFn:async()=>{const{data:e,error:s}=await G.from("virtual_number_activations").select("id, global_order_no, nv_activation_id, service_id, service_name, service_icon, phone, status, sms_code, cost_cents, refunded, created_at").eq("user_id",t.id).order("created_at",{ascending:!1}).limit(100);if(s)throw s;return e||[]},refetchInterval:e=>{const s=e.state.data;return s!=null&&s.some(a=>a.status==="waiting"||a.status==="received")?8e3:3e4}}),{data:_=[],isLoading:fe}=A({queryKey:["my-bm-orders",t==null?void 0:t.id],enabled:!!t,queryFn:async()=>{const{data:e}=await G.functions.invoke("alfa-bm-proxy",{body:{action:"my-orders"}});return(e==null?void 0:e.orders)||[]},refetchInterval:e=>{const s=e.state.data;return(s==null?void 0:s.some(C=>xe.includes(C.status)))?8e3:3e4}}),{data:k=[],isLoading:be}=A({queryKey:["my-g2-orders",t==null?void 0:t.id],enabled:!!t,queryFn:async()=>{const{data:e,error:s}=await G.from("g2_orders").select("*").eq("user_id",t.id).order("created_at",{ascending:!1});if(s)throw s;return e||[]},refetchInterval:e=>{const s=e.state.data;return(s==null?void 0:s.some(C=>pe.includes(C.status)))?1e4:3e4}}),[ye,je]=Ee(),x=ye.get("tab"),V=["marketplace","official","smm","numeros","bm","g2"],Ne=x&&V.includes(x)?x:"official",[c,h]=d.useState("all"),[o,E]=d.use
1State(Ne),[$,P]=d.useState(!!x),[U,ve]=d.useState(""),n=U.trim().toLowerCase(),j=(e,s)=>{var re;if(!s)return!0;const a=s.toLowerCase();return[(e==null?void 0:e.short_id)!=null?String(e.short_id):null,(e==null?void 0:e.short_id)!=null?`#${e.short_id}`:null,e==null?void 0:e.id,(e==null?void 0:e.global_order_no)!=null?String(e.global_order_no):null,(e==null?void 0:e.global_order_no)!=null?`#${e.global_order_no}`:null,e==null?void 0:e.nv_activation_id,e==null?void 0:e.product_title_snapshot,e==null?void 0:e.service_name,e==null?void 0:e.product_title,e==null?void 0:e.title,...((re=e==null?void 0:e.items)==null?void 0:re.map(N=>{var se;return(se=N==null?void 0:N.product)==null?void 0:se.title}))||[]].filter(N=>typeof N=="string").some(N=>N.toLowerCase().includes(a))};d.useEffect(()=>{x&&V.includes(x)&&x!==o&&(E(x),h("all"),P(!0))},[x]);const K=e=>{E(e),h("all"),P(!0),je({tab:e},{replace:!0})},f=d.useMemo(()=>l.filter(e=>{var s;return!((s=e.store)!=null&&s.is_official)}),[l]),T=d.useMemo(()=>l.filter(e=>{var s;return(s=e.store)==null?void 0:s.is_official}),[l]),F=d.useMemo(()=>{const e=n?f.filter(s=>j(s,n)):f;return{all:e,active:e.filter(s=>ie.includes(s.status)),completed:e.filter(s=>ue.includes(s.status)),cancelled:e.filter(s=>me.includes(s.status))}},[f,n]),D=d.useMemo(()=>{const e=n?T.filter(a=>j(a,n)):T,s=n?u.filter(a=>j(a,n)):u;return{all:{orders:e,purchases:s},active:{orders:e.filter(a=>ie.includes(a.status)),purchases:s.filter(a=>Ke.includes(a.status))},completed:{orders:e.filter(a=>ue.includes(a.status)),purchases:s.filter(a=>Qe.includes(a.status))},cancelled:{orders:e.filter(a=>me.includes(a.status)),purchases:s.filter(a=>Re.includes(a.status))}}},[T,u,n]),Q=d.useMemo(()=>{const e=n?m.filter(s=>j(s,n)):m;return{all:e,active:e.filter(s=>We.includes(s.status)),completed:e.filter(s=>ze.includes(s.status)),cancelled:e.filter(s=>Ye.includes(s.status))}},[m,n]),R=d.useMemo(()=>{const e=n?g.filter(s=>j(s,n)):g;return{all:e,active:e.filter(s=>He.includes(s.status)),completed:e.filter(s=>Je.includes(s.status)),cancelled:e.filter(s=>Xe.includes(s.status))}},[g,n]),W=d.useMemo(()=>{const e=n?_.filter(s=>j({...s,short_id:s.bm_order_no,title:s.bm_name},n)):_;return{all:e,active:e.filter(s=>xe.includes(s.status)),completed:e.filter(s=>Ze.includes(s.status)),cancelled:e.filter(s=>er.includes(s.status))}},[_,n]),z=d.useMemo(()=>{const e=n?k.filter(s=>j(s,n)):k;return{all:e,active:e.filter(s=>pe.includes(s.status)),completed:e.filter(s=>rr.includes(s.status)),cancelled:e.filter(s=>sr.includes(s.status))}},[k,n]),q=F[c],_e=d.useMemo(()=>he(q),[q]),O=D[c],ke=d.useMemo(()=>he(O.orders),[O.orders]),Y=Q[c],H=R[c],J=W[c],X=z[c],S=u.length+T.length,Ce=o==="marketplace"?i:o==="smm"?L:o==="numeros"?B:o==="bm"?fe:o==="g2"?be:y||i,Z=i||y||L||B,I=d.useMemo(()=>[{key:"official",label:"Loja Oficial",count:S,icon:te,accentClass:"text-emerald-500"},{key:"marketplace",label:"Marketplace",count:f.length,icon:Oe,accentClass:"text-primary"},{key:"smm",label:"Painel SMM",count:m.length,icon:ae,accentClass:"text-primary"},{key:"numeros",label:"Nº Virtuais",count:g.length,icon:ne,accentClass:"text-accent-foreground"},{key:"bm",label:"BM com Gasto",count:_.length,icon:de,accentClass:"text-[#1877F2]"},{key:"g2",label:"Google G2",count:k.length,icon:oe,accentClass:"text-[#4285F4]"}],[S,f.length,m.length,g.length,_,k]),we=(ee=I.find(e=>e.key===o))==null?void 0:ee.label;return d.useEffect(()=>{$||Z||S>0||(m.length>0?E("smm"):f.length>0?E("marketplace"):g.length>0&&E("numeros"),P(!0))},[Z,S,m.length,f.length,g.length,$]),Ce&&(o==="marketplace"?l.length===0:u.length===0)?r.jsxs("div",{className:"min-h-screen bg-background",children:[r.jsx(le,{}),r.jsx("div",{className:"flex items-center justify-center py-20",children:r.jsx(Se,{className:"h-6 w-6 animate-spin text-primary"})})]}):r.jsxs("div",{className:"min-h-screen bg-background",children:[r.jsx(le,{}),r.jsxs("main",{className:"w-[95%] lg:w-[90%] xl:w-[80%] mx-auto px-0 py-6",children:[r.jsxs(v,{to:"/marketplace",className:"inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground mb-4",children:[r.jsx(Te,{className:"h-4 w-4"})," Marketplace"]}),r.jsxs(Ie.div,{initial:{opacity:0,y:12}
1,animate:{opacity:1,y:0},children:[r.jsxs("h1",{className:"text-xl font-bold text-foreground mb-3 flex items-center gap-2",children:[r.jsx(b,{className:"h-5 w-5"})," Meus Pedidos"]}),r.jsxs("div",{className:"relative mb-4",children:[r.jsx(Ae,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),r.jsx(Ge,{placeholder:"Buscar por #ID, UUID ou produto...",value:U,onChange:e=>ve(e.target.value),className:"pl-9 bg-card border-border"})]}),r.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[240px_minmax(0,1fr)] gap-6",children:[r.jsx("div",{className:"hidden lg:block",children:r.jsx("div",{className:"sticky top-20",children:r.jsx(Pe,{title:"Categorias",hideAll:!0,allLabel:"",items:I,selected:we,onSelect:e=>{const s=I.find(C=>C.label===e),a=s==null?void 0:s.key;a&&K(a)}})})}),r.jsx("div",{className:"lg:hidden flex gap-1 bg-muted rounded-lg p-0.5 overflow-x-auto",children:I.map(e=>r.jsxs("button",{onClick:()=>K(e.key),className:`flex-1 min-w-[110px] text-[10px] sm:text-xs font-medium py-2 sm:py-2.5 rounded-md transition-all flex items-center justify-center gap-1 sm:gap-1.5 ${o===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[r.jsx(e.icon,{className:"h-3.5 w-3.5"}),e.label,e.count>0&&r.jsx("span",{className:"text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full",children:e.count})]},e.key))}),r.jsxs("div",{className:"min-w-0",children:[o==="marketplace"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex gap-1 bg-muted rounded-lg p-0.5 mb-6",children:M.map(e=>r.jsxs("button",{onClick:()=>h(e.key),className:`flex-1 text-[10px] sm:text-xs font-medium py-2 rounded-md transition-all min-w-0 ${c===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.label,F[e.key].length>0&&r.jsx("span",{className:"ml-1.5 text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full",children:F[e.key].length})]},e.key))}),f.length===0?r.jsxs("div",{className:"text-center py-16 bg-card border border-border rounded-xl",children:[r.jsx(b,{className:"h-10 w-10 text-muted-foreground mx-auto mb-3"}),r.jsx("p",{className:"text-muted-foreground",children:"Você ainda não fez nenhum pedido"}),r.jsx(v,{to:"/marketplace",children:r.jsx(w,{variant:"outline",className:"mt-4",children:"Explorar Marketplace"})})]}):q.length===0?r.jsxs("div",{className:"text-center py-12 bg-card border border-border rounded-xl",children:[r.jsx(b,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum pedido nesta categoria"})]}):r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:_e.map(e=>r.jsx(ce,{order:e[0],groupedOrders:e,unreadCount:e.reduce((s,a)=>s+(p[a.id]||0),0)},e.map(s=>s.id).join("-")))})]}),o==="official"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex gap-1 bg-muted rounded-lg p-0.5 mb-6",children:M.map(e=>{const s=D[e.key].orders.length+D[e.key].purchases.length;return r.jsxs("button",{onClick:()=>h(e.key),className:`flex-1 text-xs font-medium py-2 rounded-md transition-all ${c===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.label,s>0&&r.jsx("span",{className:"ml-1.5 text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full",children:s})]},e.key)})}),S===0?r.jsxs("div",{className:"text-center py-16 bg-card border border-border rounded-xl",children:[r.jsx(te,{className:"h-10 w-10 text-muted-foreground mx-auto mb-3"}),r.jsx("p",{className:"text-muted-foreground",children:"Nenhuma compra na Loja Oficial"}),r.jsx(v,{to:"/loja-oficial",children:r.jsx(w,{variant:"outline",className:"mt-4",children:"Ir para Loja Oficial"})})]}):O.orders.length===0&&O.purchases.length===0?r.jsxs("div",{className:"text-center py-12 bg-card border border-border rounded-xl",children:[r.jsx(b,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma compra nesta categoria"})]}):r.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:[ke.map(e=>r.jsx(ce,{order:e[0],groupedOrders:e,unreadCount:e.reduce((s,a)=>s+(p[a.id]||0),0)},e.map(s=>s.id).join("-"))),O.purchases.map(e=>r.jsx(qe,{purchase:e},e.id))]})]}),o==="smm"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex gap-1 bg-muted rounded-lg p-0.5 mb-6",children:M.map(e=>{const s=Q[e.key].length;return r.jsxs("button",{onClick:()=>h(e.key),className:`flex-1 text-xs font-medium py-2 rounded-md transition-all ${c===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.label,s>0&&r.jsx("span",{className:"ml-1.5 text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full",children:s})]},e.key)})}),m.length===0?r.jsxs("div",{className:"text-center py-16 bg-card border border-border rounded-xl",children:[r.jsx(ae,{className:"h-10 w-10 text-muted-foreground mx-auto mb-3"}),r.jsx("p",{className:"text-muted-foreground",children:"Nenhum pedido na Painel SMM"}),r.jsx(v,{to:"/painel-smm",children:r.jsx(w,{variant:"outline",className:"mt-4",children:"Abrir Painel SMM"})})]}):Y.length===0?r.jsxs("div",{className:"text-center py-12 bg-card border border-border rounded-xl",children:[r.jsx(b,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum pedido nesta categoria"})]}):r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:Y.map(e=>r.jsx(Be,{order:e},e.id))})]}),o==="numeros"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex gap-1 bg-muted rounded-lg p-0.5 mb-6",children:M.map(e=>{const s=R[e.key].length;return r.jsxs("button",{onClick:()=>h(e.key),className:`flex-1 text-xs font-medium py-2 rounded-md transition-all ${c===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.label,s>0&&r.jsx("span",{className:"ml-1.5 text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full",children:s})]},e.key)})}),g.length===0?r.jsxs("div",{className:"text-center py-16 bg-card border border-border rounded-xl",children:[r.jsx(ne,{className:"h-10 w-10 text-muted-foreground mx-auto mb-3"}),r.jsx("p",{className:"text-muted-foreground",children:"Nenhum número virtual solicitado"}),r.jsx(v,{to:"/sms",children:r.jsx(w,{variant:"outline",className:"mt-4",children:"Solicitar Número"})})]}):H.length===0?r.jsxs("div",{className:"text-center py-12 bg-card border border-border rounded-xl",children:[r.jsx(b,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum número nesta categoria"})]}):r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:H.map(e=>r.jsx(Ve,{a:e},e.id))})]}),o==="bm"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex gap-1 bg-muted rounded-lg p-0.5 mb-6",children:M.map(e=>{const s=W[e.key].length;return r.jsxs("button",{onClick:()=>h(e.key),className:`flex-1 text-xs font-medium py-2 rounded-md transition-all ${c===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.label,s>0&&r.jsx("span",{className:"ml-1.5 text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full",children:s})]},e.key)})}),_.length===0?r.jsxs("div",{className:"text-center py-16 bg-card border border-border rounded-xl",children:[r.jsx(de,{className:"h-10 w-10 text-muted-foreground mx-auto mb-3"}),r.jsx("p",{className:"text-muted-foreground",children:"Nenhum pedido de BM ainda"}),r.jsx(v,{to:"/contas-com-gasto",children:r.jsx(w,{variant:"outline",className:"mt-4",children:"Ver estoque de BMs"})})]}):J.length===0?r.jsxs("div",{className:"text-center py-12 bg-card border border-border rounded-xl",children:[r.jsx(b,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum pedido nesta categoria"})]}):r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:J.map(e=>r.jsx($e,{o:e},e.id))})]}),o==="g2"&&r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"flex gap-1 bg-muted rounded-lg p-0.5 mb-6",children:M.map(e=>{const s=z[e.key].length;return r.jsxs("button",{onClick:()=>h(e.key),className:`flex-1 text-xs font-medium py-2 rounded-md transition-all ${c===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.label,s>0&&r.jsx("span",{className:"ml-1.5 text-[10px] bg-primary/10 text-primary px-1.5 py-0.5 rounded-full",children:s})]},e.key)})}),k.length===0?r.jsxs("div",{className:"text-center py-16 bg-card border border-border rounded-xl",children:[r.jsx(oe,{className:"h-10 w-10 mx-auto mb-3"}),r.jsx("p",{className:"text-muted-foreground",children:"Nenhuma liberação G2 ainda"}),r.jsx(v,{to:"/liberacao-g2",children:r.jsx(w,{variant:"outline",className:"mt-4",children:"Solicitar liberação G2"})})]}):X.length===0?r.jsxs("div",{className:"text-center py-12 bg-card border border-border rounded-xl",children:[r.jsx(b,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),r.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhum pedido nesta categoria"})]}):r.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-3",children:X.map(e=>r.jsx(Ue,{order:e},e.id))})]})]})]})]})]})]})};export{Ar 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.