call-control-sdk 6.4.5-dev.1 → 6.4.5-dev.11

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