import{r as o,j as e,m as f}from"./vendor-CIGJ9g2q.js";import{c,u as j,t as w,f as k}from"./index-C-2a0Dur.js";import{P as m}from"./page-transition-BW0vKBw7.js";import{B as h}from"./button-DVA8JUsJ.js";import{C as u,b as g,c as b,a as N}from"./card-nJeJbIly.js";import{u as _,C as p,a as C,R as A}from"./use-copy-CVXJQEWW.js";import{U as z}from"./user-mg4Hsar6.js";import{S as E}from"./shopping-bag-Bz4mjJdB.js";import{C as M}from"./circle-alert-DZHB7FtA.js";import"./ui-BeEpfTFY.js";/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const $=[["path",{d:"m15.477 12.89 1.515 8.526a.5.5 0 0 1-.81.47l-3.58-2.687a1 1 0 0 0-1.197 0l-3.586 2.686a.5.5 0 0 1-.81-.469l1.514-8.526",key:"1yiouv"}],["circle",{cx:"12",cy:"8",r:"6",key:"1vp47v"}]],S=c("award",$);/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const I=[["rect",{width:"20",height:"14",x:"2",y:"5",rx:"2",key:"ynyp8z"}],["line",{x1:"2",x2:"22",y1:"10",y2:"10",key:"1b3vmo"}]],y=c("credit-card",I);/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const H=[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]],U=c("file-text",H);/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const P=[["path",{d:"M13.832 16.568a1 1 0 0 0 1.213-.303l.355-.465A2 2 0 0 1 17 15h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2A18 18 0 0 1 2 4a2 2 0 0 1 2-2h3a2 2 0 0 1 2 2v3a2 2 0 0 1-.8 1.6l-.468.351a1 1 0 0 0-.292 1.233 14 14 0 0 0 6.392 6.384",key:"9njp5v"}]],T=c("phone",P);/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const q=[["path",{d:"M12.586 2.586A2 2 0 0 0 11.172 2H4a2 2 0 0 0-2 2v7.172a2 2 0 0 0 .586 1.414l8.704 8.704a2.426 2.426 0 0 0 3.42 0l6.58-6.58a2.426 2.426 0 0 0 0-3.42z",key:"vktsd0"}],["circle",{cx:"7.5",cy:"7.5",r:".5",fill:"currentColor",key:"kqv944"}]],B=c("tag",q);/**
 * @license lucide-react v0.511.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const L=[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["path",{d:"M16 3.128a4 4 0 0 1 0 7.744",key:"16gr8j"}],["path",{d:"M22 21v-2a4 4 0 0 0-3-3.87",key:"kshegd"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}]],R=c("users",L),F=({userData:a})=>{var x,i;const{copyToClipboard:l}=_(),[n,r]=o.useState(!1),{user:s}=j(),d=async(t,v)=>{await l(t),w.success(v)};return e.jsx(f.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3},className:"mb-6",children:e.jsxs(u,{children:[e.jsx(g,{className:"pb-2",children:e.jsx(b,{className:"text-xl text-center pb-3",children:"اطلاعات شخصی"})}),e.jsx(N,{children:e.jsxs("div",{className:"flex flex-col md:flex-row items-center gap-6",children:[e.jsx("div",{className:"relative h-24 w-24 flex items-center justify-center bg-neutral-100 dark:bg-neutral-800 rounded-full",children:!n&&(s!=null&&s.photo_url)?e.jsx("img",{src:typeof(s==null?void 0:s.photo_url)=="string"?s.photo_url:void 0,alt:(s==null?void 0:s.username)||"تصویر کاربر",className:"rounded-full h-full w-full object-cover",onError:()=>{r(!0)}}):e.jsx("span",{className:"text-2xl font-semibold",children:((x=s==null?void 0:s.first_name)==null?void 0:x.charAt(0))||((i=s==null?void 0:s.username)==null?void 0:i.charAt(0))||"U"})}),e.jsxs("div",{className:"flex-1 space-y-3 text-right w-full",children:[e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"نام:"})]}),e.jsx("span",{children:`${(s==null?void 0:s.first_name)??""} ${(s==null?void 0:s.last_name)??""}`})]}),e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"شناسه کاربری:"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{children:s==null?void 0:s.id}),e.jsx(h,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>d(String((s==null?void 0:s.id)??""),"شناسه کاربری کپی شد"),children:e.jsx(p,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"کد معرف:"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{dir:"ltr",children:a.codeInvitation}),e.jsx(h,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",onClick:()=>d(a.codeInvitation,"کد معرف کپی شد"),children:e.jsx(p,{className:"h-3 w-3"})})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(T,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"شماره تماس:"})]}),e.jsx("span",{className:"text-red-500",children:(a==null?void 0:a.phone)||"ارسال نشده است"})]}),e.jsxs("div",{className:"flex items-center justify-between border-b pb-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"زمان ثبت نام:"})]}),e.jsx("span",{children:a.time_join})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(S,{className:"h-4 w-4 text-muted-foreground"}),e.jsx("span",{className:"text-muted-foreground",children:"گروه کاربری:"})]}),e.jsx("span",{children:a.group_type})]})]})]})})]})})},V=({userData:a})=>{const balance=Number(a.balance??0);return e.jsx(f.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.3,delay:.1},className:"mb-6",children:e.jsxs(u,{children:[e.jsx(g,{className:"pb-2",children:e.jsx(b,{className:"text-xl text-right pb-3",children:"آمار حساب"})}),e.jsx(N,{children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[(()=>{const l=balance>5e5?"text-green-600 dark:text-green-400":balance>0?"text-yellow-600 dark:text-yellow-400":"text-red-600 dark:text-red-400",n=balance>5e5?"bg-green-100 dark:bg-green-900/30":balance>0?"bg-yellow-100 dark:bg-yellow-900/30":"bg-red-100 dark:bg-red-900/30";return e.jsxs("div",{className:"bg-neutral-100 dark:bg-neutral-800 p-4 rounded-lg flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`p-2 rounded-full ${n}`,children:e.jsx(y,{className:`h-5 w-5 ${l}`})}),e.jsx("span",{children:"موجودی:"})]}),e.jsxs("span",{className:`font-bold ${l}`,children:[balance.toLocaleString("fa-IR")," تومان"]})]})})(),e.jsxs("div",{className:"bg-neutral-100 dark:bg-neutral-800 p-4 rounded-lg flex items-center justify-between",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-full",children:e.jsx(E,{className:"h-5 w-5 text-blue-600 dark:text-blue-400"})}),e.jsx("span",{className:"text-sm",children:"سرویس‌های خریداری شده:"})]}),e.jsxs("span",{className:"font-bold",children:[a.count_order," عدد"]})]}),e.jsxs("div",{className:"bg-neutral-100 dark:bg-neutral-800 p-4 rounded-lg flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-purple-100 dark:bg-purple-900/30 rounded-full",children:e.jsx(U,{className:"h-5 w-5 text-purple-600 dark:text-purple-400"})}),e.jsx("span",{children:"فاکتورهای پرداخت شده:"})]}),e.jsxs("span",{className:"font-bold",children:[a.count_payment," عدد"]})]}),e.jsxs("div",{className:"bg-neutral-100 dark:bg-neutral-800 p-4 rounded-lg flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 bg-yellow-100 dark:bg-yellow-900/30 rounded-full",children:e.jsx(R,{className:"h-5 w-5 text-yellow-600 dark:text-yellow-400"})}),e.jsx("span",{children:"زیرمجموعه‌ها:"})]}),e.jsxs("span",{className:"font-bold",children:[a.affiliatescount," نفر"]})]})]})})]})});};function ee(){const{user:a}=j(),[l,n]=o.useState(!0),[r,s]=o.useState(null),[d,x]=o.useState({codeInvitation:"",balance:0,phone:"",count_order:0,count_payment:0,group_type:"",time_join:"",affiliatescount:""}),i=async()=>{try{n(!0),s(null);const t=await k(a==null?void 0:a.id);if(!t||!t.obj)throw new Error("اطلاعات کاربری یافت نشد");x(t.obj)}catch(t){console.error("Error fetching user data:",t),t instanceof Error?s(t.message):s("خطا در دریافت اطلاعات کاربری")}finally{n(!1)}};return o.useEffect(()=>{i()},[a==null?void 0:a.id]),r?e.jsx(m,{children:e.jsx("div",{className:"container mx-auto px-4 py-8 font-vazir",children:e.jsxs("div",{className:"flex flex-col items-center justify-center min-h-[60vh]",children:[e.jsx("div",{className:"bg-red-100 dark:bg-red-900/20 text-red-600 dark:text-red-400 p-4 rounded-full mb-4",children:e.jsx(M,{size:48})}),e.jsx("h2",{className:"text-2xl font-bold mb-2",children:"خطا در دریافت اطلاعات"}),e.jsx("p",{className:"text-muted-foreground mb-6 text-center max-w-md",children:r}),e.jsxs(h,{onClick:i,className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-4 w-4"}),"تلاش مجدد"]})]})})}):l?e.jsx(m,{children:e.jsx("div",{className:"container mx-auto px-4 py-8 font-vazir",children:e.jsx("div",{className:"flex flex-col items-center justify-center min-h-[60vh]",children:e.jsxs("div",{className:"animate-pulse space-y-4 w-full max-w-md",children:[e.jsx("div",{className:"h-12 bg-neutral-200 dark:bg-neutral-700 rounded-md w-3/4 mx-auto"}),e.jsx("div",{className:"h-32 bg-neutral-200 dark:bg-neutral-700 rounded-md"}),e.jsx("div",{className:"h-64 bg-neutral-200 dark:bg-neutral-700 rounded-md"})]})})})}):e.jsx(m,{children:e.jsxs("div",{className:"container mx-auto px-4 py-8 mb-16 font-vazir",children:[e.jsx("h1",{className:"text-4xl font-bold mb-8 text-center",children:"حساب کاربری"}),e.jsx(F,{userData:d}),e.jsx(V,{userData:d})]})})}export{ee as default};
