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