call-control-sdk 5.4.8 β†’ 6.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,2 +1,85 @@
1
- var vs=Object.defineProperty,Es=Object.defineProperties;var Ts=Object.getOwnPropertyDescriptors;var Qo=Object.getOwnPropertySymbols;var Ss=Object.prototype.hasOwnProperty,Ds=Object.prototype.propertyIsEnumerable;var it=(t,o,e)=>o in t?vs(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,l=(t,o)=>{for(var e in o||(o={}))Ss.call(o,e)&&it(t,e,o[e]);if(Qo)for(var e of Qo(o))Ds.call(o,e)&&it(t,e,o[e]);return t},F=(t,o)=>Es(t,Ts(o));var ie=(t,o,e)=>it(t,typeof o!="symbol"?o+"":o,e);var lt=class{constructor(){ie(this,"state");ie(this,"listeners",[]);ie(this,"STORAGE_KEY","call-control-sdk-state");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(l({},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())}initialize(o,e,a){if(!o||typeof o!="string"||o.trim().length===0)throw new Error("API key not available");this.state.agentId=e,this.state.openConferenceDialog=!1,this.state.openCallTransferDialog=!1,this.state.sdkConfig=l({disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},a),this.state.isInitialized=!0,this.saveToStorage(),this.notifyListeners()}getState(){return l({},this.state)}subscribe(o){return this.listeners.push(o),()=>{let e=this.listeners.indexOf(o);e>-1&&this.listeners.splice(e,1)}}setHolding(o){this.state.isHolding=o,this.saveToStorage(),this.notifyListeners()}setMuted(o){this.state.isMuted=o,this.saveToStorage(),this.notifyListeners()}setStatus(o){this.state.status=o,this.saveToStorage(),this.notifyListeners()}setProcess(o){this.state.process=o,this.saveToStorage(),this.notifyListeners()}setControlPanelPosition(o){this.state.controlPanelPosition=o,this.saveToStorage(),this.notifyListeners()}setIframePosition(o){this.state.iframePosition=o,this.saveToStorage(),this.notifyListeners()}startCall(){this.state.callStartTime=Date.now(),this.state.status="on call",this.saveToStorage(),this.notifyListeners()}endCall(){this.state.callStartTime=null,this.state.status="idle",this.state.isHolding=!1,this.state.isMuted=!1,this.saveToStorage(),this.notifyListeners()}setInitCheck(){this.state.isInitialized=!1,this.saveToStorage(),this.notifyListeners()}setOpenConferenceDialog(o){this.state.openConferenceDialog=o,this.saveToStorage(),this.notifyListeners()}setOpenCallTransferDialog(o){this.state.openCallTransferDialog=o,this.saveToStorage(),this.notifyListeners()}updateCallData(o){this.state.callData=l(l({},this.state.callData),o),this.saveToStorage(),this.notifyListeners()}updateConferenceData(o){this.state.conferenceLine=[...o],this.saveToStorage(),this.notifyListeners()}setConferenceLine(o){var a;(!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=(a=this.state.conferenceLine)==null?void 0:a.map(i=>i.line===o.line?o:i);this.state.conferenceLine=e,this.saveToStorage(),this.notifyListeners()}resetConferenceLines(){this.state.conferenceLine=this.getInitialState().conferenceLine,this.saveToStorage(),this.notifyListeners()}clearStorageAndReset(){try{localStorage.removeItem(this.STORAGE_KEY),this.state=this.getInitialState(),this.notifyListeners()}catch(o){console.warn("Failed to clear localStorage:",o)}}debugStorage(){try{let o=localStorage.getItem(this.STORAGE_KEY);console.log("Current localStorage data:",o),o&&console.log("Parsed localStorage data:",JSON.parse(o)),console.log("Current state:",this.state)}catch(o){console.error("Error debugging storage:",o)}}getConferenceLines(){return this.state.conferenceLine||[]}},x=new lt;var rt=class{constructor(){ie(this,"config",null);ie(this,"ticketId",null);ie(this,"baseUrl","");ie(this,"eventQueue",[]);ie(this,"isOnline",!0);ie(this,"retryQueue",[]);ie(this,"flushTimer",null)}async init(o){this.config=l({autoTrack:!0,retryAttempts:3,queueSize:100,flushInterval:5e3},o),this.baseUrl=o.baseUrl||(typeof window!="undefined"?window.location.origin:""),this.setupNetworkDetection();let e=await this.createTicket();return this.startPeriodicFlush(),console.log("EventTracker SDK initialized successfully"),e}isInitialized(){return this.config!==null&&this.ticketId!==null}getConfig(){return this.config}getTicketId(){return this.ticketId}async createTicket(){if(!this.config)throw new Error("EventTracker not initialized");try{let o=await this.makeRequest("/api/v1/et/init",{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.config.apiKey},body:JSON.stringify({agentId:this.config.agentId,sessionId:this.config.sessionId})});if(!o.ok)throw 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 a={eventType:o,eventData:e,timestamp:Date.now()};if(this.eventQueue.push(a),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift(),this.isOnline)try{await this.sendEvent(a)}catch(i){console.warn("Failed to send event, will retry later:",i)}}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 a=this.eventQueue.findIndex(i=>i.timestamp===o.timestamp);a>-1&&this.eventQueue.splice(a,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 a of o)await this.sendEvent(a);let e=[...this.retryQueue];this.retryQueue=[];for(let a of e)try{await a()}catch(i){console.error("Retry failed:",i)}}async makeRequest(o,e){var r;let a=`${this.baseUrl}${o}`,i=((r=this.config)==null?void 0:r.retryAttempts)||3;for(let c=1;c<=i;c++)try{return await fetch(a,e)}catch(m){if(c===i)throw m;let b=Math.min(1e3*Math.pow(2,c-1),1e4);await new Promise(f=>setTimeout(f,b))}throw new Error("Max retries exceeded")}setupAutoTracking(){var a;if(typeof window=="undefined"||!((a=this.config)!=null&&a.autoTrack))return;let o=this.config.autoTrack===!0?{}:this.config.autoTrack;if(o.pageVisits!==!1&&this.logEvent("pageVisit",{url:window.location.href,title:document.title,referrer:document.referrer,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},timestamp:new Date().toISOString()}).catch(i=>console.warn("Failed to track page visit:",i)),o.clicks!==!1&&document.addEventListener("click",i=>{var c;let r=i.target;(r.tagName==="BUTTON"||r.tagName==="A"||r.onclick||r.getAttribute("role")==="button"||r instanceof HTMLButtonElement&&r.type==="button")&&this.logEvent("click",{element:r.tagName,text:(c=r.textContent)==null?void 0:c.trim().substring(0,100),href:r.getAttribute("href"),id:r.id,className:r.className,role:r.getAttribute("role"),position:{x:i.clientX,y:i.clientY},timestamp:new Date().toISOString()}).catch(m=>console.warn("Failed to track click:",m))}),o.forms!==!1&&document.addEventListener("submit",i=>{let r=i.target,c=new FormData(r),m={};c.forEach((b,f)=>{m[f]=b.toString()}),this.logEvent("formSubmission",{formId:r.id,action:r.action,method:r.method,fields:Object.keys(m),fieldCount:Object.keys(m).length,timestamp:new Date().toISOString()}).catch(b=>console.warn("Failed to track form submission:",b))}),o.inputs!==!1){let i;document.addEventListener("input",r=>{let c=r.target;(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.tagName==="SELECT")&&(clearTimeout(i),i=setTimeout(()=>{var m;this.logEvent("fieldChange",{element:c.tagName,type:c.getAttribute("type"),name:c.getAttribute("name"),id:c.id,valueLength:((m=c.value)==null?void 0:m.length)||0,timestamp:new Date().toISOString()}).catch(b=>console.warn("Failed to track field change:",b))},1e3))})}let e=Date.now();window.addEventListener("beforeunload",()=>{let i=Date.now()-e;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:i,timestamp:new Date().toISOString()}),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",i=>{this.logEvent("jsError",{message:i.message,filename:i.filename,lineno:i.lineno,colno:i.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",i=>{var r;this.logEvent("unhandledRejection",{reason:(r=i.reason)==null?void 0:r.toString(),timestamp:new Date().toISOString()})})),o.performance!==!1&&typeof window.performance!="undefined"&&window.performance.navigation&&window.addEventListener("load",()=>{setTimeout(()=>{let i=window.performance.navigation,r=window.performance.timing;this.logEvent("performanceMetrics",{navigationTime:r.navigationStart,loadTime:r.loadEventEnd-r.navigationStart,domReady:r.domContentLoadedEventEnd-r.navigationStart,renderTime:r.loadEventEnd-r.domContentLoadedEventEnd,navigationType:i.type,redirectCount:i.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 As,useState as Ne}from"react";var Qe="10.10.102.42",H=`http://${Qe}:8095`,Ls=`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:`${Ls}${K.v1}/cti/ws`};import Is from"axios";var Rs="12345",_s=6e4;function ws(){return Rs}function ks(){let t=Is.create({baseURL:H,headers:{"Content-Type":"application/json",Accept:"application/json"},timeout:_s,withCredentials:!1});return t.interceptors.request.use(o=>{let e=ws();return e&&o.headers&&(o.headers.Authorization=`Bearer ${e}`),o.metadata={startTime:new Date().getTime()},o},o=>(console.error("Request interceptor error:",o),Promise.reject(o))),t.interceptors.response.use(o=>{var i;let e=new Date().getTime(),a=(i=o.config.metadata)==null?void 0:i.startTime;return a&&console.log(`Request to ${o.config.url} took ${e-a}ms`),o},async o=>{var a;let e=o.config;return((a=o.response)==null?void 0:a.status)===401&&!e._retry&&(e._retry=!0,console.warn("Unauthorized request, attempting retry...")),o.response||(console.error("Network error:",o.message),o.message="Network error: Please check your internet connection"),o.response&&o.response.status>=500&&(console.error("Server error:",o.response.status,o.response.data),o.message="Server error: Please try again later"),Promise.reject(o)}),t}var Ns=ks(),Z=Ns;var Ps=()=>{let[t,o]=Ne(!1),[e,a]=Ne(!1),[i,r]=Ne(!1),[c,m]=Ne(null),[b,f]=Ne(null);return{logout:As(async()=>{var C;let p=JSON.parse((C=localStorage.getItem("call-control-sdk-state"))!=null?C:"");o(!0);let u={action:"LOGOUTUSER",userId:p.agentId||""};return Z.post(I.LOGOUT,u).then(g=>(x.clearStorageAndReset(),localStorage.clear(),sessionStorage.clear(),f(g==null?void 0:g.data),a(!0),g==null?void 0:g.data)).catch(g=>{var h;return r(!0),m(g),(h=g==null?void 0:g.response)==null?void 0:h.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:c,data:b}};import{useCallback as Os,useState as Ae}from"react";var Us=()=>{let[t,o]=Ae(!1),[e,a]=Ae(!1),[i,r]=Ae(!1),[c,m]=Ae(null),[b,f]=Ae(null);return{handleEndCall:Os(async p=>{var g,h,_,U,M,P,$,Q,z,w,v,T,ee,oe,L;let u=JSON.parse((g=localStorage.getItem("call-control-sdk-state"))!=null?g:"");o(!0);let C={action:"ENDCALL",userId:u==null?void 0:u.agentId,processid:(U=(_=(h=u==null?void 0:u.process)==null?void 0:h.process_id)==null?void 0:_.toString())!=null?U:"",process_name:(P=(M=u==null?void 0:u.process)==null?void 0:M.process_name)!=null?P:"",callreferenceid:(Q=($=u==null?void 0:u.callData)==null?void 0:$.convox_id)!=null?Q:"",mobile_number:(w=(z=u==null?void 0:u.callData)==null?void 0:z.phone_number)!=null?w:"",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,C).then(E=>(x.endCall(),f(E==null?void 0:E.data),a(!0),E==null?void 0:E.data)).catch(E=>{var k;return r(!0),m(E),(k=E==null?void 0:E.response)==null?void 0:k.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:c,data:b}};import{useCallback as Ms,useState as Pe}from"react";var Bs=()=>{let[t,o]=Pe(!1),[e,a]=Pe(!1),[i,r]=Pe(!1),[c,m]=Pe(null),[b,f]=Pe(null);return{handleStartCall:Ms(async p=>{var C,g,h,_,U,M,P,$,Q;let u=JSON.parse((C=localStorage.getItem("call-control-sdk-state"))!=null?C:"");if(o(!0),((g=u==null?void 0:u.callData)==null?void 0:g.status)==="IDLE"){let z={action:"CALL",userId:u==null?void 0:u.agentId,phone_number:p==null?void 0:p.mobileNumber};return Z.post(I.CLICK_TO_CALL,z).then(w=>(f(w==null?void 0:w.data),a(!0),w==null?void 0:w.data)).catch(w=>{var v;return r(!0),m(w),(v=w==null?void 0:w.response)==null?void 0:v.data}).finally(()=>{o(!1)})}else if(((h=u==null?void 0:u.callData)==null?void 0:h.status)==="ONCALL"){let z=(U=(_=u==null?void 0:u.conferenceLine)==null?void 0:_.filter(v=>v.line!==1))==null?void 0:U.find(v=>v.status==="IDLE"&&!(v!=null&&v.isCallStart)),w={action:"EXTERNAL_CONFERENCE",operation:`CALL${z.line}`,line_used:String(z.line),thirdparty_no:p==null?void 0:p.mobileNumber,userid:(P=(M=u.callData)==null?void 0:M.agent_id)!=null?P:"",process:(Q=($=u.callData)==null?void 0:$.process_name)!=null?Q:""};return Z.post(I.CONFERENCE_CALL,w).then(v=>(f(v==null?void 0:v.data),a(!0),x.setConferenceLine(F(l({},z),{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 r(!0),m(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:i,error:c,data:b}};import{memo as On,useCallback as Un}from"react";import{CallEnd as un,Close as gn,DragIndicator as us,Group as fn,KeyboardArrowDown as mn,Layers as xn,Mic as Cn,MicOff as yn,Pause as bn,Pending as hn,Phone as vn,PlayArrow as En,SupportAgent as Tn,TransferWithinAStation as Sn,Upcoming as Dn,WifiCalling3 as Ln}from"@mui/icons-material";import{Box as re,Button as Se,Chip as nt,CircularProgress as Be,Fade as gs,IconButton as at,Menu as gt,MenuItem as fs,Paper as ms,TextField as In,Tooltip as he,Typography as xs,useTheme as Rn}from"@mui/material";import{useCallback as _n,useEffect as He,useRef as wn,useState as ue}from"react";import{useCallback as Ze,useRef as dt,useState as es}from"react";function pt(t,o){let[e,a]=es(t),[i,r]=es(!1),c=dt(),m=dt({x:0,y:0}),b=dt({x:0,y:0}),f=Ze(C=>{let g=c.current;if(!g)return;let h=g.getBoundingClientRect(),_=window.innerWidth,U=window.innerHeight,M={x:Math.max(0,Math.min(C.x,_-h.width)),y:Math.max(0,Math.min(C.y,U-h.height))};a(M),o==null||o(M)},[o]),A=Ze((C,g)=>{r(!0),m.current={x:C,y:g},b.current=e;let h=(P,$)=>{let Q=P-m.current.x,z=$-m.current.y;f({x:b.current.x+Q,y:b.current.y+z})},_=P=>{P.preventDefault(),h(P.clientX,P.clientY)},U=P=>{P.preventDefault();let $=P.touches[0];$&&h($.clientX,$.clientY)},M=()=>{r(!1),document.removeEventListener("mousemove",_),document.removeEventListener("mouseup",M),document.removeEventListener("touchmove",U),document.removeEventListener("touchend",M)};document.addEventListener("mousemove",_),document.addEventListener("mouseup",M),document.addEventListener("touchmove",U,{passive:!1}),document.addEventListener("touchend",M)},[e,f]),p=Ze(C=>{C.preventDefault(),A(C.clientX,C.clientY)},[A]),u=Ze(C=>{C.preventDefault();let g=C.touches[0];g&&A(g.clientX,g.clientY)},[A]);return{position:e,isDragging:i,dragRef:c,handleMouseDown:p,handleTouchStart:u}}import{useState as Hs,useEffect as $s}from"react";function ve(){let[t,o]=Hs(x.getState());return $s(()=>x.subscribe(()=>{o(x.getState())}),[]),t}import{useCallback as Gs,useReducer as js}from"react";import{createContext as qs,useContext as zs,useState as ut}from"react";import{Snackbar as Fs,Alert as Ks}from"@mui/material";import{jsx as ts,jsxs as Ws}from"react/jsx-runtime";var os=qs(void 0),be=()=>{let t=zs(os);if(!t)throw new Error("useToast must be used inside ToastProvider");return t},ss=({children:t})=>{let[o,e]=ut(!1),[a,i]=ut(""),[r,c]=ut("info"),m=(b,f="info")=>{i(b),c(f),e(!0)};return Ws(os.Provider,{value:{showToast:m},children:[t,ts(Fs,{open:o,color:r,autoHideDuration:3e3,onClose:()=>e(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:ts(Ks,{variant:"filled",severity:r,onClose:()=>e(!1),sx:{width:"100%"},children:a})})]})};var Ys={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},Xs=(t,o)=>{if(o.type==="isLoading")return F(l({},t),{isLoading:o.payload});if(o.type==="isSuccess")return F(l({},t),{isSuccess:!0,data:o.payload});if(o.type==="isError")return F(l({},t),{isError:!0,error:o.payload});if(o.type==="reset")return{isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null};throw Error("Unknown action.")};var le=(t={})=>{let{onSuccess:o=null,onError:e=null,disabledSuccessToast:a=!1}=t,{showToast:i}=be(),[r,c]=js(Xs,Ys);return[Gs((b,f,A={})=>{c({type:"isLoading",payload:!0}),Z.post(b,f,A).then(p=>{var u,C;c({type:"isSuccess",payload:p.data}),o==null||o(p.data,f),console.log((u=p.data)==null?void 0:u.message,"res45"),a||i((C=p.data)==null?void 0:C.message,"success")}).catch(p=>{var C,g,h,_,U,M,P,$,Q,z,w,v;let u={status:(g=(C=p.response)==null?void 0:C.status)!=null?g:500,message:((_=(h=p.response)==null?void 0:h.data)==null?void 0:_.detail)||((M=(U=p.response)==null?void 0:U.data)==null?void 0:M.message)||p.message||"An unknown error occurred",data:($=(P=p.response)==null?void 0:P.data)!=null?$:null,statusText:(z=(Q=p.response)==null?void 0:Q.statusText)!=null?z:"",code:(w=p==null?void 0:p.code)!=null?w:"",name:(v=p==null?void 0:p.name)!=null?v:""};i(u.message,"error"),c({type:"isError",payload:u}),e==null||e(u,f)}).finally(()=>{c({type:"isLoading",payload:!1})})},[o,e,i]),r]};import{Call as tt,CallEnd as ns,CallSplit as Qs,Close as st,Mic as Zs,MicOff as en,Pause as tn,PhoneDisabled as on,PlayArrow as sn,SupportAgent as ot}from"@mui/icons-material";import{Box as O,Button as ae,Dialog as Ue,IconButton as Ce,Paper as Te,TextField as Ee,Typography as te,Autocomplete as as,Tooltip as Oe,useTheme as nn,TableContainer as an,Table as ln,TableHead as rn,TableRow as is,TableCell as pe,TableBody as cn,CircularProgress as me}from"@mui/material";import{useEffect as dn,useState as xe}from"react";import{useTheme as Js}from"@mui/material";var Vs=({disabled:t,enabled:o,outlined:e})=>{let a=Js();return{disabled:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",border:"1px solid rgb(206, 204, 204)",height:"40px","&:hover":{boxShadow:" 0px 2px 2px rgba(0, 0, 0, 0.79)",border:`1px solid ${a.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${a.palette.primary.light}`}},t),enabled:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${a.palette.primary.main}`,height:"40px","&:hover":{boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${a.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${a.palette.primary.light}`}},o),outlined:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",backgroundColor:a.palette.grey[200],boxShadow:`0px 2px 1px ${a.palette.primary.light}`,border:`0px solid ${a.palette.primary.main}`,height:"40px","&:hover":{boxShadow:`0px 2px 1px ${a.palette.primary.main}`,border:`0px solid ${a.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${a.palette.primary.light}`}},e)}},et=Vs;import{Fragment as Me,jsx as s,jsxs as S}from"react/jsx-runtime";var pn=({each:t})=>{var w,v,T,ee,oe;let o=ve(),{showToast:e}=be(),{disabled:a,enabled:i,outlined:r}=et({disabled:((w=o.sdkConfig)==null?void 0:w.disabled)||{},enabled:((v=o.sdkConfig)==null?void 0:v.enabled)||{},outlined:((T=o.sdkConfig)==null?void 0:T.outlined)||{}}),c=nn(),[m,b]=xe(!1),[f,A]=xe(!1),[p,u]=xe(!1),[C,g]=xe(!1),[h,_]=xe(!1),U=(L,E)=>{x.setConferenceLine(l(l({},L),E))},M=(L,E)=>{var G,B,Y,X;let k=l(l({},L),E);b(!0);let W={action:"EXTERNAL_CONFERENCE",operation:`CALL${k.line}`,line_used:String(k.line),thirdparty_no:k.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(R=>{var D;e((D=R.data)==null?void 0:D.message,"success"),x.setConferenceLine(l(l({},L),E))}).catch(R=>{var q,J,V,j;let D=((J=(q=R.response)==null?void 0:q.data)==null?void 0:J.detail)||((j=(V=R.response)==null?void 0:V.data)==null?void 0:j.message)||R.message||"An unknown error occurred";e(D,"error")}).finally(()=>{b(!1)})},P=(L,E)=>{var G,B,Y,X;let k=l(l({},L),E);A(!0);let W={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(k.line),thirdparty_no:k.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(R=>{var D;e((D=R.data)==null?void 0:D.message,"success"),x.setConferenceLine(l(l({},L),E))}).catch(R=>{var q,J,V,j;let D=((J=(q=R.response)==null?void 0:q.data)==null?void 0:J.detail)||((j=(V=R.response)==null?void 0:V.data)==null?void 0:j.message)||R.message||"An unknown error occurred";e(D,"error")}).finally(()=>{A(!1)})},$=(L,E,k)=>{var B,Y,X,R;let W=l(l({},L),E);u(!0);let G={action:"EXTERNAL_CONFERENCE",operation:k,hold_channel_no:k==="HOLDUSER"?`hold${W.line}`:`unhold${W.line}`,userid:(Y=(B=o.callData)==null?void 0:B.agent_id)!=null?Y:"",process:(R=(X=o.callData)==null?void 0:X.process_name)!=null?R:""};Z.post(I.CONFERENCE_CALL_HOLD_OR_UN_HOLD,G).then(D=>{var q;e((q=D.data)==null?void 0:q.message,"success"),x.setConferenceLine(l(l({},L),E))}).catch(D=>{var J,V,j,ce;let q=((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(q,"error")}).finally(()=>{u(!1)})},Q=(L,E,k)=>{var B,Y,X,R;let W=l(l({},L),E);g(!0);let G={action:"EXTERNAL_CONFERENCE",operation:k,channel_no:k==="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:(R=(X=o.callData)==null?void 0:X.process_name)!=null?R:""};Z.post(I.CONFERENCE_CALL_MUTE_OT_UN_MUTE,G).then(D=>{var q;e((q=D.data)==null?void 0:q.message,"success"),x.setConferenceLine(l(l({},L),E))}).catch(D=>{var J,V,j,ce;let q=((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(q,"error")}).finally(()=>{g(!1)})},z=(L,E)=>{var G,B,Y,X;let k=l(l({},L),E);_(!0);let W={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(k.line-1),user_type:`THIRDPARTY${k.line-1}`,thirdparty_no:k.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(R=>{var D;e((D=R.data)==null?void 0:D.message,"success"),x.setConferenceLine(l(l({},L),E))}).catch(R=>{var q,J,V,j;let D=((J=(q=R.response)==null?void 0:q.data)==null?void 0:J.detail)||((j=(V=R.response)==null?void 0:V.data)==null?void 0:j.message)||R.message||"An unknown error occurred";e(D,"error")}).finally(()=>{_(!1)})};return S(is,{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(ae,{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)==="LINE USED",onChange:L=>{U(t,{phone:L.target.value})}})}),s(pe,{sx:{padding:"6px"},children:S(O,{sx:{display:"flex",alignItems:"center",justifyContent:"space-around"},children:[t.line!==1&&s(Oe,{title:"Call",children:s(ae,{variant:(t==null?void 0:t.status)!=="IDLE"?"outlined":"contained",color:"success",sx:(t==null?void 0:t.status)!=="IDLE"?l({},a):F(l({},i),{border:`0px solid ${c.palette.success.light}`,"&:hover":{bgcolor:"success.light",boxShadow:`0px 2px 1px ${c.palette.success.light}`,border:`0px solid ${c.palette.success.light}`},"&:active":{bgcolor:"success.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}),onClick:()=>{M(t,{})},disabled:(t==null?void 0:t.status)!=="IDLE",children:m?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(ae,{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(l({},a),{padding:"0px 16px"}):(t==null?void 0:t.status)==="ONCALL"?F(l({},r),{padding:"0px 16px"}):F(l({},a),{padding:"0px 16px"}),onClick:()=>{P(t,{isMergeCall:!0})},disabled:(t==null?void 0:t.status)!=="ONCALL"||f,children:[t!=null&&t.isMergeCall?"Merged":"Merge",f?s(me,{size:"20px"}):s(Qs,{})]})}),s(Oe,{title:t.isHold?"Hold":"Un Hold",children:s(ae,{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"?l({},a):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},r):l({},a),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:c.palette.primary.main}}):t.isHold?s(sn,{}):s(tn,{})})}),s(Oe,{title:t.isMute?"Mute":"Un Mute",children:s(ae,{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"?l({},a):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},r):l({},a),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"||C,children:C?s(me,{size:"20px",sx:{color:c.palette.primary.main}}):t.isMute?s(en,{}):s(Zs,{})})}),(t==null?void 0:t.line)!==1?s(Oe,{title:"End Call",children:s(ae,{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(l({},i),{border:`0px solid ${c.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${c.palette.error.light}`,border:`0px solid ${c.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}):l({},a),onClick:()=>{z(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(ns,{})})}):s(ae,{variant:t!=null&&t.isCallStart?"contained":"outlined",color:"error",sx:{display:"none"},onClick:()=>{z(t,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:!(t!=null&&t.isCallStart)||h,children:h?s(me,{size:"20px",color:"error"}):s(ns,{})})]})})]},t.line)};function ls(){var c;let t=ve(),{showToast:o}=be(),[e,a]=xe(!1),i=()=>{x.setOpenConferenceDialog(!1)},r=()=>{var b,f,A,p;a(!0);let m={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(f=(b=t.callData)==null?void 0:b.agent_id)!=null?f:"",process:(p=(A=t.callData)==null?void 0:A.process_name)!=null?p:""};Z.post(I.CONFERENCE_CALL_END_ALL,m).then(u=>{var C;o((C=u.data)==null?void 0:C.message,"success"),x.resetConferenceLines(),i()}).catch(u=>{var g,h,_,U;let C=((h=(g=u.response)==null?void 0:g.data)==null?void 0:h.detail)||((U=(_=u.response)==null?void 0:_.data)==null?void 0:U.message)||u.message||"An unknown error occurred";o(C,"error")}).finally(()=>{a(!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(O,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px"},children:[S(te,{variant:"body1",children:[(c=t==null?void 0:t.agentId)!=null?c:""," conference"]}),s(Ce,{onClick:i,children:s(st,{})})]}),s(O,{sx:{boxShadow:"1px 1px 2px #e7e5e5ff",margin:"0px 15px",borderRadius:"20px"},children:s(an,{component:Te,sx:{outline:"0px solid gray !important",boxShadow:"1px 1px 6px #e7e5e5ff"},children:S(ln,{sx:{border:"4px solid #ffffff !important"},children:[s(rn,{children:S(is,{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(cn,{children:t==null?void 0:t.conferenceLine.map(m=>s(pn,{each:m}))})]})})}),s(O,{textAlign:"center",m:2,children:S(ae,{variant:"outlined",color:"error",size:"large",onClick:r,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(on,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function rs({open:t}){var C,g,h,_,U,M,P,$,Q,z,w,v;let[o]=le({onSuccess:()=>{x.setOpenCallTransferDialog(!1)}}),e=ve(),[a,i]=xe("process"),[r,{data:c,isLoading:m}]=le({disabledSuccessToast:!0}),[b,{data:f,isLoading:A}]=le({disabledSuccessToast:!0}),p=()=>{x.setOpenCallTransferDialog(!1)},u=(T,ee)=>{var oe,L,E,k,W,G,B,Y,X,R,D,q,J,V,j,ce,De,$e,Le,qe,ze,Fe,Ie,Ke,We,Ge,je,Re,Ye,Xe,_e,Je,Ve;if(console.log(T,"data34"),ee==="PROCESS"){let ye={mobile_number:(L=(oe=e.callData)==null?void 0:oe.phone_number)!=null?L:"",userid:(k=(E=e.callData)==null?void 0:E.agent_id)!=null?k:"",type:"PROCESS",transfer_to:(W=T==null?void 0:T.process_name)!=null?W:"",callreferenceid:(B=(G=e.callData)==null?void 0:G.convox_id)!=null?B:"",processid:String((X=(Y=e.callData)==null?void 0:Y.process_id)!=null?X:""),process_name:(D=(R=e.callData)==null?void 0:R.process_name)!=null?D:""};o(I.TRANSFER_CALL,ye)}else if(ee==="QUEUE"){let ye={mobile_number:(J=(q=e.callData)==null?void 0:q.phone_number)!=null?J:"",userid:(j=(V=e.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=e.callData)==null?void 0:De.convox_id)!=null?$e:"",processid:String((qe=(Le=e.callData)==null?void 0:Le.process_id)!=null?qe:""),process_name:(Fe=(ze=e.callData)==null?void 0:ze.process_name)!=null?Fe:""};o(I.TRANSFER_CALL,ye)}else if(ee==="AGENT"){let ye={mobile_number:(Ke=(Ie=e.callData)==null?void 0:Ie.phone_number)!=null?Ke:"",userid:(Ge=(We=e.callData)==null?void 0:We.agent_id)!=null?Ge:"",type:"AGENT",transfer_to:(je=T==null?void 0:T.user_id)!=null?je:"",callreferenceid:(Ye=(Re=e.callData)==null?void 0:Re.convox_id)!=null?Ye:"",processid:String((_e=(Xe=e.callData)==null?void 0:Xe.process_id)!=null?_e:""),process_name:(Ve=(Je=e.callData)==null?void 0:Je.process_name)!=null?Ve:""};o(I.TRANSFER_CALL,ye)}};return dn(()=>{r(I.AGENTS_LIST,{status:"IDLE",active:!0}),b(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),console.log(c,"idleAgentsList"),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(O,{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(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:[S(O,{sx:{display:"flex",gap:1},children:[s(ae,{variant:a==="process"?"contained":"outlined",onClick:()=>{i("process"),b(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Process"}),s(ae,{variant:a==="queues"?"contained":"outlined",onClick:()=>{i("queues"),b(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Queues"}),s(ae,{variant:a==="agents"?"contained":"outlined",onClick:()=>{i("agents"),r(I.AGENTS_LIST,{status:"IDLE",active:!0})},children:"Agents"})]}),(A||m)&&S(O,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"80px"},children:[s(me,{})," "]}),!A&&!m&&a==="process"&&s(O,{sx:{display:"flex",gap:1},children:(C=f==null?void 0:f.data)!=null&&C.process&&((h=(g=f==null?void 0:f.data)==null?void 0:g.process)==null?void 0:h.length)>0?(U=(_=f==null?void 0:f.data)==null?void 0:_.process)==null?void 0:U.map((T,ee)=>S(O,{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:()=>{u(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"})}),!A&&!m&&a==="queues"&&s(O,{sx:{display:"flex",gap:1},children:(M=f==null?void 0:f.data)!=null&&M.queue&&(($=(P=f==null?void 0:f.data)==null?void 0:P.queue)==null?void 0:$.length)>0?(z=(Q=f==null?void 0:f.data)==null?void 0:Q.queue)==null?void 0:z.map((T,ee)=>{var oe,L,E,k,W,G;return S(O,{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=f==null?void 0:f.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=(k=f==null?void 0:f.data)==null?void 0:k.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:()=>{u(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"})}),!A&&!m&&a==="agents"&&s(O,{sx:{display:"flex",gap:1},children:c!=null&&c.data&&((w=c==null?void 0:c.data)==null?void 0:w.length)>0?(v=c==null?void 0:c.data)==null?void 0:v.map((T,ee)=>S(O,{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:()=>{u(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 cs({open:t,setOpen:o,onSubmitDisposition:e}){var A,p,u,C;let[a,i]=xe({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),r=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],c=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],m=(g,h)=>{i(_=>F(l({},_),{[g]:h}))},b=()=>{i({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},f=()=>{b(),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(O,{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(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"10px",margin:"10px",borderRadius:"10px"},children:[S(O,{display:"flex",gap:2,children:[s(as,{value:a.disposition,options:r,getOptionLabel:g=>g.label,onChange:(g,h)=>m("disposition",h),size:"small",renderInput:g=>s(Ee,F(l({},g),{label:"Disposition",fullWidth:!0})),sx:{flex:1}}),s(as,{options:c,getOptionLabel:g=>g.label,value:a.followUp,onChange:(g,h)=>m("followUp",h),size:"small",renderInput:g=>s(Ee,F(l({},g),{label:"Follow Up",fullWidth:!0})),sx:{flex:1}})]}),((p=(A=a==null?void 0:a.followUp)==null?void 0:A.label)==null?void 0:p.toLowerCase())==="yes"&&S(O,{display:"flex",gap:2,mt:2,children:[s(Ee,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:a.callbackDate,onChange:g=>m("callbackDate",g.target.value),fullWidth:!0,sx:{flex:1}}),s(Ee,{size:"small",label:"Hours (0-23)",type:"text",value:a.callbackHrs,onChange:g=>m("callbackHrs",g.target.value),fullWidth:!0,sx:{flex:1}})]}),((C=(u=a==null?void 0:a.followUp)==null?void 0:u.label)==null?void 0:C.toLowerCase())==="yes"&&S(O,{display:"flex",gap:2,mt:2,children:[s(Ee,{size:"small",label:"Minutes (0-59)",type:"text",value:a.callbackMins,onChange:g=>m("callbackMins",g.target.value),fullWidth:!0,sx:{flex:1}}),s(O,{sx:{flex:1}})]})]}),S(O,{textAlign:"right",m:2,children:[s(ae,{variant:"outlined",color:"error",size:"large",onClick:f,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),s(ae,{variant:"contained",color:"primary",size:"large",onClick:()=>e(a),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function ds({open:t,setOpen:o,processList:e=null,handleSelectedProcessor:a}){let i=()=>{o(!1)};return console.log(e,"processList"),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(O,{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:i,children:s(st,{})})]}),s(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:e.length>0?e==null?void 0:e.map((r,c)=>s(O,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px",cursor:"pointer","&:hover":{bgcolor:"action.selected"}},onClick:()=>{a(r)},children:S(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[s(ot,{sx:{marginRight:"4px"}}),r.process_name]})},c)):null})]})})})}function ps({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(O,{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(O,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Coming Soon..."})]})})})}import{Fragment as Nn,jsx as d,jsxs as ge}from"react/jsx-runtime";var kn=(t,o,e)=>t.map(i=>{var r,c,m;if((i==null?void 0:i.line)===1)return{line:1,status:(r=e==null?void 0:e.status)!=null?r:"",type:"internal",phone:(c=e==null?void 0:e.phone_number)!=null?c:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};{let b=`line_${i.line}_status`,f=`line_${i.line}_phonenumber`;return F(l({},i),{status:(m=o[b])!=null?m:"IDLE",phone:o[f]!=="0"?o[f]:""})}});function Cs({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,qt,zt,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,qo,zo;let o=Rn(),e=ve(),{showToast:a}=be(),{disabled:i,enabled:r,outlined:c}=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)||{}}),m=wn(null),[b,f]=ue(null),[A,p]=ue(!0),[u,C]=ue(null),[g,h]=ue(null),[_,U]=ue(!1),[M,P]=ue(!1),[$,Q]=ue(!1),[z,w]=ue(null),[v,T]=ue(""),[ee,oe]=ue(0),{position:L,isDragging:E,dragRef:k,handleMouseDown:W,handleTouchStart:G}=pt(e.controlPanelPosition,n=>x.setControlPanelPosition(n)),{position:B,isDragging:Y,dragRef:X,handleMouseDown:R,handleTouchStart:D}=pt(e.iframePosition,n=>x.setIframePosition(n)),[q,{isLoading:J}]=le({onSuccess:()=>{T(""),h(null)}}),[V,{isLoading:j}]=le({onSuccess:()=>{x.setHolding(!e.isHolding)},onError:n=>{console.log("error",n)}}),[ce,{isLoading:De}]=le({onSuccess:()=>{x.setMuted(!e.isMuted)},onError:n=>{console.log("error",n)}}),[$e,{isLoading:Le}]=le(),[qe,{isLoading:ze}]=le(),[Fe,{isLoading:Ie}]=le(),Ke=_n(n=>{let y=Math.floor(n/60),N=n%60;return`${y.toString().padStart(2,"0")}:${N.toString().padStart(2,"0")}`},[]),We=()=>{f(null)},Ge=n=>{p(!0),h(n.currentTarget),x.setStatus("dial")},je=()=>{e.status!=="on call"&&x.setStatus("idle"),h(null)},Re=n=>{C(n.currentTarget)},Ye=()=>{C(null)},Xe=()=>{let n={action:"READYAGENT",userId:e.agentId};$e(I.READY_AGENT,n)},_e=n=>{C(null);let y={action:"AGENTBREAK",break_type:n,userId:e.agentId};qe(I.UPDATE_AGENT_BREAK,y)},Je=n=>{if(n.length!==10)a("Invalid phone number","error");else if(!/^\d+$/.test(n))a("Invalid phone number","error");else{let y={action:"CALL",phone_number:n,userId:e.agentId};q(I.CLICK_TO_CALL,y)}},Ve=()=>{let n={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};V(I.HOLD_CALL,n)},ye=()=>{let n={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};ce(I.MUTE_CALL,n)},hs=n=>{var N,se,ne,de,fe,we,ke,Fo,Ko,Wo,Go,jo,Yo,Xo,Jo,Vo;console.log("data",n);let y={action:"ENDCALL",userId:e.agentId,processid:(ne=(se=(N=e.process)==null?void 0:N.process_id)==null?void 0:se.toString())!=null?ne:"",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=n==null?void 0:n.disposition)==null?void 0:Wo.value)!=null?Go:"",set_followUp:(Yo=(jo=n==null?void 0:n.followUp)==null?void 0:jo.value)!=null?Yo:"",callback_date:(Xo=n==null?void 0:n.callbackDate)!=null?Xo:"",callback_hrs:(Jo=n==null?void 0:n.callbackHrs)!=null?Jo:"",callback_mins:(Vo=n==null?void 0:n.callbackMins)!=null?Vo:"",endcall_type:"CLOSE"};T(""),Fe(I.END_CALL,y),x.endCall(),U(!1)};return He(()=>{let n=y=>{y.preventDefault()};return window.addEventListener("beforeunload",n),()=>{window.removeEventListener("beforeunload",n)}},[]),He(()=>{let n;return e.callData.status&&e.callData.status==="ONCALL"?n=setInterval(()=>{let y=Math.floor((Date.now()-e.callStartTime)/1e3);oe(y)},1e3):oe(0),()=>{n&&clearInterval(n)}},[e.callData.status]),He(()=>{if(t&&e.callData){let{process_id:n,process_name:y,status:N,phone_number:se,agent_id:ne,convox_id:de}=e.callData;t({phone_number:se,status:N,callReferenceId:de,agent_id:ne,process_id:n,process_name:y})}},[e.callData,t]),He(()=>{e.agentId?Z.post(I.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}).then(n=>{var y,N;console.log(n.data.data,"res4"),n&&n.data&&((y=n==null?void 0:n.data)==null?void 0:y.length)>1?(w(n.data.data),P(!0)):(x.setProcess((N=n==null?void 0:n.data)==null?void 0:N.data[0]),P(!1))}).catch(n=>{a(n.response.data.message,"error")}):console.log("No agentId available, skipping API call")},[e.agentId]),He(()=>(e.agentId&&(m.current=new WebSocket(`${Zo.WS}?agent_id=${e.agentId}`),m.current.onopen=()=>{console.log("WebSocket connection established")},m.current.onmessage=n=>{try{let y=JSON.parse(n.data),N=kn(e==null?void 0:e.conferenceLine,y==null?void 0:y.conferencestatus,y);console.log(N,"parsedJSON:",y),x.updateCallData(y),x.updateConferenceData([...N]),y.status==="ONCALL"&&(x.startCall(),A||p(!0)),y.status==="WRAPUP"&&x.endCall()}catch(y){console.log("Raw message:",n.data)}},m.current.onclose=()=>{console.log("WebSocket connection closed")},m.current.onerror=n=>{console.error("WebSocket error:",n)}),()=>{var n;(n=m.current)==null||n.close()}),[e.agentId]),!e.isInitialized||!e.process?d(re,{children:!!M&&d(ds,{processList:z,open:M,setOpen:P,handleSelectedProcessor:n=>{x.setProcess(n)}})}):ge(Nn,{children:[d(re,{children:d(gs,{in:!0,timeout:300,children:d(ms,{ref:(yt=e.sdkConfig)!=null&&yt.isDraggable?k: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(us,{})," "]}),d(re,{sx:{},children:!((Dt=e.sdkConfig)!=null&&Dt.disabledDialButton)&&d(he,{title:"Dial",children:d(at,{size:"small",onClick:n=>{var y,N,se,ne,de,fe,we,ke;((N=(y=e.callData)==null?void 0:y.status)==null?void 0:N.toUpperCase())!=="ONCALL"&&((ne=(se=e.callData)==null?void 0:se.status)==null?void 0:ne.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"&&Ge(n)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:d(Ln,{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(xs,{sx:{color:"success.main",width:"40px",marginRight:"10px",fontSize:"18px",fontWeight:"600"},children:Ke(ee)}),d(nt,{sx:{padding:"18px 0px"},label:ze||Le?d(re,{sx:{fontWeight:"bold",width:"60px",display:"flex",alignItems:"center",justifyContent:"center"},children:d(Be,{size:"20px"})}):d(xs,{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(mn,{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:n=>{var y,N,se,ne;(((N=(y=e.callData)==null?void 0:y.status)==null?void 0:N.toUpperCase())==="BREAK"||((ne=(se=e.callData)==null?void 0:se.status)==null?void 0:ne.toUpperCase())==="MISSED")&&(n.stopPropagation(),Xe())},classes:{root:((zt=(qt=e.callData)==null?void 0:qt.status)==null?void 0:zt.toUpperCase())==="BREAK"||((Kt=(Ft=e.callData)==null?void 0:Ft.status)==null?void 0:Kt.toUpperCase())==="MISSED"?"outlined":"enabled"},sx:l({},((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"?c:r),disabled:Le,children:d(Tn,{})})}),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:n=>{n.stopPropagation(),Ve()},sx:e.isHolding&&((Qt=(Vt=e.callData)==null?void 0:Vt.status)==null?void 0:Qt.toUpperCase())==="ONCALL"?l({},r):((eo=(Zt=e.callData)==null?void 0:Zt.status)==null?void 0:eo.toUpperCase())==="ONCALL"?l({},c):l({},i),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(En,{}):d(bn,{})})}),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:n=>{n.stopPropagation(),ye()},sx:e.isMuted&&((io=(ao=e.callData)==null?void 0:ao.status)==null?void 0:io.toUpperCase())==="ONCALL"?l({},r):((ro=(lo=e.callData)==null?void 0:lo.status)==null?void 0:ro.toUpperCase())==="ONCALL"?l({},c):l({},i),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(yn,{}):d(Cn,{})})}),!((uo=e.sdkConfig)!=null&&uo.disableCallTransferButton)&&d(he,{title:"Transfer Call",children:d(Se,{variant:e.openCallTransferDialog?"contained":"outlined",onClick:n=>{var y,N;((N=(y=e.callData)==null?void 0:y.status)==null?void 0:N.toUpperCase())==="ONCALL"&&(n.stopPropagation(),x.setOpenCallTransferDialog(!0))},sx:e.openCallTransferDialog?l({},r):((fo=(go=e.callData)==null?void 0:go.status)==null?void 0:fo.toUpperCase())==="ONCALL"?l({},c):l({},i),disabled:((xo=(mo=e.callData)==null?void 0:mo.status)==null?void 0:xo.toUpperCase())!=="ONCALL",children:d(Sn,{})})}),!((Co=e.sdkConfig)!=null&&Co.disableConferenceButton)&&d(he,{title:"Conference Call",children:d(Se,{variant:e.openConferenceDialog?"contained":"outlined",onClick:n=>{var y,N;((N=(y=e.callData)==null?void 0:y.status)==null?void 0:N.toUpperCase())==="ONCALL"&&(n.stopPropagation(),x.setOpenConferenceDialog(!0))},sx:e.openConferenceDialog?l({},r):((bo=(yo=e.callData)==null?void 0:yo.status)==null?void 0:bo.toUpperCase())==="ONCALL"?l({},c):l({},i),disabled:((vo=(ho=e.callData)==null?void 0:ho.status)==null?void 0:vo.toUpperCase())!=="ONCALL",children:d(fn,{})})}),!((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:n=>{var y,N,se,ne,de,fe;(((N=(y=e.callData)==null?void 0:y.status)==null?void 0:N.toUpperCase())==="ONCALL"||((ne=(se=e.callData)==null?void 0:se.status)==null?void 0:ne.toUpperCase())==="RINGING"||((fe=(de=e.callData)==null?void 0:de.status)==null?void 0:fe.toUpperCase())==="WRAPUP")&&(n.stopPropagation(),U(!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(l({},r),{borderRight:"1px",backgroundColor:"error.main",minWidth:"60px !important",boxShadow:" 0px 2px 1px #5f3f3f",border:`1px solid ${o.palette.error.light}`,height:"40px","&:hover":{bgcolor:"error.light",boxShadow:" 0px 2px 1px #5f3f3f",border:`0px solid ${o.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${o.palette.primary.light}`}}):F(l({},i),{minWidth:"60px !important"}),disabled:((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(un,{})})})]})]})})})}),d(gs,{in:!0,timeout:300,children:ge(ms,{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:A&&!((qo=e.sdkConfig)!=null&&qo.disableSoftPhone)?"visible":"hidden",userSelect:"none"},children:[ge(re,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll",padding:"0px 10px"},onMouseDown:R,onTouchStart:D,children:[d(us,{sx:{transform:"rotate(90deg)",color:"#7b7b7b"}})," ",d(at,{onClick:()=>p(!1),children:d(gn,{})})]}),d(re,{children:d("iframe",{src:`https://${Qe}/ConVoxCCS/iframe?agent_id=${e.agentId}&process_id=${(zo=e.process)==null?void 0:zo.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay",style:{border:"none"}})})]})}),d(gt,{anchorEl:g,open:!!g,onClose:je,onClick:n=>n.stopPropagation(),sx:{zIndex:99999},children:ge(re,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[d(In,{size:"small",value:v,placeholder:"Enter Mobile No.",onChange:n=>{T(n.target.value)}}),d(at,{color:"info",onClick:()=>{Je(v)},children:J?d(Be,{size:"20px",sx:{color:o.palette.success.main}}):d(vn,{color:"success"})})]})}),ge(gt,{anchorEl:u,open:!!u,onClose:Ye,onClick:n=>n.stopPropagation(),sx:{zIndex:99999},children:[d(fs,{onClick:()=>_e("Lunch"),children:"- Lunch"}),d(fs,{onClick:()=>_e("Tea"),children:"- Tea"})]}),d(gt,{anchorEl:b,open:!!b,onClose:We,onClick:n=>n.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(xn,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),d(nt,{icon:d(hn,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),d(nt,{icon:d(Dn,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!e.openConferenceDialog&&d(ls,{}),!!e.openCallTransferDialog&&d(rs,{open:e.openCallTransferDialog}),!!_&&d(cs,{open:_,setOpen:U,onSubmitDisposition:hs}),!!$&&d(ps,{open:$,setOpen:Q})]})}import{memo as An}from"react";import{jsx as Pn}from"react/jsx-runtime";var ft=An(({children:t})=>Pn(ss,{children:t}));ft.displayName="SDKProvider";import{jsx as ys}from"react/jsx-runtime";var bs=On(({onDataChange:t})=>{let o=Un(e=>{try{t&&typeof t=="function"&&t(e)}catch(a){console.error("Error in CallControlPanel data change handler:",a)}},[t]);return ys(ft,{children:ys(Cs,{onDataChange:o})})});bs.displayName="CallControlPanel";async function Li({apiKey:t,tenantId:o,agentId:e,sdkConfig:a}){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(),e.trim(),a);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(i){throw console.error("SDK initialization error:",i),x.setInitCheck(),i instanceof Error?i:new Error(`SDK initialization failed: ${String(i)}`)}}function Ii(){return"1.0.0"}function Ri(){return x.getState().isInitialized}export{bs as CallControlPanel,Ii as getSDKVersion,Li as initSDK,Ri as isSDKInitialized,Bs as useClickToCall,Us as useEndCall,Ps as useLogout};
1
+ var hs=Object.defineProperty,vs=Object.defineProperties;var Es=Object.getOwnPropertyDescriptors;var Qo=Object.getOwnPropertySymbols;var Ts=Object.prototype.hasOwnProperty,Ss=Object.prototype.propertyIsEnumerable;var it=(t,o,e)=>o in t?hs(t,o,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[o]=e,l=(t,o)=>{for(var e in o||(o={}))Ts.call(o,e)&&it(t,e,o[e]);if(Qo)for(var e of Qo(o))Ss.call(o,e)&&it(t,e,o[e]);return t},F=(t,o)=>vs(t,Es(o));var ie=(t,o,e)=>it(t,typeof o!="symbol"?o+"":o,e);var lt=class{constructor(){ie(this,"state");ie(this,"listeners",[]);ie(this,"STORAGE_KEY","call-control-sdk-state");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(l({},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())}initialize(o,e,a){if(!o||typeof o!="string"||o.trim().length===0)throw new Error("API key not available");this.state.agentId=e,this.state.openConferenceDialog=!1,this.state.openCallTransferDialog=!1,this.state.sdkConfig=l({disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},a),this.state.isInitialized=!0,this.saveToStorage(),this.notifyListeners()}getState(){return l({},this.state)}subscribe(o){return this.listeners.push(o),()=>{let e=this.listeners.indexOf(o);e>-1&&this.listeners.splice(e,1)}}setHolding(o){this.state.isHolding=o,this.saveToStorage(),this.notifyListeners()}setMuted(o){this.state.isMuted=o,this.saveToStorage(),this.notifyListeners()}setStatus(o){this.state.status=o,this.saveToStorage(),this.notifyListeners()}setProcess(o){this.state.process=o,this.saveToStorage(),this.notifyListeners()}setControlPanelPosition(o){this.state.controlPanelPosition=o,this.saveToStorage(),this.notifyListeners()}setIframePosition(o){this.state.iframePosition=o,this.saveToStorage(),this.notifyListeners()}startCall(){this.state.callStartTime=Date.now(),this.state.status="on call",this.saveToStorage(),this.notifyListeners()}endCall(){this.state.callStartTime=null,this.state.status="idle",this.state.isHolding=!1,this.state.isMuted=!1,this.saveToStorage(),this.notifyListeners()}setInitCheck(){this.state.isInitialized=!1,this.saveToStorage(),this.notifyListeners()}setOpenConferenceDialog(o){this.state.openConferenceDialog=o,this.saveToStorage(),this.notifyListeners()}setOpenCallTransferDialog(o){this.state.openCallTransferDialog=o,this.saveToStorage(),this.notifyListeners()}updateCallData(o){this.state.callData=l(l({},this.state.callData),o),this.saveToStorage(),this.notifyListeners()}updateConferenceData(o){this.state.conferenceLine=[...o],this.saveToStorage(),this.notifyListeners()}setConferenceLine(o){var a;(!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=(a=this.state.conferenceLine)==null?void 0:a.map(i=>i.line===o.line?o:i);this.state.conferenceLine=e,this.saveToStorage(),this.notifyListeners()}resetConferenceLines(){this.state.conferenceLine=this.getInitialState().conferenceLine,this.saveToStorage(),this.notifyListeners()}clearStorageAndReset(){try{localStorage.removeItem(this.STORAGE_KEY),this.state=this.getInitialState(),this.notifyListeners()}catch(o){console.warn("Failed to clear localStorage:",o)}}debugStorage(){try{let o=localStorage.getItem(this.STORAGE_KEY);console.log("Current localStorage data:",o),o&&console.log("Parsed localStorage data:",JSON.parse(o)),console.log("Current state:",this.state)}catch(o){console.error("Error debugging storage:",o)}}getConferenceLines(){return this.state.conferenceLine||[]}},x=new lt;var rt=class{constructor(){ie(this,"config",null);ie(this,"ticketId",null);ie(this,"baseUrl","");ie(this,"eventQueue",[]);ie(this,"isOnline",!0);ie(this,"retryQueue",[]);ie(this,"flushTimer",null)}async init(o){this.config=l({autoTrack:!0,retryAttempts:3,queueSize:100,flushInterval:5e3},o),this.baseUrl=o.baseUrl||(typeof window!="undefined"?window.location.origin:""),this.setupNetworkDetection();let e=await this.createTicket();return this.startPeriodicFlush(),console.log("EventTracker SDK initialized successfully"),e}isInitialized(){return this.config!==null&&this.ticketId!==null}getConfig(){return this.config}getTicketId(){return this.ticketId}async createTicket(){if(!this.config)throw new Error("EventTracker not initialized");try{let o=await this.makeRequest("/api/v1/et/init",{method:"POST",headers:{"Content-Type":"application/json","X-API-Key":this.config.apiKey},body:JSON.stringify({agentId:this.config.agentId,sessionId:this.config.sessionId})});if(!o.ok)throw 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 a={eventType:o,eventData:e,timestamp:Date.now()};if(this.eventQueue.push(a),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift(),this.isOnline)try{await this.sendEvent(a)}catch(i){console.warn("Failed to send event, will retry later:",i)}}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 a=this.eventQueue.findIndex(i=>i.timestamp===o.timestamp);a>-1&&this.eventQueue.splice(a,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 a of o)await this.sendEvent(a);let e=[...this.retryQueue];this.retryQueue=[];for(let a of e)try{await a()}catch(i){console.error("Retry failed:",i)}}async makeRequest(o,e){var r;let a=`${this.baseUrl}${o}`,i=((r=this.config)==null?void 0:r.retryAttempts)||3;for(let c=1;c<=i;c++)try{return await fetch(a,e)}catch(m){if(c===i)throw m;let b=Math.min(1e3*Math.pow(2,c-1),1e4);await new Promise(f=>setTimeout(f,b))}throw new Error("Max retries exceeded")}setupAutoTracking(){var a;if(typeof window=="undefined"||!((a=this.config)!=null&&a.autoTrack))return;let o=this.config.autoTrack===!0?{}:this.config.autoTrack;if(o.pageVisits!==!1&&this.logEvent("pageVisit",{url:window.location.href,title:document.title,referrer:document.referrer,userAgent:navigator.userAgent,viewport:{width:window.innerWidth,height:window.innerHeight},timestamp:new Date().toISOString()}).catch(i=>console.warn("Failed to track page visit:",i)),o.clicks!==!1&&document.addEventListener("click",i=>{var c;let r=i.target;(r.tagName==="BUTTON"||r.tagName==="A"||r.onclick||r.getAttribute("role")==="button"||r instanceof HTMLButtonElement&&r.type==="button")&&this.logEvent("click",{element:r.tagName,text:(c=r.textContent)==null?void 0:c.trim().substring(0,100),href:r.getAttribute("href"),id:r.id,className:r.className,role:r.getAttribute("role"),position:{x:i.clientX,y:i.clientY},timestamp:new Date().toISOString()}).catch(m=>console.warn("Failed to track click:",m))}),o.forms!==!1&&document.addEventListener("submit",i=>{let r=i.target,c=new FormData(r),m={};c.forEach((b,f)=>{m[f]=b.toString()}),this.logEvent("formSubmission",{formId:r.id,action:r.action,method:r.method,fields:Object.keys(m),fieldCount:Object.keys(m).length,timestamp:new Date().toISOString()}).catch(b=>console.warn("Failed to track form submission:",b))}),o.inputs!==!1){let i;document.addEventListener("input",r=>{let c=r.target;(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.tagName==="SELECT")&&(clearTimeout(i),i=setTimeout(()=>{var m;this.logEvent("fieldChange",{element:c.tagName,type:c.getAttribute("type"),name:c.getAttribute("name"),id:c.id,valueLength:((m=c.value)==null?void 0:m.length)||0,timestamp:new Date().toISOString()}).catch(b=>console.warn("Failed to track field change:",b))},1e3))})}let e=Date.now();window.addEventListener("beforeunload",()=>{let i=Date.now()-e;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:i,timestamp:new Date().toISOString()}),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",i=>{this.logEvent("jsError",{message:i.message,filename:i.filename,lineno:i.lineno,colno:i.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",i=>{var r;this.logEvent("unhandledRejection",{reason:(r=i.reason)==null?void 0:r.toString(),timestamp:new Date().toISOString()})})),o.performance!==!1&&typeof window.performance!="undefined"&&window.performance.navigation&&window.addEventListener("load",()=>{setTimeout(()=>{let i=window.performance.navigation,r=window.performance.timing;this.logEvent("performanceMetrics",{navigationTime:r.navigationStart,loadTime:r.loadEventEnd-r.navigationStart,domReady:r.domContentLoadedEventEnd-r.navigationStart,renderTime:r.loadEventEnd-r.domContentLoadedEventEnd,navigationType:i.type,redirectCount:i.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 Ns,useState as Ne}from"react";var Qe="10.10.102.42",H=`http://${Qe}:8095`,Ds=`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:`${Ds}${K.v1}/cti/ws`};import Ls from"axios";var Is="12345",_s=6e4;function Rs(){return Is}function ws(){let t=Ls.create({baseURL:H,headers:{"Content-Type":"application/json",Accept:"application/json"},timeout:_s,withCredentials:!1});return t.interceptors.request.use(o=>{let e=Rs();return e&&o.headers&&(o.headers.Authorization=`Bearer ${e}`),o.metadata={startTime:new Date().getTime()},o},o=>(console.error("Request interceptor error:",o),Promise.reject(o))),t.interceptors.response.use(o=>{var i;let e=new Date().getTime(),a=(i=o.config.metadata)==null?void 0:i.startTime;return a&&console.log(`Request to ${o.config.url} took ${e-a}ms`),o},async o=>{var a;let e=o.config;return((a=o.response)==null?void 0:a.status)===401&&!e._retry&&(e._retry=!0,console.warn("Unauthorized request, attempting retry...")),o.response||(console.error("Network error:",o.message),o.message="Network error: Please check your internet connection"),o.response&&o.response.status>=500&&(console.error("Server error:",o.response.status,o.response.data),o.message="Server error: Please try again later"),Promise.reject(o)}),t}var ks=ws(),Z=ks;var As=()=>{let[t,o]=Ne(!1),[e,a]=Ne(!1),[i,r]=Ne(!1),[c,m]=Ne(null),[b,f]=Ne(null);return{logout:Ns(async()=>{var C;let p=JSON.parse((C=localStorage.getItem("call-control-sdk-state"))!=null?C:"");o(!0);let u={action:"LOGOUTUSER",userId:p.agentId||""};return Z.post(I.LOGOUT,u).then(g=>(x.clearStorageAndReset(),localStorage.clear(),sessionStorage.clear(),f(g==null?void 0:g.data),a(!0),g==null?void 0:g.data)).catch(g=>{var h;return r(!0),m(g),(h=g==null?void 0:g.response)==null?void 0:h.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:c,data:b}};import{useCallback as Ps,useState as Ae}from"react";var Os=()=>{let[t,o]=Ae(!1),[e,a]=Ae(!1),[i,r]=Ae(!1),[c,m]=Ae(null),[b,f]=Ae(null);return{handleEndCall:Ps(async p=>{var g,h,R,O,M,A,$,Q,q,w,v,T,ee,oe,L;let u=JSON.parse((g=localStorage.getItem("call-control-sdk-state"))!=null?g:"");o(!0);let C={action:"ENDCALL",userId:u==null?void 0:u.agentId,processid:(O=(R=(h=u==null?void 0:u.process)==null?void 0:h.process_id)==null?void 0:R.toString())!=null?O:"",process_name:(A=(M=u==null?void 0:u.process)==null?void 0:M.process_name)!=null?A:"",callreferenceid:(Q=($=u==null?void 0:u.callData)==null?void 0:$.convox_id)!=null?Q:"",mobile_number:(w=(q=u==null?void 0:u.callData)==null?void 0:q.phone_number)!=null?w:"",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,C).then(E=>(x.endCall(),f(E==null?void 0:E.data),a(!0),E==null?void 0:E.data)).catch(E=>{var k;return r(!0),m(E),(k=E==null?void 0:E.response)==null?void 0:k.data}).finally(()=>{o(!1)})},[]),isLoading:t,isSuccess:e,isError:i,error:c,data:b}};import{useCallback as Us,useState as Pe}from"react";var Ms=()=>{let[t,o]=Pe(!1),[e,a]=Pe(!1),[i,r]=Pe(!1),[c,m]=Pe(null),[b,f]=Pe(null);return{handleStartCall:Us(async p=>{var C,g,h,R,O,M,A,$,Q;let u=JSON.parse((C=localStorage.getItem("call-control-sdk-state"))!=null?C:"");if(o(!0),((g=u==null?void 0:u.callData)==null?void 0:g.status)==="IDLE"){let q={action:"CALL",userId:u==null?void 0:u.agentId,phone_number:p==null?void 0:p.mobileNumber};return Z.post(I.CLICK_TO_CALL,q).then(w=>(f(w==null?void 0:w.data),a(!0),w==null?void 0:w.data)).catch(w=>{var v;return r(!0),m(w),(v=w==null?void 0:w.response)==null?void 0:v.data}).finally(()=>{o(!1)})}else if(((h=u==null?void 0:u.callData)==null?void 0:h.status)==="ONCALL"){let q=(O=(R=u==null?void 0:u.conferenceLine)==null?void 0:R.filter(v=>v.line!==1))==null?void 0:O.find(v=>v.status==="IDLE"&&!(v!=null&&v.isCallStart)),w={action:"EXTERNAL_CONFERENCE",operation:`CALL${q.line}`,line_used:String(q.line),thirdparty_no:p==null?void 0:p.mobileNumber,userid:(A=(M=u.callData)==null?void 0:M.agent_id)!=null?A:"",process:(Q=($=u.callData)==null?void 0:$.process_name)!=null?Q:""};return Z.post(I.CONFERENCE_CALL,w).then(v=>(f(v==null?void 0:v.data),a(!0),x.setConferenceLine(F(l({},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 r(!0),m(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:i,error:c,data:b}};import{memo as On,useCallback as Un}from"react";import{CallEnd as pn,Close as un,DragIndicator as us,Group as gn,KeyboardArrowDown as fn,Layers as mn,Mic as xn,MicOff as Cn,Pause as yn,Pending as bn,Phone as hn,PlayArrow as vn,SupportAgent as En,TransferWithinAStation as Tn,Upcoming as Sn,WifiCalling3 as Dn}from"@mui/icons-material";import{Box as re,Button as Se,Chip as nt,CircularProgress as Be,Fade as gs,IconButton as at,Menu as gt,MenuItem as fs,Paper as ms,TextField as Ln,Tooltip as he,Typography as xs,useTheme as In}from"@mui/material";import{useCallback as _n,useEffect as He,useRef as Rn,useState as ue}from"react";import{useCallback as Ze,useRef as dt,useState as es}from"react";function pt(t,o){let[e,a]=es(t),[i,r]=es(!1),c=dt(),m=dt({x:0,y:0}),b=dt({x:0,y:0}),f=Ze(C=>{let g=c.current;if(!g)return;let h=g.getBoundingClientRect(),R=window.innerWidth,O=window.innerHeight,M={x:Math.max(0,Math.min(C.x,R-h.width)),y:Math.max(0,Math.min(C.y,O-h.height))};a(M),o==null||o(M)},[o]),N=Ze((C,g)=>{r(!0),m.current={x:C,y:g},b.current=e;let h=(A,$)=>{let Q=A-m.current.x,q=$-m.current.y;f({x:b.current.x+Q,y:b.current.y+q})},R=A=>{A.preventDefault(),h(A.clientX,A.clientY)},O=A=>{A.preventDefault();let $=A.touches[0];$&&h($.clientX,$.clientY)},M=()=>{r(!1),document.removeEventListener("mousemove",R),document.removeEventListener("mouseup",M),document.removeEventListener("touchmove",O),document.removeEventListener("touchend",M)};document.addEventListener("mousemove",R),document.addEventListener("mouseup",M),document.addEventListener("touchmove",O,{passive:!1}),document.addEventListener("touchend",M)},[e,f]),p=Ze(C=>{C.preventDefault(),N(C.clientX,C.clientY)},[N]),u=Ze(C=>{C.preventDefault();let g=C.touches[0];g&&N(g.clientX,g.clientY)},[N]);return{position:e,isDragging:i,dragRef:c,handleMouseDown:p,handleTouchStart:u}}import{useState as Bs,useEffect as Hs}from"react";function ve(){let[t,o]=Bs(x.getState());return Hs(()=>x.subscribe(()=>{o(x.getState())}),[]),t}import{useCallback as Ws,useReducer as Gs}from"react";import{createContext as $s,useContext as zs,useState as ut}from"react";import{Snackbar as qs,Alert as Fs}from"@mui/material";import{jsx as ts,jsxs as Ks}from"react/jsx-runtime";var os=$s(void 0),be=()=>{let t=zs(os);if(!t)throw new Error("useToast must be used inside ToastProvider");return t},ss=({children:t})=>{let[o,e]=ut(!1),[a,i]=ut(""),[r,c]=ut("info"),m=(b,f="info")=>{i(b),c(f),e(!0)};return Ks(os.Provider,{value:{showToast:m},children:[t,ts(qs,{open:o,color:r,autoHideDuration:3e3,onClose:()=>e(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:ts(Fs,{variant:"filled",severity:r,onClose:()=>e(!1),sx:{width:"100%"},children:a})})]})};var js={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},Ys=(t,o)=>{if(o.type==="isLoading")return F(l({},t),{isLoading:o.payload});if(o.type==="isSuccess")return F(l({},t),{isSuccess:!0,data:o.payload});if(o.type==="isError")return F(l({},t),{isError:!0,error:o.payload});if(o.type==="reset")return{isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null};throw Error("Unknown action.")};var le=(t={})=>{let{onSuccess:o=null,onError:e=null,disabledSuccessToast:a=!1}=t,{showToast:i}=be(),[r,c]=Gs(Ys,js);return[Ws((b,f,N={})=>{c({type:"isLoading",payload:!0}),Z.post(b,f,N).then(p=>{var u,C;c({type:"isSuccess",payload:p.data}),o==null||o(p.data,f),console.log((u=p.data)==null?void 0:u.message,"res45"),a||i((C=p.data)==null?void 0:C.message,"success")}).catch(p=>{var C,g,h,R,O,M,A,$,Q,q,w,v;let u={status:(g=(C=p.response)==null?void 0:C.status)!=null?g:500,message:((R=(h=p.response)==null?void 0:h.data)==null?void 0:R.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:(w=p==null?void 0:p.code)!=null?w:"",name:(v=p==null?void 0:p.name)!=null?v:""};i(u.message,"error"),c({type:"isError",payload:u}),e==null||e(u,f)}).finally(()=>{c({type:"isLoading",payload:!1})})},[o,e,i]),r]};import{Call as tt,CallEnd as ns,CallSplit as Vs,Close as st,Mic as Qs,MicOff as Zs,Pause as en,PhoneDisabled as tn,PlayArrow as on,SupportAgent as ot}from"@mui/icons-material";import{Box as P,Button as ae,Dialog as Ue,IconButton as Ce,Paper as Te,TextField as Ee,Typography as te,Autocomplete as as,Tooltip as Oe,useTheme as sn,TableContainer as nn,Table as an,TableHead as ln,TableRow as is,TableCell as pe,TableBody as rn,CircularProgress as me}from"@mui/material";import{useEffect as cn,useState as xe}from"react";import{useTheme as Xs}from"@mui/material";var Js=({disabled:t,enabled:o,outlined:e})=>{let a=Xs();return{disabled:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",border:"1px solid rgb(206, 204, 204)",height:"40px","&:hover":{boxShadow:" 0px 2px 2px rgba(0, 0, 0, 0.79)",border:`1px solid ${a.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${a.palette.primary.light}`}},t),enabled:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${a.palette.primary.main}`,height:"40px","&:hover":{boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${a.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${a.palette.primary.light}`}},o),outlined:l({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",backgroundColor:a.palette.grey[200],boxShadow:`0px 2px 1px ${a.palette.primary.light}`,border:`0px solid ${a.palette.primary.main}`,height:"40px","&:hover":{boxShadow:`0px 2px 1px ${a.palette.primary.main}`,border:`0px solid ${a.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${a.palette.primary.light}`}},e)}},et=Js;import{Fragment as Me,jsx as s,jsxs as S}from"react/jsx-runtime";var dn=({each:t})=>{var w,v,T,ee,oe;let o=ve(),{showToast:e}=be(),{disabled:a,enabled:i,outlined:r}=et({disabled:((w=o.sdkConfig)==null?void 0:w.disabled)||{},enabled:((v=o.sdkConfig)==null?void 0:v.enabled)||{},outlined:((T=o.sdkConfig)==null?void 0:T.outlined)||{}}),c=sn(),[m,b]=xe(!1),[f,N]=xe(!1),[p,u]=xe(!1),[C,g]=xe(!1),[h,R]=xe(!1),O=(L,E)=>{x.setConferenceLine(l(l({},L),E))},M=(L,E)=>{var G,B,Y,X;let k=l(l({},L),E);b(!0);let W={action:"EXTERNAL_CONFERENCE",operation:`CALL${k.line}`,line_used:String(k.line),thirdparty_no:k.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(l(l({},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(()=>{b(!1)})},A=(L,E)=>{var G,B,Y,X;let k=l(l({},L),E);N(!0);let W={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(k.line),thirdparty_no:k.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(l(l({},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(()=>{N(!1)})},$=(L,E,k)=>{var B,Y,X,_;let W=l(l({},L),E);u(!0);let G={action:"EXTERNAL_CONFERENCE",operation:k,hold_channel_no:k==="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(l(l({},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(()=>{u(!1)})},Q=(L,E,k)=>{var B,Y,X,_;let W=l(l({},L),E);g(!0);let G={action:"EXTERNAL_CONFERENCE",operation:k,channel_no:k==="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(l(l({},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(()=>{g(!1)})},q=(L,E)=>{var G,B,Y,X;let k=l(l({},L),E);R(!0);let W={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(k.line-1),user_type:`THIRDPARTY${k.line-1}`,thirdparty_no:k.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(l(l({},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)})};return S(is,{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(ae,{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)==="LINE USED",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(ae,{variant:(t==null?void 0:t.status)!=="IDLE"?"outlined":"contained",color:"success",sx:(t==null?void 0:t.status)!=="IDLE"?l({},a):F(l({},i),{border:`0px solid ${c.palette.success.light}`,"&:hover":{bgcolor:"success.light",boxShadow:`0px 2px 1px ${c.palette.success.light}`,border:`0px solid ${c.palette.success.light}`},"&:active":{bgcolor:"success.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}),onClick:()=>{M(t,{})},disabled:(t==null?void 0:t.status)!=="IDLE",children:m?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(ae,{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(l({},a),{padding:"0px 16px"}):(t==null?void 0:t.status)==="ONCALL"?F(l({},r),{padding:"0px 16px"}):F(l({},a),{padding:"0px 16px"}),onClick:()=>{A(t,{isMergeCall:!0})},disabled:(t==null?void 0:t.status)!=="ONCALL"||f,children:[t!=null&&t.isMergeCall?"Merged":"Merge",f?s(me,{size:"20px"}):s(Vs,{})]})}),s(Oe,{title:t.isHold?"Hold":"Un Hold",children:s(ae,{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"?l({},a):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},r):l({},a),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:c.palette.primary.main}}):t.isHold?s(on,{}):s(en,{})})}),s(Oe,{title:t.isMute?"Mute":"Un Mute",children:s(ae,{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"?l({},a):(t==null?void 0:t.status)==="ONCALL"||(t==null?void 0:t.status)==="CONFERENCE"?l({},r):l({},a),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"||C,children:C?s(me,{size:"20px",sx:{color:c.palette.primary.main}}):t.isMute?s(Zs,{}):s(Qs,{})})}),(t==null?void 0:t.line)!==1?s(Oe,{title:"End Call",children:s(ae,{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(l({},i),{border:`0px solid ${c.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${c.palette.error.light}`,border:`0px solid ${c.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}):l({},a),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(ns,{})})}):s(ae,{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(ns,{})})]})})]},t.line)};function ls(){var c;let t=ve(),{showToast:o}=be(),[e,a]=xe(!1),i=()=>{x.setOpenConferenceDialog(!1)},r=()=>{var b,f,N,p;a(!0);let m={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(f=(b=t.callData)==null?void 0:b.agent_id)!=null?f:"",process:(p=(N=t.callData)==null?void 0:N.process_name)!=null?p:""};Z.post(I.CONFERENCE_CALL_END_ALL,m).then(u=>{var C;o((C=u.data)==null?void 0:C.message,"success"),x.resetConferenceLines(),i()}).catch(u=>{var g,h,R,O;let C=((h=(g=u.response)==null?void 0:g.data)==null?void 0:h.detail)||((O=(R=u.response)==null?void 0:R.data)==null?void 0:O.message)||u.message||"An unknown error occurred";o(C,"error")}).finally(()=>{a(!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:[(c=t==null?void 0:t.agentId)!=null?c:""," conference"]}),s(Ce,{onClick:i,children:s(st,{})})]}),s(P,{sx:{boxShadow:"1px 1px 2px #e7e5e5ff",margin:"0px 15px",borderRadius:"20px"},children:s(nn,{component:Te,sx:{outline:"0px solid gray !important",boxShadow:"1px 1px 6px #e7e5e5ff"},children:S(an,{sx:{border:"4px solid #ffffff !important"},children:[s(ln,{children:S(is,{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(rn,{children:t==null?void 0:t.conferenceLine.map(m=>s(dn,{each:m}))})]})})}),s(P,{textAlign:"center",m:2,children:S(ae,{variant:"outlined",color:"error",size:"large",onClick:r,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(tn,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function rs({open:t}){var C,g,h,R,O,M,A,$,Q,q,w,v;let o=ve(),[e]=le({onSuccess:()=>{x.setOpenCallTransferDialog(!1)}}),[a,i]=xe("process"),[r,{data:c,isLoading:m}]=le({disabledSuccessToast:!0}),[b,{data:f,isLoading:N}]=le({disabledSuccessToast:!0}),p=()=>{x.setOpenCallTransferDialog(!1)},u=(T,ee)=>{var oe,L,E,k,W,G,B,Y,X,_,D,z,J,V,j,ce,De,$e,Le,ze,qe,Fe,Ie,Ke,We,Ge,_e,je,Ye,Re,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:(k=(E=o.callData)==null?void 0:E.agent_id)!=null?k:"",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:(_e=T==null?void 0:T.user_id)!=null?_e:"",callreferenceid:(Ye=(je=o.callData)==null?void 0:je.convox_id)!=null?Ye:"",processid:String((Xe=(Re=o.callData)==null?void 0:Re.process_id)!=null?Xe:""),process_name:(Ve=(Je=o.callData)==null?void 0:Je.process_name)!=null?Ve:""};e(I.TRANSFER_CALL,ye)}};return cn(()=>{r(I.AGENTS_LIST,{status:"IDLE",active:!0}),b(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(ae,{variant:a==="process"?"contained":"outlined",onClick:()=>{i("process"),b(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Process"}),s(ae,{variant:a==="queues"?"contained":"outlined",onClick:()=>{i("queues"),b(I.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Queues"}),s(ae,{variant:a==="agents"?"contained":"outlined",onClick:()=>{i("agents"),r(I.AGENTS_LIST,{status:"IDLE",active:!0})},children:"Agents"})]}),(N||m)&&S(P,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"80px"},children:[s(me,{})," "]}),!N&&!m&&a==="process"&&s(P,{sx:{display:"flex",gap:1},children:(C=f==null?void 0:f.data)!=null&&C.process&&((h=(g=f==null?void 0:f.data)==null?void 0:g.process)==null?void 0:h.length)>0?(O=(R=f==null?void 0:f.data)==null?void 0:R.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:()=>{u(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"})}),!N&&!m&&a==="queues"&&s(P,{sx:{display:"flex",gap:1},children:(M=f==null?void 0:f.data)!=null&&M.queue&&(($=(A=f==null?void 0:f.data)==null?void 0:A.queue)==null?void 0:$.length)>0?(q=(Q=f==null?void 0:f.data)==null?void 0:Q.queue)==null?void 0:q.map((T,ee)=>{var oe,L,E,k,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=f==null?void 0:f.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=(k=f==null?void 0:f.data)==null?void 0:k.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:()=>{u(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"})}),!N&&!m&&a==="agents"&&s(P,{sx:{display:"flex",gap:1},children:c!=null&&c.data&&((w=c==null?void 0:c.data)==null?void 0:w.length)>0?(v=c==null?void 0:c.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:()=>{u(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 cs({open:t,setOpen:o,onSubmitDisposition:e}){var N,p,u,C;let[a,i]=xe({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),r=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],c=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],m=(g,h)=>{i(R=>F(l({},R),{[g]:h}))},b=()=>{i({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},f=()=>{b(),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(as,{value:a.disposition,options:r,getOptionLabel:g=>g.label,onChange:(g,h)=>m("disposition",h),size:"small",renderInput:g=>s(Ee,F(l({},g),{label:"Disposition",fullWidth:!0})),sx:{flex:1}}),s(as,{options:c,getOptionLabel:g=>g.label,value:a.followUp,onChange:(g,h)=>m("followUp",h),size:"small",renderInput:g=>s(Ee,F(l({},g),{label:"Follow Up",fullWidth:!0})),sx:{flex:1}})]}),((p=(N=a==null?void 0:a.followUp)==null?void 0:N.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:a.callbackDate,onChange:g=>m("callbackDate",g.target.value),fullWidth:!0,sx:{flex:1}}),s(Ee,{size:"small",label:"Hours (0-23)",type:"text",value:a.callbackHrs,onChange:g=>m("callbackHrs",g.target.value),fullWidth:!0,sx:{flex:1}})]}),((C=(u=a==null?void 0:a.followUp)==null?void 0:u.label)==null?void 0:C.toLowerCase())==="yes"&&S(P,{display:"flex",gap:2,mt:2,children:[s(Ee,{size:"small",label:"Minutes (0-59)",type:"text",value:a.callbackMins,onChange:g=>m("callbackMins",g.target.value),fullWidth:!0,sx:{flex:1}}),s(P,{sx:{flex:1}})]})]}),S(P,{textAlign:"right",m:2,children:[s(ae,{variant:"outlined",color:"error",size:"large",onClick:f,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),s(ae,{variant:"contained",color:"primary",size:"large",onClick:()=>e(a),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function ds({open:t,setOpen:o,processList:e=null,handleSelectedProcessor:a}){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((r,c)=>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:()=>{a(r)},children:S(te,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[s(ot,{sx:{marginRight:"4px"}}),r.process_name]})},c)):null})]})})})}function ps({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 Nn,jsx as d,jsxs as ge}from"react/jsx-runtime";var wn=(t,o,e)=>t.map(i=>{var r,c,m;if((i==null?void 0:i.line)===1)return{line:1,status:(r=e==null?void 0:e.status)!=null?r:"",type:"internal",phone:(c=e==null?void 0:e.phone_number)!=null?c:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};{let b=`line_${i.line}_status`,f=`line_${i.line}_phonenumber`;return F(l({},i),{status:(m=o[b])!=null?m:"IDLE",phone:o[f]!=="0"?o[f]:""})}}),kn=_n(t=>{let o=Math.floor(t/60),e=t%60;return`${o.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`},[]);function Cs({onDataChange:t}){var mt,xt,Ct,yt,bt,ht,vt,Et,Tt,St,Dt,Lt,It,_t,Rt,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,_o,Ro,wo,ko,No,Ao,Po,Oo,Uo,Mo,Bo,Ho,$o,zo,qo;let o=In(),e=ve(),{showToast:a}=be(),{disabled:i,enabled:r,outlined:c}=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)||{}}),m=Rn(null),[b,f]=ue(null),[N,p]=ue(!0),[u,C]=ue(null),[g,h]=ue(null),[R,O]=ue(!1),[M,A]=ue(!1),[$,Q]=ue(!1),[q,w]=ue(null),[v,T]=ue(""),[ee,oe]=ue(0),{position:L,isDragging:E,dragRef:k,handleMouseDown:W,handleTouchStart:G}=pt(e.controlPanelPosition,n=>x.setControlPanelPosition(n)),{position:B,isDragging:Y,dragRef:X,handleMouseDown:_,handleTouchStart:D}=pt(e.iframePosition,n=>x.setIframePosition(n)),[z,{isLoading:J}]=le({onSuccess:()=>{T(""),h(null)}}),[V,{isLoading:j}]=le({onSuccess:()=>{x.setHolding(!e.isHolding)},onError:n=>{console.log("\u274C Hold operation error:",n)}}),[ce,{isLoading:De}]=le({onSuccess:()=>{x.setMuted(!e.isMuted)},onError:n=>{console.log("\u274C Mute operation error:",n)}}),[$e,{isLoading:Le}]=le(),[ze,{isLoading:qe}]=le(),[Fe,{isLoading:Ie}]=le(),Ke=()=>{f(null)},We=n=>{p(!0),h(n.currentTarget),x.setStatus("dial")},Ge=()=>{e.status!=="on call"&&x.setStatus("idle"),h(null)},_e=n=>{C(n.currentTarget)},je=()=>{C(null)},Ye=()=>{let n={action:"READYAGENT",userId:e.agentId};$e(I.READY_AGENT,n)},Re=n=>{C(null);let y={action:"AGENTBREAK",break_type:n,userId:e.agentId};ze(I.UPDATE_AGENT_BREAK,y)},Xe=n=>{if(n.length!==10)a("Invalid phone number","error");else if(!/^\d+$/.test(n))a("Invalid phone number","error");else{let y={action:"CALL",phone_number:n,userId:e.agentId};z(I.CLICK_TO_CALL,y)}},Je=()=>{let n={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};V(I.HOLD_CALL,n)},Ve=()=>{let n={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};ce(I.MUTE_CALL,n)},ye=n=>{var U,se,ne,de,fe,we,ke,Fo,Ko,Wo,Go,jo,Yo,Xo,Jo,Vo;console.log("data",n);let y={action:"ENDCALL",userId:e.agentId,processid:(ne=(se=(U=e.process)==null?void 0:U.process_id)==null?void 0:se.toString())!=null?ne:"",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=n==null?void 0:n.disposition)==null?void 0:Wo.value)!=null?Go:"",set_followUp:(Yo=(jo=n==null?void 0:n.followUp)==null?void 0:jo.value)!=null?Yo:"",callback_date:(Xo=n==null?void 0:n.callbackDate)!=null?Xo:"",callback_hrs:(Jo=n==null?void 0:n.callbackHrs)!=null?Jo:"",callback_mins:(Vo=n==null?void 0:n.callbackMins)!=null?Vo:"",endcall_type:"CLOSE"};T(""),Fe(I.END_CALL,y),x.endCall(),O(!1)};return He(()=>{let n=y=>{y.preventDefault()};return window.addEventListener("beforeunload",n),()=>{window.removeEventListener("beforeunload",n)}},[]),He(()=>{let n;return e.callData.status&&e.callData.status==="ONCALL"?n=setInterval(()=>{let y=Math.floor((Date.now()-e.callStartTime)/1e3);oe(y)},1e3):oe(0),()=>{n&&clearInterval(n)}},[e.callData.status]),He(()=>{if(t&&e.callData){let{process_id:n,process_name:y,status:U,phone_number:se,agent_id:ne,convox_id:de}=e.callData;t({phone_number:se,status:U,callReferenceId:de,agent_id:ne,process_id:n,process_name:y})}},[e.callData,t]),He(()=>{e.agentId?Z.post(I.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}).then(n=>{var y,U;console.log(n.data.data,"res4"),n&&n.data&&((y=n==null?void 0:n.data)==null?void 0:y.length)>1?(w(n.data.data),A(!0)):(x.setProcess((U=n==null?void 0:n.data)==null?void 0:U.data[0]),A(!1))}).catch(n=>{a(n.response.data.message,"error")}):console.log("No agentId available, skipping API call")},[e.agentId]),He(()=>(e.agentId&&(m.current=new WebSocket(`${Zo.WS}?agent_id=${e.agentId}`),m.current.onopen=()=>{console.log("\u{1F310} WebSocket connection established")},m.current.onmessage=n=>{try{let y=JSON.parse(n.data),U=wn(e==null?void 0:e.conferenceLine,y==null?void 0:y.conferencestatus,y);console.log(U,"\u{1F4CA} Parsed JSON:",y),x.updateCallData(y),x.updateConferenceData([...U]),y.status==="ONCALL"&&(x.startCall(),N||p(!0)),y.status==="WRAPUP"&&x.endCall()}catch(y){console.log("\u{1F4E8} Raw message:",n.data)}},m.current.onclose=()=>{console.log("\u{1F50C} WebSocket connection closed")},m.current.onerror=n=>{console.error("\u274C WebSocket error:",n)}),()=>{var n;(n=m.current)==null||n.close()}),[e.agentId]),!e.isInitialized||!e.process?d(re,{children:!!M&&d(ds,{processList:q,open:M,setOpen:A,handleSelectedProcessor:n=>{x.setProcess(n)}})}):ge(Nn,{children:[d(re,{children:d(gs,{in:!0,timeout:300,children:d(ms,{ref:(yt=e.sdkConfig)!=null&&yt.isDraggable?k: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(us,{})," "]}),d(re,{children:!((Dt=e.sdkConfig)!=null&&Dt.disabledDialButton)&&d(he,{title:"Dial",children:d(at,{size:"small",onClick:n=>{var y,U,se,ne,de,fe,we,ke;((U=(y=e.callData)==null?void 0:y.status)==null?void 0:U.toUpperCase())!=="ONCALL"&&((ne=(se=e.callData)==null?void 0:se.status)==null?void 0:ne.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(n)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:d(Dn,{sx:{color:((It=(Lt=e.callData)==null?void 0:Lt.status)==null?void 0:It.toUpperCase())==="ONCALL"||((Rt=(_t=e.callData)==null?void 0:_t.status)==null?void 0:Rt.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(xs,{sx:{color:"success.main",width:"40px",marginRight:"10px",fontSize:"18px",fontWeight:"600"},children:kn(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(xs,{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:_e,deleteIcon:d(fn,{color:"primary"}),onDelete:_e})]}),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:n=>{var y,U,se,ne;(((U=(y=e.callData)==null?void 0:y.status)==null?void 0:U.toUpperCase())==="BREAK"||((ne=(se=e.callData)==null?void 0:se.status)==null?void 0:ne.toUpperCase())==="MISSED")&&(n.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:l({},((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"?c:r),disabled:Le,children:d(En,{})})}),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:n=>{n.stopPropagation(),Je()},sx:e.isHolding&&((Qt=(Vt=e.callData)==null?void 0:Vt.status)==null?void 0:Qt.toUpperCase())==="ONCALL"?l({},r):((eo=(Zt=e.callData)==null?void 0:Zt.status)==null?void 0:eo.toUpperCase())==="ONCALL"?l({},c):l({},i),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(vn,{}):d(yn,{})})}),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:n=>{n.stopPropagation(),Ve()},sx:e.isMuted&&((io=(ao=e.callData)==null?void 0:ao.status)==null?void 0:io.toUpperCase())==="ONCALL"?l({},r):((ro=(lo=e.callData)==null?void 0:lo.status)==null?void 0:ro.toUpperCase())==="ONCALL"?l({},c):l({},i),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(Cn,{}):d(xn,{})})}),!((uo=e.sdkConfig)!=null&&uo.disableCallTransferButton)&&d(he,{title:"Transfer Call",children:d(Se,{variant:e.openCallTransferDialog?"contained":"outlined",onClick:n=>{var y,U;((U=(y=e.callData)==null?void 0:y.status)==null?void 0:U.toUpperCase())==="ONCALL"&&(n.stopPropagation(),x.setOpenCallTransferDialog(!0))},sx:e.openCallTransferDialog?l({},r):((fo=(go=e.callData)==null?void 0:go.status)==null?void 0:fo.toUpperCase())==="ONCALL"?l({},c):l({},i),disabled:((xo=(mo=e.callData)==null?void 0:mo.status)==null?void 0:xo.toUpperCase())!=="ONCALL",children:d(Tn,{})})}),!((Co=e.sdkConfig)!=null&&Co.disableConferenceButton)&&d(he,{title:"Conference Call",children:d(Se,{variant:e.openConferenceDialog?"contained":"outlined",onClick:n=>{var y,U;((U=(y=e.callData)==null?void 0:y.status)==null?void 0:U.toUpperCase())==="ONCALL"&&(n.stopPropagation(),x.setOpenConferenceDialog(!0))},sx:e.openConferenceDialog?l({},r):((bo=(yo=e.callData)==null?void 0:yo.status)==null?void 0:bo.toUpperCase())==="ONCALL"?l({},c):l({},i),disabled:((vo=(ho=e.callData)==null?void 0:ho.status)==null?void 0:vo.toUpperCase())!=="ONCALL",children:d(gn,{})})}),!((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"||((_o=(Io=e.callData)==null?void 0:Io.status)==null?void 0:_o.toUpperCase())==="WRAPUP"?"contained":"outlined",onClick:n=>{var y,U,se,ne,de,fe;(((U=(y=e.callData)==null?void 0:y.status)==null?void 0:U.toUpperCase())==="ONCALL"||((ne=(se=e.callData)==null?void 0:se.status)==null?void 0:ne.toUpperCase())==="RINGING"||((fe=(de=e.callData)==null?void 0:de.status)==null?void 0:fe.toUpperCase())==="WRAPUP")&&(n.stopPropagation(),O(!0))},sx:((wo=(Ro=e.callData)==null?void 0:Ro.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(l({},r),{borderRight:"1px",backgroundColor:"error.main",minWidth:"60px !important",boxShadow:" 0px 2px 1px #5f3f3f",border:`1px solid ${o.palette.error.light}`,height:"40px","&:hover":{bgcolor:"error.light",boxShadow:" 0px 2px 1px #5f3f3f",border:`0px solid ${o.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${o.palette.primary.light}`}}):F(l({},i),{minWidth:"60px !important"}),disabled:((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(pn,{})})})]})]})})})}),d(gs,{in:!0,timeout:300,children:ge(ms,{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:N&&!((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(us,{sx:{transform:"rotate(90deg)",color:"#7b7b7b"}})," ",d(at,{onClick:()=>p(!1),children:d(un,{})})]}),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:g,open:!!g,onClose:Ge,onClick:n=>n.stopPropagation(),sx:{zIndex:99999},children:ge(re,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[d(Ln,{size:"small",value:v,placeholder:"Enter Mobile No.",onChange:n=>{T(n.target.value)}}),d(at,{color:"info",onClick:()=>{Xe(v)},children:J?d(Be,{size:"20px",sx:{color:o.palette.success.main}}):d(hn,{color:"success"})})]})}),ge(gt,{anchorEl:u,open:!!u,onClose:je,onClick:n=>n.stopPropagation(),sx:{zIndex:99999},children:[d(fs,{onClick:()=>Re("Lunch"),children:"- Lunch"}),d(fs,{onClick:()=>Re("Tea"),children:"- Tea"})]}),d(gt,{anchorEl:b,open:!!b,onClose:Ke,onClick:n=>n.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(mn,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),d(nt,{icon:d(bn,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),d(nt,{icon:d(Sn,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!e.openConferenceDialog&&d(ls,{}),!!e.openCallTransferDialog&&d(rs,{open:e.openCallTransferDialog}),!!R&&d(cs,{open:R,setOpen:O,onSubmitDisposition:ye}),!!$&&d(ps,{open:$,setOpen:Q})]})}import{memo as An}from"react";import{jsx as Pn}from"react/jsx-runtime";var ft=An(({children:t})=>Pn(ss,{children:t}));ft.displayName="SDKProvider";import{jsx as ys}from"react/jsx-runtime";var bs=On(({onDataChange:t})=>{let o=Un(e=>{try{t&&typeof t=="function"&&t(e)}catch(a){console.error("Error in CallControlPanel data change handler:",a)}},[t]);return ys(ft,{children:ys(Cs,{onDataChange:o})})});bs.displayName="CallControlPanel";async function Di({apiKey:t,tenantId:o,agentId:e,sdkConfig:a}){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(),e.trim(),a);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(i){throw console.error("SDK initialization error:",i),x.setInitCheck(),i instanceof Error?i:new Error(`SDK initialization failed: ${String(i)}`)}}function Li(){return"5.4.8"}function Ii(){return x.getState().isInitialized}export{bs as CallControlPanel,Li as getSDKVersion,Di as initSDK,Ii as isSDKInitialized,Ms as useClickToCall,Os as useEndCall,As as useLogout};
2
+ /**
3
+ * =============================================================================
4
+ * πŸ“‹ FILE SUMMARY & COMPONENT OVERVIEW
5
+ * =============================================================================
6
+ *
7
+ * 🎯 This CallControls component is a comprehensive telephony interface that provides:
8
+ *
9
+ * πŸ“ž **Core Functionality**:
10
+ * - πŸ“± Complete call control operations (dial, hold, mute, transfer, conference, end)
11
+ * - ⏸️ Hold/resume functionality with visual feedback
12
+ * - πŸ”‡ Mute/unmute controls with state synchronization
13
+ * - πŸ”„ Call transfer and conference capabilities
14
+ * - πŸ“ End call with comprehensive disposition tracking
15
+ *
16
+ * πŸ”„ **Real-time Updates**:
17
+ * - 🌐 WebSocket integration for live call status updates
18
+ * - πŸ“Š Conference data synchronization
19
+ * - ⏱️ Real-time call duration tracking
20
+ * - πŸ“‘ Automatic UI updates based on call state changes
21
+ *
22
+ * πŸ‘€ **Agent Management**:
23
+ * - 🎧 Agent ready/break status controls
24
+ * - β˜• Break type management (Lunch, Tea, etc.)
25
+ * - βš™οΈ Process selection and initialization
26
+ * - πŸ“Š Queue count monitoring
27
+ *
28
+ * 🎨 **User Experience**:
29
+ * - πŸ–±οΈ Draggable floating interface
30
+ * - πŸ“ž Soft phone iframe integration
31
+ * - πŸ“± Responsive design for different screen sizes
32
+ * - ✨ Smooth animations and transitions
33
+ * - 🎨 Material-UI theming support
34
+ *
35
+ * πŸ“Š **Data Management**:
36
+ * - πŸ“ Call disposition tracking and classification
37
+ * - πŸ“… Callback scheduling and follow-up management
38
+ * - πŸ”„ State synchronization across components
39
+ * - πŸ’Ύ Persistent position and configuration storage
40
+ *
41
+ * πŸ›‘οΈ **Error Handling**:
42
+ * - βœ… Input validation for phone numbers
43
+ * - 🍞 Toast notifications for user feedback
44
+ * - 🚫 Page unload protection during active calls
45
+ * - πŸ”„ Graceful failure management and recovery
46
+ *
47
+ * πŸ”— **Integration**:
48
+ * - πŸ“‘ Parent component communication via callbacks
49
+ * - 🌐 External system connectivity via APIs
50
+ * - πŸ”§ Configurable button states and functionality
51
+ * - πŸ“Š Real-time data synchronization
52
+ *
53
+ * πŸ—οΈ **Architecture**:
54
+ * - βš›οΈ React functional component with hooks
55
+ * - πŸ—ƒοΈ Centralized state management via SDK state manager
56
+ * - πŸ”„ Effect hooks for lifecycle management
57
+ * - πŸ“‘ Custom hooks for API operations
58
+ * - 🎨 Material-UI component library integration
59
+ *
60
+ * 🎯 **Best Practices**:
61
+ * - πŸ“ Comprehensive JSDoc documentation
62
+ * - 🎨 Consistent code formatting and structure
63
+ * - πŸ”§ TypeScript type safety throughout
64
+ * - ⚑ Performance optimization with useCallback
65
+ * - 🧹 Proper cleanup and memory management
66
+ *
67
+ * πŸ“ˆ **Performance Features**:
68
+ * - ⚑ Optimized re-renders with proper dependency arrays
69
+ * - πŸ”„ Memoized callback functions
70
+ * - 🧹 Automatic cleanup of intervals and event listeners
71
+ * - πŸ“Š Efficient state updates and synchronization
72
+ *
73
+ * 🎯 **Use Cases**:
74
+ * - 🏒 Contact center agent interfaces
75
+ * - πŸ“ž Customer service telephony systems
76
+ * - 🎧 Call center management platforms
77
+ * - πŸ“± Integrated telephony applications
78
+ * - πŸ”„ Multi-channel communication systems
79
+ *
80
+ * @version 5.4.8
81
+ * @since 1.0.0
82
+ * @author CTI SDK Team
83
+ * @license Proprietary
84
+ */
2
85
  //# sourceMappingURL=index.mjs.map