1import{r as f,j as e,L as w}from"./vendor-react-NDqzZ9RJ.js";import{b as T,u as z,s as p,R as D,a4 as R,c as v,am as U,U as A,S as P}from"./index-CoM1tmaP.js";import{C as $}from"./card-D0q8Xmsf.js";import{L as F}from"./skeletons-dfB27sMM.js";import{E as H}from"./EmptyState-Cs8aH_0B.js";import{B as K}from"./BackButton-nzMyGzSx.js";import{L as q}from"./lock-BOkQOGsu.js";import{B as G}from"./ban-DdZJn98F.js";import"./vendor-pdf-DcnCMWs_.js";import"./vendor-charts-BLT5JiYK.js";import"./vendor-tiptap-BiZ4HMKr.js";import"./skeleton-CkFNS2xE.js";import"./arrow-left-CRn4fcxS.js";function O(c,h){if(!c)return"â";const t=new Date(c),l=Date.now()-t.getTime(),m=6e4;return l<m?"az önce":l<60*m?`${Math.floor(l/m)} dk`:l<1440*m?`${Math.floor(l/(60*m))} sa`:l<10080*m?`${Math.floor(l/(1440*m))} gün`:t.toLocaleDateString(h,{day:"numeric",month:"short"})}function Q(c,h){if(!c)return"Henüz mesaj yok";const t=h?`${h}: `:"";return c.kind==="audio"?`${t}ð¤ Sesli mesaj`:c.kind==="image"?`${t}ð¼ï¸ Görsel`:`${t}${c.body??""}`}function oe(){const{t:c,i18n:h}=T(),{user:t}=z(),[l,m]=f.useState(null),[y,N]=f.useState({}),[g,C]=f.useState({}),[j,L]=f.useState(""),[b,B]=f.useState("all"),E=h.language==="tr"?"tr-TR":h.language==="ar"?"ar":"en-US";f.useEffect(()=>{if(!(typeof window>"u"||!("Notification"in window))&&Notification.permission==="default")try{Notification.requestPermission().catch(()=>{})}catch{}},[]);const I=(a,i,r)=>{if(!(typeof window>"u"||!("Notification"in window))&&Notification.permission==="granted"&&!(!document.hidden&&window.location.pathname.startsWith(`/sohbet/${a.thread_id}`))&&!(t&&a.sender_id===t.id))try{const n=a.kind==="text"?a.body??"":a.kind==="audio"?"ð¤ Sesli mesaj":"ð¼ï¸ Görsel",s=new Notification(i,{body:n.slice(0,140),icon:r??"/icon-192.png",tag:`chat-${a.thread_id}`});s.onclick=()=>{window.focus(),window.location.href=`/sohbet/${a.thread_id}`,s.close()}}catch{}},M=async()=>{var S;const{data:a}=await p.from("chat_threads").select("id, customer_id, teller_id, last_message_at, is_closed, blocked_by_customer, blocked_by_teller").order("last_message_at",{ascending:!1,nullsFirst:!1}).limit(100),i=a??[];if(m(i),!i.length||!t)return;const r=i.map(o=>o.id),{data:n}=await p.from("chat_messages").select("thread_id, sender_id, kind, body, created_at, read_at").in("thread_id",r).order("created_at",{ascending:!1}).limit(500),s={};for(const o of n??[])s[o.thread_id]||(s[o.thread_id]=o);N(s);const d=Array.from(new Set(i.map(o=>o.teller_id))),[u,x]=await Promise.all([p.rpc("get_chat_peers",{_thread_ids:r}),p.from("fortune_tellers_public").select("user_id, display_name, avatar_url").in("user_id",d)]),_={};for(const o of u.data??[])_[o.peer_id]={id:o.peer_id,name:o.peer_name??"Kullanıcı",avatar:o.peer_avatar??null};for(const o of x.data??[])!o.user_id||!o.display_name||(_[o.user_id]={id:o.user_id,name:o.display_name,avatar:o.avatar_url??((S=_[o.user_id])==null?void 0:S.avatar)??null});C(_)};f.useEffect(()=>{if(!t)return;M();const a=p.channel("sohbetler-live").on("postgres_changes",{event:"INSERT",schema:"public",table:"chat_messages"},i=>{const r=i.new;N(s=>({...s,[r.thread_id]:r})),m(s=>{if(!s)return s;const d=s.findIndex(x=>x.id===r.thread_id);if(d<0)return s;const u=[...s];return u[d]={...u[d],last_message_at:r.created_at},u.sort((x,_)=>(_.last_message_at??"").localeCompare(x.last_message_at??"")),u});const n=l==null?void 0:l.find(s=>s.id===r.thread_id);if(n&&t){const s=n.customer_id===t.id?n.teller_id:n.customer_id,d=g[s];I(r,(d==null?void 0:d.name)??"Yeni mesaj",(d==null?void 0:d.avatar)??null)}}).on("postgres_changes",{event:"UPDATE",schema:"public",table:"chat_threads"},i=>{const r=i.new;m(n=>(n==null?void 0:n.map(s=>s.id===r.id?{...s,...r}:s))??n)}).subscribe();return()=>{p.removeChannel(a)}},[t==null?void 0:t.id]);const k=f.useMemo(()=>{if(!l||!t)return l;const a=j.trim().toLowerCase();return l.filter(i=>{const r=i.customer_id===t.id?i.teller_id:i.customer_id,n=g[r],s=y[i.id],d=i.customer_id===t.id&&i.blocked_by_customer||i.teller_id===t.id&&i.blocked_by_teller,u=!!s&&s.sender_id!==t.id&&!s.read_at;return b==="unread"&&!u||b==="closed"&&!i.is_closed||b==="blocked"&&!d?!1:a?`${(n==null?void 0:n.name)??""} ${(s==null?void 0:s.body)??""}`.toLowerCase().includes(a):!0})},[l,y,g,j,b,t==null?void 0:t.id]);return e.jsxs("div",{className:"container mx-auto px-4 py-6 max-w-2xl",children:[e.jsx(K,{}),e.jsxs("h1",{className:"text-2xl font-bold mb-4 text-primary",children:["ð¬ ",c("chat.myChats")]}),e.jsxs("div",{className:"relative mb-3",children:[e.jsx(D,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-muted-foreground"}),e.jsx(R,{value:j,onChange:a=>L(a.target.value),placeholder:"Ara: isim veya mesaj",className:"pl-9"})]}),e.jsx("div",{className:"flex gap-2 mb-3 overflow-x-auto pb-1",children:[["all","Tümü"],["unread","OkunmamıÅ"],["closed","Kapalı"],["blocked","Bloklu"]].map(([a,i])=>e.jsx("button",{onClick:()=>B(a),className:v("px-3 py-1.5 rounded-full text-xs font-medium border transition whitespace-nowrap",b===a?"bg-primary text-primary-foreground border-primary":"bg-transparent border-border hover:bg-accent"),children:i},a))}),l===null?e.jsx(F,{count:4}):(l??[]).length===0?e.jsxs($,{className:"p-6 text-center flex flex-col items-center gap-4",children:[e.jsx("div",{className:"w-16 h-16 rounded-full bg-gradient-to-br from-primary/20 to-fuchsia-500/20 flex items-center justify-center",children:e.jsx(U,{className:"w-8 h-8 text-primary"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-lg",children:"Henüz sohbetin yok"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Bir falcıyla mesajlaÅarak baÅla â kahve, tarot, rüya veya aÅk falı için birebir yorum al."})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2 w-full",children:[e.jsxs(w,{to:"/falcilar",className:"flex items-center gap-3 p-3 rounded-xl border border-primary/40 bg-primary/5 hover:bg-primary/10 transition text-left",children:[e.jsx(A,{className:"w-5 h-5 text-primary shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold",children:"Falcılara göz at"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Onaylı falcıları keÅfet"})]})]}),e.jsxs(w,{to:"/uzman-falcilar",className:"flex items-center gap-3 p-3 rounded-xl border border-fuchsia-500/40 bg-fuchsia-500/5 hover:bg-fuchsia-500/10 transition text-left",children:[e.jsx(P,{className:"w-5 h-5 text-fuchsia-500 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-semibold",children:"Uzman falcılar"}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:"Deneyimli isimlerle konuÅ"})]})]})]})]}):(k??[]).length===0?e.jsx(H,{title:c("chat.empty"),description:c("chat.emptyDesc")}):(k??[]).map(a=>{const i=a.customer_id===(t==null?void 0:t.id)?a.teller_id:a.customer_id,r=g[i],n=y[a.id],s=!!n&&n.sender_id!==(t==null?void 0:t.id)&&!n.read_at,d=a.customer_id===(t==null?void 0:t.id)&&a.blocked_by_customer||a.teller_id===(t==null?void 0:t.id)&&a.blocked_by_teller,u=n&&n.sender_id===(t==null?void 0:t.id);return e.jsx(w,{to:`/sohbet/${a.id}`,children:e.jsxs($,{className:v("p-3 mb-2 flex items-center gap-3 hover:bg-accent transition",s&&"border-primary/50 bg-primary/5"),children:[e.jsx("div",{className:"w-11 h-11 rounded-full bg-gradient-to-br from-primary/20 to-fuchsia-500/20 flex items-center justify-center text-lg font-semibold overflow-hidden shrink-0",children:r!=null&&r.avatar?e.jsx("img",{src:r.avatar,alt:"",className:"w-full h-full object-cover"}):e.jsx("span",{children:((r==null?void 0:r.name)??"?").charAt(0).toUpperCase()})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex justify-between items-center gap-2",children:[e.jsx("div",{className:"text-sm font-semibold truncate",children:(r==null?void 0:r.name)??"Kullanıcı"}),e.jsx("div",{className:"text-[10px] text-muted-foreground shrink-0",children:O(a.last_message_at,E)})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[e.jsx("p",{className:v("text-xs truncate flex-1",s?"font-semibold text-foreground":"text-muted-foreground"),children:Q(n,u?"Sen":void 0)}),s&&e.jsx("span",{className:"w-2 h-2 rounded-full bg-primary shrink-0"}),a.is_closed&&e.jsx(q,{className:"w-3 h-3 text-muted-foreground shrink-0"}),d&&e.jsx(G,{className:"w-3 h-3 text-destructive shrink-0"})]})]})]})},a.id)})]})}export{oe 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.