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