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{n as pa,a as _e,k as he,q as Ce,r as k,l as L,j as e,J as ha,e as ga,p as ja,a1 as z,X as fa}from"./index-D7aUILjH.js";import{u as V}from"./useQuery-B3200vY8.js";import{u as O}from"./useMutation-DeBIkaLZ.js";import{T as ya,a as va,b as J,c as ee}from"./tabs-C6hdZLkp.js";import{C as Y,a as Q,b as Z,c as W,d as X}from"./card-oxUuQ4KR.js";import{B as y}from"./button-CXeA2D2_.js";import{S as ne}from"./switch-CTAE2JbQ.js";import{S as Ge}from"./separator-Cvel0jVN.js";import{P as ba}from"./progress-DLe1uYrx.js";import{I as $}from"./input-Drfk04bb.js";import{L as q}from"./label-DgrT_fKd.js";import{B as De}from"./badge-CV1s7q4W.js";import{D as ve,a as be,b as Ne,c as ke,e as we,d as Na}from"./dialog-amhjXjii.js";import{S as de,a as ce,b as me,c as ue,d as I}from"./select-Bu9OtDlF.js";import{P as re}from"./plus-CbAo0upY.js";import{T as Xe}from"./triangle-alert-eLE3PFYh.js";import{P as Me}from"./pencil-MHcAQQV2.js";import{T as ze}from"./trash-2-DNBlVe3t.js";import{C as ka,a as wa,b as _a}from"./collapsible-DyL4yWt-.js";import{Z as xe}from"./zap-CsvAa3DX.js";import{T as Ca}from"./timer-CjC0kzeH.js";import{C as Ie}from"./chart-column-DBOCUarh.js";import{A as Sa,a as Ta}from"./arrow-up-CO_UmRFi.js";import{A as Je}from"./arrow-right-DOH20B1u.js";import{P as Ea}from"./play-DjhvAM1c.js";import{C as Aa}from"./clock-vKgYE8vW.js";import{C as Pa}from"./chevron-up-rcvbF725.js";import{C as Ra}from"./chevron-down-Dd5bwzqM.js";import{S as $a}from"./sparkles-BFfTg9mj.js";import{C as pe}from"./circle-check-jVVRbE65.js";import{C as qa}from"./circle-x-BErokmKW.js";import{T as ea}from"./tag-Du6_ptuF.js";import{A as Da}from"./arrow-left-k1GcTzhs.js";import{U as Ye}from"./users-BszN9G4e.js";import{B as Qe}from"./brain-CCARVyLO.js";import{R as fe}from"./refresh-cw-bFbX4-ca.js";import{U as oe}from"./upload-DRjlxHtQ.js";import{L as La}from"./layout-grid-rajtFzMB.js";import{G as aa}from"./grip-vertical-DY1bZpZ-.js";import{L as H}from"./loader-circle-aqv1FVJR.js";import{T as Ma}from"./table-2-CvtU5tkX.js";import{D as za}from"./download-CnqF9ojT.js";import{R as Ia}from"./rotate-ccw-BWj6_KS-.js";import"./index-DyrCqDEg.js";import"./index-WXM71ork.js";import"./index-DOEqhBvs.js";import"./index-DzfOKn_W.js";import"./index-fqpRnqXi.js";import"./index-BdQq_4o_.js";import"./check-BlEPFiN7.js";import"./index-Ik0kZ3Vh.js";/** 3 * @license lucide-react v0.453.0 - ISC 4 * 5 * This source code is licensed under the ISC license. 6 * See the LICENSE file in the root directory of this source tree. 7 */const Fa=pa("FileUp",[["path",{d:"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z",key:"1rqfz7"}],["path",{d:"M14 2v4a2 2 0 0 0 2 2h4",key:"tnqrlb"}],["path",{d:"M12 12v6",key:"3ahymv"}],["path",{d:"m15 15-3-3-3 3",key:"15xj92"}]]),Oa=["#64748b","#3b82f6","#10b981","#f97316","#8b5cf6","#ef4444","#f59e0b","#06b6d4","#ec4899","#84cc16"];function Ze({value:s,onChange:c}){return e.jsx("div",{className:"flex flex-wrap gap-1.5",children:Oa.map(o=>e.jsx("button",{type:"button",onClick:()=>c(o),className:`w-6 h-6 rounded-full border-2 transition-all ${s===o?"border-gray-800 dark:border-white scale-110":"border-transparent"}`,style:{backgroundColor:o}},o))})}function Ka({stage:s,onEdit:c,onDelete:o,onMoveUp:r,onMoveDown:a,isFirst:i,isLast:p}){const{language:C}=_e();return e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-xl border border-gray-200/80 dark:border-gray-700/60 bg-white dark:bg-gray-800/80 group",children:[e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("button",{onClick:()=>!i&&r(s),disabled:i,className:"text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 disabled:opacity-20 p-0.5",children:e.jsx("svg",{width:"12",height:"8",viewBox:"0 0 12 8",children:e.jsx("path",{d:"M6 0L12 8H0L6 0Z",fill:"currentColor"})})}),e.jsx("button",{onClick:()=>!p&&a(s),disabled:p,className:"text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 disabled:opacity-20 p-0.5",children:e.jsx("svg",{width:"12",height:"8",viewBox:"0 0 12 8",children:e.jsx("path",{d:"M6 8L0 0H12L6 8Z",fill:"currentColor"})})})]}),e.jsx("div",{className:"w-4 h-4 rounded-full shrink-0 border border-gray-200 dark:border-gray-600",style:{backgroundColor:s.color}}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm text-gray-900 dark:text-gray-100",children:s.name}),s.is_default&&e.jsx(De,{variant:"outline",className:"text-[10px] px-1.5 py-0 border-blue-300 text-blue-600",children:C==="tr"?"İlk AÅama":"First Stage"}),s.is_terminal&&e.jsx(De,{variant:"outline",className:"text-[10px] px-1.5 py-0 border-purple-300 text-purple-600",children:C==="tr"?"Son AÅama":"Terminal"})]}),e.jsx("span",{className:"text-[11px] text-muted-foreground font-mono",children:s.slug})]}),e.jsxs("div",{className:"flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity",children:[e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:()=>c(s),children:e.jsx(Me,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-red-500 hover:text-red-600 hover:bg-red-50",onClick:()=>o(s),children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]})]})}function Ua(){const{language:s}=_e(),{toast:c}=he(),o=Ce(),[r,a]=k.useState(null),[i,p]=k.useState({stage:null,customerCount:0,targetStageId:""}),[C,h]=k.useState(!1),[j,_]=k.useState({name:"",color:"#6366f1",is_default:!1,is_terminal:!1}),{data:N,isLoading:E}=V({queryKey:["/api/pipelines/stages"],queryFn:async()=>(await L({url:"/api/pipelines/stages",method:"GET"})).json(),staleTime:60*1e3}),P=(N==null?void 0:N.stages)||[],m=O({mutationFn:async t=>(await L({url:"/api/pipelines/stages",method:"POST",data:t})).json(),onSuccess:()=>{o.invalidateQueries({queryKey:["/api/pipelines/stages"]}),h(!1),_({name:"",color:"#6366f1",is_default:!1,is_terminal:!1}),c({title:s==="tr"?"AÅama eklendi":"Stage added"})},onError:t=>c({title:s==="tr"?"Hata":"Error",description:t.message,variant:"destructive"})}),f=O({mutationFn:async({id:t,...d})=>(await L({url:`/api/pipelines/stages/${t}`,method:"PATCH",data:d})).json(),onSuccess:()=>{o.invalidateQueries({queryKey:["/api/pipelines/stages"]}),a(null),c({title:s==="tr"?"Güncellendi":"Updated"})},onError:t=>c({title:s==="tr"?"Hata":"Error",description:t.message,variant:"destructive"})}),x=O({mutationFn:async t=>(await L({url:"/api/pipelines/stages/reorder",method:"PATCH",data:{order:t}})).json(),onSuccess:()=>o.invalidateQueries({queryKey:["/api/pipelines/stages"]})}),R=O({mutationFn:async({id:t,target_stage_id:d})=>(await L({url:`/api/pipelines/stages/${t}`,method:"DELETE",data:d?{target_stage_id:d}:{}})).json(),onSuccess:()=>{o.invalidateQueries({queryKey:["/api/pipelines/stages"]}),o.invalidateQueries({queryKey:["/api/customers"]}),p({stage:null,customerCount:0,targetStageId:""}),c({title:s==="tr"?"AÅama silindi":"Stage deleted"})},onError:t=>c({title:s==="tr"?"Hata":"Error",description:t.message,variant:"destructive"})}),u=t=>{const d=P.findIndex(T=>T.id===t.id);if(d<=0)return;const b=[...P];[b[d-1],b[d]]=[b[d],b[d-1]],x.mutate(b.map((T,F)=>({id:T.id,position:F})))},v=t=>{const d=P.findIndex(T=>T.id===t.id);if(d>=P.length-1)return;const b=[...P];[b[d],b[d+1]]=[b[d+1],b[d]],x.mutate(b.map((T,F)=>({id:T.id,position:F})))},l=async t=>{var T;const d=await L({url:`/api/pipelines/stages/${t.id}/customer-count`,method:"GET"}),{count:b}=await d.json();p({stage:t,customerCount:b,targetStageId:((T=P.filter(F=>F.id!==t.id)[0])==null?void 0:T.id)||""})},w=()=>{i.stage&&R.mutate({id:i.stage.id,target_stage_id:i.customerCount>
70?i.targetStageId:void 0})};return E?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx(ha,{})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-base",children:s==="tr"?"Pipeline AÅamaları":"Pipeline Stages"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s==="tr"?"MüÅteri aÅamalarınızı özelleÅtirin":"Customize your customer stages"})]}),e.jsxs(y,{size:"sm",onClick:()=>h(!0),className:"gap-1.5",children:[e.jsx(re,{className:"h-4 w-4"}),s==="tr"?"AÅama Ekle":"Add Stage"]})]}),e.jsxs("div",{className:"space-y-2",children:[P.map((t,d)=>e.jsx(Ka,{stage:t,onEdit:b=>a({...b}),onDelete:l,onMoveUp:u,onMoveDown:v,isFirst:d===0,isLast:d===P.length-1},t.id)),P.length===0&&e.jsx("div",{className:"text-center py-12 text-muted-foreground border-2 border-dashed rounded-xl",children:s==="tr"?"Henüz aÅama yok":"No stages yet"})]}),e.jsx(ve,{open:C,onOpenChange:h,children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsx(ke,{children:s==="tr"?"Yeni AÅama Ekle":"Add New Stage"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:s==="tr"?"AÅama Adı":"Stage Name"}),e.jsx($,{value:j.name,onChange:t=>_(d=>({...d,name:t.target.value})),placeholder:s==="tr"?"ör. Nitelikli Lead":"e.g. Qualified Lead"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:s==="tr"?"Renk":"Color"}),e.jsx(Ze,{value:j.color,onChange:t=>_(d=>({...d,color:t}))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(q,{children:s==="tr"?"İlk AÅama":"First Stage"}),e.jsx(ne,{checked:j.is_default,onCheckedChange:t=>_(d=>({...d,is_default:t}))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(q,{children:s==="tr"?"Son AÅama (Terminal)":"Terminal Stage"}),e.jsx(ne,{checked:j.is_terminal,onCheckedChange:t=>_(d=>({...d,is_terminal:t}))})]})]}),e.jsxs(we,{children:[e.jsx(y,{variant:"outline",onClick:()=>h(!1),children:s==="tr"?"İptal":"Cancel"}),e.jsx(y,{onClick:()=>m.mutate(j),disabled:!j.name||m.isPending,children:m.isPending?e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}):s==="tr"?"Ekle":"Add"})]})]})}),e.jsx(ve,{open:!!r,onOpenChange:t=>!t&&a(null),children:e.jsxs(be,{children:[e.jsx(Ne,{children:e.jsx(ke,{children:s==="tr"?"AÅamayı Düzenle":"Edit Stage"})}),r&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:s==="tr"?"AÅama Adı":"Stage Name"}),e.jsx($,{value:r.name||"",onChange:t=>a(d=>({...d,name:t.target.value}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:s==="tr"?"Renk":"Color"}),e.jsx(Ze,{value:r.color||"#6366f1",onChange:t=>a(d=>({...d,color:t}))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(q,{children:s==="tr"?"İlk AÅama":"First Stage"}),e.jsx(ne,{checked:!!r.is_default,onCheckedChange:t=>a(d=>({...d,is_default:t}))})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(q,{children:s==="tr"?"Son AÅama (Terminal)":"Terminal Stage"}),e.jsx(ne,{checked:!!r.is_terminal,onCheckedChange:t=>a(d=>({...d,is_terminal:t}))})]})]}),e.jsxs(we,{children:[e.jsx(y,{variant:"outline",onClick:()=>a(null),children:s==="tr"?"İptal":"Cancel"}),e.jsx(y,{onClick:()=>r&&f.mutate(r),disabled:f.isPending,children:f.isPending?e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white"}):s==="tr"?"Kaydet":"Save"})]})]})}),e.jsx(ve,{open:!!i.stage,onOpenChange:t=>!t&&p({stage:null,customerCount:0,targetStageId:""}),children:e.jsxs(be,{children:[e.jsxs(Ne,{children:[e.jsxs(ke,{className:"flex items-center gap-2",children:[e.jsx(Xe,{className:"h-5 w-5 text-red-500"}),s==="tr"?"AÅamayı Sil":"Delete Stage"]}),e.jsx(Na,{children:i.customerCount>0?s==="tr"?`Bu aÅamada ${i.customerCount} müÅteri var. Silmeden önce taÅınacak aÅamayı seçin.`:`This stage has ${i.customerCount} customers. Select a stage to move them to before deleting.`:s==="tr"?"Bu aÅamayı silmek istediÄinizden emin misiniz?":"Are you sure you want to delete this stage?"})]}),i.customerCount>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(q,{children:s==="tr"?"MüÅterileri TaÅı":"Move Customers To"}),e.jsxs(de,{value:i.targetStageId,onValueChange:t=>p(d=>({...d,targetStageId:t})),children:[e.jsx(ce,{children:e.jsx(me,{})}),e.jsx(ue,{children:P.filter(t=>{var d;return t.id!==((d=i.stage)==null?void 0:d.id)}).map(t=>e.jsx(I,{value:t.id,children:t.name},t.id))})]})]}),e.jsxs(we,{children:[e.jsx(y,{variant:"outline",onClick:()=>p({stage:null,customerCount:0,targetStageId:""}),children:s==="tr"?"İptal":"Cancel"}),e.jsx(y,{variant:"destructive",onClick:w,disabled:R.isPending||i.customerCount>0&&!i.targetStageId,children:s==="tr"?"Sil":"Delete"})]})]})})]})}const Le=[{labelTr:"Gerçek Zamanlı",labelEn:"Real-time",icon:xe,color:"text-purple-600",items:[{value:"new_message",labelTr:"Yeni Mesaj Geldi",labelEn:"New Message Received",descTr:"MüÅteriden her yeni mesaj geldiÄinde",descEn:"Every time the customer sends a message"},{value:"first_contact",labelTr:"İlk Temas",labelEn:"First Contact",descTr:"MüÅteri ilk kez mesaj gönderdiÄinde",descEn:"When the customer messages for the very first time"},{value:"conversation_count",labelTr:"KonuÅma Sayısı",labelEn:"Conversation Count",descTr:"Toplam konuÅma sayısı eÅiÄe ulaÅtıÄında",descEn:"When total conversation count reaches a threshold"}]},{labelTr:"Zamanlı",labelEn:"Time-based",icon:Ca,color:"text-blue-600",items:[{value:"no_reply",labelTr:"Belirli Süre Cevap Yok",labelEn:"No Reply",descTr:"MüÅteri X saat boyunca hiç mesaj atmadıysa",descEn:"If customer has not replied for X hours"},{value:"stage_idle",labelTr:"AÅamada Bekleme",labelEn:"Stage Idle",descTr:"MüÅteri aynı aÅamada X gün hareketsiz kaldıysa",descEn:"If customer has been in the same stage for X days"}]},{labelTr:"Veri Tabanlı",labelEn:"Data-based",icon:Ie,color:"text-green-600",items:[{value:"lead_score_threshold",labelTr:"Lead Skoru EÅiÄi",labelEn:"Lead Score",descTr:"MüÅterinin puanı belirlenen eÅiÄi geçtiÄinde",descEn:"When the customer's score crosses a threshold"},{value:"tag_contains",labelTr:"Etiket Var",labelEn:"Has Tag",descTr:"MüÅteride belirli bir etiket bulunduÄunda",descEn:"When the customer has a specific tag"}]}],sa=Le.flatMap(s=>s.items),ta=[{value:"move_stage",labelTr:"AÅamaya TaÅı",labelEn:"Move to Stage"},{value:"add_tag",labelTr:"Etiket Ekle",labelEn:"Add Tag"},{value:"remove_tag",labelTr:"Etiket Kaldır",labelEn:"Remove Tag"},{value:"notify_member",labelTr:"Ãye Bildir",labelEn:"Notify Member"}];function na(s,c,o){var _;const r=s.trigger_type,a=s.trigger_config||{},i=s.action_type,p=s.action_config||{},C=i==="move_stage"?(_=c.find(N=>N.id===p.stage_id))==null?void 0:_.name:null;let h="";r==="no_reply"?h=o?`${a.hours||72} saat boyunca cevap gelmezse`:`No reply for ${a.hours||72} hours`:r==="stage_idle"?h=o?`${a.days||7}
7 gün aynı aÅamada beklerse`:`Stays in same stage for ${a.days||7} days`:r==="lead_score_threshold"?h=o?`Lead skoru ${a.operator||">="} ${a.threshold||70} olursa`:`Lead score ${a.operator||">="} ${a.threshold||70}`:r==="new_message"?h=o?"Yeni mesaj geldiÄinde":"When new message arrives":r==="first_contact"?h=o?"İlk mesaj geldiÄinde":"On first ever message":r==="conversation_count"?h=o?`${a.count||3} konuÅmaya ulaÅınca`:`On ${a.count||3} total conversations`:r==="tag_contains"&&(h=o?`"${a.tag||"..."}" etiketi varsa`:`Has tag "${a.tag||"..."}"`);let j="";return i==="move_stage"?j=o?`"${C||"..."}" aÅamasına taÅı`:`Move to "${C||"..."}"`:i==="add_tag"?j=o?`"${p.tag||"..."}" etiketini ekle`:`Add tag "${p.tag||"..."}"`:i==="remove_tag"?j=o?`"${p.tag||"..."}" etiketini kaldır`:`Remove tag "${p.tag||"..."}"`:i==="notify_member"&&(j=o?"Ekip üyesine bildir":"Notify team member"),!h&&!j?"":`${h} â ${j}`}function Ha({type:s,config:c,onChange:o,stages:r,tr:a}){return s==="no_reply"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:1,value:c.hours||72,onChange:i=>o({...c,hours:parseInt(i.target.value)}),className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a?"saat":"hours"})]}):s==="stage_idle"?e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:1,value:c.days||7,onChange:i=>o({...c,days:parseInt(i.target.value)}),className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a?"gün":"days"})]}),e.jsxs(de,{value:c.stage_id||"",onValueChange:i=>o({...c,stage_id:i||void 0}),children:[e.jsx(ce,{className:"w-full",children:e.jsx(me,{placeholder:a?"Herhangi bir aÅama":"Any stage"})}),e.jsxs(ue,{children:[e.jsx(I,{value:"",children:a?"Herhangi bir aÅama":"Any stage"}),r.map(i=>e.jsx(I,{value:i.id,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:i.color}}),i.name]})},i.id))]})]})]}):s==="lead_score_threshold"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(de,{value:c.operator||">=",onValueChange:i=>o({...c,operator:i}),children:[e.jsx(ce,{className:"w-20",children:e.jsx(me,{})}),e.jsxs(ue,{children:[e.jsx(I,{value:">=",children:">="}),e.jsx(I,{value:"<=",children:"<="}),e.jsx(I,{value:">",children:">"}),e.jsx(I,{value:"<",children:"<"})]})]}),e.jsx($,{type:"number",min:0,max:100,value:c.threshold||70,onChange:i=>o({...c,threshold:parseInt(i.target.value)}),className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a?"puan":"pts"})]}):s==="conversation_count"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(de,{value:c.operator||">=",onValueChange:i=>o({...c,operator:i}),children:[e.jsx(ce,{className:"w-20",children:e.jsx(me,{})}),e.jsxs(ue,{children:[e.jsx(I,{value:">=",children:">="}),e.jsx(I,{value:"==",children:"="}),e.jsx(I,{value:">",children:">"})]})]}),e.jsx($,{type:"number",min:1,value:c.count||3,onChange:i=>o({...c,count:parseInt(i.target.value)}),className:"w-24"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:a?"konuÅma":"conversations"})]}):s==="tag_contains"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ea,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx($,{value:c.tag||"",onChange:i=>o({...c,tag:i.target.value}),placeholder:a?"etiket adı":"tag name",className:"w-48"})]}):e.jsx("p",{className:"text-xs text-muted-foreground",children:a?"Bu tetikleyici için ek ayar gerekmez.":"No additional config needed."})}function Va({type:s,config:c,onChange:o,stages:r,tr:a}){return s==="move_stage"?e.jsxs(de,{value:c.stage_id||"",onValueChange:i=>o({...c,stage_id:i}),children:[e.jsx(ce,{className:"w-full",children:e.jsx(me,{placeholder:a?"Hedef aÅama seçin":"Select target stage"})}),e.jsx(ue,{children:r.map(i=>e.jsx(I,{value:i.id,children:e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:i.color}}),i.name]})},i.id))})]}):s==="add_tag"||s==="remove_tag"?e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ea,{className:"h-4 w-4 text-muted-foreground shrink-0"}),e.jsx($,{value:c.tag||"",onChange:i=>o({...c,tag:i.target.value}),placeholder:a?"Etiket adı":"Tag name",className:"w-48"})]}):s==="notify_member"?e.jsx($,{value:c.member_id||"",onChange:i=>o({...c,member_id:i.target.value}),placeholder:a?"Ãye UUID":"Member UUID",className:"w-full"}):null}function Ba({ruleId:s,tr:c}){const{data:o}=V({queryKey:["/api/automation/rules",s,"log"],queryFn:async()=>(await L({url:`/api/automation/rules/${s}/log`,method:"GET"})).json(),staleTime:3e4}),r=(o==null?void 0:o.log)||[];return r.length===0?e.jsx("p",{className:"text-xs text-muted-foreground py-2",children:c?"Henüz çalıÅma kaydı yok.":"No execution history yet."}):e.jsx("div",{className:"space-y-1 max-h-48 overflow-y-auto",children:r.map(a=>{var i;return e.jsxs("div",{className:"flex items-center gap-2 text-xs py-1 border-b border-gray-100 dark:border-gray-800 last:border-0",children:[a.result==="success"?e.jsx(pe,{className:"h-3.5 w-3.5 text-green-500 shrink-0"}):e.jsx(qa,{className:"h-3.5 w-3.5 text-red-500 shrink-0"}),e.jsx("span",{className:"text-muted-foreground",children:new Date(a.triggered_at).toLocaleStr
7ing("tr-TR")}),((i=a.customers)==null?void 0:i.customer_name)&&e.jsx("span",{className:"font-medium truncate",children:a.customers.customer_name}),a.error_message&&e.jsx("span",{className:"text-red-500 truncate",children:a.error_message})]},a.id)})})}function Ga({rule:s,stages:c,tr:o,onEdit:r,onDelete:a,onToggle:i,onMoveUp:p,onMoveDown:C,onRunNow:h,isFirst:j,isLast:_}){const[N,E]=k.useState(!1),[P,m]=k.useState(!1),f=sa.find(l=>l.value===s.trigger_type),x=ta.find(l=>l.value===s.action_type),R=s.action_type==="move_stage"?c.find(l=>{var w;return l.id===((w=s.action_config)==null?void 0:w.stage_id)}):null,u=na(s,c,o),v=s.consecutive_errors>=3;return e.jsxs("div",{className:`rounded-xl border transition-all ${s.is_active?"border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-800/80":"border-dashed border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/50 opacity-60"}`,children:[e.jsxs("div",{className:"flex items-start gap-3 p-3",children:[e.jsxs("div",{className:"flex flex-col gap-0.5 mt-0.5 shrink-0",children:[e.jsx("button",{onClick:p,disabled:j,className:"text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 disabled:opacity-20 p-0.5",children:e.jsx(Sa,{className:"h-3 w-3"})}),e.jsx("button",{onClick:C,disabled:_,className:"text-gray-400 hover:text-gray-700 dark:hover:text-gray-200 disabled:opacity-20 p-0.5",children:e.jsx(Ta,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"flex-1 min-w-0 space-y-1.5",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-semibold text-sm",children:s.name}),v&&e.jsxs(De,{variant:"outline",className:"text-[10px] border-red-300 text-red-500 px-1.5 py-0",children:[e.jsx(Xe,{className:"h-2.5 w-2.5 mr-0.5"}),s.consecutive_errors," ",o?"hata":"errors"]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap text-[11px]",children:[e.jsx("span",{className:"font-mono font-bold text-purple-600 text-[10px] bg-purple-50 dark:bg-purple-950/30 px-1.5 py-0.5 rounded",children:"EÄER"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:o?f==null?void 0:f.labelTr:f==null?void 0:f.labelEn}),e.jsx(Je,{className:"h-3 w-3 text-muted-foreground shrink-0"}),e.jsx("span",{className:"font-mono font-bold text-blue-600 text-[10px] bg-blue-50 dark:bg-blue-950/30 px-1.5 py-0.5 rounded",children:"ÃYLEYSE"}),e.jsx("span",{className:"text-gray-700 dark:text-gray-300",children:o?x==null?void 0:x.labelTr:x==null?void 0:x.labelEn}),R&&e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx("span",{className:"w-2 h-2 rounded-full shrink-0",style:{backgroundColor:R.color}}),R.name]})]}),u&&e.jsxs("p",{className:"text-[11px] text-muted-foreground italic",children:['"',u,'"']})]}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[s.trigger_type==="lead_score_threshold"&&e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-green-600 hover:text-green-700 hover:bg-green-50 dark:hover:bg-green-950/30",disabled:P,title:o?"Åimdi ÃalıÅtır":"Run Now",onClick:async()=>{m(!0),await h(),m(!1)},children:e.jsx(Ea,{className:`h-3.5 w-3.5 ${P?"animate-pulse":""}`})}),e.jsx(ne,{checked:s.is_active,onCheckedChange:i}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7",onClick:r,children:e.jsx(Me,{className:"h-3.5 w-3.5"})}),e.jsx(y,{variant:"ghost",size:"icon",className:"h-7 w-7 text-red-500 hover:text-red-600 hover:bg-red-50",onClick:a,children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]})]}),e.jsxs(ka,{open:N,onOpenChange:E,children:[e.jsx(wa,{asChild:!0,children:e.jsxs("button",{className:"w-full flex items-center gap-1.5 px-3 pb-2 text-[11px] text-muted-foreground hover:text-foreground transition-colors",children:[e.jsx(Aa,{className:"h-3 w-3"}),o?"ÃalıÅma GeçmiÅi":"Execution History",N?e.jsx(Pa,{className:"h-3 w-3 ml-auto"}):e.jsx(Ra,{className:"h-3 w-3 ml-auto"})]})}),e.jsx(_a,{children:e.jsx("div",{className:"px-3 pb-3 pt-1 border-t border-gray-100 dark:border-gray-800",children:e.jsx(Ba,{ruleId:s.id,tr:o})})})]})]})}const Ya=[{nameTr:"İlk temas â Potansiyel",nameEn:"First contact â Lead",trigger_type:"first_contact",trigger_config:{},action_type:"move_stage",action_config:{},emoji:"ð"},{nameTr:"3 gün sessizlik â Ziyaretçi",nameEn:"3 day silence â Visitor",trigger_type:"no_reply",trigger_config:{hours:72},action_type:"move_stage",action_config:{},emoji:"ð¶"},{nameTr:"Skor ⥠70 â Sıcak Aday",nameEn:"Score ⥠70 â Hot Lead",trigger_type:"lead_score_threshold",trigger_config:{operator:">=",threshold:70},action_type:"move_stage",action_config:{},emoji:"ð¥"},{nameTr:"VIP etiketi â Ãst aÅama",nameEn:"VIP tag â Upgrade",trigger_type:"tag_contains",trigger_config:{tag:"vip"},action_type:"move_stage",action_config:{},emoji:"â"}];function Qa({open:s,mode:c,rule:o,stages:r,tr:a,onClose:i,onSave:p,isSaving:C}){const[h,j]=k.useState(o),[_,N]=k.useState(c==="add"),E=na(h,r,a),P=m=>{j({...h,name:a?m.nameTr:m.nameEn,trigger_type:m.trigger_type,trigger_config:m.trigger_config,action_type:m.action_type,action_config:m.action_config}),N(!1)};return k.useState(()=>{j(o),N(c==="add")}),Le.find(m=>m.items.some(f=>f.value===h.trigger_type)),sa.find(m=>m.value===h.trigger_type),e.jsx(ve,{open:s,onOpenChange:m=>!m&&i(),children:e.jsxs(be,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[e.jsx(Ne,{children:e.jsxs(ke,{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4 text-purple-600"}),c==="add"?a?"Yeni Kural Ekle":"Add Rule":a?"Kuralı Düzenle":"Edit Rule"]})}),e.jsxs("div",{className:"space-y-5",children:[_&&c==="add"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:a?"Hızlı Å
7ablonlar":"Quick Templates"}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:Ya.map(m=>e.jsxs("button",{onClick:()=>P(m),className:"text-left rounded-lg border border-dashed p-2.5 hover:border-purple-400 hover:bg-purple-50 dark:hover:bg-purple-950/20 transition-all group",children:[e.jsx("div",{className:"text-lg mb-1",children:m.emoji}),e.jsx("p",{className:"text-xs font-medium group-hover:text-purple-700 dark:group-hover:text-purple-300",children:a?m.nameTr:m.nameEn})]},m.nameEn))}),e.jsx("button",{onClick:()=>N(!1),className:"text-xs text-muted-foreground hover:text-foreground underline w-full text-center",children:a?"Sıfırdan oluÅtur":"Build from scratch"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs font-medium",children:a?"Kural Adı":"Rule Name"}),e.jsx($,{value:h.name||"",onChange:m=>j({...h,name:m.target.value}),placeholder:a?"ör. 3 gün sessizlik â Ziyaretçi":"e.g. 3-day silence â Visitor"})]}),e.jsxs("div",{className:"rounded-xl border-2 border-purple-200 dark:border-purple-800 bg-purple-50/40 dark:bg-purple-950/20 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono font-bold text-purple-600 text-xs bg-purple-100 dark:bg-purple-900 px-2 py-0.5 rounded",children:"EÄER"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a?"Åu koÅul saÄlanırsa...":"this condition is met..."})]}),e.jsx("div",{className:"space-y-2",children:Le.map(m=>e.jsxs("div",{children:[e.jsxs("p",{className:"text-[10px] font-semibold text-muted-foreground uppercase tracking-wide mb-1 flex items-center gap-1",children:[e.jsx(m.icon,{className:`h-3 w-3 ${m.color}`}),a?m.labelTr:m.labelEn]}),e.jsx("div",{className:"grid grid-cols-1 gap-1",children:m.items.map(f=>e.jsxs("button",{onClick:()=>j({...h,trigger_type:f.value,trigger_config:{}}),className:`text-left px-3 py-2 rounded-lg border text-xs transition-all ${h.trigger_type===f.value?"border-purple-400 bg-purple-50 dark:bg-purple-950/30 text-purple-700 dark:text-purple-300 font-medium":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,children:[e.jsx("div",{className:"font-medium",children:a?f.labelTr:f.labelEn}),e.jsx("div",{className:"text-muted-foreground text-[10px] mt-0.5",children:a?f.descTr:f.descEn})]},f.value))})]},m.labelEn))}),h.trigger_type&&e.jsxs("div",{className:"pt-1 border-t border-purple-200 dark:border-purple-800",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1.5",children:a?"Parametre":"Parameters"}),e.jsx(Ha,{type:h.trigger_type,config:h.trigger_config||{},onChange:m=>j({...h,trigger_config:m}),stages:r,tr:a})]})]}),e.jsx("div",{className:"flex justify-center",children:e.jsxs("div",{className:"flex flex-col items-center gap-1",children:[e.jsx("div",{className:"w-px h-3 bg-gray-300 dark:bg-gray-600"}),e.jsx(Je,{className:"h-4 w-4 text-muted-foreground rotate-90"}),e.jsx("div",{className:"w-px h-3 bg-gray-300 dark:bg-gray-600"})]})}),e.jsxs("div",{className:"rounded-xl border-2 border-blue-200 dark:border-blue-800 bg-blue-50/40 dark:bg-blue-950/20 p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"font-mono font-bold text-blue-600 text-xs bg-blue-100 dark:bg-blue-900 px-2 py-0.5 rounded",children:"ÃYLEYSE"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:a?"Åunu yap":"do this"})]}),e.jsx("div",{className:"grid grid-cols-2 gap-1.5",children:ta.map(m=>e.jsx("button",{onClick:()=>j({...h,action_type:m.value,action_config:{}}),className:`text-left px-3 py-2 rounded-lg border text-xs transition-all ${h.action_type===m.value?"border-blue-400 bg-blue-50 dark:bg-blue-950/30 text-blue-700 dark:text-blue-300 font-medium":"border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"}`,children:a?m.labelTr:m.labelEn},m.value))}),h.action_type&&e.jsxs("div",{className:"pt-1 border-t border-blue-200 dark:border-blue-800",children:[e.jsx("p",{className:"text-[10px] text-muted-foreground mb-1.5",children:a?"Parametre":"Parameters"}),e.jsx(Va,{type:h.action_type,config:h.action_config||{},onChange:m=>j({...h,action_config:m}),stages:r,tr:a})]})]}),E&&e.jsxs("div",{className:"rounded-lg bg-muted/50 px-3 py-2.5 flex items-start gap-2",children:[e.jsx($a,{className:"h-3.5 w-3.5 text-purple-500 mt-0.5 shrink-0"}),e.jsxs("p",{className:"text-xs text-muted-foreground italic",children:['"',E,'"']})]})]}),e.jsxs(we,{children:[e.jsx(y,{variant:"outline",onClick:i,children:a?"İptal":"Cancel"}),e.jsx(y,{onClick:()=>p(h),disabled:C||!h.name||!h.trigger_type||!h.action_type,children:C?a?"Kaydediliyor...":"Saving...":a?"Kaydet":"Save"})]})]})})}const te=()=>({name:"",trigger_type:"new_message",trigger_config:{},action_type:"move_stage",action_config:{}});function Za(){const{language:s}=_e(),{toast:c}=he(),o=Ce(),r=s==="tr",[a,i]=k.useState({open:!1,mode:"add",rule:te()}),{data:p,isLoading:C}=V({queryKey:["/api/automation/rules"],queryFn:async()=>(await L({url:"/api/automation/rules",method:"GET"})).json(),staleTime:3e4}),{data:h}=V({queryKey:["/api/pipelines/stages"],queryFn:async()=>(await L({url:"/api/pipelines/stages",method:"GET"})).json(),staleTime:6e4}),j=(p==null?void 0:p.rules)||[],_=(h==null?void 0:h.stages)||[],N=O({mutationFn:async u=>(await L({url:"/api/automation/rules",method:"POST",data:u})).json(),onSuccess:()=>{o.invalidateQueries({queryKey:["/api/automation/rules"]}),i({open:!1,mode:"add",rule:te()}),c({title:r?"Kural eklendi":"Rule added"})},onError:u=>c({title:"Error",description:u.message,variant:"destructive"})}),E=O({mutationFn:async({id:u,...v})=>(await L({url:`/api/automation/rules/${u}`,method:"PATCH",data:v})).json(),onSuccess:()=>{o.invalidateQueries({queryKey:["/api/automation/rules"]}),i({open:!1,mode:"add",rule:te()}),c({title:r?"Güncellendi":"Updated"})}}),P=O({mutationFn:async u=>(await L({url:`/api/automation/rules/${u}`,method:"DELETE"})).json(),onSuccess:()=>{o.invalidateQueries({queryKey:["/api/automation/rules"]}),c({title:r?"Kural silindi":"Rule deleted"})}}),m=O({mutationFn:async u=>(await L({url:"/api/automation/rules/reorder",method:"PATCH",data:{order:u}})).json(),onSuccess:()=>o.invalidateQueries({queryKey:["/api/automation/rules"]})}),f=(u,v)=>{const l=[...j].sort((b,T)=>b.rule_order-T.rule_order),w=v==="up"?u-1:u+1;if(w<0||w>=l.length)return;const t=l.map((b,T)=>({id:b.id,rule_order:T})),d=t[u].rule_order;t[u].rule_order=t[w].rule_order,t[w].rule_order=d,m.mutate(t)},x=u=>{a.mode==="add"?N.mutate(u):E.mutate(u)},R=[...j].sort((u,v)=>u.rule_order-v.rule_order);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-lg font-semibold flex items-center gap-2",children:[e.jsx(xe,{className:"h-5 w-5 text-purple-600"}),r?"Otomasyon Kuralları":"Automation Rules"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:r?"MüÅterileri otomatik taÅıyın, etiketleyin ve bildirim gönderin.":"Automatically move, tag, and notify on customers."})]}),e.jsxs(y,{size:"sm",onClick:()=>i({open:!0,mode:"add",rule:te()}),className:"gap-1.5",children:[e.jsx(re,{className:"h-4 w-4"}),r?"Kural Ekle":"Add Rule"]})]}),C?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-purple-600"})}):R.length===0?e.jsxs("div",{className:"text-center py-16 border-2 border-dashed rounded-2xl text-muted-foreground",children:[e.jsx(xe,{className:"h-10 w-10 mx-auto mb-3 opacity-20"}),e.jsx("p",{className:"font-medium",children:r?"Henüz otomasyon kuralı yok":"No automation rules yet"}),e.jsx("p",{className:"text-sm mt-1 mb-4 max-w-xs mx-auto",children:r?'"Kural Ekle" butonuna tıklayarak veya bir Åablon seçerek baÅlayın.':'Click "Add Rule" or pick a quick template to get started.'}),e.jsxs(y,{size:"sm",variant:"outline",onClick:()=>i({open:!0,mode:"add",rule:te()}),className:"gap-1.5",children:[e.jsx(re,{className:"h-4 w-4"}),r?"İlk Kuralı Ekle":"Add First Rule"]})]}):e.jsx("div",{className:"space-y-2",children:R.map((u,v)=>e.jsx(Ga,{rule:u,stages:_,tr:r,onEdit:()=>i({open:!0,mode:"edit",rule:{...u}}),onDelete:()=>P.mutate(u.id),onToggle:l=>E.mutate({id:u.id,is_active:l}),onMoveUp:()=>f(v,"up"),onMoveDown:()=>f(v,"down"),onRunNow:async()=>{try{await L({url:`/api/automation/rules/${u.id}/run-now`,method:"POST"}),c({title:r?"Kural çalıÅtırıldı â":"Rule executed â",description:r?"EÅiÄi geçen tüm müÅteriler iÅleme alındı.":"All matching customers have been processed."}),setTimeout(()=>
7o.invalidateQueries({queryKey:["/api/automation/rules",u.id,"log"]}),2e3)}catch(l){c({title:r?"Hata":"Error",description:l.message,variant:"destructive"})}},isFirst:v===0,isLast:v===R.length-1},u.id))}),e.jsx(Qa,{open:a.open,mode:a.mode,rule:a.rule,stages:_,tr:r,onClose:()=>i({open:!1,mode:"add",rule:te()}),onSave:x,isSaving:N.isPending||E.isPending})]})}function We({options:s,onChange:c,tr:o}){const[r,a]=k.useState(""),i=()=>{const p=r.trim();!p||s.includes(p)||(c([...s,p]),a(""))};return e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:o?"Seçenekler":"Options"}),s.length>0&&e.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map((p,C)=>e.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-0.5 rounded-full bg-purple-100 text-purple-800 dark:bg-purple-900/40 dark:text-purple-200 text-xs font-medium",children:[p,e.jsx("button",{type:"button",onClick:()=>c(s.filter((h,j)=>j!==C)),className:"ml-0.5 hover:text-red-500 transition-colors",children:e.jsx(fa,{className:"h-3 w-3"})})]},C))}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx($,{value:r,onChange:p=>a(p.target.value),onKeyDown:p=>{p.key==="Enter"&&(p.preventDefault(),i())},placeholder:o?"Seçenek yaz, Enter'a bas...":"Type option, press Enter...",className:"h-8 text-sm flex-1"}),e.jsx(y,{type:"button",size:"sm",variant:"outline",className:"h-8 px-2",onClick:i,disabled:!r.trim(),children:e.jsx(re,{className:"h-3.5 w-3.5"})})]})]})}function Wa({tr:s,businessId:c}){const{toast:o}=he(),r=Ce(),[a,i]=k.useState(!1),[p,C]=k.useState({name:"",type:"text",options:[]}),[h,j]=k.useState(null),[_,N]=k.useState({name:"",type:"text",options:[]}),{data:E,isLoading:P}=V({queryKey:["/api/businesses/crm-custom-fields",c],queryFn:async()=>{const{apiRequest:l}=await z(async()=>{const{apiRequest:t}=await import("./index-D7aUILjH.js").then(d=>d.a$);return{apiRequest:t}},__vite__mapDeps([0,1]));return(await l({url:`/api/businesses/${c}/crm-custom-fields`,method:"GET"})).json()},enabled:!!c,staleTime:6e4}),m=(E==null?void 0:E.fields)||[],f=O({mutationFn:async l=>{const{apiRequest:w}=await z(async()=>{const{apiRequest:d}=await import("./index-D7aUILjH.js").then(b=>b.a$);return{apiRequest:d}},__vite__mapDeps([0,1]));return(await w({url:`/api/businesses/${c}/crm-custom-fields`,method:"PUT",data:{fields:l}})).json()},onSuccess:()=>{r.invalidateQueries({queryKey:["/api/businesses/crm-custom-fields",c]}),o({title:s?"Ãzel alanlar kaydedildi":"Custom fields saved"})},onError:l=>o({title:"Hata",description:l.message,variant:"destructive"})}),x=()=>{if(!p.name.trim())return;const l={id:crypto.randomUUID(),name:p.name.trim(),type:p.type,options:p.type==="select"?p.options:void 0};f.mutate([...m,l]),C({name:"",type:"text",options:[]}),i(!1)},R=l=>f.mutate(m.filter(w=>w.id!==l)),u=()=>{_.name.trim()&&(f.mutate(m.map(l=>l.id===h?{...l,name:_.name.trim(),type:_.type,options:_.type==="select"?_.options:void 0}:l)),j(null))},v={text:"Metin",select:"Seçim Listesi",date:"Tarih",number:"Sayı"};return e.jsxs(Y,{className:"max-w-lg",children:[e.jsxs(Q,{children:[e.jsxs(Z,{className:"flex items-center gap-2 text-base",children:[e.jsx(aa,{className:"h-4 w-4 text-purple-600"}),s?"Ãzel MüÅteri Alanları":"Custom Customer Fields"]}),e.jsx(W,{children:s?"Sektörünüze özel alanlar tanımlayın (ör. Emlak: Proje Adı, Daire Tipi). MüÅteri kartında görünür.":"Define industry-specific fields (e.g. Real estate: Project Name, Unit Type). Shown on customer cards."})]}),e.jsxs(X,{className:"space-y-3",children:[P&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(H,{className:"h-4 w-4 animate-spin"}),s?"Yükleniyor...":"Loading..."]}),m.length===0&&!P&&e.jsx("p",{className:"text-sm text-muted-foreground italic",children:s?"Henüz özel alan tanımlanmadı.":"No custom fields defined yet."}),m.map(l=>{var w;return e.jsx("div",{className:"flex items-center gap-2 p-2.5 rounded-lg border bg-muted/30",children:h===l.id?e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx($,{value:_.name,onChange:t=>N(d=>({...d,name:t.target.value})),placeholder:s?"Alan adı":"Field name",className:"h-8 text-sm"}
7),e.jsxs("select",{value:_.type,onChange:t=>N(d=>({...d,type:t.target.value})),className:"w-full h-8 rounded-md border border-input bg-background px-2 text-sm",children:[e.jsx("option",{value:"text",children:s?"Metin":"Text"}),e.jsx("option",{value:"select",children:s?"Seçim Listesi":"Select"}),e.jsx("option",{value:"date",children:s?"Tarih":"Date"}),e.jsx("option",{value:"number",children:s?"Sayı":"Number"})]}),_.type==="select"&&e.jsx(We,{options:_.options,onChange:t=>N(d=>({...d,options:t})),tr:s}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(y,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:u,disabled:f.isPending,children:[f.isPending?e.jsx(H,{className:"h-3 w-3 animate-spin"}):e.jsx(pe,{className:"h-3 w-3 mr-1"}),s?"Kaydet":"Save"]}),e.jsx(y,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>j(null),children:s?"İptal":"Cancel"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("p",{className:"text-sm font-medium truncate",children:l.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s&&v[l.type]||l.type,(w=l.options)!=null&&w.length?` · ${l.options.length} ${s?"seçenek":"options"}`:""]})]}),e.jsx(y,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0",onClick:()=>{j(l.id),N({name:l.name,type:l.type,options:l.options||[]})},children:e.jsx(Me,{className:"h-3.5 w-3.5"})}),e.jsx(y,{size:"icon",variant:"ghost",className:"h-7 w-7 shrink-0 text-destructive hover:text-destructive",onClick:()=>R(l.id),children:e.jsx(ze,{className:"h-3.5 w-3.5"})})]})},l.id)}),a?e.jsxs("div",{className:"space-y-2 p-3 rounded-lg border border-dashed border-purple-300 bg-purple-50/40 dark:bg-purple-950/20",children:[e.jsx($,{value:p.name,onChange:l=>C(w=>({...w,name:l.target.value})),placeholder:s?"Alan adı (ör: Proje Adı)":"Field name (e.g. Project Name)",className:"h-8 text-sm",autoFocus:!0}),e.jsxs("select",{value:p.type,onChange:l=>C(w=>({...w,type:l.target.value})),className:"w-full h-8 rounded-md border border-input bg-background px-2 text-sm",children:[e.jsx("option",{value:"text",children:s?"Metin":"Text"}),e.jsx("option",{value:"select",children:s?"Seçim Listesi":"Select"}),e.jsx("option",{value:"date",children:s?"Tarih":"Date"}),e.jsx("option",{value:"number",children:s?"Sayı":"Number"})]}),p.type==="select"&&e.jsx(We,{options:p.options,onChange:l=>C(w=>({...w,options:l})),tr:s}),e.jsxs("div",{className:"flex gap-1.5",children:[e.jsxs(y,{size:"sm",className:"h-7 text-xs",onClick:x,disabled:f.isPending||!p.name.trim(),children:[f.isPending?e.jsx(H,{className:"h-3 w-3 animate-spin"}):e.jsx(re,{className:"h-3 w-3 mr-1"}),s?"Ekle":"Add"]}),e.jsx(y,{size:"sm",variant:"ghost",className:"h-7 text-xs",onClick:()=>{i(!1),C({name:"",type:"text",optionsText:""})},children:s?"İptal":"Cancel"})]})]}):e.jsxs(y,{size:"sm",variant:"outline",className:"gap-1.5 border-dashed w-full justify-center",onClick:()=>i(!0),children:[e.jsx(re,{className:"h-3.5 w-3.5"}),s?"Yeni Alan Ekle":"Add New Field"]})]})]})}const ye={engagement_per_message:2,max_engagement:40,intent_per_conversation:10,recency_7d_bonus:10,recency_30d_bonus:5,max_intent:35,fit_email_phone:25,fit_email_only:18,fit_phone_only:12,fit_none:5,stage_thresholds:{lead:25,customer:50,hot_lead:70}};function Xa({tr:s}){const{toast:c}=he(),o=Ce(),[r,a]=k.useState(ye),[i,p]=k.useState(!1),{isLoading:C,data:h}=V({queryKey:["/api/automation/scoring-config"],staleTime:3e4,refetchOnMount:!0}),{data:j}=V({queryKey:["/api/pipelines/stages"],staleTime:6e4,refetchOnMount:!1}),_={};for(const x of(j==null?void 0:j.stages)||[])_[x.slug]=x.name;k.useEffect(()=>{const x=h==null?void 0:h.scoring_config;x&&(a({...ye,...x,stage_thresholds:{...ye.stage_thresholds,...x.stage_thresholds||{}}}),p(!1))},[h]);const N=O({mutationFn:async()=>(await L({url:"/api/automation/scoring-config",method:"PATCH",data:{scoring_config:r}})).json(),onSuccess:()=>{o.invalidateQueries({queryKey:["/api/automation/scoring-config"]}),p(!1),c({title:s?"Puan ayarları kaydedildi":"Scoring config saved"})},onError:x=>c({title:"Error",description:x.message,variant:"destructive"})}),E=(x,R)=>{a(u=>({...u,[x]:R})),p(!0)},P=(x,R)=>{a(u=>({...u,stage_thresholds:{...u.stage_thresholds,[x]:R}})),p(!0)},m=()=>{a(ye),p(!0)},f=r.max_engagement+r.max_intent+r.fit_email_phone;return C?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(H,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-6 max-w-2xl",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsxs("h2",{className:"text-base font-semibold flex items-center gap-2",children:[e.jsx(Ie,{className:"h-4 w-4 text-green-600"}),s?"Lead Puan Hesaplama":"Lead Score Calculation"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:s?`Her müÅteri için 0â${f} arasında puan hesaplanır. Bu puanlar aÅama atamalarını belirler.`:`Each customer is scored 0â${f}. Scores determine stage assignments.`})]}),e.jsxs("div",{className:"flex gap-2 shrink-0",children:[e.jsxs(y,{variant:"ghost",size:"sm",onClick:m,className:"gap-1.5 text-muted-foreground",children:[e.jsx(Ia,{className:"h-3.5 w-3.5"}),s?"Sıfırla":"Reset"]}),e.jsxs(y,{size:"sm",onClick:()=>N.mutate(),disabled:!i||N.isPending,className:"gap-1.5",children:[N.isPending?e.jsx(H,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(pe,{className:"h-3.5 w-3.5"}),s?"Kaydet":"Save"]})]})]}),e.jsxs(Y,{children:[e.jsxs(Q,{className:"pb-3",children:[e.jsxs(Z,{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500"}),s?"EtkileÅim Puanı (Engagement)":"Engagement Score"]}),e.jsx(W,{className:"text-xs",children:s?`MüÅterinin toplam mesaj sayısına göre hesaplanır. Max ${r.max_engagement} puan.`:`Based on total message count. Max ${r.max_engagement} points.`})]}),e.jsxs(X,{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs",children:s?"Mesaj baÅına puan":"Points per message"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:1,max:20,value:r.engagement_per_message,onChange:x=>E("engagement_per_message",Number(x.target.value)),className:"w-20"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"puan":"pts"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s?"Varsayılan: 2":"Default: 2"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs",children:s?"Maksimum engagement puanı":"Max engagement points"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:10,max:100,value:r.max_engagement,onChange:x=>E("max_engagement",Number(x.target.value)),className:"w-20"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"puan":"pts"})]}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s?"Varsayılan: 40":"Default: 40"})]})]})]}),e.jsxs(Y,{children:[e.jsxs(Q,{className:"pb-3",children:[e.jsxs(Z,{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-purple-500"}
7),s?"Niyet Puanı (Intent)":"Intent Score"]}),e.jsx(W,{className:"text-xs",children:s?`KonuÅma sayısı ve son etkileÅim tarihine göre. Max ${r.max_intent} puan.`:`Based on conversation count and recency. Max ${r.max_intent} points.`})]}),e.jsxs(X,{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs",children:s?"KonuÅma baÅına puan":"Points per conversation"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:1,max:30,value:r.intent_per_conversation,onChange:x=>E("intent_per_conversation",Number(x.target.value)),className:"w-20"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"puan":"pts"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs",children:s?"Maksimum intent puanı":"Max intent points"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:10,max:100,value:r.max_intent,onChange:x=>E("max_intent",Number(x.target.value)),className:"w-20"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"puan":"pts"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs",children:s?"Son 7 gün bonus":"Last 7-day bonus"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:0,max:20,value:r.recency_7d_bonus,onChange:x=>E("recency_7d_bonus",Number(x.target.value)),className:"w-20"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"puan":"pts"})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs",children:s?"Son 30 gün bonus":"Last 30-day bonus"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:0,max:20,value:r.recency_30d_bonus,onChange:x=>E("recency_30d_bonus",Number(x.target.value)),className:"w-20"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"puan":"pts"})]})]})]})]}),e.jsxs(Y,{children:[e.jsxs(Q,{className:"pb-3",children:[e.jsxs(Z,{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),s?"Profil Puanı (Fit)":"Profile Fit Score"]}),e.jsx(W,{className:"text-xs",children:s?"MüÅterinin iletiÅim bilgilerinin tam olmasına göre.":"Based on how complete the customer's contact info is."})]}),e.jsx(X,{className:"grid grid-cols-2 gap-4",children:[{key:"fit_email_phone",label:s?"Email + Telefon var":"Has Email + Phone"},{key:"fit_email_only",label:s?"Sadece Email var":"Email only"},{key:"fit_phone_only",label:s?"Sadece Telefon var":"Phone only"},{key:"fit_none",label:s?"İletiÅim bilgisi yok":"No contact info"}].map(({key:x,label:R})=>e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(q,{className:"text-xs",children:R}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx($,{type:"number",min:0,max:50,value:r[x],onChange:u=>E(x,Number(u.target.value)),className:"w-20"}),e.jsx("span",{className:"text-xs text-muted-foreground",children:s?"puan":"pts"})]})]},x))})]}),e.jsxs(Y,{children:[e.jsxs(Q,{className:"pb-3",children:[e.jsxs(Z,{className:"text-sm flex items-center gap-2",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-orange-500"}),s?"AÅama EÅikleri":"Stage Thresholds"]}),e.jsx(W,{className:"text-xs",children:s?"Hangi puan aralıÄında hangi aÅama atanır?":"Which score range maps to which stage?"})]}),e.jsxs(X,{className:"space-y-4",children:[(()=>{const x=((j==null?void 0:j.stages)||[]).filter(t=>!t.is_terminal).sort((t,d)=>t.position-d.position),R=["bg-gray-300 dark:bg-gray-600 text-gray-700 dark:text-gray-200","bg-blue-300 dark:bg-blue-700 text-blue-900 dark:text-blue-100","bg-purple-300 dark:bg-purple-700 text-purple-900 dark:text-purple-100","bg-orange-400 dark:bg-orange-600 text-white","bg-green-400 dark:bg-green-600 text-white"],u=["bg-gray-100 border-gray-300 text-gray-700","bg-blue-100 border-blue-300 text-blue-700","bg-purple-100 border-purple-300 text-purple-700","bg-orange-100 border-orange-300 text-orange-700","bg-green-100 border-green-300 text-green-700"],v=t=>r.stage_thresholds[t]??0,l=x.map((t,d)=>{const b=d===0?0:v(t.slug),T=x[d+1],F=T?v(T.slug):f,le=Math.max(0,(F-b)/f)*100;return{stage:t,widthPct:le,colorIdx:d}}),w=x.slice(1).map((t,d)=>({stage:t,colorIdx:d+1,hasKey:r.stage_thresholds[t.slug]!==void 0}));return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"relative h-8 rounded-full overflow-hidden bg-gray-100 dark:bg-gray-800 flex text-[10px] font-medium",children:x.length===0?e.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:s?"AÅama yükleniyor...":"Loading stages..."}):l.map(({stage:t,widthPct:d,colorIdx:b},T)=>e.jsx("div",{className:`flex items-center justify-center ${R[b]||R[R.length-1]} ${T===l.length-1?"flex-1":""}`,style:T<l.length-1?{width:`${d}%`}:void 0,children:t.name},t.id))}),e.jsx("div",{className:`grid gap-4 ${w.length<=2?"grid-cols-2":"grid-cols-3"}`,children:w.map(({stage:t,colorIdx:d,hasKey:b})=>e.jsxs("div",{className:`space-y-1.5 rounded-lg border p-3 ${u[d]||u[u.length-1]}`,children:[e.jsxs(q,{className:"text-xs font-medium",children:[t.name," ",s?"eÅiÄi (min)":"threshold (min)"]}),e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx($,{type:"number",min:0,max:f,value:b?r.stage_thresholds[t.slug]:"",placeholder:b?void 0:"â",onChange:T=>P(t.slug,Number(T.target.value)),className:"w-16 bg-white dark:bg-gray-900 text-sm"}),e.jsx("span",{className:"text-xs opacity-70",children:s?"puan":"pts"})]})]},t.slug))})]})})(),e.jsx("p",{className:"text-[11px] text-muted-foreground",children:s?`Toplam maksimum puan: ${f} (${r.max_engagement} etkileÅim + ${r.max_intent} niyet + ${r.fit_email_phone} profil)`:`Total max score: ${f} (${r.max_engagement} engagement + ${r.max_intent} intent + ${r.fit_email_phone} fit)`})]})]}),i&&e.jsx("div",{className:"flex justify-end",children:e.jsxs(y,{onClick:()=>N.mutate(),disabled:N.isPending,className:"gap-1.5",children:[N.isPending?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(pe,{className:"h-4 w-4"}),s?"DeÄiÅiklikleri Kaydet":"Save Changes"]})})]})}function Zs(){var Oe,Ke,Ue;const[,s]=ga(),{language:c}=_e(),{toast:o}=he(),{activeBusiness:r}=ja(),a=c==="tr",[i,p]=k.useState(!1),[C,h]=k.useState(!1);k.useEffect(()=>{(async()=>{try{const{apiRequest:n}=await z(async()=>{const{apiRequest:A}=await import("./index-D7aUILjH.js").then(D=>D.a$);return{apiRequest:A}},__vite__mapDeps([0,1])),S=await(await n({url:"/api/customers/auto-profile-setting",method:"GET"})).json();p(S.enabled===!0)}catch{p(!1)}})()},[]);const j=async n=>{p(n);try{const{apiRequest:g}=await z(async()=>{const{apiRequest:S}=await import("./index-D7aUILjH.js").then(A=>A.a$);return{apiRequest:S}},__vite__mapDeps([0,1]));await g({url:"/api/customers/auto-profile-setting",method:"PATCH",data:{enabled:n}}),o({title:a?n?"Otomatik Profil Açıldı":"Otomatik Profil Kapatıldı":n?"Auto Profile Enabled":"Auto Profile Disabled"})}catch(g){p(!n),o({title:a?"Hata":"Error",description:g.message,variant:"destructive"})}},_=async()=>{h(!0);try{const{apiRequest:n,queryClient:g}=await z(async()=>{const{apiRequest:D,queryClient:G}=await import("./index-D7aUILjH.js").then(K=>K.a$);return{apiRequest:D,queryClient:G}},__vite__mapDeps([0,1]));(await(await n({url:"/api/customers/generate-profiles",method:"POST",data:{}})).json()).success&&(o({title:a?"Profil OluÅturma BaÅladı":"Profile Generation Started",description:a?"Tüm müÅteriler arka planda iÅleniyor.":"All customers are being processed in the background."}),setTimeout(()=>
7g.invalidateQueries({queryKey:["/api/customers"]}),18e4))}catch(n){o({title:a?"Hata":"Error",description:n.message,variant:"destructive"})}finally{h(!1)}},[N,E]=k.useState(!1),[P,m]=k.useState(0),[f,x]=k.useState(""),R=async()=>{E(!0),m(0),x(a?"Senkronizasyon baÅlatılıyor...":"Starting sync...");try{const{apiRequest:n,queryClient:g}=await z(async()=>{const{apiRequest:S,queryClient:A}=await import("./index-D7aUILjH.js").then(D=>D.a$);return{apiRequest:S,queryClient:A}},__vite__mapDeps([0,1]));m(20),x(a?"MüÅteri verileri senkronize ediliyor...":"Syncing customer data..."),await n({url:"/api/customers/sync",method:"POST"}),m(60),x(a?"AÅamalar ve puanlar güncelleniyor...":"Updating stages and scores..."),await n({url:"/api/customers/recalculate-scores",method:"POST"}),m(90),x(a?"Veriler yükleniyor...":"Loading data..."),await g.invalidateQueries({queryKey:["/api/customers"]}),m(100),x(a?"Tamamlandı!":"Done!")}catch{x(a?"Hata oluÅtu":"Failed"),m(0)}finally{setTimeout(()=>{E(!1),m(0),x("")},2e3)}},[u,v]=k.useState("idle"),[l,w]=k.useState(null),[t,d]=k.useState(null),[b,T]=k.useState(!1),[F,le]=k.useState(!1),[ge,je]=k.useState(null),[M,Se]=k.useState(null),[ae,se]=k.useState(new Set),ie=(r==null?void 0:r.id)||null,{data:Te}=V({queryKey:["/api/businesses/crm-custom-fields",ie],queryFn:async()=>{const{apiRequest:n}=await z(async()=>{const{apiRequest:S}=await import("./index-D7aUILjH.js").then(A=>A.a$);return{apiRequest:S}},__vite__mapDeps([0,1]));return(await n({url:`/api/businesses/${ie}/crm-custom-fields`,method:"GET"})).json()},enabled:!!ie,staleTime:6e4}),ra=(Te==null?void 0:Te.fields)||[],{data:Ee}=V({queryKey:["/api/pipelines/stages",ie],queryFn:async()=>{const{apiRequest:n}=await z(async()=>{const{apiRequest:S}=await import("./index-D7aUILjH.js").then(A=>A.a$);return{apiRequest:S}},__vite__mapDeps([0,1]));return(await n({url:"/api/pipelines/stages",method:"GET"})).json()},enabled:!!ie,staleTime:5*60*1e3}),B=(Ee==null?void 0:Ee.stages)||[],la=((Oe=B[0])==null?void 0:Oe.slug)||"visitor",ia=async n=>{const{getAuthHeaders:g}=await z(async()=>{const{getAuthHeaders:K}=await import("./index-D7aUILjH.js").then(U=>U.a$);return{getAuthHeaders:K}},__vite__mapDeps([0,1])),S=new FormData;S.append("file",n);const A=await g(),D=await fetch("/api/customers/import/analyze",{method:"POST",headers:A,body:S,credentials:"include"}),G=await D.json();if(!D.ok)throw new Error(G.error||`HTTP ${D.status}`);return G},Fe=async(n,g,S=[])=>{const{getAuthHeaders:A}=await z(async()=>{const{getAuthHeaders:Pe}=await import("./index-D7aUILjH.js").then(Re=>Re.a$);return{getAuthHeaders:Pe}},__vite__mapDeps([0,1])),D=new FormData;D.append("file",n),D.append("default_stage",la),g&&D.append("dry_run","true"),S.length>0&&D.append("columns_to_create",JSON.stringify(S));const G=await A(),K=await fetch("/api/customers/upload-contacts",{method:"POST",headers:G,body:D,credentials:"include"}),U=await K.json();if(!K.ok)throw new Error(U.error||`HTTP ${K.status}`);return U},oa=async n=>{var S;const g=(S=n.target.files)==null?void 0:S[0];if(g){n.target.value="",v("analyzing"),Se(null),se(new Set),je(g);try{const A=await ia(g);Se(A),se(new Set(A.unknownColumns||[])),v("analysis")}catch(A){v("idle"),je(null),o({title:a?"Dosya Okunamadı":"File Error",description:A==null?void 0:A.message,variant:"destructive"})}}},da=async()=>{if(ge){v("previewing"),w(null);try{const n=await Fe(ge,!0,Array.from(ae));w({total:n.total,created:n.created,updated:n.updated,skipped:n.skipped,updatedDetails:n.updatedDetails,skippedDetails:n.skippedDetails}),T(!1),le(!1),v("preview")}catch(n){v("analysis"),o({title:a?"Ãnizleme BaÅarısız":"Preview Failed",description:n==null?void 0:n.message,variant:"destructive"})}}},ca=async()=>{if(ge){v("importing");try{const{queryClient:n}=await z(async()=>{const{queryClient:S}=await import("./index-D7aUILjH.js").then(A=>A.a$);return{queryClient:S}},__vite__mapDeps([0,1])),g=await Fe(ge,!1,Array.from(ae));d({total:g.total,created:g.created,updated:g.updated,skipped:g.skipped}),v("done"),je(null),n.invalidateQueries({queryKey:["/api/customers"]}),n.invalidateQueries({queryKey:["/api/businesses/crm-custom-fields"]}),o({title:a?"İçe Aktarma Tamamlandı":"Import Complete",description:a?`${g.created} yeni eklendi, ${g.updated} güncellendi`:`${g.created} added, ${g.updated} updated`})}catch(n){v("preview"),o({title:a?"İçe Aktarma BaÅarısız":"Import Failed",description:n==null?void 0:n.message,variant:"destructive"})}}},ma=()=>{var Ve,Be;const n="\uFEFF",g=ra.map(qe=>qe.name),S=g.map(()=>""),A=["telefon","ad","email","sirket","sehir","ulke","notlar","etiket","aÅama","tarih_olusturuldu","guncelleme_tarihi",...g],D='"vip,tekrar"',G=((Ve=B[0])==null?void 0:Ve.name)||"Ziyaretçiler",K=((Be=B[1])==null?void 0:Be.name)||"Lead",U=new Date().toLocaleDateString("tr-TR",{day:"2-digit",month:"2-digit",year:"numeric"}).replace(/\//g,"."),Pe=["905551234567","Ali Yılmaz","[email protected]","ABC Åirketi","İstanbul","Türkiye","VIP müÅteri",D,G,U,U,...S],Re=["905339876543","AyÅe Kara","","XYZ Ltd","Ankara","","","",K,U,U,...S],ua=[A,Pe,Re].map(qe=>qe.join(",")).join(` 8`),xa=new Blob([n+ua],{type:"text/csv;charset=utf-8;"}),He=URL.createObjectURL(xa),$e=document.createElement("a");$e.href=He,$e.download="musteri_sablonu.csv",$e.click(),URL.revokeObjectURL(He)},Ae=()=>{v("idle"),w(null),d(null),je(null),Se(null),se(new Set),T(!1),le(!1)};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"border-b bg-card/50 backdrop-blur-sm sticky top-0 z-10",children:e.jsxs("div",{className:"max-w-5xl mx-auto px-4 py-3 flex items-center gap-3",children:[e.jsxs(y,{variant:"ghost",size:"sm",onClick:()=>s("/customers"),className:"gap-2",children:[e.jsx(Da,{className:"h-4 w-4"}),a?"MüÅteriler":"Customers"]}),e.jsx(Ge,{orientation:"vertical",className:"h-5"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ye,{className:"h-4 w-4 text-purple-600"}),e.jsx("h1",{className:"font-semibold text-sm",children:a?"MüÅteri Ayarları":"Customer Settings"})]})]})}),e.jsx("div",{className:"max-w-5xl mx-auto px-4 py-6",children:e.jsxs(ya,{defaultValue:"ai",children:[e.jsxs(va,{className:"mb-6 flex-wrap h-auto gap-1",children:[e.jsxs(J,{value:"ai",className:"gap-1.5",children:[e.jsx(Qe,{className:"h-3.5 w-3.5"}),a?"AI Profil":"AI Profile"]}),e.jsxs(J,{value:"sync",className:"gap-1.5",children:[e.jsx(fe,{className:"h-3.5 w-3.5"}),a?"Veri Senkronizasyonu":"Data Sync"]}),e.jsxs(J,{value:"import",className:"gap-1.5",children:[e.jsx(oe,{className:"h-3.5 w-3.5"}),a?"İçe Aktar":"Import"]}),e.jsxs(J,{value:"pipeline",className:"gap-1.5",children:[e.jsx(La,{className:"h-3.5 w-3.5"}),"Pipeline"]}),e.jsxs(J,{value:"automation",className:"gap-1.5",children:[e.jsx(xe,{className:"h-3.5 w-3.5"}),a?"Otomasyon":"Automation"]}),e.jsxs(J,{value:"scoring",className:"gap-1.5",children:[e.jsx(Ie,{className:"h-3.5 w-3.5"}),a?"Puanlama":"Scoring"]}),e.jsxs(J,{value:"fields",className:"gap-1.5",children:[e.jsx(aa,{className:"h-3.5 w-3.5"}),a?"Ãzel Alanlar":"Custom Fields"]})]}),e.jsx(ee,{value:"ai",children:e.jsxs(Y,{className:"max-w-lg",children:[e.jsxs(Q,{children:[e.jsxs(Z,{className:"flex items-center gap-2 text-base",children:[e.jsx(Qe,{className:"h-4 w-4 text-purple-600"}),a?"Yapay Zeka ile Profil OluÅturma":"AI Profile Generation"]}),e.jsx(W,{children:a?"Sohbet geçmiÅinden müÅteri profilleri ve tercihler otomatik çıkarılır.":"Customer profiles and preferences are automatically extracted from chat history."})]}),e.jsxs(X,{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center justify-between rounded-lg border p-4 bg-muted/30",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx("p",{className:"text-sm font-medium",children:a?"Otomatik (Her gece)":"Automatic (Nightly)"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:i?a?"Son 24 saatteki konuÅmalar her gece iÅlenir":"Last 24h conversations processed nightly":a?"Otomatik iÅleme kapalı â manuel çalıÅtırın":"Auto processing off â run manually"})]}),e.jsx(ne,{checked:i,onCheckedChange:j})]}),e.jsx(Ge,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium",children:a?"Manuel ÃalıÅtır":"Run Manually"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:a?"Tüm müÅterilerin profilini hemen günceller. Büyük hesaplarda birkaç dakika sürebilir.":"Updates all customer profiles immediately. May take a few minutes for large accounts."}),e.jsx(y,{onClick:_,disabled:C,variant:"outline",className:"gap-2 border-purple-300 text-purple-700 hover:bg-purple-50",children:C?e.jsxs(e.Fragment,{children:[e.jsx(H,{className:"h-4 w-4 animate-spin"}),a?"İÅleniyor...":"Processing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"h-4 w-4"}),a?"Åimdi ÃalıÅtır":"Run Now"]})})]})]})]})}),e.jsx(ee,{value:"sync",children:e.jsxs(Y,{className:"max-w-lg",children:[e.jsxs(Q,{children:[e.jsxs(Z,{className:"flex items-center gap-2 text-base",children:[e.jsx(fe,{className:"h-4 w-4 text-blue-600"}),a?"Veri Senkronizasyonu":"Data Sync"]}),e.jsx(W,{children:a?"Tüm kanallardan (WhatsApp, Instagram, Web Sohbet) müÅteri verilerini çeker ve puanları yeniden hesaplar."
8:"Syncs customer data from all channels (WhatsApp, Instagram, Webchat) and recalculates scores."})]}),e.jsxs(X,{className:"space-y-4",children:[N&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ba,{value:P,className:"h-2"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:f})]}),e.jsxs(y,{onClick:R,disabled:N,className:"gap-2",children:[N?e.jsx(H,{className:"h-4 w-4 animate-spin"}):e.jsx(fe,{className:"h-4 w-4"}),N?a?"Senkronize Ediliyor...":"Syncing...":a?"Åimdi Senkronize Et":"Sync Now"]})]})]})}),e.jsx(ee,{value:"import",children:e.jsxs(Y,{className:"max-w-lg",children:[e.jsxs(Q,{children:[e.jsxs(Z,{className:"flex items-center gap-2 text-base",children:[e.jsx(oe,{className:"h-4 w-4 text-green-600"}),a?"KiÅi Listesi İçe Aktar":"Import Contacts"]}),e.jsx(W,{children:a?"Excel, CSV veya VCF yükleyin. Telefon numarası eÅleÅen kiÅiler güncellenir, yeniler eklenir.":"Upload Excel, CSV or VCF. Existing contacts matched by phone are updated, new ones added."})]}),e.jsxs(X,{className:"space-y-4",children:[u==="done"&&t&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-2 text-green-600",children:[e.jsx(pe,{className:"h-5 w-5"}),e.jsx("span",{className:"font-medium",children:a?"İçe Aktarma Tamamlandı":"Import Complete"})]}),e.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:a?"Yeni":"New",value:t.created,color:"text-green-600"},{label:a?"Güncellendi":"Updated",value:t.updated,color:"text-blue-600"},{label:a?"Atlandı":"Skipped",value:t.skipped,color:"text-gray-500"}].map(n=>e.jsxs("div",{className:"rounded-lg border p-3 text-center",children:[e.jsx("div",{className:`text-2xl font-bold ${n.color}`,children:n.value}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:n.label})]},n.label))}),e.jsxs(y,{variant:"outline",onClick:Ae,className:"w-full gap-2",children:[e.jsx(oe,{className:"h-4 w-4"}),a?"Yeni Dosya Yükle":"Upload Another File"]})]}),u==="preview"&&l&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsxs("div",{className:"rounded-lg border p-3 text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:l.created}),e.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:a?"Yeni Eklenecek":"To Add"})]}),e.jsxs("div",{className:`rounded-lg border p-3 text-center cursor-pointer transition-colors ${l.updated>0?"hover:bg-blue-50":""}`,onClick:()=>l.updated>0&&T(n=>!n),children:[e.jsx("div",{className:"text-2xl font-bold text-blue-600",children:l.updated}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5 flex items-center justify-center gap-1",children:[a?"Güncellenecek":"To Update",l.updated>0&&e.jsx("span",{className:"text-blue-400",children:b?"â²":"â¼"})]})]}),e.jsxs("div",{className:`rounded-lg border p-3 text-center cursor-pointer transition-colors ${l.skipped>0?"hover:bg-gray-50":""}`,onClick:()=>l.skipped>0&&le(n=>!n),children:[e.jsx("div",{className:"text-2xl font-bold text-gray-500",children:l.skipped}),e.jsxs("div",{className:"text-xs text-muted-foreground mt-0.5 flex items-center justify-center gap-1",children:[a?"DeÄiÅiklik Yok":"No Change",l.skipped>0&&e.jsx("span",{className:"text-gray-400",children:F?"â²":"â¼"})]})]})]}),b&&l.updatedDetails&&l.updatedDetails.length>0&&e.jsxs("div",{className:"rounded-lg border border-blue-200 bg-blue-50/50 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 bg-blue-100/80 text-xs font-semibold text-blue-700 flex items-center justify-between",children:[e.jsx("span",{children:a?"Güncellenecek KiÅiler":"Contacts to Update"}),e.jsx("span",{className:"text-blue-500 font-normal",children:a?"eÅleÅme: telefon veya e-posta":"match: phone or email"})]}),e.jsx("div",{className:"max-h-48 overflow-y-auto divide-y divide-blue-100",children:l.updatedDetails.map((n,g)=>e.jsxs("div",{className:"px-3 py-2 flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"font-medium text-foreground truncate max-w-[140px]",children:n.name||"â"}),n.phone&&e.jsx("span",{className:"text-muted-foreground truncate",children:n.phone}),n.email&&!n.phone&&e.jsx("span",{className:"text-muted-foreground truncate",children:n.email})]}),e.jsx("span",{className:`shrink-0 ml-2 ${n.reason.includes("file_dup")?"text-orange-400":"text-blue-500"}`,children:n.reason==="phone_db"?a?"DB'de mevcut (tel)":"in DB (phone)":n.reason==="email_db"?a?"DB'de mevcut (e-posta)":"in DB (email)":n.reason==="phone_file_dup"?a?"dosyada tekrar (tel)":"file duplicate (phone)":a?"dosyada tekrar (e-posta)":"file duplicate (email)"})]},g))}),l.updated>
8l.updatedDetails.length&&e.jsx("div",{className:"px-3 py-1.5 text-xs text-center text-blue-500 border-t border-blue-100",children:a?`ve ${l.updated-l.updatedDetails.length} kiÅi daha...`:`and ${l.updated-l.updatedDetails.length} more...`})]}),F&&l.skippedDetails&&l.skippedDetails.length>0&&e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-gray-50/50 overflow-hidden",children:[e.jsxs("div",{className:"px-3 py-2 bg-gray-100/80 text-xs font-semibold text-gray-600 flex items-center justify-between",children:[e.jsx("span",{children:a?"DeÄiÅiklik Olmayan KiÅiler":"No-change Contacts"}),e.jsx("span",{className:"text-gray-400 font-normal",children:a?"DB ile aynı veri":"identical to DB"})]}),e.jsx("div",{className:"max-h-48 overflow-y-auto divide-y divide-gray-100",children:l.skippedDetails.map((n,g)=>e.jsxs("div",{className:"px-3 py-2 flex items-center justify-between text-xs",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("span",{className:"font-medium text-foreground truncate max-w-[140px]",children:n.name||"â"}),n.phone&&e.jsx("span",{className:"text-muted-foreground truncate",children:n.phone}),n.email&&!n.phone&&e.jsx("span",{className:"text-muted-foreground truncate",children:n.email})]}),e.jsx("span",{className:"text-gray-400 shrink-0 ml-2",children:a?"deÄiÅiklik yok":"no change"})]},g))}),l.skipped>l.skippedDetails.length&&e.jsx("div",{className:"px-3 py-1.5 text-xs text-center text-gray-400 border-t border-gray-100",children:a?`ve ${l.skipped-l.skippedDetails.length} kiÅi daha...`:`and ${l.skipped-l.skippedDetails.length} more...`})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[a?"Toplam kayıt:":"Total records:"," ",l.total]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{variant:"outline",onClick:Ae,className:"flex-1",children:a?"İptal":"Cancel"}),e.jsxs(y,{onClick:ca,className:"flex-1 gap-2",children:[e.jsx(oe,{className:"h-4 w-4"}),a?"İçe Aktar":"Import"]})]})]}),(u==="analyzing"||u==="previewing"||u==="importing")&&e.jsxs("div",{className:"flex flex-col items-center gap-3 py-6",children:[e.jsx(H,{className:"h-8 w-8 animate-spin text-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:u==="analyzing"?a?"Dosya okunuyor...":"Reading file...":u==="previewing"?a?"Ãnizleme hazırlanıyor...":"Preparing preview...":a?"İçe aktarılıyor...":"Importing..."})]}),u==="analysis"&&M&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 flex-wrap",children:[e.jsxs("div",{className:"flex items-center gap-1.5 bg-blue-50 text-blue-700 rounded-full px-3 py-1 text-xs font-medium",children:[e.jsx(Ye,{className:"h-3.5 w-3.5"}),M.rowCount," ",a?"kayıt":"records"]}),M.emptyPhoneCount>0&&e.jsxs("div",{className:"flex items-center gap-1.5 bg-blue-50 text-blue-600 rounded-full px-3 py-1 text-xs",children:[M.emptyPhoneCount," ",a?"telefonsuz (ad/e-posta ile eÅleÅir)":"no phone (matched by name/email)"]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:a?"Tanınan Kolonlar":"Recognized Columns"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:M.knownColumns.map(({col:n,label:g})=>e.jsxs("span",{className:"flex items-center gap-1 bg-green-50 text-green-700 border border-green-200 rounded px-2 py-0.5 text-xs",children:[e.jsx("span",{className:"text-green-500",children:"â"})," ",n," ",e.jsxs("span",{className:"text-green-500/70",children:["â ",g]})]},n))})]}),M.stageMatches.length>0&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide",children:a?"AÅama EÅleÅmeleri":"Stage Matches"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:M.stageMatches.map(({input:n,matched:g})=>e.jsxs("span",{className:`flex items-center gap-1 rounded px-2 py-0.5 text-xs border ${g?"bg-green-50 text-green-700 border-green-200":"bg-orange-50 text-orange-700 border-orange-200"}`,children:[g?"â":"?"," ",n]},n))}),M.stageMatches.some(n=>!n.matched)&&e.jsx("p",{className:"text-xs text-orange-600",children:a?"? iÅaretli aÅamalar ilk aÅamaya aktarılacak.":"Unmatched stages will use the first stage."})]}),M.unknownColumns.length>0&&e.jsxs("div",{className:"space-y-2 border rounded-lg p-3 bg-purple-50/50 border-purple-100",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("p",{className:"text-xs font-semibold text-purple-800",children:a?"⨠Ãzel Alan Olarak Eklenecek":"⨠Will be created as Custom Fields"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>se(new Set(M.unknownColumns)),className:"text-xs text-purple-600 hover:underline",children:a?"Tümü":"All"}),e.jsx("button",{onClick:()=>se(new Set),className:"text-xs text-muted-foreground hover:underline",children:a?"Hiçbiri":"None"})]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:M.unknownColumns.map(n=>{const g=ae.has(n);return e.jsxs("button",{onClick:()=>{const S=new Set(ae);g?S.delete(n):S.add(n),se(S)},className:`flex items-center gap-1.5 rounded px-2.5 py-1 text-xs border transition-colors ${g?"bg-purple-600 text-white border-purple-600":"bg-white text-muted-foreground border-border hover:border-purple-400"}`,children:[g?"â":"+"," ",n]},n)})}),ae.size>0&&e.jsxs("p",{className:"text-xs text-purple-700",children:[ae.size," ",a?"yeni özel alan oluÅturulacak.":"new custom fields will be created."]})]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsx("button",{onClick:Ae,className:"flex-1 rounded-md border px-4 py-2 text-sm hover:bg-muted transition-colors",children:a?"İptal":"Cancel"}),e.jsxs("button",{onClick:da,className:"flex-1 rounded-md bg-primary text-primary-foreground px-4 py-2 text-sm font-medium hover:bg-primary/90 transition-colors flex items-center justify-center gap-2",children:[e.jsx(oe,{className:"h-4 w-4"}),a?"Devam Et":"Continue"]})]})]}),u==="idle"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("label",{className:"border-2 border-dashed rounded-lg p-6 text-center hover:border-primary/50 transition-colors cursor-pointer flex flex-col items-center gap-2",children:[e.jsx(Fa,{className:"h-8 w-8 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:a?"Dosya seçmek için tıklayın":"Click to select a file"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:".xlsx, .csv, .vcf, .txt"})]}),e.jsx("input",{type:"file",accept:".xlsx,.xls,.csv,.vcf,.vcard,.txt",onCh
8ange:oa,className:"hidden"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("p",{className:"text-xs font-medium flex items-center gap-1",children:[e.jsx(Ma,{className:"h-3.5 w-3.5"}),a?"Excel/CSV Sütun Adları:":"Excel/CSV Column Names:"]}),e.jsxs(y,{variant:"ghost",size:"sm",className:"h-6 text-xs px-2 gap-1",onClick:ma,children:[e.jsx(za,{className:"h-3 w-3"}),a?"Åablon İndir":"Template"]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-x-4 gap-y-0.5 text-xs text-muted-foreground",children:[e.jsxs("span",{children:[e.jsx("strong",{children:"telefon"})," ",a?"(zorunlu)":"(required)"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"ad"})," â ",a?"isim":"name"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"email"})," â ",a?"e-posta":"email"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"sirket"})," â ",a?"Åirket":"company"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"sehir"})," â ",a?"Åehir":"city"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"notlar"})," â ",a?"not":"notes"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"etiket"})," â ",a?"virgülle ayrılmıÅ":"comma-sep"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"aÅama"})," â ",B.length>0?B.map(n=>n.name).join(" / "):a?"aÅama adı":"stage name"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"tarih_olusturuldu"})," â ",a?"oluÅturma tarihi":"date created"]}),e.jsxs("span",{children:[e.jsx("strong",{children:"guncelleme_tarihi"})," â ",a?"son güncelleme":"last modified"]})]}),B.length>0&&e.jsx("p",{className:"text-xs text-muted-foreground pt-1 border-t border-border/50",children:a?`AÅama girilmezse "${(Ke=B[0])==null?void 0:Ke.name}" olarak atanır.`:`If no stage is provided, "${(Ue=B[0])==null?void 0:Ue.name}" is assigned.`})]})]})]})]})}),e.jsx(ee,{value:"pipeline",children:e.jsx(Ua,{})}),e.jsx(ee,{value:"automation",children:e.jsx(Za,{})}),e.jsx(ee,{value:"scoring",children:e.jsx(Xa,{tr:a})}),e.jsx(ee,{value:"fields",children:e.jsx(Wa,{tr:a,businessId:(r==null?void 0:r.id)||""})})]})})]})}export{Zs 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.