call-control-sdk 6.4.7 → 6.4.9-dev.0

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