1import{_ as oe}from"./DuTdilBw.js";import{e as le,a7 as ie,p as g,g as de,as as ce,f as L,s as ue,c as o,a as e,i as s,k as R,l as x,b as l,m as E,F as b,r as k,n as m,t as u,w as fe,a4 as q,a2 as F,d as G,j as xe,_ as me,o as r,Z as pe,q as v,a8 as A}from"./CkpukmhO.js";import{_ as he}from"./LD-2PJAR.js";import{_ as ge}from"./CHVPS9kP.js";import{u as H}from"./DulI2fsf.js";const be={class:"flex h-[calc(100vh-65px)] overflow-hidden"},ve={class:"px-4 py-4 border-b border-gray-100"},ye={class:"flex items-center justify-between mb-3"},_e={class:"flex items-center gap-2"},we={key:0,class:"flex-1 p-3 space-y-2 overflow-y-auto"},ke={key:1,class:"flex-1 flex flex-col items-center justify-center p-6 text-center"},Ce={key:2,class:"flex-1 overflow-y-auto"},De=["onClick"],$e={class:"relative shrink-0"},Ne={class:"w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-700 font-bold text-sm"},ze={key:0,class:"absolute -top-0.5 -right-0.5 w-3 h-3 bg-green-500 rounded-full border-2 border-white"},je={class:"flex-1 min-w-0"},Me={class:"flex items-center justify-between"},Te={class:"text-sm font-semibold text-gray-900 truncate"},Ve={class:"text-[10px] text-gray-400 shrink-0 ml-1"},Ae={class:"text-xs text-gray-400 truncate mt-0.5"},Pe={key:0,class:"mt-1"},Ue={key:0,class:"flex-1 flex flex-col items-center justify-center text-center p-8"},Be={class:"w-16 h-16 rounded-2xl bg-gray-100 flex items-center justify-center mb-4"},Se={class:"bg-white border-b border-gray-200 px-4 md:px-6 py-4 shrink-0"},Ie={class:"flex items-center justify-between"},Le={class:"flex items-center gap-3"},Re={class:"w-10 h-10 rounded-full bg-green-100 flex items-center justify-center text-green-700 font-bold"},Ee={class:"text-sm font-bold text-gray-900"},qe={class:"flex items-center gap-2 mt-0.5 flex-wrap"},Fe={class:"text-xs text-gray-400"},Ge={key:0,class:"flex gap-1 flex-wrap"},He={class:"flex items-center gap-2"},Ke={key:0,class:"w-8 h-8 rounded-full bg-gray-200 shrink-0"},We={key:0,class:"w-7 h-7 rounded-full bg-gray-200 flex items-center justify-center text-xs font-bold text-gray-600 shrink-0 mb-1"},Je={class:"max-w-[80%] md:max-w-xs"},Oe={key:0,class:"ml-1"},Qe={key:0,class:"mx-3 md:mx-4 mb-3 rounded-xl overflow-hidden border border-purple-200 shrink-0"},Ye={class:"bg-gradient-to-r from-purple-50 to-blue-50 px-4 py-3"},Ze={class:"flex items-center justify-between mb-2"},Xe={class:"flex items-center gap-2"},et={class:"w-5 h-5 rounded-full bg-purple-600 flex items-center justify-center"},tt={class:"text-sm text-gray-700 leading-relaxed"},st={class:"flex gap-2 mt-3 flex-wrap"},nt={class:"bg-white border-t border-gray-200 px-4 py-3 shrink-0"},at={class:"flex items-end gap-2 md:gap-3"},ft=le({__name:"index",async setup(rt){let p,C;const K=ie(),D=g(""),i=g(K.query.id??null),f=g(""),z=g(!1),$=g(),y=g(!1);de(()=>{y.value=window.innerWidth<768;const a=()=>{y.value=window.innerWidth<768};window.addEventListener("resize",a),ce(()=>window.removeEventListener("resize",a))});const{data:W,pending:J,refresh:P}=([p,C]=L(()=>H("/api/conversations","$iWwDMsoEJ2")),p=await p,C(),p),{data:O,pending:Q,refresh:U}=([p,C]=L(()=>H(()=>i.value?`/api/conversations/${i.value}/messages`:null,"$G4RyhSDAQz")),p=await p,C(),p),N=v(()=>W.value??[]),B=v(()=>{const a=D.value.toLowerCase();return a?N.value.filter(n=>(n.subscriberName??"").toLowerCase().includes(a)||(n.phoneNumber??"").includes(a)):N.value}),S=v(()=>N.value.filter(a=>a.aiDraftPending).length),c=v(()=>N.value.find(a=>a.id===i.value)??null),I=v(()=>O.value??[]),_=v(()=>c.value?.aiDraft??null);function Y(a){i.value=a.id,U(),A(()=>M())}function Z(){i.value=null}function j(a){return(a?.subscriberName??a?.phoneNumber??"S")[0].toUpperCase()}function X(a){if(!a)return"";const n=Date.now()-new Date(a).getTime(),h=Math.floor(n/6e4);if(h<1)return"now";if(h<60)return`${h}m`;const d=Math.floor(h/60);return d<24?`${d}h`:`${Math.floor(d/24)}d`}function ee(a){return a?new Date(a).toLocaleTimeString("en-NG",{hour:"2-digit",minute:"2-digit"}):""}function M(){$.value&&($.value.scrollTop=$.value.scrollHeight)}async function T(){if(!(!f.value.trim()||!i.value)){z.value=!0;try{await $fetch(`/api/conversations/${i.value}/messages`,{method:"POST",body:{body:f.value}}),f.value="",await U(),A(()=>M())}catch(a){console.error(a)}finally{z.value=!1}}}async function te(){!i.value||!_.value||(f.value=_.value,await T(),V())}function se(){f.value=_.value??""}function V(){i.value&&($fetch(`/api/conversations/${i.value}`,{method:"PATCH",body:{aiDraftPending:!1}}).catch(()=>{}),P())}return ue(I,()=>{A(()=>M())}),(a,n)=>{const h=oe,d=xe,ne=he,w=pe,ae=me,re=ge;return r(),o("div",be,[e("div",{class:m(["bg-white border-r border-gray-200 flex flex-col shrink-0 transition-all",[s(y)&&s(i)?"hidden":"flex","w-full md:w-80"]])},[e("div",ve,[e("div",ye,[e("div",_e,[n[3]||(n[3]=e("h3",{class:"text-sm font-bold text-gray-900"},"Inbox",-1)),s(S)>0?(r(),R(h,{key:0,label:`${s(S)}`,color:"success",variant:"solid",size:"xs"},null,8,["label"])):x("",!0)]),l(d,{size:"xs",color:"neutral",variant:"ghost",icon:"i-lucide-refresh-cw",onClick:n[0]||(n[0]=t=>s(P)())})]),l(ne,{modelValue:s(D),"onUpdate:modelValue":n[1]||(n[1]=t=>E(D)?D.value=t:null),placeholder:"Search conversations...",icon:"i-lucide-search",size:"sm",class:"w-full"},null,8,["modelValue"])]),s(J)?(r(),o("div",we,[(r(),o(b,null,k(6,t=>e("div",{key:t,class:"flex gap-3 p-2 animate-pulse"},[...n[4]||(n[4]=[e("div",{class:"w-10 h-10 rounded-full bg-gray-100 shrink-0"},null,-1),e("div",{class:"flex-1 space-y-2"},[e("div",{class:"h-3 bg-gray-100 rounded w-28"}),e("div",{class:"h-2.5 bg-gray-100 rounded w-full"})],-1)])])),64))])):s(B).length?(r(),o("div",Ce,[(r(!0),o(b,null,k(s(B),t=>(r(),o("button",{key:t.id,class:m(["w-full flex items-start gap-3 px-4 py-3.5 border-b border-gray-50 hover:bg-gray-50 transition-colors text-left relative",s(i)===t.id?"bg-green-50 border-l-2 border-l-green-600 pl-3.5":"border-l-2 border-l-transparent"]),onClick:ot=>Y(t)},[e("div",$e,[e("div",Ne,u(j(t)),1),t.aiDraftPending?(r(),o("span",ze)):x("",!0)]),e("div",je,[e("div",Me,[e("p",Te,u(t.subscriberName??t.phoneNumber),1),e("span",Ve,u(X(t.lastMessageAt)),1)]),e("p",Ae,u(t.lastMessage),1),t.aiDraftPending?(r(),o("div",Pe,[...n[7]||(n[7]=[e("span",{class:"text-[10px] text-purple-600 font-medium bg-purple-50 px-1.5 py-0.5 rounded-full"},"AI draft ready",-1)])])):x("",!0)])],10,De))),128))])):(r(),o("div",ke,[l(w,{name:"i-lucide-inbox",class:"w-10 h-10 text-gray-300 mb-3"}),n[5]||(n[5]=e("p",{class:"text-sm font-medium text-gray-500"},"No conversations",-1)),n[6]||(n[6]=e("p",{class:"text-xs text-gray-400 mt-1"},"Replies from subscribers will appear here",-1))]))],2),e("div",{class:m(["flex-1 flex-col overflow-hidden",s(y)&&!s(i)?"hidden":"flex"])},[s(c)?(r(),o(b,{key:1},[e("div",Se,[e("div",Ie,[e("div",Le,[s(y)?(r(),o("button",{key:0,class:"text-gray-400 hover:text-gray-600 transition-colors mr-1",onClick:Z},[l(w,{name:"i-lucide-arrow-left",class:"w-5 h-5"})])):x("",!0),e("div",Re,u(j(s(c))),1),e("div",null,[e("p",Ee,u(s(c).subscriberName??s(c).phoneNumber),1),e("div",qe,[e("p",Fe,u(s(c).phoneNumber),1),s(c).tags?.length?(r(),o("div",Ge,[(r(!0),o(b,null,k(s(c).tags,t=>(r(),R(h,{key:t,label:t,size:"xs",color:"neutral",variant:"subtle"},null,8,["label"]))),128))])):x("",!0)])])]),e("div",He,[l(ae,{to:`/dashboard/subscribers?search=${s(c).phoneNumber}`},{default:fe(()=>[l(d,{size:"xs",color:"neutral",variant:"outline",icon:"i-lucide-user",label:"Profile",class:"hidden sm:flex"}),l(d,{size:"xs",color:"neutral",variant:"outline",icon:"i-lucide-user",class:"sm:hidden"})]),_:1},8,["to"])])])]),e("div",{ref_key:"messagesContainer",ref:$,class:"flex-1 overflow-y-auto px-4 md:px-6 py-4 space-y-3 bg-gray-50"},[s(Q)?(r(),o(b,{key:0},k(4,t=>e("div",{key:t,class:m(["flex gap-2 animate-pulse",t%2===0?"justify-end":""])},[t%2!==0?(r(),o("div",Ke)):x("",!0),e("div",{class:m(`h-10 rounded-xl w-48 ${t%2===0?"bg-green-100":"bg-white"}`)},null,2)],2)),64)):(r(!0),o(b,{key:1},k(s(I),t=>(r(),o("div",{key:t.id,class:m(["flex items-end gap-2",t.direction==="outbound"?"justify-end":"justify-start"])},[t.direction==="inbound"?(r(),o("div",We,u(j(s(c))),1)):x("",!0),e("div",Je,[e("div",{class:m(["rounded-2xl px-3.5 py-2.5 text-sm leading-relaxed",t.direction==="outbound"?"bg-green-600 text-white rounded-br-sm":"bg-white text-gray-800 border border-gray-200 rounded-bl-sm shadow-sm"])},u(t.body),3),e("p",{class:m(["text-[10px] text-gray-400 mt-1",t.direction==="outbound"?"text-right":"text-left"])},[G(u(ee(t.createdAt))+" ",1),t.direction==="outbound"?(r(),o("span",Oe,[l(w,{name:t.status==="delivered"?"i-lucide-check-check":"i-lucide-check",class:m(["w-3 h-3 inline",t.status==="delivered"?"text-green-400":"text-gray-400"])},null,8,["name","class"])])):x("",!0)],2)])],2))),128))],512),s(c).aiDraftPending&&s(_)?(r(),o("div",Qe,[e("div",Ye,[e("div",Ze,[e("div",Xe,[e("div",et,[l(w,{name:"i-lucide-sparkles",class:"w-3 h-3 text-white"})]),n[10]||(n[10]=e("span",{class:"text-xs font-semibold text-purple-700"},"AI Draft Suggestion",-1))]),l(d,{size:"xs",color:"neutral",variant:"ghost",icon:"i-lucide-x",onClick:V})]),e("p",tt,u(s(_)),1),e("div",st,[l(d,{size:"xs",color:"primary",icon:"i-lucide-send",label:"Send",onClick:te}),l(d,{size:"xs",color:"neutral",variant:"outline",icon:"i-lucide-pencil",label:"Edit",onClick:se}),l(d,{size:"xs",color:"neutral",variant:"ghost",label:"Discard",onClick:V})])])])):x("",!0),e("div",nt,[e("div",at,[l(re,{modelValue:s(f),"onUpdate:modelValue":n[2]||(n[2]=t=>E(f)?f.value=t:null),rows:2,placeholder:"Reply to subscriber...",class:"flex-1 resize-none",onKeydown:[q(F(T,["exact","prevent"]),["enter"]),q(F(()=>{},["shift"]),["enter"])]},null,8,["modelValue","onKeydown"]),l(d,{color:"primary",icon:"i-lucide-send",disabled:!s(f).trim(),loading:s(z),onClick:T},null,8,["disabled","loading"])]),n[11]||(n[11]=e("p",{class:"text-[10px] text-gray-400 mt-1"},[G("Sending as: "),e("span",{class:"font-medium"},"YarnHive NG")],-1))])],64)):(r(),o("div",Ue,[e("div",Be,[l(w,{name:"i-lucide-message-square",class:"w-8 h-8 text-gray-400"})]),n[8]||(n[8]=e("h3",{class:"text-base font-semibold text-gray-700"},"Select a conversation",-1)),n[9]||(n[9]=e("p",{class:"text-sm text-gray-400 mt-2"},"Choose a conversation from the inbox to view the full thread",-1))]))],2)])}}});
1export{ft 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.