PageSourceSearch

https://socialselling.ai/_next/static/chunks/61020.6384c89113a6830a.js

js socialselling.ai collected 2026-10-05 14:51:50 UTC 401,306 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[61020],{61020:function(e,a,s){s.r(a),s.d(a,{default:function(){return aT}});var t=s(57437),l=s(2265),r=s(93448),n=s(99376);s(29762);var i=s(79820),d=s(12381),c=s(69174),o=s(15291),m=s(90641),u=s(40279),x=s(23675),p=s(75060),h=s(32060),g=s(94589),f=s(71488),j=s(60183),b=s(65302),v=s(32489),N=s(99397),w=s(15863),_=s(37806),y=s(69064),k=s(16300),C=s(71837);function S(e){let{onSuccess:a,embedded:s=!1,workspaceId:r,pipelineId:c,pipelineName:m,aiCallingEnabled:x=!1}=e;console.log("[LeadCaptureForm] Rendered with pipelineId:",c,"embedded:",s,"workspaceId:",r,"aiCallingEnabled:",x);let h=(0,n.useRouter)(),[g,f]=(0,l.useState)(!1),[S,Z]=(0,l.useState)(!1),[F,A]=(0,l.useState)(!1),[z,I]=(0,l.useState)(null),[P,D]=(0,l.useState)(!1),[E,L]=(0,l.useState)({name:"",email:"",phone:"",company:"",gender:"",source:s?"manual":"landing_page"}),[R,M]=(0,l.useState)([]),[O,B]=(0,l.useState)(!1),T=()=>{M(e=>[...e,{id:crypto.randomUUID(),key:"",value:""}])},U=e=>{M(a=>a.filter(a=>a.id!==e))},q=(e,a,s)=>{M(t=>t.map(t=>t.id===e?{...t,[a]:s}:t))},V=()=>{let e={};return R.forEach(a=>{a.key.trim()&&a.value.trim()&&(e[a.key.trim()]=a.value.trim())}),e},Q=async function(e){let a=arguments.length>1&&void 0!==arguments[1]&&arguments[1];e.preventDefault(),f(!0),B(a);try{if(!r){y.default.error("Workspace ID is missing. Please refresh the page and try again."),f(!1);return}if(s&&(E.phone||E.email))try{let e=await C.api.post("/leads/check-contact",{phone:E.phone||null,email:E.email||null,pipeline_id:c||null});if(e.data.contact_found){I({contact_id:e.data.contact_id,contact_name:e.data.contact_name,contact_phone:e.data.contact_phone,contact_email:e.data.contact_email,contact_company:e.data.contact_company,has_lead_in_pipeline:e.data.has_lead_in_pipeline,existing_lead_id:e.data.existing_lead_id,existing_lead_name:e.data.existing_lead_name}),A(!0),f(!1);return}}catch(e){console.log("[LeadCaptureForm] Contact check failed, proceeding with normal submission:",e)}await W(void 0,a)}catch(e){console.error("Lead capture exception:",e),y.default.error("An error occurred. Please try again."),f(!1)}},W=async function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];try{let l=localStorage.getItem("access_token"),n={"Content-Type":"application/json"};l&&(n.Authorization="Bearer ".concat(l));let i=new URLSearchParams;c&&i.append("pipeline_id",c);let d=s&&l?"/api/leads/".concat(i.toString()?"?"+i.toString():""):"/api/leads/capture?workspace_id=".concat(r).concat(c?"&pipeline_id="+c:"");console.log("[LeadCaptureForm] Submitting to:",d,"pipelineId:",c,"selfAssign:",t);let o=V(),m={...E,meta_data:Object.keys(o).length>0?o:void 0,pipeline_id:c||void 0,contact_id:e||void 0,self_assign:t},u=await fetch(d,{method:"POST",headers:n,body:JSON.stringify(m)}),x=await u.json();if(u.ok){Z(!0);let e=x.lead||x,t=x.action||"created",l=x.message||"Lead added successfully!";"updated"===t?y.default.success(l,{duration:5e3}):y.default.success("New lead created successfully!"),L({name:"",email:"",phone:"",company:"",gender:"",source:s?"manual":"landing_page"}),M([]),a&&a(e)}else{console.error("Lead capture error:",x);let e="Failed to submit form. Please try again.";if(!1===x.success&&x.message){let a=x.error;e="E3005"===a||"E3002"===a||x.message.toLowerCase().includes("duplicate")?x.message:(null==a?void 0:a.startsWith("E2"))?x.message||"Please check your input and try again.":(null==a?void 0:a.startsWith("E4"))?x.message||"Unable to process request. Please check your subscription.":x.message}else x.detail?"string"==typeof x.detail?e=x.detail:x.detail.message&&(e=x.detail.message):x.error&&"string"==typeof x.error&&!x.error.startsWith("E")?e=x.error:x.details&&(e="string"==typeof x.details?x.details:"Please check your input.");y.default.error(e)}}catch(e){console.error("Lead capture exception:",e),y.default.error("An error occurred. Please try again.")}finally{f(!1)}},Y=(e,a)=>{L(s=>({...s,[e]:a}))},$=async e=>{D(!0);try{await W(e,O),A(!1),I(null)}catch(e){console.error("Failed to add contact to pipeline:",e),y.default.error("Failed to add contact to pipeline")}finally{D(!1)}},K=e=>{A(!1),I(null),h.push("/dashboard/contacts/".concat(e))};return S&&!s?(0,t.jsx)(i.Zb,{className:"max-w-sm mx-auto",children:(0,t.jsx)(i.aY,{className:"pt-6",children:(0,t.jsxs)("div",{className:"text-center py-8",children:[(0,t.jsx)(b.Z,{className:"h-16 w-16 text-green-500 mx-auto mb-4"}),(0,t.jsx)("h3",{className:"text-2xl font-bold mb-2",children:"Thank You!"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"Your information has been received. Our team will reach out to you within 24 hours."})]})})}):s?(0,t.jsxs)("div",{className:"flex flex-col min-h-0 max-h-[60vh]",children:[(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto scrollbar-minimal -mr-4 pr-4 space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"name",className:"text-sm font-medium",children:"Name *"}),(0,t.jsx)(u.I,{id:"name",required:!0,value:E.name,onChange:e=>Y("name",e.target.value),placeholder:"John Doe",className:"h-9"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"email",className:"text-sm font-medium",children:"Email"}),(0,t.jsx)(u.I,{id:"email",type:"email",value:E.email,onChange:e=>Y("email",e.target.value),placeholder:"[email protected]",className:"h-9"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"phone",className:"text-sm font-medium",children:"Phone"}),(0,t.jsx)(j.s,{id:"phone",value:E.phone,onChange:e=>Y("phone",e||""),placeholder:"+91"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"company",className:"text-sm font-medium",children:"Company"}),(0,t.jsx)(u.I,{id:"company",value:E.company,onChange:e=>Y("company",e.target.value),placeholder:"Acme Corp",className:"h-9"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"gender",className:"text-sm font-medium",children:"Gender"}),(0,t.jsxs)(o.Ph,{value:E.gender,onValueChange:e=>Y("gender",e),children:[(0,t.jsx)(o.i4,{className:"h-9",children:(0,t.jsx)(o.ki,{placeholder:"Select"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"male",children:"Male"}),(0,t.jsx)(o.Ql,{value:"female",children:"Female"}),(0,t.jsx)(o.Ql,{value:"other",children:"Other"})]})]})]}),R.length>0&&(0,t.jsx)("div",{className:"pt-3 border-t space-y-2",children:R.map(e=>(0,t.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,t.jsx)(u.I,{placeholder:"Field name",value:e.key,onChange:a=>q(e.id,"key",a.target.value),className:"h-8 text-sm flex-1"}),(0,t.jsx)(u.I,{placeholder:"Value",value:e.value,onChange:a=>q(e.id,"value",a.target.value),className:"h-8 text-sm flex-1"}),(0,t.jsx)("button",{type:"button",className:"h-8 w-8 flex items-center justify-center text-muted-foreground hover:text-destructive hover:bg-destructive/10 rounded transition-colors",onClick:()=>U(e.id),children:(0,t.jsx)(v.Z,{className:"h-4 w-4"})})]},e.id))}),(0,t.jsxs)("button",{type:"button",className:"w-full py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-muted/50 rounded-md border border-dashed border-muted-foreground
1/30 flex items-center justify-center gap-1.5 transition-colors",onClick:T,children:[(0,t.jsx)(N.Z,{className:"h-4 w-4"}),"Add custom field"]})]}),(0,t.jsxs)("div",{className:"flex justify-end gap-2 pt-3 mt-3 border-t flex-shrink-0",children:[!x&&(0,t.jsx)(d.z,{type:"button",onClick:e=>Q(e,!0),disabled:g||S,className:"h-9 px-4 bg-blue-600 hover:bg-blue-700 text-white",children:g&&O?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(_.Z,{className:"mr-1.5 h-4 w-4"}),"Self Assign & Save"]})}),(0,t.jsx)(d.z,{type:"button",onClick:e=>Q(e,!1),disabled:g||S,className:"h-9 px-4",children:g&&!O?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}):S?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(b.Z,{className:"mr-1.5 h-4 w-4"}),"Added!"]}):"Save"})]}),(0,t.jsx)(k.y,{open:F,onOpenChange:A,contactData:z,pipelineName:m,onAddToPipeline:$,onViewContact:K,adding:P})]}):(0,t.jsxs)(i.Zb,{className:"max-w-sm mx-auto",children:[(0,t.jsxs)(i.Ol,{className:"pb-3",children:[(0,t.jsx)(i.ll,{className:"text-xl",children:"Add New Lead"}),(0,t.jsx)(i.SZ,{children:"Enter contact details to create a new lead"})]}),(0,t.jsx)(i.aY,{children:(0,t.jsxs)("form",{onSubmit:e=>{e.preventDefault(),Q(e,!1)},children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"name",className:"text-sm font-medium",children:"Name *"}),(0,t.jsx)(u.I,{id:"name",required:!0,value:E.name,onChange:e=>Y("name",e.target.value),placeholder:"John Doe",className:"h-9"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"email",className:"text-sm font-medium",children:"Email"}),(0,t.jsx)(u.I,{id:"email",type:"email",value:E.email,onChange:e=>Y("email",e.target.value),placeholder:"[email protected]",className:"h-9"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"phone",className:"text-sm font-medium",children:"Phone"}),(0,t.jsx)(j.s,{id:"phone",value:E.phone,onChange:e=>Y("phone",e||""),placeholder:"+91"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"company",className:"text-sm font-medium",children:"Company"}),(0,t.jsx)(u.I,{id:"company",value:E.company,onChange:e=>Y("company",e.target.value),placeholder:"Acme Corp",className:"h-9"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{htmlFor:"gender",className:"text-sm font-medium",children:"Gender"}),(0,t.jsxs)(o.Ph,{value:E.gender,onValueChange:e=>Y("gender",e),children:[(0,t.jsx)(o.i4,{className:"h-9",children:(0,t.jsx)(o.ki,{placeholder:"Select"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"male",children:"Male"}),(0,t.jsx)(o.Ql,{value:"female",children:"Female"}),(0,t.jsx)(o.Ql,{value:"other",children:"Other"})]})]})]}),R.length>0&&(0,t.jsx)("div",{className:"pt-3 border-t space-y-2",children:R.map(e=>(0,t.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,t.jsx)(u.I,{placeholder:"Field name",value:e.key,onChange:a=>q(e.id,"key",a.target.value),className:"h-8 text-sm flex-1"}),(0,t.jsx)(u.I,{placeholder:"Value",value:e.value,onChange:a=>q(e.id,"value",a.target.value),className:"h-8 text-sm flex-1"}),(0,t.jsx)("button",{type:"button",className:"h-8 w-8 flex items-center justify-center text-muted-foreground hover:text-destructive hover:bg-destructive/10 rounded transition-colors",onClick:()=>U(e.id),children:(0,t.jsx)(v.Z,{className:"h-4 w-4"})})]},e.id))}),(0,t.jsxs)("button",{type:"button",className:"w-full py-2 text-sm text-muted-foreground hover:text-foreground hover:bg-muted/50 rounded-md border border-dashed border-muted-foreground/30 flex items-center justify-center gap-1.5 transition-colors",onClick:T,children:[(0,t.jsx)(N.Z,{className:"h-4 w-4"}),"Add custom field"]})]}),(0,t.jsx)("div",{className:"flex justify-end gap-2 pt-3 mt-3 border-t",children:(0,t.jsx)(d.z,{type:"button",onClick:e=>Q(e,!1),disabled:g||S,className:"h-9 px-4",children:g?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}):S?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(b.Z,{className:"mr-1.5 h-4 w-4"}),"Added!"]}):"Save"})})]})}),(0,t.jsx)(k.y,{open:F,onOpenChange:A,contactData:z,pipelineName:m,onAddToPipeline:$,onViewContact:K,adding:P})]})}var Z=s(38251),F=s(53417),A=s(82718),z=s(92451),I=s(91723),P=s(44743),D=s(74291);function E(e){let{channel:a,className:s="h-4 w-4"}=e,l=(a||"").toLowerCase();return"whatsapp"===l?(0,t.jsx)("svg",{className:"".concat(s," text-green-600"),viewBox:"0 0 24 24",fill:"
1currentColor",children:(0,t.jsx)("path",{d:"M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"})}):"instagram"===l?(0,t.jsx)("svg",{className:"".concat(s," text-pink-600"),viewBox:"0 0 24 24",fill:"currentColor",children:(0,t.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"})}):"messenger"===l||"facebook"===l?(0,t.jsx)(F.Z,{className:"".concat(s," text-blue-600")}):(0,t.jsx)(A.Z,{className:"".concat(s," text-gray-500")})}function L(e){let{leadId:a,leadName:s,isOpen:n,onClose:i}=e,[o,u]=(0,l.useState)([]),[p,h]=(0,l.useState)(null),[g,f]=(0,l.useState)([]),[j,b]=(0,l.useState)(""),[v,N]=(0,l.useState)(!1),[_,y]=(0,l.useState)(!1),[k,S]=(0,l.useState)(!1),[Z,F]=(0,l.useState)(null),L=(0,l.useRef)(null),R=(0,l.useRef)(null),M=(0,l.useCallback)(async()=>{if(a){N(!0),F(null);try{let e=(await C.api.get("/leads/".concat(a,"/conversations"))).data||[];u(e),1===e.length&&h(e[0])}catch(e){console.error("Failed to fetch conversations:",e),F("Failed to load conversations")}finally{N(!1)}}},[a]),O=(0,l.useCallback)(async()=>{if(p){y(!0);try{let e=await C.api.get("/conversations/".concat(p.id,"/messages"));f(e.data||[])}catch(e){console.error("Failed to fetch messages:",e),F("Failed to load messages")}finally{y(!1)}}},[p]);(0,l.useEffect)(()=>{n&&a&&M()},[n,a,M]),(0,l.useEffect)(()=>{p&&O()},[p,O]),(0,l.useEffect)(()=>{if(L.current){let e=L.current.querySelector("[data-radix-scroll-area-viewport]");e&&(e.scrollTop=e.scrollHeight)}},[g]),(0,l.useEffect)(()=>{n||(h(null),f([]),u([]),b(""),F(null))},[n]);let B=async()=>{if(!j.trim()||!p)return;S(!0);let e=j.trim();b("");try{await C.api.post("/conversations/".concat(p.id,"/messages"),{content:e}),await O()}catch(a){console.error("Failed to send message:",a),F("Failed to send message"),b(e)}finally{S(!1)}};return(0,t.jsx)(D.Vq,{open:n,onOpenChange:e=>!e&&i(),children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-[500px] h-[600px] flex flex-col p-0",children:[(0,t.jsx)(D.fK,{className:"px-4 py-3 border-b flex-shrink-0",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[p&&o.length>1&&(0,t.jsx)(d.z,{variant:"ghost",size:"icon",className:"h-8 w-8",onClick:()=>{h(null),f([])},children:(0,t.jsx)(z.Z,{className:"h-4 w-4"})}),(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(A.Z,{className:"h-5 w-5"}),p?(0,t.jsxs)("span",{className:"flex items-center gap-2",children:[(0,t.jsx)(E,{channel:p.platform}),s," - ",p.platform]}):(0,t.jsxs)("span",{children:["Chat with ",s]})]})]})}),(0,t.jsx)("div",{className:"flex-1 overflow-hidden",children:v?(0,t.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,t.jsx)(w.Z,{className:"h-8 w-8 animate-spin text-muted-foreground"})}):Z?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-muted-foreground",children:[(0,t.jsx)("p",{children:Z}),(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:M,children:"Retry"})]}):0===o.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-muted-foreground",children:[(0,t.jsx)(A.Z,{className:"h-12 w-12 opacity-50"}
1),(0,t.jsx)("p",{children:"No conversations found"}),(0,t.jsx)("p",{className:"text-sm",children:"Start a conversation from WhatsApp or social media"})]}):p?(0,t.jsxs)("div",{className:"flex flex-col h-full",children:[_?(0,t.jsx)("div",{className:"flex items-center justify-center flex-1",children:(0,t.jsx)(w.Z,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):0===g.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center flex-1 text-muted-foreground",children:[(0,t.jsx)(A.Z,{className:"h-10 w-10 opacity-50 mb-2"}),(0,t.jsx)("p",{children:"No messages yet"})]}):(0,t.jsx)(m.x,{ref:L,className:"flex-1 px-4",children:(0,t.jsx)("div",{className:"py-4 space-y-3",children:g.map(e=>{let a="agent"===e.sender_type||"business"===e.sender_type||"agent"===e.sender;return(0,t.jsx)("div",{className:(0,r.cn)("flex",a?"justify-end":"justify-start"),children:(0,t.jsxs)("div",{className:(0,r.cn)("max-w-[80%] rounded-2xl px-4 py-2",a?"bg-primary text-primary-foreground rounded-br-md":"bg-muted rounded-bl-md"),children:[(0,t.jsx)("p",{className:"text-sm whitespace-pre-wrap break-words",children:e.content||"[No content]"}),(0,t.jsxs)("div",{className:(0,r.cn)("flex items-center gap-1 mt-1 text-xs",a?"text-primary-foreground/70 justify-end":"text-muted-foreground"),children:[(0,t.jsx)(I.Z,{className:"h-3 w-3"}),new Date(e.created_at).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})]})]})},e.id)})})}),(0,t.jsx)("div",{className:"border-t p-3 flex-shrink-0",children:(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(x.g,{ref:R,value:j,onChange:e=>b(e.target.value),onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),B())},placeholder:"Type a message...",className:"min-h-[40px] max-h-[120px] resize-none",rows:1,disabled:k}),(0,t.jsx)(d.z,{size:"icon",onClick:B,disabled:!j.trim()||k,children:k?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(P.Z,{className:"h-4 w-4"})})]})})]}):(0,t.jsx)(m.x,{className:"h-full",children:(0,t.jsx)("div",{className:"p-2 space-y-1",children:o.map(e=>(0,t.jsx)("button",{className:(0,r.cn)("w-full p-3 rounded-lg text-left transition-colors","hover:bg-muted/50 focus:bg-muted/50",e.is_unread&&"bg-blue-50 dark:bg-blue-950/20"),onClick:()=>h(e),children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)(E,{channel:e.platform,className:"h-6 w-6"}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"font-medium capitalize truncate",children:e.platform}),e.last_message_at&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:function(e){let a=new Date(e),s=new Date().getTime()-a.getTime(),t=Math.floor(s/6e4),l=Math.floor(s/36e5),r=Math.floor(s/864e5);return t<1?"Just now":t<60?"".concat(t,"m ago"):l<24?"".concat(l,"h ago"):r<7?"".concat(r,"d ago"):a.toLocaleDateString("en-US",{month:"short",day:"numeric"})}(e.last_message_at)})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,t.jsxs)(c.C,{variant:"outline",className:"text-xs",children:[e.message_count," messages"]}),e.is_unread&&(0,t.jsx)(c.C,{className:"bg-blue-500 text-white text-xs",children:"Unread"})]})]})]})},e.id))})})})]})})}var R=s(13041),M=s(58896),O=s(95252),B=s(70525),T=s(66901),U=s(45131),q=s(64022),V=s(10866),Q=s(11239);let W=[{name:"New Leads",slug:"new_lead",color:"#3B82F6",is_fixed:!0,is_entry_point:!0,probability:10},{name:"Initial Contact",slug:"initial_contact",color:"#8B5CF6",probability:30},{name:"Qualified",slug:"qualified",color:"#14B8A6",is_qualification_point:!0,probability:50},{name:"Proposal",slug:"proposal",color:"#EC4899",probability:60},{name:"Negotiation",slug:"negotiation",color:"#F59E0B",probability:75},{name:"Closed Won",slug:"closed_won",color:"#10B981",is_fixed:!0,is_won_point:!0,probability:100},{name:"Closed Lost",slug:"closed_lost",color:"#EF4444",is_fixed:!0,is_lost_point:!0,probability:0},{name:"Do Not Disturb",slug:"dnd",color:"#6B7280",is_fixed:!0,is_dnd_point:!0,probability:0}],Y=e=>{switch(e){case"new_lead":return(0,t.jsx)(_.Z,{className:"h-4 w-4"});case"initial_contact":return(0,t.jsx)(R.Z,{className:"h-4 w-4"});case"qualified":return(0,t.jsx)(M.Z,{className:"h-4 w-4"});case"proposal":return(0,t.jsx)(O.Z,{className:"h-4 w-4"});case"negotiation":return(0,t.jsx)(B.Z,{className:"h-4 w-4"});case"closed_won":default:return(0,t.jsx)(T.Z,{className:"h-4 w-4"});case"closed_lost":return(0,t.jsx)(U.Z,{className:"h-4 w-4"});case"dnd":return(0,t.jsx)(q.Z,{className:"h-4 w-4"})}};function $(e){let{open:a,onOpenChange:s,onSetupComplete:r,workspaceId:n}=e,[o,m]=(0,l.useState)("default"),[u,x]=(0,l.useState)(!1),p=async()=>{x(!0);try{let e=await C.api.post("/leads/pipeline/setup",{pipeline_type:o,custom_stages:"custom"===o?W:void 0},{params:{workspace_id:n}});if(e.data.success)y.default.success("Pipeline configured successfully"),r(),s(!1);else throw Error(e.data.message||"Setup failed")}catch(s){var e,a;console.error("Pipeline setup failed:",s),y.default.error((null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to set up pipeline")}finally{x(!1)}};return(0,t.jsx)(D.Vq,{open:a,onOpenChange:s,children:(0,t.jsxs)(D.cZ,{className:"max-w-2xl",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(V.Z,{className:"h-5 w-5 text-primary"}),"Set Up Your Lead Pipeline"]}),(0,t.jsx)(D.Be,{children:"Choose how you want to organize your lead stages. You can customize this later."})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4 py-4",children:[(0,t.jsx)(i.Zb,{className:"cursor-pointer transition-all ".concat("default"===o?"ring-2 ring-primary bg-primary/5":"hover:border-primary/50"),onClick:()=>m("default"),children:(0,t.jsxs)(i.aY,{className:"pt-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,t.jsx)(Q.Z,{className:"h-5 w-5 text-yellow-500"}
1),(0,t.jsx)("span",{className:"font-semibold",children:"Quick Start"}),"default"===o&&(0,t.jsx)(c.C,{variant:"secondary",className:"ml-auto",children:"Selected"})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"Use our recommended 6-stage pipeline optimized for sales workflows."}),(0,t.jsx)("div",{className:"space-y-1",children:W.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs py-1",children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:e.color}}),(0,t.jsx)("span",{style:{color:e.color},children:Y(e.slug)}),(0,t.jsx)("span",{className:"truncate",children:e.name}),e.is_qualification_point&&(0,t.jsx)(c.C,{variant:"outline",className:"text-[9px] py-0 px-1 border-teal-500 text-teal-600 ml-auto",children:"CRM"}),e.is_dnd_point&&(0,t.jsx)(c.C,{variant:"outline",className:"text-[9px] py-0 px-1 border-gray-500 text-gray-600 ml-auto",children:"DND"}),e.is_fixed&&!e.is_qualification_point&&!e.is_dnd_point&&(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground ml-auto",children:"(Fixed)"})]},e.slug))})]})}),(0,t.jsx)(i.Zb,{className:"cursor-pointer transition-all ".concat("custom"===o?"ring-2 ring-primary bg-primary/5":"hover:border-primary/50"),onClick:()=>m("custom"),children:(0,t.jsxs)(i.aY,{className:"pt-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,t.jsx)(V.Z,{className:"h-5 w-5 text-purple-500"}),(0,t.jsx)("span",{className:"font-semibold",children:"Custom Pipeline"}),"custom"===o&&(0,t.jsx)(c.C,{variant:"secondary",className:"ml-auto",children:"Selected"})]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"Start with default stages and customize them to match your sales process."}),(0,t.jsxs)("div",{className:"bg-muted/50 rounded-lg p-3 text-xs space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(T.Z,{className:"h-3 w-3 text-green-500"}),(0,t.jsx)("span",{children:"Add custom stages"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(T.Z,{className:"h-3 w-3 text-green-500"}),(0,t.jsx)("span",{children:"Rename existing stages"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(T.Z,{className:"h-3 w-3 text-green-500"}),(0,t.jsx)("span",{children:"Set custom colors and probabilities"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(T.Z,{className:"h-3 w-3 text-green-500"}),(0,t.jsx)("span",{children:"Reorder stages"})]})]})]})})]}),(0,t.jsxs)(D.cN,{children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),(0,t.jsx)(d.z,{onClick:p,disabled:u,children:u?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Setting up..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(T.Z,{className:"h-4 w-4 mr-2"}),"Set Up Pipeline"]})})]})]})})}var K=s(45675),H=s(83229),G=s(66337),J=s(41905),X=s(18930);let ee=[{name:"Blue",value:"#3B82F6"},{name:"Purple",value:"#8B5CF6"},{name:"Pink",value:"#EC4899"},{name:"Orange",value:"#F59E0B"},{name:"Green",value:"#10B981"},{name:"Red",value:"#EF4444"},{name:"Teal",value:"#14B8A6"},{name:"Indigo",value:"#6366F1"},{name:"Gray",value:"#6B7280"}];function ea(e){let{open:a,onOpenChange:s,stages:r,onStagesUpdated:n,workspaceId:m,pipelineId:x}=e,[h,f]=(0,l.useState)([]),[j,b]=(0,l.useState)(null),[v,_]=(0,l.useState)(!1),[k,S]=(0,l.useState)(""),[Z,F]=(0,l.useState)("#6B7280"),[A,z]=(0,l.useState)(50),[I,P]=(0,l.useState)(!1),[E,L]=(0,l.useState)(!1),[R,O]=(0,l.useState)(null);(0,l.useEffect)(()=>{f([...r].sort((e,a)=>e.position-a.position))},[r]);let B=async()=>{if(!k.trim()){y.default.error("Please enter a stage name");return}if(!x){y.default.error("No pipeline selected");return}_(!0);try{(await C.api.post("/lead-pipelines/".concat(x,"/stages"),{name:k.trim(),color:Z,probability:A,is_qualification_point:I},{params:{workspace_id:m}})).data.stage&&(y.default.success("Stage added successfully"),S(""),F("#6B7280"),z(50),P(!1),L(!1),n())}catch(s){var e,a;console.error("Failed to add stage:",s),y.default.error((null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to add stage")}finally{_(!1)}},T=async e=>{if(!x){y.default.error("No pipeline selected");return}_(!0);try{(await C.api.put("/lead-pipelines/".concat(x,"/stages/").concat(e.id),{name:e.name,color:e.color,probability:e.probability,is_qualification_point:e.is_qualification_point},{params:{workspace_id:m}})).data.stage&&(y.default.success("Stage updated"),b(null),n())}catch(e){var a,s;console.error("Failed to update stage:",e),y.default.error((null===(s=e.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to update stage")}finally{_(!1)}},U=async e=>{if(e.is_fixed){y.default.error("Cannot delete fixed stages");return}if(!x){y.default.error("No pipeline selected");return}if(confirm('Delete stage "'.concat(e.name,'"? Any leads in this stage will need to be moved.'))){_(!0);try{let a=h.find(a=>a.id!==e.id&&!(a.is_lost_point||a.is_dropped_point));(await C.api.delete("/lead-pipelines/".concat(x,"/stages/").concat(e.id),{params:{workspace_id:m,move_entries_to:null==a?void 0:a.id}})).data.message&&(y.default.success("Stage deleted"),n())}catch(e){var a,s;console.error("Failed to delete stage:",e),y.default.error((null===(s=e.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to delete stage")}finally{_(!1)}}},V=async e=>{if(f(e),!x){y.default.error("No pipeline selected");return}try{await C.api.post("/lead-pipelines/".concat(x,"/stages/reorder"),{stage_ids:e.map(e=>e.id)},{params:{workspace_id:m}}),n()}catch(e){console.error("Failed to reorder stages:",e),y.default.error("Failed to save order"),f([...r].sort((e,a)=>e.position-a.position))}},Q=e=>{O(e)},W=(e,a)=>{if(e.preventDefault(),null===R||R===a)return;let s=[...h],t=s[R];
1s.splice(R,1),s.splice(a,0,t),s.forEach((e,a)=>{e.position=a}),f(s),O(a)},Y=()=>{null!==R&&V(h),O(null)};return(0,t.jsx)(D.Vq,{open:a,onOpenChange:s,children:(0,t.jsxs)(D.cZ,{className:"max-w-2xl max-h-[80vh] overflow-hidden flex flex-col !p-0 gap-0",children:[(0,t.jsxs)(D.fK,{className:"px-6 py-4 border-b flex-shrink-0",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(K.Z,{className:"h-5 w-5 text-primary"}),"Customize Pipeline Stages"]}),(0,t.jsx)(D.Be,{children:"Add, edit, reorder, or delete pipeline stages. Drag stages to reorder them."})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4 [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-slate-200 [&::-webkit-scrollbar-thumb]:rounded-full dark:[&::-webkit-scrollbar-thumb]:bg-slate-700",children:[(0,t.jsx)("div",{className:"space-y-2",children:h.map((e,a)=>{var s;return(0,t.jsx)(i.Zb,{draggable:!e.is_fixed,onDragStart:()=>Q(a),onDragOver:e=>W(e,a),onDragEnd:Y,className:"transition-all ".concat(R===a?"opacity-50 scale-95":""," ").concat(e.is_fixed?"bg-muted/30":"cursor-grab active:cursor-grabbing"),children:(0,t.jsx)(i.aY,{className:"py-3 px-4",children:(null==j?void 0:j.id)===e.id?(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Name"}),(0,t.jsx)(u.I,{value:j.name,onChange:e=>b({...j,name:e.target.value}),className:"h-8"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Color"}),(0,t.jsxs)(o.Ph,{value:j.color,onValueChange:e=>b({...j,color:e}),children:[(0,t.jsx)(o.i4,{className:"h-8",children:(0,t.jsx)(o.ki,{children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:j.color}}),(null===(s=ee.find(e=>e.value===j.color))||void 0===s?void 0:s.name)||"Custom"]})})}),(0,t.jsx)(o.Bw,{children:ee.map(e=>(0,t.jsx)(o.Ql,{value:e.value,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.value}}),e.name]})},e.value))})]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Win Probability (%)"}),(0,t.jsx)(u.I,{type:"number",min:0,max:100,value:j.probability||0,onChange:e=>b({...j,probability:parseInt(e.target.value)||0}),className:"h-8 w-24"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"CRM Qualification"}),(0,t.jsxs)("div",{className:"flex items-center gap-2 h-8",children:[(0,t.jsx)(g.r,{checked:j.is_qualification_point,onCheckedChange:e=>b({...j,is_qualification_point:e}),disabled:j.is_entry_point||j.is_won_point||j.is_completed_point||j.is_lost_point||j.is_dropped_point||j.is_dnd_point}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:j.is_qualification_point?"Qualified for CRM":"Not qualification stage"})]})]})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{size:"sm",onClick:()=>T(j),disabled:v,children:v?(0,t.jsx)(w.Z,{className:"h-3 w-3 animate-spin"}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(H.Z,{className:"h-3 w-3 mr-1"}),"Save"]})}),(0,t.jsx)(d.z,{size:"sm",variant:"outline",onClick:()=>b(null),children:"Cancel"})]})]}):(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:e.is_fixed?(0,t.jsx)(G.Z,{className:"h-4 w-4"}):(0,t.jsx)(J.Z,{className:"h-4 w-4"})}),(0,t.jsx)("div",{className:"w-4 h-4 rounded-full flex-shrink-0",style:{backgroundColor:e.color}}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"font-medium truncate",children:e.name}),e.is_entry_point&&(0,t.jsx)(c.C,{variant:"outline",className:"text-[10px] py-0",children:"Entry"}),e.is_qualification_point&&(0,t.jsxs)(c.C,{variant:"outline",className:"text-[10px] py-0 border-teal-500 text-teal-600",children:[(0,t.jsx)(M.Z,{className:"h-2.5 w-2.5 mr-0.5"}),"CRM"]}),(e.is_won_point||e.is_completed_point)&&(0,t.jsx)(c.C,{variant:"outline",className:"text-[10px] py-0 border-green-500 text-green-600",children:"Won"}),(e.is_lost_point||e.is_dropped_point)&&(0,t.jsx)(c.C,{variant:"outline",className:"text-[10px] py-0 border-red-500 text-red-600",children:"Lost"}),e.is_dnd_point&&(0,t.jsxs)(c.C,{variant:"outline",className:"text-[10px] py-0 border-gray-500 text-gray-600",children:[(0,t.jsx)(q.Z,{className:"h-2.5 w-2.5 mr-0.5"}),"DND"]}),e.is_fixed&&(0,t.jsx)(c.C,{variant:"secondary",className:"text-[10px] py-0",children:"Fixed"})]}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:void 0!==e.probability?"".concat(e.probability,"% probability"):"No probability set"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>b(e),children:(0,t.jsx)(K.Z,{className:"h-3 w-3"})}),!e.is_fixed&&(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive",onClick:()=>U(e),disabled:v,children:(0,t.jsx)(X.Z,{className:"h-3 w-3"})})]})]})})},e.id)})}),E?(0,t.jsx)(i.Zb,{className:"border-dashed border-primary",children:(0,t.jsx)(i.aY,{className:"py-4",children:(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"grid grid-cols-3 gap-3",children:[(0,t.jsxs)("div",{className:"space-y-1 col-span-2",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Stage Name"}),(0,t.jsx)(u.I,{placeholder:"e.g., Demo Scheduled",value:k,onChange:e=>S(e.target.value),className:"h-8"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Color"}),(0,t.jsxs)(o.Ph,{value:Z,onValueChange:F,children:[(0,t.jsx)(o.i4,{className:"h-8",children:(0,t.jsx)(o.ki,{children:(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:Z}})})})}),(0,t.jsx)(o.Bw,{children:ee.map(e=>(0,t.jsx)(o.Ql,{value:e.value,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.value}}),e.name]})},e.value))})]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Win Probability (%)"}),(0,t.jsx)(u.I,{type:"number",min:0,max:100,value:A,onChange:e=>z(parseInt(e.target.value)||0),className:"h-8 w-24"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"CRM Qualification Stage"}),(0,t.jsxs)("div",{className:"flex items-center gap-2 h-8",children:[(0,t.jsx)(g.r,{checked:I,onCheckedChange:P}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:I?"Leads here qualify for CRM":"Not qualification stage"})]})]})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{size:"sm",onClick:B,disabled:v||!k.trim(),children:v?(0,t.jsx)(w.Z,{className:"h-3 w-3 animate-spin"}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(N.Z,{className:"h-3 w-3 mr-1"}),"Add Stage"]})}),(0,t.jsx)(d.z,{size:"sm",variant:"outline",onClick:()=>{L(!1),S(""),F("#6B7280"),z(50),P(!1)},children:"Cancel"})]})]})})}):(0,t.jsxs)(d.z,{variant:"outline",className:"w-full border-dashed",onClick:()=>L(!0),children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-2"}),"Add New Stage"]})]}),(0,t.jsx)(D.cN,{className:"px-6 py-3 border-t flex-shrink-0",children:(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>s(!1),children:"Close"})})]})})}var es=s(40875),et=s(22135);async function el(e,a){let s={};return e&&(s.workspace_id=e),a&&(s.pipeline_id=a),(await C.api.get("/call-statuses",{params:s})).data.statuses}async function er(e,a,s){let t={};return a&&(t.workspace_id=a),s&&(t.pipeline_id=s),(await C.api.post("/call-statuses",e,{params:t})).data.status}async function en(e,a,s,t){let l={};return s&&(l.workspace_id=s),t&&(l.pipeline_id=t),(await C.api.put("/call-statuses/".concat(e),a,{params:l})).data.status}async function ei(e,a,s){let t={};a&&(t.workspace_id=a),s&&(t.pipeline_id=s),await C.api.delete("/call-statuses/".concat(e),{params:t})}async function ed(e,a,s,t){let l={};s&&(l.workspace_id=s),t&&(l.pipeline_id=t),await C.api.post("/call-statuses/reorder",{category:e,status_ids:a},{params:l})}let ec=[{name:"Green",value:"#10B981"},{name:"Blue",value:"#3B82F6"},{name:"Purple",value:"#8B5CF6"},{name:"Pink",value:"#EC4899"},{name:"Orange",value:"#F59E0B"},{name:"Red",value:"#EF4444"},{name:"Teal",value:"#14B8A6"},{name:"Indigo",value:"#6366F1"},{name:"Gray",value:"#6B7280"}],eo={positive:{label:"Positive Outcomes",badgeClass:"border-green-500 text-green-600"},neutral:{label:"Neutral Outcomes",badgeClass:"border-yellow-500 text-yellow-600"},negative:{label:"Negative Outcomes",badgeClass:"border-red-500 text-red-600"}};function em(e){let{open:a,onOpenChange:s,statuses:r,onStatusesUpdated:n,workspaceId:m,pipelineId:x}=e,[h,g]=(0,l.useState)({positive:[],neutral:[],negative:[]}),[f,j]=(0,l.useState)(null),[b,v]=(0,l.useState)(!1),[_,k]=(0,l.useState)(null),[C,S]=(0,l.useState)(""),[Z,F]=(0,l.useState)("#6B7280"),[A,z]=(0,l.useState)({}),[I,P]=(0,l.useState)(null),[E,L]=(0,l.useState)(null);(0,l.useEffect)(()=>{g({...r})},[r]);let R=e=>{z(a=>({...a,[e]:!a[e]}))},M=async e=>{if(!C.trim()){y.default.error("Please enter a status name");return}v(!0);try{await er({name:C.trim(),category:e,color:Z},m,x),y.default.success("Status added"),S(""),F("#6B7280"),k(null),n()}catch(e){var a,s;console.error("Failed to add status:",e),y.default.error((null===(s=e.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to add status")}finally{v(!1)}},O=async e=>{v(!0);try{await en(e.id,{name:e.name,color:e.color},m,x),y.default.success("Status updated"),j(null),n()}catch(e){var a,s;console.error("Failed to update status:",e),y.default.error((null===(s=e.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to update status")}finally{v(!1)}},B=async e=>{if(confirm('Deactivate status "'.concat(e.name,'"? It will no longer appear in dropdowns.'))){v(!0);try{await ei(e.id,m,x),y.default.success("Status deactivated"),n()}catch(e){var a,s;console.error("Failed to delete status:",e),y.default.error((null===(s=e.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to delete status")}finally{v(!1)}}},T=(e,a)=>{L(e),P(a)},U=(e,a,s)=>{if(e.preventDefault(),E!==a||null===I||I===s)return;let t=[...h[a]],l=t[I];t.splice(I,1),t.splice(s,0,l),g(e=>({...e,[a]:t})),P(s)},q=e=>{if(null!==I&&E===e){let a=h[e];ed(e,a.map(e=>e.id),m,x).then(()=>n()).catch(()=>y.default.error("Failed to save order"))}P(null),L(null)},V=e=>{let a=eo[e],s=h[e],l=A[e];return(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("button",{onClick:()=>R(e),className:"w-full flex items-center justify-between text-sm font-semibold py-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(c.C,{variant:"outline",className:"text-[10px] ".concat(a.badgeClass),children:a.label}),(0,t.jsxs)("span",{className:"text-muted-foreground text-xs",children:["(",s.length,")"]})]}),l?(0,t.jsx)(es.Z,{className:"h-4 w-4 text-muted-foreground"}):(0,t.jsx)(et.Z,{className:"h-4 w-4 text-muted-foreground"})]}),!l&&(0,t.jsxs)("div",{className:"space-y-1.5",children:[s.map((a,s)=>(0,t.jsx)(i.Zb,{draggable:!a.is_default,onDragStart:()=>T(e,s),onDragOver:a=>U(a,e,s),onDragEnd:()=>q(e),className:"transition-all ".concat(I===s&&E===e?"opacity-50 scale-95":""," ").concat(a.is_default?"bg-muted/30":"cursor-grab active:cursor-grabbing"),children:(0,t.jsx)(i.aY,{className:"py-2 px-3",children:(null==f?void 0:f.id)===a.id?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Name"}),(0,t.jsx)(u.I,{value:f.name,onChange:e=>j({...f,name:e.target.value}),className:"h-7 text-xs"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Color"}),(0,t.jsxs)(o.Ph,{value:f.color,onValueChange:e=>j({...f,color:e}),children:[(0,t.jsx)(o.i4,{className:"h-7 text-xs",children:(0,t.jsx)(o.ki,{children:(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:f.color}})})})}),(0,t.jsx)(o.Bw,{children:ec.map(e=>(0,t.jsx)(o.Ql,{value:e.value,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.value}}),e.name]})},e.value))})]})]})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{size:"sm",className:"h-6 text-xs",onClick:()=>O(f),disabled:b,children:b?(0,t.jsx)(w.Z,{className:"h-3 w-3 animate-spin"}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(H.Z,{className:"h-3 w-3 mr-1"}),"Save"]})}),(0,t.jsx)(d.z,{size:"sm",variant:"outline",className:"h-6 text-xs",onClick:()=>j(null),children:"Cancel"})]})]}):(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:a.is_default?(0,t.jsx)(G.Z,{className:"h-3 w-3"}):(0,t.jsx)(J.Z,{className:"h-3 w-3"})}),(0,t.jsx)("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:a.color}}),(0,t.jsx)("span",{className:"flex-1 text-sm truncate",children:a.name}),(0,t.jsxs)("div",{className:"flex items-center gap-0.5",children:[(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0",onClick:()=>j(a),children:(0,t.jsx)(K.Z,{className:"h-3 w-3"})}),(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-6 w-6 p-0 text-destructive hover:text-destructive",onClick:()=>B(a),disabled:b,children:(0,t.jsx)(X.Z,{className:"h-3 w-3"})})]})]})})},a.id)),_===e?(0,t.jsx)(i.Zb,{className:"border-dashed border-primary",children:(0,t.jsx)(i.aY,{className:"py-3 px-3",children:(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Status Name"}),(0,t.jsx)(u.I,{placeholder:"e.g., Meeting Set",value:C,onChange:e=>S(e.target.value),className:"h-7 text-xs"})]}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Color"}),(0,t.jsxs)(o.Ph,{value:Z,onValueChange:F,children:[(0,t.jsx)(o.i4,{className:"h-7 text-xs",children:(0,t.jsx)(o.ki,{children:(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:Z}})})})}),(0,t.jsx)(o.Bw,{children:ec.map(e=>(0,t.jsx)(o.Ql,{value:e.value,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.value}}),e.name]})},e.value))})]})]})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{size:"sm",className:"h-6 text-xs",onClick:()=>M(e),disabled:b||!C.trim(),children:b?(0,t.jsx)(w.Z,{className:"h-3 w-3 animate-spin"}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(N.Z,{className:"h-3 w-3 mr-1"}),"Add"]})}),(0,t.jsx)(d.z,{size:"sm",variant:"outline",className:"h-6 text-xs",onClick:()=>{k(null),S(""),F("#6B7280")},children:"Cancel"})]})]})})}):(0,t.jsxs)(d.z,{variant:"outline",size:"sm",className:"w-full border-dashed h-7 text-xs",onClick:()=>{k(e),S(""),F("#6B7280")},children:[(0,t.jsx)(N.Z,{className:"h-3 w-3 mr-1"}),"Add Status"]})]})]},e)};return(0,t.jsx)(D.Vq,{open:a,onOpenChange:s,children:(0,t.jsxs)(D.cZ,{className:"max-w-lg max-h-[80vh] overflow-hidden flex flex-col !p-0 gap-0",children:[(0,t.jsxs)(D.fK,{className:"px-6 py-4 border-b flex-shrink-0",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(K.Z,{className:"h-5 w-5 text-primary"}),"Manage Call Statuses"]}),(0,t.jsx)(D.Be,{children:"Customize call outcome statuses. Drag to reo
1rder within each category."})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4 [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-slate-200 [&::-webkit-scrollbar-thumb]:rounded-full dark:[&::-webkit-scrollbar-thumb]:bg-slate-700",children:[V("positive"),V("neutral"),V("negative")]}),(0,t.jsx)(D.cN,{className:"px-6 py-3 border-t flex-shrink-0",children:(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>s(!1),children:"Close"})})]})})}var eu=s(92369);function ex(e){let{leadId:a,workspaceId:s,callStatuses:r}=e,[n,i]=(0,l.useState)([]),[d,o]=(0,l.useState)(!0),[m,u]=(0,l.useState)(!1);(0,l.useEffect)(()=>{x()},[a]);let x=async()=>{try{o(!0);let e={};s&&(e.workspace_id=s);let t=await C.api.get("/calls/lead/".concat(a),{params:e});i(t.data.calls||[])}catch(e){console.error("Failed to fetch call history:",e)}finally{o(!1)}},p=e=>e?[...r.positive,...r.neutral,...r.negative].find(a=>a.slug===e):null;return d?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground py-2",children:[(0,t.jsx)(w.Z,{className:"h-3 w-3 animate-spin"}),"Loading call history..."]}):0===n.length?null:(0,t.jsxs)("div",{className:"border rounded-[4px] overflow-hidden",children:[(0,t.jsxs)("button",{onClick:()=>u(!m),className:"w-full flex items-center justify-between px-3 py-2 bg-muted/30 hover:bg-muted/50 transition-colors text-sm",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(R.Z,{className:"h-3.5 w-3.5 text-muted-foreground"}),(0,t.jsx)("span",{className:"font-medium",children:"Previous Calls"}),(0,t.jsx)(c.C,{variant:"secondary",className:"text-[10px] h-4 px-1.5",children:n.length})]}),m?(0,t.jsx)(et.Z,{className:"h-4 w-4 text-muted-foreground"}):(0,t.jsx)(es.Z,{className:"h-4 w-4 text-muted-foreground"})]}),m&&(0,t.jsx)("div",{className:"divide-y max-h-48 overflow-y-auto",children:n.map(e=>{let a=p(e.outcome);return(0,t.jsxs)("div",{className:"px-3 py-2 flex items-center gap-3 text-xs",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:function(e){let a=new Date(e),s=new Date().getTime()-a.getTime(),t=Math.floor(s/6e4),l=Math.floor(s/36e5),r=Math.floor(s/864e5);return t<1?"Just now":t<60?"".concat(t,"m ago"):l<24?"".concat(l,"h ago"):r<7?"".concat(r,"d ago"):a.toLocaleDateString()}(e.started_at)}),void 0!==e.duration_seconds&&e.duration_seconds>0&&(0,t.jsxs)("span",{className:"flex items-center gap-1 text-muted-foreground",children:[(0,t.jsx)(I.Z,{className:"h-3 w-3"}),function(e){if(!e||0===e)return"0s";let a=Math.floor(e/60),s=e%60;return 0===a?"".concat(s,"s"):"".concat(a,"m ").concat(s,"s")}(e.duration_seconds)]})]}),e.agent_name&&(0,t.jsxs)("div",{className:"flex items-center gap-1 text-muted-foreground mt-0.5",children:[(0,t.jsx)(eu.Z,{className:"h-3 w-3"}),e.agent_name]})]}),a?(0,t.jsxs)(c.C,{variant:"outline",className:"text-[10px] shrink-0",style:{borderColor:a.color,color:a.color},children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full mr-1 inline-block",style:{backgroundColor:a.color}}),a.name]}):e.outcome?(0,t.jsx)(c.C,{variant:"outline",className:"text-[10px] shrink-0",children:e.outcome}):null]},e.id)})})]})}var ep=s(98420),eh=s(82222),eg=s(82023),ef=s(89345),ej=s(50091),eb=s(31047),ev=s(88226),eN=s(10407),ew=s(22252),e_=s(96362),ey=s(32795),ek=s(82431),eC=s(48736),eS=s(76858),eZ=s(13781),eF=s(12194),eA=s(68667),ez=s(63639),eI=s(8544);let eP={lead_created:_.Z,lead_updated:eC.Z,stage_changed:eS.Z,pipeline_changed:eZ.Z,pipeline_added:N.Z,ai_call_initiated:R.Z,ai_call_completed:eF.Z,ai_call_failed:eA.Z,ai_call:eF.Z,agent_assigned:eu.Z,agent_unassigned:eu.Z,followup_created:eb.Z,followup_completed:T.Z,followup_cancelled:U.Z,followup:eb.Z,added_to_crm:ej.Z,note_added:eC.Z,crm_note_added:eC.Z,stage_change:eS.Z,pipeline_change:eZ.Z,assignment:eu.Z,payment_received:ey.Z,payment_pending:I.Z,payment_failed:U.Z,payment_refunded:ek.Z,payment:ey.Z,default:Q.Z},eD={lead_created:{bg:"bg-green-50 dark:bg-green-900/20",icon:"text-green-600",border:"border-l-green-500"},stage_changed:{bg:"bg-purple-50 dark:bg-purple-900/20",icon:"text-purple-600",border:"border-l-purple-500"},stage_change:{bg:"bg-purple-50 dark:bg-purple-900/20",icon:"text-purple-600",border:"border-l-purple-500"},pipeline_changed:{bg:"bg-indigo-50 dark:bg-indigo-900/20",icon:"text-indigo-600",border:"border-l-indigo-500"},pipeline_change:{bg:"bg-indigo-50 dark:bg-indigo-900/20",icon:"text-indigo-600",border:"border-l-indigo-500"},pipeline_added:{bg:"bg-blue-50 dark:bg-blue-900/20",icon:"text-blue-600",border:"border-l-blue-500"},ai_call_initiated:{bg:"bg-amber-50 dark:bg-amber-900/20",icon:"text-amber-600",border:"border-l-amber-500"},ai_call_completed:{bg:"bg-green-50 dark:bg-green-900/20",icon:"text-green-600",border:"border-l-green-500"},ai_call:{bg:"bg-green-50 dark:bg-green-900/20",icon:"text-green-600",border:"border-l-green-500"},ai_call_failed:{bg:"bg-red-50 dark:bg-red-900/20",icon:"text-red-600",border:"border-l-red-500"},agent_assigned:{bg:"bg-blue-50 dark:bg-blue-900/20",icon:"text-blue-600",border:"border-l-blue-500"},assignment:{bg:"bg-blue-50 dark:bg-blue-900/20",icon:"text-blue-600",border:"border-l-blue-500"},followup_created:{bg:"bg-amber-50 dark:bg-amber-900/20",icon:"text-amber-600",border:"border-l-amber-500"},followup_completed:{bg:"bg-green-50 dark:bg-green-900/20",icon:"text-green-600",border:"border-l-green-500"},followup:{bg:"bg-amber-50 dark:bg-amber-900/20",icon:"text-amber-600",border:"border-l-amber-500"},followup_cancelled:{bg:"bg-red-50 dark:bg-red-900/20",icon:"text-red-600",border:"border-l-red-500"},added_to_crm:{bg:"bg-blue-50 dark:bg-blue-900/20",icon:"text-blue-600",border:"border-l-blue-500"},note_added:{bg:"bg-gray-50 dark:bg-gray-900/20",icon:"text-gray-600",border:"border-l-gray-400"},crm_note_added:{bg:"bg-blue-50 dark:bg-blue-900/20",icon:"text-blue-600",border:"border-l-blue-500"},payment_received:{bg:"bg-green-50 dark:bg-green-900/20",icon:"text-green-600",border:"border-l-green-500"},payment_pending:{bg:"bg-amber-50 dark:bg-amber-900/20",icon:"text-amber-600",border:"border-l-amber-500"},payment_failed:{bg:"bg-red-50 dark:bg-red-900/20",icon:"text-red-600",border:"border-l-red-500"},payment_refunded:{bg:"bg-orange-50 dark:bg-orange-900/20",icon:"text-orange-600",border:"border-l-orange-500"},payment:{bg:"bg-green-50 dark:bg-green-900/20",icon:"text-green-600",border:"border-l-green-500"},default:{bg:"bg-gray-50 dark:bg-gray-900/20",icon:"text-gray-600",border:"border-l-gray-400"}};function eE(e){let{leadId:a,workspaceId:s,onAddFollowUp:n,className:c}=e,[o,m]=(0,l.useState)([]),[u,x]=(0,l.useState)(!0),[p,h]=(0,l.useState)(null),[g,f]=(0,l.useState)(!0),[j,b]=(0,l.useState)(new Set),v=(0,l.useCallback)(async()=>
1{if(a)try{x(!0),h(null);let e=await eI.S.getLeadHistory(a,{limit:50,include_stage_history:!1,include_pipeline_history:!1,include_assignment_history:!1,include_ai_calls:!0,include_followups:!0});m(e.history)}catch(e){console.error("Failed to fetch lead activities:",e),h("Failed to load activity history")}finally{x(!1)}},[a]);(0,l.useEffect)(()=>{v()},[v]);let _=e=>{b(a=>{let s=new Set(a);return s.has(e)?s.delete(e):s.add(e),s})},y=e=>eP[e.activity_type]||eP[e.item_type]||eP.default,k=e=>eD[e.activity_type]||eD[e.item_type]||eD.default;return(0,t.jsxs)(i.Zb,{className:(0,r.cn)("",c),children:[(0,t.jsx)(i.Ol,{className:"pb-3",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(i.ll,{className:"text-sm font-medium flex items-center gap-2",children:[(0,t.jsx)(d.z,{variant:"ghost",size:"sm",className:"p-0 h-auto hover:bg-transparent",onClick:()=>f(!g),children:g?(0,t.jsx)(et.Z,{className:"h-4 w-4 mr-1"}):(0,t.jsx)(es.Z,{className:"h-4 w-4 mr-1"})}),(0,t.jsx)(Q.Z,{className:"h-4 w-4 text-indigo-500"}),"History (",o.length,")"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(d.z,{variant:"ghost",size:"sm",onClick:v,disabled:u,children:(0,t.jsx)(ek.Z,{className:(0,r.cn)("h-4 w-4",u&&"animate-spin")})}),n&&(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:n,children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-1"}),"Add"]})]})]})}),g&&(0,t.jsx)(i.aY,{className:"pt-0",children:u&&0===o.length?(0,t.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,t.jsx)(w.Z,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):p?(0,t.jsxs)("div",{className:"text-center py-8",children:[(0,t.jsx)(ez.Z,{className:"h-8 w-8 text-amber-500 mx-auto mb-2"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:p}),(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:v,className:"mt-2",children:"Retry"})]}):0===o.length?(0,t.jsxs)("div",{className:"text-center py-8",children:[(0,t.jsx)(F.Z,{className:"h-8 w-8 text-muted-foreground mx-auto mb-2"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No activity yet"}),n&&(0,t.jsx)(d.z,{variant:"link",size:"sm",onClick:n,className:"mt-1 text-primary",children:"Schedule your first call"})]}):(0,t.jsx)("div",{className:"space-y-3",children:o.map((e,a)=>{let s=y(e),l=k(e),n=j.has(e.id),i=e.description||e.activity_data;return(0,t.jsxs)("div",{className:(0,r.cn)("relative pl-4 border-l-2 py-2 px-3 rounded-r-lg transition-all",l.border,l.bg,i&&"cursor-pointer hover:shadow-sm"),onClick:()=>i&&_(e.id),children:[(0,t.jsx)("div",{className:(0,r.cn)("absolute -left-[9px] top-3 h-4 w-4 rounded-full border-2 border-background flex items-center justify-center",l.bg),children:(0,t.jsx)(s,{className:(0,r.cn)("h-2.5 w-2.5",l.icon)})}),(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(s,{className:(0,r.cn)("h-4 w-4 flex-shrink-0",l.icon)}),(0,t.jsx)("p",{className:"text-sm font-medium text-foreground truncate",children:e.title})]}),(e.description||n)&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:e.description}),n&&e.activity_data&&(0,t.jsx)("div",{className:"mt-2 p-2 bg-background/50 rounded text-xs space-y-1",children:Object.entries(e.activity_data).map(e=>{let[a,s]=e;if(null==s)return null;let l=a.replace(/_/g," ").replace(/\b\w/g,e=>e.toUpperCase());return(0,t.jsxs)("div",{className:"flex justify-between",children:[(0,t.jsxs)("span",{className:"text-muted-foreground",children:[l,":"]}),(0,t.jsx)("span",{className:"font-medium",children:String(s)})]},a)})}),e.created_by_name&&(0,t.jsxs)("p",{className:"text-[10px] text-muted-foreground mt-1 flex items-center gap-1",children:[(0,t.jsx)(eu.Z,{className:"h-3 w-3"}),e.created_by_name]})]}),(0,t.jsxs)("div",{className:"flex flex-col items-end flex-shrink-0",children:[(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground whitespace-nowrap",children:function(e){let a=new Date(e),s=new Date,t=s.getTime()-a.getTime(),l=Math.floor(t/6e4),r=Math.floor(t/36e5),n=Math.floor(t/864e5);return l<1?"Just now":l<60?"".concat(l,"m ago"):r<24?"".concat(r,"h ago"):1===n?"Yesterday":n<7?"".concat(n,"d ago"):a.toLocaleDateString("en-US",{month:"short",day:"numeric",year:a.getFullYear()!==s.getFullYear()?"numeric":void 0})}(e.created_at)}),i&&(0,t.jsx)(es.Z,{className:(0,r.cn)("h-3 w-3 text-muted-foreground mt-1 transition-transform",n&&"rotate-180")}
1)]})]})]},e.id)})})})]})}let eL={getNotes:async e=>(await C.api.get("/leads/".concat(e,"/notes"))).data,createNote:async(e,a)=>(await C.api.post("/leads/".concat(e,"/notes"),{content:a})).data,deleteNote:async(e,a)=>{await C.api.delete("/leads/".concat(e,"/notes/").concat(a))}};function eR(e){let{open:a,onOpenChange:s,lead:n,workspaceId:m,stages:x,rolePermissions:h,onMoveLead:g,onSaveLead:j,onSaveCustomFields:b,onAssignClick:k,onAddFollowUp:S,onCall:Z,onFetchPayments:z,onFetchRegistrationRequirement:P,onSubmitPayment:E,onRegistrationPayment:L,onGeneratePaymentLink:M,onSendWhatsApp:B,onCopyPaymentLink:U,onFetchCalendarTasks:q,leadQuality:Q}=e,[W,Y]=(0,l.useState)("timeline"),[$,H]=(0,l.useState)(!1),[G,J]=(0,l.useState)({name:"",email:"",phone:"",company:"",score:0}),[X,ee]=(0,l.useState)(!1),[ea,es]=(0,l.useState)(!1),[el,er]=(0,l.useState)(!1),[en,ei]=(0,l.useState)({}),[ed,ec]=(0,l.useState)([]),[eo,em]=(0,l.useState)(!1),[ex,eC]=(0,l.useState)(new Date),[eS,eZ]=(0,l.useState)([]),[eF,eA]=(0,l.useState)(!1),[ez,eI]=(0,l.useState)(null),[eP,eD]=(0,l.useState)(!1),[eR,eM]=(0,l.useState)(!1),[eO,eB]=(0,l.useState)(!1),[eT,eU]=(0,l.useState)(!1),[eq,eV]=(0,l.useState)(!1),[eQ,eW]=(0,l.useState)({amount:"",currency:"INR",payment_date:new Date().toISOString().split("T")[0],payment_method:"upi",payment_status:"completed",invoice_number:"",description:"",is_recurring:!1,recurring_frequency:""}),[eY,e$]=(0,l.useState)([]),[eK,eH]=(0,l.useState)(!1),[eG,eJ]=(0,l.useState)(""),[eX,e0]=(0,l.useState)(!1),[e1,e5]=(0,l.useState)(!1),[e2,e4]=(0,l.useState)(!1),[e3,e6]=(0,l.useState)("Follow-up"),[e8,e9]=(0,l.useState)(""),[e7,ae]=(0,l.useState)("medium"),[aa,as]=(0,l.useState)(""),[at,al]=(0,l.useState)(!1);(0,l.useEffect)(()=>{a||(Y("timeline"),H(!1),es(!1),ec([]),eZ([]),eI(null),e$([]),eJ(""),e5(!1),e4(!1),e6("Follow-up"),e9(""),ae("medium"),as(""))},[a]);let ar=(0,l.useCallback)(()=>{n&&(J({name:n.name||"",email:n.email||"",phone:n.phone||"",company:n.company||"",score:n.score||0}),H(!0))},[n]),an=async()=>{if(n){ee(!0);try{await j(n.id,G),H(!1)}finally{ee(!1)}}},ai=e=>{let a={};e.forEach(e=>{let[s,t]=e;a[s]=null!=t?String(t):""}),ei(a),es(!0)},ad=async()=>{if(null==n?void 0:n.pipeline_entry_id){er(!0);try{await b(n.pipeline_entry_id,en),es(!1)}finally{er(!1)}}},ac=async e=>{if(Y(e),n){if("calendar"===e&&(!Array.isArray(ed)||0===ed.length)){em(!0);try{let e=await q(n.id);ec(Array.isArray(e)?e:[])}finally{em(!1)}}if("payment"===e){eA(!0),eD(!0),eW({amount:"",currency:"INR",payment_date:new Date().toISOString().split("T")[0],payment_method:"upi",payment_status:"completed",invoice_number:"",description:"",is_recurring:!1,recurring_frequency:""});try{let[e,a]=await Promise.all([z(n.id),P(n.id)]);eZ(Array.isArray(e)?e:[]),eI(a)}finally{eA(!1),eD(!1)}}if("notes"===e&&0===eY.length){eH(!0);try{let e=await eL.getNotes(n.id);e$(e)}catch(e){console.error("Failed to fetch notes:",e)}finally{eH(!1)}}}},ao=async()=>{if(!n||!eG.trim())return!1;e0(!0);try{await eL.createNote(n.id,eG.trim());let e=await eL.getNotes(n.id);return e$(e),eJ(""),e5(!1),!0}catch(e){return console.error("Failed to add note:",e),!1}finally{e0(!1)}},am=async e=>{if(n)try{await eL.deleteNote(n.id,e),e$(a=>a.filter(a=>a.id!==e))}catch(e){console.error("Failed to delete note:",e)}},au=async()=>{if(n&&e3.trim()&&e8){al(!0);try{await C.api.post("/follow-ups",{title:e3,task_type:"call",due_date:new Date(e8).toISOString(),priority:"medium"===e7?"normal":e7,lead_id:n.id,contact_name:n.name,contact_phone:n.phone,contact_email:n.email,company_name:n.company,notes:aa},{params:{workspace_id:m}}),y.default.success("Follow-up scheduled"),e4(!1),e6("Follow-up"),e9(""),ae("medium"),as("");let e=await q(n.id);ec(Array.isArray(e)?e:[]),Y("calendar")}catch(e){console.error("Failed to add follow-up:",e),y.default.error("Failed to schedule follow-up")}finally{al(!1)}}},ax=async()=>{if(n&&eQ.amount){eM(!0);try{await E(n.id,eQ),eW({amount:"",currency:"INR",payment_date:new Date().toISOString().split("T")[0],payment_method:"upi",payment_status:"completed",invoice_number:"",description:"",is_recurring:!1,recurring_frequency:""});let e=await z(n.id);eZ(Array.isArray(e)?e:[])}finally{eM(!1)}}},ap=async()=>
1{if(n&&(null==ez?void 0:ez.registration_amount)){eB(!0);try{await L(n.id,ez.registration_amount);let e=await P(n.id);eI(e);let a=await z(n.id);eZ(Array.isArray(a)?a:[])}finally{eB(!1)}}},ah=async()=>{if(n&&(null==ez?void 0:ez.crm_pipeline_id)){eU(!0);try{await M(n.id,ez.crm_pipeline_id);let e=await P(n.id);eI(e)}finally{eU(!1)}}},ag=async()=>{if(!n||!(null==ez?void 0:ez.crm_pipeline_id)||!(null==ez?void 0:ez.payment_link_url))return;let e=await B(n.id,ez.crm_pipeline_id,ez.payment_link_url);e&&window.open(e,"_blank"),eI(await P(n.id))},af=(e,a)=>new Date(e,a+1,0).getDate(),aj=(e,a)=>new Date(e,a,1).getDay(),ab=e=>Array.isArray(ed)?ed.filter(a=>{let s=new Date(a.due_date);return s.getDate()===e.getDate()&&s.getMonth()===e.getMonth()&&s.getFullYear()===e.getFullYear()}):[],av=e=>{eC(a=>{let s=new Date(a);return s.setMonth(a.getMonth()+("next"===e?1:-1)),s})},aN=x.find(e=>e.name===(null==n?void 0:n.stage));if(!n)return null;let aw=(()=>{let e=(null==n?void 0:n.custom_fields)||(null==n?void 0:n.meta_data)||(null==n?void 0:n.metadata);if(!e||"object"!=typeof e)return null;let a=["name","full_name","email","phone","company","company_name","id","workspace_id","lead_id","created_at","updated_at","job_title","source","score","status","ai_classification","ai_first_call_status","ai_first_call_id","ai_first_call_at","ai_first_call_attempts","ai_interest_score","ai_interest_category","ai_call_summary","ai_recommended_action"],s=Object.entries(e).filter(e=>{let[s,t]=e;return!a.includes(s.toLowerCase())&&"object"!=typeof t&&null!=t&&""!==String(t).trim()});return s.length>0?s:null})();return(0,t.jsx)(D.Vq,{open:a,onOpenChange:s,children:(0,t.jsxs)(D.cZ,{className:"max-w-5xl max-h-[90vh] p-0 overflow-hidden",children:[(0,t.jsx)(D.fK,{className:"px-6 py-4 border-b bg-gradient-to-r from-primary/5 to-primary/10",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-4",children:[(0,t.jsx)("div",{className:"h-12 w-12 rounded-full bg-primary/10 border-2 border-primary/20 flex items-center justify-center",children:(0,t.jsx)("span",{className:"text-lg font-semibold text-primary",children:n.name.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2)})}),(0,t.jsxs)("div",{children:[(0,t.jsx)(D.$N,{className:"text-xl font-semibold",children:n.name}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[n.company&&(0,t.jsxs)("span",{className:"text-sm text-muted-foreground flex items-center gap-1",children:[(0,t.jsx)(ep.Z,{className:"h-3 w-3"}),n.company]}),n.source&&(0,t.jsx)(c.C,{variant:"outline",className:"text-xs capitalize",children:n.source})]})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)(c.C,{variant:n.score>=70?"default":n.score>=40?"secondary":"outline",className:"flex items-center gap-1",children:[(0,t.jsx)(eh.Z,{className:"h-3 w-3"}),n.score]}),(0,t.jsxs)(c.C,{className:"bg-purple-100 text-purple-700 border-purple-200 flex items-center gap-1",title:(null==Q?void 0:Q.has_quality)?"AI-powered quality score":"Not enough data",children:[(0,t.jsx)(eg.Z,{className:"h-3 w-3"}),(null==Q?void 0:Q.has_quality)?"Quality: ".concat(Q.quality_score):"No score"]})]})]})}),(0,t.jsxs)("div",{className:"flex h-[calc(90vh-180px)]",children:[(0,t.jsxs)("div",{className:"w-[40%] border-r overflow-y-auto p-5 space-y-5 bg-muted/20 scrollbar-minimal",children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Contact Information"}),!$&&(0,t.jsx)(d.z,{size:"sm",variant:"ghost",onClick:ar,className:"h-7 px-2",children:(0,t.jsx)(V.Z,{className:"h-3.5 w-3.5"})})]}),$?(0,t.jsxs)("div",{className:"space-y-3 p-3 bg-background rounded-lg border",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Name"}),(0,t.jsx)(u.I,{value:G.name,onChange:e=>J({...G,name:e.target.value}),className:"h-8 text-sm",placeholder:"Lead name"})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Email"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ef.Z,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,t.jsx)(u.I,{value:G.email,onChange:e=>J({...G,email:e.target.value}),className:"h-8 text-sm",placeholder:"[email protected]",type:"email"})]})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Phone"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(R.Z,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,t.jsx)(u.I,{value:G.phone,onChange:e=>J({...G,phone:e.target.value}),className:"h-8 text-sm",placeholder:"+91 98765 43210"})]})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Company"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ep.Z,{className:"h-4 w-4 text-muted-foreground flex-shrink-0"}),(0,t.jsx)(u.I,{value:G.company,onChange:e=>J({...G,company:e.target.value}),className:"h-8 text-sm",placeholder:"Company name"})]})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(p._,{className:"text-xs",children:"Score (0-100)"}),(0,t.jsx)(u.I,{type:"number",value:G.score,onChange:e=>J({...G,score:parseInt(e.target.value)||0}),className:"h-8 text-sm w-24",min:0,max:100})]}),(0,t.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,t.jsx)(d.z,{size:"sm",onClick:an,disabled:X||!G.name,className:"flex-1",children:X?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-3.5 w-3.5 mr-1 animate-spin"})," Saving..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(T.Z,{className:"h-3.5 w-3.5 mr-1"})," Save"]})}),(0,t.jsx)(d.z,{size:"sm",variant:"outline",onClick:()=>
1{H(!1),J({name:"",email:"",phone:"",company:"",score:0})},disabled:X,children:(0,t.jsx)(v.Z,{className:"h-3.5 w-3.5"})})]})]}):(0,t.jsxs)("div",{className:"space-y-2.5",children:[n.email&&(0,t.jsxs)("div",{className:"flex items-center gap-3 p-2.5 bg-background rounded-lg border",children:[(0,t.jsx)(ef.Z,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("a",{href:"mailto:".concat(n.email),className:"text-sm text-primary hover:underline truncate",children:n.email})]}),n.phone&&(0,t.jsxs)("div",{className:"flex items-center gap-3 p-2.5 bg-background rounded-lg border",children:[(0,t.jsx)(R.Z,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("a",{href:"tel:".concat(n.phone),className:"text-sm text-primary hover:underline",children:n.phone})]}),n.company&&(0,t.jsxs)("div",{className:"flex items-center gap-3 p-2.5 bg-background rounded-lg border",children:[(0,t.jsx)(ep.Z,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{className:"text-sm",children:n.company})]})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Current Status"}),eY.length>0?(0,t.jsxs)("div",{className:"p-3 bg-amber-50 dark:bg-amber-950/30 rounded-lg border border-amber-200 dark:border-amber-800",children:[(0,t.jsx)("p",{className:"text-sm text-slate-700 dark:text-slate-300 whitespace-pre-wrap line-clamp-3",children:eY[0].content}),(0,t.jsxs)("div",{className:"flex items-center justify-between mt-2 pt-2 border-t border-amber-200 dark:border-amber-700",children:[(0,t.jsx)("span",{className:"text-xs text-amber-700 dark:text-amber-400",children:eY[0].created_by}),(0,t.jsx)("span",{className:"text-xs text-amber-600 dark:text-amber-500",children:new Date(eY[0].created_at).toLocaleDateString("en-IN",{day:"numeric",month:"short",hour:"2-digit",minute:"2-digit"})})]})]}):(0,t.jsx)("div",{className:"p-3 bg-muted/30 rounded-lg border border-dashed text-center",children:(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"No status notes yet"})})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Pipeline Stage"}),(0,t.jsxs)(o.Ph,{value:n.stage,onValueChange:async e=>{e!==n.stage&&await g(n.id,e)},children:[(0,t.jsx)(o.i4,{className:"h-10 bg-background",children:(0,t.jsx)(o.ki,{placeholder:"Select stage",children:aN&&(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-3 h-3 rounded-full",style:{backgroundColor:aN.color}}),aN.name]})})}),(0,t.jsx)(o.Bw,{children:x.map(e=>(0,t.jsx)(o.Ql,{value:e.name,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.name))})]})]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Assignment"}),(0,t.jsxs)("div",{className:"flex items-center justify-between p-3 bg-background rounded-lg border",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(_.Z,{className:"h-4 w-4 text-muted-foreground"}),n.assigned_to?(0,t.jsx)(c.C,{variant:"secondary",className:"text-xs",children:n.assigned_to_name||n.assigned_to}):(0,t.jsx)("span",{className:"text-sm text-orange-500",children:"Not assigned"})]}),h.isSuperAdmin&&(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:e=>k(n,e),children:n.assigned_to?"Reassign":"Assign"})]})]}),aw&&(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-2",children:[(0,t.jsx)(ej.Z,{className:"h-3.5 w-3.5 text-purple-500"}),"Imported Data"]}),n.pipeline_entry_id&&(ea?(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:()=>{es(!1),ei({})},disabled:el,children:"Cancel"}),(0,t.jsx)(d.z,{size:"sm",className:"h-7 px-2 text-xs bg-purple-600 hover:bg-purple-700",onClick:ad,disabled:el,children:el?(0,t.jsx)(w.Z,{className:"h-3 w-3 animate-spin"}):"Save"})]}):(0,t.jsxs)(d.z,{size:"sm",variant:"ghost",className:"h-7 px-2 text-xs",onClick:()=>ai(aw),children:[(0,t.jsx)(K.Z,{className:"h-3 w-3 mr-1"}),"Edit"]}))]}),(0,t.jsx)("div",{className:"bg-background rounded-lg border p-3 space-y-2",children:aw.map(e=>{let[a,s]=e;return(0,t.jsxs)("div",{className:"flex items-center justify-between py-1.5 border-b last:border-b-0",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground capitalize",children:a.replace(/_/g," ")}),ea?(0,t.jsx)("input",{type:"text",value:en[a]||"",onChange:e=>ei(s=>({...s,[a]:e.target.value})),className:"text-sm bg-muted border border-input rounded px-2 py-1 
1w-[120px] text-right"}):(0,t.jsx)("span",{className:"text-sm font-medium truncate max-w-[140px]",title:String(s),children:String(s)})]},a)})})]})]}),(0,t.jsxs)("div",{className:"w-[60%] flex flex-col",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1 px-4 py-3 border-b bg-muted/30",children:[(0,t.jsxs)(d.z,{size:"sm",variant:"timeline"===W?"default":"ghost",onClick:()=>ac("timeline"),className:"gap-1.5",children:[(0,t.jsx)(I.Z,{className:"h-4 w-4"}),"Timeline"]}),(0,t.jsxs)(d.z,{size:"sm",variant:"calendar"===W?"default":"ghost",onClick:()=>ac("calendar"),className:"gap-1.5",children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4"}),"Calendar"]}),(0,t.jsxs)(d.z,{size:"sm",variant:"payment"===W?"default":"ghost",onClick:()=>ac("payment"),className:"gap-1.5",children:[(0,t.jsx)(ev.Z,{className:"h-4 w-4"}),"Payment"]}),(0,t.jsxs)(d.z,{size:"sm",variant:"notes"===W?"default":"ghost",onClick:()=>ac("notes"),className:"gap-1.5",children:[(0,t.jsx)(F.Z,{className:"h-4 w-4"}),"Notes"]})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 scrollbar-minimal",children:["timeline"===W&&(0,t.jsx)(eE,{leadId:n.id,workspaceId:m}),"calendar"===W&&(0,t.jsxs)(i.Zb,{children:[(0,t.jsx)(i.Ol,{className:"pb-3",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(i.ll,{className:"text-sm font-medium flex items-center gap-2",children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4"}),"Calendar"]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(d.z,{variant:e2?"ghost":"outline",size:"sm",onClick:()=>e4(!e2),className:"h-7 text-xs",children:e2?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(et.Z,{className:"h-3 w-3 mr-1"}),"Hide"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(N.Z,{className:"h-3 w-3 mr-1"}),"Follow Up"]})}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(d.z,{variant:"ghost",size:"sm",onClick:()=>av("prev"),className:"h-7 w-7 p-0",children:(0,t.jsx)(eN.Z,{className:"h-4 w-4 rotate-180"})}),(0,t.jsx)(d.z,{variant:"ghost",size:"sm",onClick:()=>eC(new Date),className:"h-7 px-2 text-xs",children:"Today"}),(0,t.jsx)("span",{className:"text-sm font-medium min-w-[100px] text-center",children:ex.toLocaleDateString("en-US",{month:"short",year:"numeric"})}),(0,t.jsx)(d.z,{variant:"ghost",size:"sm",onClick:()=>av("next"),className:"h-7 w-7 p-0",children:(0,t.jsx)(eN.Z,{className:"h-4 w-4"})})]})]})]})}),(0,t.jsxs)(i.aY,{className:"pt-0 space-y-4",children:[e2&&(0,t.jsxs)("div",{className:"space-y-3 p-4 bg-green-50 dark:bg-green-950/30 rounded-lg border border-green-200 dark:border-green-800",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-green-700 dark:text-green-300 mb-2",children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4"}),"Schedule Follow-up"]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(p._,{htmlFor:"calFollowUpTitle",className:"text-xs text-muted-foreground",children:"Task Title"}),(0,t.jsx)(u.I,{id:"calFollowUpTitle",placeholder:"Follow-up",value:e3,onChange:e=>e6(e.target.value),className:"mt-1"})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)(p._,{htmlFor:"calFollowUpDate",className:"text-xs text-muted-foreground",children:"Scheduled Date"}),(0,t.jsx)(u.I,{id:"calFollowUpDate",type:"date",value:e8,onChange:e=>e9(e.target.value),className:"mt-1"})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(p._,{htmlFor:"calFollowUpPriority",className:"text-xs text-muted-foreground",children:"Priority"}),(0,t.jsxs)(o.Ph,{value:e7,onValueChange:e=>ae(e),children:[(0,t.jsx)(o.i4,{id:"calFollowUpPriority",className:"mt-1",children:(0,t.jsx)(o.ki,{})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"low",children:"Low"}),(0,t.jsx)(o.Ql,{value:"medium",children:"Medium"}),(0,t.jsx)(o.Ql,{value:"high",children:"High"})]})]})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)(p._,{htmlFor:"calFollowUpNotes",className:"text-xs text-muted-foreground",children:"Notes (Optional)"}),(0,t.jsx)("textarea",{id:"calFollowUpNotes",placeholder:"Add any notes for this follow-up...",value:aa,onChange:e=>
1as(e.target.value),className:"mt-1 w-full min-h-[60px] px-3 py-2 text-sm rounded-md border border-input bg-background resize-none focus:outline-none focus:ring-2 focus:ring-ring"})]})]}),(0,t.jsx)(d.z,{onClick:au,disabled:at||!e3.trim()||!e8,className:"w-full bg-green-600 hover:bg-green-700",children:at?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Scheduling..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4 mr-2"}),"Schedule Follow-up"]})})]}),eo?(0,t.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,t.jsx)(w.Z,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):(0,t.jsxs)("div",{className:"border rounded-lg overflow-hidden",children:[(0,t.jsx)("div",{className:"grid grid-cols-7 bg-muted/50",children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(e=>(0,t.jsx)("div",{className:"py-2 text-center text-xs font-semibold text-muted-foreground border-r last:border-r-0",children:e},e))}),(0,t.jsx)("div",{children:(()=>{let e=ex.getFullYear(),a=ex.getMonth(),s=af(e,a),l=aj(e,a),n=[],i=[];for(let e=0;e<l;
1e++)i.push((0,t.jsx)("div",{className:"min-h-[60px] bg-muted/20 border-r border-b last:border-r-0"},"empty-".concat(e)));for(let d=1;d<=s;d++){let o=new Date(e,a,d),m=ab(o),u=new Date().toDateString()===o.toDateString();if(i.push((0,t.jsxs)("div",{className:(0,r.cn)("min-h-[60px] border-r border-b last:border-r-0 p-1",u?"bg-blue-50 dark:bg-blue-900/20":"hover:bg-muted/30"),children:[(0,t.jsx)("div",{className:(0,r.cn)("text-xs font-medium mb-1",u&&"text-blue-600"),children:d}),(0,t.jsxs)("div",{className:"space-y-0.5",children:[m.slice(0,2).map(e=>{let a={low:"bg-amber-100 text-amber-800 dark:bg-amber-900/30 dark:text-amber-300",normal:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300",medium:"bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300",high:"bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-300"},s=e.priority||"normal",l="completed"===e.status?"bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300 line-through opacity-70":a[s]||a.normal;return(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{delayDuration:200,children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsxs)("div",{className:(0,r.cn)("text-[10px] px-1 py-0.5 rounded truncate cursor-pointer",l),children:["call"===e.task_type&&(0,t.jsx)(R.Z,{className:"h-2 w-2 inline mr-0.5"}),e.title]})}),(0,t.jsxs)(f._v,{side:"right",className:"max-w-[280px] p-0 bg-white border border-slate-200 shadow-lg rounded-lg overflow-hidden",children:[(0,t.jsx)("div",{className:"px-3 py-2 bg-slate-50 border-b border-slate-100",children:(0,t.jsxs)("div",{className:"font-semibold text-sm text-slate-800 flex items-center gap-2",children:["call"===e.task_type&&(0,t.jsx)(R.Z,{className:"h-3.5 w-3.5 text-blue-500"}),e.title]})}),(0,t.jsxs)("div",{className:"p-3 space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-4 text-xs",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)("span",{className:(0,r.cn)("w-2 h-2 rounded-full","high"===s&&"bg-red-500","low"===s&&"bg-amber-500",("medium"===s||"normal"===s)&&"bg-blue-500")}),(0,t.jsxs)("span",{className:"text-slate-600 capitalize",children:["normal"===s?"Medium":s," Priority"]})]}),(0,t.jsx)(c.C,{variant:"outline",className:(0,r.cn)("text-[10px] px-1.5 py-0","completed"===e.status&&"border-green-200 bg-green-50 text-green-700","pending"===e.status&&"border-blue-200 bg-blue-50 text-blue-700","overdue"===e.status&&"border-red-200 bg-red-50 text-red-700",!e.status&&"border-slate-200 bg-slate-50 text-slate-600"),children:e.status||"Pending"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[(0,t.jsx)(eb.Z,{className:"h-3 w-3"}),new Date(e.due_date).toLocaleDateString("en-IN",{weekday:"short",day:"numeric",month:"short",year:"numeric"})]}),e.notes&&(0,t.jsx)("div",{className:"pt-2 mt-2 border-t border-slate-100",children:(0,t.jsx)("p",{className:"text-xs text-slate-600 leading-relaxed",children:e.notes})}),e.contact_name&&(0,t.jsxs)("div",{className:"flex items-center gap-2 pt-2 mt-2 border-t border-slate-100 text-xs text-slate-500",children:[(0,t.jsx)(eu.Z,{className:"h-3 w-3"}),(0,t.jsx)("span",{children:e.contact_name}),e.contact_phone&&(0,t.jsxs)("span",{className:"text-slate-400",children:["• ",e.contact_phone]})]})]})]})]})},e.id)}),m.length>2&&(0,t.jsxs)("div",{className:"text-[10px] text-muted-foreground px-1",children:["+",m.length-2," more"]})]})]},d)),(l+d)%7==0||d===s){for(;i.length<7;
1)i.push((0,t.jsx)("div",{className:"min-h-[60px] bg-muted/20 border-r border-b last:border-r-0"},"empty-end-".concat(i.length)));n.push((0,t.jsx)("div",{className:"grid grid-cols-7",children:i},"week-".concat(n.length))),i=[]}}return n})()})]}),(0,t.jsxs)("div",{className:"flex items-center gap-4 mt-3 text-xs text-muted-foreground",children:[(0,t.jsx)("span",{className:"font-medium",children:"Priority:"}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded bg-amber-500"}),(0,t.jsx)("span",{children:"Low"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded bg-blue-500"}),(0,t.jsx)("span",{children:"Medium"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded bg-red-500"}),(0,t.jsx)("span",{children:"High"})]}),(0,t.jsx)("span",{className:"mx-2",children:"|"}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded bg-green-500"}),(0,t.jsx)("span",{children:"Completed"})]})]}),Array.isArray(ed)&&ed.length>0?(0,t.jsxs)("div",{className:"mt-3 pt-3 border-t text-sm text-muted-foreground",children:["Total: ",ed.length," follow-ups (",ed.filter(e=>"completed"===e.status).length," completed,"," ",ed.filter(e=>"completed"!==e.status).length," pending)"]}):!eo&&(0,t.jsxs)("div",{className:"mt-3 pt-3 border-t text-center text-sm text-muted-foreground",children:[(0,t.jsx)("p",{children:"No follow-ups scheduled yet."}),(0,t.jsx)(d.z,{variant:"link",size:"sm",className:"text-primary",onClick:()=>S(n),children:"Schedule your first call"})]})]})]}),"payment"===W&&(0,t.jsxs)("div",{className:"space-y-4",children:[eP?(0,t.jsx)(i.Zb,{className:"border-purple-200 bg-purple-50/50",children:(0,t.jsx)(i.aY,{className:"py-4",children:(0,t.jsxs)("div",{className:"flex items-center justify-center gap-2",children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin text-purple-600"}),(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"Checking registration requirement..."})]})})}):(null==ez?void 0:ez.required)&&(0,t.jsxs)(i.Zb,{className:(0,r.cn)("border-2",ez.registration_paid?"border-green-300 bg-green-50/50":"border-purple-300 bg-purple-50/50"),children:[(0,t.jsxs)(i.Ol,{className:"pb-3",children:[(0,t.jsx)("div",{className:"flex items-center justify-between",children:(0,t.jsx)(i.ll,{className:"text-sm font-medium flex items-center gap-2",children:ez.registration_paid?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(T.Z,{className:"h-4 w-4 text-green-600"}),(0,t.jsx)("span",{className:"text-green-700",children:"Registration Payment Complete"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ew.Z,{className:"h-4 w-4 text-purple-600"}),(0,t.jsx)("span",{className:"text-purple-700",children:"Registration Payment Required"})]})})}),ez.crm_pipeline_name&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["For CRM Pipeline: ",ez.crm_pipeline_name]})]}),(0,t.jsxs)(i.aY,{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Registration Amount"}),(0,t.jsxs)("p",{className:"text-2xl font-bold text-purple-700",children:["₹",new Intl.NumberFormat("en-IN").format(ez.registration_amount||0)]})]}),ez.registration_paid?(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("p",{className:"text-sm text-green-600 font-medium",children:"Paid"}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["₹",new Intl.NumberFormat("en-IN").format(ez.paid_amount||0)]})]}):ez.razorpay_enabled?(0,t.jsx)("div",{className:"flex flex-col gap-2",children:ez.payment_link_url?(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[(0,t.jsxs)(d.z,{onClick:ag,className:"bg-green-600 hover:bg-green-700",size:"sm",children:[(0,t.jsx)(A.Z,{className:"h-4 w-4 mr-1"}),ez.whatsapp_sent?"Resend":"WhatsApp"]}),(0,t.jsxs)(d.z,{onClick:()=>U(ez.payment_link_url),variant:"outline",size:"sm",children:[(0,t.jsx)(e_.Z,{className:"h-4 w-4 mr-1"}),"Copy Link"]}),(0,t.jsx)(d.z,{onClick:()=>window.open(ez.payment_link_url,"_blank"),variant:"outline",size:"sm",children:"Pay Now"})]}):(0,t.jsx)(d.z,{onClick:ah,disabled:eT,className:"bg-blue-600 hover:bg-blue-700",size:"sm",children:eT?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Generating..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e_.Z,{className:"h-4 w-4 mr-2"}),"Generate Link"]})})}):(0,t.jsx)(d.z,{onClick:ap,disabled:eO,className:"bg-purple-600 hover:bg-purple-700",children:eO?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Processing..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ev.Z,{className:"h-4 w-4 mr-2"}),"Mark as Paid"]})})]}),!ez.registration_paid&&(0,t.jsxs)(t.Fragment,{children:[ez.razorpay_enabled&&ez.payment_link_url&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground bg-blue-50 p-2 rounded",children:[(0,t.jsx)("span",{className:"font-medium",children:"Payment Link:"}),(0,t.jsx)("a",{href:ez.payment_link_url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:underline truncate max-w-[200px]",children:ez.payment_link_url}),ez.whatsapp_sent&&(0,t.jsxs)(c.C,{variant:"outline",className:"text-green-600 border-green-300",children:[(0,t.jsx)(T.Z,{className:"h-3 w-3 mr-1"}),"Sent"]})]}),(0,t.jsx)("p",{className:"text-xs text-purple-700 bg-purple-100 p-2 rounded",children:"This payment is required before moving this lead to the qualification stage."})]})]})]}),(0,t.jsxs)(i.Zb,{children:[(0,t.jsx)(i.Ol,{className:"pb-3",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(i.ll,{className:"text-sm font-medium flex items-center gap-2",children:[(0,t.jsx)(ev.Z,{className:"h-4 w-4"}),"Record Payment"]}),(0,t.jsx)(d.z,{variant:eq?"ghost":"outline",size:"sm",onClick:()=>eV(!eq),children:eq?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(et.Z,{className:"h-4 w-4 mr-1"}),"Hide"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-1"}),"Add"]})})]})}),(0,t.jsxs)(i.aY,{className:"space-y-4",children:[eq&&(0,t.jsxs)("div",{className:"space-y-4 p-4 bg-muted/30 rounded-lg border",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"payment-amount",className:"text-sm font-medium",children:"Amount *"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(ey.Z,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,t.jsx)(u.I,{id:"payment-amount",type:"number",placeholder:"Enter amount",value:eQ.amount,onChange:e=>eW(a=>({...a,amount:e.target.value})),className:"pl-9"})]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"payment-date",className:"text-sm font-medium",children:"Date *"}),(0,t.jsx)(u.I,{id:"payment-date",type:"date",value:eQ.payment_date,onChange:e=>eW(a=>({...a,payment_date:e.target.value}))})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"payment-method",className:"text-sm font-medium",children:"Method *"}),(0,t.jsxs)("select",{id:"payment-method",value:eQ.payment_method,onChange:e=>eW(a=>({...a,payment_method:e.target.value})),className:"w-full h-10 px-3 rounded-md border border-input bg-background text-sm",children:[(0,t.jsx)("option",{value:"upi",children:"UPI"}),(0,t.jsx)("option",{value:"card",children:"Card"}),(0,t.jsx)("option",{value:"cash",children:"Cash"}),(0,t.jsx)("option",{value:"bank_transfer",children:"Bank Transfer"}),(0,t.jsx)("option",{value:"other",children:"Other"})]})]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"payment-status",className:"text-sm font-medium",children:"Status"}),(0,t.jsxs)("select",{id:"payment-status",value:eQ.payment_status,onChange:e=>eW(a=>({...a,payment_status:e.target.value})),className:"w-full h-10 px-3 rounded-md border border-input bg-background text-sm",children:[(0,t.jsx)("option",{value:"completed",children:"Completed"}),(0,t.jsx)("option",{value:"pending",children:"Pending"}),(0,t.jsx)("option",{value:"failed",children:"Failed"}),(0,t.jsx)("option",{value:"refunded",children:"Refunded"})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"invoice-number",className:"text-sm font-medium",children:"Invoice #"}),(0,t.jsx)(u.I,{id:"invoice-number",placeholder:"INV-001",value:eQ.invoice_number,onChange:e=>eW(a=>({...a,invoice_number:e.target.value}))})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"payment-description",className:"text-sm font-medium",children:"Description"}),(0,t.jsx)(u.I,{id:"payment-description",placeholder:"Payment for...",value:eQ.description,onChange:e=>eW(a=>({...a,description:e.target.value}))})]}),(0,t.jsxs)("div",{className:"space-y-2 pt-2 border-t",children:[(0,t.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,t.jsx)("input",{type:"checkbox",id:"is-recurring",checked:eQ.is_recurring,onChange:e=>eW(a=>({...a,is_recurring:e.target.checked}
1)),className:"h-4 w-4 rounded border-gray-300"}),(0,t.jsx)(p._,{htmlFor:"is-recurring",className:"text-sm font-normal",children:"Recurring payment"})]}),eQ.is_recurring&&(0,t.jsx)("div",{className:"pl-6",children:(0,t.jsxs)("select",{value:eQ.recurring_frequency,onChange:e=>eW(a=>({...a,recurring_frequency:e.target.value})),className:"w-full h-9 px-3 rounded-md border border-input bg-background text-sm",children:[(0,t.jsx)("option",{value:"",children:"Select frequency"}),(0,t.jsx)("option",{value:"monthly",children:"Monthly"}),(0,t.jsx)("option",{value:"quarterly",children:"Quarterly"}),(0,t.jsx)("option",{value:"yearly",children:"Yearly"})]})})]}),(0,t.jsx)(d.z,{onClick:()=>{ax(),eV(!1)},disabled:eR||!eQ.amount,className:"w-full bg-green-600 hover:bg-green-700",children:eR?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-2"}),"Add Payment"]})})]}),(0,t.jsxs)("div",{className:"pt-4 border-t",children:[(0,t.jsxs)("h4",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,t.jsx)(O.Z,{className:"h-4 w-4 text-green-600"}),"Payment History"]}),eF?(0,t.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,t.jsx)(w.Z,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===eS.length?(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-6",children:"No payments recorded yet."}):(0,t.jsx)("div",{className:"space-y-2 max-h-[200px] overflow-y-auto scrollbar-minimal",children:eS.map(e=>(0,t.jsxs)("div",{className:(0,r.cn)("p-3 rounded-lg border","completed"===e.payment_status?"bg-green-50 border-green-200":"pending"===e.payment_status?"bg-yellow-50 border-yellow-200":"failed"===e.payment_status?"bg-red-50 border-red-200":"bg-gray-50 border-gray-200"),children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ey.Z,{className:"h-4 w-4 text-green-600"}),(0,t.jsx)("span",{className:"font-semibold",children:new Intl.NumberFormat("en-IN").format(e.amount)}),(0,t.jsx)("span",{className:(0,r.cn)("text-xs px-2 py-0.5 rounded-full","completed"===e.payment_status?"bg-green-100 text-green-700":"pending"===e.payment_status?"bg-yellow-100 text-yellow-700":"failed"===e.payment_status?"bg-red-100 text-red-700":"bg-gray-100 text-gray-700"),children:e.payment_status})]}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground uppercase",children:e.payment_method.replace("_"," ")})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between mt-1",children:[(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:new Date(e.payment_date).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric"})}),e.invoice_number&&(0,t.jsxs)("span",{className:"text-xs text-muted-foreground",children:["#",e.invoice_number]})]}),e.description&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-1",children:e.description}),e.is_recurring&&(0,t.jsxs)("div",{className:"flex items-center gap-1 mt-1",children:[(0,t.jsx)(ek.Z,{className:"h-3 w-3 text-blue-500"}),(0,t.jsx)("span",{className:"text-xs text-blue-600",children:e.recurring_frequency})]})]},e.id))})]})]})]})]}),"notes"===W&&(0,t.jsxs)(i.Zb,{children:[(0,t.jsx)(i.Ol,{className:"pb-3",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(i.ll,{className:"text-sm font-medium flex items-center gap-2",children:[(0,t.jsx)(F.Z,{className:"h-4 w-4"}),"Notes & Remarks"]}),(0,t.jsx)(d.z,{variant:e1?"ghost":"outline",size:"sm",onClick:()=>e5(!e1),children:e1?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(et.Z,{className:"h-4 w-4 mr-1"}),"Hide"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-1"}),"Add"]})})]})}),(0,t.jsxs)(i.aY,{className:"space-y-4",children:[e1&&(0,t.jsxs)("div",{className:"space-y-3 p-4 bg-muted/30 rounded-lg border",children:[(0,t.jsx)("textarea",{placeholder:"Add a note about this lead...",value:eG,onChange:e=>eJ(e.target.value),className:"w-full min-h-[80px] px-3 py-2 text-sm rounded-md border border-input bg-background resize-none focus:outline-none focus:ring-2 focus:ring-ring"}),(0,t.jsx)(d.z,{onClick:ao,disabled:eX||!eG.trim(),className:"w-full bg-blue-600 hover:bg-blue-700",children:eX?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Adding..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-2"}),"Add Note"]})})]}),(0,t.jsxs)("div",{className:e1||e2?"pt-4 border-t":"",children:[(0,t.jsx)("h4",{className:"text-sm font-semibold mb-3",children:"Previous Notes & Follow-ups"}),eK?(0,t.jsx)("div",{className:"flex items-center justify-center py-6",children:(0,t.jsx)(w.Z,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===eY.length?(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-6",children:'No notes yet. Click "Add" to add your first note.'}):(0,t.jsx)("div",{className:"space-y-3 max-h-[300px] overflow-y-auto scrollbar-minimal",children:eY.map(e=>(0,t.jsxs)("div",{className:"p-3 rounded-lg border bg-muted/30 group relative",children:[(0,t.jsx)("p",{className:"text-sm whitespace-pre-wrap pr-6",children:e.content}),(0,t.jsxs)("div",{className:"flex items-center justify-between mt-2 text-xs text-muted-foreground",children:[(0,t.jsx)("span",{children:e.created_by}),(0,t.jsx)("span",{children:new Date(e.created_at).toLocaleDateString("en-IN",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})})]}),(0,t.jsx)(d.z,{variant:"ghost",size:"sm",onClick:()=>am(e.id),className:"absolute top-2 right-2 h-6 w-6 p-0 opacity-0 group-hover:opacity-100 transition-opacity text-red-500 hover:text-red-700 hover:bg-red-100",children:(0,t.jsx)(v.Z,{className:"h-3 w-3"})})]},e.id))})]})]})]})]})]})]}),(0,t.jsxs)("div",{className:"px-6 py-4 border-t bg-muted/30 flex items-center justify-between",children:[(0,t.jsx)("div",{className:"flex items-center gap-2",children:n.phone&&Z&&(0,t.jsxs)(d.z,{onClick:e=>Z(n,e),className:"bg-green-600 hover:bg-green-700 text-white px-5",children:[(0,t.jsx)(R.Z,{className:"h-4 w-4 mr-2"}),"Call"]})}),(0,t.jsx)(d.z,{variant:"outline",onClick:()=>s(!1),children:"Close"})]})]})})}var eM=s(24524),eO=s(56439),eB=s(29985),eT=s(53470),eU=s(14438),eq=s(3362);function eV(e){let{open:a,onOpenChange:s,workspaceId:r,pipelineId:n,pipelineName:i}=e,[d,o]=(0,l.useState)(!1),[m,u]=(0,l.useState)(null),[x,p]=(0,l.useState)([]),h=(0,l.useCallback)(async()=>
1{if(r&&n){o(!0);try{let e=await (0,eq.GT)(r,{includeUnmapped:!0});p(e.campaigns||[])}catch(e){console.error("Failed to load campaigns",e),eU.A.error("Failed to load ad campaigns")}finally{o(!1)}}},[r,n]);(0,l.useEffect)(()=>{a&&h()},[a,h]);let f=e=>{var a;return(null===(a=e.pipeline_mapping)||void 0===a?void 0:a.pipeline_id)===n},j=e=>!!e.pipeline_mapping&&e.pipeline_mapping.pipeline_id!==n,b=async(e,a)=>{u(e.platform_campaign_id);try{a?(await (0,eq.uy)(e.platform_campaign_id,r,{pipeline_id:n,auto_route_enabled:!0}),eU.A.success('"'.concat(e.name,'" now feeds this pipeline'))):(await (0,eq.or)(e.platform_campaign_id,r),eU.A.success('"'.concat(e.name,'" disconnected'))),await h()}catch(e){console.error("Failed to update mapping",e),eU.A.error("Failed to update ad source")}finally{u(null)}},v=x.filter(f),N=x.filter(e=>!f(e)),_=e=>{let a=(e.effective_status||e.status||"").toUpperCase();return a.includes("ACTIVE")?"text-emerald-600 dark:text-emerald-400":a.includes("PAUSED")?"text-amber-600 dark:text-amber-400":"text-slate-500"},y=e=>{var a,s,l,r;let{c:n}=e,i=f(n),d=j(n);return(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 rounded-lg border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 px-3 py-2.5",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"truncate text-sm font-medium text-foreground",children:n.name}),(0,t.jsx)("span",{className:"text-[10px] font-medium ".concat(_(n)),children:(n.effective_status||n.status||"").toUpperCase()||"—"})]}),(0,t.jsxs)("div",{className:"mt-0.5 flex items-center gap-2 text-[11px] text-muted-foreground",children:[(0,t.jsx)("span",{className:"truncate",children:n.account_name||n.platform}),i&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 text-emerald-600 dark:text-emerald-400",children:[(0,t.jsx)(B.Z,{className:"h-3 w-3"}),null!==(r=null===(a=n.pipeline_mapping)||void 0===a?void 0:a.leads_routed)&&void 0!==r?r:0," leads routed"]}),d&&(0,t.jsxs)(c.C,{variant:"outline",className:"h-4 px-1 text-[9px]",children:["→ ",(null===(l=n.pipeline_mapping)||void 0===l?void 0:null===(s=l.pipeline)||void 0===s?void 0:s.name)||"another pipeline"]})]})]}),(0,t.jsx)("div",{className:"shrink-0",children:m===n.platform_campaign_id?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin text-muted-foreground"}):(0,t.jsx)(g.r,{checked:i,onCheckedChange:e=>b(n,e),"aria-label":i?"Disconnect campaign":"Connect campaign"})})]})};return(0,t.jsx)(D.Vq,{open:a,onOpenChange:s,children:(0,t.jsxs)(D.cZ,{className:"max-w-2xl max-h-[90vh] overflow-y-auto",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(eO.Z,{className:"h-5 w-5 text-pink-500"}),"Ad Sources",i?" — ".concat(i):""]}),(0,t.jsx)(D.Be,{children:"Pick the ad campaigns that feed this pipeline. Leads from a connected campaign auto-route to the entry stage, then get engaged by the sales agent and assigned per your rules."})]}),d?(0,t.jsxs)("div",{className:"flex items-center justify-center py-12 text-muted-foreground",children:[(0,t.jsx)(w.Z,{className:"h-5 w-5 animate-spin mr-2"})," Loading campaigns…"]}):0===x.length?(0,t.jsx)("div",{className:"py-12 text-center text-sm text-muted-foreground",children:"No ad campaigns found. Launch or connect a Meta ad first."}):(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"mb-2 flex items-center gap-2 text-xs font-semibold text-emerald-600 dark:text-emerald-400",children:[(0,t.jsx)(eB.Z,{className:"h-3.5 w-3.5"})," Feeding this pipeline (",v.length,")"]}),0===v.length?(0,t.jsx)("p",{className:"rounded-lg border border-dashed border-slate-200 dark:border-slate-800 px-3 py-4 text-center text-xs text-muted-foreground",children:"No campaigns connected yet — flip a switch below to connect one."}):(0,t.jsx)("div",{className:"space-y-2",children:v.map(e=>(0,t.jsx)(y,{c:e},e.platform_campaign_id))})]}),N.length>0&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"mb-2 flex items-center gap-2 text-xs font-semibold text-muted-foreground",children:[(0,t.jsx)(eT.Z,{className:"h-3.5 w-3.5"})," Available campaigns (",N.length,")"]}),(0,t.jsx)("div",{className:"space-y-2",children:N.map(e=>(0,t.jsx)(y,{c:e},e.platform_campaign_id))})]})]})]})})}var eQ=s(17624),eW=s(2093),eY=s(68245),e$=s(61649),eK=s(17689),eH=s(32660);let eG=[{value:"__none__",label:"—"},{value:"name",label:"Name"},{value:"email",label:"Email"},{value:"phone",label:"Phone"},{value:"company",label:"Company"},{value:"gender",label:"Gender"}],eJ=[{code:"none",label:"None"},{code:"+91",label:"+91"},{code:"+1",label:"+1"},{code:"+44",label:"+44"},{code:"+971",label:"+971"},{code:"+65",label:"+65"},{code:"+61",label:"+61"},{code:"+49",label:"+49"},{code:"+33",label:"+33"},{code:"+81",label:"+81"},{code:"+86",label:"+86"}];function eX(e){let{open:a,onOpenChange:s,pipelineId:r,pipelineName:n,onImportComplete:i}=e,[m,x]=(0,l.useState)("upload"),[p,h]=(0,l.useState)(null),[g,f]=(0,l.useState)([]),[j,b]=(0,l.useState)([]),[v,N]=(0,l.useState)(!1),_=(0,l.useRef)(null),[k,S]=(0,l.useState)(new Set),[Z,F]=(0,l.useState)(new Set),[A,I]=(0,l.useState)(1),[P,E]=(0,l.useState)(null),[L,R]=(0,l.useState)(""),[M,O]=(0,l.useState)({}),[B,U]=(0,l.useState)("none"),[q,V]=(0,l.useState)(!1),Q=Math.ceil(j.length/100),W=(A-1)*100,Y=Math.min(W+100,j.length),$=j.slice(W,Y),H=e=>{let a=Object.entries(M).find(a=>{let[s,t]=a;return t===e});return a?parseInt(a[0]):null};H("phone");let G=(0,l.useCallback)(()=>{x("upload"),h(null),f([]),b([]),S(new Set),F(new Set),I(1),E(null),R(""),O({}),U("none"),V(!1)},[]);(0,l.useEffect)(()=>{a||G()},[a,G]);let J=e=>{e.preventDefault(),e.stopPropagation(),N("dragenter"===e.type||"dragover"===e.type)},X=async e=>
1{if(![".xlsx",".xls",".csv"].some(a=>e.name.toLowerCase().endsWith(a))){y.default.error("Please upload an Excel or CSV file");return}h(e);try{let a=await e.arrayBuffer(),s=eW.ij(a,{raw:!0}),t=s.Sheets[s.SheetNames[0]],l=eW.P6.sheet_to_json(t,{header:1,raw:!0,rawNumbers:!1});if(l.length<2){y.default.error("File must have header row and at least one data row"),h(null);return}let r=l[0].map(e=>String(e||"").trim()),n=l.slice(1).filter(e=>e.some(e=>null!=e&&""!==e));if(n.length>500){y.default.error("Max ".concat(500," rows. Use dedicated import for larger files.")),h(null);return}f(r),b(n),S(new Set(n.map((e,a)=>a))),F(new Set(r.map((e,a)=>a)));let i={};r.forEach((e,a)=>{let s=e.toLowerCase();(s.includes("name")||s.includes("fullname"))&&!s.includes("company")&&!Object.values(i).includes("name")?i[a]="name":(s.includes("email")||s.includes("mail"))&&!Object.values(i).includes("email")?i[a]="email":(s.includes("phone")||s.includes("mobile")||s.includes("cell"))&&!Object.values(i).includes("phone")?i[a]="phone":s.includes("company")&&!Object.values(i).includes("company")?i[a]="company":s.includes("gender")&&!Object.values(i).includes("gender")&&(i[a]="gender")}),O(i),I(1),x("select")}catch(e){y.default.error("Failed to read file"),h(null)}},ee=e=>{F(a=>{let s=new Set(a);return s.has(e)?(s.delete(e),O(a=>{let s={...a};return delete s[e],s})):s.add(e),s})},ea=(e,a)=>{O(s=>{let t={...s};return"__none__"!==a&&Object.keys(t).forEach(e=>{t[parseInt(e)]===a&&delete t[parseInt(e)]}),"__none__"===a?delete t[e]:t[e]=a,t})},es=e=>{let a=W+e,s=new Set(k);s.has(a)?s.delete(a):s.add(a),S(s)},et=(e,a)=>{var s,t;let l=W+e;E({row:l,col:a}),R(null!==(t=null===(s=j[l])||void 0===s?void 0:s[a])&&void 0!==t?t:"")},el=()=>{if(!P)return;let e=[...j];e[P.row]=[...e[P.row]],e[P.row][P.col]=L,b(e),E(null)},er=e=>{"Enter"===e.key?el():"Escape"===e.key&&E(null)},en=()=>{let e=Object.values(M).includes("name"),a=Object.values(M).includes("email"),s=Object.values(M).includes("phone");return e&&(a||s)},ei=async()=>{if(!en()||!r||0===k.size)return;let e=H("name"),a=H("email"),t=H("phone"),l=H("company"),n=H("gender"),d=new Set(Z),c={...M};Object.values(c);let o=j.filter((e,a)=>k.has(a)).map(s=>{let r=null!==e?String(s[e]||"").trim():"",i=null!==a?String(s[a]||"").trim():"",o=null!==t?String(s[t]||"").trim():"",m=null!==l?String(s[l]||"").trim():"",u=null!==n?String(s[n]||"").trim():"";o&&"none"!==B&&!o.startsWith("+")&&(o=B+o.replace(/^0+/,""));let x={};return g.forEach((e,a)=>{let t=d.has(a),l=void 0!==c[a],r=s[a],n=null!=r&&""!==String(r).trim();t&&!l&&n&&(x[e]=String(r).trim())}),m&&(x.company=m),u&&(x.gender=u),{name:r||"Unknown",email:i||null,phone:o||null,source:"instant_import",meta_data:Object.keys(x).length?x:null,_valid:r&&(i||o)}}).filter(e=>e._valid);if(!o.length){y.default.error("No valid leads to import");return}V(!0);try{let e=await C.api.post("/leads/import/batch",{leads:o.map(e=>{let{_valid:a,...s}=e;return s}),pipeline_id:r,stage_id:null});if(e.data.success){let{imported:a=0,failed:t=0}=e.data;y.default.success(t?"Imported ".concat(a,", ").concat(t," failed"):"Imported ".concat(a," leads")),null==i||i(a),setTimeout(()=>s(!1),1200)}}catch(e){var m,u;y.default.error((null===(u=e.response)||void 0===u?void 0:null===(m=u.data)||void 0===m?void 0:m.detail)||"Import failed")}finally{V(!1)}},ed=Object.values(M).includes("name"),ec=Object.values(M).includes("email"),eo=Object.values(M).includes("phone");return(0,t.jsx)(D.Vq,{open:a,onOpenChange:s,children:(0,t.jsxs)(D.cZ,{className:"w-[95vw] max-w-5xl h-[90vh] md:h-[85vh] p-0 gap-0 flex flex-col overflow-hidden",children:[(0,t.jsxs)(D.fK,{className:"px-4 md:px-6 py-3 md:py-4 border-b shrink-0",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2 text-base",children:[(0,t.jsx)(e$.Z,{className:"w-5 h-5 text-emerald-500"}),"Instant Import",n&&(0,t.jsx)(c.C,{variant:"secondary",className:"text-xs font-normal hidden sm:inline-flex",children:n})]}),(0,t.jsx)(D.Be,{className:"text-sm",children:"upload"===m?"Upload Excel or CSV":"Map columns and select rows"})]}),(0,t.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col",children:"upload"===m?(0,t.jsxs)("div",{className:"flex-1 flex",children:[(0,t.jsxs)("div",{className:"flex-1 md:flex-[7] flex flex-col items-center justify-center p-6 md:p-8 bg-gradient-to-br from-slate-50/50 to-white",children:[(0,t.jsxs)("div",{className:"w-full max-w-sm border-2 border-dashed rounded-2xl p-6 md:p-8 text-center transition-all duration-200 ".concat(v?"border-emerald-400 bg-emerald-50/80 scale-[1.02] shadow-lg shadow-emerald-100":"border-slate-200 hover:border-emerald-300 hover:bg-emerald-50/30"),onDragEnter:J,onDragLeave:J,onDragOver:J,onDrop:e=>{var a;e.preventDefault(),e.stopPropagation(),N(!1),(null===(a=e.dataTransfer.files)||void 0===a?void 0:a[0])&&X(e.dataTransfer.files[0])},children:[(0,t.jsx)("div",{className:"w-14 h-14 md:w-16 md:h-16 mx-auto mb-3 md:mb-4 rounded-2xl flex items-center justify-center transition-colors ".concat(v?"bg-amber-200":"bg-amber-100"),children:(0,t.jsx)(eK.Z,{className:"w-7 h-7 md:w-8 md:h-8 transition-colors ".concat(v?"text-amber-600":"text-amber-500")})}),(0,t.jsx)("p",{className:"font-semibold text-slate-700 mb-1",children:"Drop your file here"}),(0,t.jsx)("p",{className:"text-sm text-slate-400 mb-4 md:mb-5",children:"or click to browse"}),(0,t.jsx)("input",{ref:_,type:"file",accept:".xlsx,.xls,.csv",className:"hidden",onChange:e=>{var a;return(null===(a=e.target.files)||void 0===a?void 0:a[0])&&X(e.target.files[0])}}),(0,t.jsxs)(d.z,{variant:"outline",onClick:()=>{var e;return null===(e=_.current)||void 0===e?void 0:e.click()},className:"bg-white hover:bg-emerald-50 hover:text-emerald-600 hover:border-emerald-300 transition-colors",children:[(0,t.jsx)(e$.Z,{className:"w-4 h-4 mr-2"}),"Select File"]})]}),(0,t.jsxs)("div",{className:"flex md:hidden flex-wrap justify-center gap-2 mt-5 px-4",children:[(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 bg-amber-50 border border-amber-200 rounded-full text-xs text-amber-700",children:[(0,t.jsx)(ew.Z,{className:"w-3 h-3"}),"Name + Email/Phone"]}),(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 bg-blue-50 border border-blue-200 rounded-full text-xs text-blue-700",children:[(0,t.jsx)(eK.Z,{className:"w-3 h-3"}),"Max 500 rows"]}),(0,t.jsx)("span",{className:"inline-flex items-center gap-1.5 px-2.5 py-1 bg-slate-100 border border-slate-200 rounded-full text-xs text-slate-600",children:".xlsx .xls .csv"})]})]}),(0,t.jsxs)("div",{className:"hidden md:flex flex-[3] bg-slate-50 border-l flex-col min-h-0",children:[(0,t.jsx)("div",{className:"px-5 py-4 border-b bg-slate-50 shrink-0",children:(0,t.jsxs)("h3",{className:"font-semibold text-slate-700 flex items-center gap-2",children:[(0,t.jsx)(e$.Z,{className:"w-4 h-4 text-emerald-500"}),"Quick Import"]})}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-3 [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-thumb]:bg-slate-200 [&::-webkit-scrollbar-thumb]:rounded-full",children:[(0,t.jsx)("div",{className:"p-2.5 bg-amber-50 border border-amber-200 rounded-lg",children:(0,t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,t.jsx)(ew.Z,{className:"w-4 h-4 text-amber-500 shrink-0 mt-0.5"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium text-amber-700",children:"Required Fields"}),(0,t.jsx)("p",{className:"text-xs text-amber-600 mt-0.5",children:"Name + Email or Phone"})]})]})}),(0,t.jsx)("div",{className:"p-2.5 bg-blue-50 border border-blue-200 rounded-lg",children:(0,t.jsxs)("div",{className:"flex items-start gap-2",children:[(0,t.jsx)(eK.Z,{className:"w-4 h-4 text-blue-500 shrink-0 mt-0.5"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-sm font-medium text-blue-700",children:"Row Limit"}),(0,t.jsx)("p",{className:"text-xs text-blue-600 mt-0.5",children:"Maximum 500 rows per import"})]})]})}),(0,t.jsxs)("div",{className:"p-2.5 bg-slate-100 border border-slate-200 rounded-lg",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-slate-600 mb-1.5",children:"Supported Formats"}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-slate-200 rounded text-xs text-slate-600",children:".xlsx"}),(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-slate-200 rounded text-xs text-slate-600",children:".xls"}),(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-slate-200 rounded text-xs text-slate-600",children:".csv"})]})]}),(0,t.jsxs)("div",{className:"p-2.5 bg-emerald-50 border border-emerald-200 rounded-lg",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-emerald-700 mb-1.5",children:"Mappable Fields"}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-1.5",children:[(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-emerald-200 rounded text-xs text-emerald-600",children:"Name"}),(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-emerald-200 rounded text-xs text-emerald-600",children:"Email"}),(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-emerald-200 rounded text-xs text-emerald-600",children:"Phone"}),(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-emerald-200 rounded text-xs text-emerald-600",children:"Company"}),(0,t.jsx)("span",{className:"px-2 py-0.5 bg-white border border-emerald-200 rounded text-xs text-emerald-600",children:"Gender"})]})]})]})]})]}):(0,t.jsxs)("div",{className:"flex-1 flex flex-col min-h-0",children:[(0,t.jsxs)("div",{className:"px-5 py-2.5 bg-slate-50/80 border-b flex items-center justify-between shrink-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)(e$.Z,{className:"w-4 h-4 text-slate-400"}),(0,t.jsx)("span",{className:"font-medium text-slate-700 truncate max-w-[180px]",children:null==p?void 0:p.name}),(0,t.jsx)("span",{className:"text-slate-400",children:"•"}),(0,t.jsxs)("span",{className:"text-slate-500",children:[k.size," of ",j.length," rows"]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(d.z,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>S(new Set(j.map((e,a)=>a))),children:"All"}),(0,t.jsx)(d.z,{variant:"ghost",size:"sm",className:"h-7 text-xs",onClick:()=>S(new Set),children:"None"})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-auto [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-thumb]:bg-slate-200 [&::-webkit-scrollbar-thumb]:rounded-full hover:[&::-webkit-scrollbar-thumb]:bg-slate-300 [&::-webkit-scrollbar-track]:bg-transparent",children:(0,t.jsxs)("table",{className:"w-full text-sm min-w-max",children:[(0,t.jsxs)("thead",{className:"sticky top-0 z-20",children:[(0,t.jsxs)("tr",{className:"bg-slate-100 border-b",children:[(0,t.jsx)("th",{className:"w-10 px-3 py-2 text-center sticky left-0 bg-slate-100 z-30",children:(0,t.jsx)(eY.X,{checked:$.length>0&&$.every((e,a)=>k.has(W+a)),onCheckedChange:()=>{let e=$.map((e,a)=>W+a),a=e.every(e=>k.has(e)),s=new Set(k);
1e.forEach(e=>a?s.delete(e):s.add(e)),S(s)},className:"h-3.5 w-3.5"})}),(0,t.jsx)("th",{className:"w-10 px-2 py-2 text-left text-xs font-semibold text-slate-500",children:"#"}),g.map((e,a)=>{let s=Z.has(a);return(0,t.jsx)("th",{className:"px-3 py-2 text-left ".concat(s?"":"opacity-40"),children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(eY.X,{checked:s,onCheckedChange:()=>ee(a),className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{className:"text-xs font-semibold text-slate-700",children:e})]})},a)})]}),(0,t.jsxs)("tr",{className:"bg-slate-50 border-b",children:[(0,t.jsx)("th",{className:"sticky left-0 bg-slate-50 z-30"}),(0,t.jsx)("th",{}),g.map((e,a)=>{let s=Z.has(a),l=M[a]||"__none__",r="phone"===l;return(0,t.jsx)("th",{className:"px-2 py-1.5 text-left ".concat(s?"":"opacity-40"),children:(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[r&&s&&(0,t.jsxs)(o.Ph,{value:B,onValueChange:U,children:[(0,t.jsx)(o.i4,{className:"h-7 w-16 text-xs bg-white",children:(0,t.jsx)(o.ki,{})}),(0,t.jsx)(o.Bw,{children:eJ.map(e=>(0,t.jsx)(o.Ql,{value:e.code,className:"text-xs",children:e.label},e.code))})]}),(0,t.jsxs)(o.Ph,{value:l,onValueChange:e=>ea(a,e),disabled:!s,children:[(0,t.jsx)(o.i4,{className:"h-7 text-xs ".concat(r?"w-20":"w-24"," ").concat(s?"__none__"!==l?"border-emerald-300 bg-emerald-50/50 text-emerald-700":"bg-white":"bg-slate-100 cursor-not-allowed"),children:(0,t.jsx)(o.ki,{})}),(0,t.jsx)(o.Bw,{children:eG.map(e=>{let s="__none__"!==e.value&&Object.values(M).includes(e.value)&&M[a]!==e.value;return(0,t.jsxs)(o.Ql,{value:e.value,className:"text-xs",disabled:s,children:[e.label,s?" ✓":""]},e.value)})})]})]})},a)})]})]}),(0,t.jsx)("tbody",{children:$.map((e,a)=>{let s=W+a,l=k.has(s);return(0,t.jsxs)("tr",{className:"border-b border-slate-100 transition-colors ".concat(l?"bg-white":"bg-slate-50/30 opacity-40"," hover:bg-slate-50"),children:[(0,t.jsx)("td",{className:"px-3 py-1.5 text-center sticky left-0 bg-inherit z-10",children:(0,t.jsx)(eY.X,{checked:l,onCheckedChange:()=>es(a),className:"h-3.5 w-3.5"})}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-xs text-slate-400",children:s+1}),g.map((l,r)=>{let n=Z.has(r),i=(null==P?void 0:P.row)===s&&(null==P?void 0:P.col)===r,d=e[r],c=M[r];return(0,t.jsx)("td",{className:"px-3 py-1 ".concat(n?c?"":"opacity-50":"opacity-30"),children:i&&n?(0,t.jsx)(u.I,{value:L,onChange:e=>R(e.target.value),onKeyDown:er,onBlur:el,className:"h-6 text-xs",autoFocus:!0}):(0,t.jsxs)("div",{className:"group flex items-center gap-1 rounded px-1 py-0.5 -mx-1 max-w-[160px] ".concat(n?"cursor-pointer hover:bg-slate-100":"cursor-not-allowed"),onClick:()=>n&&et(a,r),children:[(0,t.jsx)("span",{className:"truncate text-xs ".concat(d?"text-slate-600":"text-slate-300"),children:null!=d?d:"—"}),n&&(0,t.jsx)(K.Z,{className:"w-2.5 h-2.5 text-slate-300 opacity-0 group-hover:opacity-100 shrink-0"})]})},r)})]},s)})})]})}),Q>1&&(0,t.jsxs)("div",{className:"px-5 py-2 border-t border-slate-100 flex items-center justify-between text-xs text-slate-500 shrink-0 bg-white",children:[(0,t.jsxs)("span",{children:["Page ",A," of ",Q]}),(0,t.jsxs)("div",{className:"flex gap-1",children:[(0,t.jsx)(d.z,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",disabled:1===A,onClick:()=>I(e=>e-1),children:(0,t.jsx)(z.Z,{className:"w-3.5 h-3.5"})}),(0,t.jsx)(d.z,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",disabled:A===Q,onClick:()=>I(e=>e+1),children:(0,t.jsx)(eN.Z,{className:"w-3.5 h-3.5"})})]})]})]})}),(0,t.jsx)("div",{className:"px-6 py-3 border-t bg-slate-50/50 flex items-center justify-between shrink-0",children:"upload"===m?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{}),(0,t.jsx)(d.z,{variant:"ghost",onClick:()=>s(!1),children:"Cancel"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 text-xs",children:[(0,t.jsxs)("span",{className:"flex items-center gap-1 ".concat(ed?"text-emerald-600":"text-slate-400"),children:[ed?(0,t.jsx)(T.Z,{className:"w-3.5 h-3.5"}):(0,t.jsx)(ew.Z,{className:"w-3.5 h-3.5"}),"Name"]}),(0,t.jsxs)("span",{className:"flex items-center gap-1 ".concat(ec?"text-emerald-600":"text-slate-400"),children:[ec?(0,t.jsx)(T.Z,{className:"w-3.5 h-3.5"}):(0,t.jsx)("span",{className:"w-3.5 h-3.5 rounded-full border border-current"}),"Email"]}),(0,t.jsxs)("span",{className:"flex items-center gap-1 ".concat(eo?"text-emerald-600":"text-slate-400"),children:[eo?(0,t.jsx)(T.Z,{className:"w-3.5 h-3.5"}):(0,t.jsx)("span",{className:"w-3.5 h-3.5 rounded-full border border-current"}),"Phone",eo&&"none"!==B&&(0,t.jsxs)("span",{className:"text-slate-400",children:["(",B,")"]})]}),!en()&&(0,t.jsx)("span",{className:"text-amber-600 ml-2",children:"• Map Name + Email or Phone"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)(d.z,{variant:"ghost",onClick:()=>x("upload"),children:[(0,t.jsx)(eH.Z,{className:"w-4 h-4 mr-1"})," Back"]}),(0,t.jsx)(d.z,{onClick:ei,disabled:q||!en()||0===k.size,className:"bg-emerald-500 hover:bg-emerald-600 text-white min-w-[130px]",children:q?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"w-4 h-4 mr-1.5 animate-spin"})," Importing..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(T.Z,{className:"w-4 h-4 mr-1.5"})," Import ",k.size]})})]})]})})]})})}var e0=s(79587),e1=s(29487),e5=s(42488),e2=s(65621),e4=s(46221),e3=s(87133);function e6(e){let{workspaceId:a,pollInterval:s=3e3,selectedCallId:n,onSelectCall:i,onCallsUpdate:d,excludeCallIds:c=[],recentlyFinishedCalls:o=[],className:m}=e,[u,x]=(0,l.useState)([]),[p,h]=(0,l.useState)(!0),[g,f]=(0,l.useState)({}),j=(0,l.useCallback)(async()=>{try{let e=new URLSearchParams;a&&e.append("workspace_id",a);let s=await C.api.get("/ai-calls/active?".concat(e.toString()));if(s.data.success){let e=(s.data.active_calls||[]).filter((e,a,s)=>a===s.findIndex(a=>a.conversation_id===e.conversation_id)),a=new Map;for(let s of e){let e=s.phone_number;if(!e)continue;let t=a.get(e);if(t){let l=new Date(t.started_at||0).getTime();new Date(s.started_at||0).getTime()>l&&a.set(e,s)}else a.set(e,s)}let t=Array.from(a.values()).filter(e=>!c.includes(e.call_id||"")&&!c.includes(e.conversation_id));x(t)}}catch(e){console.error("Failed to fetch active calls:",e)}finally{h(!1)}},[a,c.join(",")]);(0,l.useEffect)(()=>{j();let e=setInterval(j,s);return()=>clearInterval(e)},[j,s]),(0,l.useEffect)(()=>{c.length>0&&j()},[c.join(",")]),(0,l.useEffect)(()=>{let e=u.filter(e=>!c.includes(e.call_id||"")&&!c.includes(e.conversation_id));null==d||d(e)},[u,c.join(","),d]),(0,l.useEffect)(()=>{let e=()=>{let e={};for(let a of u)a.started_at&&(e[a.conversation_id]=function(e){let a=new Date(e),s=Math.floor((new Date().getTime()-a.getTime())/1e3);return"".concat(Math.floor(s/60).toString().padStart(2,"0"),":").concat((s%60).toString().padStart(2,"0"))}(a.started_at));f(e)};e();let a=setInterval(e,1e3);return()=>clearInterval(a)},[u]);let v=u.filter(e=>!c.includes(e.call_id||"")&&!c.includes(e.conversation_id));return p&&0===v.length?(0,t.jsx)("div",{className:(0,r.cn)("flex items-center justify-center h-full",m),children:(0,t.jsx)(w.Z,{className:"h-5 w-5 animate-spin text-muted-foreground"})}):0===v.length&&0===o.length?(0,t.jsxs)("div",{className:(0,r.cn)("flex flex-col items-center justify-center h-full p-4 text-center",m),children:[(0,t.jsx)("div",{className:"relative mb-2",children:(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-purple-100 to-violet-100 dar
1k:from-purple-900/30 dark:to-violet-900/30 flex items-center justify-center",children:(0,t.jsx)(R.Z,{className:"h-4 w-4 text-purple-400 dark:text-purple-500"})})}),(0,t.jsx)("p",{className:"text-slate-600 dark:text-slate-300 text-xs font-medium",children:"No Active Calls"}),(0,t.jsx)("p",{className:"text-slate-400 dark:text-slate-500 text-[10px] mt-0.5",children:"Initiate AI calls from Pipeline"})]}):(0,t.jsxs)("div",{className:(0,r.cn)("overflow-y-auto",m),children:[v.map(e=>{let a=n===e.conversation_id,s="ringing"===e.status||"initiated"===e.status,l="connected"===e.status||"in_progress"===e.status;return(0,t.jsx)("div",{onClick:()=>null==i?void 0:i(e),className:(0,r.cn)("px-3 py-2.5 cursor-pointer transition-all border-b border-purple-100/50 dark:border-purple-900/30","hover:bg-purple-50/50 dark:hover:bg-purple-900/20",a&&"bg-gradient-to-r from-purple-100/80 to-violet-100/80 dark:from-purple-900/40 dark:to-violet-900/40 border-l-3 border-l-purple-500"),children:(0,t.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,t.jsxs)("div",{className:"relative flex-shrink-0",children:[(0,t.jsx)("div",{className:(0,r.cn)("h-9 w-9 rounded-lg flex items-center justify-center shadow-sm",s&&"bg-gradient-to-br from-amber-400 to-orange-500 shadow-amber-500/20",l&&"bg-gradient-to-br from-emerald-400 to-green-500 shadow-green-500/20",!s&&!l&&"bg-gradient-to-br from-slate-300 to-slate-400 dark:from-slate-600 dark:to-slate-700"),children:(0,t.jsx)(eh.Z,{className:"h-4 w-4 text-white"})}),(s||l)&&(0,t.jsx)("span",{className:(0,r.cn)("absolute -top-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-white dark:border-slate-900",s&&"bg-amber-500 animate-pulse",l&&"bg-green-500")})]}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("span",{className:"font-semibold text-sm text-slate-800 dark:text-slate-100 truncate block",children:e.lead_name||"Unknown"}),(0,t.jsx)("span",{className:"text-[11px] text-slate-400 dark:text-slate-500 font-mono",children:function(e){if(!e)return"";let a=e.replace(/\s/g,"");return a.startsWith("+91")&&13===a.length?"".concat(a.slice(0,3)," ").concat(a.slice(3,8)," ").concat(a.slice(8)):e}(e.phone_number)})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,t.jsx)("span",{className:"text-xs font-mono font-semibold px-1.5 py-0.5 rounded bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-300",children:g[e.conversation_id]||"00:00"}),(0,t.jsxs)("span",{className:(0,r.cn)("px-2 py-0.5 rounded-md text-[10px] font-semibold",s&&"bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300",l&&"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300",!s&&!l&&"bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400"),children:[s&&(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsxs)("span",{className:"relative flex h-1.5 w-1.5",children:[(0,t.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-amber-500"})]}),"Ringing"]}),l&&(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-green-500"}),"Live"]}),!s&&!l&&(0,t.jsx)("span",{className:"capitalize",children:e.status})]})]})]})})]})},e.conversation_id)}),o.length>0&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"px-3 py-1.5 bg-slate-100/80 dark:bg-slate-800/80 border-y border-slate-200/50 dark:border-slate-700/50",children:(0,t.jsxs)("span",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400 flex items-center gap-1.5 uppercase tracking-wider",children:[(0,t.jsx)(b.Z,{className:"h-3 w-3"}),"Completed"]})}),o.map(e=>(0,t.jsx)("div",{className:"px-3 py-2 border-b border-slate-100/50 dark:border-slate-800/50 bg-slate-50/30 dark:bg-slate-900/20",children:(0,t.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg flex items-center justify-center bg-slate-200 dark:bg-slate-700 flex-shrink-0",children:(0,t.jsx)(e3.Z,{className:"h-3.5 w-3.5 text-slate-500 dark:text-slate-400"})}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("span",{className:"font-medium text-sm truncate text-slate-500 dark:text-slate-400",children:e.lead_name||"Unknown"}),(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,t.jsx)("span",{className:"text-[10px] text-slate-400 dark:text-slate-500",children:function(e){let a=new Date(e),s=Math.floor((new Date().getTime()-a.getTime())/1e3);if(s<60)return"just now";let t=Math.floor(s/60);return t<60?"".concat(t,"m ago"):"".concat(Math.floor(t/60),"h ago")}(e.ended_at)}),(0,t.jsx)("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-semibold bg-slate-200/80 text-slate-500 dark:bg-slate-700/80 dark:text-slate-400",children:"Done"})]})]})})]})},"finished-".concat(e.conversation_id)))]})]})}function e8(e){var a;let{call:s,onEndCall:n,className:i}=e,[c,o]=(0,l.useState)("00:00"),[m,u]=(0,l.useState)(!1);(0,l.useEffect)(()=>
1{if(!(null==s?void 0:s.started_at)){o("00:00");return}let e=()=>{o(function(e){let a=new Date(e),s=Math.floor((new Date().getTime()-a.getTime())/1e3);return"".concat(Math.floor(s/60).toString().padStart(2,"0"),":").concat((s%60).toString().padStart(2,"0"))}(s.started_at))};e();let a=setInterval(e,1e3);return()=>clearInterval(a)},[null==s?void 0:s.started_at]);let x=async()=>{if(!s||m)return;let e=s.call_id||s.conversation_id;if(console.log("[ActiveCallUI] Ending call, call_id:",s.call_id,"conversation_id:",s.conversation_id,"using:",e),!e){console.error("[ActiveCallUI] No call_id available to end call");return}u(!0);try{await (null==n?void 0:n(e))}finally{u(!1)}};if(!s)return(0,t.jsx)("div",{className:(0,r.cn)("flex items-center justify-center h-full p-3",i),children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-slate-100 dark:bg-slate-800 flex items-center justify-center",children:(0,t.jsx)(R.Z,{className:"h-4 w-4 text-slate-400"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-slate-500 dark:text-slate-400 text-xs font-medium",children:"No Active Call"}),(0,t.jsx)("p",{className:"text-slate-400 dark:text-slate-500 text-[10px]",children:"Waiting for calls..."})]})]})});let p="ringing"===s.status||"initiated"===s.status,h="connected"===s.status||"in_progress"===s.status;return(0,t.jsxs)("div",{className:(0,r.cn)("flex items-center h-full px-3 py-2",i),children:[(0,t.jsxs)("div",{className:"relative flex-shrink-0 mr-3",children:[(0,t.jsx)("div",{className:(0,r.cn)("h-11 w-11 rounded-xl flex items-center justify-center transition-all shadow-md",p&&"bg-gradient-to-br from-amber-400 to-orange-500 shadow-amber-500/30 animate-pulse",h&&"bg-gradient-to-br from-emerald-400 to-green-500 shadow-green-500/30",!p&&!h&&"bg-gradient-to-br from-slate-300 to-slate-400 dark:from-slate-600 dark:to-slate-700"),children:(0,t.jsx)("span",{className:"text-lg font-bold text-white uppercase",children:(null===(a=s.lead_name)||void 0===a?void 0:a.charAt(0))||"?"})}),(0,t.jsx)("div",{className:(0,r.cn)("absolute -bottom-0.5 -right-0.5 h-4 w-4 rounded-md flex items-center justify-center border-2 border-white dark:border-slate-900",p&&"bg-amber-500",h&&"bg-green-500",!p&&!h&&"bg-slate-400"),children:(p||h)&&(0,t.jsx)(R.Z,{className:"h-2 w-2 text-white"})})]}),(0,t.jsxs)("div",{className:"flex-1 min-w-0 mr-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-slate-800 dark:text-slate-100 truncate",children:s.lead_name||"Unknown"}),(0,t.jsxs)("span",{className:(0,r.cn)("flex-shrink-0 px-1.5 py-0.5 rounded text-[9px] font-semibold",p&&"bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300",h&&"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300",!p&&!h&&"bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-400"),children:[p&&(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsxs)("span",{className:"relative flex h-1.5 w-1.5",children:[(0,t.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-amber-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-amber-500"})]}),"Ringing"]}),h&&(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{className:"h-1.5 w-1.5 rounded-full bg-green-500"}),"Live"]}),!p&&!h&&(0,t.jsx)("span",{className:"capitalize",children:s.status})]})]}),(0,t.jsx)("p",{className:"text-[10px] font-mono text-slate-400 dark:text-slate-500 truncate",children:function(e){if(!e)return"";let a=e.replace(/\s/g,"");return a.startsWith("+91")&&13===a.length?"".concat(a.slice(0,3)," ").concat(a.slice(3,8)," ").concat(a.slice(8)):e}(s.phone_number)})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(0,t.jsx)("span",{className:"text-lg font-mono font-bold text-slate-700 dark:text-slate-200",children:c}),(0,t.jsxs)(d.z,{variant:"destructive",size:"sm",className:"h-8 rounded-lg px-2.5 gap-1 shadow-md shadow-red-500/20",onClick:x,disabled:m,children:[(0,t.jsx)(e3.Z,{className:"h-3.5 w-3.5"}),(0,t.jsx)("span",{className:"text-[10px] font-medium",children:m?"...":"End"})]})]})]})}var e9=s(55589),e7=s(17168);function ae(e){var a;let{isOpen:s,onClose:n,conversationId:i,leadName:d,phoneNumber:c,duration:o}=e,[m,u]=(0,l.useState)(null),[x,p]=(0,l.useState)(!1),[h,g]=(0,l.useState)(null),[f,j]=(0,l.useState)("summary");(0,l.useEffect)(()=>{s&&i&&(b(),j("summary"))},[s,i]);let b=async()=>{p(!0),g(null);try{let e=new URLSearchParams;c&&e.append("phone_number",c);
1let a="/calls/elevenlabs/transcript/".concat(i).concat(e.toString()?"?"+e.toString():""),s=await C.api.get(a);s.data.success?u({transcript:s.data.transcript||[],summary:s.data.summary,summary_title:s.data.summary_title,call_successful:s.data.call_successful,main_language:s.data.main_language,call_duration_secs:s.data.call_duration_secs}):g(s.data.error||"Failed to fetch transcript")}catch(s){var e,a;console.error("Failed to fetch transcript:",s),g((null==s?void 0:null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to fetch transcript")}finally{p(!1)}},v=(null==m?void 0:m.transcript)||[];return(0,t.jsx)(D.Vq,{open:s,onOpenChange:e=>!e&&n(),children:(0,t.jsxs)(D.cZ,{className:"max-w-2xl max-h-[85vh] flex flex-col",children:[(0,t.jsxs)(D.fK,{className:"flex-shrink-0 border-b pb-4",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2 text-lg",children:[(0,t.jsx)(F.Z,{className:"h-5 w-5 text-purple-500"}),(null==m?void 0:m.summary_title)||"Call Details"]}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-4 mt-3 text-sm",children:[d&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-slate-600 dark:text-slate-300",children:[(0,t.jsx)(eu.Z,{className:"h-4 w-4 text-slate-400"}),(0,t.jsx)("span",{className:"font-medium",children:d})]}),c&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-slate-600 dark:text-slate-300",children:[(0,t.jsx)(R.Z,{className:"h-4 w-4 text-slate-400"}),(0,t.jsx)("span",{className:"font-mono text-xs",children:c})]}),(o||(null==m?void 0:m.call_duration_secs))&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-slate-600 dark:text-slate-300",children:[(0,t.jsx)(I.Z,{className:"h-4 w-4 text-slate-400"}),(0,t.jsx)("span",{children:(a=o||(null==m?void 0:m.call_duration_secs)||0)&&!(a<=0)?"".concat(Math.floor(a/60),":").concat((a%60).toString().padStart(2,"0")):"0:00"})]})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-hidden flex flex-col min-h-[350px]",children:x?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-3",children:[(0,t.jsx)(w.Z,{className:"h-8 w-8 animate-spin text-purple-500"}),(0,t.jsx)("p",{className:"text-sm text-slate-500",children:"Loading..."})]}):h?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center px-4",children:[(0,t.jsx)("div",{className:"h-12 w-12 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center",children:(0,t.jsx)(F.Z,{className:"h-6 w-6 text-red-500"})}),(0,t.jsx)("p",{className:"text-sm text-red-600 dark:text-red-400",children:h})]}):(0,t.jsxs)(e7.Tabs,{value:f,onValueChange:j,className:"flex-1 flex flex-col overflow-hidden",children:[(0,t.jsxs)(e7.TabsList,{className:"grid w-full grid-cols-2 mb-4",children:[(0,t.jsxs)(e7.TabsTrigger,{value:"summary",className:"flex items-center gap-2",children:[(0,t.jsx)(eg.Z,{className:"h-4 w-4"}),"Summary"]}),(0,t.jsxs)(e7.TabsTrigger,{value:"transcript",className:"flex items-center gap-2",children:[(0,t.jsx)(eC.Z,{className:"h-4 w-4"}),"Transcript"]})]}),(0,t.jsx)(e7.TabsContent,{value:"summary",className:"flex-1 overflow-y-auto mt-0 max-h-[400px]",children:(null==m?void 0:m.summary)?(0,t.jsxs)("div",{className:"space-y-4 p-4",children:[(0,t.jsxs)("div",{className:"relative overflow-hidden rounded-2xl border border-purple-200/50 dark:border-purple-700/30 bg-gradient-to-br from-white via-purple-50/50 to-violet-50 dark:from-slate-900 dark:via-purple-950/30 dark:to-violet-950/20 shadow-lg shadow-purple-100/50 dark:shadow-purple-900/20",children:[(0,t.jsx)("div",{className:"absolute -top-10 -right-10 h-32 w-32 bg-gradient-to-br from-purple-400/20 to-violet-500/20 rounded-full blur-2xl"}),(0,t.jsx)("div",{className:"absolute -bottom-8 -left-8 h-24 w-24 bg-gradient-to-br from-indigo-400/15 to-purple-500/15 rounded-full blur-xl"}),(0,t.jsxs)("div",{className:"relative p-5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-xl bg-gradient-to-br from-purple-500 via-violet-500 to-indigo-600 flex items-center justify-center shadow-lg shadow-purple-500/30",children:(0,t.jsx)(eg.Z,{className:"h-5 w-5 text-white"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"font-bold text-purple-900 dark:text-purple-100",children:"AI Call Summary"}),(0,t.jsx)("p",{className:"text-xs text-purple-600/70 dark:text-purple-400/70",children:"Powered by AI analysis"})]})]}),(0,t.jsx)("div",{className:"bg-white/60 dark:bg-slate-800/40 rounded-xl p-4 backdrop-blur-sm border border-purple-100/50 dark:border-purple-800/30",children:(0,t.jsx)("p",{className:"text-slate-700 dark:text-slate-200 leading-relaxed text-[15px]",children:m.summary})})]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[m.main_language&&(0,t.jsxs)("div",{className:"bg-gradient-to-br from-slate-50 to-slate-100/50 dark:from-slate-800/80 dark:to-slate-800/40 rounded-xl p-4 border border-slate-200/50 dark:border-slate-700/50",children:[(0,t.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-slate-400 dark:text-slate-500 mb-1.5 font-semibold",children:"Language"}),(0,t.jsx)("p",{className:"font-bold text-slate-700 dark:text-slate-200 uppercase text-lg",children:m.main_language})]}),m.call_successful&&(0,t.jsxs)("div",{className:(0,r.cn)("rounded-xl p-4 border","true"===m.call_successful&&"bg-gradient-to-br from-green-50 to-emerald-50/50 dark:from-green-900/20 dark:to-emerald-900/10 border-green-200/50 dark:border-green-700/30","false"===m.call_successful&&"bg-gradient-to-br from-red-50 to-rose-50/50 dark:from-red-900/20 dark:to-rose-900/10 border-red-200/50 dark:border-red-700/30","unknown"===m.call_successful&&"bg-gradient-to-br from-slate-50 to-slate-100/50 dark:from-slate-800/80 dark:to-slate-800/40 border-slate-200/50 dark:border-slate-700/50"),children:[(0,t.jsx)("p",{className:"text-[10px] uppercase tracking-wider text-slate-400 dark:text-slate-500 mb-1.5 font-semibold",children:"Call Status"}),(0,t.jsx)("p",{className:(0,r.cn)("font-bold capitalize text-lg","true"===m.call_successful&&"text-green-600 dark:text-green-400","fal
1se"===m.call_successful&&"text-red-600 dark:text-red-400","unknown"===m.call_successful&&"text-slate-600 dark:text-slate-300"),children:"unknown"===m.call_successful?"Completed":"true"===m.call_successful?"Successful":"Unsuccessful"})]})]})]}):(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center",children:[(0,t.jsx)("div",{className:"h-12 w-12 rounded-full bg-slate-100 dark:bg-slate-800 flex items-center justify-center",children:(0,t.jsx)(eg.Z,{className:"h-6 w-6 text-slate-400"})}),(0,t.jsx)("p",{className:"text-sm text-slate-500",children:"No summary available"})]})}),(0,t.jsx)(e7.TabsContent,{value:"transcript",className:"flex-1 overflow-y-auto mt-0 max-h-[400px]",children:0===v.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center h-full gap-2 text-center",children:[(0,t.jsx)("div",{className:"h-12 w-12 rounded-full bg-slate-100 dark:bg-slate-800 flex items-center justify-center",children:(0,t.jsx)(F.Z,{className:"h-6 w-6 text-slate-400"})}),(0,t.jsx)("p",{className:"text-sm text-slate-500",children:"No transcript available"})]}):(0,t.jsx)("div",{className:"space-y-3 px-1 py-2",children:v.map((e,a)=>{var s,l;let n=(null===(s=e.role)||void 0===s?void 0:s.toLowerCase())==="agent",i=(null===(l=e.role)||void 0===l?void 0:l.toLowerCase())==="user";return e.message&&"None"!==e.message?(0,t.jsxs)("div",{className:(0,r.cn)("flex gap-3",i&&"flex-row-reverse"),children:[(0,t.jsx)("div",{className:(0,r.cn)("flex-shrink-0 h-8 w-8 rounded-full flex items-center justify-center text-xs font-semibold",n&&"bg-gradient-to-br from-purple-500 to-violet-600 text-white",i&&"bg-gradient-to-br from-emerald-500 to-green-600 text-white",!n&&!i&&"bg-slate-200 dark:bg-slate-700 text-slate-600 dark:text-slate-300"),children:n?"AI":i?(null==d?void 0:d.charAt(0))||"U":"?"}),(0,t.jsx)("div",{className:(0,r.cn)("flex-1 max-w-[80%] rounded-2xl px-4 py-2.5",n&&"bg-purple-50 dark:bg-purple-900/20 rounded-tl-sm",i&&"bg-emerald-50 dark:bg-emerald-900/20 rounded-tr-sm",!n&&!i&&"bg-slate-100 dark:bg-slate-800"),children:(0,t.jsx)("p",{className:(0,r.cn)("text-sm leading-relaxed",n&&"text-purple-900 dark:text-purple-100",i&&"text-emerald-900 dark:text-emerald-100",!n&&!i&&"text-slate-700 dark:text-slate-300"),children:e.message})})]},a):null})})})]})})]})})}function aa(e){let{workspaceId:a,limit:s=20,pollInterval:n=1e4,className:i,showPopup:d=!0,compact:c=!1,onlyAnswered:o=!1,largeText:m=!1}=e,[u,x]=(0,l.useState)([]),[p,h]=(0,l.useState)(!0),[g,f]=(0,l.useState)(null),[j,b]=(0,l.useState)(!1),v=async()=>{try{let e=new URLSearchParams;a&&e.append("workspace_id",a),e.append("limit",s.toString()),e.append("include_ai_classification","true");let t=await C.api.get("/calls/finished?".concat(e.toString()));t.data.success&&x(t.data.calls||[])}catch(e){console.error("Failed to fetch finished calls:",e)}finally{h(!1)}};(0,l.useEffect)(()=>{v();let e=setInterval(v,n);return()=>clearInterval(e)},[a,s,n]);let N=e=>{d&&e.provider_call_id&&(f(e),b(!0))};if(p&&0===u.length)return(0,t.jsx)("div",{className:(0,r.cn)("flex items-center justify-center h-full p-3",i),children:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-slate-400",children:[(0,t.jsx)("div",{className:"h-3 w-3 border-2 border-slate-300 border-t-slate-500 rounded-full animate-spin"}),(0,t.jsx)("span",{className:"text-xs",children:"Loading..."})]})});let w=o?u.filter(e=>(e.duration_seconds>0||"connected"===e.disposition||"completed"===e.outcome||"connected"===e.outcome)&&!!e.provider_call_id):u;return 0===w.length?(0,t.jsxs)("div",{className:(0,r.cn)("flex flex-col items-center justify-center h-full p-4 text-center",i),children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-slate-100 dark:bg-slate-800 flex items-center justify-center mb-2",children:(0,t.jsx)(e3.Z,{className:"h-4 w-4 text-slate-400"})}),(0,t.jsx)("p",{className:"text-slate-500 dark:text-slate-400 text-xs font-medium",children:o?"No answered calls yet":"No History"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:(0,r.cn)("overflow-y-auto",i),children:w.map((e,a)=>{var s;let l=e.ai_interest_category,n=l?e9.nb[l]:null,i=e.ai_interest_emoji||(null==n?void 0:n.emoji),c=e.ai_interest_score,o=e.duration_seconds>0||"connected"===e.disposition||"completed"===e.outcome||"connected"===e.outcome,u=!!e.provider_call_id&&o,x=!o||"no_answer"===e.disposition||"no_answer"===e.outcome;return(0,t.jsx)("div",{onClick:()=>u&&d&&N(e),className:(0,r.cn)("px-2 py-1.5 transition-all",u&&d&&"cursor-pointer hover:bg-purple-50/80 dark:hover:bg-purple-900/20",x&&"opacity-50 cursor-default",!u&&!x&&"hover:bg-slate-50/80 dark:hover:bg-slate-800/50",a!==w.length-1&&"border-b border-slate-100 dar
1k:border-slate-800"),children:(0,t.jsxs)("div",{className:(0,r.cn)("flex items-center",m?"gap-2.5":"gap-1.5"),children:[(0,t.jsx)("div",{className:(0,r.cn)("rounded flex items-center justify-center font-semibold flex-shrink-0",m?"h-8 w-8 text-sm":"h-6 w-6 text-[10px]",x&&"bg-gray-200 text-gray-400 dark:bg-gray-700 dark:text-gray-500",!x&&"hot"===l&&"bg-green-100 text-green-600 dark:bg-green-900/40 dark:text-green-400",!x&&"warm"===l&&"bg-amber-100 text-amber-600 dark:bg-amber-900/40 dark:text-amber-400",!x&&"cold"===l&&"bg-slate-100 text-slate-500 dark:bg-slate-800 dark:text-slate-400",!x&&!l&&"bg-slate-100 text-slate-500 dark:bg-slate-800 dark:text-slate-400"),children:x?(0,t.jsx)(e3.Z,{className:m?"h-4 w-4":"h-3 w-3"}):i||"\uD83D\uDCDE"}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-1",children:[(0,t.jsx)("span",{className:(0,r.cn)("font-medium text-slate-700 dark:text-slate-200 truncate",m?"text-sm":"text-[11px]"),children:e.lead_name||"Unknown"}),(0,t.jsxs)("div",{className:"flex items-center gap-1 flex-shrink-0",children:[x&&(0,t.jsx)("span",{className:(0,r.cn)("px-1 py-0.5 rounded font-medium bg-gray-200 text-gray-500 dark:bg-gray-700 dark:text-gray-400",m?"text-[10px]":"text-[8px]"),children:"No Answer"}),u&&d&&(0,t.jsx)(F.Z,{className:m?"h-4 w-4 text-purple-400":"h-3 w-3 text-purple-400"}),!x&&null!=c&&(0,t.jsx)("span",{className:(0,r.cn)("px-1 py-0.5 rounded font-bold",m?"text-[10px]":"text-[8px]","hot"===l&&"bg-green-500 text-white","warm"===l&&"bg-amber-500 text-white","cold"===l&&"bg-slate-400 text-white",!l&&"bg-slate-300 text-slate-600"),children:c})]})]}),!x&&e.ai_call_summary&&(0,t.jsxs)("p",{className:(0,r.cn)("text-slate-500 dark:text-slate-400 truncate mt-0.5 italic",m?"text-xs":"text-[9px]"),children:['"',e.ai_call_summary.split(".")[0].slice(0,60),e.ai_call_summary.length>60?"...":"",'"']}),(0,t.jsxs)("div",{className:(0,r.cn)("flex items-center gap-1.5 text-slate-400 dark:text-slate-500 mt-0.5",m?"text-[10px]":"text-[8px]"),children:[(0,t.jsxs)("span",{className:"flex items-center gap-0.5",children:[(0,t.jsx)(I.Z,{className:m?"h-3 w-3":"h-2 w-2"}),(s=e.duration_seconds)&&!(s<=0)?"".concat(Math.floor(s/60),":").concat((s%60).toString().padStart(2,"0")):"0:00"]}),(0,t.jsx)("span",{children:"•"}),(0,t.jsx)("span",{children:function(e){let a=new Date(e),s=Math.floor((new Date().getTime()-a.getTime())/6e4);if(s<1)return"just now";if(s<60)return"".concat(s,"m ago");let t=Math.floor(s/60);return t<24?"".concat(t,"h ago"):"".concat(Math.floor(t/24),"d ago")}(e.ended_at)})]})]})]})},e.id)})}),d&&(0,t.jsx)(ae,{isOpen:j,onClose:()=>{b(!1),f(null)},conversationId:(null==g?void 0:g.provider_call_id)||"",leadName:null==g?void 0:g.lead_name,phoneNumber:null==g?void 0:g.phone_number,duration:null==g?void 0:g.duration_seconds})]})}function as(e){let{workspaceId:a,className:s}=e,[n,i]=(0,l.useState)(null),[d,c]=(0,l.useState)(0),[o,m]=(0,l.useState)([]),[u,x]=(0,l.useState)([]),[p,h]=(0,l.useState)(!1),g=(0,l.useRef)([]),f=(0,l.useCallback)((e,a)=>a.some(a=>a.conversation_id===e.conversation_id||a.call_id&&e.call_id&&a.call_id===e.call_id),[]),j=(0,l.useCallback)(e=>{c(e.length);let a=g.current.filter(a=>{let s=e.find(e=>e.conversation_id===a.conversation_id),t=o.includes(a.conversation_id)||o.includes(a.call_id||"");return!s&&!t});a.length>0&&x(e=>[...a.filter(a=>!f(a,e)).map(e=>({...e,status:"finished",ended_at:new Date().toISOString()})),...e].slice(0,10)),g.current=e,!n&&e.length>0?i(e[0]):n&&!e.find(e=>e.conversation_id===n.conversation_id)&&(e.length>0?i(e[0]):i(null))},[n,o,f]),b=async e=>{if(!e){y.default.error("No call ID available");return}console.log("[Calls Monitor] Ending call:",e,"workspace:",a);try{let s=await C.api.post("/ai-calls/cancel/".concat(e),{},{params:{workspace_id:a}});console.log("[Calls Monitor] Cancel response:",s.data);let t=[e];(null==n?void 0:n.conversation_id)&&n.conversation_id!==e&&t.push(n.conversation_id),(null==n?void 0:n.call_id)&&n.call_id!==e&&t.push(n.call_id),m(e=>[...new Set([...e,...t])]),n&&(g.current=g.current.filter(e=>e.conversation_id!==n.conversation_id)),n&&x(e=>f(n,e)?e:[{...n,status:"finished",ended_at:new Date().toISOString()},...e].slice(0,10)),y.default.success("Call ended"),i(null),setTimeout(()=>{m(e=>e.filter(e=>!t.includes(e)))},1e4)}catch(r){var s,t,l;console.error("[Calls Monitor] Failed to end call:",(null==r?void 0:null===(s=r.response)||void 0===s?void 0:s.data)||r);let a=(null==r?void 0:null===(l=r.response)||void 0===l?void 0:null===(t=l.data)||void 0===t?void 0:t.detail)||"Failed to end call";if(y.default.error(a),a.includes("already ended")||a.includes("not found")){let a=[e];(null==n?void 0:n.conversation_id)&&n.conversation_id!==e&&a.push(n.conversation_id),m(e=>[...new Set([...e,...a])]),i(null),setTimeout(()=>{m(e=>e.filter(e=>!a.includes(e)))},1e4)}}};return(0,t.jsxs)("div",{className:(0,r.cn)("h-[calc(100vh-380px)] flex gap-3",s),children:[(0,t.jsxs)("div",{className:"flex-[7] flex flex-col overflow-hidden rounded-xl bg-gradient-to-br from-violet-500/5 via-purple-500/5 to-fuchsia-500/5 dark:from-violet-500/10 dark:via-purple-500/10 dark:to-fuchsia-500/10 border border-purple-200/50 dark:border-purple-800/30 shadow-lg shadow-purple-500/5",children:[(0,t.jsx)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-purple-200/50 dark:border-purple-800/30 bg-gradient-to-r from-white/80 to-purple-50/80 dark:from-slate-900/80 dark:to-purple-950/50",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("div",{className:"h-7 w-7 rounded-lg bg-gradient-to-br from-violet-500 via-purple-500 to-fuchsia-500 flex items-center justify-center shadow-md shadow-purple-500/20",children:(0,t.jsx)(eh.Z,{className:"h-3.5 w-3.5 text-white"})}),d>0&&(0,t.jsx)("span",{className:"absolute -top-0.5 -right-0.5 h-2.5 w-2.5 rounded-full bg-green-500 border border-white dark:border-slate-900 animate-pulse"})]}),(0,t.jsx)("span",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:"AI Call Monitor"})]}),(0,t.jsx)("div",{className:"flex items-center gap-2",children:d>0&&(0,t.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-0.5 rounded-full bg-green-500/10 border border-green-500/20",children:[(0,t.jsx)(e5.Z,{className:"h-3 w-3 text-green-500 animate-pulse"}),(0,t.jsxs)("span",{className:"text-xs font-semibold text-green-600 dark:text-green-400",children:[d," Live"]})]})})]})}),(0,t.jsxs)("div",{className:"flex-1 overflow-hidden bg-white/50 dark:bg-slate-900/50 flex flex-col",children:[(0,t.jsx)("div",{className:"flex-shrink-0",children:(0,t.jsx)(e6,{workspaceId:a,pollInterval:3e3,selectedCallId:null==n?void 0:n.conversation_id,onSelectCall:i,onCallsUpdate:j,excludeCallIds:o,recentlyFinishedCalls:u,className:"max-h-[200px]"})}),(0,t.jsxs)("div",{className:"flex-1 min-h-0 flex flex-col border-t border-purple-200/30 dark:border-purple-800/20",children:[(0,t.jsx)("div",{className:"flex-shrink-0 px-3 py-1.5 bg-slate-50/80 dark:bg-slate-800/50",children:(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(e2.Z,{className:"h-3 w-3 text-slate-400"}),(0,t.jsx)("span",{className:"text-[10px] font-semibold text-slate-500 dark:text-slate-400 uppercase tracking-wider",children:"Call History"})]})}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto",children:(0,t.jsx)(aa,{workspaceId:a,limit:15,pollInterval:1e4,showPopup:!1,largeText:!0,className:"h-full"})})]})]})]}),(0,t.jsxs)("div",{className:"flex-[3] flex flex-col gap-3 min-w-[320px]",children:[(0,t.jsxs)("div",{className:"flex-[3] flex flex-col overflow-hidden rounded-xl bg-gradient-to-br from-emerald-500/5 via-green-500/5 to-teal-500/5 dark:from-emerald-500/10 dark:via-green-500/10 dark:to-teal-500/10 border border-green-200/50 dark:border-green-800/30 shadow-lg shadow-green-500/5",children:[(0,t.jsx)("div",{className:"flex-shrink-0 px-3 py-1.5 border-b border-green-200/50 dark:border-green-800/30 bg-gradient-to-r from-white/80 to-green-50/80 dark:from-slate-900/80 dark:to-green-950/50",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-6 w-6 rounded-md bg-gradient-to-br from-emerald-500 via-green-500 to-teal-500 flex items-center justify-center shadow-sm shadow-green-500/20",children:(0,t.jsx)(R.Z,{className:"h-3 w-3 text-white"})}),(0,t.jsx)("span",{className:"text-xs font-semibold text-slate-700 dark:text-slate-200",children:"Current Call"})]})}),(0,t.jsx)("div",{className:"flex-1 bg-white/50 dark:bg-slate-900/50",children:(0,t.jsx)(e8,{call:n,onEndCall:b,className:"rounded-none border-0 bg-transparent h-full"})})]}),(0,t.jsxs)("div",{className:"flex-[7] min-h-0 flex flex-col overflow-hidden rounded-xl bg-gradient-to-br from-indigo-500/5 via-blue-500/5 to-cyan-500/5 dark:from-indigo-500/10 dark:via-blue-500/10 dark:to-cyan-500/10 border border-indigo-200/50 dark:border-indigo-800/30 shadow-lg shadow-indigo-500/5",children:[(0,t.jsx)("div",{className:"flex-shrink-0 px-3 py-2 border-b border-indigo-200/50 dark:border-indigo-800/30 bg-gradient-to-r from-white/80 to-indigo-50/80 dark:from-slate-900/80 dark:to-indigo-950/50",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-7 w-7 rounded-lg bg-gradient-to-br from-indigo-500 via-blue-500 to-cyan-500 flex items-center justify-center shadow-md shadow-indigo-500/20",children:(0,t.jsx)(e4.Z,{className:"h-3.5 w-3.5 text-white"})}),(0,t.jsx)("span",{className:"text-sm font-semibold text-slate-700 dark:text-slate-200",children:"Analytics"})]})}),(0,t.jsx)("div",{className:"flex-1 overflow-hidden bg-white/50 dark:bg-slate-900/50",children:(0,t.jsx)(aa,{workspaceId:a,limit:20,pollInterval:1e4,showPopup:!0,onlyAnswered:!0,className:"h-full"})})]})]})]})}var at=s(68300),al=s(35471),ar=s(48662);function an(e){return"".concat(Math.floor(e/60).toString().padStart(2,"0"),":").concat((e%60).toString().padStart(2,"0"))}var ai=s(84881);function ad(e){let{open:a,onOpenChange:s,lead:r,onCallEnded:n}=e,{user:i}=(0,ai.a)(),{status:c,customerPhone:o,duration:m,error:u,callId:x,makeCall:p,endCall:h,reset:g,isActive:f}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},[a,s]=(0,l.useState)({status:"idle",customerPhone:null,duration:0,error:null,callId:null,refId:null}),t=(0,l.useRef)(null),r=(0,l.useRef)(null),n=(0,l.useRef)(null),i=(0,l.useRef)(null),d=(0,l.useRef)(null),c=(0,l.useRef)(null),o=(0,l.useRef)(e);(0,l.useEffect)(()=>{o.current=e},[e]);let m=(0,l.useCallback)(()=>{d.current&&(clearInterval(d.current),d.current=null),i.current&&(i.current.disconnect(),i.current=null),n.current&&(n.current.getTracks().forEac
1h(e=>e.stop()),n.current=null),r.current&&(r.current.close(),r.current=null),t.current&&(t.current.close(),t.current=null),c.current=null},[]),u=(0,l.useCallback)(async e=>{var a,l,r,i;let{customerPhone:u,workspaceId:h,contactId:g,leadId:f,agentName:j}=e;if(!u){s(e=>({...e,status:"error",error:"Customer phone is required"}));return}m();try{let e;s(e=>({...e,status:"checking-mic",customerPhone:u,error:null}));try{e=await navigator.mediaDevices.getUserMedia({audio:{sampleRate:16e3,channelCount:1,echoCancellation:!0,noiseSuppression:!0}}),n.current=e}catch(t){let e="Microphone access required";"NotFoundError"===t.name?e="No microphone found":"NotAllowedError"===t.name&&(e="Microphone permission denied"),s(a=>({...a,status:"error",error:e})),null===(a=(l=o.current).onCallError)||void 0===a||a.call(l,e);return}s(e=>({...e,status:"connecting"}));let r="https:"===window.location.protocol?"wss:":"ws:",i="".concat(r,"//").concat(window.location.host,"/api/sip-proxy/browser-voice-call"),b=new WebSocket(i);return t.current=b,await new Promise((e,a)=>{b.onopen=()=>e(),b.onerror=()=>a(Error("WebSocket connection failed")),setTimeout(()=>a(Error("Connection timeout")),1e4)}),b.send(JSON.stringify({type:"start_call",customer_phone:u,workspace_id:h,contact_id:g,lead_id:f,agent_name:j})),s(e=>({...e,status:"calling"})),b.onmessage=async a=>{try{var t,l,r,n,i,h;let g=JSON.parse(a.data);switch(g.type){case"call_initiated":s(e=>({...e,callId:g.call_id,refId:g.ref_id})),null===(t=(l=o.current).onCallStarted)||void 0===t||t.call(l,u,g.call_id);break;case"connected":c.current=Date.now(),d.current=setInterval(()=>{if(c.current){let e=Math.floor((Date.now()-c.current)/1e3);s(a=>({...a,duration:e}))}},1e3),s(e=>({...e,status:"connected"})),await x(b,e);break;case"audio":p(g.data);break;case"call_ended":let f=c.current?Math.floor((Date.now()-c.current)/1e3):0;m(),s(e=>({...e,status:"ended",duration:f})),null===(r=(n=o.current).onCallEnded)||void 0===r||r.call(n,f);break;case"error":m(),s(e=>({...e,status:"error",error:g.message||"Call failed"})),null===(i=(h=o.current).onCallError)||void 0===i||i.call(h,g.message||"Call failed")}}catch(e){console.error("[BrowserVoice] Message parse error:",e)}},b.onclose=()=>{let e=c.current?Math.floor((Date.now()-c.current)/1e3):0;m(),s(a=>{if("connected"===a.status||"calling"===a.status){var s,t;return null===(s=(t=o.current).onCallEnded)||void 0===s||s.call(t,e),{...a,status:"ended",duration:e}}return a})},b.onerror=()=>{m(),s(e=>({...e,status:"error",error:"Connection lost"}))},{callId:void 0,refId:void 0}}catch(a){m();let e=a instanceof Error?a.message:"Call failed";s(a=>({...a,status:"error",error:e})),null===(r=(i=o.current).onCallError)||void 0===r||r.call(i,e);return}},[m]),x=async(e,a)=>{try{let s=new AudioContext({sampleRate:16e3});r.current=s;let t=s.createMediaStreamSource(a),l=s.createScriptProcessor(4096,1,1);l.onaudioprocess=a=>{if(e.readyState!==WebSocket.OPEN)return;let s=a.inputBuffer.getChannelData(0),t=new Int16Array(s.length);for(let e=0;e<s.length;e++){let a=Math.max(-1,Math.min(1,s[e]));t[e]=a<0?32768*a:32767*a}let l=new Uint8Array(t.buffer),r=btoa(String.fromCharCode(...l));e.send(JSON.stringify({type:"audio",data:r}))},t.connect(l),l.connect(s.destination),console.log("[BrowserVoice] Audio streaming started")}catch(e){console.error("[BrowserVoice] Audio streaming error:",e)}},p=e=>{try{r.current||(r.current=new AudioContext({sampleRate:16e3}));let a=r.current,s=atob(e),t=new Uint8Array(s.length);for(let e=0;e<s.length;e++)t[e]=s.charCodeAt(e);let l=new Int16Array(t.buffer),n=new Float32Array(l.length);for(let e=0;e<l.length;e++)n[e]=l[e]/32768;let i=a.createBuffer(1,n.length,16e3);i.copyToChannel(n,0);let d=a.createBufferSource();d.buffer=i,d.connect(a.destination),d.start()}catch(e){console.error("[BrowserVoice] Audio playback error:",e)}},h=(0,l.useCallback)(()=>{var e,a;t.current&&t.current.readyState===WebSocket.OPEN&&t.current.send(JSON.stringify({type:"end_call"}));let l=c.current?Math.floor((Date.now()-c.current)/1e3):0;m(),s(e=>({...e,status:"ended",duration:l})),null===(e=(a=o.current).onCallEnded)||void 0===e||e.call(a,l)},[m]),g=(0,l.useCallback)(()=>{m(),s({status:"idle",customerPhone:null,duration:0,error:null,callId:null,refId:null})},[m]);return(0,l.useEffect)(()=>m,[m]),{...a,makeCall:u,endCall:h,reset:g,isActive:"calling"===a.status||"connected"===a.status}}({onCallEnded:e=>{null==n||n(e)}});(0,l.useEffect)(()=>{a||g()},[a,g]),(0,l.useEffect)(()=>{a&&(null==r?void 0:r.phone)&&"idle"===c&&j()},[a,r]);let j=()=>{(null==r?void 0:r.phone)&&p({customerPhone:r.phone,workspaceId:null==i?void 0:i.workspace_id,contactId:r.contactId||r.id,leadId:r.id,agentName:(null==i?void 0:i.full_name)||(null==i?void 0:i.email)||"Agent"})},b=()=>{h()},v=async()=>
1{if(x&&("ended"===c||m>0))try{await fetch("/api/sip-proxy/calls/".concat(x,"/complete"),{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({disposition:m>0?"connected":"no_answer",duration_seconds:m})})}catch(e){console.error("[SmartfloCallDialog] Failed to complete call:",e)}g(),s(!1)};return r?(0,t.jsx)(D.Vq,{open:a,onOpenChange:v,children:(0,t.jsxs)(D.cZ,{className:"max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(al.Z,{className:"h-5 w-5 ".concat("connected"===c?"text-green-600":"text-blue-600")}),"ended"===c?"Call Ended":"connected"===c?"Call Connected":"calling"===c?"Calling...":"Browser Call"]}),(0,t.jsx)(D.Be,{children:"checking-mic"===c?"Checking microphone access...":"connecting"===c?"Connecting to call server...":"calling"===c?"Calling ".concat(r.name,"..."):"connected"===c?"Call in progress - speak into your microphone":"ended"===c?"Call completed":"error"===c?"Call failed":"Starting call..."})]}),(0,t.jsxs)("div",{className:"py-4 flex flex-col items-center gap-4",children:[(0,t.jsxs)("div",{className:"text-center",children:[(0,t.jsx)("p",{className:"text-lg font-semibold",children:r.name}),r.company&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:r.company}),(0,t.jsx)("p",{className:"text-sm text-blue-600",children:r.phone})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:["checking-mic"===c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-amber-100 dark:bg-amber-900 flex items-center justify-center",children:(0,t.jsx)(ar.Z,{className:"h-8 w-8 text-amber-600 animate-pulse"})}),(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"Checking microphone access..."})]}),"connecting"===c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-blue-100 dark:bg-blue-900 flex items-center justify-center",children:(0,t.jsx)(w.Z,{className:"h-8 w-8 text-blue-600 animate-spin"})}),(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"Connecting to call server..."})]}),"calling"===c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-blue-100 dark:bg-blue-900 flex items-center justify-center animate-pulse",children:(0,t.jsx)(R.Z,{className:"h-8 w-8 text-blue-600"})}),(0,t.jsxs)("span",{className:"absolute -bottom-1 -right-1 flex h-5 w-5",children:[(0,t.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-5 w-5 bg-blue-500"})]})]}),(0,t.jsx)("span",{className:"text-sm font-medium text-blue-600",children:"Ringing..."}),(0,t.jsxs)(d.z,{variant:"destructive",onClick:b,children:[(0,t.jsx)(e3.Z,{className:"h-4 w-4 mr-2"}),"Cancel"]})]}),"connected"===c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-green-100 dark:bg-green-900 flex items-center justify-center",children:(0,t.jsx)(T.Z,{className:"h-8 w-8 text-green-600"})}),(0,t.jsx)("span",{className:"text-base font-semibold text-green-600",children:"Connected"}),(0,t.jsx)("span",{className:"text-3xl font-mono font-bold tabular-nums",children:an(m)}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,t.jsx)(ar.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{children:"Speak into your microphone"})]}),(0,t.jsx)(d.z,{variant:"destructive",size:"lg",className:"rounded-full h-14 w-14 p-0 mt-2",onClick:b,title:"End Call",children:(0,t.jsx)(R.Z,{className:"h-6 w-6 rotate-[135deg]"})})]}),"ended"===c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-gray-100 dark:bg-gray-800 flex items-center justify-center",children:(0,t.jsx)(R.Z,{className:"h-8 w-8 text-gray-500"})}),(0,t.jsx)("span",{className:"text-base font-medium",children:"Call Ended"}),(0,t.jsx)("span",{className:"text-2xl font-mono font-bold",children:an(m)}),(0,t.jsx)(d.z,{variant:"outline",onClick:v,className:"mt-2",children:"Close"})]}),"error"===c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-red-100 dark:bg-red-900 flex items-center justify-center",children:(0,t.jsx)(U.Z,{className:"h-8 w-8 text-red-600"})}),(0,t.jsx)("span",{className:"text-sm text-red-600 font-medium text-center",children:u||"Call failed"}),(0,t.jsxs)("div",{className:"flex gap-2 mt-2",children:[(0,t.jsx)(d.z,{variant:"outline",onClick:v,children:"Close"}),(0,t.jsx)(d.z,{onClick:j,children:"Retry"})]})]}),"idle"===c&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-gray-100 dark:bg-gray-800 flex items-center justify-center",children:(0,t.jsx)(w.Z,{className:"h-8 w-8 text-gray-400 animate-spin"})}),(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"Initializing..."})]})]})]})]})}):null}var ac=s(436),ao=s(93228),am=s(30767);s(12749);var au=s(91032),ax=s(69076),ap=s(41414),ah=s(95805),ag=s(97418),af=s(30401),aj=s(63307),ab=s(6076),av=s(73247),aN=s(43745),aw=s(17684),a_=s(92735),ay=s(62720),ak=s(3085),aC=s(25846),aS=s(49474),aZ=s(29659),aF=s(86595),aA=s(64972),az=s(85639),aI=s(61273),aP=s(73009),aD=s(24746),aE=s(39890),aL=s(9310),aR=s(27049);let aM=[{value:"single_user",label:"Single User",description:"Assign all leads to one selected user",icon:eu.Z,color:"slate"},{value:"round_robin",label:"Round Robin",description:"Distribute leads evenly in sequence",icon:ax.Z,color:"blue"},{value:"least_loaded",label:"Least Loaded",description:"Assign to agent with fewest leads",icon:M.Z,color:"emerald"}];function aO(e){let{open:a,onOpenChange:s,pipelineId:r,pipelineName:n,stages:i,workspaceId:x}=e,[h,g]=(0,l.useState)(1),[f,j]=(0,l.useState)([]),[b,v]=(0,l.useState)([]),[_,k]=(0,l.useState)([]),[S,Z]=(0,l.useState)(!1),[F,A]=(0,l.useState)(!1),[z,I]=(0,l.useState)(""),[P,E]=(0,l.useState)("segment"),[L,R]=(0,l.useState)([]),[O,B]=(0,l.useState)(""),[V,Q]=(0,l.useState)("__default__"),[W,Y]=(0,l.useState)(!1),[$,K]=(0,l.useState)(""),[H,G]=(0,l.useState)([]),[J,X]=(0,l.useState)([]),[ee,ea]=(0,l.useState)(""),[es,et]=(0,l.useState)(""),[el,er]=(0,l.useState)("manual"),[en,ei]=(0,l.useState)([]),[ed,ec]=(0,l.useState)([]),[eo,em]=(0,l.useState)(!1);(0,l.useMemo)(()=>i.filter(e=>e.is_completed_point||e.is_won_point||e.is_dropped_point||e.is_lost_point||e.is_dnd_point),[i]);let eu=(0,l.useMemo)(()=>{let e=[],a=i.filter(e=>e.is_completed_point||e.is_won_point);a.length>0&&e.push({id:"won",label:"Closed Won",color:"#10B981",stageIds:a.map(e=>e.id)});let s=i.filter(e=>e.is_dropped_point||e.is_lost_point);s.length>0&&e.push({id:"lost",label:"Closed Lost",color:"#EF4444",stageIds:s.map(e=>e.id)});let t=i.filter(e=>e.is_dnd_point);return t.length>0&&e.push({id:"dnd",label:"Do Not Disturb",color:"#6B7280",stageIds:t.map(e=>e.id)}),e},[i]),ex=e=>{j(a=>a.includes(e)?a.filter(a=>a!==e):[...a,e])},eh=async()=>
1{if(0!==f.length){Z(!0);try{let e=f.flatMap(e=>{let a=eu.find(a=>a.id===e);return(null==a?void 0:a.stageIds)||[]}),a=await C.api.get("/lead-pipelines/".concat(r,"/board"),{params:{workspace_id:x}});if(a.data.board&&Array.isArray(a.data.board)){let s=[];a.data.board.forEach(a=>{var t;let l=null===(t=a.stage)||void 0===t?void 0:t.id;e.includes(l)&&Array.isArray(a.entries)&&a.entries.forEach(e=>{let a=e.lead||{};s.push({id:e.id,entry_id:e.id,lead_id:e.lead_id,stage_id:e.stage_id,contact_id:e.contact_id,name:a.name||e.lead_id,email:a.email,phone:a.phone,company:a.company,score:a.score})})}),v(s),k(s.map(e=>e.contact_id))}}catch(e){console.error("Failed to fetch leads:",e),y.default.error("Failed to fetch leads")}finally{Z(!1)}}},ef=async()=>{Y(!0);try{let e=((await C.api.get("/lead-pipelines?workspace_id=".concat(x,"&include_stages=true&active_only=true"))).data.pipelines||[]).filter(e=>e.id!==r);R(e);let a=await C.api.get("/branches?workspace_id=".concat(x));G(a.data.branches||[]);let s=await C.api.get("/agent-groups?workspace_id=".concat(x));X(s.data.groups||s.data||[]),await ej()}catch(e){console.error("Failed to fetch pipelines:",e)}finally{Y(!1)}},ej=async()=>{em(!0);try{let e=await C.api.get("/lead-pipelines/".concat(r,"?workspace_id=").concat(x)),a=e.data.pipeline||e.data,s=(null==a?void 0:a.agent_group_ids)||[];if(0===s.length){ei([]);return}let t=[],l=new Set;for(let e of s)try{for(let a of(await C.api.get("/agent-groups/".concat(e,"/members?workspace_id=").concat(x))).data||[])l.has(a.user_id)||(l.add(a.user_id),t.push({id:a.user_id,name:a.user_name||a.name||a.email||"Unknown"}))}catch(a){console.error("Failed to fetch members for group ".concat(e,":"),a)}ei(t)}catch(e){console.error("Failed to fetch pipeline staff:",e),ei([])}finally{em(!1)}},eb=async()=>{1===h?(await eh(),g(2)):2===h&&(await ef(),g(3))},ev=e=>{k(a=>a.includes(e)?a.filter(a=>a!==e):[...a,e])},eN=async()=>{if(0===_.length){y.default.error("Please select at least one lead");return}A(!0);try{if("segment"===P){let e=z.trim()||"Retarget ".concat(n," - ").concat(f.join(", ")," (").concat(new Date().toLocaleDateString(),")"),a=(await C.api.post("/segments",{name:e,description:"Retargeting segment from ".concat(n," pipeline"),segment_type:"static",color:"#3B82F6"},{params:{workspace_id:x}})).data.id;await C.api.post("/segments/".concat(a,"/members"),{contact_ids:_,source:"retarget"},{params:{workspace_id:x}}),y.default.success('Created segment "'.concat(e,'" with ').concat(_.length," contacts"))}else if("lead_pipeline"===P){if(!O){y.default.error("Please select a pipeline");return}let e=(await C.api.post("/contacts/bulk-add-to-leads-pipeline?workspace_id=".concat(x),{contact_ids:_,pipeline_id:O,stage_id:"__default__"!==V?V:void 0,source:"retargets"})).data,a=e.ai_calls_triggered>0?" (".concat(e.ai_calls_triggered," AI calls triggered)"):"",s=L.find(e=>e.id===O);y.default.success("Added ".concat(e.leads_added,' contact(s) to "').concat(null==s?void 0:s.name,'"').concat(a))}else if("create_pipeline"===P){if(!$.trim()){y.default.error("Please enter a pipeline name");return}let e={name:$.trim(),description:"Retargeting pipeline from ".concat(n),color:"#F97316",pipeline_type:"custom"};ee&&"__none__"!==ee&&(e.branch_id=ee),es&&"__none__"!==es&&(e.agent_group_ids=[es],e.assignment_strategy=el);let a=(await C.api.post("/lead-pipelines?workspace_id=".concat(x),e)).data.pipeline,s=(await C.api.post("/contacts/bulk-add-to-leads-pipeline?workspace_id=".concat(x),{contact_ids:_,pipeline_id:a.id,source:"retargets"})).data,t=s.ai_calls_triggered>0?" (".concat(s.ai_calls_triggered," AI calls triggered)"):"";y.default.success('Created pipeline "'.concat($,'" and added ').concat(s.leads_added," contact(s)").concat(t))}else if("retarget_same_pipeline"===P){let e=i.find(e=>e.is_retarget||"retarget"===e.name.toLowerCase());e||(e=(await C.api.post("/lead-pipelines/".concat(r,"/stages?workspace_id=").concat(x),{name:"Retarget",color:"#F97316",is_retarget:!0})).data.stage);let a={entry_ids:b.filter(e=>_.includes(e.contact_id)).map(e=>e.entry_id),stage_id:e.id,update_source:"retargets"};ed.length>0&&(a.assigned_to_list=ed);let s=(await C.api.post("/lead-pipelines/".concat(r,"/entries/bulk-move?workspace_id=").concat(x),a)).data,t="";if(1===ed.length){let e=en.find(e=>e.id===ed[0]);t=e?" and assigned to ".concat(e.name):""}else ed.length>1&&(t=" and distributed via round robin to ".concat(ed.length," staff"));y.default.success("Moved ".concat(s.moved," lead(s) to Retarget stage").concat(t).concat(s.skipped>0?" (".concat(s.skipped," already there)"):""))}s(!1),e_()}catch(s){var e,a;console.error("Failed to execute action:",s),y.default.error((null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to complete action")}finally{A(!1)}},e_=()=>{g(1),j([]),v([]),k([]),I(""),E("segment"),B(""),Q("__default__"),K(""),ea(""),et(""),er("single_user"),ec([]),ei([])};(0,l.useEffect)(()=>{a||e_()},[a]);let ey=L.find(e=>e.id===O);return(0,t.jsx)(D.Vq,{open:a,onOpenChange:s,children:(0,t.jsxs)(D.cZ,{className:"max-w-xl max-h-[85vh] overflow-hidden flex flex-col",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(ap.Z,{className:"h-5 w-5 text-blue-500"}),"Retarget Leads"]}),(0,t.jsxs)(D.Be,{children:[1===h&&"Select the lead categories you want to retarget",2===h&&"Select leads to retarget (".concat(_.length,"/").concat(b.length," selected)"),3===h&&"Choose what to do with selected leads"]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 px-1",children:[(0,t.jsx)("div",{className:"flex-1 h-1 rounded-full ".concat(h>=1?"bg-blue-500":"bg-muted")}),(0,t.jsx)("div",{className:"flex-1 h-1 rounded-full ".concat(h>=2?"bg-blue-500":"bg-muted")}),(0,t.jsx)("div",{className:"flex-1 h-1 rounded-full ".concat(h>=3?"bg-blue-500":"bg-muted")})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto py-4",children:[1===h&&(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:"Select the stage types to include in your retargeting:"}),0===eu.length?(0,t.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,t.jsx)(ew.Z,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,t.jsx)("p",{children:"No flagged stages found in this pipeline"}),(0,t.jsx)("p",{className:"text-xs mt-1",children:"Add Won, Lost, or DND stages to enable retargeting"})]}):eu.map(e=>(0,t.jsxs)("div",{onClick:()=>ex(e.id),className:"flex items-center gap-3 p-4 rounded-lg border cursor-pointer transition-all ".concat(f.includes(e.id)?"border-blue-500 bg-blue-50 dark:bg-blue-950/30":"border-border hover:border-blue-300"),children:[(0,t.jsx)(eY.X,{checked:f.includes(e.id),onCheckedChange:()=>ex(e.id)}),(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.color}}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("span",{className:"font-medium",children:e.label}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[e.stageIds.length," stage",1!==e.stageIds.length?"s":""]})]}),"won"===e.id&&(0,t.jsx)(T.Z,{className:"h-4 w-4 text-emerald-500"}),"lost"===e.id&&(0,t.jsx)(U.Z,{className:"h-4 w-4 text-red-500"}),"dnd"===e.id&&(0,t.jsx)(q.Z,{className:"h-4 w-4 text-gray-500"})]},e.id))]}),2===h&&(0,t.jsx)("div",{className:"space-y-3",children:S?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsx)(w.Z,{className:"h-8 w-8 animate-spin text-blue-500"})}):0===b.length?(0,t.jsxs)("div",{className:"text-center py-8 text-muted-foreground",children:[(0,t.jsx)(ah.Z,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,t.jsx)("p",{children:"No leads found in selected stages"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 mb-3",children:[(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>{k(b.map(e=>e.contact_id))},children:[(0,t.jsx)(ag.Z,{className:"h-3.5 w-3.5 mr-1"}),"Select All"]}),(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>{k([])},children:[(0,t.jsx)(U.Z,{className:"h-3.5 w-3.5 mr-1"}),"Deselect All"]}),(0,t.jsxs)("span",{className:"text-sm text-muted-foreground ml-auto",children:[_.length," of ",b.length," selected"]})]}),(0,t.jsx)("div",{className:"space-y-2 max-h-[300px] overflow-y-auto border rounded-lg p-2",children:b.map(e=>(0,t.jsxs)("div",{onClick:()=>ev(e.contact_id),className:"flex items-center gap-3 p-3 rounded-md cursor-pointer transition-all ".concat(_.includes(e.contact_id)?"bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800":"hover:bg-muted/50 border border-transparent"),children:[(0,t.jsx)(eY.X,{checked:_.includes(e.contact_id),onCheckedChange:()=>ev(e.contact_id)}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"font-medium truncate",children:e.name||"Unknown"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:e.email||e.phone||"No contact info"})]}),e.company&&(0,t.jsx)(c.C,{variant:"outline",className:"text-[10px]",children:e.company})]},e.id))})]})}
1),3===h&&(0,t.jsx)("div",{className:"space-y-4",children:W?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsx)(w.Z,{className:"h-8 w-8 animate-spin text-blue-500"})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Choose Action"}),(0,t.jsxs)("div",{className:"grid grid-cols-1 gap-2",children:[(0,t.jsxs)("div",{onClick:()=>{E("segment"),B(""),Q("__default__")},className:"flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-all ".concat("segment"===P?"border-blue-500 bg-blue-50 dark:bg-blue-950/30":"border-border hover:border-blue-300"),children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-blue-100 dark:bg-blue-900/50 flex items-center justify-center",children:(0,t.jsx)(M.Z,{className:"h-4 w-4 text-blue-600"})}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:"Create Segment"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Create a retargeting segment for campaigns"})]}),"segment"===P&&(0,t.jsx)(af.Z,{className:"h-4 w-4 text-blue-600"})]}),(0,t.jsxs)("div",{onClick:()=>{E("lead_pipeline"),B(""),Q("__default__")},className:"flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-all ".concat("lead_pipeline"===P?"border-orange-500 bg-orange-50 dark:bg-orange-950/30":"border-border hover:border-orange-300"),children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-orange-100 dark:bg-orange-900/50 flex items-center justify-center",children:(0,t.jsx)(aj.Z,{className:"h-4 w-4 text-orange-600"})}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:"Add to Lead Pipeline"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Re-engage with AI calls & assignment rules"})]}),"lead_pipeline"===P&&(0,t.jsx)(af.Z,{className:"h-4 w-4 text-orange-600"})]}),(0,t.jsxs)("div",{onClick:()=>{E("create_pipeline"),B(""),Q("__default__")},className:"flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-all ".concat("create_pipeline"===P?"border-purple-500 bg-purple-50 dark:bg-purple-950/30":"border-border hover:border-purple-300"),children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-purple-100 dark:bg-purple-900/50 flex items-center justify-center",children:(0,t.jsx)(N.Z,{className:"h-4 w-4 text-purple-600"})}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:"Create Lead Pipeline"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Create new pipeline for retargeting"})]}),"create_pipeline"===P&&(0,t.jsx)(af.Z,{className:"h-4 w-4 text-purple-600"})]}),(0,t.jsxs)("div",{onClick:()=>{E("retarget_same_pipeline"),B(""),Q("__default__")},className:"flex items-center gap-3 p-3 rounded-lg border cursor-pointer transition-all ".concat("retarget_same_pipeline"===P?"border-amber-500 bg-amber-50 dark:bg-amber-950/30":"border-border hover:border-amber-300"),children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-amber-100 dark:bg-amber-900/50 flex items-center justify-center",children:(0,t.jsx)(ax.Z,{className:"h-4 w-4 text-amber-600"})}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:"Retarget on This Pipeline"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Move to Retarget stage in current pipeline"})]}),"retarget_same_pipeline"===P&&(0,t.jsx)(af.Z,{className:"h-4 w-4 text-amber-600"})]})]})]}),"segment"===P&&(0,t.jsxs)("div",{className:"space-y-2 pt-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Segment Name (optional)"}),(0,t.jsx)(u.I,{placeholder:"Retarget ".concat(n," - ").concat(f.join(", ")),value:z,onChange:e=>I(e.target.value)})]}),"retarget_same_pipeline"===P&&(0,t.jsxs)("div",{className:"space-y-2 pt-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Assign to Staff (optional - select multiple for round robin)"}),eo?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground py-2",children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}),"Loading staff..."]}):en.length>0?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"max-h-36 overflow-y-auto rounded-lg border p-1 [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",children:(0,t.jsx)("div",{className:"space-y-1",children:en.map(e=>{let a=ed.includes(e.id);return(0,t.jsxs)("div",{onClick:()=>{ec(s=>a?s.filter(a=>
1a!==e.id):[...s,e.id])},className:"flex items-center gap-3 px-3 py-2 rounded-md cursor-pointer transition-all ".concat(a?"bg-amber-50 dark:bg-amber-950/30 border border-amber-300":"hover:bg-muted border border-transparent"),children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-full flex items-center justify-center ".concat(a?"bg-amber-500 text-white":"bg-amber-100 dark:bg-amber-900/50"),children:a?(0,t.jsx)(af.Z,{className:"h-4 w-4"}):(0,t.jsx)("span",{className:"text-sm font-medium text-amber-700 dark:text-amber-300",children:e.name.charAt(0).toUpperCase()})}),(0,t.jsx)("span",{className:"text-sm font-medium",children:e.name})]},e.id)})})}),ed.length>1&&(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-blue-50 dark:bg-blue-950/30 border border-blue-200 dark:border-blue-800",children:[(0,t.jsx)(ap.Z,{className:"h-4 w-4 text-blue-600"}),(0,t.jsx)("span",{className:"text-sm font-medium text-blue-700 dark:text-blue-300",children:"Round Robin enabled - leads will be distributed evenly"})]})]}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-2",children:"No agent groups assigned to this pipeline"})]}),"lead_pipeline"===P&&(0,t.jsxs)("div",{className:"space-y-3 pt-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Select Lead Pipeline"}),(0,t.jsx)(m.x,{className:"h-40 rounded border p-2",children:(0,t.jsxs)("div",{className:"space-y-2",children:[L.map(e=>(0,t.jsxs)("div",{onClick:()=>{B(e.id),Q("__default__")},className:"flex items-center gap-3 p-3 rounded-md cursor-pointer transition-all ".concat(O===e.id?"bg-orange-50 dark:bg-orange-950/30 border border-orange-300":"hover:bg-muted border border-transparent"),children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.color}}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsx)("p",{className:"font-medium text-sm truncate",children:e.name})}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[e.is_default&&(0,t.jsx)(c.C,{variant:"secondary",className:"text-[10px]",children:"Default"}),e.ai_calls_enabled&&(0,t.jsx)(c.C,{className:"text-[10px] bg-blue-100 text-blue-700",children:"AI"})]})]},e.id)),0===L.length&&(0,t.jsx)("div",{className:"text-center py-4 text-sm text-muted-foreground",children:"No lead pipelines available"})]})}),O&&(null==ey?void 0:ey.stages)&&ey.stages.length>0&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Starting Stage"}),(0,t.jsxs)(o.Ph,{value:V,onValueChange:Q,children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:"Entry point (default)"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"__default__",children:"Entry point (default)"}),ey.stages.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name,e.is_entry_point&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:"(Entry)"})]})},e.id))]})]})]}),O&&ey&&(0,t.jsx)("div",{className:"rounded-lg border bg-muted/30 p-3 text-sm",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-muted-foreground",children:[(0,t.jsx)(ew.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{children:"AI calling rules and assignment strategy will be applied"})]})})]}),"create_pipeline"===P&&(0,t.jsxs)("div",{className:"space-y-4 pt-2",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)(p._,{className:"text-sm",children:["Pipeline Name ",(0,t.jsx)("span",{className:"text-red-500",children:"*"})]}),(0,t.jsx)(u.I,{placeholder:"Retarget ".concat(n),value:$,onChange:e=>K(e.target.value)})]}),H.length>0&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Branch (optional)"}),(0,t.jsxs)(o.Ph,{value:ee,onValueChange:ea,children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:"No branch selected"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"__none__",children:"No branch"}),H.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ep.Z,{className:"h-3 w-3 text-muted-foreground"}),e.name]})},e.id))]})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Agent Group (optional)"}),(0,t.jsxs)(o.Ph,{value:es,onValueChange:et,children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:"No group selected"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"__none__",children:"No group (Manual assignment)"}),J.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ah.Z,{className:"h-3 w-3 text-muted-foreground"}),e.name,void 0!==e.member_count&&(0,t.jsxs)("span",{className:"text-xs text-muted-foreground",children:["(",e.member_count," members)"]})]})},e.id))]})]})]}),es&&"__none__"!==es&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Assignment Strategy"}),(0,t.jsxs)(o.Ph,{value:el,onValueChange:er,children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:"Select strategy"})}),(0,t.jsx)(o.Bw,{children:aM.map(e=>(0,t.jsx)(o.Ql,{value:e.value,children:(0,t.jsxs)("div",{className:"flex flex-col",children:[(0,t.jsx)("span",{children:e.label}),(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:e.description})]})},e.value))})]})]}),(0,t.jsx)("div",{className:"rounded-lg border bg-purple-50 dark:bg-purple-950/30 p-3 text-sm",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 text-purple-700 dark:text-purple-300",children:[(0,t.jsx)(eg.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{children:"Pipeline will be created with default stages. You can customize it later."})]})})]})]})})]}),(0,t.jsxs)(D.cN,{className:"gap-2",children:[h>1&&(0,t.jsxs)(d.z,{variant:"outline",onClick:()=>{2===h?(g(1),v([]),k([])):3===h&&(g(2),E("segment"),B(""),Q("__default__"))},children:[(0,t.jsx)(eH.Z,{className:"h-4 w-4 mr-1"}),"Back"]}),(0,t.jsx)(d.z,{variant:"outline",onClick:()=>s(!1),children:"Cancel"}),h<3?(0,t.jsxs)(d.z,{onClick:eb,disabled:1===h?0===f.length:0===_.length,children:["Next",(0,t.jsx)(eS.Z,{className:"h-4 w-4 ml-1"})]}):(0,t.jsx)(d.z,{onClick:eN,disabled:F||"lead_pipeline"===P&&!O||"create_pipeline"===P&&!$.trim(),className:"segment"===P?"bg-gradient-to-r from-blue-500 to-indigo-600 hover:from-blue-600 hover:to-indigo-700":"create_pipeline"===P?"bg-gradient-to-r from-purple-500 to-violet-600 hover:from-purple-600 hover:to-violet-700":"retarget_same_pipeline"===P?"bg-gradient-to-r from-amber-500 to-orange-600 hover:from-amber-600 hover:to-orange-700":"bg-gradient-to-r from-orange-500 to-amber-600 hover:from-orange-600 hover:to-amber-700",children:F?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-1 animate-spin"}),"Processing..."]}):(0,t.jsxs)(t.Fragment,{children:["segment"===P&&(0,t.jsx)(M.Z,{className:"h-4 w-4 mr-1"}),"lead_pipeline"===P&&(0,t.jsx)(aj.Z,{className:"h-4 w-4 mr-1"}),"create_pipeline"===P&&(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-1"}),"retarget_same_pipeline"===P&&(0,t.jsx)(ax.Z,{className:"h-4 w-4 mr-1"}),"segment"===P&&"Create Segment (".concat(_.length,")"),"lead_pipeline"===P&&"Add to Lead Pipeline (".concat(_.length,")"),"create_pipeline"===P&&"Create Pipeline & Add (".concat(_.length,")"),"retarget_same_pipeline"===P&&"Move to Retarget (".concat(_.length,")")]})})]})]})})}function aB(e){var a,s;let{user:r,rolePermissions:n,pipelines:i,pipelineStages:c,callStatuses:m,agentGroups:x,workspaceUsers:h=[],usersLoading:j=!1,updateWorksp
1aceUser:b,refreshUsers:k,setShowPipelineManager:S,setShowStageEditor:Z,setShowCallStatusEditor:F,setShowAICallSettings:A,setShowAdSourcesDialog:z,selectedPipelineId:I,onPipelineChange:P,isDemoUser:E=!1,setDemoOpen:L,setDemoResult:O,refreshPipelines:B}=e,[U,q]=(0,l.useState)("manual"),[W,Y]=(0,l.useState)(!1),[$,K]=(0,l.useState)(null),[H,G]=(0,l.useState)(!1),[J,X]=(0,l.useState)(!1),[ee,ea]=(0,l.useState)(null),[et,el]=(0,l.useState)([]),[er,en]=(0,l.useState)(!1),[ei,ed]=(0,l.useState)(!1),[ec,eo]=(0,l.useState)(!1),[em,eu]=(0,l.useState)("add"),[ex,ep]=(0,l.useState)(""),[eb,ev]=(0,l.useState)([]),[eN,ew]=(0,l.useState)(!1),[e_,ey]=(0,l.useState)(null),[ek,eC]=(0,l.useState)([]),[eF,eA]=(0,l.useState)(!1),[ez,eI]=(0,l.useState)(new Set),[eP,eD]=(0,l.useState)(new Set),[eE,eL]=(0,l.useState)(!1),[eR,eM]=(0,l.useState)({}),[eT,eU]=(0,l.useState)(!1);(0,l.useEffect)(()=>{let e=i.find(e=>e.id===I);if(null==e?void 0:e.excluded_agent_ids){let a=new Set(e.excluded_agent_ids);eI(a),eD(a)}else eI(new Set),eD(new Set)},[I,i]);let[eq,eV]=(0,l.useState)(!1),[eQ,eW]=(0,l.useState)(!1),[eY,e$]=(0,l.useState)([]),[eK,eH]=(0,l.useState)(null),[eG,eJ]=(0,l.useState)(!1),[eX,e0]=(0,l.useState)(!1),[e1,e5]=(0,l.useState)(null),[e2,e4]=(0,l.useState)(null),[e3,e6]=(0,l.useState)(!1),[e8,e9]=(0,l.useState)(null),[e7,ae]=(0,l.useState)([]),[aa,as]=(0,l.useState)(!1),[at,al]=(0,l.useState)(!1),[ar,an]=(0,l.useState)([]),[ai,ad]=(0,l.useState)(!1),[ac,ao]=(0,l.useState)(new Set);(0,l.useEffect)(()=>{if(I){let e=i.find(e=>e.id===I);(null==e?void 0:e.assignment_strategy)?q(e.assignment_strategy):q("single_user"),(async()=>{X(!0);try{let e=(await C.api.get("/lead-pipelines/".concat(I,"/ai-calling-settings?workspace_id=").concat(null==r?void 0:r.workspace_id))).data,a=null==e?void 0:e.settings,s=a&&a.is_enabled&&a.trigger_on_new_lead;G(s)}catch(e){G(!1)}finally{X(!1)}})(),(async()=>{eJ(!0);try{var e;let a=await C.api.get("/crm/pipelines?workspace_id=".concat(null==r?void 0:r.workspace_id)),s=(null===(e=a.data)||void 0===e?void 0:e.pipelines)||[];e$(s);let t=s.find(e=>e.linked_lead_pipeline_id===I);eH(t||null)}catch(e){console.error("Failed to fetch CRM pipelines:",e),e$([]),eH(null)}finally{eJ(!1)}})(),(async()=>{try{var e;let a=await C.api.get("/workspace-razorpay/status?workspace_id=".concat(null==r?void 0:r.workspace_id));e4((null===(e=a.data)||void 0===e?void 0:e.configured)||!1)}catch(e){console.error("Failed to fetch Razorpay status:",e),e4(!1)}})()}},[I,i,null==r?void 0:r.workspace_id]);let am=async e=>{e0(!0);try{eK&&eK.id!==e&&await C.api.put("/crm/pipelines/".concat(eK.id,"?workspace_id=").concat(null==r?void 0:r.workspace_id),{complementary_pipeline_enabled:!1,linked_lead_pipeline_id:null}),await C.api.put("/crm/pipelines/".concat(e,"?workspace_id=").concat(null==r?void 0:r.workspace_id),{complementary_pipeline_enabled:!0,linked_lead_pipeline_id:I});let a=eY.find(a=>a.id===e);a&&eH({...a,complementary_pipeline_enabled:!0,linked_lead_pipeline_id:I}),y.default.success("CRM pipeline linked")}catch(e){var a,s;console.error("Failed to link CRM pipeline:",e),y.default.error((null===(s=e.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed to link CRM pipeline")}finally{e0(!1)}},au=async()=>{if(eK){e0(!0);try{await C.api.put("/crm/pipelines/".concat(eK.id,"?workspace_id=").concat(null==r?void 0:r.workspace_id),{complementary_pipeline_enabled:!1,linked_lead_pipeline_id:null}),eH(null),y.default.success("CRM pipeline unlinked")}catch(e){console.error("Failed to unlink CRM pipeline:",e),y.default.error("Failed to unlink CRM pipeline")}finally{e0(!1)}}},ax=e1?{...eK,...e1}:eK,ap=e=>{e5(a=>({...a||{},...e}))},ag=null!==e1,aj=async()=>{if(eK&&e1){e0(!0);try{await C.api.put("/crm/pipelines/".concat(eK.id,"?workspace_id=").concat(null==r?void 0:r.workspace_id),e1),eH(e=>e?{...e,...e1}:null),e5(null),y.default.success("Settings saved"),eW(!1)}catch(e){console.error("Failed to save CRM qualification settings:",e),y.default.error("Failed to save settings")}finally{e0(!1)}}},aw=async e=>{if(!I){y.default.error("Please select a pipeline first");return}q(e),Y(!0);try{await C.api.put("/lead-pipelines/".concat(I,"?workspace_id=").concat(null==r?void 0:r.workspace_id),{assignment_strategy:e}),y.default.success("Assignment strategy updated for pipeline")}catch(e){console.error("Failed to save strategy:",e),y.default.error("Failed to update strategy")}finally{Y(!1)}};h.filter(e=>"sales_agent"===e.dashboard_role||"sales_manager"===e.dashboard_role||"staff"===e.enterprise_role);let a_=i.find(e=>e.id===I),ay=(0,l.useMemo)(()=>{var e;return(null==a_?void 0:null===(e=a_.agent_group_ids)||void 0===e?void 0:e.length)?x.filter(e=>{var a;return null===(a=a_.agent_group_ids)||void 0===a?void 0:a.includes(e.id)}):[]},[a_,x]),ak=(0,l.useMemo)(()=>{var e;return(null==a_?void 0:null===(e=a_.agent_group_ids)||void 0===e?void 0:e.length)?x.filter(e=>{var a;return!(null===(a=a_.agent_group_ids)||void 0===a?void 0:a.includes(e.id))}):x},[a_,x]),aC=(0,l.useRef)(null),aS=e=>{if(ep(e),aC.current&&clearTimeout(aC.current),!e.trim()){ev([]);return}aC.current=setTimeout(async()=>{ew(!0);try{let a=await C.api.get("/agent-groups?workspace_id=".concat(null==r?void 0:r.workspace_id,"&search=").concat(encodeURIComponent(e))),s=a.data.groups||a.data||[];ev(s)}catch(e){console.error("Failed to search groups:",e),ev([])}finally{ew(!1)}},300)},aZ=ex.trim()?eb:ak,aF=async()=>
1{if(0!==ay.length){eU(!0);try{let e={};await Promise.all(ay.map(async a=>{let s=await C.api.get("/agent-groups/".concat(a.id,"/members"));e[a.id]=s.data||[]})),eM(e)}catch(e){console.error("Failed to fetch all group members:",e)}finally{eU(!1)}}},aA=(0,l.useMemo)(()=>{let e=new Map;for(let a of ay)for(let s of eR[a.id]||[]){let t=s.user_id||s.id;e.has(t)||e.set(t,{user:s,groups:[],isExcluded:ez.has(t)}),e.get(t).groups.push(a)}return Array.from(e.values())},[ay,eR,ez]);(0,l.useEffect)(()=>{"users"===em&&ec&&ay.length>0&&aF()},[em,ec,ay.length]);let az=async e=>{if(e_===e){ey(null),eC([]);return}ey(e),eA(!0),eC([]);try{let a=await C.api.get("/agent-groups/".concat(e,"/members"));eC(a.data||[])}catch(e){console.error("Failed to load group members:",e),eC([])}finally{eA(!1)}},aI=async e=>{if(a_&&(null==r?void 0:r.workspace_id))try{let a=[...a_.agent_group_ids||[],e];await C.api.put("/lead-pipelines/".concat(a_.id,"?workspace_id=").concat(r.workspace_id),{agent_group_ids:a}),y.default.success("Group added to pipeline"),await (null==B?void 0:B())}catch(e){console.error("Failed to add group:",e),y.default.error("Failed to add group to pipeline")}},aP=async e=>{if(a_&&(null==r?void 0:r.workspace_id))try{let a=(a_.agent_group_ids||[]).filter(a=>a!==e);await C.api.put("/lead-pipelines/".concat(a_.id,"?workspace_id=").concat(r.workspace_id),{agent_group_ids:a}),y.default.success("Group removed from pipeline"),await (null==B?void 0:B())}catch(e){console.error("Failed to remove group:",e),y.default.error("Failed to remove group from pipeline")}},aD=e=>{eI(a=>{let s=new Set(a);return s.has(e)?s.delete(e):s.add(e),s})},aE=(()=>{if(ez.size!==eP.size)return!0;for(let e of ez)if(!eP.has(e))return!0;return!1})(),aL=async()=>{if(!aE||!I||!(null==r?void 0:r.workspace_id)){eo(!1);return}eL(!0);try{await C.api.put("/lead-pipelines/".concat(I,"?workspace_id=").concat(null==r?void 0:r.workspace_id),{excluded_agent_ids:Array.from(ez)}),y.default.success("User exclusions saved"),eD(new Set(ez)),await (null==B?void 0:B())}catch(e){console.error("Failed to save user exclusions:",e),y.default.error("Failed to save changes")}finally{eL(!1)}},aR=async()=>{if(I&&(null==r?void 0:r.workspace_id)){as(!0);try{var e;let a=await C.api.get("/lead-pipelines/".concat(I,"/unassigned-count"),{params:{workspace_id:r.workspace_id}}),s=(null===(e=a.data)||void 0===e?void 0:e.unassigned_count)||0;ae(Array(s).fill({id:"",name:"Lead"}))}catch(e){console.error("Failed to fetch unassigned lead count:",e),ae([])}finally{as(!1)}}},aB=async()=>{if(I&&(null==r?void 0:r.workspace_id)){ad(!0);try{var e;let a=await C.api.get("/lead-pipelines/".concat(I,"/agent-loads"),{params:{workspace_id:r.workspace_id}}),s=(null===(e=a.data)||void 0===e?void 0:e.agents)||[];s.sort((e,a)=>(e.lead_count||0)-(a.lead_count||0)),an(s);let t=i.find(e=>e.id===I);(null==t?void 0:t.assignment_strategy)==="single_user"&&(null==t?void 0:t.single_user_agent_id)?ao(new Set([t.single_user_agent_id])):s.length>0&&ao(new Set([s[0].id]))}catch(e){console.error("Failed to fetch agent loads:",e),an([])}finally{ad(!1)}}},aT=async()=>{if(I&&(null==r?void 0:r.workspace_id)&&0!==ac.size){Y(!0);try{let e=Array.from(ac)[0];await C.api.put("/lead-pipelines/".concat(I,"?workspace_id=").concat(null==r?void 0:r.workspace_id),{single_user_agent_id:e}),y.default.success("Single user assignment saved"),await (null==B?void 0:B())}catch(e){console.error("Failed to save single user:",e),y.default.error("Failed to save")}finally{Y(!1)}}},aU=async()=>{if(I&&(null==r?void 0:r.workspace_id)&&0!==ac.size){al(!0);try{let e=(await C.api.post("/lead-pipelines/".concat(I,"/trigger-assignment"),{workspace_id:r.workspace_id,strategy:"single_user",agent_ids:Array.from(ac)})).data;e.assigned_count>0?y.default.success("Assigned ".concat(e.assigned_count," leads")):(0,y.default)("No leads were assigned"),await Promise.all([aR(),aB()])}catch(s){var e,a;console.error("Failed to trigger assignment:",s),y.default.error((null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to trigger assignment")}finally{al(!1)}}},aq=async()=>
1{if(I&&(null==r?void 0:r.workspace_id)&&0!==e7.length){al(!0);try{let e=(await C.api.post("/lead-pipelines/".concat(I,"/trigger-assignment"),{workspace_id:r.workspace_id,strategy:"round_robin"})).data;e.assigned_count>0?y.default.success("Assigned ".concat(e.assigned_count," leads to agents")):(0,y.default)("No leads were assigned"),await aR()}catch(s){var e,a;console.error("Failed to trigger assignment:",s),y.default.error((null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to trigger assignment")}finally{al(!1)}}},aV=async()=>{if(I&&(null==r?void 0:r.workspace_id)&&0!==e7.length&&0!==ac.size){al(!0);try{let e=(await C.api.post("/lead-pipelines/".concat(I,"/trigger-assignment"),{workspace_id:r.workspace_id,strategy:"least_loaded",agent_ids:Array.from(ac)})).data;e.assigned_count>0?y.default.success("Assigned ".concat(e.assigned_count," leads to agents")):(0,y.default)("No leads were assigned"),await Promise.all([aR(),aB()])}catch(s){var e,a;console.error("Failed to trigger assignment:",s),y.default.error((null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to trigger assignment")}finally{al(!1)}}},aQ=e=>e.split(" ").map(e=>e[0]).join("").toUpperCase().slice(0,2),aW=e=>({blue:"bg-blue-500",green:"bg-green-500",orange:"bg-orange-500",purple:"bg-purple-500",teal:"bg-teal-500",red:"bg-red-500"})[e||""]||"bg-emerald-500";return(0,t.jsxs)("div",{className:"space-y-6",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between p-4 rounded-lg bg-gradient-to-r from-slate-50 via-white to-slate-50 dark:from-slate-900/50 dark:via-slate-800/30 dark:to-slate-900/50 border border-slate-200/60 dark:border-slate-700/40",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-md bg-gradient-to-br from-slate-600 to-slate-700 flex items-center justify-center shadow-sm",children:(0,t.jsx)(V.Z,{className:"h-5 w-5 text-white"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"text-base font-semibold text-gray-900 dark:text-white",children:"Pipeline Settings"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Configure settings for the selected pipeline"})]})]}),(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)("div",{children:(0,t.jsxs)(o.Ph,{value:I||"",onValueChange:P,children:[(0,t.jsxs)(o.i4,{className:"w-[180px] h-9 bg-white dark:bg-slate-800 border-slate-300 dark:border-slate-600 rounded-sm text-sm",children:[a_&&(0,t.jsx)("div",{className:"w-2.5 h-2.5 rounded-full mr-2 shrink-0",style:{backgroundColor:a_.color}}),(0,t.jsx)("span",{className:"truncate",children:(0,t.jsx)(o.ki,{placeholder:"Select Pipeline"})})]}),(0,t.jsx)(o.Bw,{children:i.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2 max-w-[150px]",children:[(0,t.jsx)("div",{className:"w-2.5 h-2.5 rounded-full shrink-0",style:{backgroundColor:e.color}}),(0,t.jsx)("span",{className:"truncate",children:e.name}),e.is_default&&(0,t.jsx)("span",{className:"text-[9px] text-muted-foreground bg-muted px-1 py-0.5 rounded shrink-0",children:"Default"})]})},e.id))})]})})}),(0,t.jsx)(f._v,{side:"bottom",className:"max-w-[300px]",children:(0,t.jsx)("p",{className:"font-medium",children:(null==a_?void 0:a_.name)||"Select pipeline"})})]})})})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4",children:[n.isSuperAdmin&&(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-purple-300 dark:hover:border-purple-800 hover:shadow-lg hover:shadow-purple-500/5 transition-all duration-200 cursor-pointer",onClick:()=>S(!0),children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-purple-500 to-violet-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(ej.Z,{className:"h-5 w-5 text-white"})}),(0,t.jsx)(eS.Z,{className:"h-4 w-4 text-slate-400 group-hover:text-purple-500 group-hover:translate-x-0.5 transition-all"})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Manage Pipelines"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"Create & edit pipelines"}
1),(0,t.jsxs)("div",{className:"flex -space-x-1.5",children:[i.slice(0,4).map(e=>(0,t.jsx)("div",{className:"w-5 h-5 rounded-full border-2 border-white dark:border-slate-900",style:{backgroundColor:e.color},title:e.name},e.id)),i.length>4&&(0,t.jsxs)("div",{className:"w-5 h-5 rounded-full border-2 border-white dark:border-slate-900 bg-slate-200 dark:bg-slate-700 flex items-center justify-center text-[9px] font-medium",children:["+",i.length-4]})]})]}),(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-blue-300 dark:hover:border-blue-800 hover:shadow-lg hover:shadow-blue-500/5 transition-all duration-200 cursor-pointer",onClick:()=>n.isSuperAdmin&&Z(!0),children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-blue-500 to-indigo-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(eZ.Z,{className:"h-5 w-5 text-white"})}),a_&&(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-blue-50 dark:bg-blue-950/50 text-blue-600 dark:text-blue-400 max-w-[250px] truncate",title:a_.name,children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:a_.color}}),a_.name]})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Stage Settings"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"Configure pipeline stages"}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-1",children:[c.slice(0,3).map((e,a)=>(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded text-[10px] font-medium bg-slate-100 dark:bg-slate-800",children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:e.color}}),e.name]},e.id||a)),c.length>3&&(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground",children:["+",c.length-3]})]})]}),(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-emerald-300 dark:hover:border-emerald-800 hover:shadow-lg hover:shadow-emerald-500/5 transition-all duration-200 cursor-pointer",onClick:()=>n.isSuperAdmin&&F(!0),children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-emerald-500 to-teal-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(R.Z,{className:"h-5 w-5 text-white"})}),a_&&(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-emerald-50 dark:bg-emerald-950/50 text-emerald-600 dark:text-emerald-400 max-w-[250px] truncate",title:a_.name,children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:a_.color}}),a_.name]})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Call Statuses"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"Track call outcomes"}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-[10px]",children:[(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full bg-emerald-500"}),m.positive.length]}),(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full bg-amber-500"}),m.neutral.length]}),(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full bg-red-500"}),m.negative.length]})]})]}),(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-amber-300 dark:hover:border-amber-800 hover:shadow-lg hover:shadow-amber-500/5 transition-all duration-200 cursor-pointer",onClick:()=>{if(!I){y.default.error("Please select a pipeline first");return}eo(!0)},children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-amber-500 to-orange-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(_.Z,{className:"h-5 w-5 text-white"})}),a_&&(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-amber-50 dark:bg-amber-950/50 text-amber-600 dar
1k:text-amber-400 max-w-[250px] truncate",title:a_.name,children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:a_.color}}),a_.name]})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Manage Users"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"Assign users to pipeline"}),(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsxs)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300",children:[(0,t.jsx)(ah.Z,{className:"h-3 w-3 mr-1"}),ay.length," ",1===ay.length?"group":"groups"]})})]}),(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-indigo-300 dark:hover:border-indigo-800 hover:shadow-lg hover:shadow-indigo-500/5 transition-all duration-200 cursor-pointer",onClick:()=>{if(!I){y.default.error("Please select a pipeline first");return}e6(!0)},children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-indigo-500 to-blue-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(Q.Z,{className:"h-5 w-5 text-white"})}),a_&&(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-indigo-50 dark:bg-indigo-950/50 text-indigo-600 dark:text-indigo-400 max-w-[250px] truncate",title:a_.name,children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:a_.color}}),a_.name]})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Lead Assignment"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"Assign reps — runs alongside AI"}),(0,t.jsxs)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-indigo-100 dark:bg-indigo-900/30 text-indigo-700 dark:text-indigo-300",children:[(null===(a=aM.find(e=>e.value===U))||void 0===a?void 0:a.icon)&&(0,t.jsx)("span",{className:"mr-1",children:(()=>{var e;let a=(null===(e=aM.find(e=>e.value===U))||void 0===e?void 0:e.icon)||ah.Z;return(0,t.jsx)(a,{className:"h-3 w-3"})})()}),(null===(s=aM.find(e=>e.value===U))||void 0===s?void 0:s.label)||"Manual"]})]}),(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-violet-300 dark:hover:border-violet-800 hover:shadow-lg hover:shadow-violet-500/5 transition-all duration-200 cursor-pointer",onClick:()=>(n.isAdmin||n.isSuperAdmin)&&A(!0),children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-violet-500 to-purple-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(eh.Z,{className:"h-5 w-5 text-white"})}),a_&&(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-violet-50 dark:bg-violet-950/50 text-violet-600 dark:text-violet-400 max-w-[250px] truncate",title:a_.name,children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:a_.color}}),a_.name]})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Sales Agent (AI)"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"RAG text + voice replies"}),(0,t.jsxs)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-violet-100 dark:bg-violet-900/30 text-violet-700 dark:text-violet-300",children:[(0,t.jsx)(eg.Z,{className:"h-3 w-3 mr-1"}),"AI Powered"]})]}),(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-pink-300 dark:hover:border-pink-800 hover:shadow-lg hover:shadow-pink-500/5 transition-all duration-200 cursor-pointer",onClick:()=>{if(!I){y.default.error("Please select a pipeline first");return}z(!0)},children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-pink-500 to-rose-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(eO.Z,{className:"h-5 w-5 text-white"})}),a_&&(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-pink-50 dark:bg-pink-950/50 text-pink-600 dark:text-pink-400 max-w-[250px] truncate",title:a_.name,children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:a_.color}}),a_.name]})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Ad Sources"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"Connect campaigns → this pipeline"}),(0,t.jsxs)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-pink-100 dark:bg-pink-900/30 text-pink-700 dark:text-pink-300",children:[(0,t.jsx)(eB.Z,{className:"h-3 w-3 mr-1"}),"Auto-route leads"]})]}),(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-slate-200 dark:border-slate-800 bg-white dark:bg-slate-900 hover:border-purple-300 dark:hover:border-purple-800 hover:shadow-lg hover:shadow-
1purple-500/5 transition-all duration-200 cursor-pointer",onClick:()=>{if(!I){y.default.error("Please select a pipeline first");return}eW(!0)},children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-purple-500 to-violet-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(eB.Z,{className:"h-5 w-5 text-white"})}),a_&&(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded text-[9px] font-medium bg-purple-50 dark:bg-purple-950/50 text-purple-600 dark:text-purple-400 max-w-[250px] truncate",title:a_.name,children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full shrink-0",style:{backgroundColor:a_.color}}),a_.name]})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"CRM Qualification"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"Auto-add to CRM pipeline"}),(0,t.jsx)("div",{className:"flex items-center gap-2 text-[10px]",children:(null==eK?void 0:eK.complementary_pipeline_enabled)?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-green-100 dark:bg-green-900/30 text-green-700 dark:text-green-300",children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500"}),"Enabled"]}),(0,t.jsx)("span",{className:"text-muted-foreground truncate",children:eK.name})]}):eK?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300",children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-500"}),"Linked"]}),(0,t.jsx)("span",{className:"text-muted-foreground truncate",children:eK.name})]}):(0,t.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-slate-100 dark:bg-slate-800 text-slate-600 dark:text-slate-400",children:[(0,t.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-slate-400"}),eG?"Loading...":"Not linked"]})})]}),E&&L&&(0,t.jsxs)("div",{className:"group relative p-5 rounded-xl border border-fuchsia-200 dark:border-fuchsia-900 bg-gradient-to-br from-fuchsia-50 to-violet-50 dark:from-fuchsia-950/40 dark:to-violet-950/40 hover:shadow-lg hover:shadow-fuchsia-500/10 transition-all duration-200 cursor-pointer",onClick:()=>{L(!0),null==O||O(null)},children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-lg bg-gradient-to-br from-fuchsia-500 to-violet-600 flex items-center justify-center shadow-sm",children:(0,t.jsx)(ab.Z,{className:"h-5 w-5 text-white"})}),(0,t.jsx)(eS.Z,{className:"h-4 w-4 text-slate-400 group-hover:text-fuchsia-500 group-hover:translate-x-0.5 transition-all"})]}),(0,t.jsx)("h3",{className:"font-semibold text-foreground mb-1",children:"Quick Demo"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3",children:"20 sample leads → calls + voice → classify"}),(0,t.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded text-[10px] font-medium bg-fuchsia-100 dark:bg-fuchsia-900/30 text-fuchsia-700 dark:text-fuchsia-300",children:"Demo only"})]})]}),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(D.Vq,{open:ei,onOpenChange:ed,children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-white ".concat(aW(null==ee?void 0:ee.color)),children:(0,t.jsx)(ah.Z,{className:"w-4 h-4"})}),null==ee?void 0:ee.name]}),(0,t.jsx)(D.Be,{children:(null==ee?void 0:ee.description)||"Staff members in this group"})]}),(0,t.jsx)("div",{className:"mt-4",children:er?(0,t.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,t.jsx)(w.Z,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):0===et.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[(0,t.jsx)(ah.Z,{className:"w-12 h-12 text-muted-foreground
1/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No members in this group"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:"Add staff members to this group to enable lead assignment"})]}):(0,t.jsx)("div",{className:"space-y-2 max-h-[300px] overflow-y-auto pr-2",children:et.map(e=>(0,t.jsxs)("div",{className:"flex items-center gap-3 p-3 rounded-lg bg-slate-50 dark:bg-slate-800/50 hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:[(0,t.jsx)("div",{className:"w-10 h-10 rounded-full bg-emerald-100 dark:bg-emerald-900/30 flex items-center justify-center text-emerald-700 dark:text-emerald-300 font-medium",children:aQ(e.user_name||"U")}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"font-medium truncate",children:e.user_name||"Unknown"}),(0,t.jsxs)("p",{className:"text-sm text-muted-foreground flex items-center gap-1 truncate",children:[(0,t.jsx)(ef.Z,{className:"w-3 h-3 flex-shrink-0"}),e.user_email||"-"]})]})]},e.id))})}),(0,t.jsxs)(D.cN,{className:"flex justify-between items-center mt-4 pt-4 border-t",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:[et.length," ",1===et.length?"member":"members"]}),(0,t.jsx)(d.z,{variant:"outline",onClick:()=>ed(!1),children:"Close"})]})]})}),(0,t.jsx)(D.Vq,{open:ec,onOpenChange:e=>{if(eo(e),e){let e=new Set((null==a_?void 0:a_.excluded_agent_ids)||[]);eI(e),eD(e)}else ey(null),eC([]),eu("add"),ep(""),ev([])},children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-lg max-h-[85vh] !p-0 gap-0 overflow-hidden flex flex-col",children:[(0,t.jsxs)(D.fK,{className:"px-6 py-4 border-b flex-shrink-0",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-amber-500 to-orange-600 flex items-center justify-center text-white",children:(0,t.jsx)(_.Z,{className:"w-4 h-4"})}),"Manage Users"]}),(0,t.jsxs)(D.Be,{children:['Manage groups for "',(null==a_?void 0:a_.name)||"this pipeline",'"']})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-hidden flex flex-col px-6 py-4",children:[(0,t.jsxs)("div",{className:"flex gap-1 p-1 bg-slate-100 dark:bg-slate-800 rounded-lg flex-shrink-0",children:[(0,t.jsxs)("button",{onClick:()=>eu("assigned"),className:"flex-1 px-3 py-2 text-sm font-medium rounded-md transition-all ".concat("assigned"===em?"bg-white dark:bg-slate-900 text-amber-600 shadow-sm":"text-muted-foreground hover:text-foreground"),children:["Assigned (",ay.length,")"]}),(0,t.jsx)("button",{onClick:()=>eu("users"),className:"flex-1 px-3 py-2 text-sm font-medium rounded-md transition-all ".concat("users"===em?"bg-white dark:bg-slate-900 text-amber-600 shadow-sm":"text-muted-foreground hover:text-foreground"),children:"Users"}),(0,t.jsx)("button",{onClick:()=>eu("add"),className:"flex-1 px-3 py-2 text-sm font-medium rounded-md transition-all ".concat("add"===em?"bg-white dark:bg-slate-900 text-amber-600 shadow-sm":"text-muted-foreground hover:text-foreground"),children:"Add +"})]}),(0,t.jsxs)("div",{className:"mt-4 flex-1 overflow-y-auto min-h-0 [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-slate-200 [&::-webkit-scrollbar-thumb]:rounded-full dark:[&::-webkit-scrollbar-thumb]:bg-slate-700",children:["assigned"===em&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"relative mb-3",children:[(0,t.jsx)(av.Z,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,t.jsx)(u.I,{placeholder:"Search groups...",value:ex,onChange:e=>aS(e.target.value),className:"pl-9 h-9"}),eN&&(0,t.jsx)(w.Z,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 animate-spin text-muted-foreground"})]}),ex.trim()?(0,t.jsx)(t.Fragment,{children:0===aZ.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[(0,t.jsx)(av.Z,{className:"w-12 h-12 text-muted-foreground/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No groups found"}
1),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:"Try a different search term"})]}):(0,t.jsx)("div",{className:"space-y-2 max-h-[300px] overflow-y-auto pr-2",children:aZ.map(e=>{var a;let s=null==a_?void 0:null===(a=a_.agent_group_ids)||void 0===a?void 0:a.includes(e.id);return(0,t.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg border transition-all ".concat(s?"border-amber-200 dark:border-amber-800 bg-amber-50/50 dark:bg-amber-900/20":"border-slate-200 dark:border-slate-700 bg-slate-50/50 dark:bg-slate-900/50 hover:border-emerald-300 dark:hover:border-emerald-700 hover:bg-emerald-50/50 dark:hover:bg-emerald-900/20"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-full flex items-center justify-center text-white ".concat(aW(e.color)),children:(0,t.jsx)(ah.Z,{className:"h-5 w-5"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:e.name}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[e.member_count||0," ",1===(e.member_count||0)?"member":"members",s&&(0,t.jsx)("span",{className:"ml-1 text-amber-600",children:"• Assigned"})]})]})]}),s?(0,t.jsxs)(d.z,{size:"sm",variant:"outline",className:"text-red-600 border-red-300 hover:bg-red-50",onClick:()=>aP(e.id),children:[(0,t.jsx)(v.Z,{className:"h-4 w-4 mr-1"}),"Remove"]}):(0,t.jsxs)(d.z,{size:"sm",variant:"outline",className:"text-emerald-600 border-emerald-300 hover:bg-emerald-50",onClick:()=>aI(e.id),children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-1"}),"Add"]})]},e.id)})})}):(0,t.jsx)(t.Fragment,{children:0===ay.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[(0,t.jsx)(ah.Z,{className:"w-12 h-12 text-muted-foreground/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No groups assigned"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:'Switch to "Add +" tab to assign groups'})]}):(0,t.jsx)("div",{className:"space-y-2 max-h-[300px] overflow-y-auto pr-2",children:ay.map(e=>(0,t.jsxs)("div",{className:"border border-slate-200 dark:border-slate-700 rounded-lg overflow-hidden",children:[(0,t.jsxs)("div",{onClick:()=>az(e.id),className:"flex items-center justify-between p-3 bg-slate-50/50 dark:bg-slate-900/50 cursor-pointer hover:bg-amber-50/50 dark:hover:bg-amber-900/20 transition-all",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-full flex items-center justify-center text-white ".concat(aW(e.color)),children:(0,t.jsx)(ah.Z,{className:"h-5 w-5"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:e.name}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[e.member_count||0," ",1===(e.member_count||0)?"member":"members"]})]})]}),(0,t.jsx)(es.Z,{className:"h-5 w-5 text-muted-foreground transition-transform ".concat(e_===e.id?"rotate-180":"")})]}),e_===e.id&&(0,t.jsxs)("div",{className:"border-t border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-950",children:[(0,t.jsx)("div",{className:"p-2",children:eF?(0,t.jsx)("div",{className:"flex items-center justify-center py-4",children:(0,t.jsx)(w.Z,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):0===ek.length?(0,t.jsx)("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No members in this group"}):(0,t.jsx)("div",{className:"space-y-1",children:ek.map(e=>{let a=e.user_id||e.id,s=ez.has(a);return(0,t.jsxs)("div",{onClick:()=>aD(a),className:"flex items-center gap-2 p-2 rounded-md cursor-pointer transition-colors ".concat(s?"bg-red-50 dark:bg-red-900/20 hover:bg-red-100 dark:hover:bg-red-900/30":"hover:bg-slate-100 dark:hover:bg-slate-800"),children:[(0,t.jsx)("input",{type:"checkbox",checked:!s,onChange:()=>{},className:"h-4 w-4 rounded border-slate-300 text-amber-600 focus:ring-amber-500"}),(0,t.jsx)("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xs font-medium ".concat(s?"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300":"bg-amber-100 dar
1k:bg-amber-900/30 text-amber-700 dark:text-amber-300"),children:aQ(e.user_name||"U")}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"text-sm font-medium truncate ".concat(s?"line-through text-muted-foreground":""),children:e.user_name||"Unknown"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:e.user_email||"-"})]}),s&&(0,t.jsx)("span",{className:"text-xs text-red-600 dark:text-red-400",children:"Excluded"})]},e.id)})})}),(0,t.jsx)("div",{className:"border-t border-slate-200 dark:border-slate-700 px-3 py-2 bg-slate-50/50 dark:bg-slate-900/50 flex justify-end",children:(0,t.jsxs)("button",{onClick:a=>{a.stopPropagation(),aP(e.id)},className:"flex items-center gap-1.5 text-sm text-red-600 dark:text-red-400 hover:text-red-700 dark:hover:text-red-300 transition-colors",children:[(0,t.jsx)(v.Z,{className:"h-4 w-4"}),"Remove Group"]})})]})]},e.id))})})]}),"add"===em&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"relative mb-3",children:[(0,t.jsx)(av.Z,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,t.jsx)(u.I,{placeholder:"Search groups...",value:ex,onChange:e=>aS(e.target.value),className:"pl-9 h-9"}),eN&&(0,t.jsx)(w.Z,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 animate-spin text-muted-foreground"})]}),0===aZ.length?(0,t.jsx)("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:ex.trim()?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(av.Z,{className:"w-12 h-12 text-muted-foreground/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No groups found"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:"Try a different search term"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(T.Z,{className:"w-12 h-12 text-emerald-500/50 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"All groups are assigned"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:"Create new groups in Settings to add more"})]})}):(0,t.jsx)("div",{className:"space-y-2 max-h-[300px] overflow-y-auto pr-2",children:aZ.map(e=>{var a;let s=null==a_?void 0:null===(a=a_.agent_group_ids)||void 0===a?void 0:a.includes(e.id);return(0,t.jsxs)("div",{className:"flex items-center justify-between p-3 rounded-lg border transition-all ".concat(s?"border-amber-200 dark:border-amber-800 bg-amber-50/50 dark:bg-amber-900/20":"border-slate-200 dark:border-slate-700 bg-slate-50/50 dark:bg-slate-900/50 hover:border-emerald-300 dark:hover:border-emerald-700 hover:bg-emerald-50/50 dark:hover:bg-emerald-900/20"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-full flex items-center justify-center text-white ".concat(aW(e.color)),children:(0,t.jsx)(ah.Z,{className:"h-5 w-5"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:e.name}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:[e.member_count||0," ",1===(e.member_count||0)?"member":"members",s&&(0,t.jsx)("span",{className:"ml-1 text-amber-600",children:"• Assigned"})]})]})]}),s?(0,t.jsxs)(d.z,{size:"sm",variant:"outline",className:"text-red-600 border-red-300 hover:bg-red-50",onClick:()=>aP(e.id),children:[(0,t.jsx)(v.Z,{className:"h-4 w-4 mr-1"}),"Remove"]}):(0,t.jsxs)(d.z,{size:"sm",variant:"outline",className:"text-emerald-600 border-emerald-300 hover:bg-emerald-50",onClick:()=>aI(e.id),children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 mr-1"}),"Add"]})]},e.id)})})]}),"users"===em&&(0,t.jsx)(t.Fragment,{children:eT?(0,t.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,t.jsx)(w.Z,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):0===aA.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[(0,t.jsx)(aN.Z,{className:"w-12 h-12 text-muted-foreground/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No users found"}
1),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:"Assign groups with members to see users here"})]}):(0,t.jsx)("div",{className:"space-y-2 max-h-[350px] overflow-y-auto pr-2",children:aA.map(e=>{let{user:a,groups:s,isExcluded:l}=e,r=a.user_id||a.id;return(0,t.jsxs)("div",{onClick:()=>aD(r),className:"flex items-center justify-between p-3 rounded-lg border cursor-pointer transition-colors ".concat(l?"border-red-200 dark:border-red-800 bg-red-50/50 dark:bg-red-900/20 hover:bg-red-100/50":"border-slate-200 dark:border-slate-700 bg-slate-50/50 dark:bg-slate-900/50 hover:bg-slate-100/50"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("input",{type:"checkbox",checked:!l,onChange:()=>{},className:"h-4 w-4 rounded border-slate-300 text-amber-600 focus:ring-amber-500"}),(0,t.jsx)("div",{className:"w-10 h-10 rounded-full flex items-center justify-center text-sm font-medium ".concat(l?"bg-red-100 dark:bg-red-900/30 text-red-700 dark:text-red-300":"bg-amber-100 dark:bg-amber-900/30 text-amber-700 dark:text-amber-300"),children:aQ(a.user_name||"U")}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-sm ".concat(l?"line-through text-muted-foreground":""),children:a.user_name||"Unknown"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:a.user_email||"-"})]})]}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-1 justify-end max-w-[200px]",children:[l&&(0,t.jsx)("span",{className:"text-xs text-red-600 dark:text-red-400 mr-2",children:"Excluded"}),s.map(e=>(0,t.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium text-white ".concat(aW(e.color)),children:e.name},e.id))]})]},r)})})})]})]}),(0,t.jsxs)(D.cN,{className:"flex justify-between items-center px-6 py-3 border-t flex-shrink-0",children:[(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:[ay.length," ",1===ay.length?"group":"groups"," assigned",aE&&(0,t.jsx)("span",{className:"ml-2 text-amber-600 dark:text-amber-400",children:"• Unsaved changes"})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>{eI(new Set(eP)),ey(null),eC([]),eo(!1)},children:"Cancel"}),(0,t.jsx)(d.z,{size:"sm",onClick:aL,disabled:eE,className:"bg-amber-600 hover:bg-amber-700 text-white",children:eE?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"w-4 h-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})]})]})]})}),(0,t.jsx)(D.Vq,{open:e3,onOpenChange:e6,children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-gradient-to-br from-indigo-500 to-blue-600 flex items-center justify-center",children:(0,t.jsx)(Q.Z,{className:"h-4 w-4 text-white"})}),"Lead Assignment"]}),(0,t.jsx)(D.Be,{children:"Choose how new leads are automatically assigned to agents"})]}),(0,t.jsx)("div",{className:"space-y-2 py-2 overflow-y-auto [&::-webkit-scrollbar]:hidden [-ms-overflow-style:none] [scrollbar-width:none]",children:aM.map(e=>{let a=e.icon,s=U===e.value,l=e8===e.value,r="round_robin"===e.value||"least_loaded"===e.value||"single_user"===e.value;return(0,t.jsxs)("div",{className:"rounded-lg border-2 overflow-hidden transition-all ".concat(s?"border-indigo-500":"border-slate-200 dark:border-slate-800"),children:[(0,t.jsxs)("div",{onClick:()=>{aw(e.value),r&&(s&&l?e9(null):(e9(e.value),aR(),("least_loaded"===e.value||"single_user"===e.value)&&aB()))},className:"\n                        flex items-center gap-2.5 px-3 py-2.5 transition-all cursor-pointer\n                        ".concat(s?"bg-indigo-50 dark:bg-indigo-950/30":"hover:bg-slate-50 dark:hover:bg-slate-900/50","\n                        ").concat(W?"opacity-50 pointer-events-none":"","\n                      "),children:[(0,t.jsx)("div",{className:"p-1.5 rounded-md ".concat(s?"bg-indigo-500 text-white":"bg-slate-100 dark:bg-slate-800"),children:(0,t.jsx)(a,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:e.label}),(0,t.jsx)("p",{className:"text-[11px] text-muted-foreground leading-tight",children:e.description})]}),r&&s&&(0,t.jsx)(es.Z,{className:"h-4 w-4 text-muted-foreground transition-transform ".concat(l?"rotate-180":"")})]}),"single_user"===e.value&&l&&(0,t.jsxs)("div",{className:"border-t border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-950 p-2.5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,t.jsx)("p",{className:"text-xs font-medium",children:"Unassigned Leads"}
1),(0,t.jsxs)("span",{className:"text-[10px] bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded-full",children:[e7.length," leads"]})]}),ai||aa?(0,t.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,t.jsx)(w.Z,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):0===ar.length?(0,t.jsx)("div",{className:"text-center py-3 text-muted-foreground",children:(0,t.jsx)("p",{className:"text-xs",children:"No agents in pipeline groups"})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground mb-2",children:"Select Agent"}),(0,t.jsx)("div",{className:"space-y-1.5 max-h-[150px] overflow-y-auto pr-2 mb-3 [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-slate-300 [&::-webkit-scrollbar-thumb]:rounded-full dark:[&::-webkit-scrollbar-thumb]:bg-slate-600",children:ar.map(e=>(0,t.jsxs)("div",{onClick:a=>{a.stopPropagation(),ao(new Set([e.id]))},className:"flex items-center gap-2 p-2 rounded-lg cursor-pointer transition-colors ".concat(ac.has(e.id)?"bg-slate-100 dark:bg-slate-800 border-2 border-slate-500":"bg-slate-50 dark:bg-slate-900 border-2 border-transparent hover:border-slate-300"),children:[(0,t.jsx)("input",{type:"radio",checked:ac.has(e.id),onChange:()=>{},className:"h-3.5 w-3.5 text-slate-600 focus:ring-slate-500"}),(0,t.jsx)("div",{className:"w-7 h-7 rounded-full bg-slate-200 dark:bg-slate-700 flex items-center justify-center text-slate-700 dark:text-slate-300 text-xs font-medium",children:(e.name||"U").charAt(0).toUpperCase()}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsx)("p",{className:"text-sm font-medium truncate",children:e.name||"Unknown"})}),(0,t.jsx)("span",{className:"px-1.5 py-0.5 rounded-full text-[10px] font-medium bg-slate-100 text-slate-600 dark:bg-slate-800 dark:text-slate-300",children:e.lead_count||0})]},e.id))}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{onClick:e=>{e.stopPropagation(),aT()},disabled:W||0===ac.size,variant:"outline",size:"sm",className:"flex-1",children:W?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"Saving..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(af.Z,{className:"w-3.5 h-3.5 mr-1.5"}),"Save"]})}),(0,t.jsx)(d.z,{onClick:e=>{e.stopPropagation(),aU()},disabled:at||0===e7.length||0===ac.size,size:"sm",className:"flex-1 bg-slate-600 hover:bg-slate-700 text-white",children:at?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"Assigning..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Q.Z,{className:"w-3.5 h-3.5 mr-1.5"}),"Assign (",e7.length,")"]})})]})]})]}),"round_robin"===e.value&&l&&(0,t.jsxs)("div",{className:"border-t border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-950 p-2.5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,t.jsx)("p",{className:"text-xs font-medium",children:"Unassigned Leads"}),(0,t.jsxs)("span",{className:"text-[10px] bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded-full",children:[e7.length," leads"]})]}),aa?(0,t.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,t.jsx)(w.Z,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):0===e7.length?(0,t.jsxs)("div",{className:"text-center py-3 text-muted-foreground",children:[(0,t.jsx)(T.Z,{className:"w-6 h-6 mx-auto mb-1 text-emerald-500/50"}),(0,t.jsx)("p",{className:"text-xs",children:"All leads are assigned"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"p-2.5 mb-2 rounded-lg bg-slate-50 dark:bg-slate-900 text-center",children:[(0,t.jsx)("p",{className:"text-xl font-bold text-indigo-600 dark:text-indigo-400",children:e7.length.toLocaleString()}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"leads ready"})]}),(0,t.jsx)(d.z,{onClick:e=>{e.stopPropagation(),aq()},disabled:at||0===e7.length,size:"sm",className:"w-full bg-indigo-600 hover:bg-indigo-700 text-white",children:at?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"Assigning..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Q.Z,{className:"w-3.5 h-3.5 mr-1.5"}
1),"Assign All (",e7.length.toLocaleString(),")"]})})]})]}),"least_loaded"===e.value&&l&&(0,t.jsxs)("div",{className:"border-t border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-950 p-2.5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,t.jsx)("p",{className:"text-xs font-medium",children:"Unassigned Leads"}),(0,t.jsxs)("span",{className:"text-[10px] bg-slate-100 dark:bg-slate-800 px-1.5 py-0.5 rounded-full",children:[e7.length," leads"]})]}),ai||aa?(0,t.jsx)("div",{className:"flex items-center justify-center py-3",children:(0,t.jsx)(w.Z,{className:"w-4 h-4 animate-spin text-muted-foreground"})}):0===ar.length?(0,t.jsx)("div",{className:"text-center py-3 text-muted-foreground",children:(0,t.jsx)("p",{className:"text-xs",children:"No agents in pipeline groups"})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"mb-2",children:[(0,t.jsx)("p",{className:"text-[10px] text-muted-foreground mb-1.5",children:"Least Loaded Agent"}),ar.slice(0,1).map(e=>(0,t.jsxs)("div",{onClick:a=>{a.stopPropagation(),ao(new Set([e.id]))},className:"flex items-center gap-2 p-2 rounded-lg cursor-pointer transition-colors ".concat(ac.has(e.id)?"bg-emerald-50 dark:bg-emerald-900/20 border-2 border-emerald-500":"bg-slate-50 dark:bg-slate-900 border-2 border-transparent hover:border-emerald-300"),children:[(0,t.jsx)("input",{type:"radio",checked:ac.has(e.id),onChange:()=>{},className:"h-3.5 w-3.5 text-emerald-600 focus:ring-emerald-500"}),(0,t.jsx)("div",{className:"w-7 h-7 rounded-full bg-emerald-100 dark:bg-emerald-900/30 flex items-center justify-center text-emerald-700 dark:text-emerald-300 text-xs font-medium",children:(e.name||"U").charAt(0).toUpperCase()}),(0,t.jsx)("div",{className:"flex-1 min-w-0",children:(0,t.jsx)("p",{className:"text-sm font-medium truncate",children:e.name||"Unknown"})}),(0,t.jsx)("span",{className:"px-1.5 py-0.5 rounded-full text-[10px] font-medium bg-emerald-100 text-emerald-700 dark:bg-emerald-900/30 dark:text-emerald-300",children:e.lead_count||0})]},e.id))]}),(0,t.jsx)(d.z,{onClick:e=>{e.stopPropagation(),aV()},disabled:at||0===e7.length||0===ac.size,size:"sm",className:"w-full bg-emerald-600 hover:bg-emerald-700 text-white",children:at?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"w-3.5 h-3.5 mr-1.5 animate-spin"}),"Assigning..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(M.Z,{className:"w-3.5 h-3.5 mr-1.5"}),"Trigger Assignment"]})})]})]})]},e.value)})}),(0,t.jsx)(D.cN,{className:"pt-2",children:(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>e6(!1),children:"Close"})})]})}),(0,t.jsx)(D.Vq,{open:eQ,onOpenChange:e=>{eW(e),e||e5(null)},children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-md max-h-[85vh] !p-0 gap-0 overflow-hidden flex flex-col",children:[(0,t.jsxs)(D.fK,{className:"px-6 py-4 border-b flex-shrink-0",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-gradient-to-br from-purple-500 to-violet-600 flex items-center justify-center",children:(0,t.jsx)(eB.Z,{className:"h-4 w-4 text-white"})}),"CRM Qualification Settings"]}),(0,t.jsx)(D.Be,{children:"Configure automatic CRM pipeline assignment for qualified leads"})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto px-6 py-4 space-y-4 [&::-webkit-scrollbar]:w-1.5 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-slate-200 [&::-webkit-scrollbar-thumb]:rounded-full dark:[&::-webkit-scrollbar-thumb]:bg-slate-700",children:eG?(0,t.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,t.jsx)(w.Z,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Select CRM Pipeline"}),(0,t.jsxs)(o.Ph,{value:(null==eK?void 0:eK.id)||"",onValueChange:e=>{"none"===e?au():am(e)},disabled:eX,children:[(0,t.jsx)(o.i4,{className:"w-full",children:(0,t.jsx)(o.ki,{placeholder:"Select a CRM pipeline to link",children:eK?(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:eK.color||"#8B5CF6"}}),eK.name]}):"Select a CRM pipeline to link"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"none",children:(0,t.jsx)("span",{className:"text-muted-foreground",children:"No pipeline (unlink)"})}),eY.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:e.color||"#8B5CF6"}}),e.name]})},e.id))]})]}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Qualified leads will be automatically added to the selected CRM pipeline"})]}),eK&&(0,t.jsxs)("div",{className:"space-y-4 p-4 rounded-lg border border-slate-200 dark:border-slate-700 bg-slate-50/50 dark:bg-slate-800/50",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"space-y-0.5",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Enable Auto-Add"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Automatically add qualified leads to CRM"})]}),(0,t.jsx)(g.r,{checked:(null==ax?void 0:ax.complementary_pipeline_enabled)||!1,onCheckedChange:e=>{ap({complementary_pipeline_enabled:e})},disabled:eX})]}),(null==ax?void 0:ax.complementary_pipeline_enabled)&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"border-t pt-4",children:(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"space-y-0.5",children:[(0,t.jsx)(p._,{className:"text-sm font-medium ".concat(!1===e2?"text-muted-foreground":""),children:"Payment Verification"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:!1===e2?"Connect Razorpay in Settings first":"Require payment before qualification"})]}),(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)("span",{children:(0,t.jsx)(g.r,{checked:(null==ax?void 0:ax.payment_verification_enabled)||!1,onCheckedChange:e=>{ap({payment_verification_enabled:e,registration_amount:e?null==ax?void 0:ax.registration_amount:null})},disabled:eX||!1===e2})})}),!1===e2&&(0,t.jsx)(f._v,{children:(0,t.jsx)("p",{children:"Connect Razorpay in Settings → Razorpay"})})]})})]})}),(null==ax?void 0:ax.payment_verification_enabled)&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Registration Amount"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"text-sm text-muted-foreground",children:"₹"}),(0,t.jsx)(u.I,{type:"number",min:"0",step:"0.01",placeholder:"0.00",value:(null==ax?void 0:ax.registration_amount)||"",onChange:e=>{ap({registration_amount:e.target.value?parseFloat(e.target.value):null})},className:"w-32",disabled:eX})]}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Amount required before qualification"})]}),(null==ax?void 0:ax.payment_verification_enabled)&&(null==ax?void 0:ax.registration_amount)&&(0,t.jsxs)("div",{className:"border-t pt-4",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"space-y-0.5",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Use Razorpay"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Generate payment links"})]}),(0,t.jsx)(g.r,{checked:(null==ax?void 0:ax.razorpay_enabled)||!1,onCheckedChange:e=>{ap({razorpay_enabled:e})},disabled:eX})]}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-2",children:(null==ax?void 0:ax.razorpay_enabled)?"✓ Payment links will be generated automatically":"Manual payment recording only"})]})]})]})]})}),(0,t.jsxs)(D.cN,{className:"px-6 py-3 border-t flex-shrink-0 flex justify-between items-center",children:[(0,t.jsx)("div",{className:"text-sm text-muted-foreground",children:ag&&(0,t.jsx)("span",{className:"text-amber-600 dar
1k:text-amber-400",children:"Unsaved changes"})}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>{e5(null),eW(!1)},children:"Cancel"}),(0,t.jsx)(d.z,{size:"sm",onClick:aj,disabled:eX||!ag,className:"bg-purple-600 hover:bg-purple-700 text-white",children:eX?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"w-4 h-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})]})]})]})}),I&&a_&&(0,t.jsx)(aO,{open:eq,onOpenChange:eV,pipelineId:I,pipelineName:a_.name,stages:c,workspaceId:(null==r?void 0:r.workspace_id)||""})]})]})}function aT(){var e,a,s,m,j,b,k,F,P,E;let W=(0,n.useRouter)(),Y=(0,n.useSearchParams)(),{user:H}=(0,ai.a)(),G=["[email protected]","[email protected]"].includes(((null==H?void 0:H.email)||(null==H?void 0:null===(e=H.settings)||void 0===e?void 0:e.email)||"").toLowerCase()),[J,ee]=(0,l.useState)(!1),[et,er]=(0,l.useState)("both"),[en,ei]=(0,l.useState)(20),[ed,ec]=(0,l.useState)(!1),[eo,ev]=(0,l.useState)(null),{endNavigation:ek}=(0,aL.H)(),eC=(0,aD.DO)(),{groups:ez,loading:eP}=(0,aE.r)(),{users:eD,loading:eE,updateUser:eL,refresh:eO}=(0,e0.U)(),eB=(0,l.useRef)(null),eT=(0,l.useRef)(null);console.log("[Leads] Role permissions:",{canAssignLeads:null==eC?void 0:eC.canAssignLeads,dashboardRole:null==eC?void 0:eC.dashboardRole,loading:null==eC?void 0:eC.loading});let eU=null!==(P=null==eC?void 0:eC.canAssignLeads)&&void 0!==P&&P,eq=null!==(E=null==eC?void 0:eC.canDeleteLeads)&&void 0!==E&&E;null==eC||eC.canMoveLeads,null==eC||eC.dashboardRole,null==eC||eC.isManager;let[e$,eG]=(0,l.useState)(null),[eJ,e5]=(0,l.useState)(null),[e2,e6]=(0,l.useState)(null),[e8,e9]=(0,l.useState)(!1),[e7,ae]=(0,l.useState)(!0),[aa,al]=(0,l.useState)(!1),[ar,an]=(0,l.useState)(!1),[ap,ag]=(0,l.useState)(!1),[af,aM]=(0,l.useState)(!1),[aT,aU]=(0,l.useState)(null),[aq,aV]=(0,l.useState)(null),[aQ,aW]=(0,l.useState)(!1),[aY,a$]=(0,l.useState)(null),[aK,aH]=(0,l.useState)(!1),[aG,aJ]=(0,l.useState)(null),[aX,a0]=(0,l.useState)(!1),[a1,a5]=(0,l.useState)(null),[a2,a4]=(0,l.useState)(!1),[a3,a6]=(0,l.useState)(!1),[a8,a9]=(0,l.useState)(new Set),[a7,se]=(0,l.useState)(!1),[sa,ss]=(0,l.useState)(!1),[st,sl]=(0,l.useState)([]),[sr,sn]=(0,l.useState)(!1),[si,sd]=(0,l.useState)(!1),[sc,so]=(0,l.useState)(!0),[sm,su]=(0,l.useState)(!1),[sx,sp]=(0,l.useState)(null),[sh,sg]=(0,l.useState)(!1),[sf,sj]=(0,l.useState)({name:"",email:"",phone:"",company:"",score:0}),[sb,sv]=(0,l.useState)(!1),[sN,sw]=(0,l.useState)([]),[s_,sy]=(0,l.useState)(!1),[sk,sC]=(0,l.useState)(!1),[sS,sZ]=(0,l.useState)({}),[sF,sA]=(0,l.useState)(!1),[sz,sI]=(0,l.useState)("timeline"),[sP,sD]=(0,l.useState)([]),[sE,sL]=(0,l.useState)(!1),[sR,sM]=(0,l.useState)(new Date),[sO,sB]=(0,l.useState)({amount:"",currency:"INR",payment_date:new Date().toISOString().split("T")[0],payment_method:"upi",payment_status:"completed",invoice_number:"",description:"",is_recurring:!1,recurring_frequency:""}),[sT,sU]=(0,l.useState)(!1),[sq,sV]=(0,l.useState)([]),[sQ,sW]=(0,l.useState)(!1),[sY,s$]=(0,l.useState)(null),[sK,sH]=(0,l.useState)(!1),[sG,sJ]=(0,l.useState)(!1),[sX,s0]=(0,l.useState)(!1),[s1,s5]=(0,l.useState)(!1),[s2,s4]=(0,l.useState)(null),[s3,s6]=(0,l.useState)("First Call"),[s8,s9]=(0,l.useState)(""),[s7,te]=(0,l.useState)("high"),[ta,ts]=(0,l.useState)(""),[tt,tl]=(0,l.useState)(!1),[tr,tn]=(0,l.useState)("schedule"),[ti,td]=(0,l.useState)(""),[tc,to]=(0,l.useState)(""),[tm,tu]=(0,l.useState)(0),[tx,tp]=(0,l.useState)(""),[th,tg]=(0,l.useState)(""),[tf,tj]=(0,l.useState)(!1),[tb,tv]=(0,l.useState)(null),[tN,tw]=(0,l.useState)("calling"),[t_,ty]=(0,l.useState)(null),[tk,tC]=(0,l.useState)(0),[tS,tZ]=(0,l.useState)(!1),[tF,tA]=(0,l.useState)(null),tz=(0,l.useRef)(null),tI=(0,l.useRef)(null),tP=(0,l.useRef)(null),tD=(0,l.useRef)([]),[tE,tL]=(0,l.useState)(""),[tR,tM]=(0,l.useState)(""),[tO,tB]=(0,l.useState)(""),[tT,tU]=(0,l.useState)(""),[tq,tV]=(0,l.useState)(""),[tQ,tW]=(0,l.useState)(!1),[tY,t$]=(0,l.useState)(""),[tK,tH]=(0,l.useState)(!1),[tG,tJ]=(0,l.useState)(null),[tX,t0]=(0,l.useState)(!1),[t1,t5]=(0,l.useState)(!1),[t2,t4]=(0,l.useState)("smartflo"),[t3,t6]=(0,l.useState)({positive:[],neutral:[],negative:[]}),[t8,t9]=(0,l.useState)(!1),[t7,le]=(0,l.useState)([]),[la,ls]=(0,l.useState)(!1),[lt,ll]=(0,l.useState)(""),[lr,ln]=(0,l.useState)(!1);(0,l.useRef)(null);let[li,ld]=(0,l.useState)(!1),[lc,lo]=(0,l.useState)(""),[lm,lu]=(0,l.useState)([]),[lx,lp]=(0,l.useState)(!1),lh=(0,l.useRef)(null),[lg,lf]=(0,l.useState)(""),[lj,lb]=(0,l.useState)(""),[lv,lN]=(0,l.useState)([]),[lw,l_]=(0,l.useState)(!1),[ly,lk]=(0,l.useState)(!1),[lC,lS]=(0,l.useState)(!1),[lZ,lF]=(0,l.useState)([]),[lA,lz]=(0,l.useState)(new Set),[lI,lP]=(0,l.useState)(1),[lD,lE]=(0,l.useState)(!0),[lL,lR]=(0,l.useState)(!1),[lM,lO]=(0,l.useState)(!1),[lB,lT]=(0,l.useState)(!1),[lU,lq]=(0,l.useState)("all"),[lV,lQ]=(0,l.useState)(!1),[lW,lY]=(0,l.useState)(!1),[l$,lK]=(0,l.useState)([]),lH=(0,l.useRef)(null),[lG,lJ]=(0,l.useState)("pipeline"),[lX,l0]=(0,l.useState)([]),[l1,l5]=(0,l.useState)(!0),[l2,l4]=(0,l.useState)([]),[l3,l6]=(0,l.useState)(0),l8=(0,l.useRef)(null),l9=(0,l.useRef)(null),[l7,re]=(0,l.useState)(!1),[ra,rs]=(0,l.useState)([]),[rt,rl]=(0,l.useState)(!0),[rr,rn]=(0,l.useState)(!1),[ri,rd]=(0,l.useState)({total_amount:0,completed_amount:0,pending_amount:0,payment_count:0,completed_count:0,pending_count:0}),[rc,ro]=(0,l.useState)(!0),[rm,ru]=(0,l.useState)([]),[rx,rp]=(0,l.useState)(null),[rh,rg]=(0,l.useState)({active:[],inactive:[]}),[rf,rj]=(0,l.useState)(!1),[rb,rv]=(0,l.useState)(null),[rN,rw]=(0,l.useState)(!1),[r_,ry]=(0,l.useState)(!1),[rk,rC]=(0,l.useState)(null),[rS,rZ]=(0,l.useState)([]),[rF,rA]=(0,l.useState)(null),[rz,rI]=(0,l.useState)(!1),[rP,rD]=(0,l.useState)(!1),[rE,rL]=(0,l.useState)([]),[rR,rM]=(0,l.useState)(()=>Y.get("pipeline")||localStorage.getItem("leads_selected_pipeline")||null),[rO,rB]=(0,l.useState)(!1),[rT,rU]=(0,l.useState)(null),[rq,rV]=(0,l.useState)(""),[rQ,rW]=(0,l.useState)("#3B82F6"),[rY,r$]=(0,l.useState)(""),[rK,rH]=(0,l.useState)([]),[rG,rJ]=(0,l.useState)([]),[rX,r0]=(0,l.useState)(!1),[r1,r5]=(0,l.useState)(""),[r2,r4]=(0,l.useState)(""),[r3,r6]=(0,l.useState)(!1),[r8,r9]=(0,l.useState)(!1),[r7,ne]=(0,l.useState)({open:!1,pipelineId:"",pipelineName:"",leadsCount:0,warning:""}),[na,ns]=(0,l.useState)({}),[nt,nl]=(0,l.useState)(!1),[nr,nn]=(0,l.useState)(0),[ni,nd]=(0,l.useState)(!1),[nc,no]=(0,l.useState)(null),[nm,nu]=(0,l.useState)(!1),[nx,np]=(0,l.useState)("all"),[nh,ng]=(0,l.useState)(!1),[nf,nj]=(0,l.useState)(0),[nb,nv]=(0,l.useState)({totalLeads:0,wonLeads:0,lostLeads:0}),[nN,nw]=(0,l.useState)(!1),[n_,ny]=(0,l.useState)(null),[nk,nC]=(0,l.useState)(""),[nS,nZ]=(0,l.useState)(!1),[nF,nA]=(0,l.useState)(!1),[nz,nI]=(0,l.useState)(!1),[nP,nD]=(0,l.useState)(1),[nE,nL]=(0,l.useState)([]),[nR,nM]=(0,l.useState)(null),[nO,nB]=(0,l.useState)([]),[nT,nU]=(0,l.useState)(null),[nq,nV]=(0,l.useState)(!1),[nQ,nW]=(0,l.useState)(!1),[nY,n$]=(0,l.useState)(""),[nK,nH]=(0,l.useState)([]),[nG,nJ]=(0,l.useState)(new Set),[nX,n0]=(0,l.useState)(!1),[n1,n5]=(0,l.useState)("segment_only"),[n2,n4]=(0,l.useState)("lead"),[n3,n6]=(0,l.useState)(""),[n8,n9]=(0,l.useState)("sales"),[n7,ie]=(0,l.useState)(!1);(0,l.useMemo)(()=>st.map(e=>({id:e.id||e.slug,name:e.name,slug:e.slug,color:e.color||"#3B82F6",position:e.position||0})),[st]);let ia=(0,l.useMemo)(()=>{let e=new Map;return st.forEach(a=>
1{(a.leads||[]).forEach(a=>{a.assigned_to&&a.assigned_to_name&&!e.has(a.assigned_to)&&e.set(a.assigned_to,{id:a.assigned_to,name:a.assigned_to_name})})}),Array.from(e.values()).sort((e,a)=>e.name.localeCompare(a.name))},[st]);(0,l.useEffect)(()=>{(null==H?void 0:H.workspace_id)&&(it(),ii(),il(),iN()),iO()},[null==H?void 0:H.workspace_id]),(0,l.useEffect)(()=>{(async()=>{if((null==H?void 0:H.workspace_id)&&0!==rE.length)try{let t=0,l=0,r=0;for(let n of rE)try{var e,a,s;let i=await C.api.get("/lead-pipelines/".concat(n.id,"/board"),{params:{workspace_id:H.workspace_id}});for(let n of(null===(e=i.data)||void 0===e?void 0:e.board)||[]){let e=n.stage,i=n.entries||[];t+=i.length;let d=(null==e?void 0:e.is_completed_point)||(null==e?void 0:e.is_won_point)||(null==e?void 0:null===(a=e.name)||void 0===a?void 0:a.toLowerCase().includes("won")),c=(null==e?void 0:e.is_dropped_point)||(null==e?void 0:e.is_lost_point)||(null==e?void 0:null===(s=e.name)||void 0===s?void 0:s.toLowerCase().includes("lost"));d&&(l+=i.length),c&&(r+=i.length)}}catch(e){console.error("Failed to fetch pipeline ".concat(n.id,":"),e)}nv({totalLeads:t,wonLeads:l,lostLeads:r})}catch(e){console.error("Failed to fetch all pipelines stats:",e)}})()},[null==H?void 0:H.workspace_id,rE,e$]),(0,l.useEffect)(()=>{let e=async()=>{try{l5(!0);let e=await eI.S.getAllActivities({limit:15});l0(e.activities)}catch(e){console.error("Failed to fetch activities:",e)}finally{l5(!1)}};return e(),l8.current=setInterval(e,1e4),()=>{l8.current&&clearInterval(l8.current)}},[]),(0,l.useEffect)(()=>{let e=async()=>{try{var e;rl(!0);let a=await C.api.get("/leads/analytics/insights",{params:{limit:10,include_read:!1}});rs((null===(e=a.data)||void 0===e?void 0:e.insights)||[])}catch(e){console.error("Failed to fetch workspace insights:",e)}finally{rl(!1)}};e();let a=setInterval(e,3e4);return()=>{clearInterval(a)}},[]),(0,l.useEffect)(()=>{(async()=>{if("analytics"===lG)try{var e;nu(!0);let a=await C.api.get("/ai-calls/dashboard",{params:{period:"all",pipeline_id:"all"===nx?void 0:nx}});(null===(e=a.data)||void 0===e?void 0:e.charts_data)&&no(a.data.charts_data)}catch(e){console.error("Failed to fetch AI call analytics:",e)}finally{nu(!1)}})()},[lG,nx]),(0,l.useEffect)(()=>{if("analytics"===lG&&rE.length>0){let e=rE.filter(e=>e.ai_calls_enabled);e.length>0&&("all"===nx||!e.find(e=>e.id===nx))&&np(e[0].id)}},[lG,rE]),(0,l.useEffect)(()=>{if(0===lX.length){l4([]);return}l4([]),l6(0);let e=lX[0];return e&&(l4([e]),l6(1)),l9.current=setInterval(()=>{l6(e=>{let a=e%lX.length,s=lX[a];return l4(e=>[s,...e.filter(e=>
1e.id!==s.id)].slice(0,5)),e+1})},3e3),()=>{l9.current&&clearInterval(l9.current)}},[lX]),(0,l.useEffect)(()=>{if(rR){eT.current&&eT.current.abort();let e=new AbortController;eT.current=e,e$?al(!0):ae(!0),(async()=>{try{await iM(rf,rb,rx,rR,e.signal),await is(),await i_()}catch(e){if((null==e?void 0:e.name)==="CanceledError"||(null==e?void 0:e.code)==="ERR_CANCELED"){console.log("[Pipeline] Request cancelled - user switched pipelines");return}throw e}finally{e.signal.aborted||(al(!1),ae(!1))}})()}return()=>{eT.current&&eT.current.abort()}},[rR]),(0,l.useEffect)(()=>{if(!(null==H?void 0:H.workspace_id))return;iy();let e=setInterval(iy,5e3);return()=>clearInterval(e)},[null==H?void 0:H.workspace_id]),(0,l.useEffect)(()=>{let e=Y.get("openLead");if(e&&(null==e$?void 0:e$.pipeline)&&!e7){let a=null;for(let s of Object.keys(e$.pipeline)){let t=e$.pipeline[s].find(a=>a.id===e);if(t){a=t;break}}a&&(e5(a),sI("timeline"),W.replace("/dashboard/leads",{scroll:!1}))}},[Y,e$,e7,W]),(0,l.useEffect)(()=>()=>{tz.current&&clearInterval(tz.current),tP.current&&clearTimeout(tP.current)},[]),(0,l.useEffect)(()=>{let e=e=>{let a=e.detail;if(t_&&a.call_id===t_){if(console.log("[Call WS] Status update:",a.status,a),"ringing"===a.status);else if("connected"===a.status)tw(e=>"calling"===e?(tI.current=new Date,tz.current=setInterval(()=>{tC(e=>e+1)},1e3),"connected"):e);else if("completed"===a.status){da();let e=a.duration_seconds;e&&e>0?(tH(!0),tC(e),tw(e=>"calling"===e?(setTimeout(()=>tw("ended"),3e3),"connected"):"ended")):tw("ended")}else"failed"===a.status&&(da(),tw("ended"))}};return window.addEventListener("ws:call_status_update",e),()=>window.removeEventListener("ws:call_status_update",e)},[t_]),(0,l.useEffect)(()=>{let e=e=>{let a=e.detail;if(console.log("[AI Call WS] Status update received:",a),!(null==a?void 0:a.lead_id)||!(null==a?void 0:a.call_type)||"ai_call"!==a.call_type)return;let s=a.lead_id,t=a.status,l=a.disposition,r="in_progress",n="initiated";if("queued"===t||"initiated"===t?(r="in_progress",n="initiated"):"ringing"===t?(r="in_progress",n="ringing"):"connected"===t||"in-progress"===t||"in_progress"===t||"connected"===l?(r="in_progress",n="connected"):"answered"===t||"answered"===l?(r="in_progress",n="answered"):"completed"===t?(r="completed",n="completed"):"hangup"===t?(r="hangup",n="hangup"):"busy"===t||"busy"===l?(r="failed",n="busy"):"no-answer"===t||"no_answer"===t||"no_answer"===l?(r="no_answer",n="no_answer"):"cancelled"===t||"canceled"===t||"cancelled"===l?(r="cancelled",n="cancelled"):("failed"===t||"failed"===l||"rejected"===l)&&(r="failed",n="failed"),e$){let e={...e$.pipeline},t=!1;for(let l in e)e[l]=e[l].map(e=>{if(e.id===s){var l;return t=!0,{...e,ai_first_call_status:r,ai_call_display_status:n,ai_first_call_id:a.call_id||a.conversation_id||e.ai_first_call_id,ai_interest_score:null!==(l=a.ai_interest_score)&&void 0!==l?l:e.ai_interest_score,ai_interest_category:a.ai_interest_category||a.outcome||e.ai_interest_category,ai_interest_emoji:a.ai_interest_emoji||e.ai_interest_emoji}}return e});t&&eG({...e$,pipeline:e})}};return window.addEventListener("ws:call_status_update",e),()=>window.removeEventListener("ws:call_status_update",e)},[e$]),(0,l.useEffect)(()=>{let e=e=>{var a;let s=e.detail;if((null==s?void 0:s.event_type)!=="lead_updated"||!(null==s?void 0:null===(a=s.data)||void 0===a?void 0:a.lead_id)||"ai_call"!==s.data.source)return;let t=s.data,l=t.lead_id;if(console.log("[Dashboard WS] Lead updated with AI data:",t),e$){let e={...e$.pipeline},a=!1;for(let s in e)e[s]=e[s].map(e=>{if(e.id===l){var s;return a=!0,{...e,ai_first_call_status:t.ai_first_call_status||e.ai_first_call_status,ai_interest_score:null!==(s=t.ai_interest_score)&&void 0!==s?s:e.ai_interest_score,ai_interest_category:t.ai_interest_category||e.ai_interest_category,ai_call_summary:t.ai_call_summary||e.ai_call_summary}}return e});if(a&&(eG({...e$,pipeline:e}),t.ai_interest_category&&"completed"===t.ai_first_call_status)){let e=t.ai_interest_category,a=t.ai_interest_score||0;"hot"===e?y.default.success("\uD83D\uDD25 Hot lead! Score: ".concat(a,"/100")):"warm"===e?y.default.success("☀️ Warm lead. Score: ".concat(a,"/100")):"cold"===e&&(0,y.default)("❄️ Cold lead. Score: ".concat(a,"/100"))}}};return window.addEventListener("ws:dashboard_event",e),()=>window.removeEventListener("ws:dashboard_event",e)},[e$]),(0,l.useEffect)(()=>
1{if(!(null==e$?void 0:e$.pipeline)){tD.current=[];return}let e=[];for(let a in e$.pipeline)for(let s of e$.pipeline[a])("in_progress"===s.ai_first_call_status||"pending"===s.ai_first_call_status)&&s.ai_first_call_id&&e.push({leadId:s.id,callId:s.ai_first_call_id});tD.current=e},[null==e$?void 0:e$.pipeline]);let is=async()=>{try{let e=await el(null==H?void 0:H.workspace_id,rR||void 0);t6(e)}catch(e){console.error("Failed to fetch call statuses:",e)}},it=async()=>{try{let e=null==H?void 0:H.workspace_id,a=(await C.api.get("/facebook-campaigns/accounts",{params:{workspace_id:e}})).data;a.success&&ru(a.accounts||[])}catch(e){console.error("Failed to fetch ad accounts:",e)}},il=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:rx;try{rw(!0);let a=null==H?void 0:H.workspace_id,s={};a&&(s.workspace_id=a),e&&(s.account_id=e);let t=(await C.api.get("/facebook-campaigns/campaigns",{params:s})).data;t.success&&rg({active:t.active_campaigns||[],inactive:t.inactive_campaigns||[]})}catch(e){console.error("Failed to fetch campaigns:",e)}finally{rw(!1)}},ir=e=>{if(rM(e),e){localStorage.setItem("leads_selected_pipeline",e);let a=new URLSearchParams(Y.toString());a.set("pipeline",e),W.replace("?".concat(a.toString()),{scroll:!1})}else localStorage.removeItem("leads_selected_pipeline")},ii=async()=>{try{var e;let a=null==H?void 0:H.workspace_id;if(!a)return;let s=await C.api.get("/lead-pipelines",{params:{workspace_id:a}}),t=(null===(e=s.data)||void 0===e?void 0:e.pipelines)||[];if(rL(t),t.length>0){let e=Y.get("pipeline"),a=localStorage.getItem("leads_selected_pipeline"),s=e&&t.some(a=>a.id===e),l=a&&t.some(e=>e.id===a),r=rR&&t.some(e=>e.id===rR);if(s)rM(e),localStorage.setItem("leads_selected_pipeline",e);else if(l)rM(a);else if(r);else{let e=t.find(e=>e.is_default)||t[0];ir(e.id)}}0===t.length&&(ae(!1),ek(),eG({pipeline:{},metrics:{total_leads:0,total_pipeline_value:0,average_lead_score:0,conversion_rate:0,average_sales_cycle:0,stage_conversion_rates:{}},forecasting:{this_month:0,this_quarter:0,this_year:0}}))}catch(e){console.error("Failed to fetch pipelines:",e),ae(!1),ek()}},id=(e,a,s)=>{lo(e),lh.current&&clearTimeout(lh.current);let t=void 0!==a?a:lg,l=void 0!==s?s:lj;if(!e.trim()&&!t&&!l){lu([]);return}lh.current=setTimeout(async()=>{lp(!0);try{var a;let s={workspace_id:null==H?void 0:H.workspace_id,pipeline_id:rR,limit:50};e.trim()&&(s.q=e),t&&(s.stage_id=t),l&&(s.assigned_to=l);let r=await C.api.get("/leads/search",{params:s});lu((null===(a=r.data)||void 0===a?void 0:a.leads)||r.data||[])}catch(e){console.error("Failed to search leads:",e),lu([])}finally{lp(!1)}},300)},ic=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,a=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=arguments.length>2?arguments[2]:void 0;if(!rR||!(null==H?void 0:H.workspace_id))return;let t=null!=s?s:lU;lR(!0);try{let s=[];(null==e$?void 0:e$.pipeline)&&Object.values(e$.pipeline).forEach(e=>{Array.isArray(e)&&s.push(...e)});let l=s;"all"!==t&&(l=s.filter(e=>{let a=e.ai_call_display_status||e.ai_first_call_status;return"pending"===t?!a||"pending"===a:"done"===t?"completed"===a||"connected"===a:"hangup"===t?"hangup"===a:"no_answer"===t?"no_answer"===a||"failed"===a||"busy"===a:"cancelled"!==t||"cancelled"===a}));let r=(e-1)*50,n=r+50,i=l.slice(r,n);a?lF(i):lF(e=>[...e,...i]),lE(n<l.length),lP(e)}catch(e){console.error("Failed to fetch leads for AI Call Handle:",e),y.default.error("Failed to load leads")}finally{lR(!1)}},io=async()=>{if(lS(!0),lz(new Set),lP(1),lq("all"),ic(1,!0),rR)try{var e,a,s;let t=await C.api.get("/lead-pipelines/".concat(rR,"/ai-calling-settings"),{params:{workspace_id:null==H?void 0:H.workspace_id}});lQ(null!==(s=null===(a=t.data)||void 0===a?void 0:null===(e=a.settings)||void 0===e?void 0:e.is_enabled)&&void 0!==s&&s)}catch(e){console.warn("Could not fetch AI calling settings:",e),lQ(!1)}},im=async e=>{var a,s,t;if(rR){lY(!0);try{let s=await C.api.get("/lead-pipelines/".concat(rR,"/ai-calling-settings"),{params:{workspace_id:null==H?void 0:H.workspace_id}}),t=(null===(a=s.data)||void 0===a?void 0:a.settings)||{};await C.api.put("/lead-pipelines/".concat(rR,"/ai-calling-settings?workspace_id=").concat(null==H?void 0:H.workspace_id),{...t,is_enabled:e,trigger_on_new_lead:e}),lQ(e),y.default.success(e?"AI Calling activated":"AI Calling deactivated")}catch(e){console.error("Failed to toggle AI calling:",e),y.default.error((null==e?void 0:null===(t=e.response)||void 0===t?void 0:null===(s=t.data)||void 0===s?void 0:s.detail)||"Failed to update AI calling status")}finally{lY(!1)}}},iu=e=>{lz(a=>
1{let s=new Set(a);return s.has(e)?s.delete(e):s.add(e),s})},ix=()=>{lz(new Set(lZ.map(e=>e.id)))},ip=()=>{lz(new Set)},ih=()=>{if(!(null==e$?void 0:e$.pipeline))return[];let e=[];return(Object.values(e$.pipeline).forEach(a=>{Array.isArray(a)&&e.push(...a)}),"all"===lU)?e:e.filter(e=>{let a=e.ai_call_display_status||e.ai_first_call_status;return"pending"===lU?!a||"pending"===a:"done"===lU?"completed"===a||"connected"===a:"hangup"===lU?"hangup"===a:"no_answer"===lU?"no_answer"===a||"failed"===a||"busy"===a:"cancelled"!==lU||"cancelled"===a})},ig=async()=>{var e,a,s,t,l;if(0===lA.size){y.default.error("Please select at least one lead");return}lO(!0);try{let t=null,l=null;if(rR)try{let a=await C.api.get("/lead-pipelines/".concat(rR,"/ai-calling-settings"),{params:{workspace_id:null==H?void 0:H.workspace_id}}),s=null===(e=a.data)||void 0===e?void 0:e.settings;s&&(t=(s.advanced_voice_settings||{}).voice_provider||null,l=s.voice_type||null)}catch(e){console.warn("Could not fetch pipeline AI settings, using defaults:",e)}let r=Array.from(lA),n=0,i=0,d=[];for(let e of r)try{let a=lZ.find(a=>a.id===e);if(!(null==a?void 0:a.phone)){i++,d.push("".concat((null==a?void 0:a.name)||e,"
1: No phone number"));continue}let s=a.phone.startsWith("+91")||a.phone.startsWith("91"),r="pipecat_sip"===t?"india":s?"india":"international";await C.api.post("/ai-calls/initiate",{lead_id:e,phone_number:a.phone,pipeline_id:rR,provider:t,voice_id:l,telephony:r},{params:{workspace_id:null==H?void 0:H.workspace_id}}),n++}catch(l){console.error("Failed to trigger AI call for lead ".concat(e,":"),l);let t=lZ.find(a=>a.id===e);d.push("".concat((null==t?void 0:t.name)||e,": ").concat((null===(s=l.response)||void 0===s?void 0:null===(a=s.data)||void 0===a?void 0:a.detail)||"Failed")),i++}n>0?y.default.success("AI calls triggered for ".concat(n," lead(s)").concat(i>0?", ".concat(i," failed"):"")):i>0&&y.default.error("Failed to trigger AI calls: ".concat(d.slice(0,2).join(", ")).concat(d.length>2?" and ".concat(d.length-2," more"):"")),setTimeout(()=>ic(1,!0),1e3),lz(new Set),setTimeout(()=>iM(),1500)}catch(e){console.error("Failed to trigger AI calls:",e),y.default.error((null===(l=e.response)||void 0===l?void 0:null===(t=l.data)||void 0===t?void 0:t.detail)||"Failed to trigger AI calls")}finally{lO(!1)}},ij=async()=>{if(!rR||!(null==H?void 0:H.workspace_id)){y.default.error("No pipeline selected");return}if(0===l$.length){(0,y.default)("No active or pending calls to terminate");return}lT(!0);try{let{pending_cancelled:e,active_terminated:a,total:s}=(await C.api.post("/ai-calls/end-all-calls",{workspace_id:H.workspace_id,pipeline_id:rR})).data;s>0?y.default.success("Cancelled ".concat(s," call(s) (").concat(a," active, ").concat(e," pending)")):(0,y.default)("No calls to cancel"),await ib(),setTimeout(()=>ic(1,!0,lU),500),setTimeout(()=>iM(),1e3),lz(new Set)}catch(s){var e,a;console.error("Failed to terminate AI calls:",s),y.default.error((null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to terminate AI calls")}finally{lT(!1)}},ib=async()=>{if(rR&&(null==H?void 0:H.workspace_id))try{var e;let a=await C.api.get("/ai-calls/queue/active",{params:{workspace_id:H.workspace_id,pipeline_id:rR}}),s=(null===(e=a.data)||void 0===e?void 0:e.entries)||[];lK(s)}catch(e){console.error("Failed to fetch active calls:",e)}};(0,l.useEffect)(()=>(lC&&rR&&(ib(),lH.current=setInterval(()=>{ib()},5e3)),()=>{lH.current&&(clearInterval(lH.current),lH.current=null)}),[lC,rR]);let iv=e=>{let a=e.ai_call_display_status||e.ai_first_call_status;return a&&"pending"!==a?"completed"===a||"connected"===a?{label:"Done",color:"bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400"}:"calling"===a||"ringing"===a||"in_progress"===a?{label:"In Progress",color:"bg-blue-100 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400"}:"hangup"===a?{label:"Hung Up",color:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"}:"no_answer"===a?{label:"No Answer",color:"bg-orange-100 text-orange-700 dark:bg-orange-900/30 dark:text-orange-400"}:"cancelled"===a?{label:"Cancelled",color:"bg-slate-100 text-slate-700 dark:bg-slate-800/30 dark:text-slate-400"}:{label:"Failed",color:"bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400"}:{label:"Pending",color:"bg-amber-100 text-amber-700 dark:bg-amber-900/30 dark:text-amber-400"}},iN=async()=>{try{let e=null==H?void 0:H.workspace_id;if(!e)return;let a=await (0,aP.Pz)(e,{activeOnly:!0});rJ(a)}catch(e){console.error("Failed to fetch branches:",e)}},iw=async()=>{if(!r1.trim()){y.default.error("Please enter a branch name");return}try{r6(!0);let e=null==H?void 0:H.workspace_id;if(!e)return;let a=r2.trim()||r1.trim().toUpperCase().replace(/\s+/g,"_").slice(0,10),s=await (0,aP.Qj)(e,{name:r1.trim(),code:a});rJ([...rG,s]),r$(s.id),r0(!1),r5(""),r4(""),y.default.success('Branch "'.concat(s.name,'" created!'))}catch(s){var e,a;console.error("Failed to create branch:",s),y.default.error((null==s?void 0:null===(a=s.response)||void 0===a?void 0:null===(e=a.data)||void 0===e?void 0:e.detail)||"Failed to create branch")}finally{r6(!1)}},i_=async()=>{if(rR&&(null==H?void 0:H.workspace_id))try{let e=await C.api.get("/leads/pipeline/".concat(rR,"/ai-calls-status"));nn(e.data.total_active||0)}catch(e){console.error("Failed to fetch AI calls status:",e)}},iy=async()=>
1{if(null==H?void 0:H.workspace_id)try{let e=await C.api.get("/ai-calls/active",{params:{workspace_id:H.workspace_id}});e.data.success&&nj(e.data.count||0)}catch(e){console.error("Failed to fetch workspace active calls:",e)}},ik=async()=>{if(!rR){y.default.error("Please select a pipeline first");return}ng(!0);try{var e;let a=[];if((null==e$?void 0:e$.pipeline)&&Object.values(e$.pipeline).forEach(e=>{e&&Array.isArray(e)&&a.push(...e)}),(null==e$?void 0:e$.stages)&&e$.stages.forEach(e=>{e.leads&&Array.isArray(e.leads)&&e.leads.forEach(e=>{a.some(a=>a.id===e.id)||a.push(e)})}),0===a.length){y.default.error("No leads to export"),ng(!1);return}let s=a.map(e=>({Name:e.name||"",Email:e.email||"",Phone:e.phone||"",Company:e.company||"",Stage:e.stage||"",Score:e.score||0,Quality:e.quality||"",Value:e.value||0,Source:e.source||"","Days in Stage":e.days_in_stage||0,"Last Call Outcome":e.last_call_outcome||"","Assigned To":e.assigned_to_name||"","AI Interest":e.ai_interest_category||""})),t=eW.P6.book_new(),l=eW.P6.json_to_sheet(s),r=Object.keys(s[0]||{}).map(e=>({wch:Math.min(30,Math.max(e.length,...s.map(a=>String(a[e]||"").length)))}));l["!cols"]=r,eW.P6.book_append_sheet(t,l,"Leads");let n=rE.find(e=>e.id===rR),i=(null==n?void 0:null===(e=n.name)||void 0===e?void 0:e.replace(/[^a-zA-Z0-9]/g,"_"))||"Pipeline",d=new Date().toISOString().split("T")[0],c="".concat(i,"_Leads_").concat(d,".xlsx");eW.NC(t,c),y.default.success("Exported ".concat(a.length," leads to Excel"))}catch(e){console.error("Failed to export leads:",e),y.default.error("Failed to export leads")}finally{ng(!1)}},iC=async()=>{if(rR){nV(!0);try{var e;let a=await C.api.get("/lead-pipelines/".concat(rR,"/columns?workspace_id=").concat(null==H?void 0:H.workspace_id));nL((null===(e=a.data)||void 0===e?void 0:e.columns)||[])}catch(e){console.error("Failed to fetch tag columns:",e),nL([])}finally{nV(!1)}}},iS=async e=>{if(rR){nW(!0),nB([]),nU(null);try{var a;let s=await C.api.get("/lead-pipelines/".concat(rR,"/column-values?workspace_id=").concat(null==H?void 0:H.workspace_id,"&column=").concat(encodeURIComponent(e)));nB((null===(a=s.data)||void 0===a?void 0:a.values)||[])}catch(e){console.error("Failed to fetch tag values:",e),nB([])}finally{nW(!1)}}},iZ=async()=>{if(nR&&nT&&rR){n0(!0);try{var e;let a=await C.api.get("/lead-pipelines/".concat(rR,"/contacts-by-tag?workspace_id=").concat(null==H?void 0:H.workspace_id,"&column=").concat(encodeURIComponent(nR),"&value=").concat(encodeURIComponent(nT))),s=(null===(e=a.data)||void 0===e?void 0:e.contacts)||[];nH(s),nJ(new Set(s.map(e=>e.id)));let t=rE.find(e=>e.id===rR);n$("".concat((null==t?void 0:t.name)||"Pipeline"," - ").concat(nR,": ").concat(nT))}catch(e){console.error("Failed to fetch tag contacts:",e),nH([]),nJ(new Set)}finally{n0(!1)}}},iF=async()=>
1{if(nR&&nT&&rR){if(0===nG.size){y.default.error("Please select at least one contact");return}if(!nY.trim()){y.default.error("Please enter a segment name");return}if("pipeline"===n1&&!n3.trim()){y.default.error("Please enter a pipeline name");return}ie(!0);try{var e,a;let s=await C.api.post("/lead-pipelines/".concat(rR,"/create-segment-from-tag?workspace_id=").concat(null==H?void 0:H.workspace_id),{column:nR,value:nT,segment_name:nY.trim(),contact_ids:Array.from(nG),create_pipeline:"pipeline"===n1,pipeline_type:"pipeline"===n1?n2:null,pipeline_name:"pipeline"===n1?n3.trim():null,pipeline_template:"pipeline"===n1?n8:null});if(!(null===(e=s.data)||void 0===e?void 0:e.success))throw Error((null===(a=s.data)||void 0===a?void 0:a.message)||"Failed to create segment");nA(!1),iA(),"pipeline"===n1&&s.data.pipeline_error?y.default.error("Segment created but pipeline failed: ".concat(s.data.pipeline_error)):"pipeline"===n1&&s.data.pipeline_id?y.default.success(s.data.message||"Created segment and pipeline"):"pipeline"===n1?(0,y.default)("Segment created but pipeline was not created",{icon:"⚠️"}):y.default.success('Created segment "'.concat(s.data.segment_name,'" with ').concat(s.data.added_count," contacts")),W.push("/dashboard/segments")}catch(e){console.error("Failed to create segment:",e),y.default.error((0,C.getErrorMessage)(e,"Failed to create segment"))}finally{ie(!1)}}},iA=()=>{nD(1),nM(null),nU(null),nB([]),n$(""),nH([]),nJ(new Set),n5("segment_only"),n4("lead"),n6(""),n9("sales")},iz=async e=>{2===e&&1===nP&&await iZ(),3===e&&2===nP&&n6("".concat(nY," Pipeline")),nD(e)},iI=async()=>{nA(!0),await iC()};(0,l.useEffect)(()=>{nR&&rR&&iS(nR)},[nR,rR]);let iP=async()=>{if(!rq.trim()){y.default.error("Please enter a pipeline name");return}r9(!0);try{var e,a;
1let s=null==H?void 0:H.workspace_id,t=await C.api.post("/lead-pipelines",{name:rq.trim().toUpperCase(),color:rQ,branch_id:rY||void 0,agent_group_ids:rK.length>0?rK:void 0},{params:{workspace_id:s}});y.default.success("Pipeline created"),rV(""),rW("#3B82F6"),r$(""),rH([]),await ii(),(null===(a=t.data)||void 0===a?void 0:null===(e=a.pipeline)||void 0===e?void 0:e.id)&&ir(t.data.pipeline.id)}catch(e){console.error("Failed to create pipeline:",e),y.default.error((0,C.getErrorMessage)(e,"Failed to create pipeline"))}finally{r9(!1)}},iD=async()=>{if(!rT||!rT.name.trim()){y.default.error("Please enter a pipeline name");return}r9(!0);try{let e=null==H?void 0:H.workspace_id;await C.api.put("/lead-pipelines/".concat(rT.id),{name:rT.name.trim().toUpperCase(),color:rT.color,agent_group_ids:rT.agent_group_ids||[],branch_id:rT.branch_id||null},{params:{workspace_id:e}}),y.default.success("Pipeline updated"),rU(null),await ii()}catch(e){console.error("Failed to update pipeline:",e),y.default.error((0,C.getErrorMessage)(e,"Failed to update pipeline"))}finally{r9(!1)}},iE=async(e,a)=>{r9(!0);try{var s;let t=null==H?void 0:H.workspace_id,l=await C.api.delete("/lead-pipelines/".concat(e),{params:{workspace_id:t,confirm:!1}});if(null===(s=l.data)||void 0===s?void 0:s.requires_confirmation){ne({open:!0,pipelineId:e,pipelineName:l.data.pipeline_name||a,leadsCount:l.data.leads_count||0,warning:l.data.warning||"This will permanently delete all leads in this pipeline."}),r9(!1);return}if(y.default.success("Pipeline deleted"),await ii(),rR===e){let a=rE.filter(a=>a.id!==e);if(a.length>0){let e=a.find(e=>e.is_default)||a[0];ir(e.id)}}}catch(e){console.error("Failed to delete pipeline:",e),y.default.error((0,C.getErrorMessage)(e,"Failed to delete pipeline"))}finally{r9(!1)}},iL=async()=>{if(r7.pipelineId){r9(!0);try{var e;let a=null==H?void 0:H.workspace_id,s=await C.api.delete("/lead-pipelines/".concat(r7.pipelineId),{params:{workspace_id:a,confirm:!0}});if(y.default.success("Pipeline deleted along with ".concat((null===(e=s.data)||void 0===e?void 0:e.leads_deleted)||r7.leadsCount," leads")),ne({open:!1,pipelineId:"",pipelineName:"",leadsCount:0,warning:""}),await ii(),rR===r7.pipelineId){let e=rE.filter(e=>e.id!==r7.pipelineId);if(e.length>0){let a=e.find(e=>e.is_default)||e[0];ir(a.id)}}}catch(e){console.error("Failed to delete pipeline:",e),y.default.error((0,C.getErrorMessage)(e,"Failed to delete pipeline"))}finally{r9(!1)}}},iR=async(e,a)=>{if(rR&&!na[e]){ns(a=>({...a,[e]:!0}));try{var s;let t=(null==e$?void 0:e$.pipeline[a])||[],l=t.length,r=await C.api.get("/lead-pipelines/".concat(rR,"/stages/").concat(e,"/entries"),{params:{workspace_id:null==H?void 0:H.workspace_id,offset:l,limit:100}}),n=(null===(s=r.data.entries)||void 0===s?void 0:s.map(e=>({id:e.lead.id,name:e.lead.name,email:e.lead.email,phone:e.lead.phone,company:e.lead.company,source:e.lead.source,score:e.lead.score,pipeline_entry_id:e.id,stage:a,stage_id:e.stage_id,deal_value:e.deal_value,added_at:e.added_at,assigned_to:e.assigned_to||e.lead.assigned_to,assigned_to_name:e.assigned_to_name||e.lead.assigned_to_name,ai_first_call_status:e.lead.ai_first_call_status,ai_first_call_id:e.lead.ai_first_call_id,ai_first_call_at:e.lead.ai_first_call_at,ai_first_call_attempts:e.lead.ai_first_call_attempts||0,ai_interest_score:e.lead.ai_interest_score,ai_interest_category:e.lead.ai_interest_category,ai_call_summary:e.lead.ai_call_summary,meta_data:e.lead.meta_data,metadata:e.lead.metadata,custom_fields:e.lead.custom_fields||e.lead.meta_data||e.lead.metadata})))||[];eG(e=>e?{...e,pipeline:{...e.pipeline,[a]:[...t,...n]}}:e),sl(a=>a.map(a=>a.id===e?(t.length,n.length,{...a,has_more:r.data.has_more,leads:[...a.leads||[],...n]}):a)),y.default.success("Loaded ".concat(n.length," more leads"))}catch(e){console.error("Failed to load more entries:",e),y.default.error("Failed to load more leads")}finally{ns(a=>({...a,[e]:!1}))}}},iM=async function(){var e,a;let s=arguments.length>0&&void 0!==arguments[0]?arguments[0]:rf,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:rb,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:rx,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:rR,n=arguments.length>4?arguments[4]:void 0;try{let a=null==H?void 0:H.workspace_id;if(r){let s=(await C.api.get("/lead-pipelines/".concat(r,"/board"),{params:{workspace_id:a},timeout:6e4,signal:n})).data,t=(null===(e=s.board)||void 0===e?void 0:e.map(e=>{var a;return{id:e.stage.id,name:e.stage.name,slug:e.stage.slug,color:e.stage.color,position:e.stage.position,is_entry_point:e.stage.is_entry_point,is_completed_point:e.stage.is_completed_point,is_dropped_point:e.stage.is_dropped_point,is_qualification_point:e.stage.is_qualification_point,is_dnd_point:e.stage.is_dnd_point,total_count:e.total_count||0,has_more:e.has_more||!1,leads:(null===(a=e.entries)||void 0===a?void 0:a.map(a=>({id:a.lead.id,name:a.lead.name,email:a.lead.email,phone:a.lead.phone,company:a.lead.company,source:a.lead.source,score:a.lead.score,pipeline_entry_id:a.id,stage:e.stage.name,stage_id:a.stage_id,deal_value:a.deal_value,added_at:a.added_at,assigned_to:a.assigned_to||a.lead.assigned_to,assigned_to_name:a.assigned_to_name||a.lead.assigned_to_name,ai_first_call_status:a.lead.ai_first_call_status,ai_first_call_id:a.lead.ai_first_call_id,ai_first_call_at:a.lead.ai_first_call_at,ai_first_call_attempts:a.lead.ai_first_call_attempts||0,ai_interest_score:a.lead.ai_interest_score,ai_interest_category:a.lead.ai_interest_category,ai_call_summary:a.lead.ai_call_summary,meta_data:a.lead.meta_data,metadata:a.lead.metadata,custom_fields:a.lead.custom_fields||a.lead.meta_data||a.lead.metadata,in_crm_via_complementary:a.lead.in_crm_via_complementary||!1,complementary_crm_names:a.lead.complementary_crm_names||[]})))||[]}}))||[],l={};
1t.forEach(e=>{l[e.name]=e.leads||[]}),sl(t),so(!0),eG({pipeline:l,metrics:{total_leads:s.total_active||0,total_pipeline_value:0,average_lead_score:0,conversion_rate:0,average_sales_cycle:0,stage_conversion_rates:{}},forecasting:{this_month:0,this_quarter:0,this_year:0}});return}let i={workspace_id:a};s&&(i.active_campaigns_only=!0),t&&(i.campaign_id=t),l&&(i.ad_account_id=l);let d=(await C.api.get("/leads/pipeline",{params:i})).data;eG(d),d.stages&&d.stages.length>0&&(sl(d.stages),so(!0))}catch(t){if((null==t?void 0:t.name)==="CanceledError"||(null==t?void 0:t.code)==="ERR_CANCELED"||(null==t?void 0:null===(a=t.message)||void 0===a?void 0:a.includes("canceled"))){console.log("Pipeline fetch canceled (expected on pipeline switch)");return}console.error("Failed to fetch pipeline:",t),y.default.error("Failed to load pipeline data");let e=[{id:"1",name:"New Leads",slug:"new_lead",color:"#3B82F6",position:0,is_fixed:!0,is_entry_point:!0},{id:"2",name:"Initial Contact",slug:"initial_contact",color:"#8B5CF6",position:1,is_fixed:!1},{id:"3",name:"Qualified",slug:"qualified",color:"#14B8A6",position:2,is_fixed:!1,is_qualification_point:!0},{id:"4",name:"Proposal",slug:"proposal",color:"#EC4899",position:3,is_fixed:!1},{id:"5",name:"Negotiation",slug:"negotiation",color:"#F59E0B",position:4,is_fixed:!1},{id:"6",name:"Closed Won",slug:"closed_won",color:"#10B981",position:5,is_fixed:!0,is_won_point:!0},{id:"7",name:"Closed Lost",slug:"closed_lost",color:"#EF4444",position:6,is_fixed:!0,is_lost_point:!0},{id:"8",name:"Do Not Disturb",slug:"dnd",color:"#6B7280",position:7,is_fixed:!0,is_dnd_point:!0}];sl(e);let s={};e.forEach(e=>{s[e.name]=[]}),eG({pipeline:s,metrics:{total_leads:0,total_pipeline_value:0,average_lead_score:0,conversion_rate:0,average_sales_cycle:0,stage_conversion_rates:{}},forecasting:{this_month:0,this_quarter:0,this_year:0}})}finally{ae(!1),ek()}},iO=async()=>{try{ro(!0);let e=null==H?void 0:H.workspace_id;if(!e)return;let a=new Date,s=new Date(a.getFullYear(),a.getMonth(),1),t=new Date(a.getFullYear(),a.getMonth()+1,0,23,59,59),l=await C.api.get("/leads-payment/summary",{params:{workspace_id:e,start_date:s.toISOString(),end_date:t.toISOString()}}),r=await C.api.get("/leads-payment",{params:{workspace_id:e,payment_status:"pending",start_date:s.toISOString(),end_date:t.toISOString(),page_size:1}}),n=await C.api.get("/leads-payment",{params:{workspace_id:e,payment_status:"completed",start_date:s.toISOString(),end_date:t.toISOString(),page_size:1}});rd({total_amount:l.data.total_amount||0,completed_amount:l.data.completed_amount||0,pending_amount:l.data.pending_amount||0,payment_count:l.data.payment_count||0,completed_count:n.data.total||0,pending_count:r.data.total||0})}catch(e){console.error("Failed to fetch revenue summary:",e)}finally{ro(!1)}},iB=e=>{switch(e){case"hot":return"bg-red-500";case"warm":return"bg-orange-500";case"cool":return"bg-blue-500";default:return"bg-gray-500"}},iT=(e,a)=>{switch(a||e.toLowerCase().replace(/\s+/g,"_")){case"new_lead":case"new_leads":return(0,t.jsx)(_.Z,{className:"h-4 w-4"});case"initial_contact":case"contacted":return(0,t.jsx)(R.Z,{className:"h-4 w-4"});case"qualified":return(0,t.jsx)(T.Z,{className:"h-4 w-4"});case"proposal":return(0,t.jsx)(M.Z,{className:"h-4 w-4"});case"negotiation":return(0,t.jsx)(B.Z,{className:"h-4 w-4"});case"closed_won":return(0,t.jsx)(O.Z,{className:"h-4 w-4"});case"closed_lost":return(0,t.jsx)(U.Z,{className:"h-4 w-4"});case"dnd":case"do_not_disturb":return(0,t.jsx)(q.Z,{className:"h-4 w-4"});default:return(0,t.jsx)(ew.Z,{className:"h-4 w-4"})}},iU=(0,l.useMemo)(()=>st.length>0?[...st].sort((e,a)=>e.position-a.position):Object.keys((null==e$?void 0:e$.pipeline)||{}).map((e,a)=>({id:"fallback-".concat(a),name:e,slug:e.toLowerCase().replace(/\s+/g,"_"),color:"#6B7280",position:a,is_fixed:!1,is_entry_point:0===a,is_won_point:e.toLowerCase().includes("won"),is_lost_point:e.toLowerCase().includes("lost"),is_qualification_point:e.toLowerCase().includes("qualified")})),[st,null==e$?void 0:e$.pipeline]),iq=async e=>{e5(e),e6(null),sI("timeline"),sM(new Date);try{let a=await C.api.get("/leads/".concat(e.id,"/insights"));console.log("Lead insights:",a.data)}catch(e){console.error("Failed to fetch lead insights:",e)}try{var a;let s=await C.api.get("/leads/".concat(e.id,"/quality"));(null===(a=s.data)||void 0===a?void 0:a.quality)&&e6(s.data.quality)}catch(e){console.error("Failed to fetch lead quality:",e)}i5(e.id)},iV=async()=>{rI(!0);try{var e;let a=(null==H?void 0:H.workspace_id)||localStorage.getItem("workspace_id");if(!a)return;let s=await C.api.get("/crm/pipelines?workspace_id=".concat(a,"&include_stages=true"));rZ((null===(e=s.data)||void 0===e?void 0:e.pipelines)||[])}catch(e){console.error("Failed to fetch CRM pipelines:",e),rZ([])}finally{rI(!1)}},iQ=e=>{rC(e),rA(null),ry(!0),iV()},iW=async()=>{var e,a,s,t;if(!rk||!rF){y.default.error("Please select a pipeline");return}if(console.log("[Add to CRM] Lead:",rk.id,rk.name),console.log("[Add to CRM] Selected Pipeline ID:",rF),!rS.find(e=>e.id===rF)){y.default.error("Invalid pipeline selected");return}rD(!0);try{let t=(null==H?void 0:H.workspace_id)||localStorage.getItem("workspace_id"),l={lead_id:rk.id,pipeline_ids:[rF],remove_from_leads:!0};console.log("[Add to CRM] Sending payload:",l);let r=await C.api.post("/crm/pipelines/contacts/add?workspace_id=".concat(t),l);if(console.log("[Add to CRM] Response:",r.data),null===(e=r.data)||void 0===e?void 0:e.success){let e=(null===(a=r.data)||void 0===a?void 0:a.added_to)||[],t=(null===(s=r.data)||void 0===s?void 0:s.already_in)||[];e.length>0&&(y.default.success("Lead moved to CRM: ".concat(e.join(", "))),iM()),t.length>0&&(0,y.default)("Already in: ".concat(t.join(", ")),{icon:"ℹ️",duration:3e3}),ry(!1),rC(null),rA(null)}else y.default.error("Failed to add lead to pipeline")}catch(e){console.error("[Add to CRM] Error:",e),console.error("[Add to CRM] Error response:",null===(t=e.response)||void 0===t?void 0:t.data),y.default.error((0,C.getErrorMessage)(e,"Failed to add lead to CRM"))}finally{rD(!1)}},iY=e=>{rA(e)},i$=e=>{ny(e),nC(""),nw(!0)},iK=async()=>
1{if(!n_||!nk){y.default.error("Please select a pipeline");return}let e=n_.pipeline_entry_id;if(!e){y.default.error("Cannot find pipeline entry for this lead");return}nZ(!0);try{let a=(null==H?void 0:H.workspace_id)||localStorage.getItem("workspace_id");await C.api.put("/lead-pipelines/entries/".concat(e,"/reassign?workspace_id=").concat(a),{target_pipeline_id:nk});let s=rE.find(e=>e.id===nk);y.default.success("Lead reassigned to ".concat((null==s?void 0:s.name)||"pipeline")),nw(!1),ny(null),nC(""),iM(rf,rb,rx,rR)}catch(e){console.error("Failed to reassign lead:",e),y.default.error((0,C.getErrorMessage)(e,"Failed to reassign lead"))}finally{nZ(!1)}},iH=async(e,a)=>{if(!(null==e$?void 0:e$.pipeline))return;let s=null,t=null;for(let[a,l]of Object.entries(e$.pipeline)){let r=l.find(a=>a.id===e);if(r){s=r,t=a;break}}if(!s||!t||t===a){aV(null);return}let l={...e$.pipeline},r={...e$.pipeline};r[t]=r[t].filter(a=>a.id!==e),r[a]=[...r[a],{...s,stage:a}],eG({...e$,pipeline:r}),aV(null);try{await C.api.post("/leads/".concat(e,"/move"),{new_stage:a,pipeline_id:rR||void 0}),y.default.success("Lead moved to ".concat(a)),iM()}catch(a){var n,i;console.error("Failed to move lead:",a);let e=(null==a?void 0:null===(i=a.response)||void 0===i?void 0:null===(n=i.data)||void 0===n?void 0:n.detail)||(null==a?void 0:a.message)||"Failed to move lead";throw y.default.error(e),eG({...e$,pipeline:l}),a}},iG=(e,a)=>{a5({id:e,name:a}),a0(!0)},iJ=async()=>{if(a1){a4(!0);try{await C.api.delete("/leads/".concat(a1.id)),y.default.success("Lead deleted successfully"),a0(!1),a5(null),await iM()}catch(e){console.error("Failed to delete lead:",e),y.default.error((0,C.getErrorMessage)(e,"Failed to delete lead"))}finally{a4(!1)}}},iX=async()=>{if(0===a8.size)return;ss(!0);let e=0,a=0;for(let s of a8)try{await C.api.delete("/leads/".concat(s)),e++}catch(e){console.error("Failed to delete lead ".concat(s,":"),e),a++}e>0&&y.default.success("Successfully deleted ".concat(e," lead").concat(e>1?"s":"")),a>0&&y.default.error("Failed to delete ".concat(a," lead").concat(a>1?"s":"")),a9(new Set),se(!1),ss(!1),await iM()},i0=async e=>{ag(!1),await iM()},i1=async e=>{try{if(e&&e.length>0){let a=[],s=new Set;for(let t of e)try{let e=await C.api.get("/agent-groups/".concat(t,"/members"));if(console.log("Agent group ".concat(t," members response:"),e.data),e.data&&Array.isArray(e.data))for(let t of e.data)s.has(t.user_id)||(s.add(t.user_id),a.push({id:t.user_id,name:t.user_name||"Unknown",email:t.user_email||"",role:"sales_agent"}))}catch(e){console.error("Failed to fetch members for group ".concat(t,":"),e)}let t=a.filter(e=>"Unknown"!==e.name);console.log("Mapped agents from all groups:",t),sw(t);return}let a=await C.api.get("/users",{params:{enterprise_role:"agent"}});if(console.log("Users API response:",a.data),a.data&&Array.isArray(a.data)){let e=a.data.map(e=>({id:e.id,name:e.full_name||"Unknown",email:e.email||"",role:"sales_agent"})).filter(e=>"Unknown"!==e.name);console.log("Mapped agents from users:",e),sw(e)}else sw([])}catch(e){console.error("Failed to fetch team members:",e),sw([])}};(0,l.useEffect)(()=>{if(rR){let e=rE.find(e=>e.id===rR);(null==e?void 0:e.agent_group_ids)&&i1(e.agent_group_ids)}},[rR,rE]);let i5=async e=>{if(e){sL(!0);try{var a;
1let s=null==H?void 0:H.workspace_id,t=await C.api.get("/follow-ups/lead/".concat(e),{params:{workspace_id:s,include_completed:!0}});sD((null===(a=t.data)||void 0===a?void 0:a.tasks)||[])}catch(e){console.error("Failed to fetch lead calendar tasks:",e),sD([])}finally{sL(!1)}}},i2=(e,a)=>{a.stopPropagation(),sp(e),su(!0);let s=rE.find(e=>e.id===rR);console.log("=== ASSIGN CLICK DEBUG ==="),console.log("Selected pipeline ID:",rR),console.log("Selected pipeline:",s),console.log("Pipeline agent_group_ids:",null==s?void 0:s.agent_group_ids),console.log("All pipelines:",rE.map(e=>({id:e.id,name:e.name,agent_group_ids:e.agent_group_ids}))),i1(null==s?void 0:s.agent_group_ids)},i4=async(e,a)=>{if(!sx)return;let s=sx.pipeline_entry_id;if(!s){y.default.error("Cannot find pipeline entry for this lead");return}try{sA(!0);let t=(null==H?void 0:H.workspace_id)||localStorage.getItem("workspace_id");await C.api.put("/lead-pipelines/entries/".concat(s,"?workspace_id=").concat(t),{assigned_to:e}),y.default.success("Lead assigned to ".concat(a)),su(!1),sp(null),await iM()}catch(e){var t;console.error("Failed to assign lead:",e),(null===(t=e.response)||void 0===t?void 0:t.status)===403?y.default.error("You do not have permission to assign leads"):y.default.error("Failed to assign lead")}finally{sA(!1)}},i3=(e,a)=>{a.stopPropagation(),s4(e),s6("First Call"),s9(new Date().toISOString().split("T")[0]),te("high"),ts(""),tn("schedule"),td(""),to(""),tu(0),tp(""),tg(""),s5(!0)},i6=async()=>{if(s2&&s3.trim()&&s8){if("complete"===tr&&!ti){y.default.error("Please select a call outcome");return}tl(!0);try{let t=null==H?void 0:H.workspace_id;if("schedule"===tr)await C.api.post("/follow-ups",{title:s3,task_type:"call",due_date:new Date(s8).toISOString(),priority:"medium"===s7?"normal":s7,lead_id:s2.id,contact_name:s2.name,contact_phone:s2.phone,contact_email:s2.email,company_name:s2.company,notes:ta},{params:{workspace_id:t}}),y.default.success("First Call task scheduled successfully");else{var e,a,s;let l=await C.api.post("/follow-ups",{title:s3,task_type:"call",due_date:new Date(s8).toISOString(),priority:s7,lead_id:s2.id,contact_name:s2.name,contact_phone:s2.phone,contact_email:s2.email,company_name:s2.company,notes:ta},{params:{workspace_id:t}}),r=(null===(a=l.data)||void 0===a?void 0:null===(e=a.task)||void 0===e?void 0:e.id)||(null===(s=l.data)||void 0===s?void 0:s.id);if(r){if(await C.api.post("/follow-ups/".concat(r,"/complete"),{outcome:ti,outcome_reason:tc||void 0,completion_notes:ta,call_outcome:"connected",call_duration_seconds:tm||void 0,next_action_type:tx?"call":void 0,next_action_date:tx?new Date(tx).toISOString():void 0,next_action_notes:th||void 0},{params:{workspace_id:t}}),y.default.success("First Call completed and follow-up scheduled!"),"New Lead"===s2.stage)try{await C.api.post("/leads/".concat(s2.id,"/move"),{new_stage:"Contacted"})}catch(e){console.warn("Could not auto-move lead to Contacted:",e)}}else throw Error("Failed to get task ID")}s5(!1),s4(null),s6("First Call"),s9(""),te("high"),ts(""),tn("schedule"),td(""),to(""),tu(0),tp(""),tg(""),await iM()}catch(e){console.error("Failed to process First Call task:",e),y.default.error("Failed to process First Call task")}finally{tl(!1)}}},i8=(e,a)=>{a.stopPropagation(),e.phone&&(tJ(e),"smartflo"===t2?t5(!0):t0(!0))},i9=e=>{console.log("[Call] Call ended, duration:",e),t0(!1),tG&&(tv(tG),tw("ended"),tC(e),tH(e>0),tL(""),tM(""),tB(""),tU(""),tV(""),tj(!0))},i7=async(e,a)=>{var s,t,l,r;if(a.stopPropagation(),console.log("[AI Call] Initiating call for lead:",e.name,e.id),!e.phone){y.default.error("Lead has no phone number");return}try{let a=(null==H?void 0:H.workspace_id)||"default";console.log("[AI Call] Calling API with workspace:",a,"pipeline:",rR);let l=await C.api.post("/ai-calls/initiate?workspace_id=".concat(a),{lead_id:e.id,pipeline_id:rR});if(console.log("[AI Call] Response:",l.data),null===(s=l.data)||void 0===s?void 0:s.success){y.default.success("AI calling ".concat(e.name,"..."));let a=l.data.call_id||l.data.job_id;if(console.log("[AI Call] SUCCESS! call_id:",a,"provider:",l.data.provider,"status_url:",l.data.status_url),e$){console.log("[AI Call] Updating pipelineData for lead:",e.i
1d);let s={...e$.pipeline};for(let t in s)s[t]=s[t].map(s=>s.id===e.id?(console.log("[AI Call] Found lead, updating status to in_progress, call_id:",a),{...s,ai_first_call_status:"in_progress",ai_first_call_id:a}):s);eG({...e$,pipeline:s}),console.log("[AI Call] pipelineData updated")}else console.log("[AI Call] WARNING: pipelineData is null/undefined!")}else y.default.error((null===(t=l.data)||void 0===t?void 0:t.error)||"Failed to initiate AI call")}catch(e){console.error("Failed to initiate AI call:",e),y.default.error((null==e?void 0:null===(r=e.response)||void 0===r?void 0:null===(l=r.data)||void 0===l?void 0:l.detail)||(null==e?void 0:e.message)||"Failed to initiate AI call")}},de=async()=>{if(tw("connected"),tH(!0),tI.current=new Date,tz.current=setInterval(()=>{tC(e=>e+1)},1e3),t_)try{let e=null==H?void 0:H.workspace_id;await C.api.post("/calls/".concat(t_,"/connect"),{connected_at:new Date().toISOString()},{params:{workspace_id:e}})}catch(e){console.error("Error marking call connected:",e)}},da=()=>{tP.current&&(clearTimeout(tP.current),tP.current=null),tz.current&&(clearInterval(tz.current),tz.current=null)},ds=async()=>{if(da(),t_)try{let e=null==H?void 0:H.workspace_id;await C.api.post("/calls/".concat(t_,"/hangup"),{voice_call_id:tF},{params:{workspace_id:e}})}catch(e){console.error("Hangup API error:",e)}tw("ended")},dt=()=>{da(),tj(!1),tv(null),tw("calling"),tC(0),ty(null),tA(null),t$(""),tI.current=null},dl=async()=>{if(!tb||!tE){y.default.error("Please select a call outcome");return}tW(!0);try{var e,a,s;let t=null==H?void 0:H.workspace_id;t_&&await C.api.put("/calls/".concat(t_),{disposition:tK?"connected":"no_answer",outcome:tE,outcome_reason:tR||void 0,notes:tO||void 0},{params:{workspace_id:t}});let l=await C.api.post("/follow-ups",{title:"Call",task_type:"call",due_date:new Date().toISOString(),priority:"high",lead_id:tb.id,contact_name:tb.name,contact_phone:tb.phone,contact_email:tb.email,company_name:tb.company,notes:tO},{params:{workspace_id:t}}),r=(null===(a=l.data)||void 0===a?void 0:null===(e=a.task)||void 0===e?void 0:e.id)||(null===(s=l.data)||void 0===s?void 0:s.id);r&&await C.api.post("/follow-ups/".concat(r,"/complete"),{outcome:tE,outcome_reason:tR||void 0,completion_notes:tO,call_outcome:"connected",call_duration_seconds:tk||void 0,next_action_type:tT?"call":void 0,next_action_date:tT?new Date(tT).toISOString():void 0,next_action_notes:tq||void 0},{params:{workspace_id:t}});let n=tY||("New Lead"===tb.stage?"Contacted":"");if(n&&n!==tb.stage)try{await C.api.post("/leads/".concat(tb.id,"/move"),{new_stage:n})}catch(e){console.warn("Could not move lead to new stage:",e)}y.default.success("Call logged successfully"),dt(),await iM()}catch(e){console.error("Failed to save call outcome:",e),y.default.error("Failed to save call outcome")}finally{tW(!1)}},dr=e=>{let a=Math.floor(e/60).toString().padStart(2,"0"),s=(e%60).toString().padStart(2,"0");return"".concat(a,":").concat(s)};return e7?(0,t.jsx)("div",{className:"flex items-center justify-center min-h-[60vh]",children:(0,t.jsx)(aR.LoadingScreen,{fullScreen:!1,size:"lg",message:"Loading Leads...",variant:"logo"})}):(0,t.jsx)("div",{className:"min-h-full",children:(0,t.jsxs)("div",{className:"p-3 sm:p-4 md:p-6 2xl:p-8 3xl:p-10 space-y-3 sm:space-y-4 2xl:space-y-5 w-full max-w-full 3xl:max-w-[2200px] 3xl:mx-auto",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-xl bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center shadow-md",children:(0,t.jsx)(M.Z,{className:"h-5 w-5 text-white"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{className:"text-xl sm:text-2xl font-bold text-foreground",children:"Leads Pipeline"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Track and manage your leads through the sales funnel"})]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3",children:[(0,t.jsxs)(d.z,{size:"sm",onClick:io,className:"gap-2 rounded-md transition-all px-3 sm:px-4 shadow-sm bg-gradient-to-r from-purple-500 to-violet-600 hover:from-purple-600 hover:to-violet-700 text-white",style:{height:"32px"},children:[(0,t.jsx)(R.Z,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}),(0,t.jsx)("span",{className:"hidden sm:inline text-xs sm:text-sm",children:"AI Call Handle"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1 p-0.5 bg-slate-100 dar
1k:bg-slate-800 rounded-md",children:[(0,t.jsxs)(d.z,{variant:"pipeline"===lG?"default":"ghost",size:"sm",onClick:()=>lJ("pipeline"),className:"gap-2 rounded-md transition-all px-3 sm:px-4 ".concat("pipeline"===lG?"shadow-sm":"hover:bg-slate-200 dark:hover:bg-slate-700"),style:{height:"32px"},children:[(0,t.jsx)(aj.Z,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}),(0,t.jsx)("span",{className:"hidden sm:inline text-xs sm:text-sm",children:"Pipeline"})]}),(0,t.jsxs)(d.z,{variant:"analytics"===lG?"default":"ghost",size:"sm",onClick:()=>lJ("analytics"),className:"gap-2 rounded-md transition-all px-3 sm:px-4 ".concat("analytics"===lG?"shadow-sm bg-gradient-to-r from-emerald-500 to-green-600 text-white":"hover:bg-slate-200 dark:hover:bg-slate-700"),style:{height:"32px"},children:[(0,t.jsx)(e4.Z,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}),(0,t.jsx)("span",{className:"hidden sm:inline text-xs sm:text-sm",children:"AI Analytics"})]}),(0,t.jsxs)(d.z,{variant:"settings"===lG?"default":"ghost",size:"sm",onClick:()=>lJ("settings"),className:"gap-2 rounded-md transition-all px-3 sm:px-4 ".concat("settings"===lG?"shadow-sm":"hover:bg-slate-200 dark:hover:bg-slate-700"),style:{height:"32px"},children:[(0,t.jsx)(V.Z,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"}),(0,t.jsx)("span",{className:"hidden sm:inline text-xs sm:text-sm",children:"Settings"})]})]}),(0,t.jsx)(ao.$,{href:"/dashboard/leads/insights"})]})]}),"pipeline"===lG?(0,t.jsxs)(t.Fragment,{children:[!1,ni?(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 px-1",children:[(0,t.jsxs)(d.z,{variant:"ghost",size:"sm",onClick:()=>nd(!1),className:"gap-2 h-9 px-3 rounded-xl hover:bg-slate-100 dark:hover:bg-slate-800 transition-colors",children:[(0,t.jsx)(eH.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"font-medium",children:"Back to Pipeline"})]}),nf>0&&(0,t.jsxs)("span",{className:"px-3 py-1 rounded-full text-xs font-semibold bg-gradient-to-r from-purple-100 to-violet-100 text-purple-700 dark:from-purple-900/40 dark:to-violet-900/40 dark:text-purple-300 flex items-center gap-1.5",children:[(0,t.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,t.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-purple-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-2 w-2 bg-purple-500"})]}),nf," Live Calls"]})]}),(0,t.jsx)(as,{workspaceId:null==H?void 0:H.workspace_id})]}):(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 bg-gradient-to-r from-slate-50 via-white to-slate-50 dark:from-slate-900/50 dark:via-slate-800/30 dark:to-slate-900/50 rounded-[6px] border border-slate-200/60 dark:border-slate-700/40 shadow-sm",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-[3px] bg-gradient-to-br from-green-500 to-emerald-600 flex items-center justify-center shadow-md",children:(0,t.jsx)(aj.Z,{className:"h-4 w-4 text-white"})}),(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)("div",{children:(0,t.jsxs)(o.Ph,{value:rR||"",onValueChange:e=>ir(e),children:[(0,t.jsx)(o.i4,{className:"w-[200px] h-9 text-xs rounded-[3px] border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 shadow-sm hover:shadow-md transition-shadow overflow-hidden",children:(0,t.jsx)(o.ki,{placeholder:"Select pipeline",className:"truncate"})}),(0,t.jsx)(o.Bw,{className:"rounded-lg",children:rE.map(e=>(0,t.jsx)(o.Ql,{value:e.id,className:"rounded-md",children:(0,t.jsxs)("div",{className:"flex items-center gap-2 max-w-[160px]",children:[(0,t.jsx)("div",{className:"w-2.5 h-2.5 rounded-full shadow-sm shrink-0",style:{backgroundColor:e.color}}),(0,t.jsx)("span",{className:"font-medium truncate",children:e.name}),e.is_default&&(0,t.jsx)("span",{className:"text-[9px] text-muted-foreground bg-muted px-1.5 py-0.5 rounded-full shrink-0",children:"Default"})]})},e.id))})]})})}),(0,t.jsx)(f._v,{side:"bottom",className:"max-w-[300px]",children:(0,t.jsx)("p",{className:"font-medium",children:(null===(a=rE.find(e=>e.id===rR))||void 0===a?void 0:a.name)||"Select pipeline"})})]})}),eC.isSuperAdmin&&(0,t.jsx)(d.z,{variant:"outline",size:"sm",className:"h-9 w-9 p-0 rounded-[3px] bg-white dark:bg-slate-900 border-slate-400 dark:border-slate-500 hover:bg-slate-50 dark:hover:bg-slate-800 hover:border-slate-500",onClick:()=>rB(!0),title:"Manage Pipelines",children:(0,t.jsx)(N.Z,{className:"h-4 w-4 text-slate-700 dark:text-slate-300"})})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>ld(!0),className:"h-9 w-9 p-0 rounded-md bg-gradient-to-b from-white to-slate-50 dark:from-slate-800 dark:to-slate-900 border border-slate-200 dark:border-slate-600 shadow-sm hover:shadow hover:border-emerald-300 dark:hover:border-emerald-600 hover:from-emerald-50 hover:to-white dark:hover:from-emerald-950/30 dark:hover:to-slate-800 transition-all duration-200",title:"Search leads",children:(0,t.jsx)(av.Z,{className:"h-4 w-4 text-slate-500 dark:text-slate-400"})}),(0,t.jsx)("div",{className:"h-5 w-px bg-slate-200 dark:bg-slate-700"}),(0,t.jsxs)(h.h_,{children:[(0,t.jsx)(h.$F,{asChild:!0,children:(0,t.jsxs)(d.z,{variant:"outline",size:"sm",className:"h-9 px-3.5 gap-2 rounded-md bg-gradient-to-b from-white to-slate-50 dark:from-slate-800 dark:to-slate-900 border border-slate-200 dark:border-slate-600 shadow-sm hover:shadow hover:border-emerald-300 dark:hover:border-emerald-600 hover:from-emerald-50 hover:to-white dark:hover:from-emerald-950/30 dark:hover:to-slate-800 transition-all duration-200",title:"Add options",children:[(0,t.jsx)(N.Z,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-400"}),(0,t.jsx)("span",{className:"text-xs font-medium text-slate-600 dar
1k:text-slate-300",children:"Add"})]})}),(0,t.jsxs)(h.AW,{align:"end",className:"w-48",children:[(0,t.jsxs)(h.Xi,{onClick:()=>rE.length>0&&ag(!ap),disabled:0===rE.length,className:"cursor-pointer",children:[(0,t.jsx)(_.Z,{className:"h-4 w-4 mr-2 text-emerald-500"}),"Add Lead"]}),(0,t.jsxs)(h.Xi,{onClick:()=>{if(!rR){y.default.error("Please select a pipeline first");return}aM(!0)},disabled:!rR,className:"cursor-pointer",children:[(0,t.jsx)(aI.LkT,{className:"h-4 w-4 mr-2 text-amber-500"}),(0,t.jsx)("span",{className:"font-semibold",children:"Instant Import"})]})]})]}),(eC.isAdmin||eC.isSuperAdmin)&&(0,t.jsxs)(h.h_,{children:[(0,t.jsx)(h.$F,{asChild:!0,children:(0,t.jsxs)(d.z,{variant:"outline",size:"sm",className:"h-9 px-3.5 gap-2 rounded-md bg-gradient-to-b from-white to-slate-50 dark:from-slate-800 dark:to-slate-900 border border-slate-200 dark:border-slate-600 shadow-sm hover:shadow hover:border-emerald-300 dark:hover:border-emerald-600 hover:from-emerald-50 hover:to-white dark:hover:from-emerald-950/30 dark:hover:to-slate-800 transition-all duration-200",title:"More actions",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-slate-600 dark:text-slate-300",children:"More"}),(0,t.jsx)(aw.Z,{className:"h-4 w-4 text-slate-400 dark:text-slate-500"})]})}),(0,t.jsxs)(h.AW,{align:"end",className:"w-48",children:[(0,t.jsxs)(h.Xi,{onClick:()=>W.push("/dashboard/contacts?tab=import"),className:"cursor-pointer",children:[(0,t.jsx)(eK.Z,{className:"h-4 w-4 mr-2 text-purple-500"}),"Import"]}),(0,t.jsxs)(h.Xi,{onClick:ik,disabled:nh||!rR,className:"cursor-pointer",children:[nh?(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 text-blue-500 animate-spin"}):(0,t.jsx)(a_.Z,{className:"h-4 w-4 mr-2 text-blue-500"}),"Export"]}),(0,t.jsx)(h.VD,{}),(0,t.jsxs)(h.Xi,{onClick:iI,disabled:!rR,className:"cursor-pointer",children:[(0,t.jsx)(ay.Z,{className:"h-4 w-4 mr-2 text-emerald-500"}),"Tag"]}),(0,t.jsxs)(h.Xi,{onClick:()=>nI(!0),disabled:!rR,className:"cursor-pointer",children:[(0,t.jsx)(ax.Z,{className:"h-4 w-4 mr-2 text-orange-500"}),"Retarget"]})]})]}),(eC.isAdmin||eC.isSuperAdmin)&&(0,t.jsx)("div",{className:"h-5 w-px bg-slate-200 dark:bg-slate-700"}),(0,t.jsx)("button",{onClick:()=>{eB.current&&eB.current.scrollBy({left:-300,behavior:"smooth"})},className:"h-9 w-9 rounded-[3px] bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-700 flex items-center justify-center transition-all shadow-sm hover:shadow-md",children:(0,t.jsx)(z.Z,{className:"h-4 w-4 text-slate-600 dark:text-slate-300"})}),(0,t.jsx)("button",{onClick:()=>{eB.current&&eB.current.scrollBy({left:300,behavior:"smooth"})},className:"h-9 w-9 rounded-[3px] bg-white dark:bg-slate-800 border border-slate-200 dark:border-slate-700 hover:bg-slate-50 dark:hover:bg-slate-700 flex items-center justify-center transition-all shadow-sm hover:shadow-md",children:(0,t.jsx)(eN.Z,{className:"h-4 w-4 text-slate-600 dark:text-slate-300"})})]})]}),(0,t.jsxs)("div",{className:"relative flex-1",children:[aa&&(0,t.jsx)("div",{className:"absolute inset-0 bg-white/80 dark:bg-gray-900/80 backdrop-blur-sm z-20 flex items-center justify-center rounded-[4px]",children:(0,t.jsxs)("div",{className:"flex flex-col items-center gap-3 bg-white dark:bg-gray-800 p-6 rounded-xl shadow-lg",children:[(0,t.jsx)(w.Z,{className:"h-8 w-8 animate-spin text-emerald-500"}),(0,t.jsx)("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Switching pipeline..."})]})}),(0,t.jsx)("div",{ref:eB,className:"overflow-x-auto overflow-y-auto border-2 rounded-[4px] p-4 bg-card h-[calc(100vh-280px)] md:h-[calc(100vh-260px)] lg:h-[calc(100vh-240px)] xl:h-[calc(100vh-220px)] min-h-[400px]",children:(0,t.jsx)("div",{className:"flex gap-3 h-full",style:{minWidth:"max-content"},children:iU.map(e=>{let a=e.name,s=(null==e$?void 0:e$.pipeline[a])||[],l=lt.toLowerCase().trim(),r=s.filter(e=>{var a,s,t;return(!(t7.length>0)||!!(e.last_call_outcome&&t7.includes(e.last_call_outcome)))&&(!l||!!((null===(a=e.name)||void 0===a?void 0:a.toLowerCase().includes(l))||(null===(s=e.phone)||void 0===s?void 0:s.toLowerCase().includes(l))||(null===(t=e.company)||void 0===t?void 0:t.toLowerCase().includes(l))))});return(0,t.jsxs)("div",{className:"w-[240px] sm:w-[280px] flex-shrink-0 flex flex-col h-full min-h-[350px]",children:[(0,t.jsxs)("div",{className:"sticky top-0 z-10 flex items-center justify-between px-4 py-3 rounded-xl shadow-lg border backdrop-blur-sm relative overflow-hidden",style:{background:"linear-gradient(145deg, ".concat(e.color,"15, ").concat(e.color,"08)"),borderColor:"".concat(e.color,"30")},children:[(0,t.jsx)("div",{className:"absolute inset-0 opacity-40 pointer-events-none",style:{background:"radial-gradient(ellipse at top left, ".concat(e.color,"20, transparent 70%)")}}),(0,t.jsxs)("div",{className:"flex items-center gap-2.5 z-10",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg flex items-center justify-center text-white shadow-md",style:{background:"linear-gradient(135deg, ".concat(e.color,", ").concat(e.color,"cc)"),boxShadow:"0 2px 8px ".concat(e.color,"40")},children:iT(a,e.slug)}),(0,t.jsx)("span",{className:"font-bold text-sm text-gray-800 dark:text-gray-100",children:a}),e.is_entry_point&&(0,t.jsx)("span",{className:"text-[9px] py-0.5 px-2 font-bold text-white rounded-full shadow-sm",style:{background:"linear-gradient(135deg, ".concat(e.color,", ").concat(e.color,"cc)")},children:"Entry"}),e.is_qualification_point&&(0,t.jsx)("span",{className:"text-[9px] py-0.5 px-2 font-bold text-white rounded-full shadow-sm bg-gradient-to-r from-teal-500 to-teal-600",children:"CRM"}),e.is_won_point&&(0,t.jsx)("span",{className:"text-[9px] py-0.5 px-2 font-bold text-white rounded-full shadow-sm bg-gradient-to-r from-green-500 to-green-600",children:"Won"}),e.is_lost_point&&(0,t.jsx)("span",{className:"text-[9px] py-0.5 px-2 font-bold text-white rounded-full shadow-sm bg-gradient-to-r from-red-500 to-red-600",children:"Lost"})]}),(0,t.jsx)("div",{className:"flex items-center gap-1 px-3 py-1.5 rounded-full text-white font-bold text-xs shadow-md",style:{backgroundColor:e.color,boxShadow:"0 2px 8px ".concat(e.color,"40")},title:e.total_count>r.length?"Showing ".concat(r.length," of ").concat(e.total_count):void 0,children:e.total_count>r.length?"".concat(r.length,"/").concat(e.total_count):r.length}),(0,t.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 opacity-60",style:{background:"linear-gradient(90deg, ".concat(e.color,", transparent)")}})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-2.5 mt-3 p-2.5 rounded-xl bg-gray-50/80 dark:bg-gray-800/30 border border-gray-100 dark:border-gray-700/30 transition-all duration-300",onDragOver:e=>{e.preventDefault(),e.dataTransfer.dropEffect="move",e.currentTarget.classList.add("bg-green-50","dark:bg-green-950/30","border-2","border-dashed","border-green-400","scale-[1.02]")},onDragLeave:e=>{e.currentTarget.classList.remove("bg-green-50","dark:bg-green-950/30","border-2","border-dashed","border-green-400","scale-[1.02]")},onDrop:e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget.classList.remove("bg-green-50","dark:bg-green-950/30","border-2","border-dashed","border-green-400","scale-[1.02]");let s="",t="",l=e.dataTransfer.getData("application/json");if(l)try{let e=JSON.parse(l);s=e.leadId||"",t=e.fromStage||""}catch(a){s=e.dataTransfer.getData("text/plain")}else s=e.dataTransfer.getData("text/plain");t!==a&&s&&iH(s,a)},children:[r.map(e=>{var s,l,r;let n=aT===e.id,d=aq===e.id;return(0,t.jsxs)(i.Zb,{"data-card":"true",style:{cursor:d?"grabbing":"grab"},className:"\n                            relative overflow-hidden rounded-2xl bg-gradient-to-br from-white via-white to-gray-50 dark:from-gray-800 dark:via-gray-800 dark:to-gray-850 border border-gray-200/80 dark:border-gray-700/60 shadow-sm transition-all duration-300 group\n                            ".concat(d?"opacity-50 scale-95 rotate-2":"","\n                            ").concat(n?"opacity-70 pointer-events-none":"hover:shadow-xl hover:shadow-green-500/15 hover:border-green-300 dark:hover:border-green-600/50 hover:-translate-y-1","\n                          "),draggable:!n,onDragStart:s=>{aV(e.id),s.dataTransfer.setData("text/plain",e.id),s.dataTransfer.setData("application/json",JSON.stringify({leadId:e.id,fromStage:a})),s.dataTransfer.effectAllowed="move"},onDragEnd:()=>{aV(null)},onClick:()=>!n&&iq(e),children:[n&&(0,t.jsx)("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm flex items-center justify-center rounded-2xl z-10",children:(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:[(0,t.jsx)(w.Z,{className:"h-6 w-6 animate-spin text-primary"}),(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:"Moving..."})]})}),(0,t.jsx)(i.aY,{className:"p-4",children:(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,t.jsx)("span",{className:"font-semibold text-sm leading-snug truncate flex-1 min-w-0",children:e.name}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[e.ai_interest_emoji&&(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)("span",{className:"text-lg cursor-default",title:"AI Score: ".concat(e.ai_interest_score||0),children:e.ai_interest_emoji})}),(0,t.jsxs)(f._v,{children:[(0,t.jsxs)("p",{className:"font-medium",children:["AI Interest: ","hot"===e.ai_interest_category?"High":"warm"===e.ai_interest_category?"Medium":"Low"]}),(0,t.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Score: ",null!==(s=e.ai_interest_score)&&void 0!==s?s:0,"/100"]})]})]})}),!e.assigned_to&&eU&&(0,t.jsx)("button",{className:"text-muted-foreground hover:text-primary transition-colors",onClick:a=>i2(e,a),title:"Assign to agent",children:(0,t.jsx)(_.Z,{className:"h-4 w-4"})}),"retargets"===e.source&&(0,t.jsx)(c.C,{className:"bg-orange-500 text-white text-[10px] px-1.5 py-0.5 h-5 flex-shrink-0",children:"Retarget"}),(0,t.jsx)(c.C,{className:"".concat(iB(e.quality)," text-white text-[11px] px-2 py-0.5 h-5 flex-shrink-0"),children:e.score}),e.in_crm_via_complementary&&e.complementary_crm_names&&e.complementary_crm_names.length>0&&(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)(c.C,{className:"bg-emerald-500 hover:bg-emerald-600 text-white text-[10px] px-1.5 py-0.5 h-5 flex-shrink-0 cursor-default",children:"CRM"})}),(0,t.jsxs)(f._v,{children:[(0,t.jsx)("p",{className:"font-medium",children:"Qualified → In CRM"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:e.complementary_crm_names.join(", ")})]})]})}),(0,t.jsxs)(h.h_,{children:[(0,t.jsx)(h.$F,{asChild:!0,children:(0,t.jsx)("button",{className:"h-6 w-6 inline-flex items-center justify-center text-muted-foreground hover:text-foreground transition-colors rounded-[4px] hover:bg-muted",onClick:e=>e.stopPropagation(),children:(0,t.jsx)(aw.Z,{className:"h-4 w-4"})})}),(0,t.jsxs)(h.AW,{align:"end",className:"w-44",children:[(0,t.jsxs)(h.Xi,{onClick:a=>{a.stopPropagation(),iQ(e)},children:[(0,t.jsx)(e_.Z,{className:"h-3.5 w-3.5 mr-2"}),"Add to CRM"]}),rE.length>1&&(0,t.jsxs)(h.Xi,{onClick:a=>{a.stopPropagation(),i$(e)},children:[(0,t.jsx)(eZ.Z,{className:"h-3.5 w-3.5 mr-2"}),"Reassign Pipeline"]}),eU&&(0,t.jsxs)(h.Xi,{onClick:a=>i2(e,a),children:[(0,t.jsx)(_.Z,{className:"h-3.5 w-3.5 mr-2"}),e.assigned_to?"Reassign":"Assign to agent"]}),(0,t.jsxs)(h.Xi,{onClick:a=>{a.stopPropagation(),s4(e),s6("Follow-up"),s9(new Date().toISOString().split("T")[0]),te("medium"),ts(""),tn("schedule"),s5(!0)},children:[(0,t.jsx)(eb.Z,{className:"h-3.5 w-3.5 mr-2"}),"Schedule"]}),(0,t.jsx)(h.VD,{}),(0,t.jsxs)(h.Xi,{onClick:a=>{a.stopPropagation(),(eq||eC.isSuperAdmin)&&iG(e.id,e.name)},className:"".concat(eq||eC.isSuperAdmin?"text-destructive focus:text-destructive":"opacity-50 cursor-not-allowed text-muted-foreground"),disabled:!(eq||eC.isSuperAdmin),children:[(0,t.jsx)(X.Z,{className:"h-3.5 w-3.5 mr-2"}),"Delete Lead"]})]})]})]})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[e.email&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground truncate",children:[(0,t.jsx)(ef.Z,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:e.email})]}),e.phone&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[(0,t.jsx)(R.Z,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,t.jsx)("a",{href:"tel:".concat(e.phone),className:"hover:underline hover:text-foreground",onClick:e=>e.stopPropagation(),children:e.phone})]}),e.company&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-xs text-muted-foreground truncate",children:[(0,t.jsx)(ep.Z,{className:"h-3.5 w-3.5 flex-shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:e.company})]})]}),(e.ai_first_call_status||e.ai_call_display_status)&&(0,t.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1.5 rounded-[4px] text-xs ".concat("initiated"===e.ai_call_display_status?"bg-yellow-50 dark:bg-yellow-950 text-yellow-700 dark:text-yellow-300":"ringing"===e.ai_call_display_status?"bg-blue-50 dark:bg-blue-950 text-blue-700 dark:text-blue-300":"connected"===e.ai_call_display_status||"answered"===e.ai_call_display_status?"bg-emerald-50 dark:bg-emerald-950 text-emerald-700 dark:text-emerald-300":"completed"===e.ai_call_display_status||"completed"===e.ai_first_call_status?"bg-green-50 dark:bg-green-950 text-green-700 dark:text-green-300":"hangup"===e.ai_call_display_status||"hangup"===e.ai_first_call_status?"bg-red-50 dark:bg-red-950 text-red-700 dark:text-red-300":"busy"===e.ai_call_display_status?"bg-amber-50 dark:bg-amber-950 text-amber-700 dark:text-amber-300":"no_answer"===e.ai_call_display_status||"no_answer"===e.ai_first_call_status?"bg-orange-50 dark:bg-orange-950 text-orange-700 dark:text-orange-300":"cancelled"===e.ai_call_display_status||"cancelled"===e.ai_first_call_status?"bg-gray-100 dark:bg-gray-800 text-gray-600 dark:text-gray-400":"failed"===e.ai_call_display_status||"failed"===e.ai_first_call_status?"bg-red-50 dark:bg-red-950 text-red-700 dark:text-red-300":"in_progress"===e.ai_first_call_status?"bg-purple-50 dark:bg-purple-950 text-purple-700 dark:text-purple-300":"pending"===e.ai_first_call_status?"bg-yellow-50 dark:bg-yellow-950 text-yellow-700 dark:text-yellow-300":"bg-gray-50 dark:bg-gray-900 text-gray-600 dark:text-gray-400"),children:["initiated"===e.ai_call_display_status?(0,t.jsx)(R.Z,{className:"h-3 w-3 animate-pulse"}):"ringing"===e.ai_call_display_status?(0,t.jsx)(R.Z,{className:"h-3 w-3 animate-bounce"}):"connected"===e.ai_call_display_status||"answered"===e.ai_call_display_status?(0,t.jsx)(R.Z,{className:"h-3 w-3 text-emerald-600"}):"completed"===e.ai_call_display_status||"completed"===e.ai_first_call_status?(0,t.jsx)(T.Z,{className:"h-3 w-3"}):"hangup"===e.ai_call_display_status||"hangup"===e.ai_first_call_status?(0,t.jsx)(e3.Z,{className:"h-3 w-3"}):"busy"===e.ai_call_display_status?(0,t.jsx)(eA.Z,{className:"h-3 w-3"}):"no_answer"===e.ai_call_display_status||"no_answer"===e.ai_first_call_status?(0,t.jsx)(eA.Z,{className:"h-3 w-3"}):"cancelled"===e.ai_call_display_status||"cancelled"===e.ai_first_call_status?(0,t.jsx)(v.Z,{className:"h-3 w-3"}):"failed"===e.ai_call_display_status||"failed"===e.ai_first_call_status?(0,t.jsx)(U.Z,{className:"h-3 w-3"}):"in_progress"===e.ai_first_call_status?(0,t.jsx)(R.Z,{className:"h-3 w-3 animate-pulse"}):"pending"===e.ai_first_call_status?(0,t.jsx)(I.Z,{className:"h-3 w-3"}):(0,t.jsx)(eh.Z,{className:"h-3 w-3"}),(0,t.jsx)("span",{className:"font-medium",children:"initiated"===e.ai_call_display_status?"Initiated":"ringing"===e.ai_call_display_status?"Ringing...":"connected"===e.ai_call_display_status?"Connected":"answered"===e.ai_call_display_status?"Answered":"hangup"===e.ai_call_display_status||"hangup"===e.ai_first_call_status?"Hung up":"completed"===e.ai_call_display_status||"completed"===e.ai_first_call_status?"Completed":"busy"===e.ai_call_display_status?"Busy":"no_answer"===e.ai_call_display_status||"no_answer"===e.ai_first_call_status?"No Answer":"cancelled"===e.ai_call_display_status||"cancelled"===e.ai_first_call_status?"Cancelled":"fail
1ed"===e.ai_call_display_status||"failed"===e.ai_first_call_status?"Failed":"in_progress"===e.ai_first_call_status?"Calling...":"pending"===e.ai_first_call_status?"Queued":"AI Call"}),("completed"===e.ai_first_call_status||"hangup"===e.ai_first_call_status)&&(0,t.jsxs)("span",{className:"ml-auto font-semibold",children:[null!==(l=e.ai_interest_score)&&void 0!==l?l:0,"/100"]}),("initiated"===e.ai_call_display_status||"ringing"===e.ai_call_display_status||"connected"===e.ai_call_display_status||"answered"===e.ai_call_display_status||"in_progress"===e.ai_first_call_status)&&(0,t.jsx)("button",{type:"button",onMouseDown:e=>{e.stopPropagation()},onClick:async a=>{a.preventDefault(),a.stopPropagation(),console.log("[STOP_AI_CALL] Button clicked for lead:",e.id),console.log("[STOP_AI_CALL] ai_first_call_id:",e.ai_first_call_id);let s=e.ai_first_call_id;if(!s){y.default.error("No active call ID found");return}try{let a=await C.api.post("/ai-calls/cancel/".concat(s),null,{params:{workspace_id:null==H?void 0:H.workspace_id}});if(console.log("[STOP_AI_CALL] API response:",a.data),y.default.success("AI call ended"),e$){let a={...e$.pipeline};for(let s in a)a[s]=a[s].map(a=>a.id===e.id?{...a,ai_first_call_status:"cancelled",ai_call_display_status:void 0,ai_first_call_id:void 0}:a);eG({...e$,pipeline:a})}}catch(e){var t,l;console.error("[STOP_AI_CALL] API error:",e),y.default.error((null==e?void 0:null===(l=e.response)||void 0===l?void 0:null===(t=l.data)||void 0===t?void 0:t.detail)||"Failed to end call")}},className:"ml-auto px-2 py-1 rounded-md bg-red-500/60 hover:bg-red-500 text-white transition-colors flex items-center justify-center relative z-10 shrink-0",title:"End AI call",children:(0,t.jsx)(az.mUf,{className:"h-3 w-3"})})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 pt-2.5 mt-1 border-t",children:[(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)("button",{className:"h-8 w-8 inline-flex items-center justify-center rounded-[4px] bg-blue-50 hover:bg-blue-100 dark:bg-blue-950 dark:hover:bg-blue-900 text-blue-600 transition-colors disabled:opacity-40 disabled:cursor-not-allowed",disabled:!e.phone,onClick:a=>i8(e,a),children:(0,t.jsx)(eF.Z,{className:"h-4 w-4"})})}),(0,t.jsx)(f._v,{children:(0,t.jsx)("p",{children:e.phone?"Call lead":"No phone number"})})]})}),(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)("button",{className:"h-8 w-8 inline-flex items-center justify-center rounded-[4px] transition-colors disabled:opacity-40 disabled:pointer-events-none ".concat("in_progress"===e.ai_first_call_status?"bg-purple-100 dark:bg-purple-900 text-purple-600 animate-pulse":"completed"===e.ai_first_call_status?"bg-green-50 hover:bg-green-100 dark:bg-green-950 dark:hover:bg-green-900 text-green-600":"hangup"===e.ai_first_call_status?"bg-red-50 hover:bg-red-100 dark:bg-red-950 dark:hover:bg-red-900 text-red-600":"bg-indigo-50 hover:bg-indigo-100 dark:bg-indigo-950 dark:hover:bg-indigo-900 text-indigo-600"),onClick:a=>{console.log("[AI Call Button] Clicked for lead:",e.name,"status:",e.ai_first_call_status,"phone:",e.phone),"in_progress"!==e.ai_first_call_status?i7(e,a):(console.log("[AI Call Button] Blocked - call in progress"),a.stopPropagation())},title:"in_progress"===e.ai_first_call_status?"AI call in progress...":"completed"===e.ai_first_call_status||"hangup"===e.ai_first_call_status?"AI call completed":"Start AI First Call",disabled:!e.phone||"in_progress"===e.ai_first_call_status,children:(0,t.jsx)(eh.Z,{className:"h-4 w-4"})})}),(0,t.jsx)(f._v,{children:(0,t.jsx)("p",{children:"in_progress"===e.ai_first_call_status?"AI calling...":"completed"===e.ai_first_call_status||"hangup"===e.ai_first_call_status?"AI Score: ".concat(null!==(r=e.ai_interest_score)&&void 0!==r?r:0,"/100"):"Start AI First Call"})})]})}),(0,t.jsx)("button",{className:"h-8 w-8 inline-flex items-center justify-center rounded-[4px] bg-green-50 hover:bg-green-100 dark:bg-green-950 dark:hover:bg-green-900 text-green-600 transition-colors disabled:opacity-40 disabled:pointer-events-none",onClick:a=>{a.stopPropagation(),a$(e),aW(!0)},title:"WhatsApp",disabled:!e.phone,children:(0,t.jsx)(A.Z,{className:"h-4 w-4"})}),(0,t.jsx)(f.pn,{children:(0,t.jsxs)(f.u,{children:[(0,t.jsx)(f.aJ,{asChild:!0,children:(0,t.jsx)("button",{className:"h-8 w-8 inline-flex items-center justify-center rounded-[4px] bg-purple-50 hover:bg-purple-100 dar
1k:bg-purple-950 dark:hover:bg-purple-900 text-purple-600 transition-colors disabled:opacity-40 disabled:pointer-events-none ml-auto",onClick:s=>{s.stopPropagation();let t=Object.keys((null==e$?void 0:e$.pipeline)||{}),l=t.indexOf(a);l<t.length-1&&iH(e.id,t[l+1])},disabled:Object.keys((null==e$?void 0:e$.pipeline)||{}).indexOf(a)>=Object.keys((null==e$?void 0:e$.pipeline)||{}).length-1,children:(0,t.jsx)(eS.Z,{className:"h-4 w-4"})})}),(0,t.jsx)(f._v,{children:(0,t.jsx)("p",{children:"Move to next stage"})})]})})]})]})})]},e.id)}),e.has_more&&(0,t.jsx)(d.z,{variant:"outline",size:"sm",className:"w-full mt-2 text-xs",onClick:()=>iR(e.id,a),disabled:na[e.id],children:na[e.id]?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-3 w-3 mr-1 animate-spin"}),"Loading..."]}):(0,t.jsxs)(t.Fragment,{children:["Load More (",e.total_count-r.length," remaining)"]})})]})]},e.id||a)})})})]})]})]}):"analytics"===lG?(0,t.jsxs)("div",{className:"p-4 bg-white dark:bg-slate-900 rounded-xl border border-slate-200 dark:border-slate-700 animate-in fade-in slide-in-from-bottom-4 duration-500",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-xl bg-gradient-to-br from-cyan-500 to-teal-600 flex items-center justify-center shadow-lg",children:(0,t.jsx)(e4.Z,{className:"h-5 w-5 text-white"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("h2",{className:"text-lg font-semibold text-slate-800 dark:text-slate-100",children:"AI Call Analytics"}),(0,t.jsxs)("p",{className:"text-sm text-slate-500 dark:text-slate-400",children:[(null===(s=rE.find(e=>e.id===nx))||void 0===s?void 0:s.name)||"Select Pipeline"," • All Time"]})]})]}),(0,t.jsxs)(o.Ph,{value:nx,onValueChange:np,children:[(0,t.jsx)(o.i4,{className:"w-[200px]",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(eZ.Z,{className:"h-4 w-4 text-slate-500"}),(0,t.jsx)(o.ki,{placeholder:"Select Pipeline"})]})}),(0,t.jsx)(o.Bw,{children:rE.filter(e=>e.ai_calls_enabled).map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(eZ.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{children:e.name})]})},e.id))})]})]}),(0,t.jsx)(ac.E,{data:nc||{daily_breakdown:[],status_distribution:{completed:0,failed:0,no_answer:0,busy:0,hangup:0,pending:0},classification_distribution:{hot:0,warm:0,cold:0},conversion_rates:{hot:0,warm:0,cold:0},summary_stats:{total_calls:0,success_rate:0,avg_duration:0,avg_calls_per_day:0,total_duration:0,pending_calls:0,active_calls:0,uncalled_leads:0}},isLoading:nm})]}):"settings"===lG?(0,t.jsx)(aB,{user:H,rolePermissions:eC,pipelines:rE,pipelineStages:st,callStatuses:t3,agentGroups:ez,workspaceUsers:eD,usersLoading:eE,updateWorkspaceUser:eL,refreshUsers:eO,setShowPipelineManager:rB,setShowStageEditor:sd,setShowCallStatusEditor:t9,setShowAICallSettings:l_,setShowAdSourcesDialog:lk,selectedPipelineId:rR,onPipelineChange:ir,isDemoUser:G,setDemoOpen:ee,setDemoResult:ev,refreshPipelines:ii}):null,(0,t.jsx)(Z.F,{open:aQ,onOpenChange:aW,lead:aY}),(0,t.jsx)(D.Vq,{open:li,onOpenChange:e=>{ld(e),e||(lo(""),lu([]),lf(""),lb(""))},children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-lg max-h-[80vh] flex flex-col",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(av.Z,{className:"h-5 w-5 text-indigo-500"}),"Search Leads"]}),(0,t.jsx)(D.Be,{children:"Search for leads by name, phone, or email"})]}),(0,t.jsx)("div",{className:"flex gap-2 mt-2",children:(0,t.jsxs)("div",{className:"relative flex-1",children:[(0,t.jsx)(av.Z,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),(0,t.jsx)(u.I,{placeholder:"Search by name, phone, email...",value:lc,onChange:e=>id(e.target.value),className:"pl-9 h-9",autoFocus:!0}),lx&&(0,t.jsx)(w.Z,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 animate-spin text-muted-foreground"})]})}),(0,t.jsxs)("div",{className:"flex gap-2 mt-2",children:[(0,t.jsxs)(o.Ph,{value:lg,onValueChange:e=>{let a="all"===e?"":e;lf(a),id(lc,a,lj)},children:[(0,t.jsx)(o.i4,{className:"h-8 text-xs w-[140px]",children:(0,t.jsx)(o.ki,{placeholder:"All Stages"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"all",children:"All Stages"}),st.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:e.name},e.id))]})]}),(0,t.jsxs)(o.Ph,{value:lj,onValueChange:e=>{let a="all"===e?"":e;lb(a),id(lc,lg,a)},children:[(0,t.jsx)(o.i4,{className:"h-8 text-xs w-[140px]",children:(0,t.jsx)(o.ki,{placeholder:"All Users"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"all",children:"All Users"}),ia.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:e.name},e.id))]})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto mt-4 min-h-[200px] max-h-[400px]",children:lc.trim()||lg||lj?lx?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsx)(w.Z,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):0===lm.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[(0,t.jsx)(aN.Z,{className:"w-12 h-12 text-muted-foreground
1/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No leads found"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:"Try a different search term"})]}):(0,t.jsx)("div",{className:"space-y-2",children:lm.map(e=>(0,t.jsxs)("div",{onClick:async()=>{try{let a=(await C.api.get("/leads/".concat(e.id))).data;a&&iq(a)}catch(e){console.error("Failed to fetch lead:",e),y.default.error("Failed to open lead")}ld(!1),lo(""),lu([])},className:"flex items-center justify-between p-3 rounded-lg border border-slate-200 dark:border-slate-700 bg-slate-50/50 dark:bg-slate-900/50 hover:bg-indigo-50 dark:hover:bg-indigo-900/20 hover:border-indigo-300 dark:hover:border-indigo-700 cursor-pointer transition-all",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-indigo-500 to-purple-600 flex items-center justify-center text-white text-sm font-medium",children:(e.name||"U").charAt(0).toUpperCase()}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:e.name||"Unknown"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:e.phone||e.email||"-"})]})]}),(0,t.jsx)("div",{className:"text-right",children:e.stage_name&&(0,t.jsx)("span",{className:"inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-slate-100 dark:bg-slate-800 text-slate-700 dark:text-slate-300",children:e.stage_name})})]},e.id))}):(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[(0,t.jsx)(av.Z,{className:"w-12 h-12 text-muted-foreground/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"Search or select a filter"})]})}),(0,t.jsx)(D.cN,{className:"mt-4",children:(0,t.jsx)(d.z,{variant:"outline",onClick:()=>ld(!1),children:"Close"})})]})}),(0,t.jsx)(D.Vq,{open:lC,onOpenChange:e=>{lS(e),e||(lF([]),lz(new Set),lP(1),lq("all"))},children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-2xl max-h-[85vh] flex flex-col",children:[(0,t.jsxs)(D.fK,{className:"pr-8",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-gradient-to-br from-purple-500 to-violet-600 flex items-center justify-center",children:(0,t.jsx)(R.Z,{className:"h-4 w-4 text-white"})}),"AI Call Handle"]}),(0,t.jsxs)("div",{className:(0,r.cn)("flex items-center gap-2 px-3 py-1.5 rounded-full transition-all",lV?"bg-emerald-500/20 border border-emerald-400/30":"bg-slate-100 dark:bg-slate-800 border border-slate-200 dark:border-slate-700"),children:[(0,t.jsx)("div",{className:(0,r.cn)("h-2 w-2 rounded-full",lV?"bg-emerald-400 animate-pulse":"bg-slate-400")}),(0,t.jsx)("span",{className:(0,r.cn)("text-xs font-medium",lV?"text-emerald-600 dark:text-emerald-400":"text-slate-500"),children:lV?"Active":"Inactive"}),(0,t.jsx)(g.r,{checked:lV,onCheckedChange:im,disabled:lW,className:"data-[state=checked]:bg-emerald-500 scale-90"})]})]}),(0,t.jsx)(D.Be,{children:"Select leads to trigger AI calls. Filter by call status to find specific leads."})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 mt-2",children:[(0,t.jsx)("div",{className:"flex items-center gap-1 p-0.5 bg-slate-100 dark:bg-slate-800 rounded-md",children:["all","pending","done","hangup","no_answer","cancelled"].map(e=>(0,t.jsx)(d.z,{variant:lU===e?"default":"ghost",size:"sm",onClick:()=>{lq(e),lP(1),lz(new Set),ic(1,!0,e)},className:"text-xs px-2 h-7 ".concat(lU===e?"pending"===e?"bg-amber-500 hover:bg-amber-600":"done"===e?"bg-green-500 hover:bg-green-600":"hangup"===e?"bg-red-500 hover:bg-red-600":"no_answer"===e?"bg-orange-500 hover:bg-orange-600":"cancelled"===e?"bg-slate-500 hover:bg-slate-600":"bg-slate-600":""),children:"no_answer"===e?"No Answer":"hangup"===e?"Hung Up":e.charAt(0).toUpperCase()+e.slice(1)},e))}),(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,t.jsxs)("span",{children:[lA.size," selected"]}),lA.size>0&&(0,t.jsx)(d.z,{variant:"ghost",size:"sm",onClick:ip,className:"h-6 text-xs px-2",children:"Clear"}),(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>{let e=new Set(ih().map(e=>e.id));lz(e),y.default.success("Selected ".concat(e.size," leads"))},disabled:lL,className:"h-6 text-xs px-2 bg-purple-50 hover:bg-purple-100 border-purple-200 text-purple-700 dark:bg-purple-900/20 dark:hover:bg-purple-900/40 dark:border-purple-700 dark:text-purple-300",children:["Select All (",ih().length,")"]})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto mt-4 border rounded-lg",children:lL&&0===lZ.length?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsx)(w.Z,{className:"w-6 h-6 animate-spin text-purple-500"})}):0===lZ.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[(0,t.jsx)(R.Z,{className:"w-12 h-12 text-muted-foreground
1/30 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No leads found"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground/70 mt-1",children:"all"!==lU?"Try changing the filter":"No leads in this pipeline"})]}):(0,t.jsxs)("div",{className:"divide-y",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 bg-slate-50 dark:bg-slate-800/50 text-xs font-medium text-muted-foreground sticky top-0",children:[(0,t.jsx)("div",{className:"w-8",children:(0,t.jsx)(eY.X,{checked:lZ.length>0&&lA.size===lZ.length,onCheckedChange:e=>{e?ix():ip()}})}),(0,t.jsx)("div",{className:"flex-1 min-w-[150px]",children:"Lead Name"}),(0,t.jsx)("div",{className:"w-[120px]",children:"Phone"}),(0,t.jsx)("div",{className:"w-[100px]",children:"Stage"}),(0,t.jsx)("div",{className:"w-[100px]",children:"Call Status"})]}),lZ.map(e=>{let a=iv(e),s=e.stage||"Unknown";return(0,t.jsxs)("div",{className:"flex items-center gap-3 px-4 py-3 hover:bg-slate-50 dark:hover:bg-slate-800/30 cursor-pointer transition-colors ".concat(lA.has(e.id)?"bg-purple-50 dark:bg-purple-900/20":""),onClick:()=>iu(e.id),children:[(0,t.jsx)("div",{className:"w-8",children:(0,t.jsx)(eY.X,{checked:lA.has(e.id),onCheckedChange:()=>iu(e.id),onClick:e=>e.stopPropagation()})}),(0,t.jsxs)("div",{className:"flex-1 min-w-[150px]",children:[(0,t.jsx)("p",{className:"font-medium text-sm truncate",children:e.name||"Unknown"}),e.email&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:e.email})]}),(0,t.jsx)("div",{className:"w-[120px] text-sm text-muted-foreground truncate",children:e.phone||"-"}),(0,t.jsx)("div",{className:"w-[100px]",children:(0,t.jsx)(c.C,{variant:"outline",className:"text-xs truncate max-w-full",children:s})}),(0,t.jsx)("div",{className:"w-[100px]",children:(0,t.jsx)(c.C,{className:"text-xs ".concat(a.color),children:a.label})})]},e.id)})]})}),lD&&lZ.length>0&&(0,t.jsx)("div",{className:"flex justify-center mt-3",children:(0,t.jsxs)(d.z,{variant:"outline",size:"sm",onClick:()=>ic(lI+1,!1),disabled:lL,className:"gap-2",children:[lL?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(es.Z,{className:"h-4 w-4"}),"Load More"]})}),l$.length>0&&(0,t.jsx)("div",{className:"flex items-center justify-between px-3 py-2 bg-blue-50 dark:bg-blue-900/20 border border-blue-200 dark:border-blue-800 rounded-lg mt-3",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-2 w-2 rounded-full bg-blue-500 animate-pulse"}),(0,t.jsxs)("span",{className:"text-sm font-medium text-blue-700 dark:text-blue-300",children:[l$.length," active call",1!==l$.length?"s":""," in progress"]})]})}),(0,t.jsxs)(D.cN,{className:"mt-4 gap-2 flex-wrap sm:flex-nowrap",children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>lS(!1),children:"Cancel"}),(0,t.jsx)(d.z,{variant:"destructive",onClick:ij,disabled:0===l$.length||lB,className:"gap-2",children:lB?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}),"Terminating..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e1.Z,{className:"h-4 w-4"}),"Terminate (",l$.length,")"]})}),(0,t.jsx)(d.z,{onClick:ig,disabled:0===lA.size||lM,className:"gap-2 bg-gradient-to-r from-purple-500 to-violet-600 hover:from-purple-600 hover:to-violet-700",children:lM?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}),"Triggering..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ab.Z,{className:"h-4 w-4"}),"Trigger Call (",lA.size,")"]})})]})]})}),(0,t.jsx)(D.Vq,{open:aX,onOpenChange:a0,children:(0,t.jsxs)(D.cZ,{className:"max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2 text-red-600",children:[(0,t.jsx)(X.Z,{className:"h-5 w-5"}),"Delete Lead"]}),(0,t.jsxs)(D.Be,{children:["Are you sure you want to delete ",(0,t.jsxs)("span",{className:"font-semibold text-foreground",children:['"',null==a1?void 0:a1.name,'"']}),"? This action cannot be undone."]})]}),(0,t.jsxs)(D.cN,{className:"gap-2 sm:gap-0",children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>{a0(!1),a5(null)},disabled:a2,children:"Cancel"}),(0,t.jsx)(d.z,{variant:"destructive",onClick:iJ,disabled:a2,children:a2?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(X.Z,{className:"h-4 w-4 mr-2"}),"Delete"]})})]})]})}),(0,t.jsx)(D.Vq,{open:a7,onOpenChange:se,children:(0,t.jsxs)(D.cZ,{className:"max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2 text-red-600",children:[(0,t.jsx)(X.Z,{className:"h-5 w-5"}),"Delete ",a8.size," Lead",a8.size>1?"s":""]}),(0,t.jsxs)(D.Be,{children:["Are you sure you want to delete ",(0,t.jsxs)("span",{className:"font-semibold text-foreground",children:[a8.size," lead",a8.size>1?"s":""]}),"? This action cannot be undone."]})]}),(0,t.jsxs)(D.cN,{className:"gap-2 sm:gap-0",children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>se(!1),disabled:sa,children:"Cancel"}),(0,t.jsx)(d.z,{variant:"destructive",onClick:iX,disabled:sa,children:sa?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Deleting..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(X.Z,{className:"h-4 w-4 mr-2"}),"Delete ",a8.size," Lead",a8.size>1?"s":""]})})]})]})}),aG&&(0,t.jsx)(L,{leadId:aG.id,leadName:aG.name||"Lead",isOpen:aK,onClose:()=>{aH(!1),aJ(null)}}),(0,t.jsx)(D.Vq,{open:ap,onOpenChange:ag,children:(0,t.jsxs)(D.cZ,{className:"max-w-md !p-4 gap-0",children:[(0,t.jsxs)(D.fK,{className:"flex-shrink-0 pb-3",children:[(0,t.jsx)(D.$N,{className:"text-base",children:"Add New Lead"}),(0,t.jsx)(D.Be,{className:"text-sm",children:"Fill in the details to add a new lead"})]}),(()=>{let e=rE.find(e=>e.id===rR);return console.log("[LeadsPageContent] Add Lead Dialog - selectedPipelineId:",rR,"selectedPipeline:",e,"ai_calls_enabled:",null==e?void 0:e.ai_calls_enabled),(0,t.jsx)(S,{onSuccess:i0,embedded:!0,workspaceId:null==H?void 0:H.workspace_id,pipelineId:rR||void 0,pipelineName:null==e?void 0:e.name,aiCallingEnabled:(null==e?void 0:e.ai_calls_enabled)||!1})})()]})}),(0,t.jsx)(D.Vq,{open:sm,onOpenChange:su,children:(0,t.jsxs)(D.cZ,{className:"max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsx)(D.$N,{children:"Assign Lead to Sales Agent"}),(0,t.jsx)(D.Be,{children:sx&&(0,t.jsxs)("span",{children:["Assign ",(0,t.jsx)("strong",{children:sx.name})," to a sales agent"]})})]}),(0,t.jsx)("div",{className:"space-y-4 py-4",children:0===sN.length?(0,t.jsxs)("div",{className:"text-center py-4 text-muted-foreground",children:[(0,t.jsx)(ah.Z,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,t.jsx)("p",{children:"No sales agents available"})]}):(0,t.jsx)("div",{className:"space-y-2",children:sN.map(e=>(0,t.jsxs)(d.z,{variant:"outline",className:"w-full justify-start h-auto py-3",onClick:()=>i4(e.id,e.name),disabled:sF,children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-full bg-primary/10 flex items-center justify-center",children:(0,t.jsx)(ah.Z,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"text-left",children:[(0,t.jsx)("div",{className:"font-medium",children:e.name}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:e.email})]})]}),sF&&(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin ml-auto"})]},e.id))})})]})}),(0,t.jsx)(eX,{open:af,onOpenChange:aM,pipelineId:rR,pipelineName:null===(m=rE.find(e=>e.id===rR))||void 0===m?void 0:m.name,onImportComplete:async e=>{e>0&&await iM()}}),(0,t.jsx)(D.Vq,{open:s1,onOpenChange:s5,children:(0,t.jsxs)(D.cZ,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(eF.Z,{className:"h-5 w-5 text-blue-600"}),"First Call"]}),(0,t.jsx)(D.Be,{children:s2&&(0,t.jsxs)("span",{children:["Manage first call for ",(0,t.jsx)("strong",{children:s2.name})]})})]}),(0,t.jsxs)("div",{className:"space-y-4 py-4",children:[(0,t.jsxs)("div",{className:"flex gap-2 p-1 bg-muted rounded-[4px]",children:[(0,t.jsxs)(d.z,{variant:"schedule"===tr?"default":"ghost",size:"sm",className:"flex-1",onClick:()=>tn("schedule"),children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4 mr-2"}),"Schedule Call"]}),(0,t.jsxs)(d.z,{variant:"complete"===tr?"default":"ghost",size:"sm",className:"flex-1",onClick:()=>tn("complete"),children:[(0,t.jsx)(T.Z,{className:"h-4 w-4 mr-2"}),"Call Done"]})]}),s2&&(0,t.jsxs)("div",{className:"bg-blue-50 dark:bg-blue-950 rounded-[4px] p-3 space-y-2 border border-blue-200 dark:border-blue-800",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-blue-700 dark:text-blue-300",children:"Contact Information"}),s2.phone&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)(R.Z,{className:"h-4 w-4 text-blue-600"}),(0,t.jsx)("a",{href:"tel:".concat(s2.phone),className:"text-blue-600 hover:underline font-medium",children:s2.phone})]}),s2.email&&(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,t.jsx)(ef.Z,{className:"h-4 w-4"}),(0,t.jsx)("span",{children:s2.email})]}),s2.company&&(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:s2.company})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"taskTitle",children:"Task Title"}),(0,t.jsx)(u.I,{id:"taskTitle",placeholder:"First Call",value:s3,onChange:e=>s6(e.target.value)})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"taskDate",children:"schedule"===tr?"Scheduled Date":"Call Date"}),(0,t.jsx)(u.I,{id:"taskDate",type:"date",value:s8,onChange:e=>s9(e.target.value)})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"taskPriority",children:"Priority"}),(0,t.jsxs)(o.Ph,{value:s7,onValueChange:e=>te(e),children:[(0,t.jsx)(o.i4,{id:"taskPriority",children:(0,t.jsx)(o.ki,{})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"low",children:"Low"}),(0,t.jsx)(o.Ql,{value:"medium",children:"Medium"}),(0,t.jsx)(o.Ql,{value:"high",children:"High"})]})]})]})]}),"complete"===tr&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)(p._,{htmlFor:"callOutcome",children:"Call Outcome *"}),eC.isSuperAdmin&&(0,t.jsx)("button",{type:"button",onClick:()=>t9(!0),className:"text-muted-foreground hover:text-foreground",children:(0,t.jsx)(V.Z,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)(o.Ph,{value:ti,onValueChange:td,children:[(0,t.jsx)(o.i4,{id:"callOutcome",children:(0,t.jsx)(o.ki,{placeholder:"Select call outcome..."})}),(0,t.jsxs)(o.Bw,{children:[t3.positive.length>0&&(0,t.jsx)(o.Ql,{value:"__positive",disabled:!0,className:"font-semibold text-green-600",children:"Positive Outcomes"}),t3.positive.map(e=>(0,t.jsx)(o.Ql,{value:e.slug,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.slug)),t3.neutral.length>0&&(0,t.jsx)(o.Ql,{value:"__neutral",disabled:!0,className:"font-semibold text-yellow-600",children:"Neutral Outcomes"}),t3.neutral.map(e=>(0,t.jsx)(o.Ql,{value:e.slug,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.slug)),t3.negative.length>0&&(0,t.jsx)(o.Ql,{value:"__negative",disabled:!0,className:"font-semibold text-red-600",children:"Negative Outcomes"}),t3.negative.map(e=>(0,t.jsx)(o.Ql,{value:e.slug,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.slug))]})]})]}),"not_eligible"===ti&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"outcomeReason",children:"Reason for Not Eligible"}),(0,t.jsx)(u.I,{id:"outcomeReason",placeholder:"Specify why the lead is not eligible...",value:tc,onChange:e=>to(e.target.value)})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"callDuration",children:"Call Duration (seconds)"}),(0,t.jsx)(u.I,{id:"callDuration",type:"number",placeholder:"0",value:tm||"",onChange:e=>tu(parseInt(e.target.value)||0)})]}),(0,t.jsxs)("div",{className:"border-t pt-4 mt-4",children:[(0,t.jsxs)("h4",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4 text-green-600"}),"Schedule Next Follow-up"]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"nextFollowUpDate",children:"Next Follow-up Date"}),(0,t.jsx)(u.I,{id:"nextFollowUpDate",type:"date",value:tx,onChange:e=>tp(e.target.value)})]}),tx&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{htmlFor:"nextFollowUpNotes",children:"Follow-up Notes"}),(0,t.jsx)(x.g,{id:"nextFollowUpNotes",placeholder:"Notes for the follow-up call...",value:th,onChange:e=>tg(e.target.value),rows:2})]})]})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)(p._,{htmlFor:"taskNotes",children:["Notes ","schedule"===tr?"(Optional)":""]}),(0,t.jsx)(x.g,{id:"taskNotes",placeholder:"schedule"===tr?"Add any notes for this call...":"Call notes and observations...",value:ta,onChange:e=>ts(e.target.value),rows:3})]}),(0,t.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,t.jsx)(d.z,{variant:"outline",className:"flex-1",onClick:()=>s5(!1),children:"Cancel"}),(0,t.jsx)(d.z,{className:"flex-1 ".concat("complete"===tr?"bg-green-600 hover:bg-green-700":"bg-blue-600 hover:bg-blue-700"),onClick:i6,disabled:!s3.trim()||!s8||tt||"complete"===tr&&!ti,children:tt?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"schedule"===tr?"Scheduling...":"Saving..."]}):"schedule"===tr?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4 mr-2"}),"Schedule Call"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(T.Z,{className:"h-4 w-4 mr-2"}),"Complete Call"]})})]})]})]})}),(0,t.jsx)(at.$,{open:tX,onOpenChange:t0,lead:tG,onCallEnded:i9}),(0,t.jsx)(ad,{open:t1,onOpenChange:t5,lead:tG,onCallEnded:i9}),(0,t.jsx)(D.Vq,{open:tf,onOpenChange:e=>{e||dt()},children:(0,t.jsxs)(D.cZ,{className:"max-w-lg max-h-[90vh] overflow-y-auto",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(eF.Z,{className:"h-5 w-5 ".concat("connected"===tN?"text-green-600":"text-blue-600")}),"ended"===tN?"Log Call Outcome":"connected"===tN?"Call Answered":"Call in Progress"]}),(0,t.jsx)(D.Be,{children:tb&&(0,t.jsx)("span",{children:"ended"===tN?(0,t.jsxs)(t.Fragment,{children:["Record the outcome for your call with ",(0,t.jsx)("strong",{children:tb.name})]}):(0,t.jsxs)(t.Fragment,{children:["Calling ",(0,t.jsx)("strong",{children:tb.name})]})})})]}),tb&&(0,t.jsxs)("div",{className:"space-y-4 py-2",children:["ended"!==tN&&(0,t.jsxs)("div",{className:"flex flex-col items-center gap-4 py-6",children:[(0,t.jsxs)("div",{className:"text-center space-y-1",children:[(0,t.jsx)("p",{className:"text-lg font-semibold",children:tb.name}),tb.company&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:tb.company}),(0,t.jsx)("p",{className:"text-sm font-medium text-blue-600",children:tb.phone})]}),(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2",children:["calling"===tN&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-blue-100 dar
1k:bg-blue-900 flex items-center justify-center animate-pulse",children:(0,t.jsx)(R.Z,{className:"h-7 w-7 text-blue-600"})}),(0,t.jsxs)("span",{className:"absolute -bottom-1 -right-1 flex h-5 w-5",children:[(0,t.jsx)("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"}),(0,t.jsx)("span",{className:"relative inline-flex rounded-full h-5 w-5 bg-blue-500"})]})]}),(0,t.jsx)("span",{className:"text-sm font-medium text-blue-600 flex items-center gap-2",children:tS?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"})," Initiating..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"})," Ringing..."]})})]}),"connected"===tN&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-16 w-16 rounded-full bg-green-100 dark:bg-green-900 flex items-center justify-center",children:(0,t.jsx)(T.Z,{className:"h-7 w-7 text-green-600"})}),(0,t.jsx)("span",{className:"text-base font-semibold text-green-600",children:"Call Answered"}),(0,t.jsx)("span",{className:"text-3xl font-mono font-bold tabular-nums",children:dr(tk)})]})]}),"calling"===tN&&!tS&&(0,t.jsxs)("div",{className:"flex gap-3 w-full max-w-xs",children:[(0,t.jsxs)(d.z,{className:"flex-1",variant:"default",onClick:de,children:[(0,t.jsx)(T.Z,{className:"h-4 w-4 mr-2"}),"Connected"]}),(0,t.jsxs)(d.z,{className:"flex-1",variant:"destructive",onClick:ds,children:[(0,t.jsx)(e3.Z,{className:"h-4 w-4 mr-2"}),"Not Answered"]})]}),"connected"===tN&&(0,t.jsx)(d.z,{variant:"destructive",size:"lg",className:"rounded-full h-14 w-14 p-0",onClick:ds,title:"End Call",children:(0,t.jsx)(R.Z,{className:"h-6 w-6 rotate-[135deg]"})}),(0,t.jsx)("button",{className:"text-xs text-muted-foreground hover:text-foreground underline",onClick:()=>{dt(),tb&&i3(tb,{stopPropagation:()=>{}})},children:"Schedule for later instead"})]}),"ended"===tN&&(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"bg-muted/50 rounded-[4px] p-3 flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm",children:[(0,t.jsx)(R.Z,{className:"h-4 w-4 text-muted-foreground"}),(0,t.jsx)("span",{children:tb.phone}),tK?(0,t.jsx)(c.C,{variant:"default",className:"bg-green-600 text-white text-[10px] px-1.5 py-0",children:"Answered"}):(0,t.jsx)(c.C,{variant:"destructive",className:"text-[10px] px-1.5 py-0",children:"Not Answered"})]}),(0,t.jsx)(c.C,{variant:"secondary",className:"font-mono",children:dr(tk)})]}),(null==tb?void 0:tb.id)&&(0,t.jsx)(ex,{leadId:tb.id,workspaceId:null==H?void 0:H.workspace_id,callStatuses:t3}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)(p._,{children:"Call Outcome *"}),eC.isSuperAdmin&&(0,t.jsx)("button",{type:"button",onClick:()=>t9(!0),className:"text-muted-foreground hover:text-foreground",children:(0,t.jsx)(V.Z,{className:"h-3.5 w-3.5"})})]}),(0,t.jsxs)(o.Ph,{value:tE,onValueChange:tL,children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:"Select call outcome..."})}),(0,t.jsxs)(o.Bw,{children:[t3.positive.length>0&&(0,t.jsx)(o.Ql,{value:"__positive",disabled:!0,className:"font-semibold text-green-600",children:"Positive Outcomes"}),t3.positive.map(e=>(0,t.jsx)(o.Ql,{value:e.slug,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.slug)),t3.neutral.length>0&&(0,t.jsx)(o.Ql,{value:"__neutral",disabled:!0,className:"font-semibold text-yellow-600",children:"Neutral Outcomes"}),t3.neutral.map(e=>(0,t.jsx)(o.Ql,{value:e.slug,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.slug)),t3.negative.length>0&&(0,t.jsx)(o.Ql,{value:"__negative",disabled:!0,className:"font-semibold text-red-600",children:"Negative Outcomes"}),t3.negative.map(e=>(0,t.jsx)(o.Ql,{value:e.slug,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color}}),e.name]})},e.slug))]})]})]}),"not_eligible"===tE&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{children:"Reason for Not Eligible"}),(0,t.jsx)(u.I,{placeholder:"Specify why the lead is not eligible...",value:tR,onChange:e=>tM(e.target.value)})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{children:"Notes"}),(0,t.jsx)(x.g,{placeholder:"Call notes and observations...",value:tO,onChange:e=>tB(e.target.value),rows:3})]}),(0,t.jsxs)("div",{className:"border-t pt-4",children:[(0,t.jsxs)("h4",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,t.jsx)(eS.Z,{className:"h-4 w-4 text-blue-600"}),"Move Pipeline Stage"]}),(0,t.jsxs)(o.Ph,{value:tY,onValueChange:t$,children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:(null==tb?void 0:tb.stage)?"Current: ".concat(tb.stage):"Select stage..."})}),(0,t.jsx)(o.Bw,{children:iU.map(e=>(0,t.jsx)(o.Ql,{value:e.name,children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:e.color}}),e.name,(null==tb?void 0:tb.stage)===e.name&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground ml-1",children:"(current)"})]})},e.name))})]})]}),(0,t.jsxs)("div",{className:"border-t pt-4",children:[(0,t.jsxs)("h4",{className:"text-sm font-semibold mb-3 flex items-center gap-2",children:[(0,t.jsx)(eb.Z,{className:"h-4 w-4 text-green-600"}),"Schedule Next Follow-up"]}),(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{children:"Next Follow-up Date"}),(0,t.jsx)(u.I,{type:"date",value:tT,onChange:e=>tU(e.target.value)})]}),tT&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{children:"Follow-up Notes"}),(0,t.jsx)(x.g,{placeholder:"Notes for the follow-up call...",value:tq,onChange:e=>tV(e.target.value),rows:2})]})]})]}),(0,t.jsxs)("div",{className:"flex gap-2 pt-2",children:[(0,t.jsx)(d.z,{variant:"outline",className:"flex-1",onClick:dt,children:"Cancel"}),(0,t.jsx)(d.z,{className:"flex-1 bg-green-600 hover:bg-green-700",onClick:dl,disabled:!tE||tQ,children:tQ?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"})," Saving..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(T.Z,{className:"h-4 w-4 mr-2"})," Save Call"]})})]})]})]})]})}),(0,t.jsx)(eR,{open:!!eJ,onOpenChange:e=>
1{e||(e5(null),sg(!1),sj({name:"",email:"",phone:"",company:"",score:0}))},lead:eJ,workspaceId:(null==H?void 0:H.workspace_id)||"",stages:iU,rolePermissions:eC,leadQuality:e2,onMoveLead:async(e,a)=>{await iH(e,a),eJ&&e5({...eJ,stage:a})},onSaveLead:async(e,a)=>{try{await C.api.put("/leads/".concat(e),{name:a.name,email:a.email||null,phone:a.phone||null,company:a.company||null,score:a.score}),eJ&&e5({...eJ,...a}),y.default.success("Lead updated successfully"),iM()}catch(e){throw y.default.error("Failed to update lead"),e}},onSaveCustomFields:async(e,a)=>{try{await C.api.put("/lead-pipelines/entries/".concat(e,"?workspace_id=").concat(null==H?void 0:H.workspace_id),{lead_meta_data:a}),eJ&&e5({...eJ,custom_fields:a,meta_data:a,metadata:a}),y.default.success("Custom fields updated"),iM()}catch(e){throw y.default.error("Failed to update custom fields"),e}},onAssignClick:i2,onCall:(e,a)=>{e5(null),i8(e,a)},onAddFollowUp:e=>{e5(null),s4(e),s6("Follow-up"),s9(new Date().toISOString().split("T")[0]),te("high"),ts(""),tn("schedule"),s5(!0)},onFetchPayments:async e=>{try{return(await C.api.get("/leads-payment/lead/".concat(e,"/payments"))).data||[]}catch(e){return console.error("Failed to fetch payments:",e),[]}},onFetchRegistrationRequirement:async e=>{try{return(await C.api.get("/leads-payment/lead/".concat(e,"/registration-requirement"))).data||null}catch(e){return console.error("Failed to fetch registration requirement:",e),null}},onSubmitPayment:async(e,a)=>{try{await C.api.post("/leads-payment",{lead_id:e,amount:parseFloat(a.amount),currency:a.currency,payment_date:new Date(a.payment_date).toISOString(),payment_method:a.payment_method,payment_status:a.payment_status,invoice_number:a.invoice_number||null,description:a.description||null,is_recurring:a.is_recurring,recurring_frequency:a.is_recurring?a.recurring_frequency:null}),y.default.success("Payment recorded successfully"),iO()}catch(e){throw y.default.error("Failed to record payment"),e}},onRegistrationPayment:async(e,a)=>{try{await C.api.post("/leads-payment",{lead_id:e,amount:a,currency:"INR",payment_date:new Date().toISOString(),payment_method:"upi",payment_status:"completed",payment_type:"registration",description:"Registration payment for CRM qualification"}),y.default.success("Registration payment recorded"),iO()}catch(e){throw y.default.error("Failed to record registration payment"),e}},onGeneratePaymentLink:async(e,a)=>{try{var s,t;let l=await C.api.post("/leads-payment/registration/generate-link",{lead_id:e,crm_pipeline_id:a});(null===(s=l.data)||void 0===s?void 0:s.success)?y.default.success("Payment link generated"):y.default.error((null===(t=l.data)||void 0===t?void 0:t.message)||"Failed to generate payment link")}catch(e){throw y.default.error("Failed to generate payment link"),e}},onSendWhatsApp:async(e,a,s)=>{try{var t,l;let r=await C.api.post("/leads-payment/registration/send-whatsapp",{lead_id:e,crm_pipeline_id:a,payment_link_url:s});if((null===(t=r.data)||void 0===t?void 0:t.success)&&(null===(l=r.data)||void 0===l?void 0:l.whatsapp_url))return y.default.success("Opening WhatsApp..."),r.data.whatsapp_url;return y.default.error("Failed to send WhatsApp"),null}catch(e){return y.default.error("Failed to send WhatsApp"),null}},onCopyPaymentLink:e=>{navigator.clipboard.writeText(e),y.default.success("Payment link copied to clipboard")},onFetchCalendarTasks:async e=>{try{var a;let s=await C.api.get("/follow-ups/lead/".concat(e),{params:{workspace_id:null==H?void 0:H.workspace_id,include_completed:!0}});return(null===(a=s.data)||void 0===a?void 0:a.tasks)||[]}catch(e){return console.error("Failed to fetch calendar tasks:",e),[]}}}),(0,t.jsx)($,{open:sr,onOpenChange:sn,onSetupComplete:()=>{so(!0),iM()},workspaceId:null==H?void 0:H.workspace_id}),(0,t.jsx)(ea,{open:si,onOpenChange:sd,stages:st,onStagesUpdated:()=>iM(),workspaceId:null==H?void 0:H.workspace_id,pipelineId:rR||void 0}),(0,t.jsx)(em,{open:t8,onOpenChange:t9,statuses:t3,onStatusesUpdated:()=>is(),workspaceId:null==H?void 0:H.workspace_id,pipelineId:rR||void 0}),rR&&(0,t.jsx)(aO,{open:nz,onOpenChange:nI,pipelineId:rR,pipelineName:(null===(j=rE.find(e=>e.id===rR))||void 0===j?void 0:j.name)||"Pipeline",stages:st,workspaceId:(null==H?void 0:H.workspace_id)||""}),(0,t.jsx)(D.Vq,{open:rO,onOpenChange:rB,children:(0,t.jsxs)(D.cZ,{className:"max-w-lg max-h-[85vh] !p-0 gap-0 overflow-hidden flex flex-col",children:[(0,t.jsxs)(D.fK,{className:"px-6 py-4 border-b flex-shrink-0",children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(V.Z,{className:"h-5 w-5 text-primary"}),"Manage Pipelines"]}),(0,t.jsx)(D.Be,{children:"Create, edit, or delete leads pipelines."})]}),(0,t.jsxs)("div",{className:"px-6 py-4 space-y-4 flex-1 overflow-hidden flex flex-col",children:[(0,t.jsxs)("div",{className:"space-y-3 p-3 border rounded-lg flex-shrink-0",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Create New Pipeline"}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(u.I,{placeholder:"Pipeline name...",value:rq,onChange:e=>rV(e.target.value),className:"flex-1 h-8 text-sm"}),(0,t.jsxs)(o.Ph,{value:rQ,onValueChange:rW,children:[(0,t.jsx)(o.i4,{className:"w-[80px] h-8",children:(0,t.jsx)(o.ki,{children:(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:rQ}})})})}),(0,t.jsx)(o.Bw,{children:["#3B82F6","#10B981","#8B5CF6","#F59E0B","#EF4444","#EC4899","#14B8A6","#6366F1"].map(e=>(0,t.jsx)(o.Ql,{value:e,children:(0,t.jsx)("div",{className:"flex items-center gap-2",children:(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e}})})},e))})]})]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsxs)(o.Ph,{value:rY||"_all",onValueChange:e=>{"_create"===e?r0(!0):r$("_all"===e?"":e)},children:[(0,t.jsx)(o.i4,{className:"flex-1 h-8",children:(0,t.jsx)(o.ki,{placeholder:"All branches"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"_all",children:"All branches"}),rG.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:e.name},e.id)),(0,t.jsx)(o.Ql,{value:"_create",className:"text-primary font-medium",children:(0,t.jsxs)("span",{className:"flex items-center gap-1",children:[(0,t.jsx)(N.Z,{className:"h-3 w-3"})," Create Branch"]})})]})]}),(0,t.jsxs)(h.h_,{children:[(0,t.jsx)(h.$F,{asChild:!0,children:(0,t.jsxs)(d.z,{variant:"outline",className:"flex-1 h-8 justify-between text-sm font-normal",children:[0===rK.length?"All groups (visible to all)":"".concat(rK.length," group").concat(rK.length>
11?"s":""," selected"),(0,t.jsx)(es.Z,{className:"h-4 w-4 opacity-50"})]})}),(0,t.jsxs)(h.AW,{className:"w-56",children:[(0,t.jsx)(h.bO,{checked:0===rK.length,onCheckedChange:()=>rH([]),children:"All groups (visible to all)"}),(0,t.jsx)(h.VD,{}),ez.map(e=>(0,t.jsxs)(h.bO,{checked:rK.includes(e.id),onCheckedChange:a=>{a?rH([...rK,e.id]):rH(rK.filter(a=>a!==e.id))},children:[(0,t.jsx)(ah.Z,{className:"h-3 w-3 mr-2"}),e.name]},e.id))]})]}),(0,t.jsx)(d.z,{size:"sm",className:"h-8 px-3",onClick:iP,disabled:r8||!rq.trim(),children:r8?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}):(0,t.jsx)(N.Z,{className:"h-4 w-4"})})]})]})]}),(0,t.jsxs)("div",{className:"flex-1 flex flex-col min-h-0",children:[(0,t.jsx)(p._,{className:"text-sm font-medium mb-2 flex-shrink-0",children:"Existing Pipelines"}),(0,t.jsxs)("div",{className:"space-y-2 flex-1 overflow-y-auto pr-1 [&::-webkit-scrollbar]:w-1 [&::-webkit-scrollbar-track]:bg-transparent [&::-webkit-scrollbar-thumb]:bg-slate-200 [&::-webkit-scrollbar-thumb]:rounded-full dark:[&::-webkit-scrollbar-thumb]:bg-slate-600",children:[rE.map(e=>(0,t.jsx)(i.Zb,{className:"".concat(e.is_default?"bg-muted/30":""),children:(0,t.jsx)(i.aY,{className:"py-2 px-3",children:(null==rT?void 0:rT.id)===e.id?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,t.jsx)(u.I,{value:rT.name,onChange:e=>rU({...rT,name:e.target.value}),className:"flex-1 h-8 text-sm"}),(0,t.jsxs)(o.Ph,{value:rT.color,onValueChange:e=>rU({...rT,color:e}),children:[(0,t.jsx)(o.i4,{className:"w-[80px] h-8",children:(0,t.jsx)(o.ki,{children:(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:rT.color}})})}),(0,t.jsx)(o.Bw,{children:["#3B82F6","#10B981","#8B5CF6","#F59E0B","#EF4444","#EC4899","#14B8A6","#6366F1"].map(e=>(0,t.jsx)(o.Ql,{value:e,children:(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e}})},e))})]})]}),(0,t.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,t.jsx)(p._,{className:"text-xs text-muted-foreground whitespace-nowrap",children:"Assign to groups:"}),(0,t.jsxs)(h.h_,{children:[(0,t.jsx)(h.$F,{asChild:!0,children:(0,t.jsxs)(d.z,{variant:"outline",className:"flex-1 h-8 justify-between text-sm font-normal",children:[rT.agent_group_ids&&0!==rT.agent_group_ids.length?"".concat(rT.agent_group_ids.length," group").concat(rT.agent_group_ids.length>1?"s":""," selected"):"All groups (visible to all)",(0,t.jsx)(es.Z,{className:"h-4 w-4 opacity-50"})]})}),(0,t.jsxs)(h.AW,{className:"w-56",children:[(0,t.jsx)(h.bO,{checked:!rT.agent_group_ids||0===rT.agent_group_ids.length,onCheckedChange:()=>rU({...rT,agent_group_ids:[]}),children:"All groups (visible to all)"}),(0,t.jsx)(h.VD,{}),ez.map(e=>{var a;return(0,t.jsxs)(h.bO,{checked:(null===(a=rT.agent_group_ids)||void 0===a?void 0:a.includes(e.id))||!1,onCheckedChange:a=>{let s=rT.agent_group_ids||[];a?rU({...rT,agent_group_ids:[...s,e.id]}):rU({...rT,agent_group_ids:s.filter(a=>a!==e.id)})},children:[(0,t.jsx)(ah.Z,{className:"h-3 w-3 mr-2"}),e.name]},e.id)})]})]})]}),(0,t.jsxs)("div",{className:"flex gap-2 items-center",children:[(0,t.jsx)(p._,{className:"text-xs text-muted-foreground whitespace-nowrap",children:"Assign to branch:"}),(0,t.jsxs)(o.Ph,{value:rT.branch_id||"_none",onValueChange:e=>rU({...rT,branch_id:"_none"===e?void 0:e}),children:[(0,t.jsx)(o.i4,{className:"flex-1 h-8",children:(0,t.jsx)(o.ki,{placeholder:"No branch (visible to all)"})}),(0,t.jsxs)(o.Bw,{children:[(0,t.jsx)(o.Ql,{value:"_none",children:"No branch (visible to all)"}),rG.map(e=>(0,t.jsx)(o.Ql,{value:e.id,children:(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(ep.Z,{className:"h-3 w-3"}),e.name]})},e.id))]})]})]}),(0,t.jsxs)("div",{className:"flex gap-2 justify-end",children:[(0,t.jsx)(d.z,{size:"sm",variant:"outline",className:"h-8 px-3",onClick:()=>rU(null),children:"Cancel"}),(0,t.jsxs)(d.z,{size:"sm",className:"h-8 px-3",onClick:iD,disabled:r8,children:[r8?(0,t.jsx)(w.Z,{className:"h-3 w-3 animate-spin mr-1"}):null,"Save"]})]})]}):(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[(0,t.jsx)("div",{className:"w-3 h-3 rounded-full",style:{backgroundColor:e.color}}),(0,t.jsx)("span",{className:"text-sm font-medium",children:e.name}),e.is_default&&(0,t.jsx)(c.C,{variant:"secondary",className:"text-[10px] h-4",children:"Default"}),e.agent_group_names&&e.agent_group_names.length>0?(0,t.jsxs)(c.C,{variant:"outline",className:"text-[10px] h-4",children:[(0,t.jsx)(ah.Z,{className:"h-2.5 w-2.5 mr-1"}),1===e.agent_group_names.length?e.agent_group_names[0]:"".concat(e.agent_group_names.length," groups")]}):e.agent_group_name&&(0,t.jsxs)(c.C,{variant:"outline",className:"text-[10px] h-4",children:[(0,t.jsx)(ah.Z,{className:"h-2.5 w-2.5 mr-1"}),e.agent_group_name]}),e.branch_name&&(0,t.jsxs)(c.C,{variant:"outline",className:"text-[10px] h-4 bg-blue-50 text-blue-700 border-blue-200",children:[(0,t.jsx)(ep.Z,{className:"h-2.5 w-2.5 mr-1"}),e.branch_name]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1",children:[(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0",onClick:()=>rU({id:e.id,name:e.name,color:e.color,agent_group_ids:e.agent_group_ids||[],branch_id:e.branch_id}),children:(0,t.jsx)(K.Z,{className:"h-3 w-3"})}),(0,t.jsx)(d.z,{size:"sm",variant:"ghost",className:"h-7 w-7 p-0 text-destructive hover:text-destructive disabled:text-muted-foreground disabled:opacity-50",onClick:()=>iE(e.id,e.name),disabled:r8||e.is_default,title:e.is_default?"Cannot delete default pipeline":"Delete pipeline",children:(0,t.jsx)(X.Z,{className:"h-3 w-3"})})]})]})})},e.id)),0===rE.length&&(0,t.jsx)("div",{className:"text-center py-4 text-muted-foreground text-sm",children:"No pipelines found. Create one above."})]})]})]}),(0,t.jsx)(D.cN,{className:"px-6 py-3 border-t flex-shrink-0",children:(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>rB(!1),children:"Close"})})]})}),(0,t.jsx)(am.aR,{open:r7.open,onOpenChange:e=>!e&&ne({open:!1,pipelineId:"",pipelineName:"",leadsCount:0,warning:""}),children:(0,t.jsxs)(am._T,{children:[(0,t.jsxs)(am.fY,{children:[(0,t.jsxs)(am.f$,{className:"flex items-center gap-2 text-destructive",children:[(0,t.jsx)(X.Z,{className:"h-5 w-5"}),'Delete Pipeline "',r7.pipelineName,'"?']}),(0,t.jsx)(am.yT,{className:"space-y-3",children:(0,t.jsxs)("div",{className:"p-3 bg-destructive/10 border border-destructive/20 rounded-lg",children:[(0,t.jsxs)("p",{className:"text-destructive font-medium",children:["This will permanently delete ",r7.leadsCount," lead",1!==r7.leadsCount?"s":""," in this pipeline."]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:"This action cannot be undone."})]})})]}),(0,t.jsxs)(am.xo,{children:[(0,t.jsx)(am.le,{disabled:r8,children:"Cancel"}),(0,t.jsxs)(am.OL,{onClick:iL,disabled:r8,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:[r8?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin mr-2"}):(0,t.jsx)(X.Z,{className:"h-4 w-4 mr-2"}),"Delete Pipeline & ",r7.leadsCount," Leads"]})]})]})}),(0,t.jsx)(D.Vq,{open:rX,onOpenChange:r0,children:(0,t.jsxs)(D.cZ,{className:"max-w-sm",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(eZ.Z,{className:"h-5 w-5 text-primary"}),"Create New Branch"]}),(0,t.jsx)(D.Be,{children:"Create a branch to organize your pipelines by team or location."})]}),(0,t.jsxs)("div",{className:"py-4 space-y-4",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Branch 
1Name *"}),(0,t.jsx)(u.I,{placeholder:"e.g., Sales Team, New York Office",value:r1,onChange:e=>r5(e.target.value)})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Branch Code (optional)"}),(0,t.jsx)(u.I,{placeholder:"e.g., SALES, NYC",value:r2,onChange:e=>r4(e.target.value.toUpperCase()),maxLength:10}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Auto-generated if left empty"})]})]}),(0,t.jsxs)(D.cN,{children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>r0(!1),children:"Cancel"}),(0,t.jsxs)(d.z,{onClick:iw,disabled:r3||!r1.trim(),children:[r3?(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin mr-2"}):null,"Create Branch"]})]})]})}),(0,t.jsx)(D.Vq,{open:r_,onOpenChange:ry,children:(0,t.jsxs)(D.cZ,{className:"max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(e_.Z,{className:"h-5 w-5 text-primary"}),"Move to CRM Pipeline"]}),(0,t.jsx)(D.Be,{children:"Select a CRM pipeline to move this lead to. The lead will be removed from the current leads pipeline."})]}),(0,t.jsxs)("div",{className:"py-4 space-y-4",children:[rk&&(0,t.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-muted/50 rounded-lg",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-full bg-primary/10 flex items-center justify-center",children:(0,t.jsx)(eu.Z,{className:"h-5 w-5 text-primary"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium",children:rk.name}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:rk.email||rk.phone||"No contact info"})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{children:"Select Pipeline"}),rz?(0,t.jsx)("div",{className:"flex items-center justify-center py-8",children:(0,t.jsx)(w.Z,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):0===rS.length?(0,t.jsxs)("div",{className:"text-center py-6 text-muted-foreground",children:[(0,t.jsx)(M.Z,{className:"h-10 w-10 mx-auto mb-2 opacity-50"}),(0,t.jsx)("p",{className:"text-sm",children:"No pipelines found"}),(0,t.jsx)("p",{className:"text-xs mt-1",children:"Create pipelines in the CRM section first"}),(0,t.jsx)(d.z,{variant:"link",size:"sm",className:"mt-2",onClick:()=>{ry(!1),W.push("/dashboard/crm")},children:"Go to CRM"})]}):(0,t.jsx)("div",{className:"space-y-2 max-h-[250px] overflow-y-auto",children:rS.map(e=>(0,t.jsxs)("div",{className:"flex items-center gap-3 p-3 border rounded-lg cursor-pointer transition-all ".concat(rF===e.id?"border-primary bg-primary/5":"hover:border-muted-foreground/50"),onClick:()=>iY(e.id),children:[(0,t.jsx)("div",{className:"w-4 h-4 rounded-full border-2 flex items-center justify-center transition-all",style:{borderColor:rF===e.id?e.color||"#3B82F6":"#d1d5db",backgroundColor:rF===e.id?e.color||"#3B82F6":"transparent"},children:rF===e.id&&(0,t.jsx)("div",{className:"w-2 h-2 rounded-full bg-white"})}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:e.color||"#3B82F6"}}),(0,t.jsx)("p",{className:"font-medium text-sm",children:e.name})]}),e.description&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-0.5",children:e.description}),e.stages&&(0,t.jsxs)("p",{className:"text-xs text-muted-foreground mt-0.5",children:[e.stages.length," stages"]})]})]},e.id))})]})]}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>{ry(!1),rC(null),rA(null)},children:"Cancel"}),(0,t.jsx)(d.z,{onClick:iW,disabled:rP||!rF,children:rP?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Moving to CRM..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(e_.Z,{className:"h-4 w-4 mr-2"}),"Move to CRM"]})})]})]})}),(0,t.jsx)(D.Vq,{open:nN,onOpenChange:e=>{nw(e),e||(ny(null),nC(""))},children:(0,t.jsxs)(D.cZ,{className:"max-w-md",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(eZ.Z,{className:"h-5 w-5 text-indigo-500"}),"Reassign to Pipeline"]}),(0,t.jsxs)(D.Be,{children:["Move ",null==n_?void 0:n_.name," to a different pipeline. The lead will be assigned to the entry stage of the selected pipeline."]})]}),(0,t.jsxs)("div",{className:"space-y-4 py-4",children:[n_&&(0,t.jsxs)("div",{className:"p-3 bg-muted/50 rounded-lg border",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground mb-1",children:"Current Pipeline"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(M.Z,{className:"h-4 w-4 text-primary"}),(0,t.jsx)("span",{className:"font-medium text-sm",children:(null===(b=rE.find(e=>e.id===rR))||void 0===b?void 0:b.name)||"Unknown"})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("p",{className:"text-sm font-medium",children:"Select Target Pipeline"}),(0,t.jsx)("div",{className:"space-y-2 max-h-[200px] overflow-y-auto",children:rE.filter(e=>e.id!==rR).map(e=>(0,t.jsxs)("div",{className:"flex items-center gap-3 p-3 border rounded-lg cursor-pointer transition-all ".concat(nk===e.id?"border-primary bg-primary/5":"hover:border-muted-foreground
1/50"),onClick:()=>nC(e.id),children:[(0,t.jsx)("div",{className:"w-4 h-4 rounded-full border-2 flex items-center justify-center transition-all ".concat(nk===e.id?"border-primary bg-primary":"border-muted-foreground/30"),children:nk===e.id&&(0,t.jsx)(T.Z,{className:"h-3 w-3 text-white"})}),(0,t.jsxs)("div",{className:"flex-1",children:[(0,t.jsx)("p",{className:"font-medium text-sm",children:e.name}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Pipeline"})]})]},e.id))}),0===rE.filter(e=>e.id!==rR).length&&(0,t.jsxs)("div",{className:"text-center py-6 text-muted-foreground",children:[(0,t.jsx)(M.Z,{className:"h-8 w-8 mx-auto mb-2 opacity-50"}),(0,t.jsx)("p",{className:"text-sm",children:"No other pipelines available"})]})]})]}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>{nw(!1),ny(null),nC("")},children:"Cancel"}),(0,t.jsx)(d.z,{onClick:iK,disabled:nS||!nk,children:nS?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Reassigning..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eS.Z,{className:"h-4 w-4 mr-2"}),"Reassign"]})})]})]})}),(0,t.jsx)(eQ.d,{open:J,onOpenChange:ee}),rR&&(null==H?void 0:H.workspace_id)&&(0,t.jsx)(eM.p,{open:lw,onOpenChange:l_,pipelineId:rR,workspaceId:H.workspace_id}),rR&&(null==H?void 0:H.workspace_id)&&(0,t.jsx)(eV,{open:ly,onOpenChange:lk,workspaceId:H.workspace_id,pipelineId:rR,pipelineName:null===(k=rE.find(e=>e.id===rR))||void 0===k?void 0:k.name}),(0,t.jsx)(au.yo,{open:l7,onOpenChange:re,children:(0,t.jsxs)(au.ue,{side:"right",className:"w-[400px] sm:w-[540px] overflow-y-auto",children:[(0,t.jsx)(au.Tu,{className:"mb-4",children:(0,t.jsxs)(au.bC,{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-gradient-to-br from-indigo-500 via-purple-500 to-violet-500 flex items-center justify-center shadow-md",children:(0,t.jsx)(Q.Z,{className:"h-4 w-4 text-white"})}),"Activity Feed",(0,t.jsx)(c.C,{variant:"secondary",className:"ml-2",children:lX.length+ra.length})]})}),(0,t.jsx)("div",{className:"space-y-3",children:l1&&rt?(0,t.jsx)("div",{className:"flex items-center justify-center py-12",children:(0,t.jsx)(w.Z,{className:"h-8 w-8 animate-spin text-indigo-500"})}):(()=>{let e=(e,a)=>{if("ai_call"===a)return(0,t.jsx)(eF.Z,{className:"h-4 w-4"});if("followup"===a)return(0,t.jsx)(eb.Z,{className:"h-4 w-4"});if("stage_change"===a)return(0,t.jsx)(eS.Z,{className:"h-4 w-4"});if("pipeline_change"===a)return(0,t.jsx)(ej.Z,{className:"h-4 w-4"});if("assignment"===a)return(0,t.jsx)(eu.Z,{className:"h-4 w-4"});if("payment"===a)return(0,t.jsx)(ey.Z,{className:"h-4 w-4"});switch(e){case"lead_created":return(0,t.jsx)(_.Z,{className:"h-4 w-4"});case"stage_changed":return(0,t.jsx)(eS.Z,{className:"h-4 w-4"});case"ai_call_completed":return(0,t.jsx)(eF.Z,{className:"h-4 w-4"});case"ai_call_initiated":return(0,t.jsx)(R.Z,{className:"h-4 w-4"});case"followup_completed":return(0,t.jsx)(T.Z,{className:"h-4 w-4"});case"followup_created":return(0,t.jsx)(eb.Z,{className:"h-4 w-4"});case"agent_assigned":return(0,t.jsx)(eu.Z,{className:"h-4 w-4"});case"added_to_crm":return(0,t.jsx)(ej.Z,{className:"h-4 w-4"});case"payment_received":case"payment_pending":case"payment_failed":case"payment_refunded":return(0,t.jsx)(ey.Z,{className:"h-4 w-4"});default:return(0,t.jsx)(Q.Z,{className:"h-4 w-4"})}},a=e=>{switch(e){case"conversion_alert":return(0,t.jsx)(ak.Z,{className:"h-4 w-4"});case"bottleneck_detected":return(0,t.jsx)(ew.Z,{className:"h-4 w-4"});
1case"recommendation":return(0,t.jsx)(aC.Z,{className:"h-4 w-4"});case"trend":return(0,t.jsx)(B.Z,{className:"h-4 w-4"});case"milestone":return(0,t.jsx)(aS.Z,{className:"h-4 w-4"});case"health_check":return(0,t.jsx)(aZ.Z,{className:"h-4 w-4"});case"opportunity":return(0,t.jsx)(aF.Z,{className:"h-4 w-4"});default:return(0,t.jsx)(aA.Z,{className:"h-4 w-4"})}},s=e=>{switch(e){case"critical":return{bg:"bg-gradient-to-r from-rose-50 to-red-50 dark:from-rose-900/20 dark:to-red-900/20",iconBg:"bg-gradient-to-br from-rose-500 to-red-500",border:"border-l-rose-500"};case"warning":return{bg:"bg-gradient-to-r from-amber-50 to-orange-50 dark:from-amber-900/20 dark:to-orange-900/20",iconBg:"bg-gradient-to-br from-amber-500 to-orange-500",border:"border-l-amber-500"};default:return{bg:"bg-gradient-to-r from-cyan-50 to-blue-50 dark:from-cyan-900/20 dark:to-blue-900/20",iconBg:"bg-gradient-to-br from-cyan-500 to-blue-500",border:"border-l-cyan-500"}}},l=(e,a,s)=>{"added_to_crm"===s&&(e="blue");let t={green:{bg:"bg-gradient-to-r from-emerald-50 to-green-50 dark:from-emerald-900/20 dark:to-green-900/20",iconBg:"bg-gradient-to-br from-emerald-500 to-green-500",border:"border-l-emerald-500"},blue:{bg:"bg-gradient-to-r from-blue-50 to-cyan-50 dark:from-blue-900/20 dark:to-cyan-900/20",iconBg:"bg-gradient-to-br from-blue-500 to-cyan-500",border:"border-l-blue-500"},purple:{bg:"bg-gradient-to-r from-purple-50 to-violet-50 dark:from-purple-900/20 dark:to-violet-900/20",iconBg:"bg-gradient-to-br from-purple-500 to-violet-500",border:"border-l-purple-500"},indigo:{bg:"bg-gradient-to-r from-indigo-50 to-blue-50 dark:from-indigo-900/20 dark:to-blue-900/20",iconBg:"bg-gradient-to-br from-indigo-500 to-blue-500",border:"border-l-indigo-500"},amber:{bg:"bg-gradient-to-r from-amber-50 to-yellow-50 dark:from-amber-900/20 dark:to-yellow-900/20",iconBg:"bg-gradient-to-br from-amber-500 to-yellow-500",border:"border-l-amber-500"},red:{bg:"bg-gradient-to-r from-red-50 to-rose-50 dark:from-red-900/20 dark:to-rose-900/20",iconBg:"bg-gradient-to-br from-red-500 to-rose-500",border:"border-l-red-500"},orange:{bg:"bg-gradient-to-r from-orange-50 to-amber-50 dark:from-orange-900/20 dark:to-amber-900/20",iconBg:"bg-gradient-to-br from-orange-500 to-amber-500",border:"border-l-orange-500"}};return e?t[e]||t.indigo:"ai_call"===a?t.green:"followup"===a?t.amber:"stage_change"===a?t.purple:"assignment"===a?t.blue:"payment"===a?t.green:t.indigo},r=e=>{let a=new Date(e),s=new Date().getTime()-a.getTime(),t=Math.floor(s/6e4),l=Math.floor(s/36e5),r=Math.floor(s/864e5);return t<1?"Just now":t<60?"".concat(t,"m ago"):l<24?"".concat(l,"h ago"):1===r?"Yesterday":"".concat(r,"d ago")},n=[...lX.map(e=>({type:"activity",data:e,created_at:e.created_at})),...ra.map(e=>({type:"insight",data:e,created_at:e.created_at}))].sort((e,a)=>new Date(a.created_at).getTime()-new Date(e.created_at).getTime());return 0===n.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[(0,t.jsx)(Q.Z,{className:"h-12 w-12 text-indigo-200 mb-3"}),(0,t.jsx)("p",{className:"text-muted-foreground",children:"No recent activity"})]}):n.map(n=>{if("insight"===n.type){let e=n.data,l=s(e.severity);return(0,t.jsx)("div",{className:"".concat(l.bg," rounded-lg p-3 border-l-4 ").concat(l.border," hover:shadow-md transition-all cursor-pointer ring-1 ring-amber-200/50"),children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsxs)("div",{className:"h-9 w-9 rounded-lg ".concat(l.iconBg," flex items-center justify-center flex-shrink-0 shadow-sm relative"),children:[(0,t.jsx)("span",{className:"text-white",children:a(e.insight_type)}),(0,t.jsx)(eg.Z,{className:"h-3 w-3 text-yellow-300 absolute -top-1 -right-1"})]}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("p",{className:"text-sm font-semibold text-foreground leading-tight",children:e.title}),(0,t.jsx)("span",{className:"text-[9px] font-bold text-amber-600 bg-amber-100 px-1.5 py-0.5 rounded-full",children:"AI"})]}),e.description&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:e.description}),e.recommendations&&e.recommendations.length>0&&(0,t.jsx)("div",{className:"mt-2 space-y-1",children:e.recommendations.slice(0,2).map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center gap-1.5 text-[10px] text-amber-700",children:[(0,t.jsx)(aC.Z,{className:"h-3 w-3 flex-shrink-0"}),(0,t.jsx)("span",{className:"line-clamp-1",children:e})]},a))}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mt-2",children:[(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground",children:r(e.created_at)}),(0,t.jsx)("span",{className:"text-muted-foreground",children:"•"}),(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground flex items-center gap-1",children:[(0,t.jsx)(aA.Z,{className:"h-3 w-3"}),"AI Agent"]})]})]})]})},"insight-".concat(e.id))}let i=n.data,d=l(i.color,i.item_type,i.activity_type);return(0,t.jsx)("div",{className:"".concat(d.bg," rounded-lg p-3 border-l-4 ").concat(d.border," hover:shadow-md transition-all cursor-pointer"),children:(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("div",{className:"h-9 w-9 rounded-lg ".concat(d.iconBg," flex items-center justify-center flex-shrink-0 shadow-sm"),children:(0,t.jsx)("span",{className:"text-white",children:e(i.activity_type,i.item_type)})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"text-sm font-semibold text-foreground leading-tight",children:i.title}),i.description&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground mt-1 line-clamp-2",children:i.description}),(0,t.jsxs)("div",{className:"flex items-center gap-2 mt-2",children:[(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground",children:r(i.created_at)}),i.created_by_name&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"text-muted-foreground",children:"•"}),(0,t.jsxs)("span",{className:"text-[10px] text-muted-foreground flex items-center gap-1",children:[(0,t.jsx)(eu.Z,{className:"h-3 w-3"}),i.created_by_name]})]})]})]})]})},"activity-".concat(i.id))})})()})]})}),(0,t.jsx)(D.Vq,{open:nF,onOpenChange:e=>{nA(e),e||iA()},children:(0,t.jsxs)(D.cZ,{className:"sm:max-w-[600px] max-h-[85vh] overflow-hidden flex flex-col",children:[(0,t.jsxs)(D.fK,{children:[(0,t.jsxs)(D.$N,{className:"flex items-center gap-2",children:[(0,t.jsx)(ay.Z,{className:"h-5 w-5 text-emerald-600"}),"Create Segment from Tag"]}),(0,t.jsxs)(D.Be,{children:[1===nP&&"Step 1: Select a column and value to filter leads",2===nP&&"Step 2: Review and select leads for the segment",3===nP&&"Step 3: Choose where to save the segment"]})]}),(0,t.jsx)("div",{className:"flex items-center justify-center gap-2 py-3 border-b",children:[1,2,3].map(e=>(0,t.jsxs)("div",{className:"flex items-center",children:[(0,t.jsx)("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-sm font-medium transition-colors ".concat(nP===e?"bg-emerald-600 text-white":nP>e?"bg-emerald-100 text-emerald-700 border border-emerald-300":"bg-gray-100 text-gray-400"),children:nP>e?"✓":e}),e<3&&(0,t.jsx)("div",{className:"w-12 h-0.5 mx-1 ".concat(nP>e?"bg-emerald-400":"bg-gray-200")})]},e))}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto py-4 space-y-4",children:[1===nP&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Select Column (Tag)"}),nq?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}),"Loading columns..."]}):0===nE.length?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No columns found for this pipeline"}):(0,t.jsxs)(o.Ph,{value:nR||"",onValueChange:e=>nM(e),children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:"Select a column"})}),(0,t.jsx)(o.Bw,{children:nE.filter(e=>e&&e.trim()).map(e=>(0,t.jsx)(o.Ql,{value:e,children:e},e))})]})]}),nR&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Select Value"}),nQ?(0,t.jsxs)("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 animate-spin"}),"Loading values..."]}):0===nO.length?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No values found for this column"}):(0,t.jsx)("div",{className:"max-h-[200px] overflow-y-auto border rounded-lg p-2 space-y-1",children:nO.filter(e=>e.value&&e.value.trim()).map(e=>(0,t.jsxs)("div",{onClick:()=>nU(e.value),className:"px-3 py-2 rounded-md cursor-pointer transition-colors flex items-center justify-between ".concat(nT===e.value?"bg-emerald-100 text-emerald-800 border border-emerald-300":"hover:bg-gray-100"),children:[(0,t.jsx)("span",{children:e.value}),(0,t.jsx)(c.C,{variant:"secondary",className:"ml-2",children:e.count})]},e.value))})]}),nR&&nT&&(0,t.jsxs)("div",{className:"bg-emerald-50 border border-emerald-200 rounded-lg p-3",children:[(0,t.jsxs)("p",{className:"text-sm text-emerald-800",children:[(0,t.jsx)("span",{className:"font-medium",children:"Selected:"})," ",nR,' = "',nT,'"']}),(0,t.jsxs)("p",{className:"text-xs text-emerald-600 mt-1",children:[(null===(F=nO.find(e=>e.value===nT))||void 0===F?void 0:F.count)||0," leads found"]}
1)]})]}),2===nP&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"Segment Name"}),(0,t.jsx)(u.I,{value:nY,onChange:e=>n$(e.target.value),placeholder:"Enter segment name"})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsxs)(p._,{className:"text-sm font-medium",children:["Leads (",nG.size," of ",nK.length," selected)"]}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>nJ(new Set(nK.map(e=>e.id))),children:"Select All"}),(0,t.jsx)(d.z,{variant:"outline",size:"sm",onClick:()=>nJ(new Set),children:"Deselect All"})]})]}),nX?(0,t.jsxs)("div",{className:"flex items-center justify-center py-8",children:[(0,t.jsx)(w.Z,{className:"h-6 w-6 animate-spin text-emerald-600"}),(0,t.jsx)("span",{className:"ml-2 text-sm text-muted-foreground",children:"Loading leads..."})]}):0===nK.length?(0,t.jsx)("p",{className:"text-sm text-muted-foreground py-4 text-center",children:"No leads found"}):(0,t.jsx)("div",{className:"max-h-[250px] overflow-y-auto border rounded-lg divide-y",children:nK.map(e=>(0,t.jsxs)("div",{onClick:()=>{let a=new Set(nG);a.has(e.id)?a.delete(e.id):a.add(e.id),nJ(a)},className:"px-3 py-2 cursor-pointer transition-colors flex items-center gap-3 ".concat(nG.has(e.id)?"bg-emerald-50":"hover:bg-gray-50"),children:[(0,t.jsx)("input",{type:"checkbox",checked:nG.has(e.id),onChange:()=>{},className:"h-4 w-4 text-emerald-600 rounded border-gray-300 focus:ring-emerald-500"}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"text-sm font-medium truncate",children:e.name||"Unknown"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground truncate",children:e.email||e.phone||"No contact info"})]}),e.company&&(0,t.jsx)("span",{className:"text-xs text-muted-foreground",children:e.company})]},e.id))})]})]}),3===nP&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"space-y-3",children:[(0,t.jsx)(p._,{className:"text-sm font-medium",children:"What would you like to do?"}),(0,t.jsxs)("div",{onClick:()=>n5("pipeline"),className:"p-4 rounded-lg border-2 cursor-pointer transition-all ".concat("pipeline"===n1?"border-emerald-500 bg-emerald-50":"border-gray-200 hover:border-gray-300"),children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("input",{type:"radio",checked:"pipeline"===n1,onChange:()=>n5("pipeline"),className:"h-4 w-4 text-emerald-600 focus:ring-emerald-500"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium",children:"Create Pipeline"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Create segment and a new pipeline with these leads"})]})]}),"pipeline"===n1&&(0,t.jsxs)("div",{className:"mt-4 pl-7 space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Pipeline Type"}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{type:"button",variant:"lead"===n2?"default":"outline",size:"sm",onClick:()=>n4("lead"),className:"lead"===n2?"bg-emerald-600 hover:bg-emerald-700":"",children:"Lead Pipeline"}),(0,t.jsx)(d.z,{type:"button",variant:"crm"===n2?"default":"outline",size:"sm",onClick:()=>n4("crm"),className:"crm"===n2?"bg-emerald-600 hover:bg-emerald-700":"",children:"CRM Pipeline"})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Pipeline Name"}),(0,t.jsx)(u.I,{value:n3,onChange:e=>n6(e.target.value),placeholder:"Enter pipeline name"})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(p._,{className:"text-sm",children:"Template"}),(0,t.jsxs)(o.Ph,{value:n8,onValueChange:n9,children:[(0,t.jsx)(o.i4,{children:(0,t.jsx)(o.ki,{placeholder:"Select template"})}),(0,t.jsx)(o.Bw,{children:"lead"===n2?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.Ql,{value:"sales",children:"Sales (7 stages)"}),(0,t.jsx)(o.Ql,{value:"onboarding",children:"Onboarding (6 stages)"}),(0,t.jsx)(o.Ql,{value:"support",children:"Support (5 stages)"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(o.Ql,{value:"sales",children:"Sales (6 stages)"}),(0,t.jsx)(o.Ql,{value:"course",children:"Course (6 stages)"}),(0,t.jsx)(o.Ql,{value:"fees",children:"Fees (4 stages)"})]})})]})]})]})]}),(0,t.jsx)("div",{onClick:()=>n5("segment_only"),className:"p-4 rounded-lg border-2 cursor-pointer transition-all ".concat("segment_only"===n1?"border-emerald-500 bg-emerald-50":"border-gray-200 hover:border-gray-300"),children:(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("input",{type:"radio",checked:"segment_only"===n1,onChange:()=>n5("segment_only"),className:"h-4 w-4 text-emerald-600 focus:ring-emerald-500"}),(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"font-medium",children:"Create Segment Only"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Just create the segment. You can add to pipeline later from Segments page."})]})]})})]}),(0,t.jsxs)("div",{className:"bg-emerald-50 border border-emerald-200 rounded-lg p-3 mt-4",children:[(0,t.jsx)("p",{className:"text-sm text-emerald-800 font-medium",children:"Summary"}),(0,t.jsxs)("ul",{className:"text-sm text-emerald-700 mt-2 space-y-1",children:[(0,t.jsxs)("li",{children:["• Segment Name: ",(0,t.jsx)("strong",{children:nY})]}),(0,t.jsxs)("li",{children:["• Leads: ",(0,t.jsx)("strong",{children:nG.size})]}),(0,t.jsxs)("li",{children:["• Filter: ",nR,' = "',nT,'"']}),"pipeline"===n1&&n3&&(0,t.jsxs)("li",{children:["• New Pipeline: ",(0,t.jsx)("strong",{children:n3})," (","lead"===n2?"Lead":"CRM",")"]})]})]})]})]}),(0,t.jsxs)("div",{className:"flex justify-between gap-2 pt-4 border-t",children:[(0,t.jsx)("div",{children:nP>1&&(0,t.jsx)(d.z,{variant:"outline",onClick:()=>nD(nP-1),children:"Back"})}),(0,t.jsxs)("div",{className:"flex gap-2",children:[(0,t.jsx)(d.z,{variant:"outline",onClick:()=>nA(!1),children:"Cancel"}),nP<3?(0,t.jsx)(d.z,{onClick:()=>iz(nP+1),disabled:1===nP&&(!nR||!nT)||2===nP&&(0===nG.size||!nY.trim()),className:"bg-emerald-600 hover:bg-emerald-700",children:"Next"}):(0,t.jsx)(d.z,{onClick:iF,disabled:n7||0===nG.size||"pipeline"===n1&&!n3.trim(),className:"bg-emerald-600 hover:bg-emerald-700",children:n7?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(w.Z,{className:"h-4 w-4 mr-2 animate-spin"}),"Creating..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ay.Z,{className:"h-4 w-4 mr-2"}),"pipeline"===n1?"Create Segment & Pipeline":"Create Segment"]})})]})]})]})})]})})}},55589:function(e,a,s){s.d(a,{nb:function(){return t}});let t={hot:{emoji:"\uD83D\uDE00",label:"Hot Lead",description:"Highly interested",color:"#22C55E",bgColor:"bg-green-100 dark:bg-green-900/30",borderColor:"border-green-300 dark:border-green-700",textColor:"text-green-700 dark:text-green-300"},warm:{emoji:"\uD83D\uDE10",label:"Warm Lead",description:"Somewhat interested",color:"#F59E0B",bgColor:"bg-
1amber-100 dark:bg-amber-900/30",borderColor:"border-amber-300 dark:border-amber-700",textColor:"text-amber-700 dark:text-amber-300"},cold:{emoji:"\uD83D\uDE1E",label:"Cold Lead",description:"Not interested",color:"#6B7280",bgColor:"bg-gray-100 dark:bg-gray-800/50",borderColor:"border-gray-300 dark:border-gray-600",textColor:"text-gray-600 dark:text-gray-400"}}},93228:function(e,a,s){s.d(a,{$:function(){return i}});var t=s(57437);s(2265);var l=s(99376),r=s(64972),n=s(10407);function i(e){let{href:a="/dashboard/crm/insights"}=e,s=(0,l.useRouter)();return(0,t.jsx)("button",{className:"uiverse-insights group",onClick:()=>s.push(a),children:(0,t.jsxs)("div",{className:"uiverse-wrapper",children:[(0,t.jsx)(r.Z,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 relative z-10"}),(0,t.jsx)("span",{className:"hidden sm:inline text-xs sm:text-sm font-semibold",children:"View Insights"}),(0,t.jsx)(n.Z,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4 relative z-10 group-hover:translate-x-0.5 transition-transform"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-12"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-11"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-10"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-9"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-8"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-7"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-6"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-5"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-4"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-3"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-2"}),(0,t.jsx)("div",{className:"uiverse-circle uiverse-circle-1"})]})})}},91032:function(e,a,s){s.d(a,{Ei:function(){return j},FF:function(){return g},Tu:function(){return h},aM:function(){return o},bC:function(){return f},ue:function(){return p},yo:function(){return c}});var t=s(57437),l=s(2265),r=s(49027),n=s(90535),i=s(20653),d=s(93448);let c=r.fC,o=r.xz;r.x8;let m=r.h_,u=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)(r.aV,{className:(0,d.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",s),...l,ref:a})});u.displayName=r.aV.displayName;let x=(0,n.j)("fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=closed]:duration-300 data-[state=open]:duration-500 data-[state=open]:animate-in data-[state=closed]:animate-out",{variants:{side:{top:"inset-x-0 top-0 border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",bottom:"inset-x-0 bottom-0 border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",left:"inset-y-0 left-0 h-full w-3/4 border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left sm:max-w-sm",right:"inset-y-0 right-0 h-full w-3/4 border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right sm:max-w-sm"}},defaultVariants:{side:"right"}}),p=l.forwardRef((e,a)=>{let{side:s="right",className:l,children:n,...c}=e;return(0,t.jsxs)(m,{children:[(0,t.jsx)(u,{}),(0,t.jsxs)(r.VY,{ref:a,className:(0,d.cn)(x({side:s}),l),...c,children:[(0,t.jsxs)(r.x8,{className:"absolute right-4 top-4 roun
1ded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary",children:[(0,t.jsx)(i.Pxu,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"sr-only",children:"Close"})]}),n]})]})});p.displayName=r.VY.displayName;let h=e=>{let{className:a,...s}=e;return(0,t.jsx)("div",{className:(0,d.cn)("flex flex-col space-y-2 text-center sm:text-left",a),...s})};h.displayName="SheetHeader";let g=e=>{let{className:a,...s}=e;return(0,t.jsx)("div",{className:(0,d.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",a),...s})};g.displayName="SheetFooter";let f=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)(r.Dx,{ref:a,className:(0,d.cn)("text-lg font-semibold text-foreground",s),...l})});f.displayName=r.Dx.displayName;let j=l.forwardRef((e,a)=>{let{className:s,...l}=e;return(0,t.jsx)(r.dk,{ref:a,className:(0,d.cn)("text-sm text-muted-foreground",s),...l})});j.displayName=r.dk.displayName},73009:function(e,a,s){s.d(a,{Pz:function(){return l},Qj:function(){return r}});var t=s(71837);async function l(e,a){var s;return(await t.api.get("/branches",{params:{workspace_id:e,active_only:null===(s=null==a?void 0:a.activeOnly)||void 0===s||s,region_id:null==a?void 0:a.regionId}})).data}async function r(e,a){return(await t.api.post("/branches/quick",a,{params:{workspace_id:e}})).data}},3362:function(e,a,s){s.d(a,{GT:function(){return r},_w:function(){return l},or:function(){return i},tR:function(){return d},uy:function(){return n}});var t=s(71837);async function l(e){return(await t.api.get("/ads/pipelines/available",{params:{workspace_id:e}})).data.pipelines}async function r(e,a){var s;return(await t.api.get("/ads/campaigns/with-pipelines",{params:{workspace_id:e,platform:null==a?void 0:a.platform,account_id:null==a?void 0:a.accountId,include_unmapped:null===(s=null==a?void 0:a.includeUnmapped)||void 0===s||s}})).data}async function n(e,a,s){return(await t.api.post("/ads/campaigns/".concat(e,"/pipeline"),s,{params:{workspace_id:a}})).data.mapping}async function i(e,a){await t.api.delete("/ads/campaigns/".concat(e,"/pipeline"),{params:{workspace_id:a}})}let d={getAvailablePipelines:l,getCampaignsWithPipelines:r,getCampaignPipelineMapping:async function(e,a){return(await t.api.get("/ads/campaigns/".concat(e,"/pipeline"),{params:{workspace_id:a}})).data.mapping},setCampaignPipelineMapping:n,removeCampaignPipelineMapping:i,bulkSetCampaignPipelineMappings:async function(e,a){return(await t.api.post("/ads/campaigns/bulk-pipeline",{campaign_mappings:a},{params:{workspace_id:e}})).data}}},8544:function(e,a,s){s.d(a,{S:function(){return l}});var t=s(71837);let l={getLeadHistory:async(e,a)=>(await t.api.get("/lead-activity/lead/".concat(e),{params:a})).data,getAllActivities:async e=>(await t.api.get("/lead-activity",{params:e})).data,getActivityTypes:async()=>(await t.api.get("/lead-activity/types")).data}}}]);

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.