1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-D7aUILjH.js","assets/index-DUB0zFnl.css"])))=>i.map(i=>d[i]); 2import{a as kt,k as _t,r as m,j as e,a1 as ee,l as lt,e as Zt,p as Xt,o as es}from"./index-D7aUILjH.js";import{B as A}from"./button-CXeA2D2_.js";import{D as ts,f as ss,a as as,b as rs,c as ns,d as ls}from"./dialog-amhjXjii.js";import{U as it}from"./user-plus-CzQa403V.js";import{C as is}from"./CustomerEditDialog-Ct-wW3jj.js";import{u as G}from"./useQuery-B3200vY8.js";import{u as os}from"./useMutation-DeBIkaLZ.js";import{B as Se}from"./badge-CV1s7q4W.js";import{A as cs}from"./arrow-right-DOH20B1u.js";import{G as ds}from"./grip-vertical-DY1bZpZ-.js";import{S as ms}from"./star-Cqw5njzB.js";import{B as Te}from"./payment-editor-dialog-BJ4RuPwA.js";import{S as De}from"./sparkles-BFfTg9mj.js";import{M as us}from"./mail-U550WBuZ.js";import{P as St}from"./phone-DFV9fpAA.js";import{E as xs}from"./external-link-DFq5er-_.js";import{C as ps}from"./clock-vKgYE8vW.js";import{M as he}from"./message-circle-CNrYwrK_.js";import{G as ot}from"./globe-CzH7iAn2.js";import{C as J,a as xe,b as pe,d as le}from"./card-oxUuQ4KR.js";import{I as ct}from"./input-Drfk04bb.js";import{P as dt}from"./progress-DLe1uYrx.js";import{T as hs,a as gs,b as mt,c as fs}from"./tabs-C6hdZLkp.js";import{T as js,a as bs,b as ut,c as V,d as ys,e as H}from"./table-Bxpkqxqk.js";import{D as xt,a as pt,b as ht,c as Z}from"./dropdown-menu-1jDHhfjz.js";import{S as vs}from"./slider-F0O42nOT.js";import{P as Ns,a as ws,b as Cs}from"./popover-ByBzKfcI.js";import{S as gt,a as ft,b as jt,c as bt,d as $}from"./select-Bu9OtDlF.js";import{L as ks}from"./layout-grid-rajtFzMB.js";import{L as _s}from"./list-DZPeJ0_j.js";import{D as Ss}from"./download-CnqF9ojT.js";import{L as Ts}from"./loader-circle-aqv1FVJR.js";import{R as Ds}from"./refresh-cw-bFbX4-ca.js";import{S as Ls}from"./settings-Cfq0tbsR.js";import{U as yt}from"./users-BszN9G4e.js";import{T as Es}from"./target-DyfxUZI_.js";import{T as Ms}from"./trending-up-OEQO8Lvj.js";import{S as As}from"./search-CQmwD4pZ.js";import{A as X}from"./arrow-up-down-PHXpwqfa.js";import{C as vt}from"./crown-B6IecaZ5.js";import{P as Fs}from"./package-CsLZ2cEN.js";import{E as Nt}from"./ellipsis-vertical-COEIu5MJ.js";import{E as wt}from"./eye-C8T7b9yE.js";import{S as Ct}from"./square-pen-LQ9rH_J2.js";import{C as Ps}from"./chevron-down-Dd5bwzqM.js";import{C as $s}from"./check-BlEPFiN7.js";import"./index-DzfOKn_W.js";import"./index-fqpRnqXi.js";import"./label-DgrT_fKd.js";import"./switch-CTAE2JbQ.js";import"./index-DOEqhBvs.js";import"./separator-Cvel0jVN.js";import"./user-BCpcGh3-.js";import"./shield-check-BbB3mI8K.js";import"./brain-CCARVyLO.js";import"./heart-CRJXw64t.js";import"./shopping-cart-C6PJDk9l.js";import"./tag-Du6_ptuF.js";import"./calendar-days-IGXRbKpM.js";import"./pencil-MHcAQQV2.js";import"./minus-N1UKkXFy.js";import"./plus-CbAo0upY.js";import"./trash-2-DNBlVe3t.js";import"./chevron-up-rcvbF725.js";import"./ellipsis-DnHa_Muj.js";import"./credit-card-BpmEXODd.js";import"./index-DyrCqDEg.js";import"./index-WXM71ork.js";import"./chevron-right-DJOqEpSE.js";import"./circle-TcX0y6tI.js";import"./index-BdQq_4o_.js";const _e={customer_name:"",phone:"",email:"",stage_id:"",notes:""};function Is({pipelineStages:a,onSuccess:i}){const{language:n}=kt(),{toast:k}=_t(),[C,_]=m.useState(!1),[u,g]=m.useState(_e),[p,T]=m.useState(!1),S=c=>{_(c),c||g(_e)},j=async()=>{if(u.customer_name.trim()){T(!0);try{const{apiRequest:c,queryClient:y}=await ee(async()=>{const{apiRequest:P,queryClient:f}=await import("./index-D7aUILjH.js").then(D=>D.a$);return{apiRequest:P,queryClient:f}},__vite__mapDeps([0,1])),N={customer_name:u.customer_name.trim(),phone:u.phone.trim()||null,email:u.email.trim()||null,stage_id:u.stage_id||null,notes:u.notes.trim()||null};await c({url:"/api/customers",method:"POST",data:N}),await y.invalidateQueries({queryKey:["/api/customers"]}),k({title:n==="tr"?"MüÅteri eklendi":"Customer added",description:u.customer_name.trim()}),_(!1),g(_e),i()}catch(c){k({title:n==="tr"?"Hata":"Error",description:String(c),variant:"destructive"})}finally{T(!1)}}};return e.jsxs(ts,{open:C,onOpenChange:S,children:[e.jsx(ss,{asChild:!0,children:e.jsxs(A,{variant:"outline",size:"sm",className:"h-8 gap-1.5",children:[e.jsx(it,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:n==="tr"?"Tek KiÅi Ekle":"Add Customer"})]})}),e.jsxs(as,{className:"sm:max-w-sm",children:[e.jsxs(rs,{children:[e.jsxs(ns,{className:"flex items-center gap-2",children:[e.jsx(it,{className:"h-5 w-5"}),n==="tr"?"Yeni MüÅteri Ekle":"Add New Customer"]}),e.jsx(ls,{children:n==="tr"?"MüÅteri bilgilerini girin.":"Enter customer details."})]}),e.jsxs("div",{className:"space-y-3 py-1",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-sm font-medium",children:[n==="tr"?"Ad Soyad":"Full Name"," ",e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx("input",{className:"w-full h-9 rounded-md border bg-background px-3 text-sm focus:outline-none focus:ring-2 focus:ring-ring",placeholder:n==="tr"?"AyÅe Kaya":"Jane Doe",value:u.customer_name,onChange:c=>g(y=>({...y,customer_name:c.target.value}))})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:n==="tr"?"Telefon":"Phone"}),e.jsx("input",{className:"w-full h-9 rounded-md border bg-background px-3 text-sm focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"+90 555 123 4567",value:u.phone,onChange:c=>g(y=>({...y,phone:c.target.value}))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:"E-posta"}),e.jsx("input",{type:"email",className:"w-full h-9 rounded-md border bg-background px-3 text-sm focus:outline-none focus:ring-2 focus:ring-ring",placeholder:"[email protected]",value:u.email,onChange:c=>g(y=>({...y,email:c.target.value}))})]})]}),a.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:n==="tr"?"AÅama":"Stage"}),e.jsxs("select",{value:u.stage_id,onChange:c=>g(y=>({...y,stage_id:c.target.value})),className:"w-full h-9 rounded-md border bg-background px-3 text-sm focus:outline-none focus:ring-2 focus:ring-ring",children:[e.jsx("option",{value:"",children:n==="tr"?"â Seçin â":"â Select â"}),a.map(c=>e.jsx("option",{value:c.id,children:c.name},c.id))]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-sm font-medium",children:n==="tr"?"Notlar":"Notes"}),e.jsx("textarea",{rows:2,className:"w-full rounded-md border bg-background px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ring resize-none",placeholder:n==="tr"?"İsteÄe baÄlı not...":"Optional notes...",value:u.notes,onChange:c=>g(y=>({...y,notes:c.target.value}))})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-1",children:[e.jsx(A,{variant:"outline",size:"sm",onClick:()=>_(!1),children:n==="tr"?"İptal":"Cancel"}),e.jsx(A,{size:"sm",disabled:p||!u.customer_name.trim(),onClick:j,children:p?n==="tr"?"Kaydediliyor...":"Saving...":n==="tr"?"Kaydet":"Save"})]})]})]})}const Rs=new Set(["visitor","lead","customer","hot_lead","my_customer"]),Us=[{id:"visitor",name:"Visitors",slug:"visitor",color:"#64748b",position:0,is_default:!0,is_terminal:!1},{id:"lead",name:"Leads",slug:"lead",color:"#3b82f6",position:1,is_default:!1,is_terminal:!1},{id:"customer",name:"Customers",slug:"customer",color:"#10b981",position:2,is_default:!1,is_terminal:!1},{id:"hot_lead",name:"Hot Leads",slug:"hot_lead",color:"#f97316",position:3,is_default:!1,is_terminal:!1},{id:"my_customer",name:"My Customers",slug:"my_customer",color:"#8b5cf6",position:4,is_default:!1,is_terminal:!0}];function qs(a){switch(a){case"whatsapp":return e.jsx(St,{className:"h-3 w-3 text-green-500"});case"instagram":return e.jsx(ot,{className:"h-3 w-3 text-pink-500"});case"facebook":return e.jsx(ot,{className:"h-3 w-3 text-blue-500"});default:return e.jsx(he,{className:"h-3 w-3 text-purple-400"})}}function Os(a){switch(a){case"whatsapp":return"WhatsApp";case"instagram":return"Instagram";case"facebook":return"Facebook";default:return"Webchat"}}function Ks({score:a}){const n=2*Math.PI*14,k=a/100*n,C=a>=70?"#10b981":a>=40?"#f59e0b":"#ef4444";return e.jsxs("div",{className:"relative flex items-center justify-center shrink-0",style:{width:36,height:36},children:[e.jsxs("svg",{width:"36",height:"36",className:"transform -rotate-90",children:[e.jsx("circle",{cx:"18",cy:"18",r:14,fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-gray-200 dark:text-gray-700"}),e.jsx("circle",{cx:"18",cy:"18",r:14,fill:"none",stroke:C,strokeWidth:"2.5",strokeDasharray:n,strokeDashoffset:n-k,strokeLinecap:"round",className:"transition-all duration-700 ease-out"})]}),e.jsx("span",{className:"absolute text-[10px] font-bold",style:{color:C},children:a})]})}function zs(a,i){if(!a)return i==="tr"?"Bilinmiyor":"Unknown";const n=a instanceof Date?a:new Date(a);if(isNaN(n.getTime()))return i==="tr"?"Bilinmiyor":"Unknown";const C=new Date().getTime()-n.getTime();if(C<0)return n.toLocaleDateString(i==="tr"?"tr-TR":"en-US",{day:"numeric",month:"short"});const _=Math.floor(C/6e4),u=Math.floor(C/36e5),g=Math.floor(C/864e5);return _<60?i==="tr"?`${_}dk`:`${_}m`:u<24?i==="tr"?`${u}sa`:`${u}h`:g<7?i==="tr"?`${g}g`:`${g}d`:n.toLocaleDateString(i==="tr"?"tr-TR":"en-US",{day:"numeric",month:"short"})}function Bs({customer:a,language:i,onDragStart:n,onClick:k,onViewConversation:C}){let _=!1;const u=a.lead_score??0,g=(a.customer_name||"?").split(" ").map(p=>p[0]).join("").toUpperCase().slice(0,2);return e.jsxs("div",{draggable:!0,onDragStart:p=>{_=!0,p.dataTransfer.setData("text/plain",a.id),p.dataTransfer.effectAllowed="move",n(a.id)},onDragEnd:()=>{_=!1},onClick:()=>{!_&&k&&k(a)},className:"group mb-2.5 rounded-xl border border-gray-200/80 dark:border-gray-700/60 bg-white dark:bg-gray-800/90 p-3 cursor-pointer hover:border-purple-300 dark:hover:border-purple-600 hover:shadow-lg hover:shadow-
2purple-500/5 transition-all duration-200 hover:-translate-y-0.5 active:scale-[0.98]",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"mt-0.5 text-gray-300 dark:text-gray-600 opacity-0 group-hover:opacity-100 transition-opacity shrink-0 cursor-grab active:cursor-grabbing",children:e.jsx(ds,{className:"h-4 w-4"})}),e.jsxs("div",{className:"flex items-center gap-2.5 flex-1 min-w-0",children:[e.jsx("div",{className:"w-8 h-8 rounded-lg bg-gradient-to-br from-purple-500 to-violet-600 flex items-center justify-center shrink-0",children:e.jsx("span",{className:"text-[10px] font-bold text-white",children:g})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-[13px] text-gray-900 dark:text-gray-100 truncate",children:a.customer_name||"Unknown"}),a.is_vip&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-amber-100 dark:bg-amber-900/40 text-amber-700 dark:text-amber-400 text-[10px] font-semibold shrink-0",children:[e.jsx(ms,{className:"h-2.5 w-2.5 fill-amber-500 text-amber-500"}),"VIP"]}),a.is_blocked&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-red-100 dark:bg-red-900/40 text-red-700 dark:text-red-400 text-[10px] font-semibold shrink-0",children:[e.jsx(Te,{className:"h-2.5 w-2.5"}),i==="tr"?"Engelli":"Blocked"]}),a.ai_profile&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 px-1.5 py-0.5 rounded-full bg-violet-100 dark:bg-violet-900/40 text-violet-700 dark:text-violet-400 text-[10px] font-semibold shrink-0",children:[e.jsx(De,{className:"h-2.5 w-2.5"}),"AI"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[qs(a.lead_source),e.jsx("span",{className:"text-[10px] text-muted-foreground",children:Os(a.lead_source)})]})]}),e.jsx(Ks,{score:u})]})]}),a.lead_source==="instagram"&&(()=>{var c,y;const p=((c=a.integration_data)==null?void 0:c.instagram_username)||null,T=(y=a.customer_name)==null?void 0:y.startsWith("@");if(!p&&!T)return null;const S=p?p.replace("@","").trim():a.customer_name.replace("@","").trim(),j=(a.customer_name||"").replace("@","").trim().toLowerCase();return!p&&j===S.toLowerCase()?null:e.jsxs("div",{className:"mt-1.5 flex items-center gap-1.5",children:[e.jsx("svg",{viewBox:"0 0 24 24",className:"h-3 w-3 shrink-0 text-[#E1306C]",fill:"currentColor",children:e.jsx("path",{d:"M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zm0-2.163c-3.259 0-3.667.014-4.947.072-4.358.2-6.78 2.618-6.98 6.98-.059 1.281-.073 1.689-.073 4.948 0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98 1.281.058 1.689.072 4.948.072 3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98-1.281-.059-1.69-.073-4.949-.073zm0 5.838c-3.403 0-6.162 2.759-6.162 6.162s2.759 6.163 6.162 6.163 6.162-2.759 6.162-6.163c0-3.403-2.759-6.162-6.162-6.162zm0 10.162c-2.209 0-4-1.79-4-4 0-2.209 1.791-4 4-4s4 1.791 4 4c0 2.21-1.791 4-4 4zm6.406-11.845c-.796 0-1.441.645-1.441 1.44s.645 1.44 1.441 1.44c.795 0 1.439-.645 1.439-1.44s-.644-1.44-1.439-1.44z"})}),e.jsxs("a",{href:`https://instagram.com/${S}`,target:"_blank",rel:"noopener noreferrer",onClick:N=>N.stopPropagation(),className:"text-[11px] text-[#E1306C] hover:underline font-medium truncate max-w-[140px]",children:["@",S]})]})})(),e.jsxs("div",{className:"mt-2.5 pt-2 border-t border-gray-100 dark:border-gray-700/50 flex items-center justify-between text-[11px] text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[a.email&&e.jsxs("span",{className:"flex items-center gap-1 truncate max-w-[90px]",children:[e.jsx(us,{className:"h-3 w-3 shrink-0 text-gray-400"}),e.jsx("span",{className:"truncate",children:a.email.split("@")[0]})]}),a.phone&&!a.email&&!/^\d{10,}$/.test(String(a.phone))&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(St,{className:"h-3 w-3 shrink-0 text-gray-400"}),e.jsx("span",{className:"truncate max-w-[80px]",children:a.phone})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[a.conversation_id&&C&&e.jsxs("button",{onClick:p=>{p.stopPropagation(),C(a.conversation_id)},className:"flex items-center gap-1 px-1.5 py-0.5 rounded-md text-[10px] font-medium text-purple-600 dar
2k:text-purple-400 bg-purple-50 dark:bg-purple-900/30 hover:bg-purple-100 dark:hover:bg-purple-900/50 transition-colors opacity-0 group-hover:opacity-100",children:[e.jsx(xs,{className:"h-3 w-3"}),i==="tr"?"Sohbet":"Chat"]}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px]",children:[e.jsx(ps,{className:"h-3 w-3 text-gray-400"}),zs(a.last_interaction_date,i)]})]})]})]})}function Tt(a){const i=parseInt(a.slice(1,3),16),n=parseInt(a.slice(3,5),16),k=parseInt(a.slice(5,7),16);return`${i}, ${n}, ${k}`}function Vs({stage:a,customers:i,language:n,onDrop:k,onDragStart:C,dragOverStage:_,onDragOverStage:u,onDragLeaveStage:g,onCustomerClick:p,onViewConversation:T,totalCustomers:S}){const j=_===a.id,c=S>0?Math.round(i.length/S*100):0,y=a.color.startsWith("#")?Tt(a.color):"99, 102, 241";return e.jsxs("div",{className:`flex flex-col rounded-2xl border min-w-[280px] max-w-[320px] flex-1 transition-all duration-300 ${j?"ring-2 shadow-lg scale-[1.01]":"shadow-sm"}`,style:{background:`linear-gradient(to bottom, rgba(${y}, 0.05), rgba(${y}, 0.02))`,borderColor:j?`rgba(${y}, 0.6)`:`rgba(${y}, 0.25)`,...j?{"--tw-ring-color":`rgba(${y}, 0.4)`}:{}},onDragOver:N=>{N.preventDefault(),N.dataTransfer.dropEffect="move",u(a.id)},onDragLeave:N=>{N.currentTarget.contains(N.relatedTarget)||g()},onDrop:N=>{N.preventDefault();const P=N.dataTransfer.getData("text/plain");P&&k(P,a.id),g()},children:[e.jsxs("div",{className:"px-4 py-3 flex items-center gap-3",children:[e.jsx("div",{className:"w-3 h-3 rounded-full shrink-0",style:{backgroundColor:a.color}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"font-bold text-sm text-gray-800 dark:text-gray-100",children:a.name}),e.jsx(Se,{className:"text-[11px] font-bold px-2 py-0.5 border-0",style:{backgroundColor:`rgba(${y}, 0.15)`,color:a.color},children:i.length})]}),e.jsxs("div",{className:"mt-1.5 flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 h-1 rounded-full bg-gray-200/80 dark:bg-gray-700/80 overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full transition-all duration-700 ease-out",style:{width:`${c}%`,backgroundColor:a.color}})}),e.jsxs("span",{className:"text-[10px] text-muted-foreground font-medium w-8 text-right",children:[c,"%"]})]})]})]}),e.jsx("div",{className:"w-full h-px",style:{background:`linear-gradient(to right, transparent, rgba(${y}, 0.3), transparent)`}}),e.jsx("div",{className:"p-2.5 flex-1 overflow-y-auto max-h-[calc(100vh-320p
2x)] min-h-[180px]",children:i.length===0?e.jsxs("div",{className:`flex flex-col items-center justify-center py-10 text-muted-foreground rounded-xl transition-all ${j?"border-2 border-dashed bg-white/50 dark:bg-white/5":""}`,style:j?{borderColor:`rgba(${y}, 0.5)`}:{},children:[e.jsx("div",{className:"w-12 h-12 rounded-2xl bg-gray-100 dark:bg-gray-800 flex items-center justify-center mb-3",children:e.jsx("div",{className:"w-5 h-5 rounded-full opacity-30",style:{backgroundColor:a.color}})}),e.jsx("p",{className:"text-xs font-medium opacity-50",children:n==="tr"?"Henüz müÅteri yok":"No customers yet"}),j&&e.jsx("p",{className:"text-[10px] mt-1.5 font-medium animate-pulse",style:{color:a.color},children:n==="tr"?"Buraya bırakın":"Drop here"})]}):i.map(N=>e.jsx(Bs,{customer:N,language:n,onDragStart:C,onClick:p,onViewConversation:T},N.id))})]})}function Hs({stages:a,language:i}){return e.jsx("div",{className:"flex items-center justify-center gap-1 mb-4 px-4 flex-wrap",children:a.map((n,k)=>(n.color.startsWith("#")&&Tt(n.color),e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full shadow-sm",style:{background:n.color},children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-white/70"}),e.jsx("span",{className:"text-[10px] font-semibold text-white tracking-wide",children:n.name.toUpperCase()})]}),k<a.length-1&&e.jsxs("div",{className:"flex items-center mx-1",children:[e.jsx("div",{className:"w-4 h-px bg-gray-300 dark:bg-gray-600"}),e.jsx(cs,{className:"h-3 w-3 text-gray-300 dark:text-gray-600 -ml-0.5"})]})]},n.id)))})}function Gs(a,i,n){var g,p,T,S;if(a.stage_id){const j=i.find(c=>c.id===a.stage_id);if(j)return j.id}if(a.customer_stage){const j=a.customer_stage,c=i.find(N=>N.slug===j);if(c)return c.id;const y=i.find(N=>N.name.toLowerCase()===j.toLowerCase());if(y)return y.id}if(n)return((g=i.find(j=>j.is_default))==null?void 0:g.id)||((p=i[0])==null?void 0:p.id)||i[0].id;const k=a.customer_stage||"visitor",C=k==="advocate"?"hot_lead":k,_=i.find(j=>j.slug===C);if(_)return _.id;const u=i.find(j=>j.name.toLowerCase()===C.toLowerCase());return u?u.id:((T=i.find(j=>j.is_default))==null?void 0:T.id)||((S=i[0])==null?void 0:S.id)||i[0].id}function Qs({customers:a,language:i,onViewConversation:n,onCustomerClick:k}){var P;const[C,_]=m.useState(null),{data:u}=G({queryKey:["/api/pipelines/stages"],queryFn:async()=>(await lt({url:"/api/pipelines/stages",method:"GET"})).json(),staleTime:5*60*1e3}),g=(P=u==null?void 0:u.stages)!=null&&P.length?u.stages:Us,p=g.some(f=>!Rs.has(f.slug)),T=m.useCallback(f=>{n?n(f):window.open(`/chats/${f}`,"_blank","noopener,noreferrer")},[n]),S=os({mutationFn:async({customerId:f,stageId:D,stageSlug:w})=>lt({url:`/api/customers/${f}/stage`,method:"PATCH",data:{stage_id:D,stage:w}}),onSuccess:(f,D)=>{const w=g.find(F=>F.id===D.stageId);toast({title:i==="tr"?"BaÅarılı":"Success",description:i==="tr"?`MüÅteri "${w==null?void 0:w.name}" aÅamasına taÅındı`:`Customer moved to "${w==null?void 0:w.name}"`}),queryClient.invalidateQueries({queryKey:["/api/customers"]})},onError:(f,D)=>{toast({title:i==="tr"?"Hata":"Error",description:i==="tr"?"AÅama güncellenemedi":"Failed to update stage",variant:"destructive"}),queryClient.invalidateQueries({queryKey:["/api/customers"]})}}),j=m.useMemo(()=>{var D;const f={};for(const w of g)f[w.id]=[];for(const w of a){const F=Gs(w,g,p);f[F]?f[F].push(w):f[(D=g[0])==null?void 0:D.id]&&f[g[0].id].push(w)}return f},[a,g,p]),c=m.useCallback(f=>{for(const[D,w]of Object.entries(j))if(w.find(F=>F.id===f))return D;return null},[j]),y=m.useCallback((f,D)=>{const w=c(f);if(!w||w===D)return;const F=g.find(R=>R.id===D);F&&S.mutate({customerId:f,stageId:D,stageSlug:F.slug})},[c,S,g]),N=m.useCallback(f=>{},[]);return e.jsxs("div",{children:[e.jsx(Hs,{stages:g,language:i}),e.jsx("div",{className:"flex gap-4 overflow-x-auto pb-4",style:{minHeight:"400px"},children:g.map(f=>e.jsx(Vs,{stage:f,customers:j[f.id]||[],language:i,onDrop:y,onDragStart:N,dragOverStage:C,onDragOverStage:_,onDragLeaveStage:()=>_(null),onCustomerClick:k,onViewConversation:T,totalCustomers:a.length},f.id))})]})}function ie({label:a,options:i,selected:n,onChange:k}){const[C,_]=m.useState(!1),u=n.length>0,g=p=>k(n.includes(p)?n.filter(T=>T!==p):[...n,p]);return e.jsxs(Ns,{open:C,onOpenChange:_,children:[e.jsx(ws,{asChild:!0,children:e.jsxs(A,{variant:"outline",size:"sm",className:`h-8 text-xs gap-1 ${u?"border-purple-400 bg-purple-50 text-purple-700 hover:bg-purple-100":"border-dashed text-muted-foreground hover:text-foreground"}`,children:[a,u&&e.jsx("span",{className:"ml-0.5 bg-purple-600 text-white text-xs rounded-full w-4 h-4 flex items-center justify-center leading-none",children:n.length}),e.jsx(Ps,{className:"h-3 w-3 opacity-50"})]})}),e.jsx(Cs,{className:"w-48 p-1.5",align:"start",children:e.jsx("div",{className:"space-y-0.5",children:i.map(p=>{const T=n.includes(p.value);return e.jsxs("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-sm cursor-pointer hover:bg-muted text-sm select-none",onClick:()=>
2g(p.value),children:[e.jsx("div",{className:`w-4 h-4 rounded border flex items-center justify-center shrink-0 ${T?"bg-purple-600 border-purple-600":"border-input"}`,children:T&&e.jsx($s,{className:"h-3 w-3 text-white"})}),e.jsx("span",{children:p.label})]},p.value)})})})]})}function Tr(){var He,Ge,Qe,We,Ye;const[a,i]=m.useState("kanban"),[n,k]=m.useState(""),[C,_]=m.useState(""),[u,g]=m.useState("all"),[p,T]=m.useState("lastContact"),[S,j]=m.useState("desc"),[c,y]=m.useState("all"),[N,P]=m.useState([]),[f,D]=m.useState([]),[w,F]=m.useState(0),[R,Le]=m.useState(100),[Q,Ee]=m.useState([]),[te,Me]=m.useState([]),[se,Ae]=m.useState([]),[oe,Fe]=m.useState(""),[Pe,ce]=m.useState(null),[$e,Ie]=m.useState(!1),[Ws,Ys]=m.useState(!1),[Js,O]=m.useState(0),[Zs,K]=m.useState(""),[Xs,ea]=m.useState(!1),[ta,sa]=m.useState("idle"),[aa,ra]=m.useState(null),[na,la]=m.useState(null),[ia,oa]=m.useState(null),[ca,da]=m.useState("my_customer"),{t:W,language:s}=kt(),{toast:Dt}=_t(),[Lt,Et]=Zt(),{activeBusiness:ge}=Xt(),{data:I,isLoading:Mt,error:Re,refetch:Ue}=G({queryKey:["/api/customers"],queryFn:async()=>{var h;const{apiRequest:t}=await ee(async()=>{const{apiRequest:b}=await import("./index-D7aUILjH.js").then(v=>v.a$);return{apiRequest:b}},__vite__mapDeps([0,1]));console.log("[CUSTOMERS FETCH] Fetching customers...");const r=await(await t({url:"/api/customers",method:"GET"})).json();return console.log("[CUSTOMERS FETCH] Received data:",{customerCount:((h=r.customers)==null?void 0:h.length)||0,needsMigration:r.needsMigration}),{customers:(r.customers||[]).map(b=>({...b,score_color:ae(b.lead_score??0),score_percentage:ke(b.lead_score??0)})),agents:r.agents||[]}},staleTime:5*60*1e3,gcTime:10*60*1e3}),E=(I==null?void 0:I.customers)||[],qe=(I==null?void 0:I.agents)||[],z=((He=E[0])==null?void 0:He.business_id)||null,fe=(ge==null?void 0:ge.id)||z,{data:Y}=G({queryKey:["/api/subscriptions/module-status"]}),At=((Qe=(Ge=Y==null?void 0:Y.modules)==null?void 0:Ge.JAS_RESERVATION)==null?void 0:Qe.billingStatus)==="active",Ft=((Ye=(We=Y==null?void 0:Y.modules)==null?void 0:We.JAS_HOTEL)==null?void 0:Ye.billingStatus)==="active",{data:je}=G({queryKey:["/api/pipelines/stages"],queryFn:async()=>{const{apiRequest:t}=await ee(async()=>{const{apiRequest:r}=await import("./index-D7aUILjH.js").then(o=>o.a$);return{apiRequest:r}},__vite__mapDeps([0,1]));return(await t({url:"/api/pipelines/stages",method:"GET"})).json()},enabled:!!fe,staleTime:5*60*1e3}),U=(je==null?void 0:je.stages)||[],{data:be}=G({queryKey:[`/api/businesses/${fe}/crm-custom-fields`],enabled:!!fe}),ye=(be==null?void 0:be.fields)||[],ve=Object.fromEntries(U.map(t=>[t.id,t])),Ne=Object.fromEntries(U.map(t=>[t.slug,t])),we=Object.fromEntries(U.map(t=>[t.name.toLowerCase(),t])),de=t=>{if(t.stage_id&&ve[t.stage_id])return ve[t.stage_id];const l=t.customer_stage;return l&&Ne[l]?Ne[l]:l&&we[l.toLowerCase()]?we[l.toLowerCase()]:null},Ce=t=>{const l=de(t);if(l)return l.name;const r=t.customer_stage||null;return r?r.charAt(0).toUpperCase()+r.slice(1).replace(/_/g," "):s==="tr"?"Ziyaretci":"Visitor"},Oe=t=>{const l=de(t);return l?l.color:"#64748b"},{data:me}=G({queryKey:["/api/customer-packages/summary",z],queryFn:async()=>{const{apiRequest:t}=await ee(async()=>{const{apiRequest:r}=await import("./index-D7aUILjH.js").then(o=>o.a$);return{apiRequest:r}},__vite__mapDeps([0,1]));return(await t({url:`/api/customer-packages/summary?businessId=${z}`,method:"GET"})).json()},enabled:!!z&&E.length>0,staleTime:2*60*1e3});m.useEffect(()=>{const t=setTimeout(()=>_(n.trim()),350);return()=>clearTimeout(t)},[n]);const{data:B}=G({queryKey:["/api/customers/service-search",C,z],queryFn:async()=>{const{apiRequest:t}=await ee(async()=>{const{apiRequest:r}=await import("./index-D7aUILjH.js").then(o=>o.a$);return{apiRequest:r}},__vite__mapDeps([0,1]));return(await t({url:`/api/customers/service-search?q=${encodeURIComponent(C)}&businessId=${z}`,method:"GET"})).json()},enabled:C.length>=2&&!!z,staleTime:30*1e3});m.useEffect(()=>{const l=new URLSearchParams(window.location.search).get("customerId");if(l&&E.length>0&&!Pe){const r=E.find(o=>o.id===l);r&&ce(r)}},[E,Lt]);const Pt=async()=>{Ie(!0),O(0),K(s==="tr"?"Senkronizasyon baÅlatılıyor...":"Starting sync...");try{const{apiRequest:t,queryClient:l}=await ee(async()=>{const{apiRequest:r,queryClient:o}=await import("./index-D7aUILjH.js").then(h=>h.a$);return{apiRequest:r,queryClient:o}},__vite__mapDeps([0,1]));O(20),K(s==="tr"?"MüÅteri verileri senkronize ediliyor...":"Syncing customer data..."),await t({url:"/api/customers/sync",method:"POST"}),O(60),K(s==="tr"?"AÅamalar ve puanlar güncelleniyor...":"Updating stages and scores..."),await t({url:"/api/customers/recalculate-scores",method:"POST"}),O(90),K(s==="tr"?"Veriler yükleniyor...":"Loading data..."),await l.invali
2dateQueries({queryKey:["/api/customers"]}),await Ue(),O(100),K(s==="tr"?"Tamamlandı!":"Done!")}catch(t){console.error("[CUSTOMERS MANUAL SYNC] Error:",t),K(s==="tr"?"Hata oluÅtu":"Failed"),O(0)}finally{setTimeout(()=>{Ie(!1),O(0),K("")},2e3)}},ae=t=>t>=70?"green":t>=40?"yellow":"red",ke=t=>Math.min(t,100),Ke=t=>{if(!t)return s==="tr"?"Web Sohbet":"Webchat";if(t==="contact-card")return"Contact Card";const r={webchat:"webchat",whatsapp:"whatsapp",instagram:"instagram",facebook:"facebook"}[t]||"webchat",o=W(`customers.sources.${r}`);return o===`customers.sources.${r}`?t.charAt(0).toUpperCase()+t.slice(1):o},d=(t,l)=>{const r=W(`customers.${t}`);return r===`customers.${t}`?l:r},x={title:d("title",s==="tr"?"MüÅteriler":"Customers"),subtitle:d("subtitle",s==="tr"?"MüÅteri iliÅkilerinizi yönetin ve takip edin":"Manage and track your customer relationships"),addCustomer:d("addCustomer",s==="tr"?"+ MüÅteri Ekle":"+ Add Customer"),search:d("search",s==="tr"?"İsim, telefon, servis ara...":"Search by name, phone, service..."),filter:d("filter",s==="tr"?"Filtrele":"Filter"),totalCustomers:d("totalCustomers",s==="tr"?"Toplam MüÅteri":"Total Customers"),activeCustomers:d("activeCustomers",s==="tr"?"Aktif müÅteri tabanı":"Active customer base"),highQuality:d("highQuality",s==="tr"?"Yüksek Kalite Potansiyeli":"High Quality Potential"),highQualityDesc:d("highQualityDesc",s==="tr"?"70+ puanlı potansiyeller":"70+ scored prospects"),activeConversations:d("activeConversations",s==="tr"?"Aktif KonuÅmalar":"Active Conversations"),activeConversationsDesc:d("activeConversationsDesc",s==="tr"?"EtkileÅimli müÅteriler":"Interactive customers"),avgScore:d("avgScore",s==="tr"?"Ortalama Potansiyel Puanı":"Average Potential Score"),avgScoreDesc:d("avgScoreDesc",s==="tr"?"Genel kalite metriÄi":"Overall quality metric"),allCustomers:d("allCustomers",s==="tr"?"Tüm MüÅteriler":"All Customers"),high:d("high",s==="tr"?"Yüksek (70+)":"High (70+)"),medium:d("medium",s==="tr"?"Orta (40-69)":"Medium (40-69)"),low:d("low",s==="tr"?"DüÅük (0-39)":"Low (0-39)"),customer:d("customer",s==="tr"?"MüÅteri":"Customer"),potentialScore:d("potentialScore",s==="tr"?"Potansiyel Puanı":"Potential Score"),stage:d("stage",s==="tr"?"AÅama":"Stage"),conversations:d("conversations",s==="tr"?"KonuÅmalar":"Conversations"),lastContact:d("lastContact",s==="tr"?"Son İletiÅim":"Last Contact"),source:d("source",s==="tr"?"Kaynak":"Source"),actions:d("actions",s==="tr"?"İÅlemler":"Actions"),noCustomers:d("noCustomers",s==="tr"?"MüÅteri bulunamadı":"No customers found"),viewConversation:d("viewConversation",s==="tr"?"KonuÅmayı Görüntüle":"View Conversation"),edit:d("edit",s==="tr"?"Düzenle":"Edit"),delete:d("delete",s==="tr"?"Sil":"Delete"),editCustomer:d("editCustomer",s==="tr"?"MüÅteriyi Düzenle":"Edit Customer"),name:d("name",s==="tr"?"İsim":"Name"),email:d("email",s==="tr"?"E-posta":"Email"),save:d("save",s==="tr"?"Kaydet":"Save"),cancel:d("cancel",s==="tr"?"İptal":"Cancel"),dateFilters:{all:d("dateFilters.all",s==="tr"?"Tüm Zamanlar":"All Time"),today:d("dateFilters.today",s==="tr"?"Bugün":"Today"),yesterday:d("dateFilters.yesterday",s==="tr"?"Dün":"Yesterday"),last7:d("dateFilters.last7",s==="tr"?"Son 7 Gün":"Last 7 Days"),last14:d("dateFilters.last14",s==="tr"?"Son 14 Gün":"Last 14 Days")}},$t=t=>{if(c==="all")return!0;const l=t.last_interaction_date||t.updated_at||t.created_at;if(!l)return!1;const r=new Date(l);if(isNaN(r.getTime()))return!1;const o=new Date,h=new Date(o.getFullYear(),o.getMonth(),o.getDate()),b=new Date(r.getFullYear(),r.getMonth(),r.getDate());switch(c){case"today":return b.getTime()===h.getTime();case"yesterday":const v=new Date(h);return v.setDate(v.getDate()-1),b.getTime()===v.getTime();case"last7":const M=new Date(h);return M.setDate(M.getDate()-7),b>=M;case"last14":const q=new Date(h);return q.setDate(q.getDate()-14),b>=q;default:return!0}},It=t=>[...t].sort((l,r)=>{let o,h;switch(p){case"name":o=l.customer_name||"",h=r.customer_name||"";break;case"score":o=l.lead_score||0,h=r.lead_score||0;break;case"stage":o=l.customer_stage||"",h=r.customer_stage||"";break;case"messages":o=l.total_messages||0,h=r.total_messages||0;break;case"lastContact":o=new Date(l.last_interaction_date||l.updated_at||l.created_at||0),h=new Date(r.last_interaction_date||r.updated_at||r.created_at||0);break;default:return 0}return o<h?S==="asc"?-1:1:o>h?S==="asc"?1:-1:0}),re=t=>{p===t?j(S==="asc"?"desc":"asc"):(T(t),j("desc"))},ze=[c!=="all",N.length>0,f.length>0,Q.length>0,w>0||R<100,te.length>0,se.length>0,oe.trim().length>
20].filter(Boolean).length,Rt=()=>{y("all"),P([]),D([]),Ee([]),F(0),Le(100),Me([]),Ae([]),Fe("")},ne=m.useMemo(()=>{const t=new Set((B==null?void 0:B.phones)||[]),l=new Set(((B==null?void 0:B.names)||[]).map(r=>r.toLowerCase().trim()));return It(E.filter(r=>{var Xe,et,tt,st,at;const o=n.toLowerCase(),h=!o||((Xe=r.customer_name)==null?void 0:Xe.toLowerCase().includes(o))||((et=r.email)==null?void 0:et.toLowerCase().includes(o))||((tt=r.phone)==null?void 0:tt.includes(n))||((st=r.notes)==null?void 0:st.toLowerCase().includes(o))||(r.phone?t.has(r.phone):!1)||l.has(((at=r.customer_name)==null?void 0:at.toLowerCase().trim())||""),b=de(r),v=(b==null?void 0:b.slug)||r.customer_stage||"visitor",M=u==="all"||v===u,q=$t(r),Bt=N.length===0||N.includes(r.lead_source||"webchat"),Vt=f.length===0||f.includes(v),Ht=Q.length===0||Q.some(rt=>{var nt;return(nt=r.agent_interactions)==null?void 0:nt.some(Jt=>Jt.agent_id===rt)})||Q.includes(r.agent_id??""),Je=r.lead_score??0,Gt=Je>=w&&Je<=R,L=r.ai_profile,Qt=te.length===0||te.includes(L==null?void 0:L.sentiment),Wt=se.length===0||se.includes(L==null?void 0:L.purchase_intent),Ze=oe.trim().toLowerCase(),Yt=!Ze||(L?[L.summary,L.conversation_summary,L.personality,L.communication_style,L.family_info,(L.key_topics||[]).join(" "),(L.special_notes||[]).join(" "),(L.what_makes_happy||[]).join(" "),(L.what_frustrates||[]).join(" "),(L.important_moments||[]).join(" ")].filter(Boolean).join(" ").toLowerCase().includes(Ze):!1);return h&&M&&q&&Bt&&Vt&&Ht&&Gt&&Qt&&Wt&&Yt}))},[E,n,u,c,N,f,Q,w,R,te,se,oe,p,S,B,ve,Ne,we]),Ut=()=>{const t=[s==="tr"?"MüÅteri":"Customer","Email",s==="tr"?"Telefon":"Phone",s==="tr"?"AÅama":"Stage",s==="tr"?"Puan":"Score",s==="tr"?"Mesajlar":"Messages",s==="tr"?"KonuÅmalar":"Conversations",s==="tr"?"Kaynak":"Source",s==="tr"?"Son İletiÅim":"Last Contact",s==="tr"?"Notlar":"Notes"],l=ne.map(v=>[v.customer_name||"",v.email||"",v.phone||"",Ce(v),v.lead_score??0,v.total_messages??0,v.total_conversations??0,v.lead_source||"webchat",v.last_interaction_date?new Date(v.last_interaction_date).toLocaleDateString(s==="tr"?"tr-TR":"en-US"):"",(v.notes||"").replace(/[\n\r]/g," ")]),r=[t,...l].map(v=>v.map(M=>`"${String(M).replace(/"/g,'""')}"`).join(",")).join(` 3`),o=new Blob(["\uFEFF"+r],{type:"text/csv;charset=utf-8;"}),h=URL.createObjectURL(o),b=document.createElement("a");b.href=h,b.download=`musteriler_${new Date().toISOString().slice(0,10)}.csv`,b.click(),URL.revokeObjectURL(h)},qt=(I==null?void 0:I.customerCount)??E.length,Ot=E.filter(t=>(t.lead_score??0)>=70).length,Kt=E.filter(t=>(t.total_conversations??0)>0).length,zt=E.length>0?Math.round(E.reduce((t,l)=>t+(l.lead_score??0),0)/E.length):0,ue=t=>{ce(t)},Be=t=>{if(!t)return s==="tr"?"Tarih yok":"No date";const l=typeof t=="string"?new Date(t):t;return isNaN(l.getTime())?s==="tr"?"Geçersiz tarih":"Invalid date":l.toLocaleDateString(s==="tr"?"tr-TR":"en-US",{month:"short",day:"numeric",year:"numeric"})},Ve=t=>{t.conversation_id?window.open(`/chats/${t.conversation_id}`,"_blank","noopener,noreferrer"):window.open("/chats","_blank","noopener,noreferrer")};return Re&&console.error("[CUSTOMERS PAGE] Query error:",Re),Mt?e.jsx(es,{}):e.jsxs("div",{className:"container mx-auto p-6 space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:x.title}),e.jsx("p",{className:"text-gray-600 mt-1",children:x.subtitle})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center border rounded-lg p-0.5 bg-muted/50",children:[e.jsxs(A,{variant:a==="kanban"?"default":"ghost",size:"sm",onClick:()=>i("kanban"),className:"gap-1.5 h-8",children:[e.jsx(ks,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:s==="tr"?"Kanban":"Pipeline"})]}),e.jsxs(A,{variant:a==="table"?"default":"ghost",size:"sm",onClick:()=>i("table"),className:"gap-1.5 h-8",children:[e.jsx(_s,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:s==="tr"?"Tablo":"Table"})]})]}),a==="table"&&e.jsxs(A,{variant:"outline",size:"sm",className:"h-8 gap-1.5",onClick:Ut,title:s==="tr"?"Tabloyu CSV olarak indir":"Download table as CSV",children:[e.jsx(Ss,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"CSV"})]}),e.jsx(Is,{pipelineStages:U,onSuccess:()=>Ue()}),e.jsx(A,{variant:"outline",size:"sm",onClick:Pt,disabled:$e,className:"h-8",children:$e?e.jsx(Ts,{className:"h-4 w-4 animate-spin"}):e.jsx(Ds,{className:"h-4 w-4"})}),e.jsxs(A,{variant:"outline",size:"sm",className:"h-8 gap-1.5",onClick:()=>Et("/customers/settings"),children:[e.jsx(Ls,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:s==="tr"?"Ayarlar":"Settings"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs(J,{children:[e.jsxs(xe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(pe,{className:"text-sm font-medium text-gray-600",children:x.totalCustomers}),e.jsx(yt,{className:"h-4 w-4 text-gray-400"})]}),e.jsxs(le,{children:[e.jsx("div",{className:"text-2xl font-bold",children:qt}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:x.activeCustomers})]})]}),e.jsxs(J,{children:[e.jsxs(xe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(pe,{className:"text-sm font-medium text-gray-600",children:x.highQuality}),e.jsx(Es,{className:"h-4 w-4 text-green-600"})]}),e.jsxs(le,{children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:Ot}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:x.highQualityDesc})]})]}),e.jsxs(J,{children:[e.jsxs(xe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(pe,{className:"text-sm font-medium text-gray-600",children:x.activeConversations}),e.jsx(he,{className:"h-4 w-4 text-blue-600"})]}),e.jsxs(le,{children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:Kt}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:x.activeConversationsDesc})]})]}),e.jsxs(J,{children:[e.jsxs(xe,{className:"flex flex-row items-center justify-between space-y-0 pb-2",children:[e.jsx(pe,{className:"text-sm font-medium text-gray-600",children:x.avgScore}),e.jsx(Ms,{className:"h-4 w-4 text-purple-600"})]}),e.jsxs(le,{children:[e.jsx("div",{className:"text-2xl font-bold text-purple-600",children:zt}),e.jsx("p",{className:"text-xs text-gray-600 mt-1",children:x.avgScoreDesc})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(As,{className:"absolute left-3 top-3 h-4 w-4 text-gray-400"}),e.jsx(ct,{placeholder:x.search,value:n,onChange:t=>k(t.target.value),className:"pl-10"})]}),e.jsxs("div",{className:"relative w-52",children:[e.jsx("span",{className:"absolute left-3 top-2.5 text-sm",children:"ð"}),e.jsx(ct,{placeholder:s==="tr"?"AI kelime: KPSS, fiyat...":"AI keyword: urgent...",value:oe,onChange:t=>Fe(t.target.value),className:"pl-8 text-sm"})]}),ze>0&&e.jsxs(A,{variant:"ghost",size:"sm",onClick:Rt,className:"text-xs text-muted-foreground hover:text-red-500 shrink-0",children:[s==="tr"?"Temizle":"Clear"," (",ze,")"]})]}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsxs(gt,{value:c,onValueChange:t=>y(t),children:[e.jsx(ft,{className:`h-8 w-auto text-xs gap-1 px-2 ${c!=="all"?"border-purple-400 bg-purple-50 text-purple-700":"border-dashed text-muted-foreground"}`,children:e.jsx(jt,{})}),e.jsxs(bt,{children:[e.jsx($,{value:"all",children:x.dateFilters.all}),e.jsx($,{value:"today",children:x.dateFilters.today}),e.jsx($,{value:"yesterday",children:x.dateFilters.yesterday}),e.jsx($,{value:"last7",children:x.dateFilters.last7}),e.jsx($,{value:"last14",children:x.dateFilters.last14})]})]}),e.jsx(ie,{label:s==="tr"?"Kaynak":"Source",selected:N,onChange:P,options:[{value:"webchat",label:s==="tr"?"Web Sohbet":"Web Chat"},{value:"whatsapp",label:"WhatsApp"},{value:"instagram",label:"Instagram"},{value:"facebook",label:"Facebook"},{value:"contact-card",label:"Contact Card"}]}),e.jsx(ie,{label:s==="tr"?"AÅama":"Stage",selected:f,onChange:D,options:U.length>0?U.map(t=>({value:t.slug,label:t.name})):[{value:"visitor",label:W("customers.stages.visitor")},{value:"lead",label:W("customers.stages.lead")},{value:"customer",label:W("customers.stages.customer")},{value:"hot_lead",label:W("customers.stages.advocate")},{value:"my_customer",label:s==="tr"?"MüÅterim":"My Customer"}]}),qe.length>0&&e.jsx(ie,{label:s==="tr"?"Ajan":"Agent",selected:Q,onChange:Ee,options:qe.map(t=>({value:t.id,label:t.name}))}),e.jsx(ie,{label:s==="tr"?"ð§ Duygu":"ð§ Sentiment",selected:te,onChange:t=>Me(t),options:[{value:"positive",label:`ð ${s==="tr"?"Pozitif":"Positive"}`},{value:"neutral",label:`ð ${s==="tr"?"Nötr":"Neutral"}`},{value:"negative",label:`ð ${s==="tr"?"Negatif":"Negative"}`}]}),e.jsx(ie,{label:s==="tr"?"ð¯ Niyet":"ð¯ Intent",selected:se,onChange:t=>Ae(t),options:[{value:"high",label:`ð¥ ${s==="tr"?"Yüksek":"High"}`},{value:"medium",label:`ð ${s==="tr"?"Orta":"Medium"}`},{value:"low",label:`âï¸ ${s==="tr"?"DüÅük":"Low"}`}]}),e.jsxs("div",{className:`flex items-center gap-1.5 text-xs border rounded-md px-2 h-8 ${w>0||R<100?"border-purple-400 bg-purple-50 text-purple-700":"border-dashed text-muted-foreground"}`,children:[e.jsxs("span",{children:[s==="tr"?"Puan":"Score",":"]}),e.jsx(vs,{value:[w,R],onValueChange:t=>{F(t[0]),Le(t[1])},max:100,min:0,step:5,className:"w-20"}),e.jsxs("span",{className:"font-medium",children:[w,"â",R]})]})]})]}),a==="kanban"&&e.jsx(Qs,{customers:ne,language:s,onCustomerClick:t=>ue(t)}),a==="table"&&e.jsxs(hs,{value:u,onValueChange:g,className:"w-full",children:[e.jsxs(gs,{className:"flex flex-wrap h-auto gap-1 bg-muted/50 p-1 rounded-lg w-full",children:[e.jsxs(mt,{value:"all",className:"text-xs sm:text-sm flex-shrink-0",children:[x.allCustomers," (",E.length,")"]}),U.map(t=>{const l=E.filter(r=>{const o=de(r);return((o==null?void 0:o.slug)||r.customer_stage||"visitor")===t.slug}).length;return e.jsxs(mt,{value:t.slug,className:"text-xs sm:text-sm flex-shrink-0 gap-1.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full shrink-0 hidden sm:inline-block",style:{backgroundColor:t.color}}),t.name," (",l,")"]},t.slug)})]}),e.jsx(fs,{value:u,className:"mt-6",children:ne.length===0?e.jsx(J,{children:e.jsxs(le,{className:"flex flex-col items-center justify-center py-16",children:[e.jsx(yt,{className:"h-12 w-12 text-gray-400 mb-4"}),e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-2",children:x.noCustomers}),e.jsx("p",{className:"text-gray-600 text-center max-w-md",children:n?s==="tr"?"Arama kriterlerinize uygun müÅteri bulunamadı":"No customers found matching your search criteria":s==="tr"?"Henüz müÅteri bulunmuyor":"No customers yet"})]})}):e.jsxs(J,{children:[e.jsx("div",{className:"hidden lg:block overflow-x-auto",children:e.jsxs(js,{children:[e.jsx(bs,{children:e.jsxs(ut,{children:[e.jsx(V,{className:"cursor-pointer",onClick:()=>re("name"),children:e.jsxs("div",{className:"flex items-center",children:[x.customer,e.jsx(X,{className:"ml-2 h-4 w-4"})]})}),e.jsx(V,{className:"cursor-pointer",onClick:()=>re("score"),children:e.jsxs("div",{className:"flex items-center",children:[x.potentialScore,e.jsx(X,{className:"ml-2 h-4 w-4"})]})}),e.jsx(V,{className:"cursor-pointer",onClick:()=>re("stage"),children:e.jsxs("div",{className:"flex items-center",children:[x.stage,e.
3jsx(X,{className:"ml-2 h-4 w-4"})]})}),e.jsx(V,{className:"cursor-pointer",onClick:()=>re("messages"),children:e.jsxs("div",{className:"flex items-center",children:[d("messages","Messages"),e.jsx(X,{className:"ml-2 h-4 w-4"})]})}),e.jsx(V,{className:"cursor-pointer",onClick:()=>re("lastContact"),children:e.jsxs("div",{className:"flex items-center",children:[x.lastContact,e.jsx(X,{className:"ml-2 h-4 w-4"})]})}),e.jsx(V,{children:x.source}),e.jsx(V,{children:x.actions})]})}),e.jsx(ys,{children:ne.map(t=>{var l,r,o,h;return e.jsxs(ut,{className:"cursor-pointer hover:bg-muted/60",onClick:()=>ue(t),children:[e.jsx(H,{children:e.jsxs("div",{className:"flex items-center space-x-3",children:[e.jsx("div",{className:"flex-shrink-0 h-10 w-10",children:e.jsx("div",{className:"h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center",children:e.jsx("span",{className:"text-purple-600 font-medium text-sm",children:((r=(l=t.customer_name)==null?void 0:l.charAt(0))==null?void 0:r.toUpperCase())||"T"})})}),e.jsxs("div",{children:[e.jsxs("div",{className:"font-medium text-sm flex items-center gap-1.5 flex-wrap",children:[t.customer_name||"Unknown Customer",t.business_name&&e.jsx("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-purple-100 text-purple-700 dark:bg-purple-900/60 dark:text-purple-300 font-semibold",children:t.business_name}),t.is_vip&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-amber-100 text-amber-700 dark:bg-amber-900/60 dark:text-amber-400 font-semibold",children:[e.jsx(vt,{className:"h-2.5 w-2.5"}),"VIP"]}),t.is_blocked&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-red-100 text-red-700 dark:bg-red-900/60 dark:text-red-400 font-semibold",children:[e.jsx(Te,{className:"h-2.5 w-2.5"}),s==="tr"?"Engelli":"Blocked"]}),t.ai_profile&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-violet-100 text-violet-700 dark:bg-violet-900/60 dark:text-violet-300 font-semibold",children:[e.jsx(De,{className:"h-2.5 w-2.5"}),"AI"]}),((o=me==null?void 0:me[t.id])==null?void 0:o.active_packages)>0&&e.jsxs("span",{className:"inline-flex items-center gap-1 text-[10px] px-1.5 py-0.5 rounded-full bg-purple-100 text-purple-700 dark:bg-purple-900 dark:text-purple-300 font-semibold",children:[e.jsx(Fs,{className:"h-2.5 w-2.5"}),me[t.id].total_remaining," seans"]})]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[t.email||t.phone||(s==="tr"?"İletiÅim bilgisi yok":"No contact info"),((h=t.integration_data)==null?void 0:h.country)&&e.jsxs("span",{className:"ml-1.5 inline-flex items-center text-[10px] px-1.5 py-0.5 rounded-full bg-blue-50 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300 font-medium",children:["ð ",t.integration_data.country]}),ye.slice(0,2).map(b=>{var M,q;const v=(q=(M=t.integration_data)==null?void 0:M.custom_fields)==null?void 0:q[b.id];return v?e.jsxs("span",{className:"ml-1.5 inline-flex items-center text-[10px] px-1.5 py-0.5 rounded-full bg-orange-50 text-orange-700 dark:bg-orange-900/40 dark:text-orange-300 font-medium",children:[b.name,": ",String(v)]},b.id):null})]}),t.tags&&t.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[t.tags.slice(0,3).map(b=>e.jsx("span",{className:`inline-flex items-center text-[10px] px-1.5 py-0.5 rounded-full font-medium ${b.toLowerCase()==="vip"?"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300":b.toLowerCase()==="tekrar"||b.toLowerCase()==="loyal"?"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300":"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300"}`,children:b},b)),t.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-gray-400",children:["+",t.tags.length-3]})]})]})]})}),e.jsx(H,{children:e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(dt,{value:ke(t.lead_score??0),className:"w-16 h-2"}),e.jsx(Se,{variant:ae(t.lead_score??0)==="green"?"default":ae(t.lead_score??0)==="yellow"?"secondary":"destructive",className:"text-xs px-2 py-0.5",children:t.lead_score??0}),e.jsx("span",{className:"text-green-600 text-xs",children:"â"})]})}),e.jsx(H,{children:e.jsx("span",{className:"text-sm font-medium",style:{color:Oe(t)},children:Ce(t)})}),e.jsx(H,{children:e.jsxs("div",{className:"flex items-center space-x-1",children:[e.jsx(he,{className:"h-3 w-3 text-gray-400"}),e.jsx("span",{className:"text-sm",children:t.total_messages??0})]})}),e.jsx(H,{children:e.jsx("span",{className:"text-sm text-gray-500",children:Be(t.last_interaction_date||t.updated_at||t.created_at)})}),e.jsx(H,{children:e.jsx("span",{className:"text-sm text-gray-600",children:Ke(t.lead_source)})}),e.jsx(H,{onClick:b=>b.stopPropagation(),children:e.jsxs(xt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(A,{variant:"ghost",size:"sm",children:e.jsx(Nt,{className:"h-4 w-4"})})}),e.jsxs(ht,{align:"end",children:[e.jsxs(Z,{onClick:()=>Ve(t),children:[e.jsx(wt,{className:"h-4 w-4 mr-2"}),x.viewConversation]}),e.jsxs(Z,{onClick:()=>ue(t),children:[e.jsx(Ct,{className:"h-4 w-4 mr-2"}),x.edit]}),e.jsx(Z,{className:"text-red-600",children:x.delete})]})]})})]},t.id)})})]})}),e.jsx("div",{className:"lg:hidden p-4 border-b bg-gray-50",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(gt,{value:p,onValueChange:t=>{T(t),S==="asc"&&j("desc")},children:[e.jsx(ft,{className:"flex-1",children:e.jsxs("div",{className:"flex items-center",children:[e.jsx(X,{className:"h-4 w-4 mr-2"}),e.jsx(jt,{})]})}),e.jsxs(bt,{children:[e.jsx($,{value:"name",children:x.customer}),e.jsx($,{value:"score",children:x.potentialScore}),e.jsx($,{value:"stage",children:x.stage}),e.jsx($,{value:"messages",children:d("messages","Messages")}),e.jsx($,{value:"lastContact",children:x.lastContact})]})]}),e.jsx(A,{variant:"outline",size:"sm",onClick:()=>j(S==="asc"?"desc":"asc"),className:"px-3",children:S==="asc"?"â
3":"â"})]})}),e.jsx("div",{className:"lg:hidden space-y-4 p-4",children:ne.map(t=>{var l,r,o;return e.jsxs("div",{className:"border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-3 flex-1",children:[e.jsx("div",{className:"flex-shrink-0 h-10 w-10",children:e.jsx("div",{className:"h-10 w-10 rounded-full bg-purple-100 flex items-center justify-center",children:e.jsx("span",{className:"text-purple-600 font-medium text-sm",children:((r=(l=t.customer_name)==null?void 0:l.charAt(0))==null?void 0:r.toUpperCase())||"T"})})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"font-medium text-sm flex items-center gap-1.5 flex-wrap",children:[t.customer_name||"Unknown Customer",t.business_name&&e.jsx("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-purple-100 text-purple-700 dark:bg-purple-900/60 dark:text-purple-300 font-semibold",children:t.business_name}),t.is_vip&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-amber-100 text-amber-700 dark:bg-amber-900/60 dark:text-amber-400 font-semibold",children:[e.jsx(vt,{className:"h-2.5 w-2.5"}),"VIP"]}),t.is_blocked&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-red-100 text-red-700 dark:bg-red-900/60 dark:text-red-400 font-semibold",children:[e.jsx(Te,{className:"h-2.5 w-2.5"}),s==="tr"?"Engelli":"Blocked"]}),t.ai_profile&&e.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[10px] px-1.5 py-0.5 rounded-full bg-violet-100 text-violet-700 dark:bg-violet-900/60 dark:text-violet-300 font-semibold",children:[e.jsx(De,{className:"h-2.5 w-2.5"}),"AI"]})]}),e.jsxs("div",{className:"text-xs text-gray-500 truncate",children:[t.email||t.phone||(s==="tr"?"İletiÅim bilgisi yok":"No contact info"),((o=t.integration_data)==null?void 0:o.country)&&e.jsxs("span",{className:"ml-1.5 inline-flex items-center text-[10px] px-1.5 py-0.5 rounded-full bg-blue-50 text-blue-600 dark:bg-blue-900/40 dark:text-blue-300 font-medium",children:["ð ",t.integration_data.country]}),ye.slice(0,2).map(h=>{var v,M;const b=(M=(v=t.integration_data)==null?void 0:v.custom_fields)==null?void 0:M[h.id];return b?e.jsxs("span",{className:"ml-1.5 inline-flex items-center text-[10px] px-1.5 py-0.5 rounded-full bg-orange-50 text-orange-700 dark:bg-orange-900/40 dark:text-orange-300 font-medium",children:[h.name,": ",String(b)]},h.id):null})]}),t.tags&&t.tags.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mt-1",children:[t.tags.slice(0,3).map(h=>e.jsx("span",{className:`inline-flex items-center text-[10px] px-1.5 py-0.5 rounded-full font-medium ${h.toLowerCase()==="vip"?"bg-amber-100 text-amber-700 dark:bg-amber-900 dark:text-amber-300":h.toLowerCase()==="tekrar"||h.toLowerCase()==="loyal"?"bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300":"bg-gray-100 text-gray-600 dark:bg-gray-800 dark:text-gray-300"}`,children:h},h)),t.tags.length>3&&e.jsxs("span",{className:"text-[10px] text-gray-400",children:["+",t.tags.length-3]})]})]})]}),e.jsxs(xt,{children:[e.jsx(pt,{asChild:!0,children:e.jsx(A,{variant:"ghost",size:"sm",children:e.jsx(Nt,{className:"h-4 w-4"})})}),e.jsxs(ht,{align:"end",children:[e.jsxs(Z,{onClick:()=>Ve(t),children:[e.jsx(wt,{className:"h-4 w-4 mr-2"}),x.viewConversation]}),e.jsxs(Z,{onClick:()=>ue(t),children:[e.jsx(Ct,{className:"h-4 w-4 mr-2"}),x.edit]}),e.jsx(Z,{className:"text-red-600",children:x.delete})]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2 text-sm",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500",children:x.potentialScore}),e.jsxs("div",{className:"flex items-center space-x-2 mt-1",children:[e.jsx(dt,{value:ke(t.lead_score??0),className:"w-16 h-2"}),e.jsx(Se,{variant:ae(t.lead_score??0)==="green"?"default":ae(t.lead_score??0)==="yellow"?"secondary":"destructive",className:"text-xs px-2 py-0.5",children:t.lead_score??0})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500",children:x.stage}),e.jsx("div",{className:"mt-1 text-sm font-medium",style:{color:Oe(t)},children:Ce(t)})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500",children:d("messages","Messages")}),e.jsxs("div",{className:"flex items-center space-x-1 mt-1",children:[e.jsx(he,{className:"h-3 w-3 text-gray-400"}),e.jsx("span",{className:"text-sm",children:t.total_messages??0})]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-xs text-gray-500",children:x.source}),e.jsx("div",{className:"mt-1 text-sm text-gray-600",children:Ke(t.lead_source)})]})]}),e.jsxs("div",{className:"pt-2 border-t",children:[e.jsx("div",{className:"text-xs text-gray-500",children:x.lastContact}),e.jsx("div",{className:"text-sm text-gray-600 mt-1",children:Be(t.last_interaction_date||t.updated_at||t.created_at)})]})]},t.id)})})]})})]}),e.jsx(is,{editingCustomer:Pe,onClose:()=>ce(null),onSaved:()=>ce(null),pipelineStages:U,crmCustomFields:ye,language:s,toast:Dt,hasJasReservation:At,hasJasHotel:Ft})]})}
3export{Tr 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.