call-control-sdk 6.4.1-dev.0 → 6.4.1

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