call-control-sdk 6.4.5-dev.6 → 6.4.5-dev.7
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.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/dist/incoming-4WP3FJI4.mp3 +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var In=Object.defineProperty,$n=Object.defineProperties;var _n=Object.getOwnPropertyDescriptors;var tn=Object.getOwnPropertySymbols;var Nn=Object.prototype.hasOwnProperty,On=Object.prototype.propertyIsEnumerable;var dt=(t,o,e)=>o in t?In(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,l=(t,o)=>{for(var e in o||(o={}))Nn.call(o,e)&&dt(t,e,o[e]);if(tn)for(var e of tn(o))On.call(o,e)&&dt(t,e,o[e]);return t},j=(t,o)=>$n(t,_n(o));var re=(t,o,e)=>dt(t,typeof o!="symbol"?o+"":o,e);var et="uat-cti.aighospitals.com",B=`https://${et}:8095`,Mn=`wss://${et}:8095`,K={v1:"/api/v1"},y={LOGIN:`${B}${K.v1}/cti/login?provider=convox`,READY_AGENT:`${B}${K.v1}/cti/ready-agent?provider=convox`,UPDATE_AGENT_BREAK:`${B}${K.v1}/cti/update-agent-status?provider=convox`,CLICK_TO_CALL:`${B}${K.v1}/cti/calls?provider=convox`,HOLD_CALL:`${B}${K.v1}/cti/calls/hold?provider=convox`,MUTE_CALL:`${B}${K.v1}/cti/calls/mute?provider=convox`,UNMUTE_CALL:`${B}${K.v1}/cti/unmute-call?provider=convox`,END_CALL:`${B}${K.v1}/cti/calls/end?provider=convox`,LOGOUT:`${B}${K.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${B}${K.v1}/cti/calls/conference?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${B}${K.v1}/cti/calls/conference/hold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${B}${K.v1}/cti/calls/conference/mute?provider=convox`,CONFERENCE_CALL_END:`${B}${K.v1}/cti/calls/conference/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${B}${K.v1}/cti/calls/conference/hangup/all?provider=convox`,TRANSFER_CALL:`${B}${K.v1}/cti/calls/transfer?provider=convox`,AGENTS_LIST:`${B}${K.v1}/cti/users`,PROCESS_LIST:`${B}${K.v1}/cti/processes-list`,TRANSFER_TO_DETAILS:`${B}${K.v1}/cti/transfer-to-details?provider=convox`,CALL_HISTORY:`${B}${K.v1}/dashboard/call-history`,SENTIMENTAL_ANALYSIS:`${B}${K.v1}/users/get_sentiment_analysis`},on={WS:`${Mn}${K.v1}/cti/ws`},me="call-control-sdk-state";var pt=class{constructor(){re(this,"state");re(this,"listeners",[]);re(this,"STORAGE_KEY",me);re(this,"apiKey");re(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 e=JSON.parse(o);this.state=j(l({},this.state),{agentId:e.agentId||"",authorization:e.authorization||void 0,process:e.process||null,openConferenceDialog:(e==null?void 0:e.openConferenceDialog)||!1,openCallTransferDialog:(e==null?void 0:e.openCallTransferDialog)||!1,isInitialized:e.isInitialized||!1,sdkConfig:e.sdkConfig||{disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},isHolding:e.isHolding||!1,isMuted:e.isMuted||!1,status:e.status||"idle",callStartTime:e.callStartTime||null,controlPanelPosition:e.controlPanelPosition||{x:10,y:10},iframePosition:e.iframePosition||{x:10,y:80},callData:e.callData||{mobileNumber:"",callReferenceId:"",agent_id:"",status:"",type:"",event_time:"",phone_number:""},conferenceLine:e.conferenceLine&&Array.isArray(e.conferenceLine)&&e.conferenceLine.length>0?e.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,e){if(!o||typeof o!="string"||o.trim().length===0)throw new Error("API key not available");if(!e||typeof e!="string"||e.trim().length===0)throw new Error("Tenant ID not available");this.apiKey=o.trim(),this.tenantId=e.trim()}initialize(o,e,r,i,a){if(this.validateCredentials(o,e),!r||typeof r!="string"||r.trim().length===0)throw new Error("Agent ID not available");this.state.agentId=r,this.state.openConferenceDialog=!1,this.state.openCallTransferDialog=!1,this.state.authorization=a,this.state.sdkConfig=l({disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},i),this.state.isInitialized=!0,this.saveToStorage(),this.notifyListeners()}getState(){return l({},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 e=this.listeners.indexOf(o);e>-1&&this.listeners.splice(e,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=l(l({},this.state.callData),o),this.saveToStorage(),this.notifyListeners()}updateConferenceData(o){this.state.conferenceLine=[...o],this.saveToStorage(),this.notifyListeners()}setConferenceLine(o){var r;(!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 e=(r=this.state.conferenceLine)==null?void 0:r.map(i=>i.line===o.line?o:i);this.state.conferenceLine=e,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 pt;var ct=class{constructor(){re(this,"config",null);re(this,"ticketId",null);re(this,"baseUrl","");re(this,"eventQueue",[]);re(this,"flushTimer",null)}async init(o){this.config=l({autoTrack:!0,retryAttempts:3,queueSize:100,flushInterval:5e3},o),this.baseUrl=o.baseUrl||(typeof window!="undefined"?window.location.origin:""),this.setupNetworkDetection();let e=await this.createTicket();return this.startPeriodicFlush(),console.log("EventTracker SDK initialized successfully"),e}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 e=await o.json();return this.ticketId=e.ticketId,this.config.autoTrack&&this.setupAutoTracking(),e}catch(o){throw console.error("EventTracker initialization failed:",o),o}}async logEvent(o,e){if(!this.config||!this.ticketId){console.warn("EventTracker not initialized, skipping event:",o);return}let r={eventType:o,eventData:e,timestamp:Date.now()};this.eventQueue.push(r),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift()}async makeRequest(o,e){var a;let r=`${this.baseUrl}${o}`,i=((a=this.config)==null?void 0:a.retryAttempts)||3;for(let p=1;p<=i;p++)try{return await fetch(r,e)}catch(d){if(p===i)throw d;let U=Math.min(1e3*Math.pow(2,p-1),1e4);await new Promise(u=>setTimeout(u,U))}throw new Error("Max retries exceeded")}setupAutoTracking(){var r;if(typeof window=="undefined"||!((r=this.config)!=null&&r.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(i=>console.warn("Failed to track page visit:",i)),o.clicks!==!1&&document.addEventListener("click",i=>{var p;let a=i.target;(a.tagName==="BUTTON"||a.tagName==="A"||a.onclick||a.getAttribute("role")==="button"||a instanceof HTMLButtonElement&&a.type==="button")&&this.logEvent("click",{element:a.tagName,text:(p=a.textContent)==null?void 0:p.trim().substring(0,100),href:a.getAttribute("href"),id:a.id,className:a.className,role:a.getAttribute("role"),position:{x:i.clientX,y:i.clientY},timestamp:new Date().toISOString()}).catch(d=>console.warn("Failed to track click:",d))}),o.forms!==!1&&document.addEventListener("submit",i=>{let a=i.target,p=new FormData(a),d={};p.forEach((U,u)=>{d[u]=U.toString()}),this.logEvent("formSubmission",{formId:a.id,action:a.action,method:a.method,fields:Object.keys(d),fieldCount:Object.keys(d).length,timestamp:new Date().toISOString()}).catch(U=>console.warn("Failed to track form submission:",U))}),o.inputs!==!1){let i;document.addEventListener("input",a=>{let p=a.target;(p.tagName==="INPUT"||p.tagName==="TEXTAREA"||p.tagName==="SELECT")&&(clearTimeout(i),i=setTimeout(()=>{var d;this.logEvent("fieldChange",{element:p.tagName,type:p.getAttribute("type"),name:p.getAttribute("name"),id:p.id,valueLength:((d=p.value)==null?void 0:d.length)||0,timestamp:new Date().toISOString()}).catch(U=>console.warn("Failed to track field change:",U))},1e3))})}let e=Date.now();window.addEventListener("beforeunload",()=>{let i=Date.now()-e;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:i,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",i=>{this.logEvent("jsError",{message:i.message,filename:i.filename,lineno:i.lineno,colno:i.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",i=>{var a;this.logEvent("unhandledRejection",{reason:(a=i.reason)==null?void 0:a.toString(),timestamp:new Date().toISOString()})})),o.performance!==!1&&typeof window.performance!="undefined"&&window.performance.navigation&&window.addEventListener("load",()=>{setTimeout(()=>{let i=window.performance.navigation,a=window.performance.timing;this.logEvent("performanceMetrics",{navigationTime:a.navigationStart,loadTime:a.loadEventEnd-a.navigationStart,domReady:a.domContentLoadedEventEnd-a.navigationStart,renderTime:a.loadEventEnd-a.domContentLoadedEventEnd,navigationType:i.type,redirectCount:i.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)}},ut=new ct;typeof window!="undefined"&&(window.EventTracker=ut);import{useCallback as jn,useState as _e}from"react";import Bn from"axios";var nn,Hn=(nn=m.getSdkAuthToken())!=null?nn:"",wn=6e4;function Fn(){var t;return(t=m.getSdkAuthToken())!=null?t:""}function Qn(){var o,e,r,i;let t=Bn.create({baseURL:B,headers:{"Content-Type":"application/json",Accept:"application/json","x-tenant-id":(e=(o=m.getCredentials())==null?void 0:o.tenantId)!=null?e:"","x-api-key":(i=(r=m.getCredentials())==null?void 0:r.apiKey)!=null?i:"",Authorization:`${Hn}`},timeout:wn,withCredentials:!1});return t.interceptors.request.use(a=>{let p=Fn();return p&&a.headers&&(a.headers.Authorization=`${p}`),a.metadata={startTime:new Date().getTime()},a},a=>(console.error("Request interceptor error:",a),Promise.reject(a))),t.interceptors.response.use(a=>{var U;let p=new Date().getTime(),d=(U=a.config.metadata)==null?void 0:U.startTime;return d&&console.log(`Request to ${a.config.url} took ${p-d}ms`),a},async a=>{var d;let p=a.config;return((d=a.response)==null?void 0:d.status)===401&&!p._retry&&(m.setInitCheck(),console.warn("Unauthorized request, attempting retry...")),a.response||(console.error("Network error:",a.message),a.message="Network error: Please check your internet connection"),a.response&&a.response.status>=500&&(console.error("Server error:",a.response.status,a.response.data),a.message="Server error: Please try again later"),Promise.reject(a)}),t}var Xn=Qn(),ee=Xn;var Kn=()=>{let[t,o]=_e(!1),[e,r]=_e(!1),[i,a]=_e(!1),[p,d]=_e(null),[U,u]=_e(null);return{logout:jn(async()=>{var x;let c=JSON.parse((x=localStorage.getItem(me))!=null?x:"");o(!0);let R={action:"LOGOUTUSER",userId:c.agentId||""};return ee.post(y.LOGOUT,R).then(g=>(m.clearStorageAndReset(),localStorage.clear(),sessionStorage.clear(),u(g==null?void 0:g.data),r(!0),g==null?void 0:g.data)).catch(g=>{var h;return a(!0),d(g),(h=g==null?void 0:g.response)==null?void 0:h.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:p,data:U}};import{useCallback as Wn,useState as Ne}from"react";var Jn=()=>{let[t,o]=Ne(!1),[e,r]=Ne(!1),[i,a]=Ne(!1),[p,d]=Ne(null),[U,u]=Ne(null);return{handleEndCall:Wn(async c=>{var g,h,A,_,P,N,H,G,w,k,D,T,Y,ne,ae;let R=JSON.parse((g=localStorage.getItem(me))!=null?g:"");o(!0);let x={action:"ENDCALL",userId:R==null?void 0:R.agentId,processid:(_=(A=(h=R==null?void 0:R.process)==null?void 0:h.process_id)==null?void 0:A.toString())!=null?_:"",process_name:(N=(P=R==null?void 0:R.process)==null?void 0:P.process_name)!=null?N:"",callreferenceid:(G=(H=R==null?void 0:R.callData)==null?void 0:H.convox_id)!=null?G:"",mobile_number:(k=(w=R==null?void 0:R.callData)==null?void 0:w.phone_number)!=null?k:"",disposition:(D=c==null?void 0:c.disposition)!=null?D:"RES",set_followUp:(T=c==null?void 0:c.followUp)!=null?T:"N",callback_date:(Y=c==null?void 0:c.callbackDate)!=null?Y:"",callback_hrs:(ne=c==null?void 0:c.callbackHrs)!=null?ne:"",callback_mins:(ae=c==null?void 0:c.callbackMins)!=null?ae:"",endcall_type:"CLOSE"};return ee.post(y.END_CALL,x).then(b=>(m.endCall(),u(b==null?void 0:b.data),r(!0),b==null?void 0:b.data)).catch(b=>{var I;return a(!0),d(b),(I=b==null?void 0:b.response)==null?void 0:I.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:p,data:U}};import{useCallback as qn,useState as Oe}from"react";var Gn=()=>{let[t,o]=Oe(!1),[e,r]=Oe(!1),[i,a]=Oe(!1),[p,d]=Oe(null),[U,u]=Oe(null);return{handleStartCall:qn(async c=>{var x,g,h,A,_,P,N,H,G;let R=JSON.parse((x=localStorage.getItem(me))!=null?x:"");if(o(!0),((g=R==null?void 0:R.callData)==null?void 0:g.status)==="IDLE"){let w={action:"CALL",userId:R==null?void 0:R.agentId,phone_number:c==null?void 0:c.mobileNumber};return ee.post(y.CLICK_TO_CALL,w).then(k=>(u(k==null?void 0:k.data),r(!0),k==null?void 0:k.data)).catch(k=>{var D;return a(!0),d(k),(D=k==null?void 0:k.response)==null?void 0:D.data}).finally(()=>{o(!1)})}else if(((h=R==null?void 0:R.callData)==null?void 0:h.status)==="ONCALL"){let w=(_=(A=R==null?void 0:R.conferenceLine)==null?void 0:A.filter(D=>D.line!==1))==null?void 0:_.find(D=>D.status==="IDLE"&&!(D!=null&&D.isCallStart)),k={action:"EXTERNAL_CONFERENCE",operation:`CALL${w.line}`,line_used:String(w.line),thirdparty_no:c==null?void 0:c.mobileNumber,userid:(N=(P=R.callData)==null?void 0:P.agent_id)!=null?N:"",process:(G=(H=R.callData)==null?void 0:H.process_name)!=null?G:""};return ee.post(y.CONFERENCE_CALL,k).then(D=>(u(D==null?void 0:D.data),r(!0),m.setConferenceLine(j(l({},w),{isCallStart:!0,status:"ONCALL",phone:c==null?void 0:c.mobileNumber})),m.setOpenConferenceDialog(!0),D==null?void 0:D.data)).catch(D=>{var T;return a(!0),d(D),(T=D==null?void 0:D.response)==null?void 0:T.data}).finally(()=>{o(!1)})}else alert("Agent is not ready")},[]),isLoading:t,isSuccess:e,isError:i,error:p,data:U}};import{useState as Yn,useEffect as Vn}from"react";var zn=()=>{let{process_id:t,process_name:o,status:e,phone_number:r,agent_id:i,convox_id:a}=m.getState().callData,p={phone_number:r,status:e,callReferenceId:a,agent_id:i,process_id:t,process_name:o},[d,U]=Yn(p);return Vn(()=>m.subscribe(()=>{let{process_id:E,process_name:c,status:R,phone_number:x,agent_id:g,convox_id:h}=m.getState().callData;U({phone_number:x,status:R,callReferenceId:h,agent_id:g,process_id:E,process_name:c})}),[]),d};import{useState as Zn,useEffect as ea}from"react";var ta=()=>{let[t,o]=Zn(m.getSdkAuthToken());return ea(()=>m.subscribe(()=>{o(m.getSdkAuthToken())}),[]),t};import{memo as Za,useCallback as es}from"react";import{CallEnd as ka,Close as va,DragIndicator as Cn,Group as Ia,KeyboardArrowDown as $a,Layers as _a,Mic as Na,MicOff as Oa,Pause as Ma,Pending as Ba,Phone as Ha,PlayArrow as wa,SupportAgent as Fa,TransferWithinAStation as Qa,Upcoming as Xa,WifiCalling3 as ja}from"@mui/icons-material";import{Box as de,Button as Le,Chip as it,CircularProgress as we,Fade as xn,IconButton as rt,Menu as Rt,MenuItem as Ka,Paper as bn,TextField as Wa,Tooltip as De,Typography as hn,useTheme as Ja}from"@mui/material";import{useEffect as ye,useRef as Fe,useState as ge}from"react";import{useCallback as tt,useRef as gt,useState as an}from"react";function ft(t,o){let[e,r]=an(t),[i,a]=an(!1),p=gt(),d=gt({x:0,y:0}),U=gt({x:0,y:0}),u=tt(x=>{let g=p.current;if(!g)return;let h=g.getBoundingClientRect(),A=window.innerWidth,_=window.innerHeight,P={x:Math.max(0,Math.min(x.x,A-h.width)),y:Math.max(0,Math.min(x.y,_-h.height))};r(P),o==null||o(P)},[o]),E=tt((x,g)=>{a(!0),d.current={x,y:g},U.current=e;let h=(N,H)=>{let G=N-d.current.x,w=H-d.current.y;u({x:U.current.x+G,y:U.current.y+w})},A=N=>{N.preventDefault(),h(N.clientX,N.clientY)},_=N=>{N.preventDefault();let H=N.touches[0];H&&h(H.clientX,H.clientY)},P=()=>{a(!1),document.removeEventListener("mousemove",A),document.removeEventListener("mouseup",P),document.removeEventListener("touchmove",_),document.removeEventListener("touchend",P)};document.addEventListener("mousemove",A),document.addEventListener("mouseup",P),document.addEventListener("touchmove",_,{passive:!1}),document.addEventListener("touchend",P)},[e,u]),c=tt(x=>{x.preventDefault(),E(x.clientX,x.clientY)},[E]),R=tt(x=>{x.preventDefault();let g=x.touches[0];g&&E(g.clientX,g.clientY)},[E]);return{position:e,isDragging:i,dragRef:p,handleMouseDown:c,handleTouchStart:R}}import{useState as oa,useEffect as na}from"react";function Ee(){let[t,o]=oa(m.getState());return na(()=>m.subscribe(()=>{o(m.getState())}),[]),t}import{useCallback as da,useReducer as pa}from"react";import{createContext as aa,useContext as sa,useState as Ut}from"react";import{Snackbar as ia,Alert as ra}from"@mui/material";import{jsx as sn,jsxs as la}from"react/jsx-runtime";var rn=aa(void 0),he=()=>{let t=sa(rn);if(!t)throw new Error("useToast must be used inside ToastProvider");return t},ln=({children:t})=>{let[o,e]=Ut(!1),[r,i]=Ut(""),[a,p]=Ut("info"),d=(U,u="info")=>{i(U),p(u),e(!0)};return la(rn.Provider,{value:{showToast:d},children:[t,sn(ia,{open:o,color:a,autoHideDuration:3e3,onClose:()=>e(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:sn(ra,{variant:"filled",severity:a,onClose:()=>e(!1),sx:{width:"100%"},children:r})})]})};var ca={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},ua=(t,o)=>{if(o.type==="isLoading")return j(l({},t),{isLoading:o.payload});if(o.type==="isSuccess")return j(l({},t),{isSuccess:!0,data:o.payload});if(o.type==="isError")return j(l({},t),{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=(t={})=>{let{onSuccess:o=null,onError:e=null,disabledSuccessToast:r=!1}=t,{showToast:i}=he(),[a,p]=pa(ua,ca);return[da((U,u,E={})=>{p({type:"isLoading",payload:!0}),ee.post(U,u,E).then(c=>{var R;p({type:"isSuccess",payload:c.data}),o==null||o(c.data,u),r||i((R=c.data)==null?void 0:R.message,"success")}).catch(c=>{var x,g,h,A,_,P,N,H,G,w,k,D;let R={status:(g=(x=c.response)==null?void 0:x.status)!=null?g:500,message:((A=(h=c.response)==null?void 0:h.data)==null?void 0:A.detail)||((P=(_=c.response)==null?void 0:_.data)==null?void 0:P.message)||c.message||"An unknown error occurred",data:(H=(N=c.response)==null?void 0:N.data)!=null?H:null,statusText:(w=(G=c.response)==null?void 0:G.statusText)!=null?w:"",code:(k=c==null?void 0:c.code)!=null?k:"",name:(D=c==null?void 0:c.name)!=null?D:""};i(R.message,"error"),p({type:"isError",payload:R}),e==null||e(R,u)}).finally(()=>{p({type:"isLoading",payload:!1})})},[o,e,i]),a]};import{Call as nt,CallEnd as dn,CallSplit as Ua,Close as st,Mic as Ra,MicOff as ma,Pause as Ca,PhoneDisabled as xa,PlayArrow as ba,SupportAgent as at}from"@mui/icons-material";import{Box as $,Button as ie,Dialog as Be,IconButton as be,Paper as Te,TextField as Se,Typography as te,Autocomplete as pn,Tooltip as Me,useTheme as ha,TableContainer as Da,Table as Ea,TableHead as Sa,TableRow as cn,TableCell as ue,TableBody as Ta,CircularProgress as Ce}from"@mui/material";import{useEffect as La,useMemo as ya,useState as xe}from"react";import{useTheme as ga}from"@mui/material";var fa=({disabled:t,enabled:o,outlined:e})=>{let r=ga();return{disabled:l({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 ${r.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}},t),enabled:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${r.palette.primary.main}`,height:"40px","&:hover":{boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${r.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}},o),outlined:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",backgroundColor:r.palette.grey[200],boxShadow:`0px 2px 1px ${r.palette.primary.light}`,border:`0px solid ${r.palette.primary.main}`,height:"40px","&:hover":{boxShadow:`0px 2px 1px ${r.palette.primary.main}`,border:`0px solid ${r.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}},e)}},ot=fa;import{Fragment as He,jsx as n,jsxs as S}from"react/jsx-runtime";var Aa=({each:t,isMergeCall:o})=>{var D,T,Y,ne,ae;let e=Ee(),{showToast:r}=he(),{disabled:i,enabled:a,outlined:p}=ot({disabled:((D=e.sdkConfig)==null?void 0:D.disabled)||{},enabled:((T=e.sdkConfig)==null?void 0:T.enabled)||{},outlined:((Y=e.sdkConfig)==null?void 0:Y.outlined)||{}}),d=ha(),[U,u]=xe(!1),[E,c]=xe(!1),[R,x]=xe(!1),[g,h]=xe(!1),[A,_]=xe(!1),P=(b,I)=>{m.setConferenceLine(l(l({},b),I))},N=(b,I)=>{var X,W,J,V;let O=l(l({},b),I);u(!0);let Q={action:"EXTERNAL_CONFERENCE",operation:`CALL${O.line}`,line_used:String(O.line),thirdparty_no:O.phone,userid:(W=(X=e.callData)==null?void 0:X.agent_id)!=null?W:"",process:(V=(J=e.callData)==null?void 0:J.process_name)!=null?V:""};ee.post(y.CONFERENCE_CALL,Q).then(v=>{var L;r((L=v.data)==null?void 0:L.message,"success"),m.setConferenceLine(l(l({},b),I))}).catch(v=>{var F,q,z,Z;let L=((q=(F=v.response)==null?void 0:F.data)==null?void 0:q.detail)||((Z=(z=v.response)==null?void 0:z.data)==null?void 0:Z.message)||v.message||"An unknown error occurred";r(L,"error")}).finally(()=>{u(!1)})},H=(b,I)=>{var X,W,J,V;let O=l(l({},b),I);c(!0);let Q={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(O.line),thirdparty_no:O.phone,userid:(W=(X=e.callData)==null?void 0:X.agent_id)!=null?W:"",process:(V=(J=e.callData)==null?void 0:J.process_name)!=null?V:""};ee.post(y.CONFERENCE_CALL,Q).then(v=>{var L;r((L=v.data)==null?void 0:L.message,"success"),m.setConferenceLine(l(l({},b),I))}).catch(v=>{var F,q,z,Z;let L=((q=(F=v.response)==null?void 0:F.data)==null?void 0:q.detail)||((Z=(z=v.response)==null?void 0:z.data)==null?void 0:Z.message)||v.message||"An unknown error occurred";r(L,"error")}).finally(()=>{c(!1)})},G=(b,I,O)=>{var W,J,V,v;let Q=l(l({},b),I);x(!0);let X={action:"EXTERNAL_CONFERENCE",operation:O,hold_channel_no:O==="HOLDUSER"?`hold${Q.line}`:`unhold${Q.line}`,userid:(J=(W=e.callData)==null?void 0:W.agent_id)!=null?J:"",process:(v=(V=e.callData)==null?void 0:V.process_name)!=null?v:""};ee.post(y.CONFERENCE_CALL_HOLD_OR_UN_HOLD,X).then(L=>{var F;r((F=L.data)==null?void 0:F.message,"success"),m.setConferenceLine(l(l({},b),I))}).catch(L=>{var q,z,Z,pe;let F=((z=(q=L.response)==null?void 0:q.data)==null?void 0:z.detail)||((pe=(Z=L.response)==null?void 0:Z.data)==null?void 0:pe.message)||L.message||"An unknown error occurred";r(F,"error")}).finally(()=>{x(!1)})},w=(b,I,O)=>{var W,J,V,v;let Q=l(l({},b),I);h(!0);let X={action:"EXTERNAL_CONFERENCE",operation:O,channel_no:O==="MUTEUSER"?`mute${Q.line}`:`play${Q.line}`,userid:(J=(W=e.callData)==null?void 0:W.agent_id)!=null?J:"",thirdparty_no:Q.phone,process:(v=(V=e.callData)==null?void 0:V.process_name)!=null?v:""};ee.post(y.CONFERENCE_CALL_MUTE_OT_UN_MUTE,X).then(L=>{var F;r((F=L.data)==null?void 0:F.message,"success"),m.setConferenceLine(l(l({},b),I))}).catch(L=>{var q,z,Z,pe;let F=((z=(q=L.response)==null?void 0:q.data)==null?void 0:z.detail)||((pe=(Z=L.response)==null?void 0:Z.data)==null?void 0:pe.message)||L.message||"An unknown error occurred";r(F,"error")}).finally(()=>{h(!1)})},k=(b,I)=>{var X,W,J,V;let O=l(l({},b),I);_(!0);let Q={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(O.line),user_type:`THIRDPARTY${O.line-1}`,thirdparty_no:O.phone,userid:(W=(X=e.callData)==null?void 0:X.agent_id)!=null?W:"",process:(V=(J=e.callData)==null?void 0:J.process_name)!=null?V:""};ee.post(y.CONFERENCE_CALL_END,Q).then(v=>{var L;r((L=v.data)==null?void 0:L.message,"success"),m.setConferenceLine(l(l({},b),I))}).catch(v=>{var F,q,z,Z;let L=((q=(F=v.response)==null?void 0:F.data)==null?void 0:q.detail)||((Z=(z=v.response)==null?void 0:z.data)==null?void 0:Z.message)||v.message||"An unknown error occurred";r(L,"error")}).finally(()=>{_(!1)})};return S(cn,{sx:{border:"2px solid #fff"},children:[n(ue,{sx:{padding:"6px"},children:S(te,{children:["Line ",(ne=t==null?void 0:t.line)!=null?ne:"",". "]})}),n(ue,{sx:{padding:"6px"},children:n(te,{variant:"body2",sx:{px:1,borderRadius:"10px"},children:(ae=t==null?void 0:t.status)!=null?ae:""})}),n(ue,{sx:{padding:"6px"},children:n(ie,{sx:{textTransform:"capitalize"},size:"small",children:n(te,{variant:"body2",children:(t==null?void 0:t.line)===1?"Internal":"External"})})}),n(ue,{sx:{padding:"6px"},children:n(Se,{size:"small",placeholder:"Phone Number",fullWidth:!0,value:(t==null?void 0:t.phone)||"",disabled:(t==null?void 0:t.line)===1||(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="DISCONNECTED"||(t==null?void 0:t.status)==="CONFERENCE"||(t==null?void 0:t.status)==="HOLD"||(t==null?void 0:t.status)==="MUTE",onChange:b=>{P(t,{phone:b.target.value})}})}),n(ue,{sx:{padding:"6px"},children:S($,{sx:{display:"flex",alignItems:"center",justifyContent:"space-around"},children:[t.line!==1&&n(Me,{title:"Call",children:n(ie,{variant:(t==null?void 0:t.status)!=="IDLE"?"outlined":"contained",color:"success",sx:(t==null?void 0:t.status)!=="IDLE"?l({},i):j(l({},a),{border:`0px solid ${d.palette.success.light}`,"&:hover":{bgcolor:"success.light",boxShadow:`0px 2px 1px ${d.palette.success.light}`,border:`0px solid ${d.palette.success.light}`},"&:active":{bgcolor:"success.light",boxShadow:`inset 1px -2px 4px ${d.palette.primary.light}`}}),onClick:()=>{N(t,{})},disabled:(t==null?void 0:t.status)!=="IDLE",children:U?n(Ce,{size:"20px",color:"success"}):n(nt,{sx:{color:(t==null?void 0:t.status)!=="IDLE"?"default":"#f3f2f2"}})})}),t.line===1&&n(Me,{title:"Merge Call",children:S(ie,{variant:o?"contained":"outlined",sx:o?j(l({},a),{padding:"0px 16px"}):j(l({},i),{padding:"0px 16px"}),onClick:()=>{H(t,{isMergeCall:!0})},disabled:!o||E,children:[t!=null&&t.isMergeCall?"Merged":"Merge",E?n(Ce,{size:"20px"}):n(Ua,{})]})}),n(Me,{title:t.status!=="HOLD"?"Hold":"Un Hold",children:n(ie,{variant:t.status==="HOLD"?"contained":"outlined",sx:t.status==="DISCONNECTED"||(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},i):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},p):l({},i),onClick:()=>{t.status==="HOLD"?G(t,{isHold:!1},"UNHOLDUSER"):G(t,{isHold:!0},"HOLDUSER")},disabled:(t==null?void 0:t.status)==="DISCONNECTED"||(t==null?void 0:t.status)==="IDLE"||R,children:R?n(Ce,{size:"20px",sx:{color:d.palette.primary.main}}):t.status==="HOLD"?n(ba,{}):n(Ca,{})})}),n(Me,{title:t.status!=="MUTE"?"Mute":"Un Mute",children:n(ie,{variant:t.status==="MUTE"?"contained":"outlined",sx:t.status==="DISCONNECTED"||(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},i):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},p):l({},i),onClick:()=>{t.status==="MUTE"?w(t,{isMute:!1},"PLAYUSER"):w(t,{isMute:!0},"MUTEUSER")},disabled:(t==null?void 0:t.status)==="DISCONNECTED"||(t==null?void 0:t.status)==="IDLE"||(t==null?void 0:t.status)==="HOLD"||g,children:g?n(Ce,{size:"20px",sx:{color:d.palette.primary.main}}):t.status==="MUTE"?n(ma,{}):n(Ra,{})})}),(t==null?void 0:t.line)!==1?n(Me,{title:"End Call",children:n(ie,{variant:(t==null?void 0:t.status)!=="IDLE"&&(t==null?void 0:t.status)!=="DISCONNECTED"?"contained":"outlined",color:"error",sx:(t==null?void 0:t.status)!=="IDLE"&&(t==null?void 0:t.status)!=="DISCONNECTED"?j(l({},a),{border:`0px solid ${d.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${d.palette.error.light}`,border:`0px solid ${d.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${d.palette.primary.light}`}}):l({},i),onClick:()=>{k(t,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:(t==null?void 0:t.status)==="IDLE"||(t==null?void 0:t.status)==="DISCONNECTED"||A,children:A?n(Ce,{size:"20px",color:"error"}):n(dn,{})})}):n(ie,{variant:t!=null&&t.isCallStart?"contained":"outlined",color:"error",sx:{display:"none"},onClick:()=>{k(t,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:(t==null?void 0:t.status)==="IDLE"||(t==null?void 0:t.status)==="DISCONNECTED"||A,children:A?n(Ce,{size:"20px",color:"error"}):n(dn,{})})]})})]},t.line)};function un(){var d;let t=Ee(),{showToast:o}=he(),[e,r]=xe(!1),i=()=>{m.setOpenConferenceDialog(!1)},a=()=>{var u,E,c,R;r(!0);let U={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(E=(u=t.callData)==null?void 0:u.agent_id)!=null?E:"",process:(R=(c=t.callData)==null?void 0:c.process_name)!=null?R:""};ee.post(y.CONFERENCE_CALL_END_ALL,U).then(x=>{var g;o((g=x.data)==null?void 0:g.message,"success"),m.resetConferenceLines(),i()}).catch(x=>{var h,A,_,P;let g=((A=(h=x.response)==null?void 0:h.data)==null?void 0:A.detail)||((P=(_=x.response)==null?void 0:_.data)==null?void 0:P.message)||x.message||"An unknown error occurred";o(g,"error")}).finally(()=>{r(!1)})},p=ya(()=>{var U;return(U=t==null?void 0:t.conferenceLine)==null?void 0:U.some(u=>u.line!==1?u.status==="ONCALL":!1)},[t.conferenceLine]);return n(He,{children:n(Be,{open:t.openConferenceDialog,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:S(Te,{sx:{borderRadius:2},children:[S($,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px"},children:[S(te,{variant:"body1",children:[(d=t==null?void 0:t.agentId)!=null?d:""," conference"]}),n(be,{onClick:i,children:n(st,{})})]}),n($,{sx:{boxShadow:"1px 1px 2px #e7e5e5ff",margin:"0px 15px",borderRadius:"20px"},children:n(Da,{component:Te,sx:{outline:"0px solid gray !important",boxShadow:"1px 1px 6px #e7e5e5ff"},children:S(Ea,{sx:{border:"4px solid #ffffff !important"},children:[n(Sa,{children:S(cn,{sx:{border:"2px solid #f3f3f3ff !important"},children:[n(ue,{sx:{padding:"6px"},children:"Line"}),n(ue,{sx:{padding:"6px"},children:"Status"}),n(ue,{sx:{padding:"6px"},children:"Call Type"}),n(ue,{sx:{padding:"6px"},children:"Mobile Number"}),n(ue,{sx:{padding:"6px"},children:"Call Actions"})]})}),n(Ta,{children:t==null?void 0:t.conferenceLine.map(U=>n(Aa,{each:U,isMergeCall:p}))})]})})}),n($,{textAlign:"center",m:2,children:S(ie,{variant:"outlined",color:"error",size:"large",onClick:a,disabled:e,sx:{px:2,borderRadius:"20px",textTransform:"capitalize"},children:[e?n(Ce,{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(xa,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function gn({open:t}){var x,g,h,A,_,P,N,H,G,w,k,D;let o=Ee(),[e]=le({onSuccess:()=>{m.setOpenCallTransferDialog(!1)}}),[r,i]=xe("process"),[a,{data:p,isLoading:d}]=le({disabledSuccessToast:!0}),[U,{data:u,isLoading:E}]=le({disabledSuccessToast:!0}),c=()=>{m.setOpenCallTransferDialog(!1)},R=(T,Y)=>{var ne,ae,b,I,O,Q,X,W,J,V,v,L,F,q,z,Z,pe,Qe,Xe,je,Ke,Ae,We,Pe,Je,ke,qe,Ge,Ye,ve,Ve,ze,Ze;if(Y==="PROCESS"){let Re={mobile_number:(ae=(ne=o.callData)==null?void 0:ne.phone_number)!=null?ae:"",userid:(I=(b=o.callData)==null?void 0:b.agent_id)!=null?I:"",type:"PROCESS",transfer_to:(O=T==null?void 0:T.process_name)!=null?O:"",callreferenceid:(X=(Q=o.callData)==null?void 0:Q.convox_id)!=null?X:"",processid:String((J=(W=o.callData)==null?void 0:W.process_id)!=null?J:""),process_name:(v=(V=o.callData)==null?void 0:V.process_name)!=null?v:""};e(y.TRANSFER_CALL,Re)}else if(Y==="QUEUE"){let Re={mobile_number:(F=(L=o.callData)==null?void 0:L.phone_number)!=null?F:"",userid:(z=(q=o.callData)==null?void 0:q.agent_id)!=null?z:"",type:"QUEUE",transfer_to:(Z=T==null?void 0:T.queue_name)!=null?Z:"",callreferenceid:(Qe=(pe=o.callData)==null?void 0:pe.convox_id)!=null?Qe:"",processid:String((je=(Xe=o.callData)==null?void 0:Xe.process_id)!=null?je:""),process_name:(Ae=(Ke=o.callData)==null?void 0:Ke.process_name)!=null?Ae:""};e(y.TRANSFER_CALL,Re)}else if(Y==="AGENT"){let Re={mobile_number:(Pe=(We=o.callData)==null?void 0:We.phone_number)!=null?Pe:"",userid:(ke=(Je=o.callData)==null?void 0:Je.agent_id)!=null?ke:"",type:"AGENT",transfer_to:(qe=T==null?void 0:T.user_id)!=null?qe:"",callreferenceid:(Ye=(Ge=o.callData)==null?void 0:Ge.convox_id)!=null?Ye:"",processid:String((Ve=(ve=o.callData)==null?void 0:ve.process_id)!=null?Ve:""),process_name:(Ze=(ze=o.callData)==null?void 0:ze.process_name)!=null?Ze:""};e(y.TRANSFER_CALL,Re)}};return La(()=>{a(y.AGENTS_LIST,{status:"IDLE",active:!0}),U(y.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:S(Te,{sx:{borderRadius:2},children:[S($,{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:c,children:n(st,{})})]}),S($,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:[S($,{sx:{display:"flex",gap:1},children:[n(ie,{variant:r==="process"?"contained":"outlined",onClick:()=>{i("process"),U(y.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Process"}),n(ie,{variant:r==="queues"?"contained":"outlined",onClick:()=>{i("queues"),U(y.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Queues"}),n(ie,{variant:r==="agents"?"contained":"outlined",onClick:()=>{i("agents"),a(y.AGENTS_LIST,{status:"IDLE",active:!0})},children:"Agents"})]}),(E||d)&&S($,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"80px"},children:[n(Ce,{})," "]}),!E&&!d&&r==="process"&&n($,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(x=u==null?void 0:u.data)!=null&&x.process&&((h=(g=u==null?void 0:u.data)==null?void 0:g.process)==null?void 0:h.length)>0?(_=(A=u==null?void 0:u.data)==null?void 0:A.process)==null?void 0:_.map((T,Y)=>S($,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[S(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(at,{sx:{marginRight:"4px"}}),T.process_name]}),n(be,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{R(T,"PROCESS")},children:n(nt,{})})]},Y)):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"})}),!E&&!d&&r==="queues"&&n($,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(P=u==null?void 0:u.data)!=null&&P.queue&&((H=(N=u==null?void 0:u.data)==null?void 0:N.queue)==null?void 0:H.length)>0?(w=(G=u==null?void 0:u.data)==null?void 0:G.queue)==null?void 0:w.map((T,Y)=>{var ne,ae,b,I,O,Q;return S($,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[S(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(at,{sx:{marginRight:"4px"}}),T.queue_name,(b=(ae=(ne=u==null?void 0:u.data)==null?void 0:ne.process)==null?void 0:ae.find(X=>X.process_id===T.process_id))!=null&&b.process_name?n(te,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((Q=(O=(I=u==null?void 0:u.data)==null?void 0:I.process)==null?void 0:O.find(X=>X.process_id===T.process_id))==null?void 0:Q.process_name)+")"}):""]}),n(be,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{R(T,"QUEUE")},children:n(nt,{})})]},Y)}):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"})}),!E&&!d&&r==="agents"&&n($,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:p!=null&&p.data&&((k=p==null?void 0:p.data)==null?void 0:k.length)>0?(D=p==null?void 0:p.data)==null?void 0:D.map((T,Y)=>S($,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[S(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(at,{sx:{marginRight:"4px"}}),T.name]}),n(be,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{R(T,"AGENT")},children:n(nt,{})})]},Y)):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 fn({open:t,setOpen:o,onSubmitDisposition:e}){var E,c,R,x;let[r,i]=xe({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),a=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],p=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],d=(g,h)=>{i(A=>j(l({},A),{[g]:h}))},U=()=>{i({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},u=()=>{U(),o(!1)};return n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:S(Te,{sx:{borderRadius:2},children:[n($,{sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:S(te,{variant:"body1",m:1,children:[" ","Call Disposition"]})}),S($,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"10px",margin:"10px",borderRadius:"10px"},children:[S($,{display:"flex",gap:2,children:[n(pn,{value:r.disposition,options:a,getOptionLabel:g=>g.label,onChange:(g,h)=>d("disposition",h),size:"small",renderInput:g=>n(Se,j(l({},g),{label:"Disposition",fullWidth:!0})),sx:{flex:1}}),n(pn,{options:p,getOptionLabel:g=>g.label,value:r.followUp,onChange:(g,h)=>d("followUp",h),size:"small",renderInput:g=>n(Se,j(l({},g),{label:"Follow Up",fullWidth:!0})),sx:{flex:1}})]}),((c=(E=r==null?void 0:r.followUp)==null?void 0:E.label)==null?void 0:c.toLowerCase())==="yes"&&S($,{display:"flex",gap:2,mt:2,children:[n(Se,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:r.callbackDate,onChange:g=>d("callbackDate",g.target.value),fullWidth:!0,sx:{flex:1}}),n(Se,{size:"small",label:"Hours (0-23)",type:"text",value:r.callbackHrs,onChange:g=>d("callbackHrs",g.target.value),fullWidth:!0,sx:{flex:1}})]}),((x=(R=r==null?void 0:r.followUp)==null?void 0:R.label)==null?void 0:x.toLowerCase())==="yes"&&S($,{display:"flex",gap:2,mt:2,children:[n(Se,{size:"small",label:"Minutes (0-59)",type:"text",value:r.callbackMins,onChange:g=>d("callbackMins",g.target.value),fullWidth:!0,sx:{flex:1}}),n($,{sx:{flex:1}})]})]}),S($,{textAlign:"right",m:2,children:[n(ie,{variant:"outlined",color:"error",size:"large",onClick:u,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),n(ie,{variant:"contained",color:"primary",size:"large",onClick:()=>e(r),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function Un({open:t,setOpen:o,processList:e=null,handleSelectedProcessor:r}){return n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:S(Te,{sx:{borderRadius:2},children:[S($,{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($,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:e.length>0?e==null?void 0:e.map((a,p)=>n($,{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:()=>{r(a)},children:S(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(at,{sx:{marginRight:"4px"}}),a.process_name]})},p)):null})]})})})}function Rn({open:t,setOpen:o}){return n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:S(Te,{sx:{borderRadius:2},children:[S($,{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($,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Coming Soon..."})]})})})}var mn="./incoming-4WP3FJI4.mp3";import{Fragment as Ya,jsx as f,jsxs as Ue}from"react/jsx-runtime";var qa=(t,o,e)=>t.map(i=>{var a,p,d;if((i==null?void 0:i.line)===1){let U=`line_${i.line}_status`;return j(l({},i),{line:1,status:(a=o[U])!=null?a:e==null?void 0:e.status,phone:(p=e==null?void 0:e.phone_number)!=null?p:""})}else{let U=`line_${i.line}_status`,u=`line_${i.line}_phonenumber`;return j(l({},i),{status:(d=o[U])!=null?d:"IDLE",phone:o[u]!=="0"?o[u]:""})}}),Ga=t=>{let o=Math.floor(t/60),e=t%60;return`${o.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`};function Dn({onDataChange:t}){var Ct,xt,bt,ht,Dt,Et,St,Tt,Lt,yt,At,Pt,kt,vt,It,$t,_t,Nt,Ot,Mt,Bt,Ht,wt,Ft,Qt,Xt,jt,Kt,Wt,Jt,qt,Gt,Yt,Vt,zt,Zt,eo,to,oo,no,ao,so,io,ro,lo,po,co,uo,go,fo,Uo,Ro,mo,Co,xo,bo,ho,Do,Eo,So,To,Lo,yo,Ao,Po,ko,vo,Io,$o,_o,No,Oo,Mo,Bo,Ho,wo,Fo,Qo,Xo,jo,Ko;let o=Ja(),e=Ee(),{showToast:r}=he(),{disabled:i,enabled:a,outlined:p}=ot({disabled:((Ct=e.sdkConfig)==null?void 0:Ct.disabled)||{},enabled:((xt=e.sdkConfig)==null?void 0:xt.enabled)||{},outlined:((bt=e.sdkConfig)==null?void 0:bt.outlined)||{}}),d=Fe(null),U=Fe(null),u=Fe(null),E=Fe(null),c=Fe(0),R=60,x=1e3,g=3e4,[h,A]=ge(null),[_,P]=ge(!0),[N,H]=ge(null),[G,w]=ge(null),[k,D]=ge(!1),[T,Y]=ge(!1),[ne,ae]=ge(!1),[b,I]=ge(null),[O,Q]=ge(""),[X,W]=ge(0),{position:J,isDragging:V,dragRef:v,handleMouseDown:L,handleTouchStart:F}=ft(e.controlPanelPosition,s=>m.setControlPanelPosition(s)),{position:q,isDragging:z,dragRef:Z,handleMouseDown:pe,handleTouchStart:Qe}=ft(e.iframePosition,s=>m.setIframePosition(s)),[Xe,{isLoading:je}]=le({onSuccess:()=>{Q(""),w(null)}}),[Ke,{isLoading:Ae}]=le({onSuccess:()=>{m.setHolding(!e.isHolding)},onError:s=>{console.log("\u274C Hold operation error:",s)}}),[We,{isLoading:Pe}]=le({onSuccess:()=>{m.setMuted(!e.isMuted)},onError:s=>{console.log("\u274C Mute operation error:",s)}}),[Je,{isLoading:ke}]=le(),[qe,{isLoading:Ge}]=le(),[Ye,{isLoading:ve}]=le(),Ve=()=>{A(null)},ze=s=>{P(!0),w(s.currentTarget),m.setStatus("dial")},Ze=()=>{e.status!=="on call"&&m.setStatus("idle"),w(null)},Re=s=>{H(s.currentTarget)},Tn=()=>{H(null)},Ln=()=>{let s={action:"READYAGENT",userId:e.agentId};Je(y.READY_AGENT,s)},yn=s=>{H(null);let C={action:"AGENTBREAK",break_type:s,userId:e.agentId};qe(y.UPDATE_AGENT_BREAK,C)},An=s=>{if(s.length!==10)r("Invalid phone number","error");else if(!/^\d+$/.test(s))r("Invalid phone number","error");else{let C={action:"CALL",phone_number:s,userId:e.agentId};Xe(y.CLICK_TO_CALL,C)}},Pn=()=>{let s={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};Ke(y.HOLD_CALL,s)},kn=()=>{let s={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};We(y.MUTE_CALL,s)},vn=s=>{var M,oe,se,ce,fe,Ie,$e,Wo,Jo,qo,Go,Yo,Vo,zo,Zo,en;let C={action:"ENDCALL",userId:e.agentId,processid:(se=(oe=(M=e.process)==null?void 0:M.process_id)==null?void 0:oe.toString())!=null?se:"",process_name:(fe=(ce=e.process)==null?void 0:ce.process_name)!=null?fe:"",callreferenceid:($e=(Ie=e.callData)==null?void 0:Ie.convox_id)!=null?$e:"",mobile_number:(Jo=(Wo=e.callData)==null?void 0:Wo.phone_number)!=null?Jo:"",disposition:(Go=(qo=s==null?void 0:s.disposition)==null?void 0:qo.value)!=null?Go:"",set_followUp:(Vo=(Yo=s==null?void 0:s.followUp)==null?void 0:Yo.value)!=null?Vo:"",callback_date:(zo=s==null?void 0:s.callbackDate)!=null?zo:"",callback_hrs:(Zo=s==null?void 0:s.callbackHrs)!=null?Zo:"",callback_mins:(en=s==null?void 0:s.callbackMins)!=null?en:"",endcall_type:"CLOSE"};Q(""),Ye(y.END_CALL,C),m.endCall(),D(!1)};ye(()=>{let s=C=>{C.preventDefault()};return window.addEventListener("beforeunload",s),()=>{window.removeEventListener("beforeunload",s)}},[]),ye(()=>{let s;return e.callData.status&&e.callData.status==="ONCALL"?s=setInterval(()=>{let C=Math.floor((Date.now()-e.callStartTime)/1e3);W(C)},1e3):W(0),()=>{s&&clearInterval(s)}},[e.callData.status]),ye(()=>(U.current=new Audio(mn),U.current.loop=!0,U.current.volume=.7,()=>{U.current&&(U.current.pause(),U.current.currentTime=0,U.current=null)}),[]),ye(()=>{if(t&&e.callData){let{process_id:s,process_name:C,status:M,phone_number:oe,agent_id:se,convox_id:ce}=e.callData;t({phone_number:oe,status:M,callReferenceId:ce,agent_id:se,process_id:s,process_name:C})}},[e.callData,t]),ye(()=>{e.agentId?ee.post(y.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}).then(s=>{var C,M;s&&s.data&&((C=s==null?void 0:s.data)==null?void 0:C.length)>1?(I(s.data.data),Y(!0)):(m.setProcess((M=s==null?void 0:s.data)==null?void 0:M.data[0]),Y(!1))}).catch(s=>{r(s.response.data.message,"error")}):console.log("No agentId available, skipping API call")},[e.agentId]);let lt=()=>{if(!e.agentId){console.log("No agentId available, cannot connect WebSocket");return}u.current&&(clearTimeout(u.current),u.current=null);try{d.current=new WebSocket(`${on.WS}?agent_id=${e.agentId}`),d.current.onopen=()=>{console.log("\u{1F310} WebSocket connection established"),c.current=0,E.current&&clearInterval(E.current),E.current=setInterval(()=>{if(d.current&&d.current.readyState===WebSocket.OPEN)try{d.current.send(JSON.stringify({type:"ping"})),console.log("\u{1F4E1} WebSocket ping sent")}catch(s){console.error("Failed to send ping:",s)}},3e4)},d.current.onmessage=s=>{try{let C=JSON.parse(s.data);if(C.type==="pong"){console.log("\u{1F4E1} WebSocket pong received");return}let M=qa(e==null?void 0:e.conferenceLine,C==null?void 0:C.conferencestatus,C);m.updateCallData(C),m.updateConferenceData([...M]),(C.status==="RINGING"||C.status==="DIALING")&&U.current&&U.current.play().catch(oe=>{console.error("Failed to play ringtone:",oe)}),C.status==="ONCALL"&&(U.current&&(U.current.pause(),U.current.currentTime=0),m.startCall(),_||P(!0)),C.status==="WRAPUP"&&(U.current&&(U.current.pause(),U.current.currentTime=0),m.endCall())}catch(C){console.log("\u{1F4E8} Raw message:",s.data)}},d.current.onclose=s=>{if(console.log("\u{1F50C} WebSocket connection closed",s.code,s.reason),E.current&&(clearInterval(E.current),E.current=null),s.code!==1e3&&c.current<R){c.current+=1;let C=Math.min(x*Math.pow(2,c.current-1),g);console.log(`\u{1F504} Attempting to reconnect WebSocket (attempt ${c.current}/${R}) in ${C}ms`),u.current=setTimeout(()=>{lt()},C)}else c.current>=R&&(console.error("\u274C Maximum reconnection attempts reached. Please refresh the page."),r("WebSocket connection failed. Please refresh the page.","error"))},d.current.onerror=s=>{console.error("\u274C WebSocket error:",s)}}catch(s){if(console.error("\u274C Failed to create WebSocket:",s),c.current<R){c.current+=1;let C=Math.min(x*Math.pow(2,c.current-1),g);u.current=setTimeout(()=>{lt()},C)}}};return ye(()=>(e.agentId&<(),()=>{u.current&&(clearTimeout(u.current),u.current=null),E.current&&(clearInterval(E.current),E.current=null),d.current&&(d.current.close(1e3,"Component unmounting"),d.current=null),c.current=0}),[e.agentId]),!e.isInitialized||!e.process?f(de,{children:!!T&&f(Un,{processList:b,open:T,setOpen:Y,handleSelectedProcessor:s=>{m.setProcess(s)}})}):Ue(Ya,{children:[f(de,{children:f(xn,{in:!0,timeout:300,children:f(bn,{ref:(ht=e.sdkConfig)!=null&&ht.isDraggable?v:null,elevation:V?4:(Dt=e.sdkConfig)!=null&&Dt.isDraggable?1:0,sx:{position:(Et=e.sdkConfig)!=null&&Et.isDraggable?"fixed":"relative",left:(St=e.sdkConfig)!=null&&St.isDraggable?J.x:"auto",top:(Tt=e.sdkConfig)!=null&&Tt.isDraggable?J.y:"auto",display:"inline-block",width:"auto",flexShrink:0,whiteSpace:"nowrap",p:.5,borderRadius:3,bgcolor:"background.paper",zIndex:(Lt=e.sdkConfig)!=null&&Lt.isDraggable?Number.MAX_SAFE_INTEGER:0,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),userSelect:"none"},children:Ue(de,{sx:{display:"flex",alignItems:"center"},children:[Ue(de,{sx:{display:"flex",alignItems:"center",gap:1,margin:"0px 10px"},children:[((yt=e.sdkConfig)==null?void 0:yt.isDraggable)&&Ue(rt,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:L,onTouchStart:F,children:[f(Cn,{})," "]}),f(de,{children:!((At=e.sdkConfig)!=null&&At.disabledDialButton)&&f(De,{title:"Dial",children:f(rt,{size:"small",onClick:s=>{var C,M,oe,se,ce,fe,Ie,$e;((M=(C=e.callData)==null?void 0:C.status)==null?void 0:M.toUpperCase())!=="ONCALL"&&((se=(oe=e.callData)==null?void 0:oe.status)==null?void 0:se.toUpperCase())!=="BREAK"&&((fe=(ce=e.callData)==null?void 0:ce.status)==null?void 0:fe.toUpperCase())!=="RINGING"&&(($e=(Ie=e.callData)==null?void 0:Ie.status)==null?void 0:$e.toUpperCase())!=="WRAPUP"&&ze(s)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:f(ja,{sx:{color:((kt=(Pt=e.callData)==null?void 0:Pt.status)==null?void 0:kt.toUpperCase())==="ONCALL"||((It=(vt=e.callData)==null?void 0:vt.status)==null?void 0:It.toUpperCase())==="BREAK"||((_t=($t=e.callData)==null?void 0:$t.status)==null?void 0:_t.toUpperCase())==="RINGING"||((Ot=(Nt=e.callData)==null?void 0:Nt.status)==null?void 0:Ot.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),f(hn,{sx:{color:"success.main",width:"40px",marginRight:"10px",fontSize:"18px",fontWeight:"600"},children:Ga(X)}),f(it,{sx:{padding:"18px 0px"},label:Ge||ke?f(de,{sx:{fontWeight:"bold",width:"60px",display:"flex",alignItems:"center",justifyContent:"center"},children:f(we,{size:"20px"})}):f(hn,{variant:"body2",sx:{fontWeight:"bold",width:"60px",textAlign:"center"},children:(Ht=(Bt=(Mt=e.callData)==null?void 0:Mt.status)==null?void 0:Bt.toUpperCase())!=null?Ht:"N/A"}),onClick:Re,deleteIcon:f($a,{color:"primary"}),onDelete:Re})]}),Ue(de,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[f(De,{title:"Agent Ready",children:f(Le,{variant:((Ft=(wt=e.callData)==null?void 0:wt.status)==null?void 0:Ft.toUpperCase())==="BREAK"||((Xt=(Qt=e.callData)==null?void 0:Qt.status)==null?void 0:Xt.toUpperCase())==="MISSED"?"outlined":"contained",onClick:s=>{var C,M,oe,se;(((M=(C=e.callData)==null?void 0:C.status)==null?void 0:M.toUpperCase())==="BREAK"||((se=(oe=e.callData)==null?void 0:oe.status)==null?void 0:se.toUpperCase())==="MISSED")&&(s.stopPropagation(),Ln())},classes:{root:((Kt=(jt=e.callData)==null?void 0:jt.status)==null?void 0:Kt.toUpperCase())==="BREAK"||((Jt=(Wt=e.callData)==null?void 0:Wt.status)==null?void 0:Jt.toUpperCase())==="MISSED"?"outlined":"enabled"},sx:l({},((Gt=(qt=e.callData)==null?void 0:qt.status)==null?void 0:Gt.toUpperCase())==="BREAK"||((Vt=(Yt=e.callData)==null?void 0:Yt.status)==null?void 0:Vt.toUpperCase())==="MISSED"?p:a),disabled:ke,children:f(Fa,{})})}),f(De,{title:e.isHolding?"Resume":"Hold",children:f(Le,{variant:e.isHolding&&((Zt=(zt=e.callData)==null?void 0:zt.status)==null?void 0:Zt.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:s=>{s.stopPropagation(),Pn()},sx:e.isHolding&&((to=(eo=e.callData)==null?void 0:eo.status)==null?void 0:to.toUpperCase())==="ONCALL"?l({},a):((no=(oo=e.callData)==null?void 0:oo.status)==null?void 0:no.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((so=(ao=e.callData)==null?void 0:ao.status)==null?void 0:so.toUpperCase())!=="ONCALL"&&!e.isHolding||Ae,children:Ae?f(we,{size:"20px",sx:{color:o.palette.primary.main}}):e.isHolding?f(wa,{}):f(Ma,{})})}),f(De,{title:e.isMuted?"Unmute":"Mute",children:f(Le,{variant:e.isMuted&&((ro=(io=e.callData)==null?void 0:io.status)==null?void 0:ro.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:s=>{s.stopPropagation(),kn()},sx:e.isMuted&&((po=(lo=e.callData)==null?void 0:lo.status)==null?void 0:po.toUpperCase())==="ONCALL"?l({},a):((uo=(co=e.callData)==null?void 0:co.status)==null?void 0:uo.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((fo=(go=e.callData)==null?void 0:go.status)==null?void 0:fo.toUpperCase())!=="ONCALL"&&!e.isMuted||Pe,children:Pe?f(we,{size:"20px",sx:{color:o.palette.primary.main}}):e.isMuted?f(Oa,{}):f(Na,{})})}),!((Uo=e.sdkConfig)!=null&&Uo.disableCallTransferButton)&&f(De,{title:"Transfer Call",children:f(Le,{variant:e.openCallTransferDialog?"contained":"outlined",onClick:s=>{var C,M;((M=(C=e.callData)==null?void 0:C.status)==null?void 0:M.toUpperCase())==="ONCALL"&&(s.stopPropagation(),m.setOpenCallTransferDialog(!0))},sx:e.openCallTransferDialog?l({},a):((mo=(Ro=e.callData)==null?void 0:Ro.status)==null?void 0:mo.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((xo=(Co=e.callData)==null?void 0:Co.status)==null?void 0:xo.toUpperCase())!=="ONCALL",children:f(Qa,{})})}),!((bo=e.sdkConfig)!=null&&bo.disableConferenceButton)&&f(De,{title:"Conference Call",children:f(Le,{variant:e.openConferenceDialog?"contained":"outlined",onClick:s=>{var C,M;((M=(C=e.callData)==null?void 0:C.status)==null?void 0:M.toUpperCase())==="ONCALL"&&(s.stopPropagation(),m.setOpenConferenceDialog(!0))},sx:e.openConferenceDialog?l({},a):((Do=(ho=e.callData)==null?void 0:ho.status)==null?void 0:Do.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((So=(Eo=e.callData)==null?void 0:Eo.status)==null?void 0:So.toUpperCase())!=="ONCALL",children:f(Ia,{})})}),!((To=e.sdkConfig)!=null&&To.disableEndCallButton)&&f(De,{title:"End Call",children:f(Le,{variant:((yo=(Lo=e.callData)==null?void 0:Lo.status)==null?void 0:yo.toUpperCase())==="ONCALL"||((Po=(Ao=e.callData)==null?void 0:Ao.status)==null?void 0:Po.toUpperCase())==="RINGING"||((vo=(ko=e.callData)==null?void 0:ko.status)==null?void 0:vo.toUpperCase())==="WRAPUP"?"contained":"outlined",onClick:s=>{var C,M,oe,se,ce,fe;(((M=(C=e.callData)==null?void 0:C.status)==null?void 0:M.toUpperCase())==="ONCALL"||((se=(oe=e.callData)==null?void 0:oe.status)==null?void 0:se.toUpperCase())==="RINGING"||((fe=(ce=e.callData)==null?void 0:ce.status)==null?void 0:fe.toUpperCase())==="WRAPUP")&&(s.stopPropagation(),D(!0))},sx:(($o=(Io=e.callData)==null?void 0:Io.status)==null?void 0:$o.toUpperCase())==="ONCALL"||((No=(_o=e.callData)==null?void 0:_o.status)==null?void 0:No.toUpperCase())==="RINGING"||((Mo=(Oo=e.callData)==null?void 0:Oo.status)==null?void 0:Mo.toUpperCase())==="WRAPUP"?j(l({},a),{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}`}}):j(l({},i),{minWidth:"60px !important"}),disabled:((Ho=(Bo=e.callData)==null?void 0:Bo.status)==null?void 0:Ho.toUpperCase())!=="ONCALL"&&((Fo=(wo=e.callData)==null?void 0:wo.status)==null?void 0:Fo.toUpperCase())!=="RINGING"&&((Xo=(Qo=e.callData)==null?void 0:Qo.status)==null?void 0:Xo.toUpperCase())!=="WRAPUP"||ve,children:ve?f(we,{size:"20px",color:"error"}):f(ka,{})})})]})]})})})}),f(xn,{in:!0,timeout:300,children:Ue(bn,{ref:Z,elevation:z?4:1,sx:{position:"absolute",left:q.x,top:q.y,borderRadius:2,bgcolor:"background.paper",zIndex:Number.MAX_SAFE_INTEGER,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),visibility:_&&!((jo=e.sdkConfig)!=null&&jo.disableSoftPhone)?"visible":"hidden",userSelect:"none"},children:[Ue(de,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll",padding:"0px 10px"},onMouseDown:pe,onTouchStart:Qe,children:[f(Cn,{sx:{transform:"rotate(90deg)",color:"#7b7b7b"}})," ",f(rt,{onClick:()=>P(!1),children:f(va,{})})]}),f(de,{children:f("iframe",{src:`https://${et}/ConVoxCCS/iframe?agent_id=${e.agentId}&process_id=${(Ko=e.process)==null?void 0:Ko.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay",style:{border:"none"}})})]})}),f(Rt,{anchorEl:G,open:!!G,onClose:Ze,onClick:s=>s.stopPropagation(),sx:{zIndex:99999},children:Ue(de,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[f(Wa,{size:"small",value:O,placeholder:"Enter Mobile No.",onChange:s=>{Q(s.target.value)}}),f(rt,{color:"info",onClick:()=>{An(O)},children:je?f(we,{size:"20px",sx:{color:o.palette.success.main}}):f(Ha,{color:"success"})})]})}),f(Rt,{anchorEl:N,open:!!N,onClose:Tn,onClick:s=>s.stopPropagation(),sx:{zIndex:99999},children:f(Ka,{onClick:()=>yn("Lunch"),children:"- Break"})}),f(Rt,{anchorEl:h,open:!!h,onClose:Ve,onClick:s=>s.stopPropagation(),sx:{zIndex:99999},children:Ue(de,{sx:{display:"flex",justifyContent:"flex-start",flexDirection:"column",padding:"0px 10px","&hover":{backgroundColor:"white"}},children:[f(it,{icon:f(_a,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),f(it,{icon:f(Ba,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),f(it,{icon:f(Xa,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!e.openConferenceDialog&&f(un,{}),!!e.openCallTransferDialog&&f(gn,{open:e.openCallTransferDialog}),!!k&&f(fn,{open:k,setOpen:D,onSubmitDisposition:vn}),!!ne&&f(Rn,{open:ne,setOpen:ae})]})}import{memo as Va}from"react";import{jsx as za}from"react/jsx-runtime";var mt=Va(({children:t})=>za(ln,{children:t}));mt.displayName="SDKProvider";import{jsx as En}from"react/jsx-runtime";var Sn=Za(({onDataChange:t})=>{let o=es(e=>{try{t&&typeof t=="function"&&t(e)}catch(r){console.error("Error in CallControlPanel data change handler:",r)}},[t]);return En(mt,{children:En(Dn,{onDataChange:o})})});Sn.displayName="CallControlPanel";async function tr({apiKey:t,tenantId:o,agentId:e,sdkConfig:r}){if(!t||typeof t!="string"||t.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(!e||typeof e!="string"||e.trim().length===0)throw new Error("SDK initialization failed: Agent ID is required and must be a non-empty string");try{let i=await ut.init({apiKey:t.trim(),tenantId:o.trim(),agentId:e.trim(),baseUrl:B});if(i)console.log("SDK initialized successfully"),m.initialize(t.trim(),o.trim(),e.trim(),r,i);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(i){throw console.error("SDK initialization error:",i),m.setInitCheck(),i instanceof Error?i:new Error(`SDK initialization failed: ${String(i)}`)}}function or(){return"6.x.x"}function nr(){return m.getState().isInitialized}export{Sn as CallControlPanel,or as getSDKVersion,tr as initSDK,nr as isSDKInitialized,Gn as useClickToCall,Jn as useEndCall,ta as useGetAuthorizationToken,zn as useGetCallerData,Kn as useLogout};
|
|
1
|
+
var wn=Object.defineProperty,Nn=Object.defineProperties;var An=Object.getOwnPropertyDescriptors;var tn=Object.getOwnPropertySymbols;var On=Object.prototype.hasOwnProperty,Pn=Object.prototype.propertyIsEnumerable;var ct=(t,o,e)=>o in t?wn(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,l=(t,o)=>{for(var e in o||(o={}))On.call(o,e)&&ct(t,e,o[e]);if(tn)for(var e of tn(o))Pn.call(o,e)&&ct(t,e,o[e]);return t},F=(t,o)=>Nn(t,An(o));var re=(t,o,e)=>ct(t,typeof o!="symbol"?o+"":o,e);var et="uat-cti.aighospitals.com",B=`https://${et}:8095`,Un=`wss://${et}:8095`,W={v1:"/api/v1"},I={LOGIN:`${B}${W.v1}/cti/login?provider=convox`,READY_AGENT:`${B}${W.v1}/cti/ready-agent?provider=convox`,UPDATE_AGENT_BREAK:`${B}${W.v1}/cti/update-agent-status?provider=convox`,CLICK_TO_CALL:`${B}${W.v1}/cti/calls?provider=convox`,HOLD_CALL:`${B}${W.v1}/cti/calls/hold?provider=convox`,MUTE_CALL:`${B}${W.v1}/cti/calls/mute?provider=convox`,UNMUTE_CALL:`${B}${W.v1}/cti/unmute-call?provider=convox`,END_CALL:`${B}${W.v1}/cti/calls/end?provider=convox`,LOGOUT:`${B}${W.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${B}${W.v1}/cti/calls/conference?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${B}${W.v1}/cti/calls/conference/hold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${B}${W.v1}/cti/calls/conference/mute?provider=convox`,CONFERENCE_CALL_END:`${B}${W.v1}/cti/calls/conference/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${B}${W.v1}/cti/calls/conference/hangup/all?provider=convox`,TRANSFER_CALL:`${B}${W.v1}/cti/calls/transfer?provider=convox`,AGENTS_LIST:`${B}${W.v1}/cti/users`,PROCESS_LIST:`${B}${W.v1}/cti/processes-list`,TRANSFER_TO_DETAILS:`${B}${W.v1}/cti/transfer-to-details?provider=convox`,CALL_HISTORY:`${B}${W.v1}/dashboard/call-history`,SENTIMENTAL_ANALYSIS:`${B}${W.v1}/users/get_sentiment_analysis`},on={WS:`${Un}${W.v1}/cti/ws`},Ce="call-control-sdk-state";var pt=class{constructor(){re(this,"state");re(this,"listeners",[]);re(this,"STORAGE_KEY",Ce);re(this,"apiKey");re(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 e=JSON.parse(o);this.state=F(l({},this.state),{agentId:e.agentId||"",authorization:e.authorization||void 0,process:e.process||null,openConferenceDialog:(e==null?void 0:e.openConferenceDialog)||!1,openCallTransferDialog:(e==null?void 0:e.openCallTransferDialog)||!1,isInitialized:e.isInitialized||!1,sdkConfig:e.sdkConfig||{disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},isHolding:e.isHolding||!1,isMuted:e.isMuted||!1,status:e.status||"idle",callStartTime:e.callStartTime||null,controlPanelPosition:e.controlPanelPosition||{x:10,y:10},iframePosition:e.iframePosition||{x:10,y:80},callData:e.callData||{mobileNumber:"",callReferenceId:"",agent_id:"",status:"",type:"",event_time:"",phone_number:""},conferenceLine:e.conferenceLine&&Array.isArray(e.conferenceLine)&&e.conferenceLine.length>0?e.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,e){if(!o||typeof o!="string"||o.trim().length===0)throw new Error("API key not available");if(!e||typeof e!="string"||e.trim().length===0)throw new Error("Tenant ID not available");this.apiKey=o.trim(),this.tenantId=e.trim()}initialize(o,e,r,i,s){if(this.validateCredentials(o,e),!r||typeof r!="string"||r.trim().length===0)throw new Error("Agent ID not available");this.state.agentId=r,this.state.openConferenceDialog=!1,this.state.openCallTransferDialog=!1,this.state.authorization=s,this.state.sdkConfig=l({disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},i),this.state.isInitialized=!0,this.saveToStorage(),this.notifyListeners()}getState(){return l({},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 e=this.listeners.indexOf(o);e>-1&&this.listeners.splice(e,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=l(l({},this.state.callData),o),this.saveToStorage(),this.notifyListeners()}updateConferenceData(o){this.state.conferenceLine=[...o],this.saveToStorage(),this.notifyListeners()}setConferenceLine(o){var r;(!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 e=(r=this.state.conferenceLine)==null?void 0:r.map(i=>i.line===o.line?o:i);this.state.conferenceLine=e,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||[]}},C=new pt;var dt=class{constructor(){re(this,"config",null);re(this,"ticketId",null);re(this,"baseUrl","");re(this,"eventQueue",[]);re(this,"flushTimer",null)}async init(o){this.config=l({autoTrack:!0,retryAttempts:3,queueSize:100,flushInterval:5e3},o),this.baseUrl=o.baseUrl||(typeof window!="undefined"?window.location.origin:""),this.setupNetworkDetection();let e=await this.createTicket();return this.startPeriodicFlush(),console.log("EventTracker SDK initialized successfully"),e}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 C.setInitCheck(),new Error(`Failed to initialize: ${o.status} ${o.statusText}`);let e=await o.json();return this.ticketId=e.ticketId,this.config.autoTrack&&this.setupAutoTracking(),e}catch(o){throw console.error("EventTracker initialization failed:",o),o}}async logEvent(o,e){if(!this.config||!this.ticketId){console.warn("EventTracker not initialized, skipping event:",o);return}let r={eventType:o,eventData:e,timestamp:Date.now()};this.eventQueue.push(r),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift()}async makeRequest(o,e){var s;let r=`${this.baseUrl}${o}`,i=((s=this.config)==null?void 0:s.retryAttempts)||3;for(let p=1;p<=i;p++)try{return await fetch(r,e)}catch(c){if(p===i)throw c;let m=Math.min(1e3*Math.pow(2,p-1),1e4);await new Promise(u=>setTimeout(u,m))}throw new Error("Max retries exceeded")}setupAutoTracking(){var r;if(typeof window=="undefined"||!((r=this.config)!=null&&r.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(i=>console.warn("Failed to track page visit:",i)),o.clicks!==!1&&document.addEventListener("click",i=>{var p;let s=i.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:(p=s.textContent)==null?void 0:p.trim().substring(0,100),href:s.getAttribute("href"),id:s.id,className:s.className,role:s.getAttribute("role"),position:{x:i.clientX,y:i.clientY},timestamp:new Date().toISOString()}).catch(c=>console.warn("Failed to track click:",c))}),o.forms!==!1&&document.addEventListener("submit",i=>{let s=i.target,p=new FormData(s),c={};p.forEach((m,u)=>{c[u]=m.toString()}),this.logEvent("formSubmission",{formId:s.id,action:s.action,method:s.method,fields:Object.keys(c),fieldCount:Object.keys(c).length,timestamp:new Date().toISOString()}).catch(m=>console.warn("Failed to track form submission:",m))}),o.inputs!==!1){let i;document.addEventListener("input",s=>{let p=s.target;(p.tagName==="INPUT"||p.tagName==="TEXTAREA"||p.tagName==="SELECT")&&(clearTimeout(i),i=setTimeout(()=>{var c;this.logEvent("fieldChange",{element:p.tagName,type:p.getAttribute("type"),name:p.getAttribute("name"),id:p.id,valueLength:((c=p.value)==null?void 0:c.length)||0,timestamp:new Date().toISOString()}).catch(m=>console.warn("Failed to track field change:",m))},1e3))})}let e=Date.now();window.addEventListener("beforeunload",()=>{let i=Date.now()-e;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:i,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",i=>{this.logEvent("jsError",{message:i.message,filename:i.filename,lineno:i.lineno,colno:i.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",i=>{var s;this.logEvent("unhandledRejection",{reason:(s=i.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 i=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:i.type,redirectCount:i.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)}},ut=new dt;typeof window!="undefined"&&(window.EventTracker=ut);import{useCallback as Kn,useState as Oe}from"react";import Mn from"axios";var nn,Bn=(nn=C.getSdkAuthToken())!=null?nn:"",Hn=6e4;function $n(){var t;return(t=C.getSdkAuthToken())!=null?t:""}function zn(){var o,e,r,i;let t=Mn.create({baseURL:B,headers:{"Content-Type":"application/json",Accept:"application/json","x-tenant-id":(e=(o=C.getCredentials())==null?void 0:o.tenantId)!=null?e:"","x-api-key":(i=(r=C.getCredentials())==null?void 0:r.apiKey)!=null?i:"",Authorization:`${Bn}`},timeout:Hn,withCredentials:!1});return t.interceptors.request.use(s=>{let p=$n();return p&&s.headers&&(s.headers.Authorization=`${p}`),s.metadata={startTime:new Date().getTime()},s},s=>(console.error("Request interceptor error:",s),Promise.reject(s))),t.interceptors.response.use(s=>{var m;let p=new Date().getTime(),c=(m=s.config.metadata)==null?void 0:m.startTime;return c&&console.log(`Request to ${s.config.url} took ${p-c}ms`),s},async s=>{var c;let p=s.config;return((c=s.response)==null?void 0:c.status)===401&&!p._retry&&(C.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)}),t}var qn=zn(),ee=qn;var Fn=()=>{let[t,o]=Oe(!1),[e,r]=Oe(!1),[i,s]=Oe(!1),[p,c]=Oe(null),[m,u]=Oe(null);return{logout:Kn(async()=>{var y;let d=JSON.parse((y=localStorage.getItem(Ce))!=null?y:"");o(!0);let x={action:"LOGOUTUSER",userId:d.agentId||""};return ee.post(I.LOGOUT,x).then(g=>(C.clearStorageAndReset(),localStorage.clear(),sessionStorage.clear(),u(g==null?void 0:g.data),r(!0),g==null?void 0:g.data)).catch(g=>{var E;return s(!0),c(g),(E=g==null?void 0:g.response)==null?void 0:E.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:p,data:m}};import{useCallback as Wn,useState as Pe}from"react";var Gn=()=>{let[t,o]=Pe(!1),[e,r]=Pe(!1),[i,s]=Pe(!1),[p,c]=Pe(null),[m,u]=Pe(null);return{handleEndCall:Wn(async d=>{var g,E,_,O,R,P,H,X,$,k,T,D,J,ne,se;let x=JSON.parse((g=localStorage.getItem(Ce))!=null?g:"");o(!0);let y={action:"ENDCALL",userId:x==null?void 0:x.agentId,processid:(O=(_=(E=x==null?void 0:x.process)==null?void 0:E.process_id)==null?void 0:_.toString())!=null?O:"",process_name:(P=(R=x==null?void 0:x.process)==null?void 0:R.process_name)!=null?P:"",callreferenceid:(X=(H=x==null?void 0:x.callData)==null?void 0:H.convox_id)!=null?X:"",mobile_number:(k=($=x==null?void 0:x.callData)==null?void 0:$.phone_number)!=null?k:"",disposition:(T=d==null?void 0:d.disposition)!=null?T:"RES",set_followUp:(D=d==null?void 0:d.followUp)!=null?D:"N",callback_date:(J=d==null?void 0:d.callbackDate)!=null?J:"",callback_hrs:(ne=d==null?void 0:d.callbackHrs)!=null?ne:"",callback_mins:(se=d==null?void 0:d.callbackMins)!=null?se:"",endcall_type:"CLOSE"};return ee.post(I.END_CALL,y).then(h=>(C.endCall(),u(h==null?void 0:h.data),r(!0),h==null?void 0:h.data)).catch(h=>{var N;return s(!0),c(h),(N=h==null?void 0:h.response)==null?void 0:N.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:p,data:m}};import{useCallback as Yn,useState as Ue}from"react";var jn=()=>{let[t,o]=Ue(!1),[e,r]=Ue(!1),[i,s]=Ue(!1),[p,c]=Ue(null),[m,u]=Ue(null);return{handleStartCall:Yn(async d=>{var y,g,E,_,O,R,P,H,X;let x=JSON.parse((y=localStorage.getItem(Ce))!=null?y:"");if(o(!0),((g=x==null?void 0:x.callData)==null?void 0:g.status)==="IDLE"){let $={action:"CALL",userId:x==null?void 0:x.agentId,phone_number:d==null?void 0:d.mobileNumber};return ee.post(I.CLICK_TO_CALL,$).then(k=>(u(k==null?void 0:k.data),r(!0),k==null?void 0:k.data)).catch(k=>{var T;return s(!0),c(k),(T=k==null?void 0:k.response)==null?void 0:T.data}).finally(()=>{o(!1)})}else if(((E=x==null?void 0:x.callData)==null?void 0:E.status)==="ONCALL"){let $=(O=(_=x==null?void 0:x.conferenceLine)==null?void 0:_.filter(T=>T.line!==1))==null?void 0:O.find(T=>T.status==="IDLE"&&!(T!=null&&T.isCallStart)),k={action:"EXTERNAL_CONFERENCE",operation:`CALL${$.line}`,line_used:String($.line),thirdparty_no:d==null?void 0:d.mobileNumber,userid:(P=(R=x.callData)==null?void 0:R.agent_id)!=null?P:"",process:(X=(H=x.callData)==null?void 0:H.process_name)!=null?X:""};return ee.post(I.CONFERENCE_CALL,k).then(T=>(u(T==null?void 0:T.data),r(!0),C.setConferenceLine(F(l({},$),{isCallStart:!0,status:"ONCALL",phone:d==null?void 0:d.mobileNumber})),C.setOpenConferenceDialog(!0),T==null?void 0:T.data)).catch(T=>{var D;return s(!0),c(T),(D=T==null?void 0:T.response)==null?void 0:D.data}).finally(()=>{o(!1)})}else alert("Agent is not ready")},[]),isLoading:t,isSuccess:e,isError:i,error:p,data:m}};import{useState as Xn,useEffect as Jn}from"react";var Vn=()=>{let{process_id:t,process_name:o,status:e,phone_number:r,agent_id:i,convox_id:s}=C.getState().callData,p={phone_number:r,status:e,callReferenceId:s,agent_id:i,process_id:t,process_name:o},[c,m]=Xn(p);return Jn(()=>C.subscribe(()=>{let{process_id:S,process_name:d,status:x,phone_number:y,agent_id:g,convox_id:E}=C.getState().callData;m({phone_number:y,status:x,callReferenceId:E,agent_id:g,process_id:S,process_name:d})}),[]),c};import{useState as Zn,useEffect as Qn}from"react";var es=()=>{let[t,o]=Zn(C.getSdkAuthToken());return Qn(()=>C.subscribe(()=>{o(C.getSdkAuthToken())}),[]),t};import{memo as Vs,useCallback as Zs}from"react";import{CallEnd as _s,Close as Rs,DragIndicator as Cn,Group as ks,KeyboardArrowDown as ws,Layers as Ns,Mic as As,MicOff as Os,Pause as Ps,Pending as Us,Phone as Ms,PlayArrow as Bs,SupportAgent as Hs,TransferWithinAStation as $s,Upcoming as zs,WifiCalling3 as qs}from"@mui/icons-material";import{Box as ce,Button as Le,Chip as it,CircularProgress as $e,Fade as bn,IconButton as rt,Menu as xt,MenuItem as Ks,Paper as yn,TextField as Fs,Tooltip as Te,Typography as hn,useTheme as Ws}from"@mui/material";import{useEffect as Ie,useRef as ze,useState as ge}from"react";import{useCallback as tt,useRef as gt,useState as sn}from"react";function ft(t,o){let[e,r]=sn(t),[i,s]=sn(!1),p=gt(),c=gt({x:0,y:0}),m=gt({x:0,y:0}),u=tt(y=>{let g=p.current;if(!g)return;let E=g.getBoundingClientRect(),_=window.innerWidth,O=window.innerHeight,R={x:Math.max(0,Math.min(y.x,_-E.width)),y:Math.max(0,Math.min(y.y,O-E.height))};r(R),o==null||o(R)},[o]),S=tt((y,g)=>{s(!0),c.current={x:y,y:g},m.current=e;let E=(P,H)=>{let X=P-c.current.x,$=H-c.current.y;u({x:m.current.x+X,y:m.current.y+$})},_=P=>{P.preventDefault(),E(P.clientX,P.clientY)},O=P=>{P.preventDefault();let H=P.touches[0];H&&E(H.clientX,H.clientY)},R=()=>{s(!1),document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",R),document.removeEventListener("touchmove",O),document.removeEventListener("touchend",R)};document.addEventListener("mousemove",_),document.addEventListener("mouseup",R),document.addEventListener("touchmove",O,{passive:!1}),document.addEventListener("touchend",R)},[e,u]),d=tt(y=>{y.preventDefault(),S(y.clientX,y.clientY)},[S]),x=tt(y=>{y.preventDefault();let g=y.touches[0];g&&S(g.clientX,g.clientY)},[S]);return{position:e,isDragging:i,dragRef:p,handleMouseDown:d,handleTouchStart:x}}import{useState as ts,useEffect as os}from"react";function Se(){let[t,o]=ts(C.getState());return os(()=>C.subscribe(()=>{o(C.getState())}),[]),t}import{useCallback as ls,useReducer as cs}from"react";import{createContext as ns,useContext as ss,useState as mt}from"react";import{Snackbar as as,Alert as is}from"@mui/material";import{jsx as an,jsxs as rs}from"react/jsx-runtime";var rn=ns(void 0),Ee=()=>{let t=ss(rn);if(!t)throw new Error("useToast must be used inside ToastProvider");return t},ln=({children:t})=>{let[o,e]=mt(!1),[r,i]=mt(""),[s,p]=mt("info"),c=(m,u="info")=>{i(m),p(u),e(!0)};return rs(rn.Provider,{value:{showToast:c},children:[t,an(as,{open:o,color:s,autoHideDuration:3e3,onClose:()=>e(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:an(is,{variant:"filled",severity:s,onClose:()=>e(!1),sx:{width:"100%"},children:r})})]})};var ps={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},ds=(t,o)=>{if(o.type==="isLoading")return F(l({},t),{isLoading:o.payload});if(o.type==="isSuccess")return F(l({},t),{isSuccess:!0,data:o.payload});if(o.type==="isError")return F(l({},t),{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=(t={})=>{let{onSuccess:o=null,onError:e=null,disabledSuccessToast:r=!1}=t,{showToast:i}=Ee(),[s,p]=cs(ds,ps);return[ls((m,u,S={})=>{p({type:"isLoading",payload:!0}),ee.post(m,u,S).then(d=>{var x;p({type:"isSuccess",payload:d.data}),o==null||o(d.data,u),r||i((x=d.data)==null?void 0:x.message,"success")}).catch(d=>{var y,g,E,_,O,R,P,H,X,$,k,T;let x={status:(g=(y=d.response)==null?void 0:y.status)!=null?g:500,message:((_=(E=d.response)==null?void 0:E.data)==null?void 0:_.detail)||((R=(O=d.response)==null?void 0:O.data)==null?void 0:R.message)||d.message||"An unknown error occurred",data:(H=(P=d.response)==null?void 0:P.data)!=null?H:null,statusText:($=(X=d.response)==null?void 0:X.statusText)!=null?$:"",code:(k=d==null?void 0:d.code)!=null?k:"",name:(T=d==null?void 0:d.name)!=null?T:""};i(x.message,"error"),p({type:"isError",payload:x}),e==null||e(x,u)}).finally(()=>{p({type:"isLoading",payload:!1})})},[o,e,i]),s]};import{Call as nt,CallEnd as cn,CallSplit as fs,Close as at,Mic as ms,MicOff as xs,Pause as Cs,PhoneDisabled as bs,PlayArrow as ys,SupportAgent as st}from"@mui/icons-material";import{Box as A,Button as ie,Dialog as Be,IconButton as he,Paper as De,TextField as ve,Typography as te,Autocomplete as pn,Tooltip as Me,useTheme as hs,TableContainer as Es,Table as Ts,TableHead as Ss,TableRow as dn,TableCell as ue,TableBody as vs,CircularProgress as be}from"@mui/material";import{useEffect as Ds,useMemo as Ls,useState as ye}from"react";import{useTheme as us}from"@mui/material";var gs=({disabled:t,enabled:o,outlined:e})=>{let r=us();return{disabled:l({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 ${r.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}},t),enabled:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${r.palette.primary.main}`,height:"40px","&:hover":{boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${r.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}},o),outlined:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",backgroundColor:r.palette.grey[200],boxShadow:`0px 2px 1px ${r.palette.primary.light}`,border:`0px solid ${r.palette.primary.main}`,height:"40px","&:hover":{boxShadow:`0px 2px 1px ${r.palette.primary.main}`,border:`0px solid ${r.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${r.palette.primary.light}`}},e)}},ot=gs;import{Fragment as He,jsx as n,jsxs as v}from"react/jsx-runtime";var Is=({each:t,isMergeCall:o})=>{var T,D,J,ne,se;let e=Se(),{showToast:r}=Ee(),{disabled:i,enabled:s,outlined:p}=ot({disabled:((T=e.sdkConfig)==null?void 0:T.disabled)||{},enabled:((D=e.sdkConfig)==null?void 0:D.enabled)||{},outlined:((J=e.sdkConfig)==null?void 0:J.outlined)||{}}),c=hs(),[m,u]=ye(!1),[S,d]=ye(!1),[x,y]=ye(!1),[g,E]=ye(!1),[_,O]=ye(!1),R=(h,N)=>{C.setConferenceLine(l(l({},h),N))},P=(h,N)=>{var K,G,Y,V;let U=l(l({},h),N);u(!0);let q={action:"EXTERNAL_CONFERENCE",operation:`CALL${U.line}`,line_used:String(U.line),thirdparty_no:U.phone,userid:(G=(K=e.callData)==null?void 0:K.agent_id)!=null?G:"",process:(V=(Y=e.callData)==null?void 0:Y.process_name)!=null?V:""};ee.post(I.CONFERENCE_CALL,q).then(w=>{var L;r((L=w.data)==null?void 0:L.message,"success"),C.setConferenceLine(l(l({},h),N))}).catch(w=>{var z,j,Z,Q;let L=((j=(z=w.response)==null?void 0:z.data)==null?void 0:j.detail)||((Q=(Z=w.response)==null?void 0:Z.data)==null?void 0:Q.message)||w.message||"An unknown error occurred";r(L,"error")}).finally(()=>{u(!1)})},H=(h,N)=>{var K,G,Y,V;let U=l(l({},h),N);d(!0);let q={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(U.line),thirdparty_no:U.phone,userid:(G=(K=e.callData)==null?void 0:K.agent_id)!=null?G:"",process:(V=(Y=e.callData)==null?void 0:Y.process_name)!=null?V:""};ee.post(I.CONFERENCE_CALL,q).then(w=>{var L;r((L=w.data)==null?void 0:L.message,"success"),C.setConferenceLine(l(l({},h),N))}).catch(w=>{var z,j,Z,Q;let L=((j=(z=w.response)==null?void 0:z.data)==null?void 0:j.detail)||((Q=(Z=w.response)==null?void 0:Z.data)==null?void 0:Q.message)||w.message||"An unknown error occurred";r(L,"error")}).finally(()=>{d(!1)})},X=(h,N,U)=>{var G,Y,V,w;let q=l(l({},h),N);y(!0);let K={action:"EXTERNAL_CONFERENCE",operation:U,hold_channel_no:U==="HOLDUSER"?`hold${q.line}`:`unhold${q.line}`,userid:(Y=(G=e.callData)==null?void 0:G.agent_id)!=null?Y:"",process:(w=(V=e.callData)==null?void 0:V.process_name)!=null?w:""};ee.post(I.CONFERENCE_CALL_HOLD_OR_UN_HOLD,K).then(L=>{var z;r((z=L.data)==null?void 0:z.message,"success"),C.setConferenceLine(l(l({},h),N))}).catch(L=>{var j,Z,Q,pe;let z=((Z=(j=L.response)==null?void 0:j.data)==null?void 0:Z.detail)||((pe=(Q=L.response)==null?void 0:Q.data)==null?void 0:pe.message)||L.message||"An unknown error occurred";r(z,"error")}).finally(()=>{y(!1)})},$=(h,N,U)=>{var G,Y,V,w;let q=l(l({},h),N);E(!0);let K={action:"EXTERNAL_CONFERENCE",operation:U,channel_no:U==="MUTEUSER"?`mute${q.line}`:`play${q.line}`,userid:(Y=(G=e.callData)==null?void 0:G.agent_id)!=null?Y:"",thirdparty_no:q.phone,process:(w=(V=e.callData)==null?void 0:V.process_name)!=null?w:""};ee.post(I.CONFERENCE_CALL_MUTE_OT_UN_MUTE,K).then(L=>{var z;r((z=L.data)==null?void 0:z.message,"success"),C.setConferenceLine(l(l({},h),N))}).catch(L=>{var j,Z,Q,pe;let z=((Z=(j=L.response)==null?void 0:j.data)==null?void 0:Z.detail)||((pe=(Q=L.response)==null?void 0:Q.data)==null?void 0:pe.message)||L.message||"An unknown error occurred";r(z,"error")}).finally(()=>{E(!1)})},k=(h,N)=>{var K,G,Y,V;let U=l(l({},h),N);O(!0);let q={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(U.line),user_type:`THIRDPARTY${U.line-1}`,thirdparty_no:U.phone,userid:(G=(K=e.callData)==null?void 0:K.agent_id)!=null?G:"",process:(V=(Y=e.callData)==null?void 0:Y.process_name)!=null?V:""};ee.post(I.CONFERENCE_CALL_END,q).then(w=>{var L;r((L=w.data)==null?void 0:L.message,"success"),C.setConferenceLine(l(l({},h),N))}).catch(w=>{var z,j,Z,Q;let L=((j=(z=w.response)==null?void 0:z.data)==null?void 0:j.detail)||((Q=(Z=w.response)==null?void 0:Z.data)==null?void 0:Q.message)||w.message||"An unknown error occurred";r(L,"error")}).finally(()=>{O(!1)})};return v(dn,{sx:{border:"2px solid #fff"},children:[n(ue,{sx:{padding:"6px"},children:v(te,{children:["Line ",(ne=t==null?void 0:t.line)!=null?ne:"",". "]})}),n(ue,{sx:{padding:"6px"},children:n(te,{variant:"body2",sx:{px:1,borderRadius:"10px"},children:(se=t==null?void 0:t.status)!=null?se:""})}),n(ue,{sx:{padding:"6px"},children:n(ie,{sx:{textTransform:"capitalize"},size:"small",children:n(te,{variant:"body2",children:(t==null?void 0:t.line)===1?"Internal":"External"})})}),n(ue,{sx:{padding:"6px"},children:n(ve,{size:"small",placeholder:"Phone Number",fullWidth:!0,value:(t==null?void 0:t.phone)||"",disabled:(t==null?void 0:t.line)===1||(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="DISCONNECTED"||(t==null?void 0:t.status)==="CONFERENCE"||(t==null?void 0:t.status)==="HOLD"||(t==null?void 0:t.status)==="MUTE",onChange:h=>{R(t,{phone:h.target.value})}})}),n(ue,{sx:{padding:"6px"},children:v(A,{sx:{display:"flex",alignItems:"center",justifyContent:"space-around"},children:[t.line!==1&&n(Me,{title:"Call",children:n(ie,{variant:(t==null?void 0:t.status)!=="IDLE"?"outlined":"contained",color:"success",sx:(t==null?void 0:t.status)!=="IDLE"?l({},i):F(l({},s),{border:`0px solid ${c.palette.success.light}`,"&:hover":{bgcolor:"success.light",boxShadow:`0px 2px 1px ${c.palette.success.light}`,border:`0px solid ${c.palette.success.light}`},"&:active":{bgcolor:"success.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}),onClick:()=>{P(t,{})},disabled:(t==null?void 0:t.status)!=="IDLE",children:m?n(be,{size:"20px",color:"success"}):n(nt,{sx:{color:(t==null?void 0:t.status)!=="IDLE"?"default":"#f3f2f2"}})})}),t.line===1&&n(Me,{title:"Merge Call",children:v(ie,{variant:o?"contained":"outlined",sx:o?F(l({},s),{padding:"0px 16px"}):F(l({},i),{padding:"0px 16px"}),onClick:()=>{H(t,{isMergeCall:!0})},disabled:!o||S,children:[t!=null&&t.isMergeCall?"Merged":"Merge",S?n(be,{size:"20px"}):n(fs,{})]})}),n(Me,{title:t.status!=="HOLD"?"Hold":"Un Hold",children:n(ie,{variant:t.status==="HOLD"?"contained":"outlined",sx:t.status==="DISCONNECTED"||(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},i):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},p):l({},i),onClick:()=>{t.status==="HOLD"?X(t,{isHold:!1},"UNHOLDUSER"):X(t,{isHold:!0},"HOLDUSER")},disabled:(t==null?void 0:t.status)==="DISCONNECTED"||(t==null?void 0:t.status)==="IDLE"||x,children:x?n(be,{size:"20px",sx:{color:c.palette.primary.main}}):t.status==="HOLD"?n(ys,{}):n(Cs,{})})}),n(Me,{title:t.status!=="MUTE"?"Mute":"Un Mute",children:n(ie,{variant:t.status==="MUTE"?"contained":"outlined",sx:t.status==="DISCONNECTED"||(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},i):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},p):l({},i),onClick:()=>{t.status==="MUTE"?$(t,{isMute:!1},"PLAYUSER"):$(t,{isMute:!0},"MUTEUSER")},disabled:(t==null?void 0:t.status)==="DISCONNECTED"||(t==null?void 0:t.status)==="IDLE"||(t==null?void 0:t.status)==="HOLD"||g,children:g?n(be,{size:"20px",sx:{color:c.palette.primary.main}}):t.status==="MUTE"?n(xs,{}):n(ms,{})})}),(t==null?void 0:t.line)!==1?n(Me,{title:"End Call",children:n(ie,{variant:(t==null?void 0:t.status)!=="IDLE"&&(t==null?void 0:t.status)!=="DISCONNECTED"?"contained":"outlined",color:"error",sx:(t==null?void 0:t.status)!=="IDLE"&&(t==null?void 0:t.status)!=="DISCONNECTED"?F(l({},s),{border:`0px solid ${c.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${c.palette.error.light}`,border:`0px solid ${c.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}):l({},i),onClick:()=>{k(t,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:(t==null?void 0:t.status)==="IDLE"||(t==null?void 0:t.status)==="DISCONNECTED"||_,children:_?n(be,{size:"20px",color:"error"}):n(cn,{})})}):n(ie,{variant:t!=null&&t.isCallStart?"contained":"outlined",color:"error",sx:{display:"none"},onClick:()=>{k(t,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:(t==null?void 0:t.status)==="IDLE"||(t==null?void 0:t.status)==="DISCONNECTED"||_,children:_?n(be,{size:"20px",color:"error"}):n(cn,{})})]})})]},t.line)};function un(){var c;let t=Se(),{showToast:o}=Ee(),[e,r]=ye(!1),i=()=>{C.setOpenConferenceDialog(!1)},s=()=>{var u,S,d,x;r(!0);let m={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(S=(u=t.callData)==null?void 0:u.agent_id)!=null?S:"",process:(x=(d=t.callData)==null?void 0:d.process_name)!=null?x:""};ee.post(I.CONFERENCE_CALL_END_ALL,m).then(y=>{var g;o((g=y.data)==null?void 0:g.message,"success"),C.resetConferenceLines(),i()}).catch(y=>{var E,_,O,R;let g=((_=(E=y.response)==null?void 0:E.data)==null?void 0:_.detail)||((R=(O=y.response)==null?void 0:O.data)==null?void 0:R.message)||y.message||"An unknown error occurred";o(g,"error")}).finally(()=>{r(!1)})},p=Ls(()=>{var m;return(m=t==null?void 0:t.conferenceLine)==null?void 0:m.some(u=>u.line!==1?u.status==="ONCALL":!1)},[t.conferenceLine]);return n(He,{children:n(Be,{open:t.openConferenceDialog,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:v(De,{sx:{borderRadius:2},children:[v(A,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px"},children:[v(te,{variant:"body1",children:[(c=t==null?void 0:t.agentId)!=null?c:""," conference"]}),n(he,{onClick:i,children:n(at,{})})]}),n(A,{sx:{boxShadow:"1px 1px 2px #e7e5e5ff",margin:"0px 15px",borderRadius:"20px"},children:n(Es,{component:De,sx:{outline:"0px solid gray !important",boxShadow:"1px 1px 6px #e7e5e5ff"},children:v(Ts,{sx:{border:"4px solid #ffffff !important"},children:[n(Ss,{children:v(dn,{sx:{border:"2px solid #f3f3f3ff !important"},children:[n(ue,{sx:{padding:"6px"},children:"Line"}),n(ue,{sx:{padding:"6px"},children:"Status"}),n(ue,{sx:{padding:"6px"},children:"Call Type"}),n(ue,{sx:{padding:"6px"},children:"Mobile Number"}),n(ue,{sx:{padding:"6px"},children:"Call Actions"})]})}),n(vs,{children:t==null?void 0:t.conferenceLine.map(m=>n(Is,{each:m,isMergeCall:p}))})]})})}),n(A,{textAlign:"center",m:2,children:v(ie,{variant:"outlined",color:"error",size:"large",onClick:s,disabled:e,sx:{px:2,borderRadius:"20px",textTransform:"capitalize"},children:[e?n(be,{size:"20px",color:"error",sx:{marginRight:"8px"}}):n(he,{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(bs,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function gn({open:t}){var y,g,E,_,O,R,P,H,X,$,k,T;let o=Se(),[e]=le({onSuccess:()=>{C.setOpenCallTransferDialog(!1)}}),[r,i]=ye("process"),[s,{data:p,isLoading:c}]=le({disabledSuccessToast:!0}),[m,{data:u,isLoading:S}]=le({disabledSuccessToast:!0}),d=()=>{C.setOpenCallTransferDialog(!1)},x=(D,J)=>{var ne,se,h,N,U,q,K,G,Y,V,w,L,z,j,Z,Q,pe,qe,Ke,Fe,We,_e,Ge,Re,Ye,ke,je,Xe,Je,we,Ve,Ze,Qe;if(J==="PROCESS"){let xe={mobile_number:(se=(ne=o.callData)==null?void 0:ne.phone_number)!=null?se:"",userid:(N=(h=o.callData)==null?void 0:h.agent_id)!=null?N:"",type:"PROCESS",transfer_to:(U=D==null?void 0:D.process_name)!=null?U:"",callreferenceid:(K=(q=o.callData)==null?void 0:q.convox_id)!=null?K:"",processid:String((Y=(G=o.callData)==null?void 0:G.process_id)!=null?Y:""),process_name:(w=(V=o.callData)==null?void 0:V.process_name)!=null?w:""};e(I.TRANSFER_CALL,xe)}else if(J==="QUEUE"){let xe={mobile_number:(z=(L=o.callData)==null?void 0:L.phone_number)!=null?z:"",userid:(Z=(j=o.callData)==null?void 0:j.agent_id)!=null?Z:"",type:"QUEUE",transfer_to:(Q=D==null?void 0:D.queue_name)!=null?Q:"",callreferenceid:(qe=(pe=o.callData)==null?void 0:pe.convox_id)!=null?qe:"",processid:String((Fe=(Ke=o.callData)==null?void 0:Ke.process_id)!=null?Fe:""),process_name:(_e=(We=o.callData)==null?void 0:We.process_name)!=null?_e:""};e(I.TRANSFER_CALL,xe)}else if(J==="AGENT"){let xe={mobile_number:(Re=(Ge=o.callData)==null?void 0:Ge.phone_number)!=null?Re:"",userid:(ke=(Ye=o.callData)==null?void 0:Ye.agent_id)!=null?ke:"",type:"AGENT",transfer_to:(je=D==null?void 0:D.user_id)!=null?je:"",callreferenceid:(Je=(Xe=o.callData)==null?void 0:Xe.convox_id)!=null?Je:"",processid:String((Ve=(we=o.callData)==null?void 0:we.process_id)!=null?Ve:""),process_name:(Qe=(Ze=o.callData)==null?void 0:Ze.process_name)!=null?Qe:""};e(I.TRANSFER_CALL,xe)}};return Ds(()=>{s(I.AGENTS_LIST,{status:"IDLE",active:!0}),m(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:v(De,{sx:{borderRadius:2},children:[v(A,{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(he,{onClick:d,children:n(at,{})})]}),v(A,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:[v(A,{sx:{display:"flex",gap:1},children:[n(ie,{variant:r==="process"?"contained":"outlined",onClick:()=>{i("process"),m(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Process"}),n(ie,{variant:r==="queues"?"contained":"outlined",onClick:()=>{i("queues"),m(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Queues"}),n(ie,{variant:r==="agents"?"contained":"outlined",onClick:()=>{i("agents"),s(I.AGENTS_LIST,{status:"IDLE",active:!0})},children:"Agents"})]}),(S||c)&&v(A,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"80px"},children:[n(be,{})," "]}),!S&&!c&&r==="process"&&n(A,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(y=u==null?void 0:u.data)!=null&&y.process&&((E=(g=u==null?void 0:u.data)==null?void 0:g.process)==null?void 0:E.length)>0?(O=(_=u==null?void 0:u.data)==null?void 0:_.process)==null?void 0:O.map((D,J)=>v(A,{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(st,{sx:{marginRight:"4px"}}),D.process_name]}),n(he,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{x(D,"PROCESS")},children:n(nt,{})})]},J)):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"})}),!S&&!c&&r==="queues"&&n(A,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(R=u==null?void 0:u.data)!=null&&R.queue&&((H=(P=u==null?void 0:u.data)==null?void 0:P.queue)==null?void 0:H.length)>0?($=(X=u==null?void 0:u.data)==null?void 0:X.queue)==null?void 0:$.map((D,J)=>{var ne,se,h,N,U,q;return v(A,{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(st,{sx:{marginRight:"4px"}}),D.queue_name,(h=(se=(ne=u==null?void 0:u.data)==null?void 0:ne.process)==null?void 0:se.find(K=>K.process_id===D.process_id))!=null&&h.process_name?n(te,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((q=(U=(N=u==null?void 0:u.data)==null?void 0:N.process)==null?void 0:U.find(K=>K.process_id===D.process_id))==null?void 0:q.process_name)+")"}):""]}),n(he,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{x(D,"QUEUE")},children:n(nt,{})})]},J)}):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"})}),!S&&!c&&r==="agents"&&n(A,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:p!=null&&p.data&&((k=p==null?void 0:p.data)==null?void 0:k.length)>0?(T=p==null?void 0:p.data)==null?void 0:T.map((D,J)=>v(A,{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(st,{sx:{marginRight:"4px"}}),D.name]}),n(he,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{x(D,"AGENT")},children:n(nt,{})})]},J)):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 fn({open:t,setOpen:o,onSubmitDisposition:e}){var S,d,x,y;let[r,i]=ye({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),s=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],p=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],c=(g,E)=>{i(_=>F(l({},_),{[g]:E}))},m=()=>{i({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},u=()=>{m(),o(!1)};return n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:v(De,{sx:{borderRadius:2},children:[n(A,{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(A,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"10px",margin:"10px",borderRadius:"10px"},children:[v(A,{display:"flex",gap:2,children:[n(pn,{value:r.disposition,options:s,getOptionLabel:g=>g.label,onChange:(g,E)=>c("disposition",E),size:"small",renderInput:g=>n(ve,F(l({},g),{label:"Disposition",fullWidth:!0})),sx:{flex:1}}),n(pn,{options:p,getOptionLabel:g=>g.label,value:r.followUp,onChange:(g,E)=>c("followUp",E),size:"small",renderInput:g=>n(ve,F(l({},g),{label:"Follow Up",fullWidth:!0})),sx:{flex:1}})]}),((d=(S=r==null?void 0:r.followUp)==null?void 0:S.label)==null?void 0:d.toLowerCase())==="yes"&&v(A,{display:"flex",gap:2,mt:2,children:[n(ve,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:r.callbackDate,onChange:g=>c("callbackDate",g.target.value),fullWidth:!0,sx:{flex:1}}),n(ve,{size:"small",label:"Hours (0-23)",type:"text",value:r.callbackHrs,onChange:g=>c("callbackHrs",g.target.value),fullWidth:!0,sx:{flex:1}})]}),((y=(x=r==null?void 0:r.followUp)==null?void 0:x.label)==null?void 0:y.toLowerCase())==="yes"&&v(A,{display:"flex",gap:2,mt:2,children:[n(ve,{size:"small",label:"Minutes (0-59)",type:"text",value:r.callbackMins,onChange:g=>c("callbackMins",g.target.value),fullWidth:!0,sx:{flex:1}}),n(A,{sx:{flex:1}})]})]}),v(A,{textAlign:"right",m:2,children:[n(ie,{variant:"outlined",color:"error",size:"large",onClick:u,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),n(ie,{variant:"contained",color:"primary",size:"large",onClick:()=>e(r),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function mn({open:t,setOpen:o,processList:e=null,handleSelectedProcessor:r}){return n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:v(De,{sx:{borderRadius:2},children:[v(A,{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(he,{onClick:()=>{o(!1)},children:n(at,{})})]}),n(A,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:e.length>0?e==null?void 0:e.map((s,p)=>n(A,{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:()=>{r(s)},children:v(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[n(st,{sx:{marginRight:"4px"}}),s.process_name]})},p)):null})]})})})}function xn({open:t,setOpen:o}){return n(He,{children:n(Be,{open:t,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:v(De,{sx:{borderRadius:2},children:[v(A,{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(he,{onClick:()=>{o(!1)},children:n(at,{})})]}),n(A,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Coming Soon..."})]})})})}import{Fragment as js,jsx as f,jsxs as me}from"react/jsx-runtime";var Gs=(t,o,e)=>t.map(i=>{var s,p,c;if((i==null?void 0:i.line)===1){let m=`line_${i.line}_status`;return F(l({},i),{line:1,status:(s=o[m])!=null?s:e==null?void 0:e.status,phone:(p=e==null?void 0:e.phone_number)!=null?p:""})}else{let m=`line_${i.line}_status`,u=`line_${i.line}_phonenumber`;return F(l({},i),{status:(c=o[m])!=null?c:"IDLE",phone:o[u]!=="0"?o[u]:""})}}),Ys=t=>{let o=Math.floor(t/60),e=t%60;return`${o.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`};function En({onDataChange:t}){var bt,yt,ht,Et,Tt,St,vt,Dt,Lt,It,_t,Rt,kt,wt,Nt,At,Ot,Pt,Ut,Mt,Bt,Ht,$t,zt,qt,Kt,Ft,Wt,Gt,Yt,jt,Xt,Jt,Vt,Zt,Qt,eo,to,oo,no,so,ao,io,ro,lo,co,po,uo,go,fo,mo,xo,Co,bo,yo,ho,Eo,To,So,vo,Do,Lo,Io,_o,Ro,ko,wo,No,Ao,Oo,Po,Uo,Mo,Bo,Ho,$o,zo,qo,Ko,Fo,Wo;let o=Ws(),e=Se(),{showToast:r}=Ee(),{disabled:i,enabled:s,outlined:p}=ot({disabled:((bt=e.sdkConfig)==null?void 0:bt.disabled)||{},enabled:((yt=e.sdkConfig)==null?void 0:yt.enabled)||{},outlined:((ht=e.sdkConfig)==null?void 0:ht.outlined)||{}}),c=ze(null),m=ze(null),u=ze(null),S=ze(null),d=ze(0),x=60,y=1e3,g=3e4,[E,_]=ge(null),[O,R]=ge(!0),[P,H]=ge(null),[X,$]=ge(null),[k,T]=ge(!1),[D,J]=ge(!1),[ne,se]=ge(!1),[h,N]=ge(null),[U,q]=ge(""),[K,G]=ge(0),{position:Y,isDragging:V,dragRef:w,handleMouseDown:L,handleTouchStart:z}=ft(e.controlPanelPosition,a=>C.setControlPanelPosition(a)),{position:j,isDragging:Z,dragRef:Q,handleMouseDown:pe,handleTouchStart:qe}=ft(e.iframePosition,a=>C.setIframePosition(a)),[Ke,{isLoading:Fe}]=le({onSuccess:()=>{q(""),$(null)}}),[We,{isLoading:_e}]=le({onSuccess:()=>{C.setHolding(!e.isHolding)},onError:a=>{console.log("\u274C Hold operation error:",a)}}),[Ge,{isLoading:Re}]=le({onSuccess:()=>{C.setMuted(!e.isMuted)},onError:a=>{console.log("\u274C Mute operation error:",a)}}),[Ye,{isLoading:ke}]=le(),[je,{isLoading:Xe}]=le(),[Je,{isLoading:we}]=le(),Ve=()=>{_(null)},Ze=a=>{R(!0),$(a.currentTarget),C.setStatus("dial")},Qe=()=>{e.status!=="on call"&&C.setStatus("idle"),$(null)},xe=a=>{H(a.currentTarget)},vn=()=>{H(null)},Dn=()=>{let a={action:"READYAGENT",userId:e.agentId};Ye(I.READY_AGENT,a)},Ln=a=>{H(null);let b={action:"AGENTBREAK",break_type:a,userId:e.agentId};je(I.UPDATE_AGENT_BREAK,b)},In=a=>{if(a.length!==10)r("Invalid phone number","error");else if(!/^\d+$/.test(a))r("Invalid phone number","error");else{let b={action:"CALL",phone_number:a,userId:e.agentId};Ke(I.CLICK_TO_CALL,b)}},_n=()=>{let a={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};We(I.HOLD_CALL,a)},Rn=()=>{let a={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};Ge(I.MUTE_CALL,a)},kn=a=>{var M,oe,ae,de,fe,Ne,Ae,Go,Yo,jo,Xo,Jo,Vo,Zo,Qo,en;let b={action:"ENDCALL",userId:e.agentId,processid:(ae=(oe=(M=e.process)==null?void 0:M.process_id)==null?void 0:oe.toString())!=null?ae:"",process_name:(fe=(de=e.process)==null?void 0:de.process_name)!=null?fe:"",callreferenceid:(Ae=(Ne=e.callData)==null?void 0:Ne.convox_id)!=null?Ae:"",mobile_number:(Yo=(Go=e.callData)==null?void 0:Go.phone_number)!=null?Yo:"",disposition:(Xo=(jo=a==null?void 0:a.disposition)==null?void 0:jo.value)!=null?Xo:"",set_followUp:(Vo=(Jo=a==null?void 0:a.followUp)==null?void 0:Jo.value)!=null?Vo:"",callback_date:(Zo=a==null?void 0:a.callbackDate)!=null?Zo:"",callback_hrs:(Qo=a==null?void 0:a.callbackHrs)!=null?Qo:"",callback_mins:(en=a==null?void 0:a.callbackMins)!=null?en:"",endcall_type:"CLOSE"};q(""),Je(I.END_CALL,b),C.endCall(),T(!1)};Ie(()=>{let a=b=>{b.preventDefault()};return window.addEventListener("beforeunload",a),()=>{window.removeEventListener("beforeunload",a)}},[]),Ie(()=>{let a;return e.callData.status&&e.callData.status==="ONCALL"?a=setInterval(()=>{let b=Math.floor((Date.now()-e.callStartTime)/1e3);G(b)},1e3):G(0),()=>{a&&clearInterval(a)}},[e.callData.status]),Ie(()=>(m.current=new Audio("../ringtones/incoming.mp3"),m.current.loop=!0,m.current.volume=.7,()=>{m.current&&(m.current.pause(),m.current.currentTime=0,m.current=null)}),[]),Ie(()=>{if(t&&e.callData){let{process_id:a,process_name:b,status:M,phone_number:oe,agent_id:ae,convox_id:de}=e.callData;t({phone_number:oe,status:M,callReferenceId:de,agent_id:ae,process_id:a,process_name:b})}},[e.callData,t]),Ie(()=>{e.agentId?ee.post(I.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}).then(a=>{var b,M;a&&a.data&&((b=a==null?void 0:a.data)==null?void 0:b.length)>1?(N(a.data.data),J(!0)):(C.setProcess((M=a==null?void 0:a.data)==null?void 0:M.data[0]),J(!1))}).catch(a=>{r(a.response.data.message,"error")}):console.log("No agentId available, skipping API call")},[e.agentId]);let lt=()=>{if(!e.agentId){console.log("No agentId available, cannot connect WebSocket");return}u.current&&(clearTimeout(u.current),u.current=null);try{c.current=new WebSocket(`${on.WS}?agent_id=${e.agentId}`),c.current.onopen=()=>{console.log("\u{1F310} WebSocket connection established"),d.current=0,S.current&&clearInterval(S.current),S.current=setInterval(()=>{if(c.current&&c.current.readyState===WebSocket.OPEN)try{c.current.send(JSON.stringify({type:"ping"})),console.log("\u{1F4E1} WebSocket ping sent")}catch(a){console.error("Failed to send ping:",a)}},3e4)},c.current.onmessage=a=>{try{let b=JSON.parse(a.data);if(b.type==="pong"){console.log("\u{1F4E1} WebSocket pong received");return}let M=Gs(e==null?void 0:e.conferenceLine,b==null?void 0:b.conferencestatus,b);C.updateCallData(b),C.updateConferenceData([...M]),(b.status==="RINGING"||b.status==="DIALING")&&m.current&&m.current.play().catch(oe=>{console.error("Failed to play ringtone:",oe)}),b.status==="ONCALL"&&(m.current&&(m.current.pause(),m.current.currentTime=0),C.startCall(),O||R(!0)),b.status==="WRAPUP"&&(m.current&&(m.current.pause(),m.current.currentTime=0),C.endCall())}catch(b){console.log("\u{1F4E8} Raw message:",a.data)}},c.current.onclose=a=>{if(console.log("\u{1F50C} WebSocket connection closed",a.code,a.reason),S.current&&(clearInterval(S.current),S.current=null),a.code!==1e3&&d.current<x){d.current+=1;let b=Math.min(y*Math.pow(2,d.current-1),g);console.log(`\u{1F504} Attempting to reconnect WebSocket (attempt ${d.current}/${x}) in ${b}ms`),u.current=setTimeout(()=>{lt()},b)}else d.current>=x&&(console.error("\u274C Maximum reconnection attempts reached. Please refresh the page."),r("WebSocket connection failed. Please refresh the page.","error"))},c.current.onerror=a=>{console.error("\u274C WebSocket error:",a)}}catch(a){if(console.error("\u274C Failed to create WebSocket:",a),d.current<x){d.current+=1;let b=Math.min(y*Math.pow(2,d.current-1),g);u.current=setTimeout(()=>{lt()},b)}}};return Ie(()=>(e.agentId&<(),()=>{u.current&&(clearTimeout(u.current),u.current=null),S.current&&(clearInterval(S.current),S.current=null),c.current&&(c.current.close(1e3,"Component unmounting"),c.current=null),d.current=0}),[e.agentId]),!e.isInitialized||!e.process?f(ce,{children:!!D&&f(mn,{processList:h,open:D,setOpen:J,handleSelectedProcessor:a=>{C.setProcess(a)}})}):me(js,{children:[f(ce,{children:f(bn,{in:!0,timeout:300,children:f(yn,{ref:(Et=e.sdkConfig)!=null&&Et.isDraggable?w:null,elevation:V?4:(Tt=e.sdkConfig)!=null&&Tt.isDraggable?1:0,sx:{position:(St=e.sdkConfig)!=null&&St.isDraggable?"fixed":"relative",left:(vt=e.sdkConfig)!=null&&vt.isDraggable?Y.x:"auto",top:(Dt=e.sdkConfig)!=null&&Dt.isDraggable?Y.y:"auto",display:"inline-block",width:"auto",flexShrink:0,whiteSpace:"nowrap",p:.5,borderRadius:3,bgcolor:"background.paper",zIndex:(Lt=e.sdkConfig)!=null&&Lt.isDraggable?Number.MAX_SAFE_INTEGER:0,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),userSelect:"none"},children:me(ce,{sx:{display:"flex",alignItems:"center"},children:[me(ce,{sx:{display:"flex",alignItems:"center",gap:1,margin:"0px 10px"},children:[((It=e.sdkConfig)==null?void 0:It.isDraggable)&&me(rt,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:L,onTouchStart:z,children:[f(Cn,{})," "]}),f(ce,{children:!((_t=e.sdkConfig)!=null&&_t.disabledDialButton)&&f(Te,{title:"Dial",children:f(rt,{size:"small",onClick:a=>{var b,M,oe,ae,de,fe,Ne,Ae;((M=(b=e.callData)==null?void 0:b.status)==null?void 0:M.toUpperCase())!=="ONCALL"&&((ae=(oe=e.callData)==null?void 0:oe.status)==null?void 0:ae.toUpperCase())!=="BREAK"&&((fe=(de=e.callData)==null?void 0:de.status)==null?void 0:fe.toUpperCase())!=="RINGING"&&((Ae=(Ne=e.callData)==null?void 0:Ne.status)==null?void 0:Ae.toUpperCase())!=="WRAPUP"&&Ze(a)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:f(qs,{sx:{color:((kt=(Rt=e.callData)==null?void 0:Rt.status)==null?void 0:kt.toUpperCase())==="ONCALL"||((Nt=(wt=e.callData)==null?void 0:wt.status)==null?void 0:Nt.toUpperCase())==="BREAK"||((Ot=(At=e.callData)==null?void 0:At.status)==null?void 0:Ot.toUpperCase())==="RINGING"||((Ut=(Pt=e.callData)==null?void 0:Pt.status)==null?void 0:Ut.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),f(hn,{sx:{color:"success.main",width:"40px",marginRight:"10px",fontSize:"18px",fontWeight:"600"},children:Ys(K)}),f(it,{sx:{padding:"18px 0px"},label:Xe||ke?f(ce,{sx:{fontWeight:"bold",width:"60px",display:"flex",alignItems:"center",justifyContent:"center"},children:f($e,{size:"20px"})}):f(hn,{variant:"body2",sx:{fontWeight:"bold",width:"60px",textAlign:"center"},children:(Ht=(Bt=(Mt=e.callData)==null?void 0:Mt.status)==null?void 0:Bt.toUpperCase())!=null?Ht:"N/A"}),onClick:xe,deleteIcon:f(ws,{color:"primary"}),onDelete:xe})]}),me(ce,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[f(Te,{title:"Agent Ready",children:f(Le,{variant:((zt=($t=e.callData)==null?void 0:$t.status)==null?void 0:zt.toUpperCase())==="BREAK"||((Kt=(qt=e.callData)==null?void 0:qt.status)==null?void 0:Kt.toUpperCase())==="MISSED"?"outlined":"contained",onClick:a=>{var b,M,oe,ae;(((M=(b=e.callData)==null?void 0:b.status)==null?void 0:M.toUpperCase())==="BREAK"||((ae=(oe=e.callData)==null?void 0:oe.status)==null?void 0:ae.toUpperCase())==="MISSED")&&(a.stopPropagation(),Dn())},classes:{root:((Wt=(Ft=e.callData)==null?void 0:Ft.status)==null?void 0:Wt.toUpperCase())==="BREAK"||((Yt=(Gt=e.callData)==null?void 0:Gt.status)==null?void 0:Yt.toUpperCase())==="MISSED"?"outlined":"enabled"},sx:l({},((Xt=(jt=e.callData)==null?void 0:jt.status)==null?void 0:Xt.toUpperCase())==="BREAK"||((Vt=(Jt=e.callData)==null?void 0:Jt.status)==null?void 0:Vt.toUpperCase())==="MISSED"?p:s),disabled:ke,children:f(Hs,{})})}),f(Te,{title:e.isHolding?"Resume":"Hold",children:f(Le,{variant:e.isHolding&&((Qt=(Zt=e.callData)==null?void 0:Zt.status)==null?void 0:Qt.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),_n()},sx:e.isHolding&&((to=(eo=e.callData)==null?void 0:eo.status)==null?void 0:to.toUpperCase())==="ONCALL"?l({},s):((no=(oo=e.callData)==null?void 0:oo.status)==null?void 0:no.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((ao=(so=e.callData)==null?void 0:so.status)==null?void 0:ao.toUpperCase())!=="ONCALL"&&!e.isHolding||_e,children:_e?f($e,{size:"20px",sx:{color:o.palette.primary.main}}):e.isHolding?f(Bs,{}):f(Ps,{})})}),f(Te,{title:e.isMuted?"Unmute":"Mute",children:f(Le,{variant:e.isMuted&&((ro=(io=e.callData)==null?void 0:io.status)==null?void 0:ro.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),Rn()},sx:e.isMuted&&((co=(lo=e.callData)==null?void 0:lo.status)==null?void 0:co.toUpperCase())==="ONCALL"?l({},s):((uo=(po=e.callData)==null?void 0:po.status)==null?void 0:uo.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((fo=(go=e.callData)==null?void 0:go.status)==null?void 0:fo.toUpperCase())!=="ONCALL"&&!e.isMuted||Re,children:Re?f($e,{size:"20px",sx:{color:o.palette.primary.main}}):e.isMuted?f(Os,{}):f(As,{})})}),!((mo=e.sdkConfig)!=null&&mo.disableCallTransferButton)&&f(Te,{title:"Transfer Call",children:f(Le,{variant:e.openCallTransferDialog?"contained":"outlined",onClick:a=>{var b,M;((M=(b=e.callData)==null?void 0:b.status)==null?void 0:M.toUpperCase())==="ONCALL"&&(a.stopPropagation(),C.setOpenCallTransferDialog(!0))},sx:e.openCallTransferDialog?l({},s):((Co=(xo=e.callData)==null?void 0:xo.status)==null?void 0:Co.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((yo=(bo=e.callData)==null?void 0:bo.status)==null?void 0:yo.toUpperCase())!=="ONCALL",children:f($s,{})})}),!((ho=e.sdkConfig)!=null&&ho.disableConferenceButton)&&f(Te,{title:"Conference Call",children:f(Le,{variant:e.openConferenceDialog?"contained":"outlined",onClick:a=>{var b,M;((M=(b=e.callData)==null?void 0:b.status)==null?void 0:M.toUpperCase())==="ONCALL"&&(a.stopPropagation(),C.setOpenConferenceDialog(!0))},sx:e.openConferenceDialog?l({},s):((To=(Eo=e.callData)==null?void 0:Eo.status)==null?void 0:To.toUpperCase())==="ONCALL"?l({},p):l({},i),disabled:((vo=(So=e.callData)==null?void 0:So.status)==null?void 0:vo.toUpperCase())!=="ONCALL",children:f(ks,{})})}),!((Do=e.sdkConfig)!=null&&Do.disableEndCallButton)&&f(Te,{title:"End Call",children:f(Le,{variant:((Io=(Lo=e.callData)==null?void 0:Lo.status)==null?void 0:Io.toUpperCase())==="ONCALL"||((Ro=(_o=e.callData)==null?void 0:_o.status)==null?void 0:Ro.toUpperCase())==="RINGING"||((wo=(ko=e.callData)==null?void 0:ko.status)==null?void 0:wo.toUpperCase())==="WRAPUP"?"contained":"outlined",onClick:a=>{var b,M,oe,ae,de,fe;(((M=(b=e.callData)==null?void 0:b.status)==null?void 0:M.toUpperCase())==="ONCALL"||((ae=(oe=e.callData)==null?void 0:oe.status)==null?void 0:ae.toUpperCase())==="RINGING"||((fe=(de=e.callData)==null?void 0:de.status)==null?void 0:fe.toUpperCase())==="WRAPUP")&&(a.stopPropagation(),T(!0))},sx:((Ao=(No=e.callData)==null?void 0:No.status)==null?void 0:Ao.toUpperCase())==="ONCALL"||((Po=(Oo=e.callData)==null?void 0:Oo.status)==null?void 0:Po.toUpperCase())==="RINGING"||((Mo=(Uo=e.callData)==null?void 0:Uo.status)==null?void 0:Mo.toUpperCase())==="WRAPUP"?F(l({},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(l({},i),{minWidth:"60px !important"}),disabled:((Ho=(Bo=e.callData)==null?void 0:Bo.status)==null?void 0:Ho.toUpperCase())!=="ONCALL"&&((zo=($o=e.callData)==null?void 0:$o.status)==null?void 0:zo.toUpperCase())!=="RINGING"&&((Ko=(qo=e.callData)==null?void 0:qo.status)==null?void 0:Ko.toUpperCase())!=="WRAPUP"||we,children:we?f($e,{size:"20px",color:"error"}):f(_s,{})})})]})]})})})}),f(bn,{in:!0,timeout:300,children:me(yn,{ref:Q,elevation:Z?4:1,sx:{position:"absolute",left:j.x,top:j.y,borderRadius:2,bgcolor:"background.paper",zIndex:Number.MAX_SAFE_INTEGER,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),visibility:O&&!((Fo=e.sdkConfig)!=null&&Fo.disableSoftPhone)?"visible":"hidden",userSelect:"none"},children:[me(ce,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll",padding:"0px 10px"},onMouseDown:pe,onTouchStart:qe,children:[f(Cn,{sx:{transform:"rotate(90deg)",color:"#7b7b7b"}})," ",f(rt,{onClick:()=>R(!1),children:f(Rs,{})})]}),f(ce,{children:f("iframe",{src:`https://${et}/ConVoxCCS/iframe?agent_id=${e.agentId}&process_id=${(Wo=e.process)==null?void 0:Wo.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay",style:{border:"none"}})})]})}),f(xt,{anchorEl:X,open:!!X,onClose:Qe,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:me(ce,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[f(Fs,{size:"small",value:U,placeholder:"Enter Mobile No.",onChange:a=>{q(a.target.value)}}),f(rt,{color:"info",onClick:()=>{In(U)},children:Fe?f($e,{size:"20px",sx:{color:o.palette.success.main}}):f(Ms,{color:"success"})})]})}),f(xt,{anchorEl:P,open:!!P,onClose:vn,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:f(Ks,{onClick:()=>Ln("Lunch"),children:"- Break"})}),f(xt,{anchorEl:E,open:!!E,onClose:Ve,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:me(ce,{sx:{display:"flex",justifyContent:"flex-start",flexDirection:"column",padding:"0px 10px","&hover":{backgroundColor:"white"}},children:[f(it,{icon:f(Ns,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),f(it,{icon:f(Us,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),f(it,{icon:f(zs,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!e.openConferenceDialog&&f(un,{}),!!e.openCallTransferDialog&&f(gn,{open:e.openCallTransferDialog}),!!k&&f(fn,{open:k,setOpen:T,onSubmitDisposition:kn}),!!ne&&f(xn,{open:ne,setOpen:se})]})}import{memo as Xs}from"react";import{jsx as Js}from"react/jsx-runtime";var Ct=Xs(({children:t})=>Js(ln,{children:t}));Ct.displayName="SDKProvider";import{jsx as Tn}from"react/jsx-runtime";var Sn=Vs(({onDataChange:t})=>{let o=Zs(e=>{try{t&&typeof t=="function"&&t(e)}catch(r){console.error("Error in CallControlPanel data change handler:",r)}},[t]);return Tn(Ct,{children:Tn(En,{onDataChange:o})})});Sn.displayName="CallControlPanel";async function Vi({apiKey:t,tenantId:o,agentId:e,sdkConfig:r}){if(!t||typeof t!="string"||t.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(!e||typeof e!="string"||e.trim().length===0)throw new Error("SDK initialization failed: Agent ID is required and must be a non-empty string");try{let i=await ut.init({apiKey:t.trim(),tenantId:o.trim(),agentId:e.trim(),baseUrl:B});if(i)console.log("SDK initialized successfully"),C.initialize(t.trim(),o.trim(),e.trim(),r,i);else throw console.error("SDK initialization failed: Event tracker initialization returned false"),C.setInitCheck(),new Error("SDK initialization failed: Unable to establish connection with the CTI system")}catch(i){throw console.error("SDK initialization error:",i),C.setInitCheck(),i instanceof Error?i:new Error(`SDK initialization failed: ${String(i)}`)}}function Zi(){return"6.x.x"}function Qi(){return C.getState().isInitialized}export{Sn as CallControlPanel,Zi as getSDKVersion,Vi as initSDK,Qi as isSDKInitialized,jn as useClickToCall,Gn as useEndCall,es as useGetAuthorizationToken,Vn as useGetCallerData,Fn as useLogout};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|