1import{a3 as e,am as s,X as a,C as t,h as r,i as l,e as d,I as n,Y as c,B as i,ao as o}from"./index-C8Rmfd6c.js";import{e as x}from"./react-vendor-DRAUbIgz.js";import{B as m}from"./badge-CCXhMFsH.js";import"./select-lJzeG2IW.js";import{T as p,b as h,c as g,a as j}from"./tabs-BTTyrlXA.js";import{u}from"./i18n-vendor-CYlRYL-q.js";import{ai as N,aQ as b,aD as w,au as f,aE as v,E as y,aA as k,a as S,r as C,s as E}from"./ui-vendor-CcnKXWoP.js";import"./chart-vendor-TUC1BS8-.js";import"./state-vendor-h7SotGLv.js";import"./sentry-vendor-CABck4yK.js";import"./socket-vendor-C2IqGKar.js";import"./form-vendor-Cwxmitua.js";import"./index-jVOyRz7F.js";const _=()=>{const{t:_}=u(),[A,L]=x.useState([]),[D,I]=x.useState(null),[P,T]=x.useState([]),[F,M]=x.useState(""),[q,B]=x.useState([]),[U,W]=x.useState([]),[z,H]=x.useState({today:{},total:{}}),[Q,V]=x.useState(!1),[X,Y]=x.useState(!1),[$,G]=x.useState(""),[J,K]=x.useState("compose"),[O,R]=x.useState(null);x.useEffect(()=>{Z()},[]),x.useEffect(()=>{D&&ee(D._id)},[D]);const Z=async()=>{V(!0);try{const[s,a,t,r]=await Promise.all([e.getCustomers(),e.get("/whatsapp/templates"),e.get("/whatsapp/stats"),e.get("/whatsapp/recent")]);s&&s.data&&s.data.success&&L(s.data.data),a&&a.data&&a.data.success&&T(a.data.data),t&&t.data&&t.data.success&&H(t.data.data),r&&r.data&&r.data.success&&W(r.data.data)}catch(s){console.error("Load error:",s),R(_("whatsapp.loadError")||"Failed to load data")}finally{V(!1)}},ee=async s=>{try{const a=await e.get(`/whatsapp/history/${s}`);a&&a.data&&a.data.success&&B(a.data.data)}catch(a){console.error("History load error:",a),R(_("whatsapp.historyLoadError")||"Failed to load message history")}},se=e=>{switch(e){case"read":return s.jsx(E,{className:"w-3 h-3 text-teal-600"});case"delivered":return s.jsx(E,{className:"w-3 h-3 text-slate-400"});case"sent":return s.jsx(C,{className:"w-3 h-3 text-slate-400"});case"failed":return s.jsx(S,{className:"w-3 h-3 text-red-500"});default:return s.jsx(y,{className:"w-3 h-3 text-slate-400"})}},ae=A.filter(e=>e.name?.toLowerCase().includes($.toLowerCase())||e.phone?.includes($));return s.jsxs("div",{className:"min-h-screen bg-slate-50 dark:bg-slate-950 p-4 md:p-6",children:[s.jsx(a,{title:"WhatsApp Entegrasyonu",noindex:!0}),s.jsxs("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-4 mb-6",children:[s.jsxs("div",{children:[s.jsxs("h1",{className:"text-2xl md:text-3xl font-bold text-slate-900 dark:text-white flex items-center gap-3",children:[s.jsx("div",{className:"p-2 bg-green-500 rounded-xl",children:s.jsx(N,{className:"w-6 h-6 text-white"})}),_("whatsapp.title")]}),s.jsx("p",{className:"text-slate-500 dark:text-slate-400 mt-1 text-sm",children:_("whatsapp.subtitle")})]}),s.jsxs("div",{className:"flex gap-3",children:[s.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-xl px-4 py-2 shadow-sm border border-slate-200 dark:border-slate-800",children:[s.jsx("p",{className:"text-xs text-slate-500",children:_("whatsapp.today")}),s.jsx("p",{className:"text-xl font-bold text-green-600",children:z.today?.total||0})]}),s.jsxs("div",{className:"bg-white dark:bg-slate-900 rounded-xl px-4 py-2 shadow-sm border border-slate-200 dark:border-slate-800",children:[s.jsx("p",{className:"text-xs text-slate-500",children:_("whatsapp.total")}),s.jsx("p",{className:"text-xl font-bold text-slate-900 dark:text-white",children:z.total?.total||0})]})]})]}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-12 gap-6",children:[s.jsxs("div",{className:"lg:col-span-4 space-y-4",children:[s.jsxs(t,{className:"border-none shadow-lg",children:[s.jsx(r,{className:"pb-3",children:s.jsxs(l,{className:"text-lg flex items-center gap-2",children:[s.jsx(b,{className:"w-5 h-5"}),_("whatsapp.selectCustomer")]})}),s.jsxs(d,{className:"space-y-3",children:[s.jsxs("div",{className:"relative",children:[s.jsx(w,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400"}),s.jsx(n,{placeholder:_("whatsapp.searchPlaceholder"),className:"pl-10",value:$,onChange:e=>G(e.target.value)})]}),s.jsx("div",{className:"max-h-[300px] overflow-y-auto space-y-2",children:ae.slice(0,20).map(e=>s.jsxs("div",{onClick:()=>I(e),className:"flex items-center gap-3 p-3 rounded-xl cursor-pointer transition-all "+(D?._id===e._id?"bg-green-50 dark:bg-green-900/20 border-2 border-green-500":"bg-slate-50 dark:bg-slate-800 hover:bg-slate-100 dar
1k:hover:bg-slate-700 border-2 border-transparent"),children:[s.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-green-400 to-green-600 flex items-center justify-center text-white font-bold",children:e.name?.charAt(0)||"?"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"font-medium text-sm truncate",children:e.name}),s.jsxs("p",{className:"text-xs text-slate-500 flex items-center gap-1",children:[s.jsx(f,{className:"w-3 h-3"}),e.phone||_("whatsapp.noPhone")]})]})]},e._id))}),D&&s.jsxs("div",{className:"p-4 bg-green-50 dark:bg-green-900/20 rounded-xl border border-green-200 dark:border-green-800",children:[s.jsx("p",{className:"text-xs text-green-600 dark:text-green-400 mb-1",children:_("whatsapp.selectedCustomer")}),s.jsx("p",{className:"font-bold text-green-800 dark:text-green-300",children:D.name}),s.jsx("p",{className:"text-sm text-green-700 dark:text-green-400",children:D.phone})]})]})]}),s.jsxs(t,{className:"border-none shadow-lg",children:[s.jsx(r,{className:"pb-3",children:s.jsx(l,{className:"text-lg",children:_("whatsapp.quickTemplates")})}),s.jsx(d,{children:s.jsx("div",{className:"grid grid-cols-2 gap-2",children:P.map(e=>s.jsxs("button",{onClick:()=>(e=>{let s=e.template;D&&(s=s.replace("{{customerName}}",D.name||_("whatsapp.valuedCustomer"))),M(s)})(e),className:"flex items-center gap-2 p-3 rounded-xl bg-slate-50 dark:bg-slate-800 hover:bg-green-50 dark:hover:bg-green-900/20 transition-all text-left",children:[s.jsx("span",{className:"text-xl",children:e.icon}),s.jsx("span",{className:"text-xs font-medium",children:e.name})]},e.id))})})]})]}),s.jsx("div",{className:"lg:col-span-8 space-y-4",children:s.jsx(t,{className:"border-none shadow-lg",children:s.jsx(d,{className:"p-0",children:s.jsxs(p,{value:J,onValueChange:K,children:[s.jsxs(h,{className:"w-full rounded-none border-b border-slate-200 dark:border-slate-800 bg-transparent p-0",children:[s.jsxs(g,{value:"compose",className:"flex-1 rounded-none border-b-2 border-transparent data-[state=active]:border-green-500 data-[state=active]:bg-transparent",children:[s.jsx(v,{className:"w-4 h-4 mr-2"}),_("whatsapp.compose")]}),s.jsxs(g,{value:"history",className:"flex-1 rounded-none border-b-2 border-transparent data-[state=active]:border-green-500 data-[state=active]:bg-transparent",children:[s.jsx(y,{className:"w-4 h-4 mr-2"}),_("whatsapp.history")]})]}),s.jsx(j,{value:"compose",className:"p-6 space-y-4",children:D?s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2 text-sm text-slate-500",children:[s.jsx(f,{className:"w-4 h-4"}),s.jsxs("span",{children:[_("whatsapp.sendingTo")," ",D.phone]})]}),s.jsx(c,{placeholder:_("whatsapp.messagePlaceholder"),className:"min-h-[150px] resize-none",value:F,onChange:e=>M(e.target.value)}),s.jsxs("div",{className:"flex items-center justify-between",children:[s.jsx("div",{className:"text-xs text-slate-500",children:_("whatsapp.characters",{count:F.length})}),s.jsxs(i,{onClick:async()=>{if(D&&F.trim()){Y(!0);try{const s=await e.post("/whatsapp/send",{to:D.phone,message:F.trim(),customerId:D._id});s&&s.data&&s.data.success?(o.success(_("whatsapp.sendSuccess")),M(""),ee(D._id),Z()):o.error(_("whatsapp.sendError"))}catch(s){o.error(_("whatsapp.sendErrorWithMsg",{message:s.message}))}finally{Y(!1)}}else o.error(_("whatsapp.requiredError"))},disabled:!F.trim()||X,className:"bg-green-600 hover:bg-green-700 gap-2",children:[X?s.jsx(k,{className:"w-4 h-4 animate-spin"}):s.jsx(v,{className:"w-4 h-4"}),_(X?"whatsapp.sending":"whatsapp.send")]})]})]}),q.length>0&&s.jsxs("div",{className:"border-t border-slate-200 dark:border-slate-800 pt-4",children:[s.jsxs("p",{className:"text-sm font-medium mb-3 flex items-center gap-2",children:[s.jsx(y,{className:"w-4 h-4"}),_("whatsapp.recentMessages")]}),s.jsx("div",{className:"space-y-2 max-h-[200px] overflow-y-auto",children:q.slice(0,5).map(e=>s.jsx("div",{className:"flex items-start gap-2 p-3 bg-slate-50 dark:bg-slate-800 rounded-lg",children:s.jsxs("div",{className:"flex-1",children:[s.jsx("p",{className:"text-sm line-clamp-2",children:e.content}),s.jsxs("div",{className:"flex items-center gap-2 mt-1 text-xs text-slate-500",children:[s.jsx("span",{children:new Date(e.createdAt).toLocaleStr
1ing("en-US")}),se(e.status)]})]})},e._id))})]})]}):s.jsxs("div",{className:"text-center py-12 text-slate-500",children:[s.jsx(N,{className:"w-16 h-16 mx-auto mb-4 opacity-20"}),s.jsx("p",{className:"text-lg font-medium",children:_("whatsapp.selectCustomerTitle")}),s.jsx("p",{className:"text-sm",children:_("whatsapp.selectCustomerDesc")})]})}),s.jsx(j,{value:"history",className:"p-6",children:s.jsx("div",{className:"space-y-3 max-h-[500px] overflow-y-auto",children:0===U.length?s.jsxs("div",{className:"text-center py-12 text-slate-500",children:[s.jsx(y,{className:"w-16 h-16 mx-auto mb-4 opacity-20"}),s.jsx("p",{children:_("whatsapp.noMessages")})]}):U.map(e=>s.jsxs("div",{className:"flex items-start gap-3 p-4 bg-slate-50 dark:bg-slate-800 rounded-xl",children:[s.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-green-400 to-green-600 flex items-center justify-center text-white font-bold shrink-0",children:e.customerId?.name?.charAt(0)||"?"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsxs("div",{className:"flex items-center justify-between mb-1",children:[s.jsx("p",{className:"font-medium text-sm",children:e.customerId?.name||_("whatsapp.unknown")}),s.jsx("span",{className:"text-xs text-slate-500",children:new Date(e.createdAt).toLocaleString("en-US")})]}),s.jsx("p",{className:"text-sm text-slate-600 dark:text-slate-400 line-clamp-2",children:e.content}),s.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[se(e.status),s.jsx(m,{variant:"sent"===e.status?"default":"failed"===e.status?"destructive":"secondary",className:"text-xs",children:"sent"===e.status?_("whatsapp.sent"):"failed"===e.status?_("whatsapp.failed"):e.status})]})]})]},e._id))})})]})})})})]})]})};export{_ 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.