import{u as Q,j as e,m as P,r as s,A as _}from"./vendor-CIGJ9g2q.js";import{P as z}from"./page-transition-BW0vKBw7.js";import{B as R}from"./button-DVA8JUsJ.js";import{I as B}from"./input-BR9BBPrf.js";import{c as M,u as U,b as D,L as H}from"./index-C-2a0Dur.js";import{C as O,a as q}from"./card-nJeJbIly.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 F=[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]],G=M("search",F),J=t=>!t||typeof t!="string"?"bg-gray-500":{active:"bg-green-500",on_hold:"bg-purple-500",limited:"bg-red-500",expired:"bg-yellow-500",disabled:"bg-gray-500",unsuccessful:"bg-red-500"}[t]||"bg-gray-500";function K({service:t,index:i,lastServiceElementRef:l,isLastElement:x}){const o=J(t.status),d=Q();return e.jsx(P.div,{ref:x?l:null,initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},transition:{duration:.3,delay:i*.05,type:"spring",stiffness:100},children:e.jsx(O,{className:"overflow-hidden hover:shadow-md transition-shadow",children:e.jsx(q,{className:"p-4",children:e.jsxs("div",{className:"flex items-center justify-between",dir:"rtl",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("div",{className:"relative h-10 w-10 flex items-center justify-center bg-neutral-100 dark:bg-neutral-800 rounded-full",children:[e.jsx("div",{className:`absolute -top-1 -left-1 h-3 w-3 rounded-full ${o}`,children:e.jsx("span",{className:`absolute inset-0 rounded-full ${o} animate-ping opacity-75`})}),e.jsx("span",{className:"text-lg font-semibold",children:t.username.charAt(0).toUpperCase()})]}),e.jsxs("div",{className:"text-right",children:[e.jsx("h3",{className:"font-bold text-lg",children:t.username||"نام کاربری"}),e.jsxs("p",{className:"text-muted-foreground",children:["تاریخ انقضا: ",t.expire||"نامشخص"]}),e.jsx("p",{className:"text-muted-foreground",children:t.note?`یادداشت: ${t.note}`:""})]})]}),e.jsx(R,{variant:"secondary",size:"sm",className:"whitespace-nowrap cursor-pointer",onClick:()=>d(`/services/${t.username}`),children:"جزئیات"})]})})})},`${t.username}-${i}`)}function se(){const{user:t,logout:i}=U(),[l,x]=s.useState([]),[o,d]=s.useState(!1),[w,j]=s.useState(null),[h,y]=s.useState(1),[p,b]=s.useState(!0),[g,C]=s.useState(""),[v,E]=s.useState(""),u=s.useRef(null),m=s.useRef(null),c=s.useRef(!1),f=s.useCallback(async(n,a,N=!1)=>{var k;if(!c.current)if(c.current=!0,d(!0),j(null),t!=null&&t.id)try{const r=await D(t==null?void 0:t.id,n,5,a);r.status?(x(N?r.obj:$=>{const T=new Set($.map(S=>S.username)),A=r.obj.filter(S=>!T.has(S.username));return[...$,...A]}),b(r.meta.currentPage<r.meta.totalPages)):j(r.msg||"خطا در دریافت سرویس‌ها")}catch(r){typeof r=="object"&&r!==null&&"response"in r&&typeof r.response=="object"&&((k=r.response)==null?void 0:k.status)===403?i():(j("خطا در ارتباط با سرور"),console.error(r))}finally{d(!1),c.current=!1}else d(!1),c.current=!1},[t==null?void 0:t.id,i]),I=s.useCallback(n=>{const a=n.target.value;C(a),m.current&&clearTimeout(m.current),m.current=setTimeout(()=>{E(a),y(1),b(!0),f(1,a,!0)},500)},[f]),L=s.useCallback(n=>{c.current||(u.current&&u.current.disconnect(),u.current=new IntersectionObserver(a=>{a[0].isIntersecting&&p&&!c.current&&y(N=>N+1)},{threshold:.5}),n&&u.current.observe(n))},[p]);return s.useEffect(()=>{t!=null&&t.id&&f(1,"",!0)},[t==null?void 0:t.id]),s.useEffect(()=>{h>1&&p&&!c.current&&f(h,v,!1)},[h]),s.useEffect(()=>{},[v,g]),s.useEffect(()=>()=>{u.current&&u.current.disconnect(),m.current&&clearTimeout(m.current)},[]),e.jsx(z,{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.jsxs("div",{className:"relative mb-6 max-w-md mx-auto",children:[e.jsx("div",{className:"absolute inset-y-0 right-3 flex items-center pointer-events-none",children:e.jsx(G,{className:"h-4 w-4 text-muted-foreground"})}),e.jsx(B,{type:"text",className:"pr-9 text-right",placeholder:"جستجوی سرویس‌ها...",value:g,onChange:I})]}),w&&e.jsx("div",{className:"bg-destructive/10 text-destructive p-4 rounded-md mb-4 max-w-md mx-auto text-right",children:w}),e.jsx("div",{className:"space-y-4 max-w-md mx-auto",children:e.jsx(_,{children:l.map((n,a)=>e.jsx(K,{service:n,index:a,lastServiceElementRef:L,isLastElement:a===l.length-1},`${n.username}-${a}`))})}),o&&e.jsx("div",{className:"flex justify-center items-center py-4",children:e.jsxs(P.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"flex items-center gap-2",children:[e.jsx(H,{className:"h-5 w-5 animate-spin text-primary"}),e.jsx("span",{children:"در حال بارگذاری سرویس‌های بیشتر..."})]})}),!o&&l.length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-muted-foreground",children:"هیچ سرویسی یافت نشد"}),g&&e.jsx(R,{variant:"outline",className:"mt-4 bg-transparent",onClick:()=>{C(""),E(""),y(1),b(!0),f(1,"",!0)},children:"پاک کردن جستجو"})]}),!o&&!p&&l.length>0&&h!==1&&e.jsx("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"سرویس بیشتری برای نمایش وجود ندارد"})]})})}export{se as default};
