call-control-sdk 6.4.5-dev.0 → 6.4.5-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,2 +1,3840 @@
1
- var Sn=Object.defineProperty,Tn=Object.defineProperties;var vn=Object.getOwnPropertyDescriptors;var Qo=Object.getOwnPropertySymbols;var Dn=Object.prototype.hasOwnProperty,Ln=Object.prototype.propertyIsEnumerable;var lt=(e,o,t)=>o in e?Sn(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,c=(e,o)=>{for(var t in o||(o={}))Dn.call(o,t)&&lt(e,t,o[t]);if(Qo)for(var t of Qo(o))Ln.call(o,t)&&lt(e,t,o[t]);return e},F=(e,o)=>Tn(e,vn(o));var ie=(e,o,t)=>lt(e,typeof o!="symbol"?o+"":o,t);var Qe="uat-cti.aighospitals.com",H=`https://${Qe}:8095`,_n=`wss://${Qe}:8095`,K={v1:"/api/v1"},_={LOGIN:`${H}${K.v1}/cti/login?provider=convox`,READY_AGENT:`${H}${K.v1}/cti/ready-agent?provider=convox`,UPDATE_AGENT_BREAK:`${H}${K.v1}/cti/update-agent-status?provider=convox`,CLICK_TO_CALL:`${H}${K.v1}/cti/calls?provider=convox`,HOLD_CALL:`${H}${K.v1}/cti/calls/hold?provider=convox`,MUTE_CALL:`${H}${K.v1}/cti/calls/mute?provider=convox`,UNMUTE_CALL:`${H}${K.v1}/cti/unmute-call?provider=convox`,END_CALL:`${H}${K.v1}/cti/calls/end?provider=convox`,LOGOUT:`${H}${K.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${H}${K.v1}/cti/calls/conference?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${H}${K.v1}/cti/calls/conference/hold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${H}${K.v1}/cti/calls/conference/mute?provider=convox`,CONFERENCE_CALL_END:`${H}${K.v1}/cti/calls/conference/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${H}${K.v1}/cti/calls/conference/hangup/all?provider=convox`,TRANSFER_CALL:`${H}${K.v1}/cti/calls/transfer?provider=convox`,AGENTS_LIST:`${H}${K.v1}/cti/users`,PROCESS_LIST:`${H}${K.v1}/cti/processes-list`,TRANSFER_TO_DETAILS:`${H}${K.v1}/cti/transfer-to-details?provider=convox`,CALL_HISTORY:`${H}${K.v1}/dashboard/call-history`,SENTIMENTAL_ANALYSIS:`${H}${K.v1}/users/get_sentiment_analysis`},en={WS:`${_n}${K.v1}/cti/ws`},me="call-control-sdk-state";var rt=class{constructor(){ie(this,"state");ie(this,"listeners",[]);ie(this,"STORAGE_KEY",me);ie(this,"apiKey");ie(this,"tenantId");this.state=this.getInitialState(),this.loadFromStorage()}getInitialState(){return{authorization:void 0,process:null,agentId:"",openConferenceDialog:!1,openCallTransferDialog:!1,isInitialized:!1,sdkConfig:{disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},isHolding:!1,isMuted:!1,status:"idle",callStartTime:null,controlPanelPosition:{x:10,y:10},iframePosition:{x:10,y:80},callData:{agent_id:"",status:"",type:"",event_time:"",phone_number:""},conferenceLine:[{line:1,status:"IDLE",type:"",phone:"",isMute:!1,isHold:!1,isCallStart:!1,isMergeCall:!1},{line:2,status:"IDLE",type:"",phone:"",isMute:!1,isHold:!1,isCallStart:!1,isMergeCall:!1},{line:3,status:"IDLE",type:"",phone:"",isMute:!1,isHold:!1,isCallStart:!1,isMergeCall:!1},{line:4,status:"IDLE",type:"",phone:"",isMute:!1,isHold:!1,isCallStart:!1,isMergeCall:!1},{line:5,status:"IDLE",type:"",phone:"",isMute:!1,isHold:!1,isCallStart:!1,isMergeCall:!1}]}}loadFromStorage(){try{let o=localStorage.getItem(this.STORAGE_KEY);if(o){let t=JSON.parse(o);this.state=F(c({},this.state),{agentId:t.agentId||"",authorization:t.authorization||void 0,process:t.process||null,openConferenceDialog:(t==null?void 0:t.openConferenceDialog)||!1,openCallTransferDialog:(t==null?void 0:t.openCallTransferDialog)||!1,isInitialized:t.isInitialized||!1,sdkConfig:t.sdkConfig||{disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},isHolding:t.isHolding||!1,isMuted:t.isMuted||!1,status:t.status||"idle",callStartTime:t.callStartTime||null,controlPanelPosition:t.controlPanelPosition||{x:10,y:10},iframePosition:t.iframePosition||{x:10,y:80},callData:t.callData||{mobileNumber:"",callReferenceId:"",agent_id:"",status:"",type:"",event_time:"",phone_number:""},conferenceLine:t.conferenceLine&&Array.isArray(t.conferenceLine)&&t.conferenceLine.length>0?t.conferenceLine:this.state.conferenceLine})}}catch(o){console.warn("Failed to load SDK state from localStorage:",o)}}saveToStorage(){try{let o={agentId:this.state.agentId,authorization:this.state.authorization,process:this.state.process,isInitialized:this.state.isInitialized,openConferenceDialog:this.state.openConferenceDialog,openCallTransferDialog:this.state.openCallTransferDialog,sdkConfig:this.state.sdkConfig,isHolding:this.state.isHolding,isMuted:this.state.isMuted,status:this.state.status,callStartTime:this.state.callStartTime,controlPanelPosition:this.state.controlPanelPosition,iframePosition:this.state.iframePosition,callData:this.state.callData,conferenceLine:this.state.conferenceLine};localStorage.setItem(this.STORAGE_KEY,JSON.stringify(o))}catch(o){console.warn("Failed to save SDK state to localStorage:",o)}}notifyListeners(){this.listeners.forEach(o=>o())}validateCredentials(o,t){if(!o||typeof o!="string"||o.trim().length===0)throw new Error("API key not available");if(!t||typeof t!="string"||t.trim().length===0)throw new Error("Tenant ID not available");this.apiKey=o.trim(),this.tenantId=t.trim()}initialize(o,t,i,l,s){if(this.validateCredentials(o,t),!i||typeof i!="string"||i.trim().length===0)throw new Error("Agent ID not available");this.state.agentId=i,this.state.openConferenceDialog=!1,this.state.openCallTransferDialog=!1,this.state.authorization=s,this.state.sdkConfig=c({disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},l),this.state.isInitialized=!0,this.saveToStorage(),this.notifyListeners()}getState(){return c({},this.state)}getCredentials(){return{apiKey:this.apiKey,tenantId:this.tenantId}}getSdkAuthToken(){var o;return(o=this.state.authorization)==null?void 0:o.accessToken}subscribe(o){return this.listeners.push(o),()=>{let t=this.listeners.indexOf(o);t>-1&&this.listeners.splice(t,1)}}setHolding(o){this.state.isHolding=o,this.saveToStorage(),this.notifyListeners()}setMuted(o){this.state.isMuted=o,this.saveToStorage(),this.notifyListeners()}setStatus(o){this.state.status=o,this.saveToStorage(),this.notifyListeners()}setProcess(o){this.state.process=o,this.saveToStorage(),this.notifyListeners()}setControlPanelPosition(o){this.state.controlPanelPosition=o,this.saveToStorage(),this.notifyListeners()}setIframePosition(o){this.state.iframePosition=o,this.saveToStorage(),this.notifyListeners()}startCall(){this.state.callStartTime=Date.now(),this.state.status="on call",this.saveToStorage(),this.notifyListeners()}endCall(){this.state.callStartTime=null,this.state.status="idle",this.state.isHolding=!1,this.state.isMuted=!1,this.saveToStorage(),this.notifyListeners()}setInitCheck(){this.state.isInitialized=!1,this.saveToStorage(),this.notifyListeners()}setOpenConferenceDialog(o){this.state.openConferenceDialog=o,this.saveToStorage(),this.notifyListeners()}setOpenCallTransferDialog(o){this.state.openCallTransferDialog=o,this.saveToStorage(),this.notifyListeners()}updateCallData(o){this.state.callData=c(c({},this.state.callData),o),this.saveToStorage(),this.notifyListeners()}updateConferenceData(o){this.state.conferenceLine=[...o],this.saveToStorage(),this.notifyListeners()}setConferenceLine(o){var i;(!this.state.conferenceLine||!Array.isArray(this.state.conferenceLine))&&(console.warn("Conference line data corrupted, resetting to initial state"),this.state.conferenceLine=this.getInitialState().conferenceLine);let t=(i=this.state.conferenceLine)==null?void 0:i.map(l=>l.line===o.line?o:l);this.state.conferenceLine=t,this.saveToStorage(),this.notifyListeners()}resetConferenceLines(){this.state.conferenceLine=this.getInitialState().conferenceLine,this.saveToStorage(),this.notifyListeners()}clearStorageAndReset(){try{localStorage.removeItem(this.STORAGE_KEY),this.state=this.getInitialState(),this.notifyListeners()}catch(o){console.warn("Failed to clear localStorage:",o)}}debugStorage(){try{let o=localStorage.getItem(this.STORAGE_KEY);console.log("Current localStorage data:",o),o&&console.log("Parsed localStorage data:",JSON.parse(o)),console.log("Current state:",this.state)}catch(o){console.error("Error debugging storage:",o)}}getConferenceLines(){return this.state.conferenceLine||[]}},m=new rt;var ct=class{constructor(){ie(this,"config",null);ie(this,"ticketId",null);ie(this,"baseUrl","");ie(this,"eventQueue",[]);ie(this,"flushTimer",null)}async init(o){this.config=c({autoTrack:!0,retryAttempts:3,queueSize:100,flushInterval:5e3},o),this.baseUrl=o.baseUrl||(typeof window!="undefined"?window.location.origin:""),this.setupNetworkDetection();let t=await this.createTicket();return this.startPeriodicFlush(),console.log("EventTracker SDK initialized successfully"),t}isInitialized(){return this.config!==null&&this.ticketId!==null}getConfig(){return this.config}getTicketId(){return this.ticketId}async createTicket(){if(!this.config)throw new Error("EventTracker not initialized");try{let o=await this.makeRequest("/api/v1/et/init",{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.config.apiKey},body:JSON.stringify({agentId:this.config.agentId,sessionId:this.config.sessionId})});if(!o.ok)throw m.setInitCheck(),new Error(`Failed to initialize: ${o.status} ${o.statusText}`);let t=await o.json();return this.ticketId=t.ticketId,this.config.autoTrack&&this.setupAutoTracking(),t}catch(o){throw console.error("EventTracker initialization failed:",o),o}}async logEvent(o,t){if(!this.config||!this.ticketId){console.warn("EventTracker not initialized, skipping event:",o);return}let i={eventType:o,eventData:t,timestamp:Date.now()};this.eventQueue.push(i),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift()}async makeRequest(o,t){var s;let i=`${this.baseUrl}${o}`,l=((s=this.config)==null?void 0:s.retryAttempts)||3;for(let r=1;r<=l;r++)try{return await fetch(i,t)}catch(f){if(r===l)throw f;let b=Math.min(1e3*Math.pow(2,r-1),1e4);await new Promise(x=>setTimeout(x,b))}throw new Error("Max retries exceeded")}setupAutoTracking(){var i;if(typeof window=="undefined"||!((i=this.config)!=null&&i.autoTrack))return;let o=this.config.autoTrack===!0?{}:this.config.autoTrack;if(o.pageVisits!==!1&&this.logEvent("pageVisit",{url:window.location.href,title:document.title,referrer:document.referrer,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},timestamp:new Date().toISOString()}).catch(l=>console.warn("Failed to track page visit:",l)),o.clicks!==!1&&document.addEventListener("click",l=>{var r;let s=l.target;(s.tagName==="BUTTON"||s.tagName==="A"||s.onclick||s.getAttribute("role")==="button"||s instanceof HTMLButtonElement&&s.type==="button")&&this.logEvent("click",{element:s.tagName,text:(r=s.textContent)==null?void 0:r.trim().substring(0,100),href:s.getAttribute("href"),id:s.id,className:s.className,role:s.getAttribute("role"),position:{x:l.clientX,y:l.clientY},timestamp:new Date().toISOString()}).catch(f=>console.warn("Failed to track click:",f))}),o.forms!==!1&&document.addEventListener("submit",l=>{let s=l.target,r=new FormData(s),f={};r.forEach((b,x)=>{f[x]=b.toString()}),this.logEvent("formSubmission",{formId:s.id,action:s.action,method:s.method,fields:Object.keys(f),fieldCount:Object.keys(f).length,timestamp:new Date().toISOString()}).catch(b=>console.warn("Failed to track form submission:",b))}),o.inputs!==!1){let l;document.addEventListener("input",s=>{let r=s.target;(r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.tagName==="SELECT")&&(clearTimeout(l),l=setTimeout(()=>{var f;this.logEvent("fieldChange",{element:r.tagName,type:r.getAttribute("type"),name:r.getAttribute("name"),id:r.id,valueLength:((f=r.value)==null?void 0:f.length)||0,timestamp:new Date().toISOString()}).catch(b=>console.warn("Failed to track field change:",b))},1e3))})}let t=Date.now();window.addEventListener("beforeunload",()=>{let l=Date.now()-t;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:l,timestamp:new Date().toISOString()})}),o.visibility!==!1&&document.addEventListener("visibilitychange",()=>{this.logEvent("visibilityChange",{hidden:document.hidden,visibilityState:document.visibilityState,timestamp:new Date().toISOString()})}),o.errors!==!1&&(window.addEventListener("error",l=>{this.logEvent("jsError",{message:l.message,filename:l.filename,lineno:l.lineno,colno:l.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",l=>{var s;this.logEvent("unhandledRejection",{reason:(s=l.reason)==null?void 0:s.toString(),timestamp:new Date().toISOString()})})),o.performance!==!1&&typeof window.performance!="undefined"&&window.performance.navigation&&window.addEventListener("load",()=>{setTimeout(()=>{let l=window.performance.navigation,s=window.performance.timing;this.logEvent("performanceMetrics",{navigationTime:s.navigationStart,loadTime:s.loadEventEnd-s.navigationStart,domReady:s.domContentLoadedEventEnd-s.navigationStart,renderTime:s.loadEventEnd-s.domContentLoadedEventEnd,navigationType:l.type,redirectCount:l.redirectCount,timestamp:new Date().toISOString()})},1e3)})}setupNetworkDetection(){typeof window!="undefined"&&(window.addEventListener("online",()=>{console.log("EventTracker: Back online, flushing queued events")}),window.addEventListener("offline",()=>{console.log("EventTracker: Offline, queueing events")}))}startPeriodicFlush(){this.flushTimer&&clearInterval(this.flushTimer)}},pt=new ct;typeof window!="undefined"&&(window.EventTracker=pt);import{useCallback as On,useState as Ne}from"react";import In from"axios";var tn,Rn=(tn=m.getSdkAuthToken())!=null?tn:"",An=6e4;function wn(){var e;return(e=m.getSdkAuthToken())!=null?e:""}function Nn(){var o,t,i,l;let e=In.create({baseURL:H,headers:{"Content-Type":"application/json",Accept:"application/json","x-tenant-id":(t=(o=m.getCredentials())==null?void 0:o.tenantId)!=null?t:"","x-api-key":(l=(i=m.getCredentials())==null?void 0:i.apiKey)!=null?l:"",Authorization:`${Rn}`},timeout:An,withCredentials:!1});return e.interceptors.request.use(s=>{let r=wn();return r&&s.headers&&(s.headers.Authorization=`${r}`),s.metadata={startTime:new Date().getTime()},s},s=>(console.error("Request interceptor error:",s),Promise.reject(s))),e.interceptors.response.use(s=>{var b;let r=new Date().getTime(),f=(b=s.config.metadata)==null?void 0:b.startTime;return f&&console.log(`Request to ${s.config.url} took ${r-f}ms`),s},async s=>{var f;let r=s.config;return((f=s.response)==null?void 0:f.status)===401&&!r._retry&&(m.setInitCheck(),console.warn("Unauthorized request, attempting retry...")),s.response||(console.error("Network error:",s.message),s.message="Network error: Please check your internet connection"),s.response&&s.response.status>=500&&(console.error("Server error:",s.response.status,s.response.data),s.message="Server error: Please try again later"),Promise.reject(s)}),e}var kn=Nn(),Q=kn;var Pn=()=>{let[e,o]=Ne(!1),[t,i]=Ne(!1),[l,s]=Ne(!1),[r,f]=Ne(null),[b,x]=Ne(null);return{logout:On(async()=>{var C;let p=JSON.parse((C=localStorage.getItem(me))!=null?C:"");o(!0);let u={action:"LOGOUTUSER",userId:p.agentId||""};return Q.post(_.LOGOUT,u).then(g=>(m.clearStorageAndReset(),localStorage.clear(),sessionStorage.clear(),x(g==null?void 0:g.data),i(!0),g==null?void 0:g.data)).catch(g=>{var y;return s(!0),f(g),(y=g==null?void 0:g.response)==null?void 0:y.data}).finally(()=>{o(!1)})},[]),isLoading:e,isSuccess:t,isError:l,error:r,data:b}};import{useCallback as Mn,useState as ke}from"react";var Un=()=>{let[e,o]=ke(!1),[t,i]=ke(!1),[l,s]=ke(!1),[r,f]=ke(null),[b,x]=ke(null);return{handleEndCall:Mn(async p=>{var g,y,R,P,U,k,z,Z,q,w,h,T,ee,oe,L;let u=JSON.parse((g=localStorage.getItem(me))!=null?g:"");o(!0);let C={action:"ENDCALL",userId:u==null?void 0:u.agentId,processid:(P=(R=(y=u==null?void 0:u.process)==null?void 0:y.process_id)==null?void 0:R.toString())!=null?P:"",process_name:(k=(U=u==null?void 0:u.process)==null?void 0:U.process_name)!=null?k:"",callreferenceid:(Z=(z=u==null?void 0:u.callData)==null?void 0:z.convox_id)!=null?Z:"",mobile_number:(w=(q=u==null?void 0:u.callData)==null?void 0:q.phone_number)!=null?w:"",disposition:(h=p==null?void 0:p.disposition)!=null?h:"RES",set_followUp:(T=p==null?void 0:p.followUp)!=null?T:"N",callback_date:(ee=p==null?void 0:p.callbackDate)!=null?ee:"",callback_hrs:(oe=p==null?void 0:p.callbackHrs)!=null?oe:"",callback_mins:(L=p==null?void 0:p.callbackMins)!=null?L:"",endcall_type:"CLOSE"};return Q.post(_.END_CALL,C).then(S=>(m.endCall(),x(S==null?void 0:S.data),i(!0),S==null?void 0:S.data)).catch(S=>{var N;return s(!0),f(S),(N=S==null?void 0:S.response)==null?void 0:N.data}).finally(()=>{o(!1)})},[]),isLoading:e,isSuccess:t,isError:l,error:r,data:b}};import{useCallback as Bn,useState as Oe}from"react";var Hn=()=>{let[e,o]=Oe(!1),[t,i]=Oe(!1),[l,s]=Oe(!1),[r,f]=Oe(null),[b,x]=Oe(null);return{handleStartCall:Bn(async p=>{var C,g,y,R,P,U,k,z,Z;let u=JSON.parse((C=localStorage.getItem(me))!=null?C:"");if(o(!0),((g=u==null?void 0:u.callData)==null?void 0:g.status)==="IDLE"){let q={action:"CALL",userId:u==null?void 0:u.agentId,phone_number:p==null?void 0:p.mobileNumber};return Q.post(_.CLICK_TO_CALL,q).then(w=>(x(w==null?void 0:w.data),i(!0),w==null?void 0:w.data)).catch(w=>{var h;return s(!0),f(w),(h=w==null?void 0:w.response)==null?void 0:h.data}).finally(()=>{o(!1)})}else if(((y=u==null?void 0:u.callData)==null?void 0:y.status)==="ONCALL"){let q=(P=(R=u==null?void 0:u.conferenceLine)==null?void 0:R.filter(h=>h.line!==1))==null?void 0:P.find(h=>h.status==="IDLE"&&!(h!=null&&h.isCallStart)),w={action:"EXTERNAL_CONFERENCE",operation:`CALL${q.line}`,line_used:String(q.line),thirdparty_no:p==null?void 0:p.mobileNumber,userid:(k=(U=u.callData)==null?void 0:U.agent_id)!=null?k:"",process:(Z=(z=u.callData)==null?void 0:z.process_name)!=null?Z:""};return Q.post(_.CONFERENCE_CALL,w).then(h=>(x(h==null?void 0:h.data),i(!0),m.setConferenceLine(F(c({},q),{isCallStart:!0,status:"ONCALL",phone:p==null?void 0:p.mobileNumber})),m.setOpenConferenceDialog(!0),h==null?void 0:h.data)).catch(h=>{var T;return s(!0),f(h),(T=h==null?void 0:h.response)==null?void 0:T.data}).finally(()=>{o(!1)})}else alert("Agent is not ready")},[]),isLoading:e,isSuccess:t,isError:l,error:r,data:b}};import{useState as zn,useEffect as $n}from"react";var qn=()=>{let{process_id:e,process_name:o,status:t,phone_number:i,agent_id:l,convox_id:s}=m.getState().callData,r={phone_number:i,status:t,callReferenceId:s,agent_id:l,process_id:e,process_name:o},[f,b]=zn(r);return $n(()=>m.subscribe(()=>{let{process_id:I,process_name:p,status:u,phone_number:C,agent_id:g,convox_id:y}=m.getState().callData;b({phone_number:C,status:u,callReferenceId:y,agent_id:g,process_id:I,process_name:p})}),[]),f};import{useState as Fn,useEffect as Kn}from"react";var Wn=()=>{let[e,o]=Fn(m.getSdkAuthToken());return Kn(()=>m.subscribe(()=>{o(m.getSdkAuthToken())}),[]),e};import{memo as qs,useCallback as Fs}from"react";import{CallEnd as bs,Close as ys,DragIndicator as mn,Group as Es,KeyboardArrowDown as hs,Layers as Ss,Mic as Ts,MicOff as vs,Pause as Ds,Pending as Ls,Phone as _s,PlayArrow as Is,SupportAgent as Rs,TransferWithinAStation as As,Upcoming as ws,WifiCalling3 as Ns}from"@mui/icons-material";import{Box as re,Button as De,Chip as at,CircularProgress as Be,Fade as xn,IconButton as it,Menu as ft,MenuItem as ks,Paper as Cn,TextField as Os,Tooltip as he,Typography as bn,useTheme as Ps}from"@mui/material";import{useEffect as He,useRef as Ms,useState as ue}from"react";import{useCallback as et,useRef as dt,useState as on}from"react";function ut(e,o){let[t,i]=on(e),[l,s]=on(!1),r=dt(),f=dt({x:0,y:0}),b=dt({x:0,y:0}),x=et(C=>{let g=r.current;if(!g)return;let y=g.getBoundingClientRect(),R=window.innerWidth,P=window.innerHeight,U={x:Math.max(0,Math.min(C.x,R-y.width)),y:Math.max(0,Math.min(C.y,P-y.height))};i(U),o==null||o(U)},[o]),I=et((C,g)=>{s(!0),f.current={x:C,y:g},b.current=t;let y=(k,z)=>{let Z=k-f.current.x,q=z-f.current.y;x({x:b.current.x+Z,y:b.current.y+q})},R=k=>{k.preventDefault(),y(k.clientX,k.clientY)},P=k=>{k.preventDefault();let z=k.touches[0];z&&y(z.clientX,z.clientY)},U=()=>{s(!1),document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",U),document.removeEventListener("touchmove",P),document.removeEventListener("touchend",U)};document.addEventListener("mousemove",R),document.addEventListener("mouseup",U),document.addEventListener("touchmove",P,{passive:!1}),document.addEventListener("touchend",U)},[t,x]),p=et(C=>{C.preventDefault(),I(C.clientX,C.clientY)},[I]),u=et(C=>{C.preventDefault();let g=C.touches[0];g&&I(g.clientX,g.clientY)},[I]);return{position:t,isDragging:l,dragRef:r,handleMouseDown:p,handleTouchStart:u}}import{useState as Gn,useEffect as Yn}from"react";function Se(){let[e,o]=Gn(m.getState());return Yn(()=>m.subscribe(()=>{o(m.getState())}),[]),e}import{useCallback as Qn,useReducer as es}from"react";import{createContext as jn,useContext as Xn,useState as gt}from"react";import{Snackbar as Jn,Alert as Vn}from"@mui/material";import{jsx as nn,jsxs as Zn}from"react/jsx-runtime";var sn=jn(void 0),Ee=()=>{let e=Xn(sn);if(!e)throw new Error("useToast must be used inside ToastProvider");return e},an=({children:e})=>{let[o,t]=gt(!1),[i,l]=gt(""),[s,r]=gt("info"),f=(b,x="info")=>{l(b),r(x),t(!0)};return Zn(sn.Provider,{value:{showToast:f},children:[e,nn(Jn,{open:o,color:s,autoHideDuration:3e3,onClose:()=>t(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:nn(Vn,{variant:"filled",severity:s,onClose:()=>t(!1),sx:{width:"100%"},children:i})})]})};var ts={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},os=(e,o)=>{if(o.type==="isLoading")return F(c({},e),{isLoading:o.payload});if(o.type==="isSuccess")return F(c({},e),{isSuccess:!0,data:o.payload});if(o.type==="isError")return F(c({},e),{isError:!0,error:o.payload});if(o.type==="reset")return{isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null};throw Error("Unknown action.")};var le=(e={})=>{let{onSuccess:o=null,onError:t=null,disabledSuccessToast:i=!1}=e,{showToast:l}=Ee(),[s,r]=es(os,ts);return[Qn((b,x,I={})=>{r({type:"isLoading",payload:!0}),Q.post(b,x,I).then(p=>{var u,C;r({type:"isSuccess",payload:p.data}),o==null||o(p.data,x),console.log((u=p.data)==null?void 0:u.message,"res45"),i||l((C=p.data)==null?void 0:C.message,"success")}).catch(p=>{var C,g,y,R,P,U,k,z,Z,q,w,h;let u={status:(g=(C=p.response)==null?void 0:C.status)!=null?g:500,message:((R=(y=p.response)==null?void 0:y.data)==null?void 0:R.detail)||((U=(P=p.response)==null?void 0:P.data)==null?void 0:U.message)||p.message||"An unknown error occurred",data:(z=(k=p.response)==null?void 0:k.data)!=null?z:null,statusText:(q=(Z=p.response)==null?void 0:Z.statusText)!=null?q:"",code:(w=p==null?void 0:p.code)!=null?w:"",name:(h=p==null?void 0:p.name)!=null?h:""};l(u.message,"error"),r({type:"isError",payload:u}),t==null||t(u,x)}).finally(()=>{r({type:"isLoading",payload:!1})})},[o,t,l]),s]};import{Call as ot,CallEnd as ln,CallSplit as as,Close as st,Mic as is,MicOff as ls,Pause as rs,PhoneDisabled as cs,PlayArrow as ps,SupportAgent as nt}from"@mui/icons-material";import{Box as O,Button as ae,Dialog as Me,IconButton as be,Paper as ve,TextField as Te,Typography as te,Autocomplete as rn,Tooltip as Pe,useTheme as ds,TableContainer as us,Table as gs,TableHead as fs,TableRow as cn,TableCell as de,TableBody as ms,CircularProgress as xe}from"@mui/material";import{useEffect as xs,useState as Ce}from"react";import{useTheme as ns}from"@mui/material";var ss=({disabled:e,enabled:o,outlined:t})=>{let i=ns();return{disabled:c({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",border:"1px solid rgb(206, 204, 204)",height:"40px","&:hover":{boxShadow:" 0px 2px 2px rgba(0, 0, 0, 0.79)",border:`1px solid ${i.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${i.palette.primary.light}`}},e),enabled:c({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${i.palette.primary.main}`,height:"40px","&:hover":{boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${i.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${i.palette.primary.light}`}},o),outlined:c({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",backgroundColor:i.palette.grey[200],boxShadow:`0px 2px 1px ${i.palette.primary.light}`,border:`0px solid ${i.palette.primary.main}`,height:"40px","&:hover":{boxShadow:`0px 2px 1px ${i.palette.primary.main}`,border:`0px solid ${i.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${i.palette.primary.light}`}},t)}},tt=ss;import{Fragment as Ue,jsx as n,jsxs as v}from"react/jsx-runtime";var Cs=({each:e})=>{var w,h,T,ee,oe;let o=Se(),{showToast:t}=Ee(),{disabled:i,enabled:l,outlined:s}=tt({disabled:((w=o.sdkConfig)==null?void 0:w.disabled)||{},enabled:((h=o.sdkConfig)==null?void 0:h.enabled)||{},outlined:((T=o.sdkConfig)==null?void 0:T.outlined)||{}}),r=ds(),[f,b]=Ce(!1),[x,I]=Ce(!1),[p,u]=Ce(!1),[C,g]=Ce(!1),[y,R]=Ce(!1),P=(L,S)=>{m.setConferenceLine(c(c({},L),S))},U=(L,S)=>{var G,B,j,X;let N=c(c({},L),S);b(!0);let W={action:"EXTERNAL_CONFERENCE",operation:`CALL${N.line}`,line_used:String(N.line),thirdparty_no:N.phone,userid:(B=(G=o.callData)==null?void 0:G.agent_id)!=null?B:"",process:(X=(j=o.callData)==null?void 0:j.process_name)!=null?X:""};Q.post(_.CONFERENCE_CALL,W).then(A=>{var D;t((D=A.data)==null?void 0:D.message,"success"),m.setConferenceLine(c(c({},L),S))}).catch(A=>{var $,J,V,Y;let D=((J=($=A.response)==null?void 0:$.data)==null?void 0:J.detail)||((Y=(V=A.response)==null?void 0:V.data)==null?void 0:Y.message)||A.message||"An unknown error occurred";t(D,"error")}).finally(()=>{b(!1)})},k=(L,S)=>{var G,B,j,X;let N=c(c({},L),S);I(!0);let W={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(N.line),thirdparty_no:N.phone,userid:(B=(G=o.callData)==null?void 0:G.agent_id)!=null?B:"",process:(X=(j=o.callData)==null?void 0:j.process_name)!=null?X:""};Q.post(_.CONFERENCE_CALL,W).then(A=>{var D;t((D=A.data)==null?void 0:D.message,"success"),m.setConferenceLine(c(c({},L),S))}).catch(A=>{var $,J,V,Y;let D=((J=($=A.response)==null?void 0:$.data)==null?void 0:J.detail)||((Y=(V=A.response)==null?void 0:V.data)==null?void 0:Y.message)||A.message||"An unknown error occurred";t(D,"error")}).finally(()=>{I(!1)})},z=(L,S,N)=>{var B,j,X,A;let W=c(c({},L),S);u(!0);let G={action:"EXTERNAL_CONFERENCE",operation:N,hold_channel_no:N==="HOLDUSER"?`hold${W.line}`:`unhold${W.line}`,userid:(j=(B=o.callData)==null?void 0:B.agent_id)!=null?j:"",process:(A=(X=o.callData)==null?void 0:X.process_name)!=null?A:""};Q.post(_.CONFERENCE_CALL_HOLD_OR_UN_HOLD,G).then(D=>{var $;t(($=D.data)==null?void 0:$.message,"success"),m.setConferenceLine(c(c({},L),S))}).catch(D=>{var J,V,Y,ce;let $=((V=(J=D.response)==null?void 0:J.data)==null?void 0:V.detail)||((ce=(Y=D.response)==null?void 0:Y.data)==null?void 0:ce.message)||D.message||"An unknown error occurred";t($,"error")}).finally(()=>{u(!1)})},Z=(L,S,N)=>{var B,j,X,A;let W=c(c({},L),S);g(!0);let G={action:"EXTERNAL_CONFERENCE",operation:N,channel_no:N==="MUTEUSER"?`mute${W.line}`:`play${W.line}`,userid:(j=(B=o.callData)==null?void 0:B.agent_id)!=null?j:"",thirdparty_no:W.phone,process:(A=(X=o.callData)==null?void 0:X.process_name)!=null?A:""};Q.post(_.CONFERENCE_CALL_MUTE_OT_UN_MUTE,G).then(D=>{var $;t(($=D.data)==null?void 0:$.message,"success"),m.setConferenceLine(c(c({},L),S))}).catch(D=>{var J,V,Y,ce;let $=((V=(J=D.response)==null?void 0:J.data)==null?void 0:V.detail)||((ce=(Y=D.response)==null?void 0:Y.data)==null?void 0:ce.message)||D.message||"An unknown error occurred";t($,"error")}).finally(()=>{g(!1)})},q=(L,S)=>{var G,B,j,X;let N=c(c({},L),S);R(!0);let W={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(N.line-1),user_type:`THIRDPARTY${N.line-1}`,thirdparty_no:N.phone,userid:(B=(G=o.callData)==null?void 0:G.agent_id)!=null?B:"",process:(X=(j=o.callData)==null?void 0:j.process_name)!=null?X:""};Q.post(_.CONFERENCE_CALL_END,W).then(A=>{var D;t((D=A.data)==null?void 0:D.message,"success"),m.setConferenceLine(c(c({},L),S))}).catch(A=>{var $,J,V,Y;let D=((J=($=A.response)==null?void 0:$.data)==null?void 0:J.detail)||((Y=(V=A.response)==null?void 0:V.data)==null?void 0:Y.message)||A.message||"An unknown error occurred";t(D,"error")}).finally(()=>{R(!1)})};return v(cn,{sx:{border:"2px solid #fff"},children:[n(de,{sx:{padding:"6px"},children:v(te,{children:["Line ",(ee=e==null?void 0:e.line)!=null?ee:"",". "]})}),n(de,{sx:{padding:"6px"},children:n(te,{variant:"body2",sx:{px:1,borderRadius:"10px"},children:(oe=e==null?void 0:e.status)!=null?oe:""})}),n(de,{sx:{padding:"6px"},children:n(ae,{sx:{textTransform:"capitalize"},size:"small",children:n(te,{variant:"body2",children:(e==null?void 0:e.line)===1?"Internal":"External"})})}),n(de,{sx:{padding:"6px"},children:n(Te,{size:"small",placeholder:"Phone Number",fullWidth:!0,value:(e==null?void 0:e.phone)||"",disabled:(e==null?void 0:e.line)===1||(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="DISCONNECTED"||(e==null?void 0:e.status)==="CONFERENCE",onChange:L=>{P(e,{phone:L.target.value})}})}),n(de,{sx:{padding:"6px"},children:v(O,{sx:{display:"flex",alignItems:"center",justifyContent:"space-around"},children:[e.line!==1&&n(Pe,{title:"Call",children:n(ae,{variant:(e==null?void 0:e.status)!=="IDLE"?"outlined":"contained",color:"success",sx:(e==null?void 0:e.status)!=="IDLE"?c({},i):F(c({},l),{border:`0px solid ${r.palette.success.light}`,"&:hover":{bgcolor:"success.light",boxShadow:`0px 2px 1px ${r.palette.success.light}`,border:`0px solid ${r.palette.success.light}`},"&:active":{bgcolor:"success.light",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}}),onClick:()=>{U(e,{})},disabled:(e==null?void 0:e.status)!=="IDLE",children:f?n(xe,{size:"20px",color:"success"}):n(ot,{sx:{color:(e==null?void 0:e.status)!=="IDLE"?"default":"#f3f2f2"}})})}),e.line===1&&n(Pe,{title:"Merge Call",children:v(ae,{variant:e!=null&&e.isMergeCall&&(e==null?void 0:e.status)==="ONCALL"?"contained":"outlined",sx:e!=null&&e.isMergeCall&&(e==null?void 0:e.status)==="ONCALL"?F(c({},i),{padding:"0px 16px"}):(e==null?void 0:e.status)==="ONCALL"?F(c({},s),{padding:"0px 16px"}):F(c({},i),{padding:"0px 16px"}),onClick:()=>{k(e,{isMergeCall:!0})},disabled:(e==null?void 0:e.status)!=="ONCALL"||x,children:[e!=null&&e.isMergeCall?"Merged":"Merge",x?n(xe,{size:"20px"}):n(as,{})]})}),n(Pe,{title:e.isHold?"Hold":"Un Hold",children:n(ae,{variant:e!=null&&e.isHold?"contained":"outlined",sx:e!=null&&e.isHold&&(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"?c({},i):(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"?c({},s):c({},i),onClick:()=>{e.isHold?z(e,{isHold:!1},"UNHOLDUSER"):z(e,{isHold:!0},"HOLDUSER")},disabled:(e==null?void 0:e.status)!=="ONCALL"&&(e==null?void 0:e.status)!=="CONFERENCE"||p,children:p?n(xe,{size:"20px",sx:{color:r.palette.primary.main}}):e.isHold?n(ps,{}):n(rs,{})})}),n(Pe,{title:e.isMute?"Mute":"Un Mute",children:n(ae,{variant:e!=null&&e.isMute?"contained":"outlined",sx:e!=null&&e.isMute&&(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"?c({},i):(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"?c({},s):c({},i),onClick:()=>{e.isMute?Z(e,{isMute:!1},"PLAYUSER"):Z(e,{isMute:!0},"MUTEUSER")},disabled:(e==null?void 0:e.status)!=="ONCALL"&&(e==null?void 0:e.status)!=="CONFERENCE"||C,children:C?n(xe,{size:"20px",sx:{color:r.palette.primary.main}}):e.isMute?n(ls,{}):n(is,{})})}),(e==null?void 0:e.line)!==1?n(Pe,{title:"End Call",children:n(ae,{variant:(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"||(e==null?void 0:e.status)==="DIALING"?"contained":"outlined",color:"error",sx:(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"||(e==null?void 0:e.status)==="DIALING"?F(c({},l),{border:`0px solid ${r.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${r.palette.error.light}`,border:`0px solid ${r.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}}):c({},i),onClick:()=>{q(e,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:(e==null?void 0:e.status)!=="ONCALL"&&(e==null?void 0:e.status)!=="CONFERENCE"&&(e==null?void 0:e.status)!=="DIALING"||y,children:y?n(xe,{size:"20px",color:"error"}):n(ln,{})})}):n(ae,{variant:e!=null&&e.isCallStart?"contained":"outlined",color:"error",sx:{display:"none"},onClick:()=>{q(e,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:!(e!=null&&e.isCallStart)||y,children:y?n(xe,{size:"20px",color:"error"}):n(ln,{})})]})})]},e.line)};function pn(){var r;let e=Se(),{showToast:o}=Ee(),[t,i]=Ce(!1),l=()=>{m.setOpenConferenceDialog(!1)},s=()=>{var b,x,I,p;i(!0);let f={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(x=(b=e.callData)==null?void 0:b.agent_id)!=null?x:"",process:(p=(I=e.callData)==null?void 0:I.process_name)!=null?p:""};Q.post(_.CONFERENCE_CALL_END_ALL,f).then(u=>{var C;o((C=u.data)==null?void 0:C.message,"success"),m.resetConferenceLines(),l()}).catch(u=>{var g,y,R,P;let C=((y=(g=u.response)==null?void 0:g.data)==null?void 0:y.detail)||((P=(R=u.response)==null?void 0:R.data)==null?void 0:P.message)||u.message||"An unknown error occurred";o(C,"error")}).finally(()=>{i(!1)})};return n(Ue,{children:n(Me,{open:e.openConferenceDialog,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:v(ve,{sx:{borderRadius:2},children:[v(O,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px"},children:[v(te,{variant:"body1",children:[(r=e==null?void 0:e.agentId)!=null?r:""," conference"]}),n(be,{onClick:l,children:n(st,{})})]}),n(O,{sx:{boxShadow:"1px 1px 2px #e7e5e5ff",margin:"0px 15px",borderRadius:"20px"},children:n(us,{component:ve,sx:{outline:"0px solid gray !important",boxShadow:"1px 1px 6px #e7e5e5ff"},children:v(gs,{sx:{border:"4px solid #ffffff !important"},children:[n(fs,{children:v(cn,{sx:{border:"2px solid #f3f3f3ff !important"},children:[n(de,{sx:{padding:"6px"},children:"Line"}),n(de,{sx:{padding:"6px"},children:"Status"}),n(de,{sx:{padding:"6px"},children:"Call Type"}),n(de,{sx:{padding:"6px"},children:"Mobile Number"}),n(de,{sx:{padding:"6px"},children:"Call Actions"})]})}),n(ms,{children:e==null?void 0:e.conferenceLine.map(f=>n(Cs,{each:f}))})]})})}),n(O,{textAlign:"center",m:2,children:v(ae,{variant:"outlined",color:"error",size:"large",onClick:s,disabled:t,sx:{px:2,borderRadius:"20px",textTransform:"capitalize"},children:[t?n(xe,{size:"20px",color:"error",sx:{marginRight:"8px"}}):n(be,{sx:{bgcolor:"error.main","&:hover":{bgcolor:"error.dark"},marginRight:"8px",width:"28px",height:"28px",fontSize:"12px",fontWeight:"600",lineHeight:"16px",letterSpacing:"0.02em",textTransform:"capitalize",color:"white",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%"},children:n(cs,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function dn({open:e}){var C,g,y,R,P,U,k,z,Z,q,w,h;let o=Se(),[t]=le({onSuccess:()=>{m.setOpenCallTransferDialog(!1)}}),[i,l]=Ce("process"),[s,{data:r,isLoading:f}]=le({disabledSuccessToast:!0}),[b,{data:x,isLoading:I}]=le({disabledSuccessToast:!0}),p=()=>{m.setOpenCallTransferDialog(!1)},u=(T,ee)=>{var oe,L,S,N,W,G,B,j,X,A,D,$,J,V,Y,ce,Le,ze,_e,$e,qe,Fe,Ie,Ke,We,Ge,Re,Ye,je,Xe,Je,Ve,Ze;if(console.log(T,"data34"),ee==="PROCESS"){let ye={mobile_number:(L=(oe=o.callData)==null?void 0:oe.phone_number)!=null?L:"",userid:(N=(S=o.callData)==null?void 0:S.agent_id)!=null?N:"",type:"PROCESS",transfer_to:(W=T==null?void 0:T.process_name)!=null?W:"",callreferenceid:(B=(G=o.callData)==null?void 0:G.convox_id)!=null?B:"",processid:String((X=(j=o.callData)==null?void 0:j.process_id)!=null?X:""),process_name:(D=(A=o.callData)==null?void 0:A.process_name)!=null?D:""};t(_.TRANSFER_CALL,ye)}else if(ee==="QUEUE"){let ye={mobile_number:(J=($=o.callData)==null?void 0:$.phone_number)!=null?J:"",userid:(Y=(V=o.callData)==null?void 0:V.agent_id)!=null?Y:"",type:"QUEUE",transfer_to:(ce=T==null?void 0:T.queue_name)!=null?ce:"",callreferenceid:(ze=(Le=o.callData)==null?void 0:Le.convox_id)!=null?ze:"",processid:String(($e=(_e=o.callData)==null?void 0:_e.process_id)!=null?$e:""),process_name:(Fe=(qe=o.callData)==null?void 0:qe.process_name)!=null?Fe:""};t(_.TRANSFER_CALL,ye)}else if(ee==="AGENT"){let ye={mobile_number:(Ke=(Ie=o.callData)==null?void 0:Ie.phone_number)!=null?Ke:"",userid:(Ge=(We=o.callData)==null?void 0:We.agent_id)!=null?Ge:"",type:"AGENT",transfer_to:(Re=T==null?void 0:T.user_id)!=null?Re:"",callreferenceid:(je=(Ye=o.callData)==null?void 0:Ye.convox_id)!=null?je:"",processid:String((Je=(Xe=o.callData)==null?void 0:Xe.process_id)!=null?Je:""),process_name:(Ze=(Ve=o.callData)==null?void 0:Ve.process_name)!=null?Ze:""};t(_.TRANSFER_CALL,ye)}};return xs(()=>{s(_.AGENTS_LIST,{status:"IDLE",active:!0}),b(_.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),n(Ue,{children:n(Me,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:v(ve,{sx:{borderRadius:2},children:[v(O,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[n(te,{variant:"body1",children:" Call Transfer"}),n(be,{onClick:p,children:n(st,{})})]}),v(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:[v(O,{sx:{display:"flex",gap:1},children:[n(ae,{variant:i==="process"?"contained":"outlined",onClick:()=>{l("process"),b(_.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Process"}),n(ae,{variant:i==="queues"?"contained":"outlined",onClick:()=>{l("queues"),b(_.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Queues"}),n(ae,{variant:i==="agents"?"contained":"outlined",onClick:()=>{l("agents"),s(_.AGENTS_LIST,{status:"IDLE",active:!0})},children:"Agents"})]}),(I||f)&&v(O,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"80px"},children:[n(xe,{})," "]}),!I&&!f&&i==="process"&&n(O,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(C=x==null?void 0:x.data)!=null&&C.process&&((y=(g=x==null?void 0:x.data)==null?void 0:g.process)==null?void 0:y.length)>0?(P=(R=x==null?void 0:x.data)==null?void 0:R.process)==null?void 0:P.map((T,ee)=>v(O,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[v(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(nt,{sx:{marginRight:"4px"}}),T.process_name]}),n(be,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{u(T,"PROCESS")},children:n(ot,{})})]},ee)):n(te,{variant:"body1",sx:{fontSize:"16px",letterSpacing:"0.02em",textTransform:"capitalize",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",margin:"10px 0px",color:"gray",height:"60px"},children:"No Process Found"})}),!I&&!f&&i==="queues"&&n(O,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(U=x==null?void 0:x.data)!=null&&U.queue&&((z=(k=x==null?void 0:x.data)==null?void 0:k.queue)==null?void 0:z.length)>0?(q=(Z=x==null?void 0:x.data)==null?void 0:Z.queue)==null?void 0:q.map((T,ee)=>{var oe,L,S,N,W,G;return v(O,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[v(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(nt,{sx:{marginRight:"4px"}}),T.queue_name,(S=(L=(oe=x==null?void 0:x.data)==null?void 0:oe.process)==null?void 0:L.find(B=>B.process_id===T.process_id))!=null&&S.process_name?n(te,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((G=(W=(N=x==null?void 0:x.data)==null?void 0:N.process)==null?void 0:W.find(B=>B.process_id===T.process_id))==null?void 0:G.process_name)+")"}):""]}),n(be,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{u(T,"QUEUE")},children:n(ot,{})})]},ee)}):n(te,{variant:"body1",sx:{fontSize:"16px",letterSpacing:"0.02em",textTransform:"capitalize",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",margin:"10px 0px",color:"gray",height:"60px"},children:"No Queues Found"})}),!I&&!f&&i==="agents"&&n(O,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:r!=null&&r.data&&((w=r==null?void 0:r.data)==null?void 0:w.length)>0?(h=r==null?void 0:r.data)==null?void 0:h.map((T,ee)=>v(O,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[v(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(nt,{sx:{marginRight:"4px"}}),T.name]}),n(be,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{u(T,"AGENT")},children:n(ot,{})})]},ee)):n(te,{variant:"body1",sx:{fontSize:"16px",letterSpacing:"0.02em",textTransform:"capitalize",display:"flex",alignItems:"center",justifyContent:"center",width:"100%",margin:"10px 0px",color:"gray",height:"60px"},children:"No Agents Found"})})]})]})})})}function un({open:e,setOpen:o,onSubmitDisposition:t}){var I,p,u,C;let[i,l]=Ce({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),s=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],r=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],f=(g,y)=>{l(R=>F(c({},R),{[g]:y}))},b=()=>{l({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},x=()=>{b(),o(!1)};return n(Ue,{children:n(Me,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:v(ve,{sx:{borderRadius:2},children:[n(O,{sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:v(te,{variant:"body1",m:1,children:[" ","Call Disposition"]})}),v(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"10px",margin:"10px",borderRadius:"10px"},children:[v(O,{display:"flex",gap:2,children:[n(rn,{value:i.disposition,options:s,getOptionLabel:g=>g.label,onChange:(g,y)=>f("disposition",y),size:"small",renderInput:g=>n(Te,F(c({},g),{label:"Disposition",fullWidth:!0})),sx:{flex:1}}),n(rn,{options:r,getOptionLabel:g=>g.label,value:i.followUp,onChange:(g,y)=>f("followUp",y),size:"small",renderInput:g=>n(Te,F(c({},g),{label:"Follow Up",fullWidth:!0})),sx:{flex:1}})]}),((p=(I=i==null?void 0:i.followUp)==null?void 0:I.label)==null?void 0:p.toLowerCase())==="yes"&&v(O,{display:"flex",gap:2,mt:2,children:[n(Te,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:i.callbackDate,onChange:g=>f("callbackDate",g.target.value),fullWidth:!0,sx:{flex:1}}),n(Te,{size:"small",label:"Hours (0-23)",type:"text",value:i.callbackHrs,onChange:g=>f("callbackHrs",g.target.value),fullWidth:!0,sx:{flex:1}})]}),((C=(u=i==null?void 0:i.followUp)==null?void 0:u.label)==null?void 0:C.toLowerCase())==="yes"&&v(O,{display:"flex",gap:2,mt:2,children:[n(Te,{size:"small",label:"Minutes (0-59)",type:"text",value:i.callbackMins,onChange:g=>f("callbackMins",g.target.value),fullWidth:!0,sx:{flex:1}}),n(O,{sx:{flex:1}})]})]}),v(O,{textAlign:"right",m:2,children:[n(ae,{variant:"outlined",color:"error",size:"large",onClick:x,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),n(ae,{variant:"contained",color:"primary",size:"large",onClick:()=>t(i),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function gn({open:e,setOpen:o,processList:t=null,handleSelectedProcessor:i}){return n(Ue,{children:n(Me,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:v(ve,{sx:{borderRadius:2},children:[v(O,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[n(te,{variant:"body1",children:" Process List"}),n(be,{onClick:()=>{o(!1)},children:n(st,{})})]}),n(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:t.length>0?t==null?void 0:t.map((s,r)=>n(O,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px",cursor:"pointer","&:hover":{bgcolor:"action.selected"}},onClick:()=>{i(s)},children:v(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(nt,{sx:{marginRight:"4px"}}),s.process_name]})},r)):null})]})})})}function fn({open:e,setOpen:o}){return n(Ue,{children:n(Me,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:v(ve,{sx:{borderRadius:2},children:[v(O,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[n(te,{variant:"body1",children:" Call History"}),n(be,{onClick:()=>{o(!1)},children:n(st,{})})]}),n(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Coming Soon..."})]})})})}import{Fragment as Hs,jsx as d,jsxs as fe}from"react/jsx-runtime";var Us=(e,o,t)=>e.map(l=>{var s,r,f;if((l==null?void 0:l.line)===1)return{line:1,status:(s=t==null?void 0:t.status)!=null?s:"",type:"internal",phone:(r=t==null?void 0:t.phone_number)!=null?r:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};{let b=`line_${l.line}_status`,x=`line_${l.line}_phonenumber`;return F(c({},l),{status:(f=o[b])!=null?f:"IDLE",phone:o[x]!=="0"?o[x]:""})}}),Bs=e=>{let o=Math.floor(e/60),t=e%60;return`${o.toString().padStart(2,"0")}:${t.toString().padStart(2,"0")}`};function yn({onDataChange:e}){var xt,Ct,bt,yt,Et,ht,St,Tt,vt,Dt,Lt,_t,It,Rt,At,wt,Nt,kt,Ot,Pt,Mt,Ut,Bt,Ht,zt,$t,qt,Ft,Kt,Wt,Gt,Yt,jt,Xt,Jt,Vt,Zt,Qt,eo,to,oo,no,so,ao,io,lo,ro,co,po,uo,go,fo,mo,xo,Co,bo,yo,Eo,ho,So,To,vo,Do,Lo,_o,Io,Ro,Ao,wo,No,ko,Oo,Po,Mo,Uo,Bo,Ho,zo,$o,qo,Fo;let o=Ps(),t=Se(),{showToast:i}=Ee(),{disabled:l,enabled:s,outlined:r}=tt({disabled:((xt=t.sdkConfig)==null?void 0:xt.disabled)||{},enabled:((Ct=t.sdkConfig)==null?void 0:Ct.enabled)||{},outlined:((bt=t.sdkConfig)==null?void 0:bt.outlined)||{}}),f=Ms(null),[b,x]=ue(null),[I,p]=ue(!0),[u,C]=ue(null),[g,y]=ue(null),[R,P]=ue(!1),[U,k]=ue(!1),[z,Z]=ue(!1),[q,w]=ue(null),[h,T]=ue(""),[ee,oe]=ue(0),{position:L,isDragging:S,dragRef:N,handleMouseDown:W,handleTouchStart:G}=ut(t.controlPanelPosition,a=>m.setControlPanelPosition(a)),{position:B,isDragging:j,dragRef:X,handleMouseDown:A,handleTouchStart:D}=ut(t.iframePosition,a=>m.setIframePosition(a)),[$,{isLoading:J}]=le({onSuccess:()=>{T(""),y(null)}}),[V,{isLoading:Y}]=le({onSuccess:()=>{m.setHolding(!t.isHolding)},onError:a=>{console.log("\u274C Hold operation error:",a)}}),[ce,{isLoading:Le}]=le({onSuccess:()=>{m.setMuted(!t.isMuted)},onError:a=>{console.log("\u274C Mute operation error:",a)}}),[ze,{isLoading:_e}]=le(),[$e,{isLoading:qe}]=le(),[Fe,{isLoading:Ie}]=le(),Ke=()=>{x(null)},We=a=>{p(!0),y(a.currentTarget),m.setStatus("dial")},Ge=()=>{t.status!=="on call"&&m.setStatus("idle"),y(null)},Re=a=>{C(a.currentTarget)},Ye=()=>{C(null)},je=()=>{let a={action:"READYAGENT",userId:t.agentId};ze(_.READY_AGENT,a)},Xe=a=>{C(null);let E={action:"AGENTBREAK",break_type:a,userId:t.agentId};$e(_.UPDATE_AGENT_BREAK,E)},Je=a=>{if(a.length!==10)i("Invalid phone number","error");else if(!/^\d+$/.test(a))i("Invalid phone number","error");else{let E={action:"CALL",phone_number:a,userId:t.agentId};$(_.CLICK_TO_CALL,E)}},Ve=()=>{let a={action:t.isHolding?"UNHOLD":"HOLD",userId:t.agentId};V(_.HOLD_CALL,a)},Ze=()=>{let a={action:t.isMuted?"UNMUTE":"MUTE",userId:t.agentId};ce(_.MUTE_CALL,a)},ye=a=>{var M,ne,se,pe,ge,Ae,we,Ko,Wo,Go,Yo,jo,Xo,Jo,Vo,Zo;console.log("data",a);let E={action:"ENDCALL",userId:t.agentId,processid:(se=(ne=(M=t.process)==null?void 0:M.process_id)==null?void 0:ne.toString())!=null?se:"",process_name:(ge=(pe=t.process)==null?void 0:pe.process_name)!=null?ge:"",callreferenceid:(we=(Ae=t.callData)==null?void 0:Ae.convox_id)!=null?we:"",mobile_number:(Wo=(Ko=t.callData)==null?void 0:Ko.phone_number)!=null?Wo:"",disposition:(Yo=(Go=a==null?void 0:a.disposition)==null?void 0:Go.value)!=null?Yo:"",set_followUp:(Xo=(jo=a==null?void 0:a.followUp)==null?void 0:jo.value)!=null?Xo:"",callback_date:(Jo=a==null?void 0:a.callbackDate)!=null?Jo:"",callback_hrs:(Vo=a==null?void 0:a.callbackHrs)!=null?Vo:"",callback_mins:(Zo=a==null?void 0:a.callbackMins)!=null?Zo:"",endcall_type:"CLOSE"};T(""),Fe(_.END_CALL,E),m.endCall(),P(!1)};return He(()=>{let a=E=>{E.preventDefault()};return window.addEventListener("beforeunload",a),()=>{window.removeEventListener("beforeunload",a)}},[]),He(()=>{let a;return t.callData.status&&t.callData.status==="ONCALL"?a=setInterval(()=>{let E=Math.floor((Date.now()-t.callStartTime)/1e3);oe(E)},1e3):oe(0),()=>{a&&clearInterval(a)}},[t.callData.status]),He(()=>{if(e&&t.callData){let{process_id:a,process_name:E,status:M,phone_number:ne,agent_id:se,convox_id:pe}=t.callData;e({phone_number:ne,status:M,callReferenceId:pe,agent_id:se,process_id:a,process_name:E})}},[t.callData,e]),He(()=>{t.agentId?Q.post(_.PROCESS_LIST,{userId:t.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}).then(a=>{var E,M;console.log(a.data.data,"res4"),a&&a.data&&((E=a==null?void 0:a.data)==null?void 0:E.length)>1?(w(a.data.data),k(!0)):(m.setProcess((M=a==null?void 0:a.data)==null?void 0:M.data[0]),k(!1))}).catch(a=>{i(a.response.data.message,"error")}):console.log("No agentId available, skipping API call")},[t.agentId]),He(()=>(t.agentId&&(f.current=new WebSocket(`${en.WS}?agent_id=${t.agentId}`),f.current.onopen=()=>{console.log("\u{1F310} WebSocket connection established")},f.current.onmessage=a=>{try{let E=JSON.parse(a.data),M=Us(t==null?void 0:t.conferenceLine,E==null?void 0:E.conferencestatus,E);console.log(M,"\u{1F4CA} Parsed JSON:",E),m.updateCallData(E),m.updateConferenceData([...M]),E.status==="ONCALL"&&(m.startCall(),I||p(!0)),E.status==="WRAPUP"&&m.endCall()}catch(E){console.log("\u{1F4E8} Raw message:",a.data)}},f.current.onclose=()=>{console.log("\u{1F50C} WebSocket connection closed")},f.current.onerror=a=>{console.error("\u274C WebSocket error:",a)}),()=>{var a;(a=f.current)==null||a.close()}),[t.agentId]),!t.isInitialized||!t.process?d(re,{children:!!U&&d(gn,{processList:q,open:U,setOpen:k,handleSelectedProcessor:a=>{m.setProcess(a)}})}):fe(Hs,{children:[d(re,{children:d(xn,{in:!0,timeout:300,children:d(Cn,{ref:(yt=t.sdkConfig)!=null&&yt.isDraggable?N:null,elevation:S?4:(Et=t.sdkConfig)!=null&&Et.isDraggable?1:0,sx:{position:(ht=t.sdkConfig)!=null&&ht.isDraggable?"fixed":"relative",left:(St=t.sdkConfig)!=null&&St.isDraggable?L.x:"auto",top:(Tt=t.sdkConfig)!=null&&Tt.isDraggable?L.y:"auto",display:"inline-block",width:"auto",flexShrink:0,whiteSpace:"nowrap",p:.5,borderRadius:3,bgcolor:"background.paper",zIndex:(vt=t.sdkConfig)!=null&&vt.isDraggable?Number.MAX_SAFE_INTEGER:0,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),userSelect:"none"},children:fe(re,{sx:{display:"flex",alignItems:"center"},children:[fe(re,{sx:{display:"flex",alignItems:"center",gap:1,margin:"0px 10px"},children:[((Dt=t.sdkConfig)==null?void 0:Dt.isDraggable)&&fe(it,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:W,onTouchStart:G,children:[d(mn,{})," "]}),d(re,{children:!((Lt=t.sdkConfig)!=null&&Lt.disabledDialButton)&&d(he,{title:"Dial",children:d(it,{size:"small",onClick:a=>{var E,M,ne,se,pe,ge,Ae,we;((M=(E=t.callData)==null?void 0:E.status)==null?void 0:M.toUpperCase())!=="ONCALL"&&((se=(ne=t.callData)==null?void 0:ne.status)==null?void 0:se.toUpperCase())!=="BREAK"&&((ge=(pe=t.callData)==null?void 0:pe.status)==null?void 0:ge.toUpperCase())!=="RINGING"&&((we=(Ae=t.callData)==null?void 0:Ae.status)==null?void 0:we.toUpperCase())!=="WRAPUP"&&We(a)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:d(Ns,{sx:{color:((It=(_t=t.callData)==null?void 0:_t.status)==null?void 0:It.toUpperCase())==="ONCALL"||((At=(Rt=t.callData)==null?void 0:Rt.status)==null?void 0:At.toUpperCase())==="BREAK"||((Nt=(wt=t.callData)==null?void 0:wt.status)==null?void 0:Nt.toUpperCase())==="RINGING"||((Ot=(kt=t.callData)==null?void 0:kt.status)==null?void 0:Ot.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),d(bn,{sx:{color:"success.main",width:"40px",marginRight:"10px",fontSize:"18px",fontWeight:"600"},children:Bs(ee)}),d(at,{sx:{padding:"18px 0px"},label:qe||_e?d(re,{sx:{fontWeight:"bold",width:"60px",display:"flex",alignItems:"center",justifyContent:"center"},children:d(Be,{size:"20px"})}):d(bn,{variant:"body2",sx:{fontWeight:"bold",width:"60px",textAlign:"center"},children:(Ut=(Mt=(Pt=t.callData)==null?void 0:Pt.status)==null?void 0:Mt.toUpperCase())!=null?Ut:"N/A"}),onClick:Re,deleteIcon:d(hs,{color:"primary"}),onDelete:Re})]}),fe(re,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[d(he,{title:"Agent Ready",children:d(De,{variant:((Ht=(Bt=t.callData)==null?void 0:Bt.status)==null?void 0:Ht.toUpperCase())==="BREAK"||(($t=(zt=t.callData)==null?void 0:zt.status)==null?void 0:$t.toUpperCase())==="MISSED"?"outlined":"contained",onClick:a=>{var E,M,ne,se;(((M=(E=t.callData)==null?void 0:E.status)==null?void 0:M.toUpperCase())==="BREAK"||((se=(ne=t.callData)==null?void 0:ne.status)==null?void 0:se.toUpperCase())==="MISSED")&&(a.stopPropagation(),je())},classes:{root:((Ft=(qt=t.callData)==null?void 0:qt.status)==null?void 0:Ft.toUpperCase())==="BREAK"||((Wt=(Kt=t.callData)==null?void 0:Kt.status)==null?void 0:Wt.toUpperCase())==="MISSED"?"outlined":"enabled"},sx:c({},((Yt=(Gt=t.callData)==null?void 0:Gt.status)==null?void 0:Yt.toUpperCase())==="BREAK"||((Xt=(jt=t.callData)==null?void 0:jt.status)==null?void 0:Xt.toUpperCase())==="MISSED"?r:s),disabled:_e,children:d(Rs,{})})}),d(he,{title:t.isHolding?"Resume":"Hold",children:d(De,{variant:t.isHolding&&((Vt=(Jt=t.callData)==null?void 0:Jt.status)==null?void 0:Vt.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),Ve()},sx:t.isHolding&&((Qt=(Zt=t.callData)==null?void 0:Zt.status)==null?void 0:Qt.toUpperCase())==="ONCALL"?c({},s):((to=(eo=t.callData)==null?void 0:eo.status)==null?void 0:to.toUpperCase())==="ONCALL"?c({},r):c({},l),disabled:((no=(oo=t.callData)==null?void 0:oo.status)==null?void 0:no.toUpperCase())!=="ONCALL"&&!t.isHolding||Y,children:Y?d(Be,{size:"20px",sx:{color:o.palette.primary.main}}):t.isHolding?d(Is,{}):d(Ds,{})})}),d(he,{title:t.isMuted?"Unmute":"Mute",children:d(De,{variant:t.isMuted&&((ao=(so=t.callData)==null?void 0:so.status)==null?void 0:ao.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),Ze()},sx:t.isMuted&&((lo=(io=t.callData)==null?void 0:io.status)==null?void 0:lo.toUpperCase())==="ONCALL"?c({},s):((co=(ro=t.callData)==null?void 0:ro.status)==null?void 0:co.toUpperCase())==="ONCALL"?c({},r):c({},l),disabled:((uo=(po=t.callData)==null?void 0:po.status)==null?void 0:uo.toUpperCase())!=="ONCALL"&&!t.isMuted||Le,children:Le?d(Be,{size:"20px",sx:{color:o.palette.primary.main}}):t.isMuted?d(vs,{}):d(Ts,{})})}),!((go=t.sdkConfig)!=null&&go.disableCallTransferButton)&&d(he,{title:"Transfer Call",children:d(De,{variant:t.openCallTransferDialog?"contained":"outlined",onClick:a=>{var E,M;((M=(E=t.callData)==null?void 0:E.status)==null?void 0:M.toUpperCase())==="ONCALL"&&(a.stopPropagation(),m.setOpenCallTransferDialog(!0))},sx:t.openCallTransferDialog?c({},s):((mo=(fo=t.callData)==null?void 0:fo.status)==null?void 0:mo.toUpperCase())==="ONCALL"?c({},r):c({},l),disabled:((Co=(xo=t.callData)==null?void 0:xo.status)==null?void 0:Co.toUpperCase())!=="ONCALL",children:d(As,{})})}),!((bo=t.sdkConfig)!=null&&bo.disableConferenceButton)&&d(he,{title:"Conference Call",children:d(De,{variant:t.openConferenceDialog?"contained":"outlined",onClick:a=>{var E,M;((M=(E=t.callData)==null?void 0:E.status)==null?void 0:M.toUpperCase())==="ONCALL"&&(a.stopPropagation(),m.setOpenConferenceDialog(!0))},sx:t.openConferenceDialog?c({},s):((Eo=(yo=t.callData)==null?void 0:yo.status)==null?void 0:Eo.toUpperCase())==="ONCALL"?c({},r):c({},l),disabled:((So=(ho=t.callData)==null?void 0:ho.status)==null?void 0:So.toUpperCase())!=="ONCALL",children:d(Es,{})})}),!((To=t.sdkConfig)!=null&&To.disableEndCallButton)&&d(he,{title:"End Call",children:d(De,{variant:((Do=(vo=t.callData)==null?void 0:vo.status)==null?void 0:Do.toUpperCase())==="ONCALL"||((_o=(Lo=t.callData)==null?void 0:Lo.status)==null?void 0:_o.toUpperCase())==="RINGING"||((Ro=(Io=t.callData)==null?void 0:Io.status)==null?void 0:Ro.toUpperCase())==="WRAPUP"?"contained":"outlined",onClick:a=>{var E,M,ne,se,pe,ge;(((M=(E=t.callData)==null?void 0:E.status)==null?void 0:M.toUpperCase())==="ONCALL"||((se=(ne=t.callData)==null?void 0:ne.status)==null?void 0:se.toUpperCase())==="RINGING"||((ge=(pe=t.callData)==null?void 0:pe.status)==null?void 0:ge.toUpperCase())==="WRAPUP")&&(a.stopPropagation(),P(!0))},sx:((wo=(Ao=t.callData)==null?void 0:Ao.status)==null?void 0:wo.toUpperCase())==="ONCALL"||((ko=(No=t.callData)==null?void 0:No.status)==null?void 0:ko.toUpperCase())==="RINGING"||((Po=(Oo=t.callData)==null?void 0:Oo.status)==null?void 0:Po.toUpperCase())==="WRAPUP"?F(c({},s),{borderRight:"1px",backgroundColor:"error.main",minWidth:"60px !important",boxShadow:" 0px 2px 1px #5f3f3f",border:`1px solid ${o.palette.error.light}`,height:"40px","&:hover":{bgcolor:"error.light",boxShadow:" 0px 2px 1px #5f3f3f",border:`0px solid ${o.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${o.palette.primary.light}`}}):F(c({},l),{minWidth:"60px !important"}),disabled:((Uo=(Mo=t.callData)==null?void 0:Mo.status)==null?void 0:Uo.toUpperCase())!=="ONCALL"&&((Ho=(Bo=t.callData)==null?void 0:Bo.status)==null?void 0:Ho.toUpperCase())!=="RINGING"&&(($o=(zo=t.callData)==null?void 0:zo.status)==null?void 0:$o.toUpperCase())!=="WRAPUP"||Ie,children:Ie?d(Be,{size:"20px",color:"error"}):d(bs,{})})})]})]})})})}),d(xn,{in:!0,timeout:300,children:fe(Cn,{ref:X,elevation:j?4:1,sx:{position:"absolute",left:B.x,top:B.y,borderRadius:2,bgcolor:"background.paper",zIndex:Number.MAX_SAFE_INTEGER,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),visibility:I&&!((qo=t.sdkConfig)!=null&&qo.disableSoftPhone)?"visible":"hidden",userSelect:"none"},children:[fe(re,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll",padding:"0px 10px"},onMouseDown:A,onTouchStart:D,children:[d(mn,{sx:{transform:"rotate(90deg)",color:"#7b7b7b"}})," ",d(it,{onClick:()=>p(!1),children:d(ys,{})})]}),d(re,{children:d("iframe",{src:`https://${Qe}/ConVoxCCS/iframe?agent_id=${t.agentId}&process_id=${(Fo=t.process)==null?void 0:Fo.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay",style:{border:"none"}})})]})}),d(ft,{anchorEl:g,open:!!g,onClose:Ge,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:fe(re,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[d(Os,{size:"small",value:h,placeholder:"Enter Mobile No.",onChange:a=>{T(a.target.value)}}),d(it,{color:"info",onClick:()=>{Je(h)},children:J?d(Be,{size:"20px",sx:{color:o.palette.success.main}}):d(_s,{color:"success"})})]})}),d(ft,{anchorEl:u,open:!!u,onClose:Ye,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:d(ks,{onClick:()=>Xe("Lunch"),children:"- Break"})}),d(ft,{anchorEl:b,open:!!b,onClose:Ke,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:fe(re,{sx:{display:"flex",justifyContent:"flex-start",flexDirection:"column",padding:"0px 10px","&hover":{backgroundColor:"white"}},children:[d(at,{icon:d(Ss,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),d(at,{icon:d(Ls,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),d(at,{icon:d(ws,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!t.openConferenceDialog&&d(pn,{}),!!t.openCallTransferDialog&&d(dn,{open:t.openCallTransferDialog}),!!R&&d(un,{open:R,setOpen:P,onSubmitDisposition:ye}),!!z&&d(fn,{open:z,setOpen:Z})]})}import{memo as zs}from"react";import{jsx as $s}from"react/jsx-runtime";var mt=zs(({children:e})=>$s(an,{children:e}));mt.displayName="SDKProvider";import{jsx as En}from"react/jsx-runtime";var hn=qs(({onDataChange:e})=>{let o=Fs(t=>{try{e&&typeof e=="function"&&e(t)}catch(i){console.error("Error in CallControlPanel data change handler:",i)}},[e]);return En(mt,{children:En(yn,{onDataChange:o})})});hn.displayName="CallControlPanel";async function qi({apiKey:e,tenantId:o,agentId:t,sdkConfig:i}){if(!e||typeof e!="string"||e.trim().length===0)throw new Error("SDK initialization failed: API key is required and must be a non-empty string");if(!o||typeof o!="string"||o.trim().length===0)throw new Error("SDK initialization failed: Tenant ID is required and must be a non-empty string");if(!t||typeof t!="string"||t.trim().length===0)throw new Error("SDK initialization failed: Agent ID is required and must be a non-empty string");try{let l=await pt.init({apiKey:e.trim(),tenantId:o.trim(),agentId:t.trim(),baseUrl:H});if(l)console.log("SDK initialized successfully"),m.initialize(e.trim(),o.trim(),t.trim(),i,l);else throw console.error("SDK initialization failed: Event tracker initialization returned false"),m.setInitCheck(),new Error("SDK initialization failed: Unable to establish connection with the CTI system")}catch(l){throw console.error("SDK initialization error:",l),m.setInitCheck(),l instanceof Error?l:new Error(`SDK initialization failed: ${String(l)}`)}}function Fi(){return"6.x.x"}function Ki(){return m.getState().isInitialized}export{hn as CallControlPanel,Fi as getSDKVersion,qi as initSDK,Ki as isSDKInitialized,Hn as useClickToCall,Un as useEndCall,Wn as useGetAuthorizationToken,qn as useGetCallerData,Pn as useLogout};
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
21
+
22
+ // call-control-sdk/lib/services/endPoint.ts
23
+ var IP = "uat-cti.aighospitals.com";
24
+ var BASE_URL = `https://${IP}:8095`;
25
+ var WS_BASE_URL = `wss://${IP}:8095`;
26
+ var VERSION = {
27
+ v1: "/api/v1"
28
+ };
29
+ var END_POINT = {
30
+ LOGIN: `${BASE_URL}${VERSION.v1}/cti/login?provider=convox`,
31
+ READY_AGENT: `${BASE_URL}${VERSION.v1}/cti/ready-agent?provider=convox`,
32
+ UPDATE_AGENT_BREAK: `${BASE_URL}${VERSION.v1}/cti/update-agent-status?provider=convox`,
33
+ CLICK_TO_CALL: `${BASE_URL}${VERSION.v1}/cti/calls?provider=convox`,
34
+ HOLD_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/hold?provider=convox`,
35
+ MUTE_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/mute?provider=convox`,
36
+ UNMUTE_CALL: `${BASE_URL}${VERSION.v1}/cti/unmute-call?provider=convox`,
37
+ END_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/end?provider=convox`,
38
+ LOGOUT: `${BASE_URL}${VERSION.v1}/cti/logout?provider=convox`,
39
+ CONFERENCE_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/conference?provider=convox`,
40
+ CONFERENCE_CALL_HOLD_OR_UN_HOLD: `${BASE_URL}${VERSION.v1}/cti/calls/conference/hold?provider=convox`,
41
+ CONFERENCE_CALL_MUTE_OT_UN_MUTE: `${BASE_URL}${VERSION.v1}/cti/calls/conference/mute?provider=convox`,
42
+ CONFERENCE_CALL_END: `${BASE_URL}${VERSION.v1}/cti/calls/conference/hangup?provider=convox`,
43
+ CONFERENCE_CALL_END_ALL: `${BASE_URL}${VERSION.v1}/cti/calls/conference/hangup/all?provider=convox`,
44
+ TRANSFER_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/transfer?provider=convox`,
45
+ AGENTS_LIST: `${BASE_URL}${VERSION.v1}/cti/users`,
46
+ PROCESS_LIST: `${BASE_URL}${VERSION.v1}/cti/processes-list`,
47
+ TRANSFER_TO_DETAILS: `${BASE_URL}${VERSION.v1}/cti/transfer-to-details?provider=convox`,
48
+ CALL_HISTORY: `${BASE_URL}${VERSION.v1}/dashboard/call-history`,
49
+ SENTIMENTAL_ANALYSIS: `${BASE_URL}${VERSION.v1}/users/get_sentiment_analysis`
50
+ };
51
+ var WS_END_POINT = {
52
+ WS: `${WS_BASE_URL}${VERSION.v1}/cti/ws`
53
+ };
54
+ var STORAGE_KEY = "call-control-sdk-state";
55
+
56
+ // call-control-sdk/lib/hooks/sdk-state.ts
57
+ var SDKStateManager = class {
58
+ constructor() {
59
+ __publicField(this, "state");
60
+ __publicField(this, "listeners", []);
61
+ __publicField(this, "STORAGE_KEY", STORAGE_KEY);
62
+ __publicField(this, "apiKey");
63
+ __publicField(this, "tenantId");
64
+ this.state = this.getInitialState();
65
+ this.loadFromStorage();
66
+ }
67
+ getInitialState() {
68
+ return {
69
+ authorization: void 0,
70
+ process: null,
71
+ agentId: "",
72
+ openConferenceDialog: false,
73
+ openCallTransferDialog: false,
74
+ isInitialized: false,
75
+ sdkConfig: {
76
+ disableEndCallButton: false,
77
+ disabledDialButton: false,
78
+ disableCallTransferButton: false,
79
+ isDraggable: true,
80
+ disableSoftPhone: false,
81
+ disableConferenceButton: false,
82
+ disabled: {},
83
+ enabled: {},
84
+ outlined: {}
85
+ },
86
+ isHolding: false,
87
+ isMuted: false,
88
+ status: "idle",
89
+ callStartTime: null,
90
+ controlPanelPosition: { x: 10, y: 10 },
91
+ iframePosition: { x: 10, y: 80 },
92
+ callData: {
93
+ agent_id: "",
94
+ status: "",
95
+ type: "",
96
+ event_time: "",
97
+ phone_number: ""
98
+ },
99
+ conferenceLine: [
100
+ {
101
+ line: 1,
102
+ status: "IDLE",
103
+ type: "",
104
+ phone: "",
105
+ isMute: false,
106
+ isHold: false,
107
+ isCallStart: false,
108
+ isMergeCall: false
109
+ },
110
+ {
111
+ line: 2,
112
+ status: "IDLE",
113
+ type: "",
114
+ phone: "",
115
+ isMute: false,
116
+ isHold: false,
117
+ isCallStart: false,
118
+ isMergeCall: false
119
+ },
120
+ {
121
+ line: 3,
122
+ status: "IDLE",
123
+ type: "",
124
+ phone: "",
125
+ isMute: false,
126
+ isHold: false,
127
+ isCallStart: false,
128
+ isMergeCall: false
129
+ },
130
+ {
131
+ line: 4,
132
+ status: "IDLE",
133
+ type: "",
134
+ phone: "",
135
+ isMute: false,
136
+ isHold: false,
137
+ isCallStart: false,
138
+ isMergeCall: false
139
+ },
140
+ {
141
+ line: 5,
142
+ status: "IDLE",
143
+ type: "",
144
+ phone: "",
145
+ isMute: false,
146
+ isHold: false,
147
+ isCallStart: false,
148
+ isMergeCall: false
149
+ }
150
+ ]
151
+ };
152
+ }
153
+ loadFromStorage() {
154
+ try {
155
+ const stored = localStorage.getItem(this.STORAGE_KEY);
156
+ if (stored) {
157
+ const parsedState = JSON.parse(stored);
158
+ this.state = __spreadProps(__spreadValues({}, this.state), {
159
+ agentId: parsedState.agentId || "",
160
+ authorization: parsedState.authorization || void 0,
161
+ process: parsedState.process || null,
162
+ openConferenceDialog: (parsedState == null ? void 0 : parsedState.openConferenceDialog) || false,
163
+ openCallTransferDialog: (parsedState == null ? void 0 : parsedState.openCallTransferDialog) || false,
164
+ isInitialized: parsedState.isInitialized || false,
165
+ sdkConfig: parsedState.sdkConfig || {
166
+ disableEndCallButton: false,
167
+ disabledDialButton: false,
168
+ disableCallTransferButton: false,
169
+ isDraggable: true,
170
+ disableSoftPhone: false,
171
+ disableConferenceButton: false,
172
+ disabled: {},
173
+ enabled: {},
174
+ outlined: {}
175
+ },
176
+ isHolding: parsedState.isHolding || false,
177
+ isMuted: parsedState.isMuted || false,
178
+ status: parsedState.status || "idle",
179
+ callStartTime: parsedState.callStartTime || null,
180
+ controlPanelPosition: parsedState.controlPanelPosition || {
181
+ x: 10,
182
+ y: 10
183
+ },
184
+ iframePosition: parsedState.iframePosition || { x: 10, y: 80 },
185
+ callData: parsedState.callData || {
186
+ mobileNumber: "",
187
+ callReferenceId: "",
188
+ agent_id: "",
189
+ status: "",
190
+ type: "",
191
+ event_time: "",
192
+ phone_number: ""
193
+ },
194
+ // Fix: Properly handle conferenceLine with fallback to initial state
195
+ conferenceLine: parsedState.conferenceLine && Array.isArray(parsedState.conferenceLine) && parsedState.conferenceLine.length > 0 ? parsedState.conferenceLine : this.state.conferenceLine
196
+ });
197
+ }
198
+ } catch (error) {
199
+ console.warn("Failed to load SDK state from localStorage:", error);
200
+ }
201
+ }
202
+ saveToStorage() {
203
+ try {
204
+ const persistentState = {
205
+ agentId: this.state.agentId,
206
+ authorization: this.state.authorization,
207
+ process: this.state.process,
208
+ isInitialized: this.state.isInitialized,
209
+ openConferenceDialog: this.state.openConferenceDialog,
210
+ openCallTransferDialog: this.state.openCallTransferDialog,
211
+ sdkConfig: this.state.sdkConfig,
212
+ isHolding: this.state.isHolding,
213
+ isMuted: this.state.isMuted,
214
+ status: this.state.status,
215
+ callStartTime: this.state.callStartTime,
216
+ controlPanelPosition: this.state.controlPanelPosition,
217
+ iframePosition: this.state.iframePosition,
218
+ callData: this.state.callData,
219
+ conferenceLine: this.state.conferenceLine
220
+ };
221
+ localStorage.setItem(this.STORAGE_KEY, JSON.stringify(persistentState));
222
+ } catch (error) {
223
+ console.warn("Failed to save SDK state to localStorage:", error);
224
+ }
225
+ }
226
+ notifyListeners() {
227
+ this.listeners.forEach((listener) => listener());
228
+ }
229
+ validateCredentials(apiKey, tenantId) {
230
+ if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
231
+ throw new Error("API key not available");
232
+ }
233
+ if (!tenantId || typeof tenantId !== "string" || tenantId.trim().length === 0) {
234
+ throw new Error("Tenant ID not available");
235
+ }
236
+ this.apiKey = apiKey.trim();
237
+ this.tenantId = tenantId.trim();
238
+ }
239
+ initialize(apiKey, tenantId, agentId, sdkConfig, initResult) {
240
+ this.validateCredentials(apiKey, tenantId);
241
+ if (!agentId || typeof agentId !== "string" || agentId.trim().length === 0) {
242
+ throw new Error("Agent ID not available");
243
+ } else {
244
+ this.state.agentId = agentId;
245
+ this.state.openConferenceDialog = false;
246
+ this.state.openCallTransferDialog = false;
247
+ this.state.authorization = initResult;
248
+ this.state.sdkConfig = __spreadValues({
249
+ disableEndCallButton: false,
250
+ disabledDialButton: false,
251
+ disableCallTransferButton: false,
252
+ isDraggable: true,
253
+ disableSoftPhone: false,
254
+ disableConferenceButton: false,
255
+ disabled: {},
256
+ enabled: {},
257
+ outlined: {}
258
+ }, sdkConfig);
259
+ this.state.isInitialized = true;
260
+ this.saveToStorage();
261
+ this.notifyListeners();
262
+ }
263
+ }
264
+ getState() {
265
+ return __spreadValues({}, this.state);
266
+ }
267
+ getCredentials() {
268
+ return { apiKey: this.apiKey, tenantId: this.tenantId };
269
+ }
270
+ getSdkAuthToken() {
271
+ var _a2;
272
+ return (_a2 = this.state.authorization) == null ? void 0 : _a2.accessToken;
273
+ }
274
+ subscribe(listener) {
275
+ this.listeners.push(listener);
276
+ return () => {
277
+ const index = this.listeners.indexOf(listener);
278
+ if (index > -1) {
279
+ this.listeners.splice(index, 1);
280
+ }
281
+ };
282
+ }
283
+ setHolding(isHolding) {
284
+ this.state.isHolding = isHolding;
285
+ this.saveToStorage();
286
+ this.notifyListeners();
287
+ }
288
+ setMuted(isMuted) {
289
+ this.state.isMuted = isMuted;
290
+ this.saveToStorage();
291
+ this.notifyListeners();
292
+ }
293
+ setStatus(status) {
294
+ this.state.status = status;
295
+ this.saveToStorage();
296
+ this.notifyListeners();
297
+ }
298
+ setProcess(process) {
299
+ this.state.process = process;
300
+ this.saveToStorage();
301
+ this.notifyListeners();
302
+ }
303
+ setControlPanelPosition(position) {
304
+ this.state.controlPanelPosition = position;
305
+ this.saveToStorage();
306
+ this.notifyListeners();
307
+ }
308
+ setIframePosition(position) {
309
+ this.state.iframePosition = position;
310
+ this.saveToStorage();
311
+ this.notifyListeners();
312
+ }
313
+ startCall() {
314
+ this.state.callStartTime = Date.now();
315
+ this.state.status = "on call";
316
+ this.saveToStorage();
317
+ this.notifyListeners();
318
+ }
319
+ endCall() {
320
+ this.state.callStartTime = null;
321
+ this.state.status = "idle";
322
+ this.state.isHolding = false;
323
+ this.state.isMuted = false;
324
+ this.saveToStorage();
325
+ this.notifyListeners();
326
+ }
327
+ setInitCheck() {
328
+ this.state.isInitialized = false;
329
+ this.saveToStorage();
330
+ this.notifyListeners();
331
+ }
332
+ setOpenConferenceDialog(open) {
333
+ this.state.openConferenceDialog = open;
334
+ this.saveToStorage();
335
+ this.notifyListeners();
336
+ }
337
+ setOpenCallTransferDialog(open) {
338
+ this.state.openCallTransferDialog = open;
339
+ this.saveToStorage();
340
+ this.notifyListeners();
341
+ }
342
+ updateCallData(data) {
343
+ this.state.callData = __spreadValues(__spreadValues({}, this.state.callData), data);
344
+ this.saveToStorage();
345
+ this.notifyListeners();
346
+ }
347
+ updateConferenceData(data) {
348
+ this.state.conferenceLine = [...data];
349
+ this.saveToStorage();
350
+ this.notifyListeners();
351
+ }
352
+ setConferenceLine(line) {
353
+ var _a2;
354
+ if (!this.state.conferenceLine || !Array.isArray(this.state.conferenceLine)) {
355
+ console.warn("Conference line data corrupted, resetting to initial state");
356
+ this.state.conferenceLine = this.getInitialState().conferenceLine;
357
+ }
358
+ const conferenceLineData = (_a2 = this.state.conferenceLine) == null ? void 0 : _a2.map((each) => {
359
+ if (each.line === line.line) {
360
+ return line;
361
+ }
362
+ return each;
363
+ });
364
+ this.state.conferenceLine = conferenceLineData;
365
+ this.saveToStorage();
366
+ this.notifyListeners();
367
+ }
368
+ resetConferenceLines() {
369
+ this.state.conferenceLine = this.getInitialState().conferenceLine;
370
+ this.saveToStorage();
371
+ this.notifyListeners();
372
+ }
373
+ clearStorageAndReset() {
374
+ try {
375
+ localStorage.removeItem(this.STORAGE_KEY);
376
+ this.state = this.getInitialState();
377
+ this.notifyListeners();
378
+ } catch (error) {
379
+ console.warn("Failed to clear localStorage:", error);
380
+ }
381
+ }
382
+ debugStorage() {
383
+ try {
384
+ const stored = localStorage.getItem(this.STORAGE_KEY);
385
+ console.log("Current localStorage data:", stored);
386
+ if (stored) {
387
+ console.log("Parsed localStorage data:", JSON.parse(stored));
388
+ }
389
+ console.log("Current state:", this.state);
390
+ } catch (error) {
391
+ console.error("Error debugging storage:", error);
392
+ }
393
+ }
394
+ getConferenceLines() {
395
+ return this.state.conferenceLine || [];
396
+ }
397
+ };
398
+ var sdkStateManager = new SDKStateManager();
399
+
400
+ // call-control-sdk/lib/hooks/eventsTracker.ts
401
+ var EventTrackerSDK = class {
402
+ constructor() {
403
+ __publicField(this, "config", null);
404
+ __publicField(this, "ticketId", null);
405
+ __publicField(this, "baseUrl", "");
406
+ __publicField(this, "eventQueue", []);
407
+ // private isOnline: boolean = true;
408
+ // private retryQueue: Array<() => Promise<void>> = [];
409
+ __publicField(this, "flushTimer", null);
410
+ }
411
+ async init(config) {
412
+ this.config = __spreadValues({
413
+ autoTrack: true,
414
+ retryAttempts: 3,
415
+ queueSize: 100,
416
+ flushInterval: 5e3
417
+ }, config);
418
+ this.baseUrl = config.baseUrl || (typeof window !== "undefined" ? window.location.origin : "");
419
+ this.setupNetworkDetection();
420
+ const ticket = await this.createTicket();
421
+ this.startPeriodicFlush();
422
+ console.log("EventTracker SDK initialized successfully");
423
+ return ticket;
424
+ }
425
+ isInitialized() {
426
+ return this.config !== null && this.ticketId !== null;
427
+ }
428
+ getConfig() {
429
+ return this.config;
430
+ }
431
+ getTicketId() {
432
+ return this.ticketId;
433
+ }
434
+ async createTicket() {
435
+ if (!this.config) {
436
+ throw new Error("EventTracker not initialized");
437
+ }
438
+ try {
439
+ const response = await this.makeRequest("/api/v1/et/init", {
440
+ method: "POST",
441
+ headers: {
442
+ "Content-Type": "application/json",
443
+ "X-API-Key": this.config.apiKey
444
+ },
445
+ body: JSON.stringify({
446
+ agentId: this.config.agentId,
447
+ sessionId: this.config.sessionId
448
+ })
449
+ });
450
+ if (!response.ok) {
451
+ sdkStateManager.setInitCheck();
452
+ throw new Error(`Failed to initialize: ${response.status} ${response.statusText}`);
453
+ }
454
+ const data = await response.json();
455
+ this.ticketId = data.ticketId;
456
+ if (this.config.autoTrack) {
457
+ this.setupAutoTracking();
458
+ }
459
+ return data;
460
+ } catch (error) {
461
+ console.error("EventTracker initialization failed:", error);
462
+ throw error;
463
+ }
464
+ }
465
+ async logEvent(eventType, eventData) {
466
+ if (!this.config || !this.ticketId) {
467
+ console.warn("EventTracker not initialized, skipping event:", eventType);
468
+ return;
469
+ }
470
+ const event = {
471
+ eventType,
472
+ eventData,
473
+ timestamp: Date.now()
474
+ };
475
+ this.eventQueue.push(event);
476
+ if (this.eventQueue.length > (this.config.queueSize || 100)) {
477
+ this.eventQueue.shift();
478
+ }
479
+ }
480
+ // private async sendEvent(event: {
481
+ // eventType: string;
482
+ // eventData?: EventData;
483
+ // timestamp: number;
484
+ // }): Promise<void> {
485
+ // if (!this.config || !this.ticketId) return;
486
+ // try {
487
+ // const response = await this.makeRequest("/api/v1/et/event", {
488
+ // method: "POST",
489
+ // headers: {
490
+ // "Content-Type": "application/json",
491
+ // "X-API-Key": this.config.apiKey,
492
+ // },
493
+ // body: JSON.stringify({
494
+ // ticketId: this.ticketId,
495
+ // eventType: event.eventType,
496
+ // eventData: event.eventData,
497
+ // }),
498
+ // });
499
+ // if (!response.ok) {
500
+ // throw new Error(`Failed to log event: ${response.status} ${response.statusText}`);
501
+ // }
502
+ // const index = this.eventQueue.findIndex((e) => e.timestamp === event.timestamp);
503
+ // if (index > -1) {
504
+ // this.eventQueue.splice(index, 1);
505
+ // }
506
+ // } catch (error) {
507
+ // console.error("Event logging failed:", error);
508
+ // // this.retryQueue.push(() => this.sendEvent(event));
509
+ // }
510
+ // }
511
+ // async closeTicket(): Promise<void> {
512
+ // if (!this.config || !this.ticketId) {
513
+ // throw new Error("EventTracker not initialized");
514
+ // }
515
+ // await this.flush();
516
+ // try {
517
+ // const response = await this.makeRequest("/api/v1/et/close", {
518
+ // method: "POST",
519
+ // headers: {
520
+ // "Content-Type": "application/json",
521
+ // "X-API-Key": this.config.apiKey,
522
+ // },
523
+ // body: JSON.stringify({
524
+ // ticketId: this.ticketId,
525
+ // }),
526
+ // });
527
+ // if (!response.ok) {
528
+ // throw new Error(`Failed to close ticket: ${response.status} ${response.statusText}`);
529
+ // }
530
+ // this.ticketId = null;
531
+ // this.stopPeriodicFlush();
532
+ // console.log("Ticket closed successfully");
533
+ // } catch (error) {
534
+ // console.error("Ticket close failed:", error);
535
+ // throw error;
536
+ // }
537
+ // }
538
+ // async flush(): Promise<void> {
539
+ // if (!this.isOnline || this.eventQueue.length === 0) return;
540
+ // // const eventsToFlush = [...this.eventQueue];
541
+ // // for (const event of eventsToFlush) {
542
+ // // await this.sendEvent(event);
543
+ // // }
544
+ // const retryItems = [...this.retryQueue];
545
+ // this.retryQueue = [];
546
+ // for (const retryFn of retryItems) {
547
+ // try {
548
+ // await retryFn();
549
+ // } catch (error) {
550
+ // console.error("Retry failed:", error);
551
+ // }
552
+ // }
553
+ // }
554
+ async makeRequest(url, options) {
555
+ var _a2;
556
+ const fullUrl = `${this.baseUrl}${url}`;
557
+ const maxRetries = ((_a2 = this.config) == null ? void 0 : _a2.retryAttempts) || 3;
558
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
559
+ try {
560
+ const response = await fetch(fullUrl, options);
561
+ return response;
562
+ } catch (error) {
563
+ if (attempt === maxRetries) {
564
+ throw error;
565
+ }
566
+ const delay = Math.min(1e3 * Math.pow(2, attempt - 1), 1e4);
567
+ await new Promise((resolve) => setTimeout(resolve, delay));
568
+ }
569
+ }
570
+ throw new Error("Max retries exceeded");
571
+ }
572
+ setupAutoTracking() {
573
+ var _a2;
574
+ if (typeof window === "undefined" || !((_a2 = this.config) == null ? void 0 : _a2.autoTrack)) return;
575
+ const autoTrackConfig = this.config.autoTrack === true ? {} : this.config.autoTrack;
576
+ if (autoTrackConfig.pageVisits !== false) {
577
+ this.logEvent("pageVisit", {
578
+ url: window.location.href,
579
+ title: document.title,
580
+ referrer: document.referrer,
581
+ userAgent: navigator.userAgent,
582
+ viewport: {
583
+ width: window.innerWidth,
584
+ height: window.innerHeight
585
+ },
586
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
587
+ }).catch((error) => console.warn("Failed to track page visit:", error));
588
+ }
589
+ if (autoTrackConfig.clicks !== false) {
590
+ document.addEventListener("click", (event) => {
591
+ var _a3;
592
+ const target = event.target;
593
+ if (target.tagName === "BUTTON" || target.tagName === "A" || target.onclick || target.getAttribute("role") === "button" || target instanceof HTMLButtonElement && target.type === "button") {
594
+ this.logEvent("click", {
595
+ element: target.tagName,
596
+ text: (_a3 = target.textContent) == null ? void 0 : _a3.trim().substring(0, 100),
597
+ href: target.getAttribute("href"),
598
+ id: target.id,
599
+ className: target.className,
600
+ role: target.getAttribute("role"),
601
+ position: {
602
+ x: event.clientX,
603
+ y: event.clientY
604
+ },
605
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
606
+ }).catch((error) => console.warn("Failed to track click:", error));
607
+ }
608
+ });
609
+ }
610
+ if (autoTrackConfig.forms !== false) {
611
+ document.addEventListener("submit", (event) => {
612
+ const target = event.target;
613
+ const formData = new FormData(target);
614
+ const formFields = {};
615
+ formData.forEach((value, key) => {
616
+ formFields[key] = value.toString();
617
+ });
618
+ this.logEvent("formSubmission", {
619
+ formId: target.id,
620
+ action: target.action,
621
+ method: target.method,
622
+ fields: Object.keys(formFields),
623
+ fieldCount: Object.keys(formFields).length,
624
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
625
+ }).catch((error) => console.warn("Failed to track form submission:", error));
626
+ });
627
+ }
628
+ if (autoTrackConfig.inputs !== false) {
629
+ let inputTimer;
630
+ document.addEventListener("input", (event) => {
631
+ const target = event.target;
632
+ if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT") {
633
+ clearTimeout(inputTimer);
634
+ inputTimer = setTimeout(() => {
635
+ var _a3;
636
+ this.logEvent("fieldChange", {
637
+ element: target.tagName,
638
+ type: target.getAttribute("type"),
639
+ name: target.getAttribute("name"),
640
+ id: target.id,
641
+ valueLength: ((_a3 = target.value) == null ? void 0 : _a3.length) || 0,
642
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
643
+ }).catch((error) => console.warn("Failed to track field change:", error));
644
+ }, 1e3);
645
+ }
646
+ });
647
+ }
648
+ const sessionStartTime = Date.now();
649
+ window.addEventListener("beforeunload", () => {
650
+ const sessionDuration = Date.now() - sessionStartTime;
651
+ this.logEvent("pageUnload", {
652
+ url: window.location.href,
653
+ sessionDuration,
654
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
655
+ });
656
+ });
657
+ if (autoTrackConfig.visibility !== false) {
658
+ document.addEventListener("visibilitychange", () => {
659
+ this.logEvent("visibilityChange", {
660
+ hidden: document.hidden,
661
+ visibilityState: document.visibilityState,
662
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
663
+ });
664
+ });
665
+ }
666
+ if (autoTrackConfig.errors !== false) {
667
+ window.addEventListener("error", (event) => {
668
+ this.logEvent("jsError", {
669
+ message: event.message,
670
+ filename: event.filename,
671
+ lineno: event.lineno,
672
+ colno: event.colno,
673
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
674
+ });
675
+ });
676
+ window.addEventListener("unhandledrejection", (event) => {
677
+ var _a3;
678
+ this.logEvent("unhandledRejection", {
679
+ reason: (_a3 = event.reason) == null ? void 0 : _a3.toString(),
680
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
681
+ });
682
+ });
683
+ }
684
+ if (autoTrackConfig.performance !== false && typeof window.performance !== "undefined" && window.performance.navigation) {
685
+ window.addEventListener("load", () => {
686
+ setTimeout(() => {
687
+ const navigation = window.performance.navigation;
688
+ const timing = window.performance.timing;
689
+ this.logEvent("performanceMetrics", {
690
+ navigationTime: timing.navigationStart,
691
+ loadTime: timing.loadEventEnd - timing.navigationStart,
692
+ domReady: timing.domContentLoadedEventEnd - timing.navigationStart,
693
+ renderTime: timing.loadEventEnd - timing.domContentLoadedEventEnd,
694
+ navigationType: navigation.type,
695
+ redirectCount: navigation.redirectCount,
696
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
697
+ });
698
+ }, 1e3);
699
+ });
700
+ }
701
+ }
702
+ setupNetworkDetection() {
703
+ if (typeof window === "undefined") return;
704
+ window.addEventListener("online", () => {
705
+ console.log("EventTracker: Back online, flushing queued events");
706
+ });
707
+ window.addEventListener("offline", () => {
708
+ console.log("EventTracker: Offline, queueing events");
709
+ });
710
+ }
711
+ startPeriodicFlush() {
712
+ if (this.flushTimer) {
713
+ clearInterval(this.flushTimer);
714
+ }
715
+ }
716
+ // private stopPeriodicFlush(): void {
717
+ // if (this.flushTimer) {
718
+ // clearInterval(this.flushTimer);
719
+ // this.flushTimer = null;
720
+ // }
721
+ // }
722
+ };
723
+ var eventTracker = new EventTrackerSDK();
724
+ if (typeof window !== "undefined") {
725
+ window.EventTracker = eventTracker;
726
+ }
727
+
728
+ // call-control-sdk/lib/hooks/useLogout.ts
729
+ import { useCallback, useState } from "react";
730
+
731
+ // call-control-sdk/lib/services/axios.ts
732
+ import axios from "axios";
733
+ var _a;
734
+ var DEFAULT_TOKEN = (_a = sdkStateManager.getSdkAuthToken()) != null ? _a : "";
735
+ var REQUEST_TIMEOUT = 6e4;
736
+ function getAuthToken() {
737
+ var _a2;
738
+ return (_a2 = sdkStateManager.getSdkAuthToken()) != null ? _a2 : "";
739
+ }
740
+ function createAxiosInstance() {
741
+ var _a2, _b, _c, _d;
742
+ const instance = axios.create({
743
+ baseURL: BASE_URL,
744
+ headers: {
745
+ "Content-Type": "application/json",
746
+ Accept: "application/json",
747
+ "x-tenant-id": (_b = (_a2 = sdkStateManager.getCredentials()) == null ? void 0 : _a2.tenantId) != null ? _b : "",
748
+ "x-api-key": (_d = (_c = sdkStateManager.getCredentials()) == null ? void 0 : _c.apiKey) != null ? _d : "",
749
+ Authorization: `${DEFAULT_TOKEN}`
750
+ },
751
+ timeout: REQUEST_TIMEOUT,
752
+ withCredentials: false
753
+ });
754
+ instance.interceptors.request.use(
755
+ (config) => {
756
+ const token = getAuthToken();
757
+ if (token && config.headers) {
758
+ config.headers.Authorization = `${token}`;
759
+ }
760
+ config.metadata = { startTime: (/* @__PURE__ */ new Date()).getTime() };
761
+ return config;
762
+ },
763
+ (error) => {
764
+ console.error("Request interceptor error:", error);
765
+ return Promise.reject(error);
766
+ }
767
+ );
768
+ instance.interceptors.response.use(
769
+ (response) => {
770
+ var _a3;
771
+ const endTime = (/* @__PURE__ */ new Date()).getTime();
772
+ const startTime = (_a3 = response.config.metadata) == null ? void 0 : _a3.startTime;
773
+ if (startTime) {
774
+ console.log(`Request to ${response.config.url} took ${endTime - startTime}ms`);
775
+ }
776
+ return response;
777
+ },
778
+ async (error) => {
779
+ var _a3;
780
+ const originalRequest = error.config;
781
+ if (((_a3 = error.response) == null ? void 0 : _a3.status) === 401 && !originalRequest._retry) {
782
+ sdkStateManager.setInitCheck();
783
+ console.warn("Unauthorized request, attempting retry...");
784
+ }
785
+ if (!error.response) {
786
+ console.error("Network error:", error.message);
787
+ error.message = "Network error: Please check your internet connection";
788
+ }
789
+ if (error.response && error.response.status >= 500) {
790
+ console.error("Server error:", error.response.status, error.response.data);
791
+ error.message = "Server error: Please try again later";
792
+ }
793
+ return Promise.reject(error);
794
+ }
795
+ );
796
+ return instance;
797
+ }
798
+ var axiosInstance = createAxiosInstance();
799
+ var axios_default = axiosInstance;
800
+
801
+ // call-control-sdk/lib/hooks/useLogout.ts
802
+ var useLogout = () => {
803
+ const [loading, setLoading] = useState(false);
804
+ const [success, setSuccess] = useState(false);
805
+ const [isError, setIsError] = useState(false);
806
+ const [error, setError] = useState(null);
807
+ const [data, setData] = useState(null);
808
+ const handleLogout = useCallback(async () => {
809
+ var _a2;
810
+ const state = JSON.parse((_a2 = localStorage.getItem(STORAGE_KEY)) != null ? _a2 : "");
811
+ setLoading(true);
812
+ const payload = {
813
+ action: "LOGOUTUSER",
814
+ userId: state.agentId || ""
815
+ };
816
+ return axios_default.post(END_POINT.LOGOUT, payload).then((res) => {
817
+ sdkStateManager.clearStorageAndReset();
818
+ localStorage.clear();
819
+ sessionStorage.clear();
820
+ setData(res == null ? void 0 : res.data);
821
+ setSuccess(true);
822
+ return res == null ? void 0 : res.data;
823
+ }).catch((err) => {
824
+ var _a3;
825
+ setIsError(true);
826
+ setError(err);
827
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
828
+ }).finally(() => {
829
+ setLoading(false);
830
+ });
831
+ }, []);
832
+ return {
833
+ logout: handleLogout,
834
+ isLoading: loading,
835
+ isSuccess: success,
836
+ isError,
837
+ error,
838
+ data
839
+ };
840
+ };
841
+
842
+ // call-control-sdk/lib/hooks/useEndCall.ts
843
+ import { useCallback as useCallback2, useState as useState2 } from "react";
844
+ var useEndCall = () => {
845
+ const [loading, setLoading] = useState2(false);
846
+ const [success, setSuccess] = useState2(false);
847
+ const [isError, setIsError] = useState2(false);
848
+ const [error, setError] = useState2(null);
849
+ const [data, setData] = useState2(null);
850
+ const handleEndCall = useCallback2(
851
+ async (data2) => {
852
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
853
+ const state = JSON.parse((_a2 = localStorage.getItem(STORAGE_KEY)) != null ? _a2 : "");
854
+ setLoading(true);
855
+ const payload = {
856
+ action: "ENDCALL",
857
+ userId: state == null ? void 0 : state.agentId,
858
+ processid: (_d = (_c = (_b = state == null ? void 0 : state.process) == null ? void 0 : _b.process_id) == null ? void 0 : _c.toString()) != null ? _d : "",
859
+ process_name: (_f = (_e = state == null ? void 0 : state.process) == null ? void 0 : _e.process_name) != null ? _f : "",
860
+ callreferenceid: (_h = (_g = state == null ? void 0 : state.callData) == null ? void 0 : _g.convox_id) != null ? _h : "",
861
+ mobile_number: (_j = (_i = state == null ? void 0 : state.callData) == null ? void 0 : _i.phone_number) != null ? _j : "",
862
+ disposition: (_k = data2 == null ? void 0 : data2.disposition) != null ? _k : "RES",
863
+ set_followUp: (_l = data2 == null ? void 0 : data2.followUp) != null ? _l : "N",
864
+ callback_date: (_m = data2 == null ? void 0 : data2.callbackDate) != null ? _m : "",
865
+ callback_hrs: (_n = data2 == null ? void 0 : data2.callbackHrs) != null ? _n : "",
866
+ callback_mins: (_o = data2 == null ? void 0 : data2.callbackMins) != null ? _o : "",
867
+ endcall_type: "CLOSE"
868
+ };
869
+ return axios_default.post(END_POINT.END_CALL, payload).then((res) => {
870
+ sdkStateManager.endCall();
871
+ setData(res == null ? void 0 : res.data);
872
+ setSuccess(true);
873
+ return res == null ? void 0 : res.data;
874
+ }).catch((err) => {
875
+ var _a3;
876
+ setIsError(true);
877
+ setError(err);
878
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
879
+ }).finally(() => {
880
+ setLoading(false);
881
+ });
882
+ },
883
+ []
884
+ );
885
+ return {
886
+ handleEndCall,
887
+ isLoading: loading,
888
+ isSuccess: success,
889
+ isError,
890
+ error,
891
+ data
892
+ };
893
+ };
894
+
895
+ // call-control-sdk/lib/hooks/useClickToCall.ts
896
+ import { useCallback as useCallback3, useState as useState3 } from "react";
897
+ var useClickToCall = () => {
898
+ const [loading, setLoading] = useState3(false);
899
+ const [success, setSuccess] = useState3(false);
900
+ const [isError, setIsError] = useState3(false);
901
+ const [error, setError] = useState3(null);
902
+ const [data, setData] = useState3(null);
903
+ const handleStartCall = useCallback3(async (data2) => {
904
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
905
+ const state = JSON.parse((_a2 = localStorage.getItem(STORAGE_KEY)) != null ? _a2 : "");
906
+ setLoading(true);
907
+ if (((_b = state == null ? void 0 : state.callData) == null ? void 0 : _b.status) === "IDLE") {
908
+ const payload = {
909
+ action: "CALL",
910
+ userId: state == null ? void 0 : state.agentId,
911
+ phone_number: data2 == null ? void 0 : data2.mobileNumber
912
+ };
913
+ return axios_default.post(END_POINT.CLICK_TO_CALL, payload).then((res) => {
914
+ setData(res == null ? void 0 : res.data);
915
+ setSuccess(true);
916
+ return res == null ? void 0 : res.data;
917
+ }).catch((err) => {
918
+ var _a3;
919
+ setIsError(true);
920
+ setError(err);
921
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
922
+ }).finally(() => {
923
+ setLoading(false);
924
+ });
925
+ } else if (((_c = state == null ? void 0 : state.callData) == null ? void 0 : _c.status) === "ONCALL") {
926
+ const line_used = (_e = (_d = state == null ? void 0 : state.conferenceLine) == null ? void 0 : _d.filter((each) => each.line !== 1)) == null ? void 0 : _e.find((each) => each.status === "IDLE" && !(each == null ? void 0 : each.isCallStart));
927
+ const payload = {
928
+ action: "EXTERNAL_CONFERENCE",
929
+ operation: `CALL${line_used.line}`,
930
+ line_used: String(line_used.line),
931
+ thirdparty_no: data2 == null ? void 0 : data2.mobileNumber,
932
+ userid: (_g = (_f = state.callData) == null ? void 0 : _f.agent_id) != null ? _g : "",
933
+ process: (_i = (_h = state.callData) == null ? void 0 : _h.process_name) != null ? _i : ""
934
+ };
935
+ return axios_default.post(END_POINT.CONFERENCE_CALL, payload).then((res) => {
936
+ setData(res == null ? void 0 : res.data);
937
+ setSuccess(true);
938
+ sdkStateManager.setConferenceLine(__spreadProps(__spreadValues({}, line_used), {
939
+ isCallStart: true,
940
+ status: "ONCALL",
941
+ phone: data2 == null ? void 0 : data2.mobileNumber
942
+ }));
943
+ sdkStateManager.setOpenConferenceDialog(true);
944
+ return res == null ? void 0 : res.data;
945
+ }).catch((err) => {
946
+ var _a3;
947
+ setIsError(true);
948
+ setError(err);
949
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
950
+ }).finally(() => {
951
+ setLoading(false);
952
+ });
953
+ } else {
954
+ alert("Agent is not ready");
955
+ }
956
+ }, []);
957
+ return {
958
+ handleStartCall,
959
+ isLoading: loading,
960
+ isSuccess: success,
961
+ isError,
962
+ error,
963
+ data
964
+ };
965
+ };
966
+
967
+ // call-control-sdk/lib/hooks/useGetCallerData.ts
968
+ import { useState as useState4, useEffect } from "react";
969
+ var useGetCallerData = () => {
970
+ const { process_id, process_name, status, phone_number, agent_id, convox_id } = sdkStateManager.getState().callData;
971
+ const initialCallData = {
972
+ phone_number,
973
+ status,
974
+ callReferenceId: convox_id,
975
+ agent_id,
976
+ process_id,
977
+ process_name
978
+ };
979
+ const [callData, setCallData] = useState4(initialCallData);
980
+ useEffect(() => {
981
+ const unsubscribe = sdkStateManager.subscribe(() => {
982
+ const { process_id: process_id2, process_name: process_name2, status: status2, phone_number: phone_number2, agent_id: agent_id2, convox_id: convox_id2 } = sdkStateManager.getState().callData;
983
+ const currentCallData = {
984
+ phone_number: phone_number2,
985
+ status: status2,
986
+ callReferenceId: convox_id2,
987
+ agent_id: agent_id2,
988
+ process_id: process_id2,
989
+ process_name: process_name2
990
+ };
991
+ setCallData(currentCallData);
992
+ });
993
+ return unsubscribe;
994
+ }, []);
995
+ return callData;
996
+ };
997
+
998
+ // call-control-sdk/lib/hooks/useGetAuthorizationToken.ts
999
+ import { useState as useState5, useEffect as useEffect2 } from "react";
1000
+ var useGetAuthorizationToken = () => {
1001
+ const [token, setToken] = useState5(sdkStateManager.getSdkAuthToken());
1002
+ useEffect2(() => {
1003
+ const unsubscribe = sdkStateManager.subscribe(() => {
1004
+ setToken(sdkStateManager.getSdkAuthToken());
1005
+ });
1006
+ return unsubscribe;
1007
+ }, []);
1008
+ return token;
1009
+ };
1010
+
1011
+ // call-control-sdk/lib/components/callControlPanel.tsx
1012
+ import { memo as memo2, useCallback as useCallback6 } from "react";
1013
+
1014
+ // call-control-sdk/lib/components/callControls.tsx
1015
+ import {
1016
+ CallEnd as CallEnd2,
1017
+ Close as Close2,
1018
+ DragIndicator,
1019
+ Group,
1020
+ KeyboardArrowDown,
1021
+ Layers,
1022
+ Mic as Mic2,
1023
+ MicOff as MicOff2,
1024
+ Pause as Pause2,
1025
+ Pending,
1026
+ Phone,
1027
+ PlayArrow as PlayArrow2,
1028
+ SupportAgent as SupportAgent2,
1029
+ TransferWithinAStation,
1030
+ Upcoming,
1031
+ WifiCalling3
1032
+ } from "@mui/icons-material";
1033
+ import {
1034
+ Box as Box2,
1035
+ Button as Button2,
1036
+ Chip,
1037
+ CircularProgress as CircularProgress2,
1038
+ Fade,
1039
+ IconButton as IconButton2,
1040
+ Menu,
1041
+ MenuItem,
1042
+ Paper as Paper2,
1043
+ TextField as TextField2,
1044
+ Tooltip as Tooltip2,
1045
+ Typography as Typography2,
1046
+ useTheme as useTheme3
1047
+ } from "@mui/material";
1048
+ import { useEffect as useEffect5, useRef as useRef2, useState as useState10 } from "react";
1049
+
1050
+ // call-control-sdk/lib/hooks/useDraggable.ts
1051
+ import { useCallback as useCallback4, useRef, useState as useState6 } from "react";
1052
+ function useDraggable(initialPosition, onPositionChange) {
1053
+ const [position, setPosition] = useState6(initialPosition);
1054
+ const [isDragging, setIsDragging] = useState6(false);
1055
+ const dragRef = useRef();
1056
+ const dragStart = useRef({ x: 0, y: 0 });
1057
+ const elementStart = useRef({ x: 0, y: 0 });
1058
+ const updatePosition = useCallback4(
1059
+ (newPosition) => {
1060
+ const element = dragRef.current;
1061
+ if (!element) return;
1062
+ const rect = element.getBoundingClientRect();
1063
+ const viewportWidth = window.innerWidth;
1064
+ const viewportHeight = window.innerHeight;
1065
+ const constrainedPosition = {
1066
+ x: Math.max(0, Math.min(newPosition.x, viewportWidth - rect.width)),
1067
+ y: Math.max(0, Math.min(newPosition.y, viewportHeight - rect.height))
1068
+ };
1069
+ setPosition(constrainedPosition);
1070
+ onPositionChange == null ? void 0 : onPositionChange(constrainedPosition);
1071
+ },
1072
+ [onPositionChange]
1073
+ );
1074
+ const handleStart = useCallback4(
1075
+ (clientX, clientY) => {
1076
+ setIsDragging(true);
1077
+ dragStart.current = { x: clientX, y: clientY };
1078
+ elementStart.current = position;
1079
+ const handleMove = (moveClientX, moveClientY) => {
1080
+ const deltaX = moveClientX - dragStart.current.x;
1081
+ const deltaY = moveClientY - dragStart.current.y;
1082
+ updatePosition({
1083
+ x: elementStart.current.x + deltaX,
1084
+ y: elementStart.current.y + deltaY
1085
+ });
1086
+ };
1087
+ const handleMouseMove = (e) => {
1088
+ e.preventDefault();
1089
+ handleMove(e.clientX, e.clientY);
1090
+ };
1091
+ const handleTouchMove = (e) => {
1092
+ e.preventDefault();
1093
+ const touch = e.touches[0];
1094
+ if (touch) {
1095
+ handleMove(touch.clientX, touch.clientY);
1096
+ }
1097
+ };
1098
+ const handleEnd = () => {
1099
+ setIsDragging(false);
1100
+ document.removeEventListener("mousemove", handleMouseMove);
1101
+ document.removeEventListener("mouseup", handleEnd);
1102
+ document.removeEventListener("touchmove", handleTouchMove);
1103
+ document.removeEventListener("touchend", handleEnd);
1104
+ };
1105
+ document.addEventListener("mousemove", handleMouseMove);
1106
+ document.addEventListener("mouseup", handleEnd);
1107
+ document.addEventListener("touchmove", handleTouchMove, {
1108
+ passive: false
1109
+ });
1110
+ document.addEventListener("touchend", handleEnd);
1111
+ },
1112
+ [position, updatePosition]
1113
+ );
1114
+ const handleMouseDown = useCallback4(
1115
+ (e) => {
1116
+ e.preventDefault();
1117
+ handleStart(e.clientX, e.clientY);
1118
+ },
1119
+ [handleStart]
1120
+ );
1121
+ const handleTouchStart = useCallback4(
1122
+ (e) => {
1123
+ e.preventDefault();
1124
+ const touch = e.touches[0];
1125
+ if (touch) {
1126
+ handleStart(touch.clientX, touch.clientY);
1127
+ }
1128
+ },
1129
+ [handleStart]
1130
+ );
1131
+ return {
1132
+ position,
1133
+ isDragging,
1134
+ dragRef,
1135
+ handleMouseDown,
1136
+ handleTouchStart
1137
+ };
1138
+ }
1139
+
1140
+ // call-control-sdk/lib/hooks/useSDKState.ts
1141
+ import { useState as useState7, useEffect as useEffect3 } from "react";
1142
+ function useSDKState() {
1143
+ const [state, setState] = useState7(sdkStateManager.getState());
1144
+ useEffect3(() => {
1145
+ const unsubscribe = sdkStateManager.subscribe(() => {
1146
+ setState(sdkStateManager.getState());
1147
+ });
1148
+ return unsubscribe;
1149
+ }, []);
1150
+ return state;
1151
+ }
1152
+
1153
+ // call-control-sdk/lib/services/request.ts
1154
+ import { useCallback as useCallback5, useReducer } from "react";
1155
+
1156
+ // call-control-sdk/lib/services/toastMessage.tsx
1157
+ import { createContext, useContext, useState as useState8 } from "react";
1158
+ import { Snackbar, Alert } from "@mui/material";
1159
+ import { jsx, jsxs } from "react/jsx-runtime";
1160
+ var ToastContext = createContext(void 0);
1161
+ var useToast = () => {
1162
+ const ctx = useContext(ToastContext);
1163
+ if (!ctx) throw new Error("useToast must be used inside ToastProvider");
1164
+ return ctx;
1165
+ };
1166
+ var ToastProvider = ({ children }) => {
1167
+ const [open, setOpen] = useState8(false);
1168
+ const [message, setMessage] = useState8("");
1169
+ const [severity, setSeverity] = useState8("info");
1170
+ const showToast = (msg, sev = "info") => {
1171
+ setMessage(msg);
1172
+ setSeverity(sev);
1173
+ setOpen(true);
1174
+ };
1175
+ return /* @__PURE__ */ jsxs(ToastContext.Provider, { value: { showToast }, children: [
1176
+ children,
1177
+ /* @__PURE__ */ jsx(
1178
+ Snackbar,
1179
+ {
1180
+ open,
1181
+ color: severity,
1182
+ autoHideDuration: 3e3,
1183
+ onClose: () => setOpen(false),
1184
+ anchorOrigin: { vertical: "top", horizontal: "right" },
1185
+ children: /* @__PURE__ */ jsx(
1186
+ Alert,
1187
+ {
1188
+ variant: "filled",
1189
+ severity,
1190
+ onClose: () => setOpen(false),
1191
+ sx: { width: "100%" },
1192
+ children: message
1193
+ }
1194
+ )
1195
+ }
1196
+ )
1197
+ ] });
1198
+ };
1199
+
1200
+ // call-control-sdk/lib/services/request.ts
1201
+ var initialState = {
1202
+ isLoading: false,
1203
+ isSuccess: false,
1204
+ isError: false,
1205
+ error: null,
1206
+ data: null
1207
+ };
1208
+ var reducer = (state, action) => {
1209
+ if (action.type === "isLoading") {
1210
+ return __spreadProps(__spreadValues({}, state), {
1211
+ isLoading: action.payload
1212
+ });
1213
+ } else if (action.type === "isSuccess") {
1214
+ return __spreadProps(__spreadValues({}, state), {
1215
+ isSuccess: true,
1216
+ data: action.payload
1217
+ });
1218
+ } else if (action.type === "isError") {
1219
+ return __spreadProps(__spreadValues({}, state), {
1220
+ isError: true,
1221
+ error: action.payload
1222
+ });
1223
+ } else if (action.type === "reset") {
1224
+ return {
1225
+ isLoading: false,
1226
+ isSuccess: false,
1227
+ isError: false,
1228
+ error: null,
1229
+ data: null
1230
+ };
1231
+ }
1232
+ throw Error("Unknown action.");
1233
+ };
1234
+ var usePostRequest = (props = {}) => {
1235
+ const { onSuccess = null, onError = null, disabledSuccessToast = false } = props;
1236
+ const { showToast } = useToast();
1237
+ const [state, dispatch] = useReducer(reducer, initialState);
1238
+ const postRequest = useCallback5(
1239
+ (url, payload, config = {}) => {
1240
+ dispatch({
1241
+ type: "isLoading",
1242
+ payload: true
1243
+ });
1244
+ axios_default.post(url, payload, config).then((res) => {
1245
+ var _a2;
1246
+ dispatch({
1247
+ type: "isSuccess",
1248
+ payload: res.data
1249
+ });
1250
+ onSuccess == null ? void 0 : onSuccess(res.data, payload);
1251
+ if (!disabledSuccessToast) {
1252
+ showToast((_a2 = res.data) == null ? void 0 : _a2.message, "success");
1253
+ }
1254
+ }).catch((err) => {
1255
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1256
+ const error = {
1257
+ status: (_b = (_a2 = err.response) == null ? void 0 : _a2.status) != null ? _b : 500,
1258
+ message: ((_d = (_c = err.response) == null ? void 0 : _c.data) == null ? void 0 : _d.detail) || ((_f = (_e = err.response) == null ? void 0 : _e.data) == null ? void 0 : _f.message) || err.message || "An unknown error occurred",
1259
+ data: (_h = (_g = err.response) == null ? void 0 : _g.data) != null ? _h : null,
1260
+ statusText: (_j = (_i = err.response) == null ? void 0 : _i.statusText) != null ? _j : "",
1261
+ code: (_k = err == null ? void 0 : err.code) != null ? _k : "",
1262
+ name: (_l = err == null ? void 0 : err.name) != null ? _l : ""
1263
+ };
1264
+ showToast(error.message, "error");
1265
+ dispatch({
1266
+ type: "isError",
1267
+ payload: error
1268
+ });
1269
+ onError == null ? void 0 : onError(error, payload);
1270
+ }).finally(() => {
1271
+ dispatch({
1272
+ type: "isLoading",
1273
+ payload: false
1274
+ });
1275
+ });
1276
+ },
1277
+ [onSuccess, onError, showToast]
1278
+ );
1279
+ return [postRequest, state];
1280
+ };
1281
+
1282
+ // call-control-sdk/lib/components/dialog.tsx
1283
+ import {
1284
+ Call,
1285
+ CallEnd,
1286
+ CallSplit,
1287
+ Close,
1288
+ Mic,
1289
+ MicOff,
1290
+ Pause,
1291
+ PhoneDisabled,
1292
+ PlayArrow,
1293
+ SupportAgent
1294
+ } from "@mui/icons-material";
1295
+ import {
1296
+ Box,
1297
+ Button,
1298
+ Dialog,
1299
+ IconButton,
1300
+ Paper,
1301
+ TextField,
1302
+ Typography,
1303
+ Autocomplete,
1304
+ Tooltip,
1305
+ useTheme as useTheme2,
1306
+ TableContainer,
1307
+ Table,
1308
+ TableHead,
1309
+ TableRow,
1310
+ TableCell,
1311
+ TableBody,
1312
+ CircularProgress
1313
+ } from "@mui/material";
1314
+ import { useEffect as useEffect4, useMemo, useState as useState9 } from "react";
1315
+
1316
+ // call-control-sdk/lib/components/styles.ts
1317
+ import { useTheme } from "@mui/material";
1318
+ var useStyles = ({
1319
+ disabled,
1320
+ enabled,
1321
+ outlined
1322
+ }) => {
1323
+ const theme = useTheme();
1324
+ return {
1325
+ disabled: __spreadValues({
1326
+ padding: "0px",
1327
+ margin: "0px",
1328
+ minWidth: "40px !important",
1329
+ borderRadius: "16px",
1330
+ border: `1px solid rgb(206, 204, 204)`,
1331
+ height: "40px",
1332
+ "&:hover": {
1333
+ boxShadow: " 0px 2px 2px rgba(0, 0, 0, 0.79)",
1334
+ border: `1px solid ${theme.palette.primary.main}`
1335
+ },
1336
+ "&:active": {
1337
+ bgcolor: "primary.main",
1338
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1339
+ }
1340
+ }, disabled),
1341
+ enabled: __spreadValues({
1342
+ padding: "0px",
1343
+ margin: "0px",
1344
+ minWidth: "40px !important",
1345
+ borderRadius: "16px",
1346
+ boxShadow: " 0px 2px 1px rgba(0, 0, 0, 0.507)",
1347
+ border: `1px solid ${theme.palette.primary.main}`,
1348
+ height: "40px",
1349
+ "&:hover": {
1350
+ boxShadow: " 0px 2px 1px rgba(0, 0, 0, 0.507)",
1351
+ border: `1px solid ${theme.palette.primary.main}`
1352
+ },
1353
+ "&:active": {
1354
+ bgcolor: "primary.main",
1355
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1356
+ }
1357
+ }, enabled),
1358
+ outlined: __spreadValues({
1359
+ padding: "0px",
1360
+ margin: "0px",
1361
+ minWidth: "40px !important",
1362
+ borderRadius: "16px",
1363
+ backgroundColor: theme.palette.grey[200],
1364
+ boxShadow: `0px 2px 1px ${theme.palette.primary.light}`,
1365
+ border: `0px solid ${theme.palette.primary.main}`,
1366
+ height: "40px",
1367
+ "&:hover": {
1368
+ boxShadow: `0px 2px 1px ${theme.palette.primary.main}`,
1369
+ border: `0px solid ${theme.palette.primary.main}`
1370
+ },
1371
+ "&:active": {
1372
+ bgcolor: "primary.main",
1373
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1374
+ }
1375
+ }, outlined)
1376
+ };
1377
+ };
1378
+ var styles_default = useStyles;
1379
+
1380
+ // call-control-sdk/lib/components/dialog.tsx
1381
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1382
+ var ConferenceTableRow = ({ each, isMergeCall }) => {
1383
+ var _a2, _b, _c, _d, _e;
1384
+ const state = useSDKState();
1385
+ const { showToast } = useToast();
1386
+ const { disabled, enabled, outlined } = styles_default({
1387
+ disabled: ((_a2 = state.sdkConfig) == null ? void 0 : _a2.disabled) || {},
1388
+ enabled: ((_b = state.sdkConfig) == null ? void 0 : _b.enabled) || {},
1389
+ outlined: ((_c = state.sdkConfig) == null ? void 0 : _c.outlined) || {}
1390
+ });
1391
+ const theme = useTheme2();
1392
+ const [conferenceCallStart, setConferenceCallStart] = useState9(false);
1393
+ const [conferenceCallMerge, setConferenceCallMerge] = useState9(false);
1394
+ const [conferenceCallHoldOrUnHold, setConferenceCallHoldOrUnHold] = useState9(false);
1395
+ const [conferenceCallMuteOrUnMute, setConferenceCallMuteOrUnMute] = useState9(false);
1396
+ const [conferenceCallEnd, setConferenceCallEnd] = useState9(false);
1397
+ const onConferenceLineUpdate = (line, data) => {
1398
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1399
+ };
1400
+ const onConferenceCallStart = (line, data) => {
1401
+ var _a3, _b2, _c2, _d2;
1402
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1403
+ setConferenceCallStart(true);
1404
+ const payload = {
1405
+ action: "EXTERNAL_CONFERENCE",
1406
+ operation: `CALL${line_used.line}`,
1407
+ line_used: String(line_used.line),
1408
+ thirdparty_no: line_used.phone,
1409
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1410
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1411
+ };
1412
+ axios_default.post(END_POINT.CONFERENCE_CALL, payload).then((res) => {
1413
+ var _a4;
1414
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1415
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1416
+ }).catch((err) => {
1417
+ var _a4, _b3, _c3, _d3;
1418
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1419
+ showToast(message, "error");
1420
+ }).finally(() => {
1421
+ setConferenceCallStart(false);
1422
+ });
1423
+ };
1424
+ const onMergeConferenceCall = (line, data) => {
1425
+ var _a3, _b2, _c2, _d2;
1426
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1427
+ setConferenceCallMerge(true);
1428
+ const payload = {
1429
+ action: "EXTERNAL_CONFERENCE",
1430
+ operation: `CONFERENCE`,
1431
+ line_used: String(line_used.line),
1432
+ thirdparty_no: line_used.phone,
1433
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1434
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1435
+ };
1436
+ axios_default.post(END_POINT.CONFERENCE_CALL, payload).then((res) => {
1437
+ var _a4;
1438
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1439
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1440
+ }).catch((err) => {
1441
+ var _a4, _b3, _c3, _d3;
1442
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1443
+ showToast(message, "error");
1444
+ }).finally(() => {
1445
+ setConferenceCallMerge(false);
1446
+ });
1447
+ };
1448
+ const onHoldOrUnHoldConferenceCall = (line, data, type) => {
1449
+ var _a3, _b2, _c2, _d2;
1450
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1451
+ setConferenceCallHoldOrUnHold(true);
1452
+ const payload = {
1453
+ action: "EXTERNAL_CONFERENCE",
1454
+ operation: type,
1455
+ hold_channel_no: type === "HOLDUSER" ? `hold${line_used.line}` : `unhold${line_used.line}`,
1456
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1457
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1458
+ };
1459
+ axios_default.post(END_POINT.CONFERENCE_CALL_HOLD_OR_UN_HOLD, payload).then((res) => {
1460
+ var _a4;
1461
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1462
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1463
+ }).catch((err) => {
1464
+ var _a4, _b3, _c3, _d3;
1465
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1466
+ showToast(message, "error");
1467
+ }).finally(() => {
1468
+ setConferenceCallHoldOrUnHold(false);
1469
+ });
1470
+ };
1471
+ const onMuteOrUnMuteConferenceCall = (line, data, type) => {
1472
+ var _a3, _b2, _c2, _d2;
1473
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1474
+ setConferenceCallMuteOrUnMute(true);
1475
+ const payload = {
1476
+ action: "EXTERNAL_CONFERENCE",
1477
+ operation: type,
1478
+ channel_no: type === "MUTEUSER" ? `mute${line_used.line}` : `play${line_used.line}`,
1479
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1480
+ thirdparty_no: line_used.phone,
1481
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1482
+ };
1483
+ axios_default.post(END_POINT.CONFERENCE_CALL_MUTE_OT_UN_MUTE, payload).then((res) => {
1484
+ var _a4;
1485
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1486
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1487
+ }).catch((err) => {
1488
+ var _a4, _b3, _c3, _d3;
1489
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1490
+ showToast(message, "error");
1491
+ }).finally(() => {
1492
+ setConferenceCallMuteOrUnMute(false);
1493
+ });
1494
+ };
1495
+ const onEndConferenceCall = (line, data) => {
1496
+ var _a3, _b2, _c2, _d2;
1497
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1498
+ setConferenceCallEnd(true);
1499
+ const payload = {
1500
+ action: "EXTERNAL_CONFERENCE",
1501
+ operation: "HANGUP_CHANNEL",
1502
+ line_used: String(line_used.line),
1503
+ user_type: `THIRDPARTY${line_used.line - 1}`,
1504
+ thirdparty_no: line_used.phone,
1505
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1506
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1507
+ };
1508
+ axios_default.post(END_POINT.CONFERENCE_CALL_END, payload).then((res) => {
1509
+ var _a4;
1510
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1511
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1512
+ }).catch((err) => {
1513
+ var _a4, _b3, _c3, _d3;
1514
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1515
+ showToast(message, "error");
1516
+ }).finally(() => {
1517
+ setConferenceCallEnd(false);
1518
+ });
1519
+ };
1520
+ return /* @__PURE__ */ jsxs2(
1521
+ TableRow,
1522
+ {
1523
+ sx: {
1524
+ border: "2px solid #fff"
1525
+ },
1526
+ children: [
1527
+ /* @__PURE__ */ jsx2(
1528
+ TableCell,
1529
+ {
1530
+ sx: {
1531
+ padding: "6px"
1532
+ },
1533
+ children: /* @__PURE__ */ jsxs2(Typography, { children: [
1534
+ "Line ",
1535
+ (_d = each == null ? void 0 : each.line) != null ? _d : "",
1536
+ ". "
1537
+ ] })
1538
+ }
1539
+ ),
1540
+ /* @__PURE__ */ jsx2(
1541
+ TableCell,
1542
+ {
1543
+ sx: {
1544
+ padding: "6px"
1545
+ },
1546
+ children: /* @__PURE__ */ jsx2(
1547
+ Typography,
1548
+ {
1549
+ variant: "body2",
1550
+ sx: {
1551
+ px: 1,
1552
+ borderRadius: "10px"
1553
+ },
1554
+ children: (_e = each == null ? void 0 : each.status) != null ? _e : ""
1555
+ }
1556
+ )
1557
+ }
1558
+ ),
1559
+ /* @__PURE__ */ jsx2(
1560
+ TableCell,
1561
+ {
1562
+ sx: {
1563
+ padding: "6px"
1564
+ },
1565
+ children: /* @__PURE__ */ jsx2(
1566
+ Button,
1567
+ {
1568
+ sx: {
1569
+ textTransform: "capitalize"
1570
+ },
1571
+ size: "small",
1572
+ children: /* @__PURE__ */ jsx2(Typography, { variant: "body2", children: (each == null ? void 0 : each.line) === 1 ? "Internal" : "External" })
1573
+ }
1574
+ )
1575
+ }
1576
+ ),
1577
+ /* @__PURE__ */ jsx2(
1578
+ TableCell,
1579
+ {
1580
+ sx: {
1581
+ padding: "6px"
1582
+ },
1583
+ children: /* @__PURE__ */ jsx2(
1584
+ TextField,
1585
+ {
1586
+ size: "small",
1587
+ placeholder: "Phone Number",
1588
+ fullWidth: true,
1589
+ value: (each == null ? void 0 : each.phone) || "",
1590
+ disabled: (each == null ? void 0 : each.line) === 1 || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "CONFERENCE" || (each == null ? void 0 : each.status) === "HOLD" || (each == null ? void 0 : each.status) === "MUTE",
1591
+ onChange: (e) => {
1592
+ onConferenceLineUpdate(each, { phone: e.target.value });
1593
+ }
1594
+ }
1595
+ )
1596
+ }
1597
+ ),
1598
+ /* @__PURE__ */ jsx2(
1599
+ TableCell,
1600
+ {
1601
+ sx: {
1602
+ padding: "6px"
1603
+ },
1604
+ children: /* @__PURE__ */ jsxs2(
1605
+ Box,
1606
+ {
1607
+ sx: {
1608
+ display: "flex",
1609
+ alignItems: "center",
1610
+ justifyContent: "space-around"
1611
+ },
1612
+ children: [
1613
+ (each == null ? void 0 : each.line) !== 1 && /* @__PURE__ */ jsx2(Tooltip, { title: "Call", children: /* @__PURE__ */ jsx2(
1614
+ Button,
1615
+ {
1616
+ variant: (each == null ? void 0 : each.status) !== "IDLE" ? "outlined" : "contained",
1617
+ color: "success",
1618
+ sx: (each == null ? void 0 : each.status) !== "IDLE" ? __spreadValues({}, disabled) : __spreadProps(__spreadValues({}, enabled), {
1619
+ border: `0px solid ${theme.palette.success.light}`,
1620
+ "&:hover": {
1621
+ bgcolor: "success.light",
1622
+ boxShadow: `0px 2px 1px ${theme.palette.success.light}`,
1623
+ border: `0px solid ${theme.palette.success.light}`
1624
+ },
1625
+ "&:active": {
1626
+ bgcolor: "success.light",
1627
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1628
+ }
1629
+ }),
1630
+ onClick: () => {
1631
+ onConferenceCallStart(each, {});
1632
+ },
1633
+ disabled: (each == null ? void 0 : each.status) !== "IDLE",
1634
+ children: conferenceCallStart ? /* @__PURE__ */ jsx2(
1635
+ CircularProgress,
1636
+ {
1637
+ size: "20px",
1638
+ color: "success"
1639
+ }
1640
+ ) : /* @__PURE__ */ jsx2(
1641
+ Call,
1642
+ {
1643
+ sx: {
1644
+ color: (each == null ? void 0 : each.status) !== "IDLE" ? "default" : "#f3f2f2"
1645
+ }
1646
+ }
1647
+ )
1648
+ }
1649
+ ) }),
1650
+ (each == null ? void 0 : each.line) === 1 && /* @__PURE__ */ jsx2(Tooltip, { title: "Merge Call", children: /* @__PURE__ */ jsxs2(
1651
+ Button,
1652
+ {
1653
+ variant: isMergeCall ? "contained" : "outlined",
1654
+ sx: isMergeCall ? __spreadProps(__spreadValues({}, enabled), { padding: "0px 16px" }) : __spreadProps(__spreadValues({}, disabled), { padding: "0px 16px" }),
1655
+ onClick: () => {
1656
+ onMergeConferenceCall(each, {
1657
+ isMergeCall: true
1658
+ });
1659
+ },
1660
+ disabled: !isMergeCall || conferenceCallMerge,
1661
+ children: [
1662
+ (each == null ? void 0 : each.isMergeCall) ? "Merged" : "Merge",
1663
+ conferenceCallMerge ? /* @__PURE__ */ jsx2(CircularProgress, { size: "20px" }) : /* @__PURE__ */ jsx2(CallSplit, {})
1664
+ ]
1665
+ }
1666
+ ) }),
1667
+ /* @__PURE__ */ jsx2(Tooltip, { title: (each == null ? void 0 : each.status) !== "HOLD" ? "Hold" : "Un Hold", children: /* @__PURE__ */ jsx2(
1668
+ Button,
1669
+ {
1670
+ variant: (each == null ? void 0 : each.status) === "HOLD" ? "contained" : "outlined",
1671
+ sx: (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" ? __spreadValues({}, disabled) : (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" ? (
1672
+ // each.status === "IDLE"
1673
+ __spreadValues({}, outlined)
1674
+ ) : __spreadValues({}, disabled),
1675
+ onClick: () => {
1676
+ if (each.status === "HOLD") {
1677
+ onHoldOrUnHoldConferenceCall(each, { isHold: false }, "UNHOLDUSER");
1678
+ } else {
1679
+ onHoldOrUnHoldConferenceCall(each, { isHold: true }, "HOLDUSER");
1680
+ }
1681
+ },
1682
+ disabled: (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" || conferenceCallHoldOrUnHold,
1683
+ children: conferenceCallHoldOrUnHold ? /* @__PURE__ */ jsx2(
1684
+ CircularProgress,
1685
+ {
1686
+ size: "20px",
1687
+ sx: {
1688
+ color: theme.palette.primary.main
1689
+ }
1690
+ }
1691
+ ) : each.status === "HOLD" ? /* @__PURE__ */ jsx2(PlayArrow, {}) : /* @__PURE__ */ jsx2(Pause, {})
1692
+ }
1693
+ ) }),
1694
+ /* @__PURE__ */ jsx2(Tooltip, { title: each.status !== "MUTE" ? "Mute" : "Un Mute", children: /* @__PURE__ */ jsx2(
1695
+ Button,
1696
+ {
1697
+ variant: each.status === "MUTE" ? "contained" : "outlined",
1698
+ sx: each.status === "DISCONNECTED" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" ? __spreadValues({}, disabled) : (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
1699
+ onClick: () => {
1700
+ if (each.status === "MUTE") {
1701
+ onMuteOrUnMuteConferenceCall(each, { isMute: false }, "PLAYUSER");
1702
+ } else {
1703
+ onMuteOrUnMuteConferenceCall(each, { isMute: true }, "MUTEUSER");
1704
+ }
1705
+ },
1706
+ disabled: (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "HOLD" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" || conferenceCallMuteOrUnMute,
1707
+ children: conferenceCallMuteOrUnMute ? /* @__PURE__ */ jsx2(
1708
+ CircularProgress,
1709
+ {
1710
+ size: "20px",
1711
+ sx: {
1712
+ color: theme.palette.primary.main
1713
+ }
1714
+ }
1715
+ ) : each.status === "MUTE" ? /* @__PURE__ */ jsx2(MicOff, {}) : /* @__PURE__ */ jsx2(Mic, {})
1716
+ }
1717
+ ) }),
1718
+ (each == null ? void 0 : each.line) !== 1 ? /* @__PURE__ */ jsx2(Tooltip, { title: "End Call", children: /* @__PURE__ */ jsx2(
1719
+ Button,
1720
+ {
1721
+ variant: (each == null ? void 0 : each.status) !== "IDLE" && (each == null ? void 0 : each.status) !== "DISCONNECTED" ? "contained" : "outlined",
1722
+ color: "error",
1723
+ sx: (each == null ? void 0 : each.status) !== "IDLE" && (each == null ? void 0 : each.status) !== "DISCONNECTED" ? __spreadProps(__spreadValues({}, enabled), {
1724
+ border: `0px solid ${theme.palette.error.light}`,
1725
+ "&:hover": {
1726
+ bgcolor: "error.light",
1727
+ boxShadow: `0px 2px 1px ${theme.palette.error.light}`,
1728
+ border: `0px solid ${theme.palette.error.light}`
1729
+ },
1730
+ "&:active": {
1731
+ bgcolor: "error.light",
1732
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1733
+ }
1734
+ }) : __spreadValues({}, disabled),
1735
+ onClick: () => {
1736
+ onEndConferenceCall(each, {
1737
+ isCallStart: false,
1738
+ isMergeCall: false,
1739
+ isMute: false,
1740
+ isHold: false
1741
+ });
1742
+ },
1743
+ disabled: (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "DISCONNECTED" || conferenceCallEnd,
1744
+ children: conferenceCallEnd ? /* @__PURE__ */ jsx2(
1745
+ CircularProgress,
1746
+ {
1747
+ size: "20px",
1748
+ color: "error"
1749
+ }
1750
+ ) : /* @__PURE__ */ jsx2(CallEnd, {})
1751
+ }
1752
+ ) }) : /* @__PURE__ */ jsx2(
1753
+ Button,
1754
+ {
1755
+ variant: (each == null ? void 0 : each.status) !== "IDLE" || (each == null ? void 0 : each.status) !== "DISCONNECTED" ? "contained" : "outlined",
1756
+ color: "error",
1757
+ sx: {
1758
+ display: "none"
1759
+ },
1760
+ onClick: () => {
1761
+ onEndConferenceCall(each, {
1762
+ isCallStart: false,
1763
+ isMergeCall: false,
1764
+ isMute: false,
1765
+ isHold: false
1766
+ });
1767
+ },
1768
+ disabled: (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "DISCONNECTED" || conferenceCallEnd,
1769
+ children: conferenceCallEnd ? /* @__PURE__ */ jsx2(
1770
+ CircularProgress,
1771
+ {
1772
+ size: "20px",
1773
+ color: "error"
1774
+ }
1775
+ ) : /* @__PURE__ */ jsx2(CallEnd, {})
1776
+ }
1777
+ )
1778
+ ]
1779
+ }
1780
+ )
1781
+ }
1782
+ )
1783
+ ]
1784
+ },
1785
+ each.line
1786
+ );
1787
+ };
1788
+ function ConferenceDialog() {
1789
+ var _a2;
1790
+ const state = useSDKState();
1791
+ const { showToast } = useToast();
1792
+ const [conferenceCallEndAll, setConferenceCallEndAll] = useState9(false);
1793
+ const handleClose = () => {
1794
+ sdkStateManager.setOpenConferenceDialog(false);
1795
+ };
1796
+ const onEndAllConferenceCalls = () => {
1797
+ var _a3, _b, _c, _d;
1798
+ setConferenceCallEndAll(true);
1799
+ const payload = {
1800
+ action: "EXTERNAL_CONFERENCE",
1801
+ operation: "ENDCONFERENCE",
1802
+ userid: (_b = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b : "",
1803
+ process: (_d = (_c = state.callData) == null ? void 0 : _c.process_name) != null ? _d : ""
1804
+ };
1805
+ axios_default.post(END_POINT.CONFERENCE_CALL_END_ALL, payload).then((res) => {
1806
+ var _a4;
1807
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1808
+ sdkStateManager.resetConferenceLines();
1809
+ handleClose();
1810
+ }).catch((err) => {
1811
+ var _a4, _b2, _c2, _d2;
1812
+ const message = ((_b2 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b2.detail) || ((_d2 = (_c2 = err.response) == null ? void 0 : _c2.data) == null ? void 0 : _d2.message) || err.message || "An unknown error occurred";
1813
+ showToast(message, "error");
1814
+ }).finally(() => {
1815
+ setConferenceCallEndAll(false);
1816
+ });
1817
+ };
1818
+ const isMergeCall = useMemo(() => {
1819
+ var _a3;
1820
+ return (_a3 = state == null ? void 0 : state.conferenceLine) == null ? void 0 : _a3.some((each) => {
1821
+ if ((each == null ? void 0 : each.line) !== 1) {
1822
+ return (each == null ? void 0 : each.status) === "ONCALL";
1823
+ }
1824
+ return false;
1825
+ });
1826
+ }, [state == null ? void 0 : state.conferenceLine]);
1827
+ return /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2(
1828
+ Dialog,
1829
+ {
1830
+ open: state.openConferenceDialog,
1831
+ "aria-labelledby": "alert-dialog-title",
1832
+ "aria-describedby": "alert-dialog-description",
1833
+ fullWidth: true,
1834
+ maxWidth: "md",
1835
+ children: /* @__PURE__ */ jsxs2(Paper, { sx: { borderRadius: 2 }, children: [
1836
+ /* @__PURE__ */ jsxs2(
1837
+ Box,
1838
+ {
1839
+ sx: {
1840
+ display: "flex",
1841
+ justifyContent: "space-between",
1842
+ alignItems: "center",
1843
+ padding: "10px 16px"
1844
+ },
1845
+ children: [
1846
+ /* @__PURE__ */ jsxs2(Typography, { variant: "body1", children: [
1847
+ (_a2 = state == null ? void 0 : state.agentId) != null ? _a2 : "",
1848
+ " conference"
1849
+ ] }),
1850
+ /* @__PURE__ */ jsx2(IconButton, { onClick: handleClose, children: /* @__PURE__ */ jsx2(Close, {}) })
1851
+ ]
1852
+ }
1853
+ ),
1854
+ /* @__PURE__ */ jsx2(
1855
+ Box,
1856
+ {
1857
+ sx: {
1858
+ boxShadow: "1px 1px 2px #e7e5e5ff",
1859
+ margin: "0px 15px",
1860
+ borderRadius: "20px"
1861
+ },
1862
+ children: /* @__PURE__ */ jsx2(
1863
+ TableContainer,
1864
+ {
1865
+ component: Paper,
1866
+ sx: {
1867
+ outline: "0px solid gray !important",
1868
+ boxShadow: "1px 1px 6px #e7e5e5ff"
1869
+ },
1870
+ children: /* @__PURE__ */ jsxs2(
1871
+ Table,
1872
+ {
1873
+ sx: {
1874
+ border: "4px solid #ffffff !important"
1875
+ },
1876
+ children: [
1877
+ /* @__PURE__ */ jsx2(TableHead, { children: /* @__PURE__ */ jsxs2(
1878
+ TableRow,
1879
+ {
1880
+ sx: {
1881
+ border: "2px solid #f3f3f3ff !important"
1882
+ },
1883
+ children: [
1884
+ /* @__PURE__ */ jsx2(
1885
+ TableCell,
1886
+ {
1887
+ sx: {
1888
+ padding: "6px"
1889
+ },
1890
+ children: "Line"
1891
+ }
1892
+ ),
1893
+ /* @__PURE__ */ jsx2(
1894
+ TableCell,
1895
+ {
1896
+ sx: {
1897
+ padding: "6px"
1898
+ },
1899
+ children: "Status"
1900
+ }
1901
+ ),
1902
+ /* @__PURE__ */ jsx2(
1903
+ TableCell,
1904
+ {
1905
+ sx: {
1906
+ padding: "6px"
1907
+ },
1908
+ children: "Call Type"
1909
+ }
1910
+ ),
1911
+ /* @__PURE__ */ jsx2(
1912
+ TableCell,
1913
+ {
1914
+ sx: {
1915
+ padding: "6px"
1916
+ },
1917
+ children: "Mobile Number"
1918
+ }
1919
+ ),
1920
+ /* @__PURE__ */ jsx2(
1921
+ TableCell,
1922
+ {
1923
+ sx: {
1924
+ padding: "6px"
1925
+ },
1926
+ children: "Call Actions"
1927
+ }
1928
+ )
1929
+ ]
1930
+ }
1931
+ ) }),
1932
+ /* @__PURE__ */ jsx2(TableBody, { children: state == null ? void 0 : state.conferenceLine.map((each) => /* @__PURE__ */ jsx2(
1933
+ ConferenceTableRow,
1934
+ {
1935
+ each,
1936
+ isMergeCall
1937
+ }
1938
+ )) })
1939
+ ]
1940
+ }
1941
+ )
1942
+ }
1943
+ )
1944
+ }
1945
+ ),
1946
+ /* @__PURE__ */ jsx2(
1947
+ Box,
1948
+ {
1949
+ textAlign: "center",
1950
+ m: 2,
1951
+ children: /* @__PURE__ */ jsxs2(
1952
+ Button,
1953
+ {
1954
+ variant: "outlined",
1955
+ color: "error",
1956
+ size: "large",
1957
+ onClick: onEndAllConferenceCalls,
1958
+ disabled: conferenceCallEndAll,
1959
+ sx: { px: 2, borderRadius: "20px", textTransform: "capitalize" },
1960
+ children: [
1961
+ conferenceCallEndAll ? /* @__PURE__ */ jsx2(
1962
+ CircularProgress,
1963
+ {
1964
+ size: "20px",
1965
+ color: "error",
1966
+ sx: {
1967
+ marginRight: "8px"
1968
+ }
1969
+ }
1970
+ ) : /* @__PURE__ */ jsx2(
1971
+ IconButton,
1972
+ {
1973
+ sx: {
1974
+ bgcolor: "error.main",
1975
+ "&:hover": { bgcolor: "error.dark" },
1976
+ marginRight: "8px",
1977
+ width: "28px",
1978
+ height: "28px",
1979
+ fontSize: "12px",
1980
+ fontWeight: "600",
1981
+ lineHeight: "16px",
1982
+ letterSpacing: "0.02em",
1983
+ textTransform: "capitalize",
1984
+ color: "white",
1985
+ display: "flex",
1986
+ alignItems: "center",
1987
+ justifyContent: "center",
1988
+ borderRadius: "50%"
1989
+ },
1990
+ children: /* @__PURE__ */ jsx2(
1991
+ PhoneDisabled,
1992
+ {
1993
+ sx: {
1994
+ color: "white",
1995
+ fontSize: "16px",
1996
+ fontWeight: "600"
1997
+ }
1998
+ }
1999
+ )
2000
+ }
2001
+ ),
2002
+ "End Conference"
2003
+ ]
2004
+ }
2005
+ )
2006
+ }
2007
+ )
2008
+ ] })
2009
+ }
2010
+ ) });
2011
+ }
2012
+ function CallTransferDialog({ open }) {
2013
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
2014
+ const state = useSDKState();
2015
+ const [transferCall] = usePostRequest({
2016
+ onSuccess: () => {
2017
+ sdkStateManager.setOpenCallTransferDialog(false);
2018
+ }
2019
+ });
2020
+ const [currentselecteTab, setCurrentselecteTab] = useState9("process");
2021
+ const [getIdelAgentsList, { data: idleAgentsList, isLoading: isIdleAgentsListLoading }] = usePostRequest({
2022
+ disabledSuccessToast: true
2023
+ });
2024
+ const [
2025
+ getProcessAndQueuesList,
2026
+ { data: processAndQueuesList, isLoading: isProcessAndQueuesListLoading }
2027
+ ] = usePostRequest({
2028
+ disabledSuccessToast: true
2029
+ });
2030
+ const handleClose = () => {
2031
+ sdkStateManager.setOpenCallTransferDialog(false);
2032
+ };
2033
+ const handleTransferCall = (data, type) => {
2034
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
2035
+ if (type === "PROCESS") {
2036
+ const payload = {
2037
+ mobile_number: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.phone_number) != null ? _b2 : "",
2038
+ userid: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.agent_id) != null ? _d2 : "",
2039
+ type: "PROCESS",
2040
+ transfer_to: (_e2 = data == null ? void 0 : data.process_name) != null ? _e2 : "",
2041
+ callreferenceid: (_g2 = (_f2 = state.callData) == null ? void 0 : _f2.convox_id) != null ? _g2 : "",
2042
+ processid: String((_i2 = (_h2 = state.callData) == null ? void 0 : _h2.process_id) != null ? _i2 : ""),
2043
+ process_name: (_k2 = (_j2 = state.callData) == null ? void 0 : _j2.process_name) != null ? _k2 : ""
2044
+ };
2045
+ transferCall(END_POINT.TRANSFER_CALL, payload);
2046
+ } else if (type === "QUEUE") {
2047
+ const payload = {
2048
+ mobile_number: (_m = (_l2 = state.callData) == null ? void 0 : _l2.phone_number) != null ? _m : "",
2049
+ userid: (_o = (_n = state.callData) == null ? void 0 : _n.agent_id) != null ? _o : "",
2050
+ type: "QUEUE",
2051
+ transfer_to: (_p = data == null ? void 0 : data.queue_name) != null ? _p : "",
2052
+ callreferenceid: (_r = (_q = state.callData) == null ? void 0 : _q.convox_id) != null ? _r : "",
2053
+ processid: String((_t = (_s = state.callData) == null ? void 0 : _s.process_id) != null ? _t : ""),
2054
+ process_name: (_v = (_u = state.callData) == null ? void 0 : _u.process_name) != null ? _v : ""
2055
+ };
2056
+ transferCall(END_POINT.TRANSFER_CALL, payload);
2057
+ } else if (type === "AGENT") {
2058
+ const payload = {
2059
+ mobile_number: (_x = (_w = state.callData) == null ? void 0 : _w.phone_number) != null ? _x : "",
2060
+ userid: (_z = (_y = state.callData) == null ? void 0 : _y.agent_id) != null ? _z : "",
2061
+ type: "AGENT",
2062
+ transfer_to: (_A = data == null ? void 0 : data.user_id) != null ? _A : "",
2063
+ callreferenceid: (_C = (_B = state.callData) == null ? void 0 : _B.convox_id) != null ? _C : "",
2064
+ processid: String((_E = (_D = state.callData) == null ? void 0 : _D.process_id) != null ? _E : ""),
2065
+ process_name: (_G = (_F = state.callData) == null ? void 0 : _F.process_name) != null ? _G : ""
2066
+ };
2067
+ transferCall(END_POINT.TRANSFER_CALL, payload);
2068
+ }
2069
+ };
2070
+ useEffect4(() => {
2071
+ getIdelAgentsList(END_POINT.AGENTS_LIST, {
2072
+ status: "IDLE",
2073
+ active: true
2074
+ });
2075
+ getProcessAndQueuesList(END_POINT.TRANSFER_TO_DETAILS, {
2076
+ status: "ACTIVE",
2077
+ active: true
2078
+ });
2079
+ }, []);
2080
+ return /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2(
2081
+ Dialog,
2082
+ {
2083
+ open,
2084
+ "aria-labelledby": "alert-dialog-title",
2085
+ "aria-describedby": "alert-dialog-description",
2086
+ fullWidth: true,
2087
+ maxWidth: "md",
2088
+ children: /* @__PURE__ */ jsxs2(Paper, { sx: { borderRadius: 2 }, children: [
2089
+ /* @__PURE__ */ jsxs2(
2090
+ Box,
2091
+ {
2092
+ sx: {
2093
+ display: "flex",
2094
+ justifyContent: "space-between",
2095
+ alignItems: "center",
2096
+ padding: "4px 16px",
2097
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2098
+ },
2099
+ children: [
2100
+ /* @__PURE__ */ jsx2(Typography, { variant: "body1", children: " Call Transfer" }),
2101
+ /* @__PURE__ */ jsx2(IconButton, { onClick: handleClose, children: /* @__PURE__ */ jsx2(Close, {}) })
2102
+ ]
2103
+ }
2104
+ ),
2105
+ /* @__PURE__ */ jsxs2(
2106
+ Box,
2107
+ {
2108
+ sx: {
2109
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2110
+ padding: "6px 10px",
2111
+ margin: "10px",
2112
+ borderRadius: "10px"
2113
+ },
2114
+ children: [
2115
+ /* @__PURE__ */ jsxs2(Box, { sx: { display: "flex", gap: 1 }, children: [
2116
+ /* @__PURE__ */ jsx2(
2117
+ Button,
2118
+ {
2119
+ variant: currentselecteTab === "process" ? "contained" : "outlined",
2120
+ onClick: () => {
2121
+ setCurrentselecteTab("process");
2122
+ getProcessAndQueuesList(END_POINT.TRANSFER_TO_DETAILS, {
2123
+ status: "ACTIVE",
2124
+ active: true
2125
+ });
2126
+ },
2127
+ children: "Process"
2128
+ }
2129
+ ),
2130
+ /* @__PURE__ */ jsx2(
2131
+ Button,
2132
+ {
2133
+ variant: currentselecteTab === "queues" ? "contained" : "outlined",
2134
+ onClick: () => {
2135
+ setCurrentselecteTab("queues");
2136
+ getProcessAndQueuesList(END_POINT.TRANSFER_TO_DETAILS, {
2137
+ status: "ACTIVE",
2138
+ active: true
2139
+ });
2140
+ },
2141
+ children: "Queues"
2142
+ }
2143
+ ),
2144
+ /* @__PURE__ */ jsx2(
2145
+ Button,
2146
+ {
2147
+ variant: currentselecteTab === "agents" ? "contained" : "outlined",
2148
+ onClick: () => {
2149
+ setCurrentselecteTab("agents");
2150
+ getIdelAgentsList(END_POINT.AGENTS_LIST, {
2151
+ status: "IDLE",
2152
+ active: true
2153
+ });
2154
+ },
2155
+ children: "Agents"
2156
+ }
2157
+ )
2158
+ ] }),
2159
+ (isProcessAndQueuesListLoading || isIdleAgentsListLoading) && /* @__PURE__ */ jsxs2(
2160
+ Box,
2161
+ {
2162
+ sx: {
2163
+ display: "flex",
2164
+ justifyContent: "center",
2165
+ alignItems: "center",
2166
+ height: "80px"
2167
+ },
2168
+ children: [
2169
+ /* @__PURE__ */ jsx2(CircularProgress, {}),
2170
+ " "
2171
+ ]
2172
+ }
2173
+ ),
2174
+ !isProcessAndQueuesListLoading && !isIdleAgentsListLoading && currentselecteTab === "process" && /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap" }, children: ((_a2 = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _a2.process) && ((_c = (_b = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _b.process) == null ? void 0 : _c.length) > 0 ? (_e = (_d = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _d.process) == null ? void 0 : _e.map((process, index) => /* @__PURE__ */ jsxs2(
2175
+ Box,
2176
+ {
2177
+ sx: {
2178
+ p: 1,
2179
+ display: "flex",
2180
+ alignItems: "center",
2181
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2182
+ padding: "6px",
2183
+ borderRadius: "10px",
2184
+ "&:hover": { bgcolor: "action.selected" }
2185
+ },
2186
+ children: [
2187
+ /* @__PURE__ */ jsxs2(
2188
+ Typography,
2189
+ {
2190
+ variant: "body1",
2191
+ sx: {
2192
+ mx: 1,
2193
+ width: "200px",
2194
+ maxWidth: "250px",
2195
+ display: "flex",
2196
+ alignItems: "center"
2197
+ },
2198
+ children: [
2199
+ /* @__PURE__ */ jsx2(SupportAgent, { sx: { marginRight: "4px" } }),
2200
+ process.process_name
2201
+ ]
2202
+ }
2203
+ ),
2204
+ /* @__PURE__ */ jsx2(
2205
+ IconButton,
2206
+ {
2207
+ color: "success",
2208
+ sx: {
2209
+ bgcolor: "action.hover",
2210
+ "&:hover": { bgcolor: "action.selected" }
2211
+ },
2212
+ onClick: () => {
2213
+ handleTransferCall(process, "PROCESS");
2214
+ },
2215
+ children: /* @__PURE__ */ jsx2(Call, {})
2216
+ }
2217
+ )
2218
+ ]
2219
+ },
2220
+ index
2221
+ )) : /* @__PURE__ */ jsx2(
2222
+ Typography,
2223
+ {
2224
+ variant: "body1",
2225
+ sx: {
2226
+ fontSize: "16px",
2227
+ letterSpacing: "0.02em",
2228
+ textTransform: "capitalize",
2229
+ display: "flex",
2230
+ alignItems: "center",
2231
+ justifyContent: "center",
2232
+ width: "100%",
2233
+ margin: "10px 0px",
2234
+ color: "gray",
2235
+ height: "60px"
2236
+ },
2237
+ children: "No Process Found"
2238
+ }
2239
+ ) }),
2240
+ !isProcessAndQueuesListLoading && !isIdleAgentsListLoading && currentselecteTab === "queues" && /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap" }, children: ((_f = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _f.queue) && ((_h = (_g = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _g.queue) == null ? void 0 : _h.length) > 0 ? (_j = (_i = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _i.queue) == null ? void 0 : _j.map((queue, index) => {
2241
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2242
+ return /* @__PURE__ */ jsxs2(
2243
+ Box,
2244
+ {
2245
+ sx: {
2246
+ p: 1,
2247
+ display: "flex",
2248
+ alignItems: "center",
2249
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2250
+ padding: "6px",
2251
+ borderRadius: "10px",
2252
+ "&:hover": { bgcolor: "action.selected" }
2253
+ },
2254
+ children: [
2255
+ /* @__PURE__ */ jsxs2(
2256
+ Typography,
2257
+ {
2258
+ variant: "body1",
2259
+ sx: {
2260
+ mx: 1,
2261
+ width: "200px",
2262
+ maxWidth: "250px",
2263
+ display: "flex",
2264
+ alignItems: "center"
2265
+ },
2266
+ children: [
2267
+ /* @__PURE__ */ jsx2(SupportAgent, { sx: { marginRight: "4px" } }),
2268
+ queue.queue_name,
2269
+ ((_c2 = (_b2 = (_a3 = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _a3.process) == null ? void 0 : _b2.find(
2270
+ (process) => process.process_id === queue.process_id
2271
+ )) == null ? void 0 : _c2.process_name) ? /* @__PURE__ */ jsx2(
2272
+ Typography,
2273
+ {
2274
+ variant: "body1",
2275
+ sx: {
2276
+ fontSize: "12px",
2277
+ fontWeight: "600",
2278
+ letterSpacing: "0.02em",
2279
+ textTransform: "capitalize",
2280
+ color: "gray"
2281
+ },
2282
+ children: "(" + ((_f2 = (_e2 = (_d2 = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _d2.process) == null ? void 0 : _e2.find(
2283
+ (process) => process.process_id === queue.process_id
2284
+ )) == null ? void 0 : _f2.process_name) + ")"
2285
+ }
2286
+ ) : ""
2287
+ ]
2288
+ }
2289
+ ),
2290
+ /* @__PURE__ */ jsx2(
2291
+ IconButton,
2292
+ {
2293
+ color: "success",
2294
+ sx: {
2295
+ bgcolor: "action.hover",
2296
+ "&:hover": { bgcolor: "action.selected" }
2297
+ },
2298
+ onClick: () => {
2299
+ handleTransferCall(queue, "QUEUE");
2300
+ },
2301
+ children: /* @__PURE__ */ jsx2(Call, {})
2302
+ }
2303
+ )
2304
+ ]
2305
+ },
2306
+ index
2307
+ );
2308
+ }) : /* @__PURE__ */ jsx2(
2309
+ Typography,
2310
+ {
2311
+ variant: "body1",
2312
+ sx: {
2313
+ fontSize: "16px",
2314
+ letterSpacing: "0.02em",
2315
+ textTransform: "capitalize",
2316
+ display: "flex",
2317
+ alignItems: "center",
2318
+ justifyContent: "center",
2319
+ width: "100%",
2320
+ margin: "10px 0px",
2321
+ color: "gray",
2322
+ height: "60px"
2323
+ },
2324
+ children: "No Queues Found"
2325
+ }
2326
+ ) }),
2327
+ !isProcessAndQueuesListLoading && !isIdleAgentsListLoading && currentselecteTab === "agents" && /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap" }, children: (idleAgentsList == null ? void 0 : idleAgentsList.data) && ((_k = idleAgentsList == null ? void 0 : idleAgentsList.data) == null ? void 0 : _k.length) > 0 ? (_l = idleAgentsList == null ? void 0 : idleAgentsList.data) == null ? void 0 : _l.map((agent, index) => /* @__PURE__ */ jsxs2(
2328
+ Box,
2329
+ {
2330
+ sx: {
2331
+ p: 1,
2332
+ display: "flex",
2333
+ alignItems: "center",
2334
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2335
+ padding: "6px",
2336
+ borderRadius: "10px",
2337
+ "&:hover": { bgcolor: "action.selected" }
2338
+ },
2339
+ children: [
2340
+ /* @__PURE__ */ jsxs2(
2341
+ Typography,
2342
+ {
2343
+ variant: "body1",
2344
+ sx: {
2345
+ mx: 1,
2346
+ width: "200px",
2347
+ maxWidth: "250px",
2348
+ display: "flex",
2349
+ alignItems: "center"
2350
+ },
2351
+ children: [
2352
+ /* @__PURE__ */ jsx2(SupportAgent, { sx: { marginRight: "4px" } }),
2353
+ agent.name
2354
+ ]
2355
+ }
2356
+ ),
2357
+ /* @__PURE__ */ jsx2(
2358
+ IconButton,
2359
+ {
2360
+ color: "success",
2361
+ sx: {
2362
+ bgcolor: "action.hover",
2363
+ "&:hover": { bgcolor: "action.selected" }
2364
+ },
2365
+ onClick: () => {
2366
+ handleTransferCall(agent, "AGENT");
2367
+ },
2368
+ children: /* @__PURE__ */ jsx2(Call, {})
2369
+ }
2370
+ )
2371
+ ]
2372
+ },
2373
+ index
2374
+ )) : /* @__PURE__ */ jsx2(
2375
+ Typography,
2376
+ {
2377
+ variant: "body1",
2378
+ sx: {
2379
+ fontSize: "16px",
2380
+ letterSpacing: "0.02em",
2381
+ textTransform: "capitalize",
2382
+ display: "flex",
2383
+ alignItems: "center",
2384
+ justifyContent: "center",
2385
+ width: "100%",
2386
+ margin: "10px 0px",
2387
+ color: "gray",
2388
+ height: "60px"
2389
+ },
2390
+ children: "No Agents Found"
2391
+ }
2392
+ ) })
2393
+ ]
2394
+ }
2395
+ )
2396
+ ] })
2397
+ }
2398
+ ) });
2399
+ }
2400
+ function EndCallDispositionDialog({ open, setOpen, onSubmitDisposition }) {
2401
+ var _a2, _b, _c, _d;
2402
+ const [formData, setFormData] = useState9({
2403
+ disposition: { label: "Resolved", value: "RES" },
2404
+ followUp: { label: "No", value: "N" },
2405
+ callbackDate: "",
2406
+ callbackHrs: "",
2407
+ callbackMins: ""
2408
+ });
2409
+ const dispositionOptions = [
2410
+ { label: "Not Interested", value: "NI" },
2411
+ { label: "Resolved", value: "RES" }
2412
+ ];
2413
+ const followUpOptions = [
2414
+ { label: "Yes", value: "Y" },
2415
+ { label: "No", value: "N" }
2416
+ ];
2417
+ const handleChange = (field, value) => {
2418
+ setFormData((prev) => __spreadProps(__spreadValues({}, prev), { [field]: value }));
2419
+ };
2420
+ const handleReset = () => {
2421
+ setFormData({
2422
+ disposition: { label: "Resolved", value: "RES" },
2423
+ followUp: { label: "No", value: "N" },
2424
+ callbackDate: "",
2425
+ callbackHrs: "",
2426
+ callbackMins: ""
2427
+ });
2428
+ };
2429
+ const handleClose = () => {
2430
+ handleReset();
2431
+ setOpen(false);
2432
+ };
2433
+ return /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2(
2434
+ Dialog,
2435
+ {
2436
+ open,
2437
+ "aria-labelledby": "alert-dialog-title",
2438
+ "aria-describedby": "alert-dialog-description",
2439
+ fullWidth: true,
2440
+ maxWidth: "xs",
2441
+ children: /* @__PURE__ */ jsxs2(Paper, { sx: { borderRadius: 2 }, children: [
2442
+ /* @__PURE__ */ jsx2(
2443
+ Box,
2444
+ {
2445
+ sx: {
2446
+ display: "flex",
2447
+ justifyContent: "center",
2448
+ alignItems: "center",
2449
+ padding: "4px 16px",
2450
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2451
+ },
2452
+ children: /* @__PURE__ */ jsxs2(
2453
+ Typography,
2454
+ {
2455
+ variant: "body1",
2456
+ m: 1,
2457
+ children: [
2458
+ " ",
2459
+ "Call Disposition"
2460
+ ]
2461
+ }
2462
+ )
2463
+ }
2464
+ ),
2465
+ /* @__PURE__ */ jsxs2(
2466
+ Box,
2467
+ {
2468
+ sx: {
2469
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2470
+ padding: "10px",
2471
+ margin: "10px",
2472
+ borderRadius: "10px"
2473
+ },
2474
+ children: [
2475
+ /* @__PURE__ */ jsxs2(
2476
+ Box,
2477
+ {
2478
+ display: "flex",
2479
+ gap: 2,
2480
+ children: [
2481
+ /* @__PURE__ */ jsx2(
2482
+ Autocomplete,
2483
+ {
2484
+ value: formData.disposition,
2485
+ options: dispositionOptions,
2486
+ getOptionLabel: (opt) => opt.label,
2487
+ onChange: (_, val) => handleChange("disposition", val),
2488
+ size: "small",
2489
+ renderInput: (params) => /* @__PURE__ */ jsx2(
2490
+ TextField,
2491
+ __spreadProps(__spreadValues({}, params), {
2492
+ label: "Disposition",
2493
+ fullWidth: true
2494
+ })
2495
+ ),
2496
+ sx: { flex: 1 }
2497
+ }
2498
+ ),
2499
+ /* @__PURE__ */ jsx2(
2500
+ Autocomplete,
2501
+ {
2502
+ options: followUpOptions,
2503
+ getOptionLabel: (opt) => opt.label,
2504
+ value: formData.followUp,
2505
+ onChange: (_, val) => handleChange("followUp", val),
2506
+ size: "small",
2507
+ renderInput: (params) => /* @__PURE__ */ jsx2(
2508
+ TextField,
2509
+ __spreadProps(__spreadValues({}, params), {
2510
+ label: "Follow Up",
2511
+ fullWidth: true
2512
+ })
2513
+ ),
2514
+ sx: { flex: 1 }
2515
+ }
2516
+ )
2517
+ ]
2518
+ }
2519
+ ),
2520
+ ((_b = (_a2 = formData == null ? void 0 : formData.followUp) == null ? void 0 : _a2.label) == null ? void 0 : _b.toLowerCase()) === "yes" && /* @__PURE__ */ jsxs2(
2521
+ Box,
2522
+ {
2523
+ display: "flex",
2524
+ gap: 2,
2525
+ mt: 2,
2526
+ children: [
2527
+ /* @__PURE__ */ jsx2(
2528
+ TextField,
2529
+ {
2530
+ size: "small",
2531
+ label: "Callback Date",
2532
+ type: "date",
2533
+ slotProps: {
2534
+ inputLabel: { shrink: true }
2535
+ },
2536
+ value: formData.callbackDate,
2537
+ onChange: (e) => handleChange("callbackDate", e.target.value),
2538
+ fullWidth: true,
2539
+ sx: { flex: 1 }
2540
+ }
2541
+ ),
2542
+ /* @__PURE__ */ jsx2(
2543
+ TextField,
2544
+ {
2545
+ size: "small",
2546
+ label: "Hours (0-23)",
2547
+ type: "text",
2548
+ value: formData.callbackHrs,
2549
+ onChange: (e) => handleChange("callbackHrs", e.target.value),
2550
+ fullWidth: true,
2551
+ sx: { flex: 1 }
2552
+ }
2553
+ )
2554
+ ]
2555
+ }
2556
+ ),
2557
+ ((_d = (_c = formData == null ? void 0 : formData.followUp) == null ? void 0 : _c.label) == null ? void 0 : _d.toLowerCase()) === "yes" && /* @__PURE__ */ jsxs2(
2558
+ Box,
2559
+ {
2560
+ display: "flex",
2561
+ gap: 2,
2562
+ mt: 2,
2563
+ children: [
2564
+ /* @__PURE__ */ jsx2(
2565
+ TextField,
2566
+ {
2567
+ size: "small",
2568
+ label: "Minutes (0-59)",
2569
+ type: "text",
2570
+ value: formData.callbackMins,
2571
+ onChange: (e) => handleChange("callbackMins", e.target.value),
2572
+ fullWidth: true,
2573
+ sx: { flex: 1 }
2574
+ }
2575
+ ),
2576
+ /* @__PURE__ */ jsx2(Box, { sx: { flex: 1 } })
2577
+ ]
2578
+ }
2579
+ )
2580
+ ]
2581
+ }
2582
+ ),
2583
+ /* @__PURE__ */ jsxs2(
2584
+ Box,
2585
+ {
2586
+ textAlign: "right",
2587
+ m: 2,
2588
+ children: [
2589
+ /* @__PURE__ */ jsx2(
2590
+ Button,
2591
+ {
2592
+ variant: "outlined",
2593
+ color: "error",
2594
+ size: "large",
2595
+ onClick: handleClose,
2596
+ sx: {
2597
+ px: 2,
2598
+ mx: 1,
2599
+ borderRadius: "10px",
2600
+ textTransform: "capitalize"
2601
+ },
2602
+ children: "cancel"
2603
+ }
2604
+ ),
2605
+ /* @__PURE__ */ jsx2(
2606
+ Button,
2607
+ {
2608
+ variant: "contained",
2609
+ color: "primary",
2610
+ size: "large",
2611
+ onClick: () => onSubmitDisposition(formData),
2612
+ sx: { px: 2, borderRadius: "10px", textTransform: "capitalize" },
2613
+ children: "Submit"
2614
+ }
2615
+ )
2616
+ ]
2617
+ }
2618
+ )
2619
+ ] })
2620
+ }
2621
+ ) });
2622
+ }
2623
+ function ProcessorListDialog({
2624
+ open,
2625
+ setOpen,
2626
+ processList = null,
2627
+ handleSelectedProcessor
2628
+ }) {
2629
+ const handleClose = () => {
2630
+ setOpen(false);
2631
+ };
2632
+ return /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2(
2633
+ Dialog,
2634
+ {
2635
+ open,
2636
+ "aria-labelledby": "alert-dialog-title",
2637
+ "aria-describedby": "alert-dialog-description",
2638
+ maxWidth: "xs",
2639
+ children: /* @__PURE__ */ jsxs2(Paper, { sx: { borderRadius: 2 }, children: [
2640
+ /* @__PURE__ */ jsxs2(
2641
+ Box,
2642
+ {
2643
+ sx: {
2644
+ display: "flex",
2645
+ justifyContent: "space-between",
2646
+ alignItems: "center",
2647
+ padding: "4px 16px",
2648
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2649
+ },
2650
+ children: [
2651
+ /* @__PURE__ */ jsx2(Typography, { variant: "body1", children: " Process List" }),
2652
+ /* @__PURE__ */ jsx2(IconButton, { onClick: handleClose, children: /* @__PURE__ */ jsx2(Close, {}) })
2653
+ ]
2654
+ }
2655
+ ),
2656
+ /* @__PURE__ */ jsx2(
2657
+ Box,
2658
+ {
2659
+ sx: {
2660
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2661
+ padding: "6px 10px",
2662
+ margin: "10px",
2663
+ borderRadius: "10px"
2664
+ },
2665
+ children: processList.length > 0 ? processList == null ? void 0 : processList.map((process, index) => /* @__PURE__ */ jsx2(
2666
+ Box,
2667
+ {
2668
+ sx: {
2669
+ p: 1,
2670
+ display: "flex",
2671
+ alignItems: "center",
2672
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2673
+ padding: "6px",
2674
+ margin: "10px 0px",
2675
+ borderRadius: "10px",
2676
+ cursor: "pointer",
2677
+ "&:hover": { bgcolor: "action.selected" }
2678
+ },
2679
+ onClick: () => {
2680
+ handleSelectedProcessor(process);
2681
+ },
2682
+ children: /* @__PURE__ */ jsxs2(
2683
+ Typography,
2684
+ {
2685
+ variant: "body1",
2686
+ sx: {
2687
+ mx: 1,
2688
+ width: "200px",
2689
+ maxWidth: "250px",
2690
+ display: "flex",
2691
+ alignItems: "center"
2692
+ },
2693
+ children: [
2694
+ /* @__PURE__ */ jsx2(SupportAgent, { sx: { marginRight: "4px" } }),
2695
+ process.process_name
2696
+ ]
2697
+ }
2698
+ )
2699
+ },
2700
+ index
2701
+ )) : null
2702
+ }
2703
+ )
2704
+ ] })
2705
+ }
2706
+ ) });
2707
+ }
2708
+ function CallHistoryDialog({ open, setOpen }) {
2709
+ const handleClose = () => {
2710
+ setOpen(false);
2711
+ };
2712
+ return /* @__PURE__ */ jsx2(Fragment, { children: /* @__PURE__ */ jsx2(
2713
+ Dialog,
2714
+ {
2715
+ open,
2716
+ "aria-labelledby": "alert-dialog-title",
2717
+ "aria-describedby": "alert-dialog-description",
2718
+ fullWidth: true,
2719
+ maxWidth: "md",
2720
+ children: /* @__PURE__ */ jsxs2(Paper, { sx: { borderRadius: 2 }, children: [
2721
+ /* @__PURE__ */ jsxs2(
2722
+ Box,
2723
+ {
2724
+ sx: {
2725
+ display: "flex",
2726
+ justifyContent: "space-between",
2727
+ alignItems: "center",
2728
+ padding: "4px 16px",
2729
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2730
+ },
2731
+ children: [
2732
+ /* @__PURE__ */ jsx2(Typography, { variant: "body1", children: " Call History" }),
2733
+ /* @__PURE__ */ jsx2(IconButton, { onClick: handleClose, children: /* @__PURE__ */ jsx2(Close, {}) })
2734
+ ]
2735
+ }
2736
+ ),
2737
+ /* @__PURE__ */ jsx2(
2738
+ Box,
2739
+ {
2740
+ sx: {
2741
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2742
+ margin: "10px",
2743
+ borderRadius: "10px",
2744
+ textAlign: "center",
2745
+ fontSize: "16px",
2746
+ fontWeight: "bold"
2747
+ },
2748
+ p: 6,
2749
+ children: "Coming Soon..."
2750
+ }
2751
+ )
2752
+ ] })
2753
+ }
2754
+ ) });
2755
+ }
2756
+
2757
+ // call-control-sdk/lib/utils/audioLoader.ts
2758
+ import incomingRingtoneUrl from "./incoming-4WP3FJI4.mp3";
2759
+ var audioBlobUrl = null;
2760
+ var audioBuffer = null;
2761
+ async function loadAudioAsBlob() {
2762
+ if (audioBlobUrl) {
2763
+ return audioBlobUrl;
2764
+ }
2765
+ if (incomingRingtoneUrl.startsWith("data:") || incomingRingtoneUrl.startsWith("http://") || incomingRingtoneUrl.startsWith("https://") || incomingRingtoneUrl.startsWith("blob:")) {
2766
+ return incomingRingtoneUrl;
2767
+ }
2768
+ try {
2769
+ const response = await fetch(incomingRingtoneUrl);
2770
+ if (!response.ok) {
2771
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
2772
+ }
2773
+ const blob = await response.blob();
2774
+ if (blob.size === 0) {
2775
+ throw new Error("Empty blob");
2776
+ }
2777
+ audioBlobUrl = URL.createObjectURL(blob);
2778
+ return audioBlobUrl;
2779
+ } catch (error) {
2780
+ console.warn("Could not create blob URL, using direct URL:", error);
2781
+ return incomingRingtoneUrl;
2782
+ }
2783
+ }
2784
+ async function createAudioElement() {
2785
+ const audio = new Audio();
2786
+ audio.loop = true;
2787
+ audio.volume = 0.7;
2788
+ audio.preload = "auto";
2789
+ let audioUrl = "";
2790
+ try {
2791
+ audioUrl = await loadAudioAsBlob();
2792
+ } catch (error) {
2793
+ console.warn("Failed to load audio as blob, trying direct URL:", error);
2794
+ audioUrl = incomingRingtoneUrl;
2795
+ }
2796
+ const tryLoadAudio = async (url) => {
2797
+ return new Promise((resolve) => {
2798
+ const checkCanPlay = () => {
2799
+ const canPlay = audio.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA;
2800
+ if (canPlay) {
2801
+ resolve(true);
2802
+ return;
2803
+ }
2804
+ if (audio.error) {
2805
+ resolve(false);
2806
+ return;
2807
+ }
2808
+ setTimeout(checkCanPlay, 100);
2809
+ };
2810
+ audio.addEventListener("canplay", () => resolve(true), { once: true });
2811
+ audio.addEventListener("error", () => resolve(false), { once: true });
2812
+ audio.src = url;
2813
+ audio.load();
2814
+ setTimeout(() => resolve(false), 2e3);
2815
+ });
2816
+ };
2817
+ let loaded = await tryLoadAudio(audioUrl);
2818
+ if (!loaded && audioUrl !== incomingRingtoneUrl) {
2819
+ console.log("Primary URL failed, trying original import URL:", incomingRingtoneUrl);
2820
+ loaded = await tryLoadAudio(incomingRingtoneUrl);
2821
+ if (loaded) {
2822
+ audioUrl = incomingRingtoneUrl;
2823
+ }
2824
+ }
2825
+ if (!loaded) {
2826
+ console.error("Failed to load audio with all methods. URL:", audioUrl);
2827
+ }
2828
+ return audio;
2829
+ }
2830
+ function cleanupAudioResources() {
2831
+ if (audioBlobUrl) {
2832
+ URL.revokeObjectURL(audioBlobUrl);
2833
+ audioBlobUrl = null;
2834
+ }
2835
+ audioBuffer = null;
2836
+ }
2837
+
2838
+ // call-control-sdk/lib/components/callControls.tsx
2839
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
2840
+ var getCombineConfrenceData = (localState, apiData) => {
2841
+ const localConfrenceData = localState == null ? void 0 : localState.conferenceLine;
2842
+ const apiConferenceData = apiData == null ? void 0 : apiData.conferencestatus;
2843
+ const updatedConferenceData = localConfrenceData.map((item) => {
2844
+ var _a2, _b, _c, _d;
2845
+ if ((item == null ? void 0 : item.line) === 1) {
2846
+ const statusKey = `line_${item.line}_status`;
2847
+ return __spreadProps(__spreadValues({}, item), {
2848
+ line: 1,
2849
+ status: (_a2 = apiConferenceData[statusKey]) != null ? _a2 : item == null ? void 0 : item.status,
2850
+ phone: (_c = (_b = localState == null ? void 0 : localState.callData) == null ? void 0 : _b.phone_number) != null ? _c : ""
2851
+ });
2852
+ } else {
2853
+ const statusKey = `line_${item.line}_status`;
2854
+ const phoneKey = `line_${item.line}_phonenumber`;
2855
+ return __spreadProps(__spreadValues({}, item), {
2856
+ status: (_d = apiConferenceData[statusKey]) != null ? _d : item.status,
2857
+ phone: apiConferenceData[phoneKey] === null || apiConferenceData[phoneKey] === "0" ? item.phone : apiConferenceData[phoneKey]
2858
+ });
2859
+ }
2860
+ });
2861
+ return updatedConferenceData;
2862
+ };
2863
+ var formatDuration = (seconds) => {
2864
+ const mins = Math.floor(seconds / 60);
2865
+ const secs = seconds % 60;
2866
+ return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
2867
+ };
2868
+ function CallControls({ onDataChange }) {
2869
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa;
2870
+ const theme = useTheme3();
2871
+ const state = useSDKState();
2872
+ const { showToast } = useToast();
2873
+ const { disabled, enabled, outlined } = styles_default({
2874
+ disabled: ((_a2 = state.sdkConfig) == null ? void 0 : _a2.disabled) || {},
2875
+ enabled: ((_b = state.sdkConfig) == null ? void 0 : _b.enabled) || {},
2876
+ outlined: ((_c = state.sdkConfig) == null ? void 0 : _c.outlined) || {}
2877
+ });
2878
+ const webSocketRef = useRef2(null);
2879
+ const audioRef = useRef2(null);
2880
+ const reconnectTimeoutRef = useRef2(null);
2881
+ const pingIntervalRef = useRef2(null);
2882
+ const reconnectAttemptsRef = useRef2(0);
2883
+ const maxReconnectAttempts = 60;
2884
+ const baseReconnectDelay = 2e3;
2885
+ const maxReconnectDelay = 3e4;
2886
+ const [anchorEl, setAnchorEl] = useState10(null);
2887
+ const [showIframe, setShowIframe] = useState10(true);
2888
+ const [statusAnchorEl, setStatusAnchorEl] = useState10(null);
2889
+ const [dialerAnchorEl, setDialerAnchorEl] = useState10(null);
2890
+ const [openCallDisposition, setOpenCallDisposition] = useState10(false);
2891
+ const [openProcessorDialog, setOpenProcessorDialog] = useState10(false);
2892
+ const [openCallHistoryDialog, setOpenCallHistoryDialog] = useState10(false);
2893
+ const [processList, setProcessList] = useState10(null);
2894
+ const [phoneNumber, setPhoneNumber] = useState10("");
2895
+ const [callDuration, setCallDuration] = useState10(0);
2896
+ const { position, isDragging, dragRef, handleMouseDown, handleTouchStart } = useDraggable(
2897
+ state.controlPanelPosition,
2898
+ (newPosition) => sdkStateManager.setControlPanelPosition(newPosition)
2899
+ );
2900
+ const {
2901
+ position: iframePosition,
2902
+ isDragging: iframeIsDragging,
2903
+ dragRef: iframeDragRef,
2904
+ handleMouseDown: iframeHandleMouseDown,
2905
+ handleTouchStart: iframeHandleTouchStart
2906
+ } = useDraggable(
2907
+ state.iframePosition,
2908
+ (newPosition) => sdkStateManager.setIframePosition(newPosition)
2909
+ );
2910
+ const [clickToCall, { isLoading: clickToCallLoading }] = usePostRequest({
2911
+ onSuccess: () => {
2912
+ setPhoneNumber("");
2913
+ setDialerAnchorEl(null);
2914
+ }
2915
+ });
2916
+ const [holdOrUnHold, { isLoading: holdOrUnHoldLoading }] = usePostRequest({
2917
+ onSuccess: () => {
2918
+ sdkStateManager.setHolding(!state.isHolding);
2919
+ },
2920
+ onError: (error) => {
2921
+ console.log("\u274C Hold operation error:", error);
2922
+ }
2923
+ });
2924
+ const [muteOrUnMute, { isLoading: muteOrUnMuteLoading }] = usePostRequest({
2925
+ onSuccess: () => {
2926
+ sdkStateManager.setMuted(!state.isMuted);
2927
+ },
2928
+ onError: (error) => {
2929
+ console.log("\u274C Mute operation error:", error);
2930
+ }
2931
+ });
2932
+ const [readyAgentStatus, { isLoading: agentReadyLoading }] = usePostRequest();
2933
+ const [updateAgentStatus, { isLoading }] = usePostRequest();
2934
+ const [endCall, { isLoading: endCallLoading }] = usePostRequest();
2935
+ const handleCloseQueueCounts = () => {
2936
+ setAnchorEl(null);
2937
+ };
2938
+ const handleOpenDialer = (event) => {
2939
+ setShowIframe(true);
2940
+ setDialerAnchorEl(event.currentTarget);
2941
+ sdkStateManager.setStatus("dial");
2942
+ };
2943
+ const handleCloseDialer = () => {
2944
+ if (state.status !== "on call") {
2945
+ sdkStateManager.setStatus("idle");
2946
+ }
2947
+ setDialerAnchorEl(null);
2948
+ };
2949
+ const handleOpenAgentStatus = (event) => {
2950
+ setStatusAnchorEl(event.currentTarget);
2951
+ };
2952
+ const handleCloseAgentStatus = () => {
2953
+ setStatusAnchorEl(null);
2954
+ };
2955
+ const handleAgentReady = () => {
2956
+ const payload = {
2957
+ action: "READYAGENT",
2958
+ userId: state.agentId
2959
+ };
2960
+ readyAgentStatus(END_POINT.READY_AGENT, payload);
2961
+ };
2962
+ const handleUpdateAgentStatus = (status) => {
2963
+ setStatusAnchorEl(null);
2964
+ const payload = {
2965
+ action: "AGENTBREAK",
2966
+ break_type: status,
2967
+ userId: state.agentId
2968
+ };
2969
+ updateAgentStatus(END_POINT.UPDATE_AGENT_BREAK, payload);
2970
+ };
2971
+ const handleStartCall = (number) => {
2972
+ if (number.length !== 10) {
2973
+ showToast("Invalid phone number", "error");
2974
+ } else if (!/^\d+$/.test(number)) {
2975
+ showToast("Invalid phone number", "error");
2976
+ } else {
2977
+ const payload = {
2978
+ action: "CALL",
2979
+ phone_number: number,
2980
+ userId: state.agentId
2981
+ };
2982
+ clickToCall(END_POINT.CLICK_TO_CALL, payload);
2983
+ }
2984
+ };
2985
+ const handleHoldToggle = () => {
2986
+ const payload = {
2987
+ action: state.isHolding ? "UNHOLD" : "HOLD",
2988
+ userId: state.agentId
2989
+ };
2990
+ holdOrUnHold(END_POINT.HOLD_CALL, payload);
2991
+ };
2992
+ const handleMuteToggle = () => {
2993
+ const payload = {
2994
+ action: state.isMuted ? "UNMUTE" : "MUTE",
2995
+ userId: state.agentId
2996
+ };
2997
+ muteOrUnMute(END_POINT.MUTE_CALL, payload);
2998
+ };
2999
+ const handleEndCall = (data) => {
3000
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2;
3001
+ const payload = {
3002
+ action: "ENDCALL",
3003
+ userId: state.agentId,
3004
+ processid: (_c2 = (_b2 = (_a3 = state.process) == null ? void 0 : _a3.process_id) == null ? void 0 : _b2.toString()) != null ? _c2 : "",
3005
+ process_name: (_e2 = (_d2 = state.process) == null ? void 0 : _d2.process_name) != null ? _e2 : "",
3006
+ callreferenceid: (_g2 = (_f2 = state.callData) == null ? void 0 : _f2.convox_id) != null ? _g2 : "",
3007
+ mobile_number: (_i2 = (_h2 = state.callData) == null ? void 0 : _h2.phone_number) != null ? _i2 : "",
3008
+ disposition: (_k2 = (_j2 = data == null ? void 0 : data.disposition) == null ? void 0 : _j2.value) != null ? _k2 : "",
3009
+ set_followUp: (_m2 = (_l2 = data == null ? void 0 : data.followUp) == null ? void 0 : _l2.value) != null ? _m2 : "",
3010
+ callback_date: (_n2 = data == null ? void 0 : data.callbackDate) != null ? _n2 : "",
3011
+ callback_hrs: (_o2 = data == null ? void 0 : data.callbackHrs) != null ? _o2 : "",
3012
+ callback_mins: (_p2 = data == null ? void 0 : data.callbackMins) != null ? _p2 : "",
3013
+ endcall_type: "CLOSE"
3014
+ };
3015
+ setPhoneNumber("");
3016
+ endCall(END_POINT.END_CALL, payload);
3017
+ sdkStateManager.endCall();
3018
+ setOpenCallDisposition(false);
3019
+ };
3020
+ useEffect5(() => {
3021
+ const handleBeforeUnload = (e) => {
3022
+ e.preventDefault();
3023
+ };
3024
+ window.addEventListener("beforeunload", handleBeforeUnload);
3025
+ return () => {
3026
+ window.removeEventListener("beforeunload", handleBeforeUnload);
3027
+ };
3028
+ }, []);
3029
+ useEffect5(() => {
3030
+ let interval;
3031
+ if (state.callData.status && state.callData.status === "ONCALL") {
3032
+ interval = setInterval(() => {
3033
+ const elapsed = Math.floor((Date.now() - state.callStartTime) / 1e3);
3034
+ setCallDuration(elapsed);
3035
+ }, 1e3);
3036
+ } else {
3037
+ setCallDuration(0);
3038
+ }
3039
+ return () => {
3040
+ if (interval) clearInterval(interval);
3041
+ };
3042
+ }, [state.callData.status]);
3043
+ useEffect5(() => {
3044
+ createAudioElement().then((audio) => {
3045
+ audioRef.current = audio;
3046
+ }).catch((error) => {
3047
+ console.error("Failed to load audio element:", error);
3048
+ });
3049
+ return () => {
3050
+ if (audioRef.current) {
3051
+ audioRef.current.pause();
3052
+ audioRef.current.currentTime = 0;
3053
+ audioRef.current.src = "";
3054
+ audioRef.current = null;
3055
+ }
3056
+ cleanupAudioResources();
3057
+ };
3058
+ }, []);
3059
+ useEffect5(() => {
3060
+ if (onDataChange && state.callData) {
3061
+ const { process_id, process_name, status, phone_number, agent_id, convox_id } = state.callData;
3062
+ const callData = {
3063
+ phone_number,
3064
+ status,
3065
+ callReferenceId: convox_id,
3066
+ agent_id,
3067
+ process_id,
3068
+ process_name
3069
+ };
3070
+ onDataChange(callData);
3071
+ }
3072
+ }, [state.callData, onDataChange]);
3073
+ useEffect5(() => {
3074
+ if (state.agentId) {
3075
+ axios_default.post(END_POINT.PROCESS_LIST, {
3076
+ userId: state.agentId,
3077
+ action: "GETAGENTPROCESSLIST",
3078
+ refno: "1234221233"
3079
+ }).then((res) => {
3080
+ var _a3, _b2;
3081
+ if (res && res.data && ((_a3 = res == null ? void 0 : res.data) == null ? void 0 : _a3.length) > 1) {
3082
+ setProcessList(res.data.data);
3083
+ setOpenProcessorDialog(true);
3084
+ } else {
3085
+ sdkStateManager.setProcess((_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.data[0]);
3086
+ setOpenProcessorDialog(false);
3087
+ }
3088
+ }).catch((err) => {
3089
+ showToast(err.response.data.message, "error");
3090
+ });
3091
+ } else {
3092
+ console.log("No agentId available, skipping API call");
3093
+ }
3094
+ }, [state.agentId]);
3095
+ const connectWebSocket = () => {
3096
+ if (!state.agentId) {
3097
+ console.log("No agentId available, cannot connect WebSocket");
3098
+ return;
3099
+ }
3100
+ if (reconnectTimeoutRef.current) {
3101
+ clearTimeout(reconnectTimeoutRef.current);
3102
+ reconnectTimeoutRef.current = null;
3103
+ }
3104
+ try {
3105
+ webSocketRef.current = new WebSocket(`${WS_END_POINT.WS}?agent_id=${state.agentId}`);
3106
+ webSocketRef.current.onopen = () => {
3107
+ console.log("\u{1F310} WebSocket connection established");
3108
+ reconnectAttemptsRef.current = 0;
3109
+ if (pingIntervalRef.current) {
3110
+ clearInterval(pingIntervalRef.current);
3111
+ }
3112
+ pingIntervalRef.current = setInterval(() => {
3113
+ if (webSocketRef.current && webSocketRef.current.readyState === WebSocket.OPEN) {
3114
+ try {
3115
+ webSocketRef.current.send(JSON.stringify({ type: "ping" }));
3116
+ console.log("\u{1F4E1} WebSocket ping sent");
3117
+ } catch (error) {
3118
+ console.error("Failed to send ping:", error);
3119
+ }
3120
+ }
3121
+ }, 3e4);
3122
+ };
3123
+ webSocketRef.current.onmessage = (event) => {
3124
+ try {
3125
+ const data = JSON.parse(event.data);
3126
+ if (data.type === "pong") {
3127
+ console.log("\u{1F4E1} WebSocket pong received");
3128
+ return;
3129
+ }
3130
+ const rls = localStorage.getItem("call-control-sdk-state");
3131
+ const confrence = getCombineConfrenceData(JSON.parse(rls || "{}"), data);
3132
+ sdkStateManager.updateCallData(data);
3133
+ sdkStateManager.updateConferenceData([...confrence]);
3134
+ if (data.status === "RINGING" || data.status === "DIALING") {
3135
+ if (audioRef.current) {
3136
+ audioRef.current.play().catch((error) => {
3137
+ console.error("Failed to play ringtone:", error);
3138
+ });
3139
+ }
3140
+ } else {
3141
+ if (audioRef.current) {
3142
+ audioRef.current.pause();
3143
+ audioRef.current.currentTime = 0;
3144
+ }
3145
+ }
3146
+ if (data.status === "ONCALL") {
3147
+ sdkStateManager.startCall();
3148
+ if (!showIframe) {
3149
+ setShowIframe(true);
3150
+ }
3151
+ }
3152
+ if (data.status === "WRAPUP") {
3153
+ sdkStateManager.endCall();
3154
+ }
3155
+ } catch (e) {
3156
+ console.log("\u{1F4E8} Raw message:", event.data);
3157
+ }
3158
+ };
3159
+ webSocketRef.current.onclose = (event) => {
3160
+ console.log("\u{1F50C} WebSocket connection closed", event.code, event.reason);
3161
+ if (pingIntervalRef.current) {
3162
+ clearInterval(pingIntervalRef.current);
3163
+ pingIntervalRef.current = null;
3164
+ }
3165
+ if (event.code !== 1e3 && reconnectAttemptsRef.current < maxReconnectAttempts) {
3166
+ reconnectAttemptsRef.current += 1;
3167
+ const delay = Math.min(
3168
+ baseReconnectDelay * Math.pow(2, reconnectAttemptsRef.current - 1),
3169
+ maxReconnectDelay
3170
+ );
3171
+ console.log(
3172
+ `\u{1F504} Attempting to reconnect WebSocket (attempt ${reconnectAttemptsRef.current}/${maxReconnectAttempts}) in ${delay}ms`
3173
+ );
3174
+ reconnectTimeoutRef.current = setTimeout(() => {
3175
+ connectWebSocket();
3176
+ }, delay);
3177
+ } else if (reconnectAttemptsRef.current >= maxReconnectAttempts) {
3178
+ console.error("\u274C Maximum reconnection attempts reached. Please refresh the page.");
3179
+ showToast("WebSocket connection failed. Please refresh the page.", "error");
3180
+ }
3181
+ };
3182
+ webSocketRef.current.onerror = (error) => {
3183
+ console.error("\u274C WebSocket error:", error);
3184
+ };
3185
+ } catch (error) {
3186
+ console.error("\u274C Failed to create WebSocket:", error);
3187
+ if (reconnectAttemptsRef.current < maxReconnectAttempts) {
3188
+ reconnectAttemptsRef.current += 1;
3189
+ const delay = Math.min(
3190
+ baseReconnectDelay * Math.pow(2, reconnectAttemptsRef.current - 1),
3191
+ maxReconnectDelay
3192
+ );
3193
+ reconnectTimeoutRef.current = setTimeout(() => {
3194
+ connectWebSocket();
3195
+ }, delay);
3196
+ }
3197
+ }
3198
+ };
3199
+ useEffect5(() => {
3200
+ if (state.agentId) {
3201
+ connectWebSocket();
3202
+ }
3203
+ return () => {
3204
+ if (reconnectTimeoutRef.current) {
3205
+ clearTimeout(reconnectTimeoutRef.current);
3206
+ reconnectTimeoutRef.current = null;
3207
+ }
3208
+ if (pingIntervalRef.current) {
3209
+ clearInterval(pingIntervalRef.current);
3210
+ pingIntervalRef.current = null;
3211
+ }
3212
+ if (webSocketRef.current) {
3213
+ webSocketRef.current.close(1e3, "Component unmounting");
3214
+ webSocketRef.current = null;
3215
+ }
3216
+ reconnectAttemptsRef.current = 0;
3217
+ };
3218
+ }, [state.agentId]);
3219
+ if (!state.isInitialized || !state.process) {
3220
+ return /* @__PURE__ */ jsx3(Box2, { children: Boolean(openProcessorDialog) && /* @__PURE__ */ jsx3(
3221
+ ProcessorListDialog,
3222
+ {
3223
+ processList,
3224
+ open: openProcessorDialog,
3225
+ setOpen: setOpenProcessorDialog,
3226
+ handleSelectedProcessor: (data) => {
3227
+ sdkStateManager.setProcess(data);
3228
+ }
3229
+ }
3230
+ ) });
3231
+ }
3232
+ return /* @__PURE__ */ jsxs3(Fragment2, { children: [
3233
+ /* @__PURE__ */ jsx3(Box2, { children: /* @__PURE__ */ jsx3(
3234
+ Fade,
3235
+ {
3236
+ in: true,
3237
+ timeout: 300,
3238
+ children: /* @__PURE__ */ jsx3(
3239
+ Paper2,
3240
+ {
3241
+ ref: ((_d = state.sdkConfig) == null ? void 0 : _d.isDraggable) ? dragRef : null,
3242
+ elevation: isDragging ? 4 : ((_e = state.sdkConfig) == null ? void 0 : _e.isDraggable) ? 1 : 0,
3243
+ sx: {
3244
+ position: ((_f = state.sdkConfig) == null ? void 0 : _f.isDraggable) ? "fixed" : "relative",
3245
+ left: ((_g = state.sdkConfig) == null ? void 0 : _g.isDraggable) ? position.x : "auto",
3246
+ top: ((_h = state.sdkConfig) == null ? void 0 : _h.isDraggable) ? position.y : "auto",
3247
+ display: "inline-block",
3248
+ width: "auto",
3249
+ flexShrink: 0,
3250
+ whiteSpace: "nowrap",
3251
+ p: 0.5,
3252
+ borderRadius: 3,
3253
+ bgcolor: "background.paper",
3254
+ zIndex: ((_i = state.sdkConfig) == null ? void 0 : _i.isDraggable) ? Number.MAX_SAFE_INTEGER : 0,
3255
+ transition: theme.transitions.create(["box-shadow", "transform"], {
3256
+ duration: theme.transitions.duration.short
3257
+ }),
3258
+ userSelect: "none"
3259
+ },
3260
+ children: /* @__PURE__ */ jsxs3(
3261
+ Box2,
3262
+ {
3263
+ sx: {
3264
+ display: "flex",
3265
+ alignItems: "center"
3266
+ },
3267
+ children: [
3268
+ /* @__PURE__ */ jsxs3(
3269
+ Box2,
3270
+ {
3271
+ sx: {
3272
+ display: "flex",
3273
+ alignItems: "center",
3274
+ gap: 1,
3275
+ margin: "0px 10px"
3276
+ },
3277
+ children: [
3278
+ ((_j = state.sdkConfig) == null ? void 0 : _j.isDraggable) && /* @__PURE__ */ jsxs3(
3279
+ IconButton2,
3280
+ {
3281
+ component: "div",
3282
+ size: "small",
3283
+ sx: {
3284
+ cursor: "all-scroll"
3285
+ },
3286
+ onMouseDown: handleMouseDown,
3287
+ onTouchStart: handleTouchStart,
3288
+ children: [
3289
+ /* @__PURE__ */ jsx3(DragIndicator, {}),
3290
+ " "
3291
+ ]
3292
+ }
3293
+ ),
3294
+ /* @__PURE__ */ jsx3(Box2, { children: !((_k = state.sdkConfig) == null ? void 0 : _k.disabledDialButton) && /* @__PURE__ */ jsx3(Tooltip2, { title: "Dial", children: /* @__PURE__ */ jsx3(
3295
+ IconButton2,
3296
+ {
3297
+ size: "small",
3298
+ onClick: (e) => {
3299
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
3300
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) !== "ONCALL" && ((_d2 = (_c2 = state.callData) == null ? void 0 : _c2.status) == null ? void 0 : _d2.toUpperCase()) !== "BREAK" && ((_f2 = (_e2 = state.callData) == null ? void 0 : _e2.status) == null ? void 0 : _f2.toUpperCase()) !== "RINGING" && ((_h2 = (_g2 = state.callData) == null ? void 0 : _g2.status) == null ? void 0 : _h2.toUpperCase()) !== "WRAPUP") {
3301
+ handleOpenDialer(e);
3302
+ }
3303
+ },
3304
+ sx: {
3305
+ bgcolor: "action.hover",
3306
+ "&:hover": {
3307
+ bgcolor: "warning"
3308
+ }
3309
+ },
3310
+ children: /* @__PURE__ */ jsx3(
3311
+ WifiCalling3,
3312
+ {
3313
+ sx: {
3314
+ color: ((_m = (_l = state.callData) == null ? void 0 : _l.status) == null ? void 0 : _m.toUpperCase()) === "ONCALL" || ((_o = (_n = state.callData) == null ? void 0 : _n.status) == null ? void 0 : _o.toUpperCase()) === "BREAK" || ((_q = (_p = state.callData) == null ? void 0 : _p.status) == null ? void 0 : _q.toUpperCase()) === "RINGING" || ((_s = (_r = state.callData) == null ? void 0 : _r.status) == null ? void 0 : _s.toUpperCase()) === "WRAPUP" ? "action.selected" : "success.main"
3315
+ }
3316
+ }
3317
+ )
3318
+ }
3319
+ ) }) }),
3320
+ /* @__PURE__ */ jsx3(
3321
+ Typography2,
3322
+ {
3323
+ sx: {
3324
+ color: "success.main",
3325
+ width: "40px",
3326
+ marginRight: "10px",
3327
+ fontSize: "18px",
3328
+ fontWeight: "600"
3329
+ },
3330
+ children: formatDuration(callDuration)
3331
+ }
3332
+ ),
3333
+ /* @__PURE__ */ jsx3(
3334
+ Chip,
3335
+ {
3336
+ sx: {
3337
+ padding: "18px 0px"
3338
+ },
3339
+ label: isLoading || agentReadyLoading ? /* @__PURE__ */ jsx3(
3340
+ Box2,
3341
+ {
3342
+ sx: {
3343
+ fontWeight: "bold",
3344
+ width: "60px",
3345
+ display: "flex",
3346
+ alignItems: "center",
3347
+ justifyContent: "center"
3348
+ },
3349
+ children: /* @__PURE__ */ jsx3(CircularProgress2, { size: "20px" })
3350
+ }
3351
+ ) : /* @__PURE__ */ jsx3(
3352
+ Typography2,
3353
+ {
3354
+ variant: "body2",
3355
+ sx: {
3356
+ fontWeight: "bold",
3357
+ width: "60px",
3358
+ textAlign: "center"
3359
+ },
3360
+ children: (_v = (_u = (_t = state.callData) == null ? void 0 : _t.status) == null ? void 0 : _u.toUpperCase()) != null ? _v : "N/A"
3361
+ }
3362
+ ),
3363
+ onClick: handleOpenAgentStatus,
3364
+ deleteIcon: /* @__PURE__ */ jsx3(KeyboardArrowDown, { color: "primary" }),
3365
+ onDelete: handleOpenAgentStatus
3366
+ }
3367
+ )
3368
+ ]
3369
+ }
3370
+ ),
3371
+ /* @__PURE__ */ jsxs3(
3372
+ Box2,
3373
+ {
3374
+ sx: {
3375
+ display: "flex",
3376
+ gap: 1,
3377
+ justifyContent: "center",
3378
+ alignItems: "center"
3379
+ },
3380
+ children: [
3381
+ /* @__PURE__ */ jsx3(Tooltip2, { title: "Agent Ready", children: /* @__PURE__ */ jsx3(
3382
+ Button2,
3383
+ {
3384
+ variant: ((_x = (_w = state.callData) == null ? void 0 : _w.status) == null ? void 0 : _x.toUpperCase()) === "BREAK" || ((_z = (_y = state.callData) == null ? void 0 : _y.status) == null ? void 0 : _z.toUpperCase()) === "MISSED" ? "outlined" : "contained",
3385
+ onClick: (e) => {
3386
+ var _a3, _b2, _c2, _d2;
3387
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "BREAK" || ((_d2 = (_c2 = state.callData) == null ? void 0 : _c2.status) == null ? void 0 : _d2.toUpperCase()) === "MISSED") {
3388
+ e.stopPropagation();
3389
+ handleAgentReady();
3390
+ }
3391
+ },
3392
+ classes: {
3393
+ root: ((_B = (_A = state.callData) == null ? void 0 : _A.status) == null ? void 0 : _B.toUpperCase()) === "BREAK" || ((_D = (_C = state.callData) == null ? void 0 : _C.status) == null ? void 0 : _D.toUpperCase()) === "MISSED" ? "outlined" : "enabled"
3394
+ },
3395
+ sx: __spreadValues({}, ((_F = (_E = state.callData) == null ? void 0 : _E.status) == null ? void 0 : _F.toUpperCase()) === "BREAK" || ((_H = (_G = state.callData) == null ? void 0 : _G.status) == null ? void 0 : _H.toUpperCase()) === "MISSED" ? outlined : enabled),
3396
+ disabled: agentReadyLoading,
3397
+ children: /* @__PURE__ */ jsx3(SupportAgent2, {})
3398
+ }
3399
+ ) }),
3400
+ /* @__PURE__ */ jsx3(Tooltip2, { title: state.isHolding ? "Resume" : "Hold", children: /* @__PURE__ */ jsx3(
3401
+ Button2,
3402
+ {
3403
+ variant: state.isHolding && ((_J = (_I = state.callData) == null ? void 0 : _I.status) == null ? void 0 : _J.toUpperCase()) === "ONCALL" ? "contained" : "outlined",
3404
+ onClick: (e) => {
3405
+ e.stopPropagation();
3406
+ handleHoldToggle();
3407
+ },
3408
+ sx: state.isHolding && ((_L = (_K = state.callData) == null ? void 0 : _K.status) == null ? void 0 : _L.toUpperCase()) === "ONCALL" ? __spreadValues({}, enabled) : ((_N = (_M = state.callData) == null ? void 0 : _M.status) == null ? void 0 : _N.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3409
+ disabled: ((_P = (_O = state.callData) == null ? void 0 : _O.status) == null ? void 0 : _P.toUpperCase()) !== "ONCALL" && !state.isHolding || holdOrUnHoldLoading,
3410
+ children: holdOrUnHoldLoading ? /* @__PURE__ */ jsx3(
3411
+ CircularProgress2,
3412
+ {
3413
+ size: "20px",
3414
+ sx: {
3415
+ color: theme.palette.primary.main
3416
+ }
3417
+ }
3418
+ ) : state.isHolding ? /* @__PURE__ */ jsx3(PlayArrow2, {}) : /* @__PURE__ */ jsx3(Pause2, {})
3419
+ }
3420
+ ) }),
3421
+ /* @__PURE__ */ jsx3(Tooltip2, { title: state.isMuted ? "Unmute" : "Mute", children: /* @__PURE__ */ jsx3(
3422
+ Button2,
3423
+ {
3424
+ variant: state.isHolding ? "outlined" : state.isMuted && ((_R = (_Q = state.callData) == null ? void 0 : _Q.status) == null ? void 0 : _R.toUpperCase()) === "ONCALL" ? "contained" : "outlined",
3425
+ onClick: (e) => {
3426
+ e.stopPropagation();
3427
+ handleMuteToggle();
3428
+ },
3429
+ sx: state.isHolding ? __spreadValues({}, disabled) : state.isMuted && ((_T = (_S = state.callData) == null ? void 0 : _S.status) == null ? void 0 : _T.toUpperCase()) === "ONCALL" ? __spreadValues({}, enabled) : ((_V = (_U = state.callData) == null ? void 0 : _U.status) == null ? void 0 : _V.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3430
+ disabled: ((_X = (_W = state.callData) == null ? void 0 : _W.status) == null ? void 0 : _X.toUpperCase()) !== "ONCALL" && !state.isMuted || muteOrUnMuteLoading || state.isHolding,
3431
+ children: muteOrUnMuteLoading ? /* @__PURE__ */ jsx3(
3432
+ CircularProgress2,
3433
+ {
3434
+ size: "20px",
3435
+ sx: {
3436
+ color: theme.palette.primary.main
3437
+ }
3438
+ }
3439
+ ) : state.isMuted ? /* @__PURE__ */ jsx3(MicOff2, {}) : /* @__PURE__ */ jsx3(Mic2, {})
3440
+ }
3441
+ ) }),
3442
+ !((_Y = state.sdkConfig) == null ? void 0 : _Y.disableCallTransferButton) && /* @__PURE__ */ jsx3(Tooltip2, { title: "Transfer Call", children: /* @__PURE__ */ jsx3(
3443
+ Button2,
3444
+ {
3445
+ variant: state.openCallTransferDialog ? "contained" : "outlined",
3446
+ onClick: (e) => {
3447
+ var _a3, _b2;
3448
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "ONCALL") {
3449
+ e.stopPropagation();
3450
+ sdkStateManager.setOpenCallTransferDialog(true);
3451
+ }
3452
+ },
3453
+ sx: state.openCallTransferDialog ? __spreadValues({}, enabled) : ((__ = (_Z = state.callData) == null ? void 0 : _Z.status) == null ? void 0 : __.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3454
+ disabled: ((_aa = (_$ = state.callData) == null ? void 0 : _$.status) == null ? void 0 : _aa.toUpperCase()) !== "ONCALL",
3455
+ children: /* @__PURE__ */ jsx3(TransferWithinAStation, {})
3456
+ }
3457
+ ) }),
3458
+ !((_ba = state.sdkConfig) == null ? void 0 : _ba.disableConferenceButton) && /* @__PURE__ */ jsx3(Tooltip2, { title: "Conference Call", children: /* @__PURE__ */ jsx3(
3459
+ Button2,
3460
+ {
3461
+ variant: state.openConferenceDialog ? "contained" : "outlined",
3462
+ onClick: (e) => {
3463
+ var _a3, _b2;
3464
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "ONCALL") {
3465
+ e.stopPropagation();
3466
+ sdkStateManager.setOpenConferenceDialog(true);
3467
+ }
3468
+ },
3469
+ sx: state.openConferenceDialog ? __spreadValues({}, enabled) : ((_da = (_ca = state.callData) == null ? void 0 : _ca.status) == null ? void 0 : _da.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3470
+ disabled: ((_fa = (_ea = state.callData) == null ? void 0 : _ea.status) == null ? void 0 : _fa.toUpperCase()) !== "ONCALL",
3471
+ children: /* @__PURE__ */ jsx3(Group, {})
3472
+ }
3473
+ ) }),
3474
+ !((_ga = state.sdkConfig) == null ? void 0 : _ga.disableEndCallButton) && /* @__PURE__ */ jsx3(Tooltip2, { title: "End Call", children: /* @__PURE__ */ jsx3(
3475
+ Button2,
3476
+ {
3477
+ variant: ((_ia = (_ha = state.callData) == null ? void 0 : _ha.status) == null ? void 0 : _ia.toUpperCase()) === "ONCALL" || ((_ka = (_ja = state.callData) == null ? void 0 : _ja.status) == null ? void 0 : _ka.toUpperCase()) === "RINGING" || ((_ma = (_la = state.callData) == null ? void 0 : _la.status) == null ? void 0 : _ma.toUpperCase()) === "WRAPUP" ? "contained" : "outlined",
3478
+ onClick: (e) => {
3479
+ var _a3, _b2, _c2, _d2, _e2, _f2;
3480
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "ONCALL" || ((_d2 = (_c2 = state.callData) == null ? void 0 : _c2.status) == null ? void 0 : _d2.toUpperCase()) === "RINGING" || ((_f2 = (_e2 = state.callData) == null ? void 0 : _e2.status) == null ? void 0 : _f2.toUpperCase()) === "WRAPUP") {
3481
+ e.stopPropagation();
3482
+ setOpenCallDisposition(true);
3483
+ }
3484
+ },
3485
+ sx: ((_oa = (_na = state.callData) == null ? void 0 : _na.status) == null ? void 0 : _oa.toUpperCase()) === "ONCALL" || ((_qa = (_pa = state.callData) == null ? void 0 : _pa.status) == null ? void 0 : _qa.toUpperCase()) === "RINGING" || ((_sa = (_ra = state.callData) == null ? void 0 : _ra.status) == null ? void 0 : _sa.toUpperCase()) === "WRAPUP" ? __spreadProps(__spreadValues({}, enabled), {
3486
+ borderRight: "1px",
3487
+ backgroundColor: "error.main",
3488
+ minWidth: "60px !important",
3489
+ boxShadow: " 0px 2px 1px #5f3f3f",
3490
+ border: `1px solid ${theme.palette.error.light}`,
3491
+ height: "40px",
3492
+ "&:hover": {
3493
+ bgcolor: "error.light",
3494
+ boxShadow: " 0px 2px 1px #5f3f3f",
3495
+ border: `0px solid ${theme.palette.error.light}`
3496
+ },
3497
+ "&:active": {
3498
+ bgcolor: "error.light",
3499
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
3500
+ }
3501
+ }) : __spreadProps(__spreadValues({}, disabled), {
3502
+ minWidth: "60px !important"
3503
+ }),
3504
+ disabled: ((_ua = (_ta = state.callData) == null ? void 0 : _ta.status) == null ? void 0 : _ua.toUpperCase()) !== "ONCALL" && ((_wa = (_va = state.callData) == null ? void 0 : _va.status) == null ? void 0 : _wa.toUpperCase()) !== "RINGING" && ((_ya = (_xa = state.callData) == null ? void 0 : _xa.status) == null ? void 0 : _ya.toUpperCase()) !== "WRAPUP" || endCallLoading,
3505
+ children: endCallLoading ? /* @__PURE__ */ jsx3(
3506
+ CircularProgress2,
3507
+ {
3508
+ size: "20px",
3509
+ color: "error"
3510
+ }
3511
+ ) : /* @__PURE__ */ jsx3(CallEnd2, {})
3512
+ }
3513
+ ) })
3514
+ ]
3515
+ }
3516
+ )
3517
+ ]
3518
+ }
3519
+ )
3520
+ }
3521
+ )
3522
+ }
3523
+ ) }),
3524
+ /* @__PURE__ */ jsx3(
3525
+ Fade,
3526
+ {
3527
+ in: true,
3528
+ timeout: 300,
3529
+ children: /* @__PURE__ */ jsxs3(
3530
+ Paper2,
3531
+ {
3532
+ ref: iframeDragRef,
3533
+ elevation: iframeIsDragging ? 4 : 1,
3534
+ sx: {
3535
+ position: "absolute",
3536
+ left: iframePosition.x,
3537
+ top: iframePosition.y,
3538
+ borderRadius: 2,
3539
+ bgcolor: "background.paper",
3540
+ zIndex: Number.MAX_SAFE_INTEGER,
3541
+ transition: theme.transitions.create(["box-shadow", "transform"], {
3542
+ duration: theme.transitions.duration.short
3543
+ }),
3544
+ visibility: showIframe && !((_za = state.sdkConfig) == null ? void 0 : _za.disableSoftPhone) ? "visible" : "hidden",
3545
+ userSelect: "none"
3546
+ },
3547
+ children: [
3548
+ /* @__PURE__ */ jsxs3(
3549
+ Box2,
3550
+ {
3551
+ sx: {
3552
+ display: "flex",
3553
+ alignItems: "center",
3554
+ justifyContent: "space-between",
3555
+ cursor: "all-scroll",
3556
+ padding: "0px 10px"
3557
+ },
3558
+ onMouseDown: iframeHandleMouseDown,
3559
+ onTouchStart: iframeHandleTouchStart,
3560
+ children: [
3561
+ /* @__PURE__ */ jsx3(
3562
+ DragIndicator,
3563
+ {
3564
+ sx: {
3565
+ transform: "rotate(90deg)",
3566
+ color: "#7b7b7b"
3567
+ }
3568
+ }
3569
+ ),
3570
+ " ",
3571
+ /* @__PURE__ */ jsx3(IconButton2, { onClick: () => setShowIframe(false), children: /* @__PURE__ */ jsx3(Close2, {}) })
3572
+ ]
3573
+ }
3574
+ ),
3575
+ /* @__PURE__ */ jsx3(Box2, { children: /* @__PURE__ */ jsx3(
3576
+ "iframe",
3577
+ {
3578
+ src: `https://${IP}/ConVoxCCS/iframe?agent_id=${state.agentId}&process_id=${(_Aa = state.process) == null ? void 0 : _Aa.process_id}`,
3579
+ height: 380,
3580
+ width: 420,
3581
+ allow: "camera; microphone; autoplay",
3582
+ style: {
3583
+ border: "none"
3584
+ }
3585
+ }
3586
+ ) })
3587
+ ]
3588
+ }
3589
+ )
3590
+ }
3591
+ ),
3592
+ /* @__PURE__ */ jsx3(
3593
+ Menu,
3594
+ {
3595
+ anchorEl: dialerAnchorEl,
3596
+ open: Boolean(dialerAnchorEl),
3597
+ onClose: handleCloseDialer,
3598
+ onClick: (e) => e.stopPropagation(),
3599
+ sx: {
3600
+ zIndex: 99999
3601
+ },
3602
+ children: /* @__PURE__ */ jsxs3(
3603
+ Box2,
3604
+ {
3605
+ sx: {
3606
+ all: "unset",
3607
+ padding: "10px",
3608
+ "&hover": {
3609
+ backgroundColor: "white"
3610
+ }
3611
+ },
3612
+ children: [
3613
+ /* @__PURE__ */ jsx3(
3614
+ TextField2,
3615
+ {
3616
+ size: "small",
3617
+ value: phoneNumber,
3618
+ placeholder: "Enter Mobile No.",
3619
+ onChange: (e) => {
3620
+ setPhoneNumber(e.target.value);
3621
+ }
3622
+ }
3623
+ ),
3624
+ /* @__PURE__ */ jsx3(
3625
+ IconButton2,
3626
+ {
3627
+ color: "info",
3628
+ onClick: () => {
3629
+ handleStartCall(phoneNumber);
3630
+ },
3631
+ children: clickToCallLoading ? /* @__PURE__ */ jsx3(
3632
+ CircularProgress2,
3633
+ {
3634
+ size: "20px",
3635
+ sx: {
3636
+ color: theme.palette.success.main
3637
+ }
3638
+ }
3639
+ ) : /* @__PURE__ */ jsx3(Phone, { color: "success" })
3640
+ }
3641
+ )
3642
+ ]
3643
+ }
3644
+ )
3645
+ }
3646
+ ),
3647
+ /* @__PURE__ */ jsx3(
3648
+ Menu,
3649
+ {
3650
+ anchorEl: statusAnchorEl,
3651
+ open: Boolean(statusAnchorEl),
3652
+ onClose: handleCloseAgentStatus,
3653
+ onClick: (e) => e.stopPropagation(),
3654
+ sx: {
3655
+ zIndex: 99999
3656
+ },
3657
+ children: /* @__PURE__ */ jsx3(MenuItem, { onClick: () => handleUpdateAgentStatus("Lunch"), children: "- Break" })
3658
+ }
3659
+ ),
3660
+ /* @__PURE__ */ jsx3(
3661
+ Menu,
3662
+ {
3663
+ anchorEl,
3664
+ open: Boolean(anchorEl),
3665
+ onClose: handleCloseQueueCounts,
3666
+ onClick: (e) => e.stopPropagation(),
3667
+ sx: {
3668
+ zIndex: 99999
3669
+ },
3670
+ children: /* @__PURE__ */ jsxs3(
3671
+ Box2,
3672
+ {
3673
+ sx: {
3674
+ display: "flex",
3675
+ justifyContent: "flex-start",
3676
+ flexDirection: "column",
3677
+ padding: "0px 10px",
3678
+ "&hover": {
3679
+ backgroundColor: "white"
3680
+ }
3681
+ },
3682
+ children: [
3683
+ /* @__PURE__ */ jsx3(
3684
+ Chip,
3685
+ {
3686
+ icon: /* @__PURE__ */ jsx3(Layers, { color: "secondary" }),
3687
+ variant: "outlined",
3688
+ label: "Waiting - 25",
3689
+ sx: {
3690
+ margin: "4px 2px"
3691
+ }
3692
+ }
3693
+ ),
3694
+ /* @__PURE__ */ jsx3(
3695
+ Chip,
3696
+ {
3697
+ icon: /* @__PURE__ */ jsx3(Pending, { color: "info" }),
3698
+ label: "Pending - 99+",
3699
+ variant: "outlined",
3700
+ sx: {
3701
+ margin: "4px 2px"
3702
+ }
3703
+ }
3704
+ ),
3705
+ /* @__PURE__ */ jsx3(
3706
+ Chip,
3707
+ {
3708
+ icon: /* @__PURE__ */ jsx3(Upcoming, { color: "success" }),
3709
+ variant: "outlined",
3710
+ label: "Upcoming - 66",
3711
+ sx: {
3712
+ margin: "4px 2px"
3713
+ }
3714
+ }
3715
+ )
3716
+ ]
3717
+ }
3718
+ )
3719
+ }
3720
+ ),
3721
+ Boolean(state.openConferenceDialog) && /* @__PURE__ */ jsx3(ConferenceDialog, {}),
3722
+ Boolean(state.openCallTransferDialog) && /* @__PURE__ */ jsx3(CallTransferDialog, { open: state.openCallTransferDialog }),
3723
+ Boolean(openCallDisposition) && /* @__PURE__ */ jsx3(
3724
+ EndCallDispositionDialog,
3725
+ {
3726
+ open: openCallDisposition,
3727
+ setOpen: setOpenCallDisposition,
3728
+ onSubmitDisposition: handleEndCall
3729
+ }
3730
+ ),
3731
+ Boolean(openCallHistoryDialog) && /* @__PURE__ */ jsx3(
3732
+ CallHistoryDialog,
3733
+ {
3734
+ open: openCallHistoryDialog,
3735
+ setOpen: setOpenCallHistoryDialog
3736
+ }
3737
+ )
3738
+ ] });
3739
+ }
3740
+
3741
+ // call-control-sdk/lib/components/SDKProvider.tsx
3742
+ import { memo } from "react";
3743
+ import { jsx as jsx4 } from "react/jsx-runtime";
3744
+ var SDKProvider = memo(({ children }) => {
3745
+ return /* @__PURE__ */ jsx4(ToastProvider, { children });
3746
+ });
3747
+ SDKProvider.displayName = "SDKProvider";
3748
+
3749
+ // call-control-sdk/lib/components/callControlPanel.tsx
3750
+ import { jsx as jsx5 } from "react/jsx-runtime";
3751
+ var CallControlPanel = memo2(({ onDataChange }) => {
3752
+ const handleDataChange = useCallback6(
3753
+ (data) => {
3754
+ try {
3755
+ if (onDataChange && typeof onDataChange === "function") {
3756
+ onDataChange(data);
3757
+ }
3758
+ } catch (error) {
3759
+ console.error("Error in CallControlPanel data change handler:", error);
3760
+ }
3761
+ },
3762
+ [onDataChange]
3763
+ );
3764
+ return /* @__PURE__ */ jsx5(SDKProvider, { children: /* @__PURE__ */ jsx5(CallControls, { onDataChange: handleDataChange }) });
3765
+ });
3766
+ CallControlPanel.displayName = "CallControlPanel";
3767
+
3768
+ // call-control-sdk/index.ts
3769
+ async function initSDK({
3770
+ apiKey,
3771
+ tenantId,
3772
+ agentId,
3773
+ sdkConfig
3774
+ }) {
3775
+ if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
3776
+ throw new Error(
3777
+ "SDK initialization failed: API key is required and must be a non-empty string"
3778
+ );
3779
+ }
3780
+ if (!tenantId || typeof tenantId !== "string" || tenantId.trim().length === 0) {
3781
+ throw new Error(
3782
+ "SDK initialization failed: Tenant ID is required and must be a non-empty string"
3783
+ );
3784
+ }
3785
+ if (!agentId || typeof agentId !== "string" || agentId.trim().length === 0) {
3786
+ throw new Error(
3787
+ "SDK initialization failed: Agent ID is required and must be a non-empty string"
3788
+ );
3789
+ }
3790
+ try {
3791
+ const initResult = await eventTracker.init({
3792
+ apiKey: apiKey.trim(),
3793
+ tenantId: tenantId.trim(),
3794
+ agentId: agentId.trim(),
3795
+ baseUrl: BASE_URL
3796
+ });
3797
+ if (initResult) {
3798
+ console.log("SDK initialized successfully");
3799
+ sdkStateManager.initialize(
3800
+ apiKey.trim(),
3801
+ tenantId.trim(),
3802
+ agentId.trim(),
3803
+ sdkConfig,
3804
+ initResult
3805
+ );
3806
+ } else {
3807
+ console.error("SDK initialization failed: Event tracker initialization returned false");
3808
+ sdkStateManager.setInitCheck();
3809
+ throw new Error(
3810
+ "SDK initialization failed: Unable to establish connection with the CTI system"
3811
+ );
3812
+ }
3813
+ } catch (error) {
3814
+ console.error("SDK initialization error:", error);
3815
+ sdkStateManager.setInitCheck();
3816
+ if (error instanceof Error) {
3817
+ throw error;
3818
+ } else {
3819
+ throw new Error(`SDK initialization failed: ${String(error)}`);
3820
+ }
3821
+ }
3822
+ }
3823
+ function getSDKVersion() {
3824
+ return "6.x.x";
3825
+ }
3826
+ function isSDKInitialized() {
3827
+ return sdkStateManager.getState().isInitialized;
3828
+ }
3829
+ export {
3830
+ CallControlPanel,
3831
+ getSDKVersion,
3832
+ initSDK,
3833
+ isSDKInitialized,
3834
+ useClickToCall,
3835
+ useEndCall,
3836
+ useGetAuthorizationToken,
3837
+ useGetCallerData,
3838
+ useLogout
3839
+ };
2
3840
  //# sourceMappingURL=index.mjs.map