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