call-control-sdk 6.4.5-dev.0 → 6.4.5-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,2 +1,3822 @@
1
- "use strict";var dn=Object.create;var Ie=Object.defineProperty,un=Object.defineProperties,gn=Object.getOwnPropertyDescriptor,fn=Object.getOwnPropertyDescriptors,mn=Object.getOwnPropertyNames,qo=Object.getOwnPropertySymbols,xn=Object.getPrototypeOf,Fo=Object.prototype.hasOwnProperty,Cn=Object.prototype.propertyIsEnumerable;var Ve=(e,o,t)=>o in e?Ie(e,o,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[o]=t,d=(e,o)=>{for(var t in o||(o={}))Fo.call(o,t)&&Ve(e,t,o[t]);if(qo)for(var t of qo(o))Cn.call(o,t)&&Ve(e,t,o[t]);return e},W=(e,o)=>un(e,fn(o));var bn=(e,o)=>{for(var t in o)Ie(e,t,{get:o[t],enumerable:!0})},Ko=(e,o,t,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let r of mn(o))!Fo.call(e,r)&&r!==t&&Ie(e,r,{get:()=>o[r],enumerable:!(l=gn(o,r))||l.enumerable});return e};var yn=(e,o,t)=>(t=e!=null?dn(xn(e)):{},Ko(o||!e||!e.__esModule?Ie(t,"default",{value:e,enumerable:!0}):t,e)),En=e=>Ko(Ie({},"__esModule",{value:!0}),e);var le=(e,o,t)=>Ve(e,typeof o!="symbol"?o+"":o,t);var Mn={};bn(Mn,{CallControlPanel:()=>st,getSDKVersion:()=>On,initSDK:()=>kn,isSDKInitialized:()=>Pn,useClickToCall:()=>Jo,useEndCall:()=>Xo,useGetAuthorizationToken:()=>Zo,useGetCallerData:()=>Vo,useLogout:()=>jo});module.exports=En(Mn);var Fe="uat-cti.aighospitals.com",$=`https://${Fe}:8095`,hn=`wss://${Fe}:8095`,G={v1:"/api/v1"},R={LOGIN:`${$}${G.v1}/cti/login?provider=convox`,READY_AGENT:`${$}${G.v1}/cti/ready-agent?provider=convox`,UPDATE_AGENT_BREAK:`${$}${G.v1}/cti/update-agent-status?provider=convox`,CLICK_TO_CALL:`${$}${G.v1}/cti/calls?provider=convox`,HOLD_CALL:`${$}${G.v1}/cti/calls/hold?provider=convox`,MUTE_CALL:`${$}${G.v1}/cti/calls/mute?provider=convox`,UNMUTE_CALL:`${$}${G.v1}/cti/unmute-call?provider=convox`,END_CALL:`${$}${G.v1}/cti/calls/end?provider=convox`,LOGOUT:`${$}${G.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${$}${G.v1}/cti/calls/conference?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${$}${G.v1}/cti/calls/conference/hold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${$}${G.v1}/cti/calls/conference/mute?provider=convox`,CONFERENCE_CALL_END:`${$}${G.v1}/cti/calls/conference/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${$}${G.v1}/cti/calls/conference/hangup/all?provider=convox`,TRANSFER_CALL:`${$}${G.v1}/cti/calls/transfer?provider=convox`,AGENTS_LIST:`${$}${G.v1}/cti/users`,PROCESS_LIST:`${$}${G.v1}/cti/processes-list`,TRANSFER_TO_DETAILS:`${$}${G.v1}/cti/transfer-to-details?provider=convox`,CALL_HISTORY:`${$}${G.v1}/dashboard/call-history`,SENTIMENTAL_ANALYSIS:`${$}${G.v1}/users/get_sentiment_analysis`},Wo={WS:`${hn}${G.v1}/cti/ws`},fe="call-control-sdk-state";var Ze=class{constructor(){le(this,"state");le(this,"listeners",[]);le(this,"STORAGE_KEY",fe);le(this,"apiKey");le(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=W(d({},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,l,r,a){if(this.validateCredentials(o,t),!l||typeof l!="string"||l.trim().length===0)throw new Error("Agent ID not available");this.state.agentId=l,this.state.openConferenceDialog=!1,this.state.openCallTransferDialog=!1,this.state.authorization=a,this.state.sdkConfig=d({disableEndCallButton:!1,disabledDialButton:!1,disableCallTransferButton:!1,isDraggable:!0,disableSoftPhone:!1,disableConferenceButton:!1,disabled:{},enabled:{},outlined:{}},r),this.state.isInitialized=!0,this.saveToStorage(),this.notifyListeners()}getState(){return d({},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=d(d({},this.state.callData),o),this.saveToStorage(),this.notifyListeners()}updateConferenceData(o){this.state.conferenceLine=[...o],this.saveToStorage(),this.notifyListeners()}setConferenceLine(o){var l;(!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=(l=this.state.conferenceLine)==null?void 0:l.map(r=>r.line===o.line?o:r);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||[]}},C=new Ze;var Qe=class{constructor(){le(this,"config",null);le(this,"ticketId",null);le(this,"baseUrl","");le(this,"eventQueue",[]);le(this,"flushTimer",null)}async init(o){this.config=d({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 C.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 l={eventType:o,eventData:t,timestamp:Date.now()};this.eventQueue.push(l),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift()}async makeRequest(o,t){var a;let l=`${this.baseUrl}${o}`,r=((a=this.config)==null?void 0:a.retryAttempts)||3;for(let c=1;c<=r;c++)try{return await fetch(l,t)}catch(x){if(c===r)throw x;let E=Math.min(1e3*Math.pow(2,c-1),1e4);await new Promise(b=>setTimeout(b,E))}throw new Error("Max retries exceeded")}setupAutoTracking(){var l;if(typeof window=="undefined"||!((l=this.config)!=null&&l.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(r=>console.warn("Failed to track page visit:",r)),o.clicks!==!1&&document.addEventListener("click",r=>{var c;let a=r.target;(a.tagName==="BUTTON"||a.tagName==="A"||a.onclick||a.getAttribute("role")==="button"||a instanceof HTMLButtonElement&&a.type==="button")&&this.logEvent("click",{element:a.tagName,text:(c=a.textContent)==null?void 0:c.trim().substring(0,100),href:a.getAttribute("href"),id:a.id,className:a.className,role:a.getAttribute("role"),position:{x:r.clientX,y:r.clientY},timestamp:new Date().toISOString()}).catch(x=>console.warn("Failed to track click:",x))}),o.forms!==!1&&document.addEventListener("submit",r=>{let a=r.target,c=new FormData(a),x={};c.forEach((E,b)=>{x[b]=E.toString()}),this.logEvent("formSubmission",{formId:a.id,action:a.action,method:a.method,fields:Object.keys(x),fieldCount:Object.keys(x).length,timestamp:new Date().toISOString()}).catch(E=>console.warn("Failed to track form submission:",E))}),o.inputs!==!1){let r;document.addEventListener("input",a=>{let c=a.target;(c.tagName==="INPUT"||c.tagName==="TEXTAREA"||c.tagName==="SELECT")&&(clearTimeout(r),r=setTimeout(()=>{var x;this.logEvent("fieldChange",{element:c.tagName,type:c.getAttribute("type"),name:c.getAttribute("name"),id:c.id,valueLength:((x=c.value)==null?void 0:x.length)||0,timestamp:new Date().toISOString()}).catch(E=>console.warn("Failed to track field change:",E))},1e3))})}let t=Date.now();window.addEventListener("beforeunload",()=>{let r=Date.now()-t;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:r,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",r=>{this.logEvent("jsError",{message:r.message,filename:r.filename,lineno:r.lineno,colno:r.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",r=>{var a;this.logEvent("unhandledRejection",{reason:(a=r.reason)==null?void 0:a.toString(),timestamp:new Date().toISOString()})})),o.performance!==!1&&typeof window.performance!="undefined"&&window.performance.navigation&&window.addEventListener("load",()=>{setTimeout(()=>{let r=window.performance.navigation,a=window.performance.timing;this.logEvent("performanceMetrics",{navigationTime:a.navigationStart,loadTime:a.loadEventEnd-a.navigationStart,domReady:a.domContentLoadedEventEnd-a.navigationStart,renderTime:a.loadEventEnd-a.domContentLoadedEventEnd,navigationType:r.type,redirectCount:r.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)}},et=new Qe;typeof window!="undefined"&&(window.EventTracker=et);var me=require("react");var Yo=yn(require("axios"));var Go,Sn=(Go=C.getSdkAuthToken())!=null?Go:"",Tn=6e4;function vn(){var e;return(e=C.getSdkAuthToken())!=null?e:""}function Dn(){var o,t,l,r;let e=Yo.default.create({baseURL:$,headers:{"Content-Type":"application/json",Accept:"application/json","x-tenant-id":(t=(o=C.getCredentials())==null?void 0:o.tenantId)!=null?t:"","x-api-key":(r=(l=C.getCredentials())==null?void 0:l.apiKey)!=null?r:"",Authorization:`${Sn}`},timeout:Tn,withCredentials:!1});return e.interceptors.request.use(a=>{let c=vn();return c&&a.headers&&(a.headers.Authorization=`${c}`),a.metadata={startTime:new Date().getTime()},a},a=>(console.error("Request interceptor error:",a),Promise.reject(a))),e.interceptors.response.use(a=>{var E;let c=new Date().getTime(),x=(E=a.config.metadata)==null?void 0:E.startTime;return x&&console.log(`Request to ${a.config.url} took ${c-x}ms`),a},async a=>{var x;let c=a.config;return((x=a.response)==null?void 0:x.status)===401&&!c._retry&&(C.setInitCheck(),console.warn("Unauthorized request, attempting retry...")),a.response||(console.error("Network error:",a.message),a.message="Network error: Please check your internet connection"),a.response&&a.response.status>=500&&(console.error("Server error:",a.response.status,a.response.data),a.message="Server error: Please try again later"),Promise.reject(a)}),e}var Ln=Dn(),oe=Ln;var jo=()=>{let[e,o]=(0,me.useState)(!1),[t,l]=(0,me.useState)(!1),[r,a]=(0,me.useState)(!1),[c,x]=(0,me.useState)(null),[E,b]=(0,me.useState)(null);return{logout:(0,me.useCallback)(async()=>{var y;let u=JSON.parse((y=localStorage.getItem(fe))!=null?y:"");o(!0);let g={action:"LOGOUTUSER",userId:u.agentId||""};return oe.post(R.LOGOUT,g).then(m=>(C.clearStorageAndReset(),localStorage.clear(),sessionStorage.clear(),b(m==null?void 0:m.data),l(!0),m==null?void 0:m.data)).catch(m=>{var h;return a(!0),x(m),(h=m==null?void 0:m.response)==null?void 0:h.data}).finally(()=>{o(!1)})},[]),isLoading:e,isSuccess:t,isError:r,error:c,data:E}};var xe=require("react");var Xo=()=>{let[e,o]=(0,xe.useState)(!1),[t,l]=(0,xe.useState)(!1),[r,a]=(0,xe.useState)(!1),[c,x]=(0,xe.useState)(null),[E,b]=(0,xe.useState)(null);return{handleEndCall:(0,xe.useCallback)(async u=>{var m,h,N,U,H,M,q,te,K,O,T,D,ne,se,I;let g=JSON.parse((m=localStorage.getItem(fe))!=null?m:"");o(!0);let y={action:"ENDCALL",userId:g==null?void 0:g.agentId,processid:(U=(N=(h=g==null?void 0:g.process)==null?void 0:h.process_id)==null?void 0:N.toString())!=null?U:"",process_name:(M=(H=g==null?void 0:g.process)==null?void 0:H.process_name)!=null?M:"",callreferenceid:(te=(q=g==null?void 0:g.callData)==null?void 0:q.convox_id)!=null?te:"",mobile_number:(O=(K=g==null?void 0:g.callData)==null?void 0:K.phone_number)!=null?O:"",disposition:(T=u==null?void 0:u.disposition)!=null?T:"RES",set_followUp:(D=u==null?void 0:u.followUp)!=null?D:"N",callback_date:(ne=u==null?void 0:u.callbackDate)!=null?ne:"",callback_hrs:(se=u==null?void 0:u.callbackHrs)!=null?se:"",callback_mins:(I=u==null?void 0:u.callbackMins)!=null?I:"",endcall_type:"CLOSE"};return oe.post(R.END_CALL,y).then(v=>(C.endCall(),b(v==null?void 0:v.data),l(!0),v==null?void 0:v.data)).catch(v=>{var P;return a(!0),x(v),(P=v==null?void 0:v.response)==null?void 0:P.data}).finally(()=>{o(!1)})},[]),isLoading:e,isSuccess:t,isError:r,error:c,data:E}};var Ce=require("react");var Jo=()=>{let[e,o]=(0,Ce.useState)(!1),[t,l]=(0,Ce.useState)(!1),[r,a]=(0,Ce.useState)(!1),[c,x]=(0,Ce.useState)(null),[E,b]=(0,Ce.useState)(null);return{handleStartCall:(0,Ce.useCallback)(async u=>{var y,m,h,N,U,H,M,q,te;let g=JSON.parse((y=localStorage.getItem(fe))!=null?y:"");if(o(!0),((m=g==null?void 0:g.callData)==null?void 0:m.status)==="IDLE"){let K={action:"CALL",userId:g==null?void 0:g.agentId,phone_number:u==null?void 0:u.mobileNumber};return oe.post(R.CLICK_TO_CALL,K).then(O=>(b(O==null?void 0:O.data),l(!0),O==null?void 0:O.data)).catch(O=>{var T;return a(!0),x(O),(T=O==null?void 0:O.response)==null?void 0:T.data}).finally(()=>{o(!1)})}else if(((h=g==null?void 0:g.callData)==null?void 0:h.status)==="ONCALL"){let K=(U=(N=g==null?void 0:g.conferenceLine)==null?void 0:N.filter(T=>T.line!==1))==null?void 0:U.find(T=>T.status==="IDLE"&&!(T!=null&&T.isCallStart)),O={action:"EXTERNAL_CONFERENCE",operation:`CALL${K.line}`,line_used:String(K.line),thirdparty_no:u==null?void 0:u.mobileNumber,userid:(M=(H=g.callData)==null?void 0:H.agent_id)!=null?M:"",process:(te=(q=g.callData)==null?void 0:q.process_name)!=null?te:""};return oe.post(R.CONFERENCE_CALL,O).then(T=>(b(T==null?void 0:T.data),l(!0),C.setConferenceLine(W(d({},K),{isCallStart:!0,status:"ONCALL",phone:u==null?void 0:u.mobileNumber})),C.setOpenConferenceDialog(!0),T==null?void 0:T.data)).catch(T=>{var D;return a(!0),x(T),(D=T==null?void 0:T.response)==null?void 0:D.data}).finally(()=>{o(!1)})}else alert("Agent is not ready")},[]),isLoading:e,isSuccess:t,isError:r,error:c,data:E}};var Ke=require("react");var Vo=()=>{let{process_id:e,process_name:o,status:t,phone_number:l,agent_id:r,convox_id:a}=C.getState().callData,c={phone_number:l,status:t,callReferenceId:a,agent_id:r,process_id:e,process_name:o},[x,E]=(0,Ke.useState)(c);return(0,Ke.useEffect)(()=>C.subscribe(()=>{let{process_id:w,process_name:u,status:g,phone_number:y,agent_id:m,convox_id:h}=C.getState().callData;E({phone_number:y,status:g,callReferenceId:h,agent_id:m,process_id:w,process_name:u})}),[]),x};var We=require("react");var Zo=()=>{let[e,o]=(0,We.useState)(C.getSdkAuthToken());return(0,We.useEffect)(()=>C.subscribe(()=>{o(C.getSdkAuthToken())}),[]),e};var Je=require("react");var L=require("@mui/icons-material"),f=require("@mui/material"),ee=require("react");var re=require("react");function tt(e,o){let[t,l]=(0,re.useState)(e),[r,a]=(0,re.useState)(!1),c=(0,re.useRef)(),x=(0,re.useRef)({x:0,y:0}),E=(0,re.useRef)({x:0,y:0}),b=(0,re.useCallback)(y=>{let m=c.current;if(!m)return;let h=m.getBoundingClientRect(),N=window.innerWidth,U=window.innerHeight,H={x:Math.max(0,Math.min(y.x,N-h.width)),y:Math.max(0,Math.min(y.y,U-h.height))};l(H),o==null||o(H)},[o]),w=(0,re.useCallback)((y,m)=>{a(!0),x.current={x:y,y:m},E.current=t;let h=(M,q)=>{let te=M-x.current.x,K=q-x.current.y;b({x:E.current.x+te,y:E.current.y+K})},N=M=>{M.preventDefault(),h(M.clientX,M.clientY)},U=M=>{M.preventDefault();let q=M.touches[0];q&&h(q.clientX,q.clientY)},H=()=>{a(!1),document.removeEventListener("mousemove",N),document.removeEventListener("mouseup",H),document.removeEventListener("touchmove",U),document.removeEventListener("touchend",H)};document.addEventListener("mousemove",N),document.addEventListener("mouseup",H),document.addEventListener("touchmove",U,{passive:!1}),document.addEventListener("touchend",H)},[t,b]),u=(0,re.useCallback)(y=>{y.preventDefault(),w(y.clientX,y.clientY)},[w]),g=(0,re.useCallback)(y=>{y.preventDefault();let m=y.touches[0];m&&w(m.clientX,m.clientY)},[w]);return{position:t,isDragging:r,dragRef:c,handleMouseDown:u,handleTouchStart:g}}var Ge=require("react");function he(){let[e,o]=(0,Ge.useState)(C.getState());return(0,Ge.useEffect)(()=>C.subscribe(()=>{o(C.getState())}),[]),e}var je=require("react");var be=require("react"),Ye=require("@mui/material"),Re=require("react/jsx-runtime"),Qo=(0,be.createContext)(void 0),Ee=()=>{let e=(0,be.useContext)(Qo);if(!e)throw new Error("useToast must be used inside ToastProvider");return e},en=({children:e})=>{let[o,t]=(0,be.useState)(!1),[l,r]=(0,be.useState)(""),[a,c]=(0,be.useState)("info"),x=(E,b="info")=>{r(E),c(b),t(!0)};return(0,Re.jsxs)(Qo.Provider,{value:{showToast:x},children:[e,(0,Re.jsx)(Ye.Snackbar,{open:o,color:a,autoHideDuration:3e3,onClose:()=>t(!1),anchorOrigin:{vertical:"top",horizontal:"right"},children:(0,Re.jsx)(Ye.Alert,{variant:"filled",severity:a,onClose:()=>t(!1),sx:{width:"100%"},children:l})})]})};var _n={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},In=(e,o)=>{if(o.type==="isLoading")return W(d({},e),{isLoading:o.payload});if(o.type==="isSuccess")return W(d({},e),{isSuccess:!0,data:o.payload});if(o.type==="isError")return W(d({},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 ce=(e={})=>{let{onSuccess:o=null,onError:t=null,disabledSuccessToast:l=!1}=e,{showToast:r}=Ee(),[a,c]=(0,je.useReducer)(In,_n);return[(0,je.useCallback)((E,b,w={})=>{c({type:"isLoading",payload:!0}),oe.post(E,b,w).then(u=>{var g,y;c({type:"isSuccess",payload:u.data}),o==null||o(u.data,b),console.log((g=u.data)==null?void 0:g.message,"res45"),l||r((y=u.data)==null?void 0:y.message,"success")}).catch(u=>{var y,m,h,N,U,H,M,q,te,K,O,T;let g={status:(m=(y=u.response)==null?void 0:y.status)!=null?m:500,message:((N=(h=u.response)==null?void 0:h.data)==null?void 0:N.detail)||((H=(U=u.response)==null?void 0:U.data)==null?void 0:H.message)||u.message||"An unknown error occurred",data:(q=(M=u.response)==null?void 0:M.data)!=null?q:null,statusText:(K=(te=u.response)==null?void 0:te.statusText)!=null?K:"",code:(O=u==null?void 0:u.code)!=null?O:"",name:(T=u==null?void 0:u.name)!=null?T:""};r(g.message,"error"),c({type:"isError",payload:g}),t==null||t(g,b)}).finally(()=>{c({type:"isLoading",payload:!1})})},[o,t,r]),a]};var A=require("@mui/icons-material"),s=require("@mui/material"),pe=require("react");var tn=require("@mui/material");var Rn=({disabled:e,enabled:o,outlined:t})=>{let l=(0,tn.useTheme)();return{disabled:d({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 ${l.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${l.palette.primary.light}`}},e),enabled:d({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${l.palette.primary.main}`,height:"40px","&:hover":{boxShadow:" 0px 2px 1px rgba(0, 0, 0, 0.507)",border:`1px solid ${l.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${l.palette.primary.light}`}},o),outlined:d({padding:"0px",margin:"0px",minWidth:"40px !important",borderRadius:"16px",backgroundColor:l.palette.grey[200],boxShadow:`0px 2px 1px ${l.palette.primary.light}`,border:`0px solid ${l.palette.primary.main}`,height:"40px","&:hover":{boxShadow:`0px 2px 1px ${l.palette.primary.main}`,border:`0px solid ${l.palette.primary.main}`},"&:active":{bgcolor:"primary.main",boxShadow:`inset 1px -2px 4px ${l.palette.primary.light}`}},t)}},Xe=Rn;var n=require("react/jsx-runtime"),An=({each:e})=>{var O,T,D,ne,se;let o=he(),{showToast:t}=Ee(),{disabled:l,enabled:r,outlined:a}=Xe({disabled:((O=o.sdkConfig)==null?void 0:O.disabled)||{},enabled:((T=o.sdkConfig)==null?void 0:T.enabled)||{},outlined:((D=o.sdkConfig)==null?void 0:D.outlined)||{}}),c=(0,s.useTheme)(),[x,E]=(0,pe.useState)(!1),[b,w]=(0,pe.useState)(!1),[u,g]=(0,pe.useState)(!1),[y,m]=(0,pe.useState)(!1),[h,N]=(0,pe.useState)(!1),U=(I,v)=>{C.setConferenceLine(d(d({},I),v))},H=(I,v)=>{var j,z,J,V;let P=d(d({},I),v);E(!0);let Y={action:"EXTERNAL_CONFERENCE",operation:`CALL${P.line}`,line_used:String(P.line),thirdparty_no:P.phone,userid:(z=(j=o.callData)==null?void 0:j.agent_id)!=null?z:"",process:(V=(J=o.callData)==null?void 0:J.process_name)!=null?V:""};oe.post(R.CONFERENCE_CALL,Y).then(k=>{var _;t((_=k.data)==null?void 0:_.message,"success"),C.setConferenceLine(d(d({},I),v))}).catch(k=>{var F,Z,Q,X;let _=((Z=(F=k.response)==null?void 0:F.data)==null?void 0:Z.detail)||((X=(Q=k.response)==null?void 0:Q.data)==null?void 0:X.message)||k.message||"An unknown error occurred";t(_,"error")}).finally(()=>{E(!1)})},M=(I,v)=>{var j,z,J,V;let P=d(d({},I),v);w(!0);let Y={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(P.line),thirdparty_no:P.phone,userid:(z=(j=o.callData)==null?void 0:j.agent_id)!=null?z:"",process:(V=(J=o.callData)==null?void 0:J.process_name)!=null?V:""};oe.post(R.CONFERENCE_CALL,Y).then(k=>{var _;t((_=k.data)==null?void 0:_.message,"success"),C.setConferenceLine(d(d({},I),v))}).catch(k=>{var F,Z,Q,X;let _=((Z=(F=k.response)==null?void 0:F.data)==null?void 0:Z.detail)||((X=(Q=k.response)==null?void 0:Q.data)==null?void 0:X.message)||k.message||"An unknown error occurred";t(_,"error")}).finally(()=>{w(!1)})},q=(I,v,P)=>{var z,J,V,k;let Y=d(d({},I),v);g(!0);let j={action:"EXTERNAL_CONFERENCE",operation:P,hold_channel_no:P==="HOLDUSER"?`hold${Y.line}`:`unhold${Y.line}`,userid:(J=(z=o.callData)==null?void 0:z.agent_id)!=null?J:"",process:(k=(V=o.callData)==null?void 0:V.process_name)!=null?k:""};oe.post(R.CONFERENCE_CALL_HOLD_OR_UN_HOLD,j).then(_=>{var F;t((F=_.data)==null?void 0:F.message,"success"),C.setConferenceLine(d(d({},I),v))}).catch(_=>{var Z,Q,X,de;let F=((Q=(Z=_.response)==null?void 0:Z.data)==null?void 0:Q.detail)||((de=(X=_.response)==null?void 0:X.data)==null?void 0:de.message)||_.message||"An unknown error occurred";t(F,"error")}).finally(()=>{g(!1)})},te=(I,v,P)=>{var z,J,V,k;let Y=d(d({},I),v);m(!0);let j={action:"EXTERNAL_CONFERENCE",operation:P,channel_no:P==="MUTEUSER"?`mute${Y.line}`:`play${Y.line}`,userid:(J=(z=o.callData)==null?void 0:z.agent_id)!=null?J:"",thirdparty_no:Y.phone,process:(k=(V=o.callData)==null?void 0:V.process_name)!=null?k:""};oe.post(R.CONFERENCE_CALL_MUTE_OT_UN_MUTE,j).then(_=>{var F;t((F=_.data)==null?void 0:F.message,"success"),C.setConferenceLine(d(d({},I),v))}).catch(_=>{var Z,Q,X,de;let F=((Q=(Z=_.response)==null?void 0:Z.data)==null?void 0:Q.detail)||((de=(X=_.response)==null?void 0:X.data)==null?void 0:de.message)||_.message||"An unknown error occurred";t(F,"error")}).finally(()=>{m(!1)})},K=(I,v)=>{var j,z,J,V;let P=d(d({},I),v);N(!0);let Y={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(P.line-1),user_type:`THIRDPARTY${P.line-1}`,thirdparty_no:P.phone,userid:(z=(j=o.callData)==null?void 0:j.agent_id)!=null?z:"",process:(V=(J=o.callData)==null?void 0:J.process_name)!=null?V:""};oe.post(R.CONFERENCE_CALL_END,Y).then(k=>{var _;t((_=k.data)==null?void 0:_.message,"success"),C.setConferenceLine(d(d({},I),v))}).catch(k=>{var F,Z,Q,X;let _=((Z=(F=k.response)==null?void 0:F.data)==null?void 0:Z.detail)||((X=(Q=k.response)==null?void 0:Q.data)==null?void 0:X.message)||k.message||"An unknown error occurred";t(_,"error")}).finally(()=>{N(!1)})};return(0,n.jsxs)(s.TableRow,{sx:{border:"2px solid #fff"},children:[(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:(0,n.jsxs)(s.Typography,{children:["Line ",(ne=e==null?void 0:e.line)!=null?ne:"",". "]})}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:(0,n.jsx)(s.Typography,{variant:"body2",sx:{px:1,borderRadius:"10px"},children:(se=e==null?void 0:e.status)!=null?se:""})}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:(0,n.jsx)(s.Button,{sx:{textTransform:"capitalize"},size:"small",children:(0,n.jsx)(s.Typography,{variant:"body2",children:(e==null?void 0:e.line)===1?"Internal":"External"})})}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:(0,n.jsx)(s.TextField,{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:I=>{U(e,{phone:I.target.value})}})}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:(0,n.jsxs)(s.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-around"},children:[e.line!==1&&(0,n.jsx)(s.Tooltip,{title:"Call",children:(0,n.jsx)(s.Button,{variant:(e==null?void 0:e.status)!=="IDLE"?"outlined":"contained",color:"success",sx:(e==null?void 0:e.status)!=="IDLE"?d({},l):W(d({},r),{border:`0px solid ${c.palette.success.light}`,"&:hover":{bgcolor:"success.light",boxShadow:`0px 2px 1px ${c.palette.success.light}`,border:`0px solid ${c.palette.success.light}`},"&:active":{bgcolor:"success.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}),onClick:()=>{H(e,{})},disabled:(e==null?void 0:e.status)!=="IDLE",children:x?(0,n.jsx)(s.CircularProgress,{size:"20px",color:"success"}):(0,n.jsx)(A.Call,{sx:{color:(e==null?void 0:e.status)!=="IDLE"?"default":"#f3f2f2"}})})}),e.line===1&&(0,n.jsx)(s.Tooltip,{title:"Merge Call",children:(0,n.jsxs)(s.Button,{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"?W(d({},l),{padding:"0px 16px"}):(e==null?void 0:e.status)==="ONCALL"?W(d({},a),{padding:"0px 16px"}):W(d({},l),{padding:"0px 16px"}),onClick:()=>{M(e,{isMergeCall:!0})},disabled:(e==null?void 0:e.status)!=="ONCALL"||b,children:[e!=null&&e.isMergeCall?"Merged":"Merge",b?(0,n.jsx)(s.CircularProgress,{size:"20px"}):(0,n.jsx)(A.CallSplit,{})]})}),(0,n.jsx)(s.Tooltip,{title:e.isHold?"Hold":"Un Hold",children:(0,n.jsx)(s.Button,{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"?d({},l):(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"?d({},a):d({},l),onClick:()=>{e.isHold?q(e,{isHold:!1},"UNHOLDUSER"):q(e,{isHold:!0},"HOLDUSER")},disabled:(e==null?void 0:e.status)!=="ONCALL"&&(e==null?void 0:e.status)!=="CONFERENCE"||u,children:u?(0,n.jsx)(s.CircularProgress,{size:"20px",sx:{color:c.palette.primary.main}}):e.isHold?(0,n.jsx)(A.PlayArrow,{}):(0,n.jsx)(A.Pause,{})})}),(0,n.jsx)(s.Tooltip,{title:e.isMute?"Mute":"Un Mute",children:(0,n.jsx)(s.Button,{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"?d({},l):(e==null?void 0:e.status)==="ONCALL"||(e==null?void 0:e.status)==="CONFERENCE"?d({},a):d({},l),onClick:()=>{e.isMute?te(e,{isMute:!1},"PLAYUSER"):te(e,{isMute:!0},"MUTEUSER")},disabled:(e==null?void 0:e.status)!=="ONCALL"&&(e==null?void 0:e.status)!=="CONFERENCE"||y,children:y?(0,n.jsx)(s.CircularProgress,{size:"20px",sx:{color:c.palette.primary.main}}):e.isMute?(0,n.jsx)(A.MicOff,{}):(0,n.jsx)(A.Mic,{})})}),(e==null?void 0:e.line)!==1?(0,n.jsx)(s.Tooltip,{title:"End Call",children:(0,n.jsx)(s.Button,{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"?W(d({},r),{border:`0px solid ${c.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${c.palette.error.light}`,border:`0px solid ${c.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${c.palette.primary.light}`}}):d({},l),onClick:()=>{K(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"||h,children:h?(0,n.jsx)(s.CircularProgress,{size:"20px",color:"error"}):(0,n.jsx)(A.CallEnd,{})})}):(0,n.jsx)(s.Button,{variant:e!=null&&e.isCallStart?"contained":"outlined",color:"error",sx:{display:"none"},onClick:()=>{K(e,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1})},disabled:!(e!=null&&e.isCallStart)||h,children:h?(0,n.jsx)(s.CircularProgress,{size:"20px",color:"error"}):(0,n.jsx)(A.CallEnd,{})})]})})]},e.line)};function on(){var c;let e=he(),{showToast:o}=Ee(),[t,l]=(0,pe.useState)(!1),r=()=>{C.setOpenConferenceDialog(!1)},a=()=>{var E,b,w,u;l(!0);let x={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(b=(E=e.callData)==null?void 0:E.agent_id)!=null?b:"",process:(u=(w=e.callData)==null?void 0:w.process_name)!=null?u:""};oe.post(R.CONFERENCE_CALL_END_ALL,x).then(g=>{var y;o((y=g.data)==null?void 0:y.message,"success"),C.resetConferenceLines(),r()}).catch(g=>{var m,h,N,U;let y=((h=(m=g.response)==null?void 0:m.data)==null?void 0:h.detail)||((U=(N=g.response)==null?void 0:N.data)==null?void 0:U.message)||g.message||"An unknown error occurred";o(y,"error")}).finally(()=>{l(!1)})};return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.Dialog,{open:e.openConferenceDialog,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,n.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,n.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"10px 16px"},children:[(0,n.jsxs)(s.Typography,{variant:"body1",children:[(c=e==null?void 0:e.agentId)!=null?c:""," conference"]}),(0,n.jsx)(s.IconButton,{onClick:r,children:(0,n.jsx)(A.Close,{})})]}),(0,n.jsx)(s.Box,{sx:{boxShadow:"1px 1px 2px #e7e5e5ff",margin:"0px 15px",borderRadius:"20px"},children:(0,n.jsx)(s.TableContainer,{component:s.Paper,sx:{outline:"0px solid gray !important",boxShadow:"1px 1px 6px #e7e5e5ff"},children:(0,n.jsxs)(s.Table,{sx:{border:"4px solid #ffffff !important"},children:[(0,n.jsx)(s.TableHead,{children:(0,n.jsxs)(s.TableRow,{sx:{border:"2px solid #f3f3f3ff !important"},children:[(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:"Line"}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:"Status"}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:"Call Type"}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:"Mobile Number"}),(0,n.jsx)(s.TableCell,{sx:{padding:"6px"},children:"Call Actions"})]})}),(0,n.jsx)(s.TableBody,{children:e==null?void 0:e.conferenceLine.map(x=>(0,n.jsx)(An,{each:x}))})]})})}),(0,n.jsx)(s.Box,{textAlign:"center",m:2,children:(0,n.jsxs)(s.Button,{variant:"outlined",color:"error",size:"large",onClick:a,disabled:t,sx:{px:2,borderRadius:"20px",textTransform:"capitalize"},children:[t?(0,n.jsx)(s.CircularProgress,{size:"20px",color:"error",sx:{marginRight:"8px"}}):(0,n.jsx)(s.IconButton,{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:(0,n.jsx)(A.PhoneDisabled,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function nn({open:e}){var y,m,h,N,U,H,M,q,te,K,O,T;let o=he(),[t]=ce({onSuccess:()=>{C.setOpenCallTransferDialog(!1)}}),[l,r]=(0,pe.useState)("process"),[a,{data:c,isLoading:x}]=ce({disabledSuccessToast:!0}),[E,{data:b,isLoading:w}]=ce({disabledSuccessToast:!0}),u=()=>{C.setOpenCallTransferDialog(!1)},g=(D,ne)=>{var se,I,v,P,Y,j,z,J,V,k,_,F,Z,Q,X,de,Se,Ae,Te,we,Ne,ke,ve,Oe,Pe,Me,De,Ue,Be,He,ze,$e,qe;if(console.log(D,"data34"),ne==="PROCESS"){let ye={mobile_number:(I=(se=o.callData)==null?void 0:se.phone_number)!=null?I:"",userid:(P=(v=o.callData)==null?void 0:v.agent_id)!=null?P:"",type:"PROCESS",transfer_to:(Y=D==null?void 0:D.process_name)!=null?Y:"",callreferenceid:(z=(j=o.callData)==null?void 0:j.convox_id)!=null?z:"",processid:String((V=(J=o.callData)==null?void 0:J.process_id)!=null?V:""),process_name:(_=(k=o.callData)==null?void 0:k.process_name)!=null?_:""};t(R.TRANSFER_CALL,ye)}else if(ne==="QUEUE"){let ye={mobile_number:(Z=(F=o.callData)==null?void 0:F.phone_number)!=null?Z:"",userid:(X=(Q=o.callData)==null?void 0:Q.agent_id)!=null?X:"",type:"QUEUE",transfer_to:(de=D==null?void 0:D.queue_name)!=null?de:"",callreferenceid:(Ae=(Se=o.callData)==null?void 0:Se.convox_id)!=null?Ae:"",processid:String((we=(Te=o.callData)==null?void 0:Te.process_id)!=null?we:""),process_name:(ke=(Ne=o.callData)==null?void 0:Ne.process_name)!=null?ke:""};t(R.TRANSFER_CALL,ye)}else if(ne==="AGENT"){let ye={mobile_number:(Oe=(ve=o.callData)==null?void 0:ve.phone_number)!=null?Oe:"",userid:(Me=(Pe=o.callData)==null?void 0:Pe.agent_id)!=null?Me:"",type:"AGENT",transfer_to:(De=D==null?void 0:D.user_id)!=null?De:"",callreferenceid:(Be=(Ue=o.callData)==null?void 0:Ue.convox_id)!=null?Be:"",processid:String((ze=(He=o.callData)==null?void 0:He.process_id)!=null?ze:""),process_name:(qe=($e=o.callData)==null?void 0:$e.process_name)!=null?qe:""};t(R.TRANSFER_CALL,ye)}};return(0,pe.useEffect)(()=>{a(R.AGENTS_LIST,{status:"IDLE",active:!0}),E(R.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.Dialog,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,n.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,n.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,n.jsx)(s.Typography,{variant:"body1",children:" Call Transfer"}),(0,n.jsx)(s.IconButton,{onClick:u,children:(0,n.jsx)(A.Close,{})})]}),(0,n.jsxs)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:[(0,n.jsxs)(s.Box,{sx:{display:"flex",gap:1},children:[(0,n.jsx)(s.Button,{variant:l==="process"?"contained":"outlined",onClick:()=>{r("process"),E(R.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Process"}),(0,n.jsx)(s.Button,{variant:l==="queues"?"contained":"outlined",onClick:()=>{r("queues"),E(R.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},children:"Queues"}),(0,n.jsx)(s.Button,{variant:l==="agents"?"contained":"outlined",onClick:()=>{r("agents"),a(R.AGENTS_LIST,{status:"IDLE",active:!0})},children:"Agents"})]}),(w||x)&&(0,n.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"80px"},children:[(0,n.jsx)(s.CircularProgress,{})," "]}),!w&&!x&&l==="process"&&(0,n.jsx)(s.Box,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(y=b==null?void 0:b.data)!=null&&y.process&&((h=(m=b==null?void 0:b.data)==null?void 0:m.process)==null?void 0:h.length)>0?(U=(N=b==null?void 0:b.data)==null?void 0:N.process)==null?void 0:U.map((D,ne)=>(0,n.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,n.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,n.jsx)(A.SupportAgent,{sx:{marginRight:"4px"}}),D.process_name]}),(0,n.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{g(D,"PROCESS")},children:(0,n.jsx)(A.Call,{})})]},ne)):(0,n.jsx)(s.Typography,{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"})}),!w&&!x&&l==="queues"&&(0,n.jsx)(s.Box,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:(H=b==null?void 0:b.data)!=null&&H.queue&&((q=(M=b==null?void 0:b.data)==null?void 0:M.queue)==null?void 0:q.length)>0?(K=(te=b==null?void 0:b.data)==null?void 0:te.queue)==null?void 0:K.map((D,ne)=>{var se,I,v,P,Y,j;return(0,n.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,n.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,n.jsx)(A.SupportAgent,{sx:{marginRight:"4px"}}),D.queue_name,(v=(I=(se=b==null?void 0:b.data)==null?void 0:se.process)==null?void 0:I.find(z=>z.process_id===D.process_id))!=null&&v.process_name?(0,n.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((j=(Y=(P=b==null?void 0:b.data)==null?void 0:P.process)==null?void 0:Y.find(z=>z.process_id===D.process_id))==null?void 0:j.process_name)+")"}):""]}),(0,n.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{g(D,"QUEUE")},children:(0,n.jsx)(A.Call,{})})]},ne)}):(0,n.jsx)(s.Typography,{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"})}),!w&&!x&&l==="agents"&&(0,n.jsx)(s.Box,{sx:{display:"flex",gap:1,flexWrap:"wrap"},children:c!=null&&c.data&&((O=c==null?void 0:c.data)==null?void 0:O.length)>0?(T=c==null?void 0:c.data)==null?void 0:T.map((D,ne)=>(0,n.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,n.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,n.jsx)(A.SupportAgent,{sx:{marginRight:"4px"}}),D.name]}),(0,n.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{g(D,"AGENT")},children:(0,n.jsx)(A.Call,{})})]},ne)):(0,n.jsx)(s.Typography,{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 sn({open:e,setOpen:o,onSubmitDisposition:t}){var w,u,g,y;let[l,r]=(0,pe.useState)({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),a=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],c=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],x=(m,h)=>{r(N=>W(d({},N),{[m]:h}))},E=()=>{r({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},b=()=>{E(),o(!1)};return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.Dialog,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:(0,n.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,n.jsx)(s.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:(0,n.jsxs)(s.Typography,{variant:"body1",m:1,children:[" ","Call Disposition"]})}),(0,n.jsxs)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"10px",margin:"10px",borderRadius:"10px"},children:[(0,n.jsxs)(s.Box,{display:"flex",gap:2,children:[(0,n.jsx)(s.Autocomplete,{value:l.disposition,options:a,getOptionLabel:m=>m.label,onChange:(m,h)=>x("disposition",h),size:"small",renderInput:m=>(0,n.jsx)(s.TextField,W(d({},m),{label:"Disposition",fullWidth:!0})),sx:{flex:1}}),(0,n.jsx)(s.Autocomplete,{options:c,getOptionLabel:m=>m.label,value:l.followUp,onChange:(m,h)=>x("followUp",h),size:"small",renderInput:m=>(0,n.jsx)(s.TextField,W(d({},m),{label:"Follow Up",fullWidth:!0})),sx:{flex:1}})]}),((u=(w=l==null?void 0:l.followUp)==null?void 0:w.label)==null?void 0:u.toLowerCase())==="yes"&&(0,n.jsxs)(s.Box,{display:"flex",gap:2,mt:2,children:[(0,n.jsx)(s.TextField,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:l.callbackDate,onChange:m=>x("callbackDate",m.target.value),fullWidth:!0,sx:{flex:1}}),(0,n.jsx)(s.TextField,{size:"small",label:"Hours (0-23)",type:"text",value:l.callbackHrs,onChange:m=>x("callbackHrs",m.target.value),fullWidth:!0,sx:{flex:1}})]}),((y=(g=l==null?void 0:l.followUp)==null?void 0:g.label)==null?void 0:y.toLowerCase())==="yes"&&(0,n.jsxs)(s.Box,{display:"flex",gap:2,mt:2,children:[(0,n.jsx)(s.TextField,{size:"small",label:"Minutes (0-59)",type:"text",value:l.callbackMins,onChange:m=>x("callbackMins",m.target.value),fullWidth:!0,sx:{flex:1}}),(0,n.jsx)(s.Box,{sx:{flex:1}})]})]}),(0,n.jsxs)(s.Box,{textAlign:"right",m:2,children:[(0,n.jsx)(s.Button,{variant:"outlined",color:"error",size:"large",onClick:b,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),(0,n.jsx)(s.Button,{variant:"contained",color:"primary",size:"large",onClick:()=>t(l),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function an({open:e,setOpen:o,processList:t=null,handleSelectedProcessor:l}){return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.Dialog,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:(0,n.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,n.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,n.jsx)(s.Typography,{variant:"body1",children:" Process List"}),(0,n.jsx)(s.IconButton,{onClick:()=>{o(!1)},children:(0,n.jsx)(A.Close,{})})]}),(0,n.jsx)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:t.length>0?t==null?void 0:t.map((a,c)=>(0,n.jsx)(s.Box,{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:()=>{l(a)},children:(0,n.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,n.jsx)(A.SupportAgent,{sx:{marginRight:"4px"}}),a.process_name]})},c)):null})]})})})}function ln({open:e,setOpen:o}){return(0,n.jsx)(n.Fragment,{children:(0,n.jsx)(s.Dialog,{open:e,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,n.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,n.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,n.jsx)(s.Typography,{variant:"body1",children:" Call History"}),(0,n.jsx)(s.IconButton,{onClick:()=>{o(!1)},children:(0,n.jsx)(A.Close,{})})]}),(0,n.jsx)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Coming Soon..."})]})})})}var p=require("react/jsx-runtime"),wn=(e,o,t)=>e.map(r=>{var a,c,x;if((r==null?void 0:r.line)===1)return{line:1,status:(a=t==null?void 0:t.status)!=null?a:"",type:"internal",phone:(c=t==null?void 0:t.phone_number)!=null?c:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};{let E=`line_${r.line}_status`,b=`line_${r.line}_phonenumber`;return W(d({},r),{status:(x=o[E])!=null?x:"IDLE",phone:o[b]!=="0"?o[b]:""})}}),Nn=e=>{let o=Math.floor(e/60),t=e%60;return`${o.toString().padStart(2,"0")}:${t.toString().padStart(2,"0")}`};function rn({onDataChange:e}){var at,it,lt,rt,ct,pt,dt,ut,gt,ft,mt,xt,Ct,bt,yt,Et,ht,St,Tt,vt,Dt,Lt,_t,It,Rt,At,wt,Nt,kt,Ot,Pt,Mt,Ut,Bt,Ht,zt,$t,qt,Ft,Kt,Wt,Gt,Yt,jt,Xt,Jt,Vt,Zt,Qt,eo,to,oo,no,so,ao,io,lo,ro,co,po,uo,go,fo,mo,xo,Co,bo,yo,Eo,ho,So,To,vo,Do,Lo,_o,Io,Ro,Ao,wo,No;let o=(0,f.useTheme)(),t=he(),{showToast:l}=Ee(),{disabled:r,enabled:a,outlined:c}=Xe({disabled:((at=t.sdkConfig)==null?void 0:at.disabled)||{},enabled:((it=t.sdkConfig)==null?void 0:it.enabled)||{},outlined:((lt=t.sdkConfig)==null?void 0:lt.outlined)||{}}),x=(0,ee.useRef)(null),[E,b]=(0,ee.useState)(null),[w,u]=(0,ee.useState)(!0),[g,y]=(0,ee.useState)(null),[m,h]=(0,ee.useState)(null),[N,U]=(0,ee.useState)(!1),[H,M]=(0,ee.useState)(!1),[q,te]=(0,ee.useState)(!1),[K,O]=(0,ee.useState)(null),[T,D]=(0,ee.useState)(""),[ne,se]=(0,ee.useState)(0),{position:I,isDragging:v,dragRef:P,handleMouseDown:Y,handleTouchStart:j}=tt(t.controlPanelPosition,i=>C.setControlPanelPosition(i)),{position:z,isDragging:J,dragRef:V,handleMouseDown:k,handleTouchStart:_}=tt(t.iframePosition,i=>C.setIframePosition(i)),[F,{isLoading:Z}]=ce({onSuccess:()=>{D(""),h(null)}}),[Q,{isLoading:X}]=ce({onSuccess:()=>{C.setHolding(!t.isHolding)},onError:i=>{console.log("\u274C Hold operation error:",i)}}),[de,{isLoading:Se}]=ce({onSuccess:()=>{C.setMuted(!t.isMuted)},onError:i=>{console.log("\u274C Mute operation error:",i)}}),[Ae,{isLoading:Te}]=ce(),[we,{isLoading:Ne}]=ce(),[ke,{isLoading:ve}]=ce(),Oe=()=>{b(null)},Pe=i=>{u(!0),h(i.currentTarget),C.setStatus("dial")},Me=()=>{t.status!=="on call"&&C.setStatus("idle"),h(null)},De=i=>{y(i.currentTarget)},Ue=()=>{y(null)},Be=()=>{let i={action:"READYAGENT",userId:t.agentId};Ae(R.READY_AGENT,i)},He=i=>{y(null);let S={action:"AGENTBREAK",break_type:i,userId:t.agentId};we(R.UPDATE_AGENT_BREAK,S)},ze=i=>{if(i.length!==10)l("Invalid phone number","error");else if(!/^\d+$/.test(i))l("Invalid phone number","error");else{let S={action:"CALL",phone_number:i,userId:t.agentId};F(R.CLICK_TO_CALL,S)}},$e=()=>{let i={action:t.isHolding?"UNHOLD":"HOLD",userId:t.agentId};Q(R.HOLD_CALL,i)},qe=()=>{let i={action:t.isMuted?"UNMUTE":"MUTE",userId:t.agentId};de(R.MUTE_CALL,i)},ye=i=>{var B,ae,ie,ue,ge,Le,_e,ko,Oo,Po,Mo,Uo,Bo,Ho,zo,$o;console.log("data",i);let S={action:"ENDCALL",userId:t.agentId,processid:(ie=(ae=(B=t.process)==null?void 0:B.process_id)==null?void 0:ae.toString())!=null?ie:"",process_name:(ge=(ue=t.process)==null?void 0:ue.process_name)!=null?ge:"",callreferenceid:(_e=(Le=t.callData)==null?void 0:Le.convox_id)!=null?_e:"",mobile_number:(Oo=(ko=t.callData)==null?void 0:ko.phone_number)!=null?Oo:"",disposition:(Mo=(Po=i==null?void 0:i.disposition)==null?void 0:Po.value)!=null?Mo:"",set_followUp:(Bo=(Uo=i==null?void 0:i.followUp)==null?void 0:Uo.value)!=null?Bo:"",callback_date:(Ho=i==null?void 0:i.callbackDate)!=null?Ho:"",callback_hrs:(zo=i==null?void 0:i.callbackHrs)!=null?zo:"",callback_mins:($o=i==null?void 0:i.callbackMins)!=null?$o:"",endcall_type:"CLOSE"};D(""),ke(R.END_CALL,S),C.endCall(),U(!1)};return(0,ee.useEffect)(()=>{let i=S=>{S.preventDefault()};return window.addEventListener("beforeunload",i),()=>{window.removeEventListener("beforeunload",i)}},[]),(0,ee.useEffect)(()=>{let i;return t.callData.status&&t.callData.status==="ONCALL"?i=setInterval(()=>{let S=Math.floor((Date.now()-t.callStartTime)/1e3);se(S)},1e3):se(0),()=>{i&&clearInterval(i)}},[t.callData.status]),(0,ee.useEffect)(()=>{if(e&&t.callData){let{process_id:i,process_name:S,status:B,phone_number:ae,agent_id:ie,convox_id:ue}=t.callData;e({phone_number:ae,status:B,callReferenceId:ue,agent_id:ie,process_id:i,process_name:S})}},[t.callData,e]),(0,ee.useEffect)(()=>{t.agentId?oe.post(R.PROCESS_LIST,{userId:t.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}).then(i=>{var S,B;console.log(i.data.data,"res4"),i&&i.data&&((S=i==null?void 0:i.data)==null?void 0:S.length)>1?(O(i.data.data),M(!0)):(C.setProcess((B=i==null?void 0:i.data)==null?void 0:B.data[0]),M(!1))}).catch(i=>{l(i.response.data.message,"error")}):console.log("No agentId available, skipping API call")},[t.agentId]),(0,ee.useEffect)(()=>(t.agentId&&(x.current=new WebSocket(`${Wo.WS}?agent_id=${t.agentId}`),x.current.onopen=()=>{console.log("\u{1F310} WebSocket connection established")},x.current.onmessage=i=>{try{let S=JSON.parse(i.data),B=wn(t==null?void 0:t.conferenceLine,S==null?void 0:S.conferencestatus,S);console.log(B,"\u{1F4CA} Parsed JSON:",S),C.updateCallData(S),C.updateConferenceData([...B]),S.status==="ONCALL"&&(C.startCall(),w||u(!0)),S.status==="WRAPUP"&&C.endCall()}catch(S){console.log("\u{1F4E8} Raw message:",i.data)}},x.current.onclose=()=>{console.log("\u{1F50C} WebSocket connection closed")},x.current.onerror=i=>{console.error("\u274C WebSocket error:",i)}),()=>{var i;(i=x.current)==null||i.close()}),[t.agentId]),!t.isInitialized||!t.process?(0,p.jsx)(f.Box,{children:!!H&&(0,p.jsx)(an,{processList:K,open:H,setOpen:M,handleSelectedProcessor:i=>{C.setProcess(i)}})}):(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(f.Box,{children:(0,p.jsx)(f.Fade,{in:!0,timeout:300,children:(0,p.jsx)(f.Paper,{ref:(rt=t.sdkConfig)!=null&&rt.isDraggable?P:null,elevation:v?4:(ct=t.sdkConfig)!=null&&ct.isDraggable?1:0,sx:{position:(pt=t.sdkConfig)!=null&&pt.isDraggable?"fixed":"relative",left:(dt=t.sdkConfig)!=null&&dt.isDraggable?I.x:"auto",top:(ut=t.sdkConfig)!=null&&ut.isDraggable?I.y:"auto",display:"inline-block",width:"auto",flexShrink:0,whiteSpace:"nowrap",p:.5,borderRadius:3,bgcolor:"background.paper",zIndex:(gt=t.sdkConfig)!=null&&gt.isDraggable?Number.MAX_SAFE_INTEGER:0,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),userSelect:"none"},children:(0,p.jsxs)(f.Box,{sx:{display:"flex",alignItems:"center"},children:[(0,p.jsxs)(f.Box,{sx:{display:"flex",alignItems:"center",gap:1,margin:"0px 10px"},children:[((ft=t.sdkConfig)==null?void 0:ft.isDraggable)&&(0,p.jsxs)(f.IconButton,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:Y,onTouchStart:j,children:[(0,p.jsx)(L.DragIndicator,{})," "]}),(0,p.jsx)(f.Box,{children:!((mt=t.sdkConfig)!=null&&mt.disabledDialButton)&&(0,p.jsx)(f.Tooltip,{title:"Dial",children:(0,p.jsx)(f.IconButton,{size:"small",onClick:i=>{var S,B,ae,ie,ue,ge,Le,_e;((B=(S=t.callData)==null?void 0:S.status)==null?void 0:B.toUpperCase())!=="ONCALL"&&((ie=(ae=t.callData)==null?void 0:ae.status)==null?void 0:ie.toUpperCase())!=="BREAK"&&((ge=(ue=t.callData)==null?void 0:ue.status)==null?void 0:ge.toUpperCase())!=="RINGING"&&((_e=(Le=t.callData)==null?void 0:Le.status)==null?void 0:_e.toUpperCase())!=="WRAPUP"&&Pe(i)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:(0,p.jsx)(L.WifiCalling3,{sx:{color:((Ct=(xt=t.callData)==null?void 0:xt.status)==null?void 0:Ct.toUpperCase())==="ONCALL"||((yt=(bt=t.callData)==null?void 0:bt.status)==null?void 0:yt.toUpperCase())==="BREAK"||((ht=(Et=t.callData)==null?void 0:Et.status)==null?void 0:ht.toUpperCase())==="RINGING"||((Tt=(St=t.callData)==null?void 0:St.status)==null?void 0:Tt.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),(0,p.jsx)(f.Typography,{sx:{color:"success.main",width:"40px",marginRight:"10px",fontSize:"18px",fontWeight:"600"},children:Nn(ne)}),(0,p.jsx)(f.Chip,{sx:{padding:"18px 0px"},label:Ne||Te?(0,p.jsx)(f.Box,{sx:{fontWeight:"bold",width:"60px",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,p.jsx)(f.CircularProgress,{size:"20px"})}):(0,p.jsx)(f.Typography,{variant:"body2",sx:{fontWeight:"bold",width:"60px",textAlign:"center"},children:(Lt=(Dt=(vt=t.callData)==null?void 0:vt.status)==null?void 0:Dt.toUpperCase())!=null?Lt:"N/A"}),onClick:De,deleteIcon:(0,p.jsx)(L.KeyboardArrowDown,{color:"primary"}),onDelete:De})]}),(0,p.jsxs)(f.Box,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[(0,p.jsx)(f.Tooltip,{title:"Agent Ready",children:(0,p.jsx)(f.Button,{variant:((It=(_t=t.callData)==null?void 0:_t.status)==null?void 0:It.toUpperCase())==="BREAK"||((At=(Rt=t.callData)==null?void 0:Rt.status)==null?void 0:At.toUpperCase())==="MISSED"?"outlined":"contained",onClick:i=>{var S,B,ae,ie;(((B=(S=t.callData)==null?void 0:S.status)==null?void 0:B.toUpperCase())==="BREAK"||((ie=(ae=t.callData)==null?void 0:ae.status)==null?void 0:ie.toUpperCase())==="MISSED")&&(i.stopPropagation(),Be())},classes:{root:((Nt=(wt=t.callData)==null?void 0:wt.status)==null?void 0:Nt.toUpperCase())==="BREAK"||((Ot=(kt=t.callData)==null?void 0:kt.status)==null?void 0:Ot.toUpperCase())==="MISSED"?"outlined":"enabled"},sx:d({},((Mt=(Pt=t.callData)==null?void 0:Pt.status)==null?void 0:Mt.toUpperCase())==="BREAK"||((Bt=(Ut=t.callData)==null?void 0:Ut.status)==null?void 0:Bt.toUpperCase())==="MISSED"?c:a),disabled:Te,children:(0,p.jsx)(L.SupportAgent,{})})}),(0,p.jsx)(f.Tooltip,{title:t.isHolding?"Resume":"Hold",children:(0,p.jsx)(f.Button,{variant:t.isHolding&&((zt=(Ht=t.callData)==null?void 0:Ht.status)==null?void 0:zt.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:i=>{i.stopPropagation(),$e()},sx:t.isHolding&&((qt=($t=t.callData)==null?void 0:$t.status)==null?void 0:qt.toUpperCase())==="ONCALL"?d({},a):((Kt=(Ft=t.callData)==null?void 0:Ft.status)==null?void 0:Kt.toUpperCase())==="ONCALL"?d({},c):d({},r),disabled:((Gt=(Wt=t.callData)==null?void 0:Wt.status)==null?void 0:Gt.toUpperCase())!=="ONCALL"&&!t.isHolding||X,children:X?(0,p.jsx)(f.CircularProgress,{size:"20px",sx:{color:o.palette.primary.main}}):t.isHolding?(0,p.jsx)(L.PlayArrow,{}):(0,p.jsx)(L.Pause,{})})}),(0,p.jsx)(f.Tooltip,{title:t.isMuted?"Unmute":"Mute",children:(0,p.jsx)(f.Button,{variant:t.isMuted&&((jt=(Yt=t.callData)==null?void 0:Yt.status)==null?void 0:jt.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:i=>{i.stopPropagation(),qe()},sx:t.isMuted&&((Jt=(Xt=t.callData)==null?void 0:Xt.status)==null?void 0:Jt.toUpperCase())==="ONCALL"?d({},a):((Zt=(Vt=t.callData)==null?void 0:Vt.status)==null?void 0:Zt.toUpperCase())==="ONCALL"?d({},c):d({},r),disabled:((eo=(Qt=t.callData)==null?void 0:Qt.status)==null?void 0:eo.toUpperCase())!=="ONCALL"&&!t.isMuted||Se,children:Se?(0,p.jsx)(f.CircularProgress,{size:"20px",sx:{color:o.palette.primary.main}}):t.isMuted?(0,p.jsx)(L.MicOff,{}):(0,p.jsx)(L.Mic,{})})}),!((to=t.sdkConfig)!=null&&to.disableCallTransferButton)&&(0,p.jsx)(f.Tooltip,{title:"Transfer Call",children:(0,p.jsx)(f.Button,{variant:t.openCallTransferDialog?"contained":"outlined",onClick:i=>{var S,B;((B=(S=t.callData)==null?void 0:S.status)==null?void 0:B.toUpperCase())==="ONCALL"&&(i.stopPropagation(),C.setOpenCallTransferDialog(!0))},sx:t.openCallTransferDialog?d({},a):((no=(oo=t.callData)==null?void 0:oo.status)==null?void 0:no.toUpperCase())==="ONCALL"?d({},c):d({},r),disabled:((ao=(so=t.callData)==null?void 0:so.status)==null?void 0:ao.toUpperCase())!=="ONCALL",children:(0,p.jsx)(L.TransferWithinAStation,{})})}),!((io=t.sdkConfig)!=null&&io.disableConferenceButton)&&(0,p.jsx)(f.Tooltip,{title:"Conference Call",children:(0,p.jsx)(f.Button,{variant:t.openConferenceDialog?"contained":"outlined",onClick:i=>{var S,B;((B=(S=t.callData)==null?void 0:S.status)==null?void 0:B.toUpperCase())==="ONCALL"&&(i.stopPropagation(),C.setOpenConferenceDialog(!0))},sx:t.openConferenceDialog?d({},a):((ro=(lo=t.callData)==null?void 0:lo.status)==null?void 0:ro.toUpperCase())==="ONCALL"?d({},c):d({},r),disabled:((po=(co=t.callData)==null?void 0:co.status)==null?void 0:po.toUpperCase())!=="ONCALL",children:(0,p.jsx)(L.Group,{})})}),!((uo=t.sdkConfig)!=null&&uo.disableEndCallButton)&&(0,p.jsx)(f.Tooltip,{title:"End Call",children:(0,p.jsx)(f.Button,{variant:((fo=(go=t.callData)==null?void 0:go.status)==null?void 0:fo.toUpperCase())==="ONCALL"||((xo=(mo=t.callData)==null?void 0:mo.status)==null?void 0:xo.toUpperCase())==="RINGING"||((bo=(Co=t.callData)==null?void 0:Co.status)==null?void 0:bo.toUpperCase())==="WRAPUP"?"contained":"outlined",onClick:i=>{var S,B,ae,ie,ue,ge;(((B=(S=t.callData)==null?void 0:S.status)==null?void 0:B.toUpperCase())==="ONCALL"||((ie=(ae=t.callData)==null?void 0:ae.status)==null?void 0:ie.toUpperCase())==="RINGING"||((ge=(ue=t.callData)==null?void 0:ue.status)==null?void 0:ge.toUpperCase())==="WRAPUP")&&(i.stopPropagation(),U(!0))},sx:((Eo=(yo=t.callData)==null?void 0:yo.status)==null?void 0:Eo.toUpperCase())==="ONCALL"||((So=(ho=t.callData)==null?void 0:ho.status)==null?void 0:So.toUpperCase())==="RINGING"||((vo=(To=t.callData)==null?void 0:To.status)==null?void 0:vo.toUpperCase())==="WRAPUP"?W(d({},a),{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}`}}):W(d({},r),{minWidth:"60px !important"}),disabled:((Lo=(Do=t.callData)==null?void 0:Do.status)==null?void 0:Lo.toUpperCase())!=="ONCALL"&&((Io=(_o=t.callData)==null?void 0:_o.status)==null?void 0:Io.toUpperCase())!=="RINGING"&&((Ao=(Ro=t.callData)==null?void 0:Ro.status)==null?void 0:Ao.toUpperCase())!=="WRAPUP"||ve,children:ve?(0,p.jsx)(f.CircularProgress,{size:"20px",color:"error"}):(0,p.jsx)(L.CallEnd,{})})})]})]})})})}),(0,p.jsx)(f.Fade,{in:!0,timeout:300,children:(0,p.jsxs)(f.Paper,{ref:V,elevation:J?4:1,sx:{position:"absolute",left:z.x,top:z.y,borderRadius:2,bgcolor:"background.paper",zIndex:Number.MAX_SAFE_INTEGER,transition:o.transitions.create(["box-shadow","transform"],{duration:o.transitions.duration.short}),visibility:w&&!((wo=t.sdkConfig)!=null&&wo.disableSoftPhone)?"visible":"hidden",userSelect:"none"},children:[(0,p.jsxs)(f.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll",padding:"0px 10px"},onMouseDown:k,onTouchStart:_,children:[(0,p.jsx)(L.DragIndicator,{sx:{transform:"rotate(90deg)",color:"#7b7b7b"}})," ",(0,p.jsx)(f.IconButton,{onClick:()=>u(!1),children:(0,p.jsx)(L.Close,{})})]}),(0,p.jsx)(f.Box,{children:(0,p.jsx)("iframe",{src:`https://${Fe}/ConVoxCCS/iframe?agent_id=${t.agentId}&process_id=${(No=t.process)==null?void 0:No.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay",style:{border:"none"}})})]})}),(0,p.jsx)(f.Menu,{anchorEl:m,open:!!m,onClose:Me,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:(0,p.jsxs)(f.Box,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[(0,p.jsx)(f.TextField,{size:"small",value:T,placeholder:"Enter Mobile No.",onChange:i=>{D(i.target.value)}}),(0,p.jsx)(f.IconButton,{color:"info",onClick:()=>{ze(T)},children:Z?(0,p.jsx)(f.CircularProgress,{size:"20px",sx:{color:o.palette.success.main}}):(0,p.jsx)(L.Phone,{color:"success"})})]})}),(0,p.jsx)(f.Menu,{anchorEl:g,open:!!g,onClose:Ue,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:(0,p.jsx)(f.MenuItem,{onClick:()=>He("Lunch"),children:"- Break"})}),(0,p.jsx)(f.Menu,{anchorEl:E,open:!!E,onClose:Oe,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:(0,p.jsxs)(f.Box,{sx:{display:"flex",justifyContent:"flex-start",flexDirection:"column",padding:"0px 10px","&hover":{backgroundColor:"white"}},children:[(0,p.jsx)(f.Chip,{icon:(0,p.jsx)(L.Layers,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),(0,p.jsx)(f.Chip,{icon:(0,p.jsx)(L.Pending,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),(0,p.jsx)(f.Chip,{icon:(0,p.jsx)(L.Upcoming,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!t.openConferenceDialog&&(0,p.jsx)(on,{}),!!t.openCallTransferDialog&&(0,p.jsx)(nn,{open:t.openCallTransferDialog}),!!N&&(0,p.jsx)(sn,{open:N,setOpen:U,onSubmitDisposition:ye}),!!q&&(0,p.jsx)(ln,{open:q,setOpen:te})]})}var cn=require("react");var pn=require("react/jsx-runtime"),ot=(0,cn.memo)(({children:e})=>(0,pn.jsx)(en,{children:e}));ot.displayName="SDKProvider";var nt=require("react/jsx-runtime"),st=(0,Je.memo)(({onDataChange:e})=>{let o=(0,Je.useCallback)(t=>{try{e&&typeof e=="function"&&e(t)}catch(l){console.error("Error in CallControlPanel data change handler:",l)}},[e]);return(0,nt.jsx)(ot,{children:(0,nt.jsx)(rn,{onDataChange:o})})});st.displayName="CallControlPanel";async function kn({apiKey:e,tenantId:o,agentId:t,sdkConfig:l}){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 r=await et.init({apiKey:e.trim(),tenantId:o.trim(),agentId:t.trim(),baseUrl:$});if(r)console.log("SDK initialized successfully"),C.initialize(e.trim(),o.trim(),t.trim(),l,r);else throw console.error("SDK initialization failed: Event tracker initialization returned false"),C.setInitCheck(),new Error("SDK initialization failed: Unable to establish connection with the CTI system")}catch(r){throw console.error("SDK initialization error:",r),C.setInitCheck(),r instanceof Error?r:new Error(`SDK initialization failed: ${String(r)}`)}}function On(){return"6.x.x"}function Pn(){return C.getState().isInitialized}0&&(module.exports={CallControlPanel,getSDKVersion,initSDK,isSDKInitialized,useClickToCall,useEndCall,useGetAuthorizationToken,useGetCallerData,useLogout});
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
+ var __getProtoOf = Object.getPrototypeOf;
10
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
11
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
+ var __spreadValues = (a, b) => {
14
+ for (var prop in b || (b = {}))
15
+ if (__hasOwnProp.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ if (__getOwnPropSymbols)
18
+ for (var prop of __getOwnPropSymbols(b)) {
19
+ if (__propIsEnum.call(b, prop))
20
+ __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
+ var __export = (target, all) => {
26
+ for (var name in all)
27
+ __defProp(target, name, { get: all[name], enumerable: true });
28
+ };
29
+ var __copyProps = (to, from, except, desc) => {
30
+ if (from && typeof from === "object" || typeof from === "function") {
31
+ for (let key of __getOwnPropNames(from))
32
+ if (!__hasOwnProp.call(to, key) && key !== except)
33
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
+ }
35
+ return to;
36
+ };
37
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
38
+ // If the importer is in node compatibility mode or this is not an ESM
39
+ // file that has been converted to a CommonJS file using a Babel-
40
+ // compatible transform (i.e. "__esModule" has not been set), then set
41
+ // "default" to the CommonJS "module.exports" for node compatibility.
42
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
43
+ mod
44
+ ));
45
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
46
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
47
+
48
+ // call-control-sdk/index.ts
49
+ var index_exports = {};
50
+ __export(index_exports, {
51
+ CallControlPanel: () => CallControlPanel,
52
+ getSDKVersion: () => getSDKVersion,
53
+ initSDK: () => initSDK,
54
+ isSDKInitialized: () => isSDKInitialized,
55
+ useClickToCall: () => useClickToCall,
56
+ useEndCall: () => useEndCall,
57
+ useGetAuthorizationToken: () => useGetAuthorizationToken,
58
+ useGetCallerData: () => useGetCallerData,
59
+ useLogout: () => useLogout
60
+ });
61
+ module.exports = __toCommonJS(index_exports);
62
+
63
+ // call-control-sdk/lib/services/endPoint.ts
64
+ var IP = "uat-cti.aighospitals.com";
65
+ var BASE_URL = `https://${IP}:8095`;
66
+ var WS_BASE_URL = `wss://${IP}:8095`;
67
+ var VERSION = {
68
+ v1: "/api/v1"
69
+ };
70
+ var END_POINT = {
71
+ LOGIN: `${BASE_URL}${VERSION.v1}/cti/login?provider=convox`,
72
+ READY_AGENT: `${BASE_URL}${VERSION.v1}/cti/ready-agent?provider=convox`,
73
+ UPDATE_AGENT_BREAK: `${BASE_URL}${VERSION.v1}/cti/update-agent-status?provider=convox`,
74
+ CLICK_TO_CALL: `${BASE_URL}${VERSION.v1}/cti/calls?provider=convox`,
75
+ HOLD_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/hold?provider=convox`,
76
+ MUTE_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/mute?provider=convox`,
77
+ UNMUTE_CALL: `${BASE_URL}${VERSION.v1}/cti/unmute-call?provider=convox`,
78
+ END_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/end?provider=convox`,
79
+ LOGOUT: `${BASE_URL}${VERSION.v1}/cti/logout?provider=convox`,
80
+ CONFERENCE_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/conference?provider=convox`,
81
+ CONFERENCE_CALL_HOLD_OR_UN_HOLD: `${BASE_URL}${VERSION.v1}/cti/calls/conference/hold?provider=convox`,
82
+ CONFERENCE_CALL_MUTE_OT_UN_MUTE: `${BASE_URL}${VERSION.v1}/cti/calls/conference/mute?provider=convox`,
83
+ CONFERENCE_CALL_END: `${BASE_URL}${VERSION.v1}/cti/calls/conference/hangup?provider=convox`,
84
+ CONFERENCE_CALL_END_ALL: `${BASE_URL}${VERSION.v1}/cti/calls/conference/hangup/all?provider=convox`,
85
+ TRANSFER_CALL: `${BASE_URL}${VERSION.v1}/cti/calls/transfer?provider=convox`,
86
+ AGENTS_LIST: `${BASE_URL}${VERSION.v1}/cti/users`,
87
+ PROCESS_LIST: `${BASE_URL}${VERSION.v1}/cti/processes-list`,
88
+ TRANSFER_TO_DETAILS: `${BASE_URL}${VERSION.v1}/cti/transfer-to-details?provider=convox`,
89
+ CALL_HISTORY: `${BASE_URL}${VERSION.v1}/dashboard/call-history`,
90
+ SENTIMENTAL_ANALYSIS: `${BASE_URL}${VERSION.v1}/users/get_sentiment_analysis`
91
+ };
92
+ var WS_END_POINT = {
93
+ WS: `${WS_BASE_URL}${VERSION.v1}/cti/ws`
94
+ };
95
+ var STORAGE_KEY = "call-control-sdk-state";
96
+
97
+ // call-control-sdk/lib/hooks/sdk-state.ts
98
+ var SDKStateManager = class {
99
+ constructor() {
100
+ __publicField(this, "state");
101
+ __publicField(this, "listeners", []);
102
+ __publicField(this, "STORAGE_KEY", STORAGE_KEY);
103
+ __publicField(this, "apiKey");
104
+ __publicField(this, "tenantId");
105
+ this.state = this.getInitialState();
106
+ this.loadFromStorage();
107
+ }
108
+ getInitialState() {
109
+ return {
110
+ authorization: void 0,
111
+ process: null,
112
+ agentId: "",
113
+ openConferenceDialog: false,
114
+ openCallTransferDialog: false,
115
+ isInitialized: false,
116
+ sdkConfig: {
117
+ disableEndCallButton: false,
118
+ disabledDialButton: false,
119
+ disableCallTransferButton: false,
120
+ isDraggable: true,
121
+ disableSoftPhone: false,
122
+ disableConferenceButton: false,
123
+ disabled: {},
124
+ enabled: {},
125
+ outlined: {}
126
+ },
127
+ isHolding: false,
128
+ isMuted: false,
129
+ status: "idle",
130
+ callStartTime: null,
131
+ controlPanelPosition: { x: 10, y: 10 },
132
+ iframePosition: { x: 10, y: 80 },
133
+ callData: {
134
+ agent_id: "",
135
+ status: "",
136
+ type: "",
137
+ event_time: "",
138
+ phone_number: ""
139
+ },
140
+ conferenceLine: [
141
+ {
142
+ line: 1,
143
+ status: "IDLE",
144
+ type: "",
145
+ phone: "",
146
+ isMute: false,
147
+ isHold: false,
148
+ isCallStart: false,
149
+ isMergeCall: false
150
+ },
151
+ {
152
+ line: 2,
153
+ status: "IDLE",
154
+ type: "",
155
+ phone: "",
156
+ isMute: false,
157
+ isHold: false,
158
+ isCallStart: false,
159
+ isMergeCall: false
160
+ },
161
+ {
162
+ line: 3,
163
+ status: "IDLE",
164
+ type: "",
165
+ phone: "",
166
+ isMute: false,
167
+ isHold: false,
168
+ isCallStart: false,
169
+ isMergeCall: false
170
+ },
171
+ {
172
+ line: 4,
173
+ status: "IDLE",
174
+ type: "",
175
+ phone: "",
176
+ isMute: false,
177
+ isHold: false,
178
+ isCallStart: false,
179
+ isMergeCall: false
180
+ },
181
+ {
182
+ line: 5,
183
+ status: "IDLE",
184
+ type: "",
185
+ phone: "",
186
+ isMute: false,
187
+ isHold: false,
188
+ isCallStart: false,
189
+ isMergeCall: false
190
+ }
191
+ ]
192
+ };
193
+ }
194
+ loadFromStorage() {
195
+ try {
196
+ const stored = localStorage.getItem(this.STORAGE_KEY);
197
+ if (stored) {
198
+ const parsedState = JSON.parse(stored);
199
+ this.state = __spreadProps(__spreadValues({}, this.state), {
200
+ agentId: parsedState.agentId || "",
201
+ authorization: parsedState.authorization || void 0,
202
+ process: parsedState.process || null,
203
+ openConferenceDialog: (parsedState == null ? void 0 : parsedState.openConferenceDialog) || false,
204
+ openCallTransferDialog: (parsedState == null ? void 0 : parsedState.openCallTransferDialog) || false,
205
+ isInitialized: parsedState.isInitialized || false,
206
+ sdkConfig: parsedState.sdkConfig || {
207
+ disableEndCallButton: false,
208
+ disabledDialButton: false,
209
+ disableCallTransferButton: false,
210
+ isDraggable: true,
211
+ disableSoftPhone: false,
212
+ disableConferenceButton: false,
213
+ disabled: {},
214
+ enabled: {},
215
+ outlined: {}
216
+ },
217
+ isHolding: parsedState.isHolding || false,
218
+ isMuted: parsedState.isMuted || false,
219
+ status: parsedState.status || "idle",
220
+ callStartTime: parsedState.callStartTime || null,
221
+ controlPanelPosition: parsedState.controlPanelPosition || {
222
+ x: 10,
223
+ y: 10
224
+ },
225
+ iframePosition: parsedState.iframePosition || { x: 10, y: 80 },
226
+ callData: parsedState.callData || {
227
+ mobileNumber: "",
228
+ callReferenceId: "",
229
+ agent_id: "",
230
+ status: "",
231
+ type: "",
232
+ event_time: "",
233
+ phone_number: ""
234
+ },
235
+ // Fix: Properly handle conferenceLine with fallback to initial state
236
+ conferenceLine: parsedState.conferenceLine && Array.isArray(parsedState.conferenceLine) && parsedState.conferenceLine.length > 0 ? parsedState.conferenceLine : this.state.conferenceLine
237
+ });
238
+ }
239
+ } catch (error) {
240
+ console.warn("Failed to load SDK state from localStorage:", error);
241
+ }
242
+ }
243
+ saveToStorage() {
244
+ try {
245
+ const persistentState = {
246
+ agentId: this.state.agentId,
247
+ authorization: this.state.authorization,
248
+ process: this.state.process,
249
+ isInitialized: this.state.isInitialized,
250
+ openConferenceDialog: this.state.openConferenceDialog,
251
+ openCallTransferDialog: this.state.openCallTransferDialog,
252
+ sdkConfig: this.state.sdkConfig,
253
+ isHolding: this.state.isHolding,
254
+ isMuted: this.state.isMuted,
255
+ status: this.state.status,
256
+ callStartTime: this.state.callStartTime,
257
+ controlPanelPosition: this.state.controlPanelPosition,
258
+ iframePosition: this.state.iframePosition,
259
+ callData: this.state.callData,
260
+ conferenceLine: this.state.conferenceLine
261
+ };
262
+ localStorage.setItem(this.STORAGE_KEY, JSON.stringify(persistentState));
263
+ } catch (error) {
264
+ console.warn("Failed to save SDK state to localStorage:", error);
265
+ }
266
+ }
267
+ notifyListeners() {
268
+ this.listeners.forEach((listener) => listener());
269
+ }
270
+ validateCredentials(apiKey, tenantId) {
271
+ if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
272
+ throw new Error("API key not available");
273
+ }
274
+ if (!tenantId || typeof tenantId !== "string" || tenantId.trim().length === 0) {
275
+ throw new Error("Tenant ID not available");
276
+ }
277
+ this.apiKey = apiKey.trim();
278
+ this.tenantId = tenantId.trim();
279
+ }
280
+ initialize(apiKey, tenantId, agentId, sdkConfig, initResult) {
281
+ this.validateCredentials(apiKey, tenantId);
282
+ if (!agentId || typeof agentId !== "string" || agentId.trim().length === 0) {
283
+ throw new Error("Agent ID not available");
284
+ } else {
285
+ this.state.agentId = agentId;
286
+ this.state.openConferenceDialog = false;
287
+ this.state.openCallTransferDialog = false;
288
+ this.state.authorization = initResult;
289
+ this.state.sdkConfig = __spreadValues({
290
+ disableEndCallButton: false,
291
+ disabledDialButton: false,
292
+ disableCallTransferButton: false,
293
+ isDraggable: true,
294
+ disableSoftPhone: false,
295
+ disableConferenceButton: false,
296
+ disabled: {},
297
+ enabled: {},
298
+ outlined: {}
299
+ }, sdkConfig);
300
+ this.state.isInitialized = true;
301
+ this.saveToStorage();
302
+ this.notifyListeners();
303
+ }
304
+ }
305
+ getState() {
306
+ return __spreadValues({}, this.state);
307
+ }
308
+ getCredentials() {
309
+ return { apiKey: this.apiKey, tenantId: this.tenantId };
310
+ }
311
+ getSdkAuthToken() {
312
+ var _a2;
313
+ return (_a2 = this.state.authorization) == null ? void 0 : _a2.accessToken;
314
+ }
315
+ subscribe(listener) {
316
+ this.listeners.push(listener);
317
+ return () => {
318
+ const index = this.listeners.indexOf(listener);
319
+ if (index > -1) {
320
+ this.listeners.splice(index, 1);
321
+ }
322
+ };
323
+ }
324
+ setHolding(isHolding) {
325
+ this.state.isHolding = isHolding;
326
+ this.saveToStorage();
327
+ this.notifyListeners();
328
+ }
329
+ setMuted(isMuted) {
330
+ this.state.isMuted = isMuted;
331
+ this.saveToStorage();
332
+ this.notifyListeners();
333
+ }
334
+ setStatus(status) {
335
+ this.state.status = status;
336
+ this.saveToStorage();
337
+ this.notifyListeners();
338
+ }
339
+ setProcess(process) {
340
+ this.state.process = process;
341
+ this.saveToStorage();
342
+ this.notifyListeners();
343
+ }
344
+ setControlPanelPosition(position) {
345
+ this.state.controlPanelPosition = position;
346
+ this.saveToStorage();
347
+ this.notifyListeners();
348
+ }
349
+ setIframePosition(position) {
350
+ this.state.iframePosition = position;
351
+ this.saveToStorage();
352
+ this.notifyListeners();
353
+ }
354
+ startCall() {
355
+ this.state.callStartTime = Date.now();
356
+ this.state.status = "on call";
357
+ this.saveToStorage();
358
+ this.notifyListeners();
359
+ }
360
+ endCall() {
361
+ this.state.callStartTime = null;
362
+ this.state.status = "idle";
363
+ this.state.isHolding = false;
364
+ this.state.isMuted = false;
365
+ this.saveToStorage();
366
+ this.notifyListeners();
367
+ }
368
+ setInitCheck() {
369
+ this.state.isInitialized = false;
370
+ this.saveToStorage();
371
+ this.notifyListeners();
372
+ }
373
+ setOpenConferenceDialog(open) {
374
+ this.state.openConferenceDialog = open;
375
+ this.saveToStorage();
376
+ this.notifyListeners();
377
+ }
378
+ setOpenCallTransferDialog(open) {
379
+ this.state.openCallTransferDialog = open;
380
+ this.saveToStorage();
381
+ this.notifyListeners();
382
+ }
383
+ updateCallData(data) {
384
+ this.state.callData = __spreadValues(__spreadValues({}, this.state.callData), data);
385
+ this.saveToStorage();
386
+ this.notifyListeners();
387
+ }
388
+ updateConferenceData(data) {
389
+ this.state.conferenceLine = [...data];
390
+ this.saveToStorage();
391
+ this.notifyListeners();
392
+ }
393
+ setConferenceLine(line) {
394
+ var _a2;
395
+ if (!this.state.conferenceLine || !Array.isArray(this.state.conferenceLine)) {
396
+ console.warn("Conference line data corrupted, resetting to initial state");
397
+ this.state.conferenceLine = this.getInitialState().conferenceLine;
398
+ }
399
+ const conferenceLineData = (_a2 = this.state.conferenceLine) == null ? void 0 : _a2.map((each) => {
400
+ if (each.line === line.line) {
401
+ return line;
402
+ }
403
+ return each;
404
+ });
405
+ this.state.conferenceLine = conferenceLineData;
406
+ this.saveToStorage();
407
+ this.notifyListeners();
408
+ }
409
+ resetConferenceLines() {
410
+ this.state.conferenceLine = this.getInitialState().conferenceLine;
411
+ this.saveToStorage();
412
+ this.notifyListeners();
413
+ }
414
+ clearStorageAndReset() {
415
+ try {
416
+ localStorage.removeItem(this.STORAGE_KEY);
417
+ this.state = this.getInitialState();
418
+ this.notifyListeners();
419
+ } catch (error) {
420
+ console.warn("Failed to clear localStorage:", error);
421
+ }
422
+ }
423
+ debugStorage() {
424
+ try {
425
+ const stored = localStorage.getItem(this.STORAGE_KEY);
426
+ console.log("Current localStorage data:", stored);
427
+ if (stored) {
428
+ console.log("Parsed localStorage data:", JSON.parse(stored));
429
+ }
430
+ console.log("Current state:", this.state);
431
+ } catch (error) {
432
+ console.error("Error debugging storage:", error);
433
+ }
434
+ }
435
+ getConferenceLines() {
436
+ return this.state.conferenceLine || [];
437
+ }
438
+ };
439
+ var sdkStateManager = new SDKStateManager();
440
+
441
+ // call-control-sdk/lib/hooks/eventsTracker.ts
442
+ var EventTrackerSDK = class {
443
+ constructor() {
444
+ __publicField(this, "config", null);
445
+ __publicField(this, "ticketId", null);
446
+ __publicField(this, "baseUrl", "");
447
+ __publicField(this, "eventQueue", []);
448
+ // private isOnline: boolean = true;
449
+ // private retryQueue: Array<() => Promise<void>> = [];
450
+ __publicField(this, "flushTimer", null);
451
+ }
452
+ async init(config) {
453
+ this.config = __spreadValues({
454
+ autoTrack: true,
455
+ retryAttempts: 3,
456
+ queueSize: 100,
457
+ flushInterval: 5e3
458
+ }, config);
459
+ this.baseUrl = config.baseUrl || (typeof window !== "undefined" ? window.location.origin : "");
460
+ this.setupNetworkDetection();
461
+ const ticket = await this.createTicket();
462
+ this.startPeriodicFlush();
463
+ console.log("EventTracker SDK initialized successfully");
464
+ return ticket;
465
+ }
466
+ isInitialized() {
467
+ return this.config !== null && this.ticketId !== null;
468
+ }
469
+ getConfig() {
470
+ return this.config;
471
+ }
472
+ getTicketId() {
473
+ return this.ticketId;
474
+ }
475
+ async createTicket() {
476
+ if (!this.config) {
477
+ throw new Error("EventTracker not initialized");
478
+ }
479
+ try {
480
+ const response = await this.makeRequest("/api/v1/et/init", {
481
+ method: "POST",
482
+ headers: {
483
+ "Content-Type": "application/json",
484
+ "X-API-Key": this.config.apiKey
485
+ },
486
+ body: JSON.stringify({
487
+ agentId: this.config.agentId,
488
+ sessionId: this.config.sessionId
489
+ })
490
+ });
491
+ if (!response.ok) {
492
+ sdkStateManager.setInitCheck();
493
+ throw new Error(`Failed to initialize: ${response.status} ${response.statusText}`);
494
+ }
495
+ const data = await response.json();
496
+ this.ticketId = data.ticketId;
497
+ if (this.config.autoTrack) {
498
+ this.setupAutoTracking();
499
+ }
500
+ return data;
501
+ } catch (error) {
502
+ console.error("EventTracker initialization failed:", error);
503
+ throw error;
504
+ }
505
+ }
506
+ async logEvent(eventType, eventData) {
507
+ if (!this.config || !this.ticketId) {
508
+ console.warn("EventTracker not initialized, skipping event:", eventType);
509
+ return;
510
+ }
511
+ const event = {
512
+ eventType,
513
+ eventData,
514
+ timestamp: Date.now()
515
+ };
516
+ this.eventQueue.push(event);
517
+ if (this.eventQueue.length > (this.config.queueSize || 100)) {
518
+ this.eventQueue.shift();
519
+ }
520
+ }
521
+ // private async sendEvent(event: {
522
+ // eventType: string;
523
+ // eventData?: EventData;
524
+ // timestamp: number;
525
+ // }): Promise<void> {
526
+ // if (!this.config || !this.ticketId) return;
527
+ // try {
528
+ // const response = await this.makeRequest("/api/v1/et/event", {
529
+ // method: "POST",
530
+ // headers: {
531
+ // "Content-Type": "application/json",
532
+ // "X-API-Key": this.config.apiKey,
533
+ // },
534
+ // body: JSON.stringify({
535
+ // ticketId: this.ticketId,
536
+ // eventType: event.eventType,
537
+ // eventData: event.eventData,
538
+ // }),
539
+ // });
540
+ // if (!response.ok) {
541
+ // throw new Error(`Failed to log event: ${response.status} ${response.statusText}`);
542
+ // }
543
+ // const index = this.eventQueue.findIndex((e) => e.timestamp === event.timestamp);
544
+ // if (index > -1) {
545
+ // this.eventQueue.splice(index, 1);
546
+ // }
547
+ // } catch (error) {
548
+ // console.error("Event logging failed:", error);
549
+ // // this.retryQueue.push(() => this.sendEvent(event));
550
+ // }
551
+ // }
552
+ // async closeTicket(): Promise<void> {
553
+ // if (!this.config || !this.ticketId) {
554
+ // throw new Error("EventTracker not initialized");
555
+ // }
556
+ // await this.flush();
557
+ // try {
558
+ // const response = await this.makeRequest("/api/v1/et/close", {
559
+ // method: "POST",
560
+ // headers: {
561
+ // "Content-Type": "application/json",
562
+ // "X-API-Key": this.config.apiKey,
563
+ // },
564
+ // body: JSON.stringify({
565
+ // ticketId: this.ticketId,
566
+ // }),
567
+ // });
568
+ // if (!response.ok) {
569
+ // throw new Error(`Failed to close ticket: ${response.status} ${response.statusText}`);
570
+ // }
571
+ // this.ticketId = null;
572
+ // this.stopPeriodicFlush();
573
+ // console.log("Ticket closed successfully");
574
+ // } catch (error) {
575
+ // console.error("Ticket close failed:", error);
576
+ // throw error;
577
+ // }
578
+ // }
579
+ // async flush(): Promise<void> {
580
+ // if (!this.isOnline || this.eventQueue.length === 0) return;
581
+ // // const eventsToFlush = [...this.eventQueue];
582
+ // // for (const event of eventsToFlush) {
583
+ // // await this.sendEvent(event);
584
+ // // }
585
+ // const retryItems = [...this.retryQueue];
586
+ // this.retryQueue = [];
587
+ // for (const retryFn of retryItems) {
588
+ // try {
589
+ // await retryFn();
590
+ // } catch (error) {
591
+ // console.error("Retry failed:", error);
592
+ // }
593
+ // }
594
+ // }
595
+ async makeRequest(url, options) {
596
+ var _a2;
597
+ const fullUrl = `${this.baseUrl}${url}`;
598
+ const maxRetries = ((_a2 = this.config) == null ? void 0 : _a2.retryAttempts) || 3;
599
+ for (let attempt = 1; attempt <= maxRetries; attempt++) {
600
+ try {
601
+ const response = await fetch(fullUrl, options);
602
+ return response;
603
+ } catch (error) {
604
+ if (attempt === maxRetries) {
605
+ throw error;
606
+ }
607
+ const delay = Math.min(1e3 * Math.pow(2, attempt - 1), 1e4);
608
+ await new Promise((resolve) => setTimeout(resolve, delay));
609
+ }
610
+ }
611
+ throw new Error("Max retries exceeded");
612
+ }
613
+ setupAutoTracking() {
614
+ var _a2;
615
+ if (typeof window === "undefined" || !((_a2 = this.config) == null ? void 0 : _a2.autoTrack)) return;
616
+ const autoTrackConfig = this.config.autoTrack === true ? {} : this.config.autoTrack;
617
+ if (autoTrackConfig.pageVisits !== false) {
618
+ this.logEvent("pageVisit", {
619
+ url: window.location.href,
620
+ title: document.title,
621
+ referrer: document.referrer,
622
+ userAgent: navigator.userAgent,
623
+ viewport: {
624
+ width: window.innerWidth,
625
+ height: window.innerHeight
626
+ },
627
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
628
+ }).catch((error) => console.warn("Failed to track page visit:", error));
629
+ }
630
+ if (autoTrackConfig.clicks !== false) {
631
+ document.addEventListener("click", (event) => {
632
+ var _a3;
633
+ const target = event.target;
634
+ if (target.tagName === "BUTTON" || target.tagName === "A" || target.onclick || target.getAttribute("role") === "button" || target instanceof HTMLButtonElement && target.type === "button") {
635
+ this.logEvent("click", {
636
+ element: target.tagName,
637
+ text: (_a3 = target.textContent) == null ? void 0 : _a3.trim().substring(0, 100),
638
+ href: target.getAttribute("href"),
639
+ id: target.id,
640
+ className: target.className,
641
+ role: target.getAttribute("role"),
642
+ position: {
643
+ x: event.clientX,
644
+ y: event.clientY
645
+ },
646
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
647
+ }).catch((error) => console.warn("Failed to track click:", error));
648
+ }
649
+ });
650
+ }
651
+ if (autoTrackConfig.forms !== false) {
652
+ document.addEventListener("submit", (event) => {
653
+ const target = event.target;
654
+ const formData = new FormData(target);
655
+ const formFields = {};
656
+ formData.forEach((value, key) => {
657
+ formFields[key] = value.toString();
658
+ });
659
+ this.logEvent("formSubmission", {
660
+ formId: target.id,
661
+ action: target.action,
662
+ method: target.method,
663
+ fields: Object.keys(formFields),
664
+ fieldCount: Object.keys(formFields).length,
665
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
666
+ }).catch((error) => console.warn("Failed to track form submission:", error));
667
+ });
668
+ }
669
+ if (autoTrackConfig.inputs !== false) {
670
+ let inputTimer;
671
+ document.addEventListener("input", (event) => {
672
+ const target = event.target;
673
+ if (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT") {
674
+ clearTimeout(inputTimer);
675
+ inputTimer = setTimeout(() => {
676
+ var _a3;
677
+ this.logEvent("fieldChange", {
678
+ element: target.tagName,
679
+ type: target.getAttribute("type"),
680
+ name: target.getAttribute("name"),
681
+ id: target.id,
682
+ valueLength: ((_a3 = target.value) == null ? void 0 : _a3.length) || 0,
683
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
684
+ }).catch((error) => console.warn("Failed to track field change:", error));
685
+ }, 1e3);
686
+ }
687
+ });
688
+ }
689
+ const sessionStartTime = Date.now();
690
+ window.addEventListener("beforeunload", () => {
691
+ const sessionDuration = Date.now() - sessionStartTime;
692
+ this.logEvent("pageUnload", {
693
+ url: window.location.href,
694
+ sessionDuration,
695
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
696
+ });
697
+ });
698
+ if (autoTrackConfig.visibility !== false) {
699
+ document.addEventListener("visibilitychange", () => {
700
+ this.logEvent("visibilityChange", {
701
+ hidden: document.hidden,
702
+ visibilityState: document.visibilityState,
703
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
704
+ });
705
+ });
706
+ }
707
+ if (autoTrackConfig.errors !== false) {
708
+ window.addEventListener("error", (event) => {
709
+ this.logEvent("jsError", {
710
+ message: event.message,
711
+ filename: event.filename,
712
+ lineno: event.lineno,
713
+ colno: event.colno,
714
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
715
+ });
716
+ });
717
+ window.addEventListener("unhandledrejection", (event) => {
718
+ var _a3;
719
+ this.logEvent("unhandledRejection", {
720
+ reason: (_a3 = event.reason) == null ? void 0 : _a3.toString(),
721
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
722
+ });
723
+ });
724
+ }
725
+ if (autoTrackConfig.performance !== false && typeof window.performance !== "undefined" && window.performance.navigation) {
726
+ window.addEventListener("load", () => {
727
+ setTimeout(() => {
728
+ const navigation = window.performance.navigation;
729
+ const timing = window.performance.timing;
730
+ this.logEvent("performanceMetrics", {
731
+ navigationTime: timing.navigationStart,
732
+ loadTime: timing.loadEventEnd - timing.navigationStart,
733
+ domReady: timing.domContentLoadedEventEnd - timing.navigationStart,
734
+ renderTime: timing.loadEventEnd - timing.domContentLoadedEventEnd,
735
+ navigationType: navigation.type,
736
+ redirectCount: navigation.redirectCount,
737
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
738
+ });
739
+ }, 1e3);
740
+ });
741
+ }
742
+ }
743
+ setupNetworkDetection() {
744
+ if (typeof window === "undefined") return;
745
+ window.addEventListener("online", () => {
746
+ console.log("EventTracker: Back online, flushing queued events");
747
+ });
748
+ window.addEventListener("offline", () => {
749
+ console.log("EventTracker: Offline, queueing events");
750
+ });
751
+ }
752
+ startPeriodicFlush() {
753
+ if (this.flushTimer) {
754
+ clearInterval(this.flushTimer);
755
+ }
756
+ }
757
+ // private stopPeriodicFlush(): void {
758
+ // if (this.flushTimer) {
759
+ // clearInterval(this.flushTimer);
760
+ // this.flushTimer = null;
761
+ // }
762
+ // }
763
+ };
764
+ var eventTracker = new EventTrackerSDK();
765
+ if (typeof window !== "undefined") {
766
+ window.EventTracker = eventTracker;
767
+ }
768
+
769
+ // call-control-sdk/lib/hooks/useLogout.ts
770
+ var import_react = require("react");
771
+
772
+ // call-control-sdk/lib/services/axios.ts
773
+ var import_axios = __toESM(require("axios"));
774
+ var _a;
775
+ var DEFAULT_TOKEN = (_a = sdkStateManager.getSdkAuthToken()) != null ? _a : "";
776
+ var REQUEST_TIMEOUT = 6e4;
777
+ function getAuthToken() {
778
+ var _a2;
779
+ return (_a2 = sdkStateManager.getSdkAuthToken()) != null ? _a2 : "";
780
+ }
781
+ function createAxiosInstance() {
782
+ var _a2, _b, _c, _d;
783
+ const instance = import_axios.default.create({
784
+ baseURL: BASE_URL,
785
+ headers: {
786
+ "Content-Type": "application/json",
787
+ Accept: "application/json",
788
+ "x-tenant-id": (_b = (_a2 = sdkStateManager.getCredentials()) == null ? void 0 : _a2.tenantId) != null ? _b : "",
789
+ "x-api-key": (_d = (_c = sdkStateManager.getCredentials()) == null ? void 0 : _c.apiKey) != null ? _d : "",
790
+ Authorization: `${DEFAULT_TOKEN}`
791
+ },
792
+ timeout: REQUEST_TIMEOUT,
793
+ withCredentials: false
794
+ });
795
+ instance.interceptors.request.use(
796
+ (config) => {
797
+ const token = getAuthToken();
798
+ if (token && config.headers) {
799
+ config.headers.Authorization = `${token}`;
800
+ }
801
+ config.metadata = { startTime: (/* @__PURE__ */ new Date()).getTime() };
802
+ return config;
803
+ },
804
+ (error) => {
805
+ console.error("Request interceptor error:", error);
806
+ return Promise.reject(error);
807
+ }
808
+ );
809
+ instance.interceptors.response.use(
810
+ (response) => {
811
+ var _a3;
812
+ const endTime = (/* @__PURE__ */ new Date()).getTime();
813
+ const startTime = (_a3 = response.config.metadata) == null ? void 0 : _a3.startTime;
814
+ if (startTime) {
815
+ console.log(`Request to ${response.config.url} took ${endTime - startTime}ms`);
816
+ }
817
+ return response;
818
+ },
819
+ async (error) => {
820
+ var _a3;
821
+ const originalRequest = error.config;
822
+ if (((_a3 = error.response) == null ? void 0 : _a3.status) === 401 && !originalRequest._retry) {
823
+ sdkStateManager.setInitCheck();
824
+ console.warn("Unauthorized request, attempting retry...");
825
+ }
826
+ if (!error.response) {
827
+ console.error("Network error:", error.message);
828
+ error.message = "Network error: Please check your internet connection";
829
+ }
830
+ if (error.response && error.response.status >= 500) {
831
+ console.error("Server error:", error.response.status, error.response.data);
832
+ error.message = "Server error: Please try again later";
833
+ }
834
+ return Promise.reject(error);
835
+ }
836
+ );
837
+ return instance;
838
+ }
839
+ var axiosInstance = createAxiosInstance();
840
+ var axios_default = axiosInstance;
841
+
842
+ // call-control-sdk/lib/hooks/useLogout.ts
843
+ var useLogout = () => {
844
+ const [loading, setLoading] = (0, import_react.useState)(false);
845
+ const [success, setSuccess] = (0, import_react.useState)(false);
846
+ const [isError, setIsError] = (0, import_react.useState)(false);
847
+ const [error, setError] = (0, import_react.useState)(null);
848
+ const [data, setData] = (0, import_react.useState)(null);
849
+ const handleLogout = (0, import_react.useCallback)(async () => {
850
+ var _a2;
851
+ const state = JSON.parse((_a2 = localStorage.getItem(STORAGE_KEY)) != null ? _a2 : "");
852
+ setLoading(true);
853
+ const payload = {
854
+ action: "LOGOUTUSER",
855
+ userId: state.agentId || ""
856
+ };
857
+ return axios_default.post(END_POINT.LOGOUT, payload).then((res) => {
858
+ sdkStateManager.clearStorageAndReset();
859
+ localStorage.clear();
860
+ sessionStorage.clear();
861
+ setData(res == null ? void 0 : res.data);
862
+ setSuccess(true);
863
+ return res == null ? void 0 : res.data;
864
+ }).catch((err) => {
865
+ var _a3;
866
+ setIsError(true);
867
+ setError(err);
868
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
869
+ }).finally(() => {
870
+ setLoading(false);
871
+ });
872
+ }, []);
873
+ return {
874
+ logout: handleLogout,
875
+ isLoading: loading,
876
+ isSuccess: success,
877
+ isError,
878
+ error,
879
+ data
880
+ };
881
+ };
882
+
883
+ // call-control-sdk/lib/hooks/useEndCall.ts
884
+ var import_react2 = require("react");
885
+ var useEndCall = () => {
886
+ const [loading, setLoading] = (0, import_react2.useState)(false);
887
+ const [success, setSuccess] = (0, import_react2.useState)(false);
888
+ const [isError, setIsError] = (0, import_react2.useState)(false);
889
+ const [error, setError] = (0, import_react2.useState)(null);
890
+ const [data, setData] = (0, import_react2.useState)(null);
891
+ const handleEndCall = (0, import_react2.useCallback)(
892
+ async (data2) => {
893
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
894
+ const state = JSON.parse((_a2 = localStorage.getItem(STORAGE_KEY)) != null ? _a2 : "");
895
+ setLoading(true);
896
+ const payload = {
897
+ action: "ENDCALL",
898
+ userId: state == null ? void 0 : state.agentId,
899
+ processid: (_d = (_c = (_b = state == null ? void 0 : state.process) == null ? void 0 : _b.process_id) == null ? void 0 : _c.toString()) != null ? _d : "",
900
+ process_name: (_f = (_e = state == null ? void 0 : state.process) == null ? void 0 : _e.process_name) != null ? _f : "",
901
+ callreferenceid: (_h = (_g = state == null ? void 0 : state.callData) == null ? void 0 : _g.convox_id) != null ? _h : "",
902
+ mobile_number: (_j = (_i = state == null ? void 0 : state.callData) == null ? void 0 : _i.phone_number) != null ? _j : "",
903
+ disposition: (_k = data2 == null ? void 0 : data2.disposition) != null ? _k : "RES",
904
+ set_followUp: (_l = data2 == null ? void 0 : data2.followUp) != null ? _l : "N",
905
+ callback_date: (_m = data2 == null ? void 0 : data2.callbackDate) != null ? _m : "",
906
+ callback_hrs: (_n = data2 == null ? void 0 : data2.callbackHrs) != null ? _n : "",
907
+ callback_mins: (_o = data2 == null ? void 0 : data2.callbackMins) != null ? _o : "",
908
+ endcall_type: "CLOSE"
909
+ };
910
+ return axios_default.post(END_POINT.END_CALL, payload).then((res) => {
911
+ sdkStateManager.endCall();
912
+ setData(res == null ? void 0 : res.data);
913
+ setSuccess(true);
914
+ return res == null ? void 0 : res.data;
915
+ }).catch((err) => {
916
+ var _a3;
917
+ setIsError(true);
918
+ setError(err);
919
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
920
+ }).finally(() => {
921
+ setLoading(false);
922
+ });
923
+ },
924
+ []
925
+ );
926
+ return {
927
+ handleEndCall,
928
+ isLoading: loading,
929
+ isSuccess: success,
930
+ isError,
931
+ error,
932
+ data
933
+ };
934
+ };
935
+
936
+ // call-control-sdk/lib/hooks/useClickToCall.ts
937
+ var import_react3 = require("react");
938
+ var useClickToCall = () => {
939
+ const [loading, setLoading] = (0, import_react3.useState)(false);
940
+ const [success, setSuccess] = (0, import_react3.useState)(false);
941
+ const [isError, setIsError] = (0, import_react3.useState)(false);
942
+ const [error, setError] = (0, import_react3.useState)(null);
943
+ const [data, setData] = (0, import_react3.useState)(null);
944
+ const handleStartCall = (0, import_react3.useCallback)(async (data2) => {
945
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
946
+ const state = JSON.parse((_a2 = localStorage.getItem(STORAGE_KEY)) != null ? _a2 : "");
947
+ setLoading(true);
948
+ if (((_b = state == null ? void 0 : state.callData) == null ? void 0 : _b.status) === "IDLE") {
949
+ const payload = {
950
+ action: "CALL",
951
+ userId: state == null ? void 0 : state.agentId,
952
+ phone_number: data2 == null ? void 0 : data2.mobileNumber
953
+ };
954
+ return axios_default.post(END_POINT.CLICK_TO_CALL, payload).then((res) => {
955
+ setData(res == null ? void 0 : res.data);
956
+ setSuccess(true);
957
+ return res == null ? void 0 : res.data;
958
+ }).catch((err) => {
959
+ var _a3;
960
+ setIsError(true);
961
+ setError(err);
962
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
963
+ }).finally(() => {
964
+ setLoading(false);
965
+ });
966
+ } else if (((_c = state == null ? void 0 : state.callData) == null ? void 0 : _c.status) === "ONCALL") {
967
+ const line_used = (_e = (_d = state == null ? void 0 : state.conferenceLine) == null ? void 0 : _d.filter((each) => each.line !== 1)) == null ? void 0 : _e.find((each) => each.status === "IDLE" && !(each == null ? void 0 : each.isCallStart));
968
+ const payload = {
969
+ action: "EXTERNAL_CONFERENCE",
970
+ operation: `CALL${line_used.line}`,
971
+ line_used: String(line_used.line),
972
+ thirdparty_no: data2 == null ? void 0 : data2.mobileNumber,
973
+ userid: (_g = (_f = state.callData) == null ? void 0 : _f.agent_id) != null ? _g : "",
974
+ process: (_i = (_h = state.callData) == null ? void 0 : _h.process_name) != null ? _i : ""
975
+ };
976
+ return axios_default.post(END_POINT.CONFERENCE_CALL, payload).then((res) => {
977
+ setData(res == null ? void 0 : res.data);
978
+ setSuccess(true);
979
+ sdkStateManager.setConferenceLine(__spreadProps(__spreadValues({}, line_used), {
980
+ isCallStart: true,
981
+ status: "ONCALL",
982
+ phone: data2 == null ? void 0 : data2.mobileNumber
983
+ }));
984
+ sdkStateManager.setOpenConferenceDialog(true);
985
+ return res == null ? void 0 : res.data;
986
+ }).catch((err) => {
987
+ var _a3;
988
+ setIsError(true);
989
+ setError(err);
990
+ return (_a3 = err == null ? void 0 : err.response) == null ? void 0 : _a3.data;
991
+ }).finally(() => {
992
+ setLoading(false);
993
+ });
994
+ } else {
995
+ alert("Agent is not ready");
996
+ }
997
+ }, []);
998
+ return {
999
+ handleStartCall,
1000
+ isLoading: loading,
1001
+ isSuccess: success,
1002
+ isError,
1003
+ error,
1004
+ data
1005
+ };
1006
+ };
1007
+
1008
+ // call-control-sdk/lib/hooks/useGetCallerData.ts
1009
+ var import_react4 = require("react");
1010
+ var useGetCallerData = () => {
1011
+ const { process_id, process_name, status, phone_number, agent_id, convox_id } = sdkStateManager.getState().callData;
1012
+ const initialCallData = {
1013
+ phone_number,
1014
+ status,
1015
+ callReferenceId: convox_id,
1016
+ agent_id,
1017
+ process_id,
1018
+ process_name
1019
+ };
1020
+ const [callData, setCallData] = (0, import_react4.useState)(initialCallData);
1021
+ (0, import_react4.useEffect)(() => {
1022
+ const unsubscribe = sdkStateManager.subscribe(() => {
1023
+ const { process_id: process_id2, process_name: process_name2, status: status2, phone_number: phone_number2, agent_id: agent_id2, convox_id: convox_id2 } = sdkStateManager.getState().callData;
1024
+ const currentCallData = {
1025
+ phone_number: phone_number2,
1026
+ status: status2,
1027
+ callReferenceId: convox_id2,
1028
+ agent_id: agent_id2,
1029
+ process_id: process_id2,
1030
+ process_name: process_name2
1031
+ };
1032
+ setCallData(currentCallData);
1033
+ });
1034
+ return unsubscribe;
1035
+ }, []);
1036
+ return callData;
1037
+ };
1038
+
1039
+ // call-control-sdk/lib/hooks/useGetAuthorizationToken.ts
1040
+ var import_react5 = require("react");
1041
+ var useGetAuthorizationToken = () => {
1042
+ const [token, setToken] = (0, import_react5.useState)(sdkStateManager.getSdkAuthToken());
1043
+ (0, import_react5.useEffect)(() => {
1044
+ const unsubscribe = sdkStateManager.subscribe(() => {
1045
+ setToken(sdkStateManager.getSdkAuthToken());
1046
+ });
1047
+ return unsubscribe;
1048
+ }, []);
1049
+ return token;
1050
+ };
1051
+
1052
+ // call-control-sdk/lib/components/callControlPanel.tsx
1053
+ var import_react13 = require("react");
1054
+
1055
+ // call-control-sdk/lib/components/callControls.tsx
1056
+ var import_icons_material2 = require("@mui/icons-material");
1057
+ var import_material4 = require("@mui/material");
1058
+ var import_react11 = require("react");
1059
+
1060
+ // call-control-sdk/lib/hooks/useDraggable.ts
1061
+ var import_react6 = require("react");
1062
+ function useDraggable(initialPosition, onPositionChange) {
1063
+ const [position, setPosition] = (0, import_react6.useState)(initialPosition);
1064
+ const [isDragging, setIsDragging] = (0, import_react6.useState)(false);
1065
+ const dragRef = (0, import_react6.useRef)();
1066
+ const dragStart = (0, import_react6.useRef)({ x: 0, y: 0 });
1067
+ const elementStart = (0, import_react6.useRef)({ x: 0, y: 0 });
1068
+ const updatePosition = (0, import_react6.useCallback)(
1069
+ (newPosition) => {
1070
+ const element = dragRef.current;
1071
+ if (!element) return;
1072
+ const rect = element.getBoundingClientRect();
1073
+ const viewportWidth = window.innerWidth;
1074
+ const viewportHeight = window.innerHeight;
1075
+ const constrainedPosition = {
1076
+ x: Math.max(0, Math.min(newPosition.x, viewportWidth - rect.width)),
1077
+ y: Math.max(0, Math.min(newPosition.y, viewportHeight - rect.height))
1078
+ };
1079
+ setPosition(constrainedPosition);
1080
+ onPositionChange == null ? void 0 : onPositionChange(constrainedPosition);
1081
+ },
1082
+ [onPositionChange]
1083
+ );
1084
+ const handleStart = (0, import_react6.useCallback)(
1085
+ (clientX, clientY) => {
1086
+ setIsDragging(true);
1087
+ dragStart.current = { x: clientX, y: clientY };
1088
+ elementStart.current = position;
1089
+ const handleMove = (moveClientX, moveClientY) => {
1090
+ const deltaX = moveClientX - dragStart.current.x;
1091
+ const deltaY = moveClientY - dragStart.current.y;
1092
+ updatePosition({
1093
+ x: elementStart.current.x + deltaX,
1094
+ y: elementStart.current.y + deltaY
1095
+ });
1096
+ };
1097
+ const handleMouseMove = (e) => {
1098
+ e.preventDefault();
1099
+ handleMove(e.clientX, e.clientY);
1100
+ };
1101
+ const handleTouchMove = (e) => {
1102
+ e.preventDefault();
1103
+ const touch = e.touches[0];
1104
+ if (touch) {
1105
+ handleMove(touch.clientX, touch.clientY);
1106
+ }
1107
+ };
1108
+ const handleEnd = () => {
1109
+ setIsDragging(false);
1110
+ document.removeEventListener("mousemove", handleMouseMove);
1111
+ document.removeEventListener("mouseup", handleEnd);
1112
+ document.removeEventListener("touchmove", handleTouchMove);
1113
+ document.removeEventListener("touchend", handleEnd);
1114
+ };
1115
+ document.addEventListener("mousemove", handleMouseMove);
1116
+ document.addEventListener("mouseup", handleEnd);
1117
+ document.addEventListener("touchmove", handleTouchMove, {
1118
+ passive: false
1119
+ });
1120
+ document.addEventListener("touchend", handleEnd);
1121
+ },
1122
+ [position, updatePosition]
1123
+ );
1124
+ const handleMouseDown = (0, import_react6.useCallback)(
1125
+ (e) => {
1126
+ e.preventDefault();
1127
+ handleStart(e.clientX, e.clientY);
1128
+ },
1129
+ [handleStart]
1130
+ );
1131
+ const handleTouchStart = (0, import_react6.useCallback)(
1132
+ (e) => {
1133
+ e.preventDefault();
1134
+ const touch = e.touches[0];
1135
+ if (touch) {
1136
+ handleStart(touch.clientX, touch.clientY);
1137
+ }
1138
+ },
1139
+ [handleStart]
1140
+ );
1141
+ return {
1142
+ position,
1143
+ isDragging,
1144
+ dragRef,
1145
+ handleMouseDown,
1146
+ handleTouchStart
1147
+ };
1148
+ }
1149
+
1150
+ // call-control-sdk/lib/hooks/useSDKState.ts
1151
+ var import_react7 = require("react");
1152
+ function useSDKState() {
1153
+ const [state, setState] = (0, import_react7.useState)(sdkStateManager.getState());
1154
+ (0, import_react7.useEffect)(() => {
1155
+ const unsubscribe = sdkStateManager.subscribe(() => {
1156
+ setState(sdkStateManager.getState());
1157
+ });
1158
+ return unsubscribe;
1159
+ }, []);
1160
+ return state;
1161
+ }
1162
+
1163
+ // call-control-sdk/lib/services/request.ts
1164
+ var import_react9 = require("react");
1165
+
1166
+ // call-control-sdk/lib/services/toastMessage.tsx
1167
+ var import_react8 = require("react");
1168
+ var import_material = require("@mui/material");
1169
+ var import_jsx_runtime = require("react/jsx-runtime");
1170
+ var ToastContext = (0, import_react8.createContext)(void 0);
1171
+ var useToast = () => {
1172
+ const ctx = (0, import_react8.useContext)(ToastContext);
1173
+ if (!ctx) throw new Error("useToast must be used inside ToastProvider");
1174
+ return ctx;
1175
+ };
1176
+ var ToastProvider = ({ children }) => {
1177
+ const [open, setOpen] = (0, import_react8.useState)(false);
1178
+ const [message, setMessage] = (0, import_react8.useState)("");
1179
+ const [severity, setSeverity] = (0, import_react8.useState)("info");
1180
+ const showToast = (msg, sev = "info") => {
1181
+ setMessage(msg);
1182
+ setSeverity(sev);
1183
+ setOpen(true);
1184
+ };
1185
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ToastContext.Provider, { value: { showToast }, children: [
1186
+ children,
1187
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1188
+ import_material.Snackbar,
1189
+ {
1190
+ open,
1191
+ color: severity,
1192
+ autoHideDuration: 3e3,
1193
+ onClose: () => setOpen(false),
1194
+ anchorOrigin: { vertical: "top", horizontal: "right" },
1195
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1196
+ import_material.Alert,
1197
+ {
1198
+ variant: "filled",
1199
+ severity,
1200
+ onClose: () => setOpen(false),
1201
+ sx: { width: "100%" },
1202
+ children: message
1203
+ }
1204
+ )
1205
+ }
1206
+ )
1207
+ ] });
1208
+ };
1209
+
1210
+ // call-control-sdk/lib/services/request.ts
1211
+ var initialState = {
1212
+ isLoading: false,
1213
+ isSuccess: false,
1214
+ isError: false,
1215
+ error: null,
1216
+ data: null
1217
+ };
1218
+ var reducer = (state, action) => {
1219
+ if (action.type === "isLoading") {
1220
+ return __spreadProps(__spreadValues({}, state), {
1221
+ isLoading: action.payload
1222
+ });
1223
+ } else if (action.type === "isSuccess") {
1224
+ return __spreadProps(__spreadValues({}, state), {
1225
+ isSuccess: true,
1226
+ data: action.payload
1227
+ });
1228
+ } else if (action.type === "isError") {
1229
+ return __spreadProps(__spreadValues({}, state), {
1230
+ isError: true,
1231
+ error: action.payload
1232
+ });
1233
+ } else if (action.type === "reset") {
1234
+ return {
1235
+ isLoading: false,
1236
+ isSuccess: false,
1237
+ isError: false,
1238
+ error: null,
1239
+ data: null
1240
+ };
1241
+ }
1242
+ throw Error("Unknown action.");
1243
+ };
1244
+ var usePostRequest = (props = {}) => {
1245
+ const { onSuccess = null, onError = null, disabledSuccessToast = false } = props;
1246
+ const { showToast } = useToast();
1247
+ const [state, dispatch] = (0, import_react9.useReducer)(reducer, initialState);
1248
+ const postRequest = (0, import_react9.useCallback)(
1249
+ (url, payload, config = {}) => {
1250
+ dispatch({
1251
+ type: "isLoading",
1252
+ payload: true
1253
+ });
1254
+ axios_default.post(url, payload, config).then((res) => {
1255
+ var _a2;
1256
+ dispatch({
1257
+ type: "isSuccess",
1258
+ payload: res.data
1259
+ });
1260
+ onSuccess == null ? void 0 : onSuccess(res.data, payload);
1261
+ if (!disabledSuccessToast) {
1262
+ showToast((_a2 = res.data) == null ? void 0 : _a2.message, "success");
1263
+ }
1264
+ }).catch((err) => {
1265
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1266
+ const error = {
1267
+ status: (_b = (_a2 = err.response) == null ? void 0 : _a2.status) != null ? _b : 500,
1268
+ message: ((_d = (_c = err.response) == null ? void 0 : _c.data) == null ? void 0 : _d.detail) || ((_f = (_e = err.response) == null ? void 0 : _e.data) == null ? void 0 : _f.message) || err.message || "An unknown error occurred",
1269
+ data: (_h = (_g = err.response) == null ? void 0 : _g.data) != null ? _h : null,
1270
+ statusText: (_j = (_i = err.response) == null ? void 0 : _i.statusText) != null ? _j : "",
1271
+ code: (_k = err == null ? void 0 : err.code) != null ? _k : "",
1272
+ name: (_l = err == null ? void 0 : err.name) != null ? _l : ""
1273
+ };
1274
+ showToast(error.message, "error");
1275
+ dispatch({
1276
+ type: "isError",
1277
+ payload: error
1278
+ });
1279
+ onError == null ? void 0 : onError(error, payload);
1280
+ }).finally(() => {
1281
+ dispatch({
1282
+ type: "isLoading",
1283
+ payload: false
1284
+ });
1285
+ });
1286
+ },
1287
+ [onSuccess, onError, showToast]
1288
+ );
1289
+ return [postRequest, state];
1290
+ };
1291
+
1292
+ // call-control-sdk/lib/components/dialog.tsx
1293
+ var import_icons_material = require("@mui/icons-material");
1294
+ var import_material3 = require("@mui/material");
1295
+ var import_react10 = require("react");
1296
+
1297
+ // call-control-sdk/lib/components/styles.ts
1298
+ var import_material2 = require("@mui/material");
1299
+ var useStyles = ({
1300
+ disabled,
1301
+ enabled,
1302
+ outlined
1303
+ }) => {
1304
+ const theme = (0, import_material2.useTheme)();
1305
+ return {
1306
+ disabled: __spreadValues({
1307
+ padding: "0px",
1308
+ margin: "0px",
1309
+ minWidth: "40px !important",
1310
+ borderRadius: "16px",
1311
+ border: `1px solid rgb(206, 204, 204)`,
1312
+ height: "40px",
1313
+ "&:hover": {
1314
+ boxShadow: " 0px 2px 2px rgba(0, 0, 0, 0.79)",
1315
+ border: `1px solid ${theme.palette.primary.main}`
1316
+ },
1317
+ "&:active": {
1318
+ bgcolor: "primary.main",
1319
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1320
+ }
1321
+ }, disabled),
1322
+ enabled: __spreadValues({
1323
+ padding: "0px",
1324
+ margin: "0px",
1325
+ minWidth: "40px !important",
1326
+ borderRadius: "16px",
1327
+ boxShadow: " 0px 2px 1px rgba(0, 0, 0, 0.507)",
1328
+ border: `1px solid ${theme.palette.primary.main}`,
1329
+ height: "40px",
1330
+ "&:hover": {
1331
+ boxShadow: " 0px 2px 1px rgba(0, 0, 0, 0.507)",
1332
+ border: `1px solid ${theme.palette.primary.main}`
1333
+ },
1334
+ "&:active": {
1335
+ bgcolor: "primary.main",
1336
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1337
+ }
1338
+ }, enabled),
1339
+ outlined: __spreadValues({
1340
+ padding: "0px",
1341
+ margin: "0px",
1342
+ minWidth: "40px !important",
1343
+ borderRadius: "16px",
1344
+ backgroundColor: theme.palette.grey[200],
1345
+ boxShadow: `0px 2px 1px ${theme.palette.primary.light}`,
1346
+ border: `0px solid ${theme.palette.primary.main}`,
1347
+ height: "40px",
1348
+ "&:hover": {
1349
+ boxShadow: `0px 2px 1px ${theme.palette.primary.main}`,
1350
+ border: `0px solid ${theme.palette.primary.main}`
1351
+ },
1352
+ "&:active": {
1353
+ bgcolor: "primary.main",
1354
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1355
+ }
1356
+ }, outlined)
1357
+ };
1358
+ };
1359
+ var styles_default = useStyles;
1360
+
1361
+ // call-control-sdk/lib/components/dialog.tsx
1362
+ var import_jsx_runtime2 = require("react/jsx-runtime");
1363
+ var ConferenceTableRow = ({ each, isMergeCall }) => {
1364
+ var _a2, _b, _c, _d, _e;
1365
+ const state = useSDKState();
1366
+ const { showToast } = useToast();
1367
+ const { disabled, enabled, outlined } = styles_default({
1368
+ disabled: ((_a2 = state.sdkConfig) == null ? void 0 : _a2.disabled) || {},
1369
+ enabled: ((_b = state.sdkConfig) == null ? void 0 : _b.enabled) || {},
1370
+ outlined: ((_c = state.sdkConfig) == null ? void 0 : _c.outlined) || {}
1371
+ });
1372
+ const theme = (0, import_material3.useTheme)();
1373
+ const [conferenceCallStart, setConferenceCallStart] = (0, import_react10.useState)(false);
1374
+ const [conferenceCallMerge, setConferenceCallMerge] = (0, import_react10.useState)(false);
1375
+ const [conferenceCallHoldOrUnHold, setConferenceCallHoldOrUnHold] = (0, import_react10.useState)(false);
1376
+ const [conferenceCallMuteOrUnMute, setConferenceCallMuteOrUnMute] = (0, import_react10.useState)(false);
1377
+ const [conferenceCallEnd, setConferenceCallEnd] = (0, import_react10.useState)(false);
1378
+ const onConferenceLineUpdate = (line, data) => {
1379
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1380
+ };
1381
+ const onConferenceCallStart = (line, data) => {
1382
+ var _a3, _b2, _c2, _d2;
1383
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1384
+ setConferenceCallStart(true);
1385
+ const payload = {
1386
+ action: "EXTERNAL_CONFERENCE",
1387
+ operation: `CALL${line_used.line}`,
1388
+ line_used: String(line_used.line),
1389
+ thirdparty_no: line_used.phone,
1390
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1391
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1392
+ };
1393
+ axios_default.post(END_POINT.CONFERENCE_CALL, payload).then((res) => {
1394
+ var _a4;
1395
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1396
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1397
+ }).catch((err) => {
1398
+ var _a4, _b3, _c3, _d3;
1399
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1400
+ showToast(message, "error");
1401
+ }).finally(() => {
1402
+ setConferenceCallStart(false);
1403
+ });
1404
+ };
1405
+ const onMergeConferenceCall = (line, data) => {
1406
+ var _a3, _b2, _c2, _d2;
1407
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1408
+ setConferenceCallMerge(true);
1409
+ const payload = {
1410
+ action: "EXTERNAL_CONFERENCE",
1411
+ operation: `CONFERENCE`,
1412
+ line_used: String(line_used.line),
1413
+ thirdparty_no: line_used.phone,
1414
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1415
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1416
+ };
1417
+ axios_default.post(END_POINT.CONFERENCE_CALL, payload).then((res) => {
1418
+ var _a4;
1419
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1420
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1421
+ }).catch((err) => {
1422
+ var _a4, _b3, _c3, _d3;
1423
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1424
+ showToast(message, "error");
1425
+ }).finally(() => {
1426
+ setConferenceCallMerge(false);
1427
+ });
1428
+ };
1429
+ const onHoldOrUnHoldConferenceCall = (line, data, type) => {
1430
+ var _a3, _b2, _c2, _d2;
1431
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1432
+ setConferenceCallHoldOrUnHold(true);
1433
+ const payload = {
1434
+ action: "EXTERNAL_CONFERENCE",
1435
+ operation: type,
1436
+ hold_channel_no: type === "HOLDUSER" ? `hold${line_used.line}` : `unhold${line_used.line}`,
1437
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1438
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1439
+ };
1440
+ axios_default.post(END_POINT.CONFERENCE_CALL_HOLD_OR_UN_HOLD, payload).then((res) => {
1441
+ var _a4;
1442
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1443
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1444
+ }).catch((err) => {
1445
+ var _a4, _b3, _c3, _d3;
1446
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1447
+ showToast(message, "error");
1448
+ }).finally(() => {
1449
+ setConferenceCallHoldOrUnHold(false);
1450
+ });
1451
+ };
1452
+ const onMuteOrUnMuteConferenceCall = (line, data, type) => {
1453
+ var _a3, _b2, _c2, _d2;
1454
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1455
+ setConferenceCallMuteOrUnMute(true);
1456
+ const payload = {
1457
+ action: "EXTERNAL_CONFERENCE",
1458
+ operation: type,
1459
+ channel_no: type === "MUTEUSER" ? `mute${line_used.line}` : `play${line_used.line}`,
1460
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1461
+ thirdparty_no: line_used.phone,
1462
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1463
+ };
1464
+ axios_default.post(END_POINT.CONFERENCE_CALL_MUTE_OT_UN_MUTE, payload).then((res) => {
1465
+ var _a4;
1466
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1467
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1468
+ }).catch((err) => {
1469
+ var _a4, _b3, _c3, _d3;
1470
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1471
+ showToast(message, "error");
1472
+ }).finally(() => {
1473
+ setConferenceCallMuteOrUnMute(false);
1474
+ });
1475
+ };
1476
+ const onEndConferenceCall = (line, data) => {
1477
+ var _a3, _b2, _c2, _d2;
1478
+ const line_used = __spreadValues(__spreadValues({}, line), data);
1479
+ setConferenceCallEnd(true);
1480
+ const payload = {
1481
+ action: "EXTERNAL_CONFERENCE",
1482
+ operation: "HANGUP_CHANNEL",
1483
+ line_used: String(line_used.line),
1484
+ user_type: `THIRDPARTY${line_used.line - 1}`,
1485
+ thirdparty_no: line_used.phone,
1486
+ userid: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b2 : "",
1487
+ process: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.process_name) != null ? _d2 : ""
1488
+ };
1489
+ axios_default.post(END_POINT.CONFERENCE_CALL_END, payload).then((res) => {
1490
+ var _a4;
1491
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1492
+ sdkStateManager.setConferenceLine(__spreadValues(__spreadValues({}, line), data));
1493
+ }).catch((err) => {
1494
+ var _a4, _b3, _c3, _d3;
1495
+ const message = ((_b3 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b3.detail) || ((_d3 = (_c3 = err.response) == null ? void 0 : _c3.data) == null ? void 0 : _d3.message) || err.message || "An unknown error occurred";
1496
+ showToast(message, "error");
1497
+ }).finally(() => {
1498
+ setConferenceCallEnd(false);
1499
+ });
1500
+ };
1501
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1502
+ import_material3.TableRow,
1503
+ {
1504
+ sx: {
1505
+ border: "2px solid #fff"
1506
+ },
1507
+ children: [
1508
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1509
+ import_material3.TableCell,
1510
+ {
1511
+ sx: {
1512
+ padding: "6px"
1513
+ },
1514
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Typography, { children: [
1515
+ "Line ",
1516
+ (_d = each == null ? void 0 : each.line) != null ? _d : "",
1517
+ ". "
1518
+ ] })
1519
+ }
1520
+ ),
1521
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1522
+ import_material3.TableCell,
1523
+ {
1524
+ sx: {
1525
+ padding: "6px"
1526
+ },
1527
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1528
+ import_material3.Typography,
1529
+ {
1530
+ variant: "body2",
1531
+ sx: {
1532
+ px: 1,
1533
+ borderRadius: "10px"
1534
+ },
1535
+ children: (_e = each == null ? void 0 : each.status) != null ? _e : ""
1536
+ }
1537
+ )
1538
+ }
1539
+ ),
1540
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1541
+ import_material3.TableCell,
1542
+ {
1543
+ sx: {
1544
+ padding: "6px"
1545
+ },
1546
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1547
+ import_material3.Button,
1548
+ {
1549
+ sx: {
1550
+ textTransform: "capitalize"
1551
+ },
1552
+ size: "small",
1553
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Typography, { variant: "body2", children: (each == null ? void 0 : each.line) === 1 ? "Internal" : "External" })
1554
+ }
1555
+ )
1556
+ }
1557
+ ),
1558
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1559
+ import_material3.TableCell,
1560
+ {
1561
+ sx: {
1562
+ padding: "6px"
1563
+ },
1564
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1565
+ import_material3.TextField,
1566
+ {
1567
+ size: "small",
1568
+ placeholder: "Phone Number",
1569
+ fullWidth: true,
1570
+ value: (each == null ? void 0 : each.phone) || "",
1571
+ disabled: (each == null ? void 0 : each.line) === 1 || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "CONFERENCE" || (each == null ? void 0 : each.status) === "HOLD" || (each == null ? void 0 : each.status) === "MUTE",
1572
+ onChange: (e) => {
1573
+ onConferenceLineUpdate(each, { phone: e.target.value });
1574
+ }
1575
+ }
1576
+ )
1577
+ }
1578
+ ),
1579
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1580
+ import_material3.TableCell,
1581
+ {
1582
+ sx: {
1583
+ padding: "6px"
1584
+ },
1585
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1586
+ import_material3.Box,
1587
+ {
1588
+ sx: {
1589
+ display: "flex",
1590
+ alignItems: "center",
1591
+ justifyContent: "space-around"
1592
+ },
1593
+ children: [
1594
+ (each == null ? void 0 : each.line) !== 1 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Tooltip, { title: "Call", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1595
+ import_material3.Button,
1596
+ {
1597
+ variant: (each == null ? void 0 : each.status) !== "IDLE" ? "outlined" : "contained",
1598
+ color: "success",
1599
+ sx: (each == null ? void 0 : each.status) !== "IDLE" ? __spreadValues({}, disabled) : __spreadProps(__spreadValues({}, enabled), {
1600
+ border: `0px solid ${theme.palette.success.light}`,
1601
+ "&:hover": {
1602
+ bgcolor: "success.light",
1603
+ boxShadow: `0px 2px 1px ${theme.palette.success.light}`,
1604
+ border: `0px solid ${theme.palette.success.light}`
1605
+ },
1606
+ "&:active": {
1607
+ bgcolor: "success.light",
1608
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1609
+ }
1610
+ }),
1611
+ onClick: () => {
1612
+ onConferenceCallStart(each, {});
1613
+ },
1614
+ disabled: (each == null ? void 0 : each.status) !== "IDLE",
1615
+ children: conferenceCallStart ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1616
+ import_material3.CircularProgress,
1617
+ {
1618
+ size: "20px",
1619
+ color: "success"
1620
+ }
1621
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1622
+ import_icons_material.Call,
1623
+ {
1624
+ sx: {
1625
+ color: (each == null ? void 0 : each.status) !== "IDLE" ? "default" : "#f3f2f2"
1626
+ }
1627
+ }
1628
+ )
1629
+ }
1630
+ ) }),
1631
+ (each == null ? void 0 : each.line) === 1 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Tooltip, { title: "Merge Call", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1632
+ import_material3.Button,
1633
+ {
1634
+ variant: isMergeCall ? "contained" : "outlined",
1635
+ sx: isMergeCall ? __spreadProps(__spreadValues({}, enabled), { padding: "0px 16px" }) : __spreadProps(__spreadValues({}, disabled), { padding: "0px 16px" }),
1636
+ onClick: () => {
1637
+ onMergeConferenceCall(each, {
1638
+ isMergeCall: true
1639
+ });
1640
+ },
1641
+ disabled: !isMergeCall || conferenceCallMerge,
1642
+ children: [
1643
+ (each == null ? void 0 : each.isMergeCall) ? "Merged" : "Merge",
1644
+ conferenceCallMerge ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.CircularProgress, { size: "20px" }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.CallSplit, {})
1645
+ ]
1646
+ }
1647
+ ) }),
1648
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Tooltip, { title: (each == null ? void 0 : each.status) !== "HOLD" ? "Hold" : "Un Hold", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1649
+ import_material3.Button,
1650
+ {
1651
+ variant: (each == null ? void 0 : each.status) === "HOLD" ? "contained" : "outlined",
1652
+ sx: (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" ? __spreadValues({}, disabled) : (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" ? (
1653
+ // each.status === "IDLE"
1654
+ __spreadValues({}, outlined)
1655
+ ) : __spreadValues({}, disabled),
1656
+ onClick: () => {
1657
+ if (each.status === "HOLD") {
1658
+ onHoldOrUnHoldConferenceCall(each, { isHold: false }, "UNHOLDUSER");
1659
+ } else {
1660
+ onHoldOrUnHoldConferenceCall(each, { isHold: true }, "HOLDUSER");
1661
+ }
1662
+ },
1663
+ disabled: (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" || conferenceCallHoldOrUnHold,
1664
+ children: conferenceCallHoldOrUnHold ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1665
+ import_material3.CircularProgress,
1666
+ {
1667
+ size: "20px",
1668
+ sx: {
1669
+ color: theme.palette.primary.main
1670
+ }
1671
+ }
1672
+ ) : each.status === "HOLD" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.PlayArrow, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Pause, {})
1673
+ }
1674
+ ) }),
1675
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Tooltip, { title: each.status !== "MUTE" ? "Mute" : "Un Mute", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1676
+ import_material3.Button,
1677
+ {
1678
+ variant: each.status === "MUTE" ? "contained" : "outlined",
1679
+ sx: each.status === "DISCONNECTED" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" ? __spreadValues({}, disabled) : (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "CONFERENCE" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
1680
+ onClick: () => {
1681
+ if (each.status === "MUTE") {
1682
+ onMuteOrUnMuteConferenceCall(each, { isMute: false }, "PLAYUSER");
1683
+ } else {
1684
+ onMuteOrUnMuteConferenceCall(each, { isMute: true }, "MUTEUSER");
1685
+ }
1686
+ },
1687
+ disabled: (each == null ? void 0 : each.status) === "DISCONNECTED" || (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "HOLD" || (each == null ? void 0 : each.status) === "ONCALL" || (each == null ? void 0 : each.status) === "DIALING" || (each == null ? void 0 : each.status) === "RINGING" || conferenceCallMuteOrUnMute,
1688
+ children: conferenceCallMuteOrUnMute ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1689
+ import_material3.CircularProgress,
1690
+ {
1691
+ size: "20px",
1692
+ sx: {
1693
+ color: theme.palette.primary.main
1694
+ }
1695
+ }
1696
+ ) : each.status === "MUTE" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.MicOff, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Mic, {})
1697
+ }
1698
+ ) }),
1699
+ (each == null ? void 0 : each.line) !== 1 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Tooltip, { title: "End Call", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1700
+ import_material3.Button,
1701
+ {
1702
+ variant: (each == null ? void 0 : each.status) !== "IDLE" && (each == null ? void 0 : each.status) !== "DISCONNECTED" ? "contained" : "outlined",
1703
+ color: "error",
1704
+ sx: (each == null ? void 0 : each.status) !== "IDLE" && (each == null ? void 0 : each.status) !== "DISCONNECTED" ? __spreadProps(__spreadValues({}, enabled), {
1705
+ border: `0px solid ${theme.palette.error.light}`,
1706
+ "&:hover": {
1707
+ bgcolor: "error.light",
1708
+ boxShadow: `0px 2px 1px ${theme.palette.error.light}`,
1709
+ border: `0px solid ${theme.palette.error.light}`
1710
+ },
1711
+ "&:active": {
1712
+ bgcolor: "error.light",
1713
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
1714
+ }
1715
+ }) : __spreadValues({}, disabled),
1716
+ onClick: () => {
1717
+ onEndConferenceCall(each, {
1718
+ isCallStart: false,
1719
+ isMergeCall: false,
1720
+ isMute: false,
1721
+ isHold: false
1722
+ });
1723
+ },
1724
+ disabled: (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "DISCONNECTED" || conferenceCallEnd,
1725
+ children: conferenceCallEnd ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1726
+ import_material3.CircularProgress,
1727
+ {
1728
+ size: "20px",
1729
+ color: "error"
1730
+ }
1731
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.CallEnd, {})
1732
+ }
1733
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1734
+ import_material3.Button,
1735
+ {
1736
+ variant: (each == null ? void 0 : each.status) !== "IDLE" || (each == null ? void 0 : each.status) !== "DISCONNECTED" ? "contained" : "outlined",
1737
+ color: "error",
1738
+ sx: {
1739
+ display: "none"
1740
+ },
1741
+ onClick: () => {
1742
+ onEndConferenceCall(each, {
1743
+ isCallStart: false,
1744
+ isMergeCall: false,
1745
+ isMute: false,
1746
+ isHold: false
1747
+ });
1748
+ },
1749
+ disabled: (each == null ? void 0 : each.status) === "IDLE" || (each == null ? void 0 : each.status) === "DISCONNECTED" || conferenceCallEnd,
1750
+ children: conferenceCallEnd ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1751
+ import_material3.CircularProgress,
1752
+ {
1753
+ size: "20px",
1754
+ color: "error"
1755
+ }
1756
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.CallEnd, {})
1757
+ }
1758
+ )
1759
+ ]
1760
+ }
1761
+ )
1762
+ }
1763
+ )
1764
+ ]
1765
+ },
1766
+ each.line
1767
+ );
1768
+ };
1769
+ function ConferenceDialog() {
1770
+ var _a2;
1771
+ const state = useSDKState();
1772
+ const { showToast } = useToast();
1773
+ const [conferenceCallEndAll, setConferenceCallEndAll] = (0, import_react10.useState)(false);
1774
+ const handleClose = () => {
1775
+ sdkStateManager.setOpenConferenceDialog(false);
1776
+ };
1777
+ const onEndAllConferenceCalls = () => {
1778
+ var _a3, _b, _c, _d;
1779
+ setConferenceCallEndAll(true);
1780
+ const payload = {
1781
+ action: "EXTERNAL_CONFERENCE",
1782
+ operation: "ENDCONFERENCE",
1783
+ userid: (_b = (_a3 = state.callData) == null ? void 0 : _a3.agent_id) != null ? _b : "",
1784
+ process: (_d = (_c = state.callData) == null ? void 0 : _c.process_name) != null ? _d : ""
1785
+ };
1786
+ axios_default.post(END_POINT.CONFERENCE_CALL_END_ALL, payload).then((res) => {
1787
+ var _a4;
1788
+ showToast((_a4 = res.data) == null ? void 0 : _a4.message, "success");
1789
+ sdkStateManager.resetConferenceLines();
1790
+ handleClose();
1791
+ }).catch((err) => {
1792
+ var _a4, _b2, _c2, _d2;
1793
+ const message = ((_b2 = (_a4 = err.response) == null ? void 0 : _a4.data) == null ? void 0 : _b2.detail) || ((_d2 = (_c2 = err.response) == null ? void 0 : _c2.data) == null ? void 0 : _d2.message) || err.message || "An unknown error occurred";
1794
+ showToast(message, "error");
1795
+ }).finally(() => {
1796
+ setConferenceCallEndAll(false);
1797
+ });
1798
+ };
1799
+ const isMergeCall = (0, import_react10.useMemo)(() => {
1800
+ var _a3;
1801
+ return (_a3 = state == null ? void 0 : state.conferenceLine) == null ? void 0 : _a3.some((each) => {
1802
+ if ((each == null ? void 0 : each.line) !== 1) {
1803
+ return (each == null ? void 0 : each.status) === "ONCALL";
1804
+ }
1805
+ return false;
1806
+ });
1807
+ }, [state == null ? void 0 : state.conferenceLine]);
1808
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1809
+ import_material3.Dialog,
1810
+ {
1811
+ open: state.openConferenceDialog,
1812
+ "aria-labelledby": "alert-dialog-title",
1813
+ "aria-describedby": "alert-dialog-description",
1814
+ fullWidth: true,
1815
+ maxWidth: "md",
1816
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Paper, { sx: { borderRadius: 2 }, children: [
1817
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1818
+ import_material3.Box,
1819
+ {
1820
+ sx: {
1821
+ display: "flex",
1822
+ justifyContent: "space-between",
1823
+ alignItems: "center",
1824
+ padding: "10px 16px"
1825
+ },
1826
+ children: [
1827
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Typography, { variant: "body1", children: [
1828
+ (_a2 = state == null ? void 0 : state.agentId) != null ? _a2 : "",
1829
+ " conference"
1830
+ ] }),
1831
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.IconButton, { onClick: handleClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Close, {}) })
1832
+ ]
1833
+ }
1834
+ ),
1835
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1836
+ import_material3.Box,
1837
+ {
1838
+ sx: {
1839
+ boxShadow: "1px 1px 2px #e7e5e5ff",
1840
+ margin: "0px 15px",
1841
+ borderRadius: "20px"
1842
+ },
1843
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1844
+ import_material3.TableContainer,
1845
+ {
1846
+ component: import_material3.Paper,
1847
+ sx: {
1848
+ outline: "0px solid gray !important",
1849
+ boxShadow: "1px 1px 6px #e7e5e5ff"
1850
+ },
1851
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1852
+ import_material3.Table,
1853
+ {
1854
+ sx: {
1855
+ border: "4px solid #ffffff !important"
1856
+ },
1857
+ children: [
1858
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.TableHead, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1859
+ import_material3.TableRow,
1860
+ {
1861
+ sx: {
1862
+ border: "2px solid #f3f3f3ff !important"
1863
+ },
1864
+ children: [
1865
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1866
+ import_material3.TableCell,
1867
+ {
1868
+ sx: {
1869
+ padding: "6px"
1870
+ },
1871
+ children: "Line"
1872
+ }
1873
+ ),
1874
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1875
+ import_material3.TableCell,
1876
+ {
1877
+ sx: {
1878
+ padding: "6px"
1879
+ },
1880
+ children: "Status"
1881
+ }
1882
+ ),
1883
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1884
+ import_material3.TableCell,
1885
+ {
1886
+ sx: {
1887
+ padding: "6px"
1888
+ },
1889
+ children: "Call Type"
1890
+ }
1891
+ ),
1892
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1893
+ import_material3.TableCell,
1894
+ {
1895
+ sx: {
1896
+ padding: "6px"
1897
+ },
1898
+ children: "Mobile Number"
1899
+ }
1900
+ ),
1901
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1902
+ import_material3.TableCell,
1903
+ {
1904
+ sx: {
1905
+ padding: "6px"
1906
+ },
1907
+ children: "Call Actions"
1908
+ }
1909
+ )
1910
+ ]
1911
+ }
1912
+ ) }),
1913
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.TableBody, { children: state == null ? void 0 : state.conferenceLine.map((each) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1914
+ ConferenceTableRow,
1915
+ {
1916
+ each,
1917
+ isMergeCall
1918
+ }
1919
+ )) })
1920
+ ]
1921
+ }
1922
+ )
1923
+ }
1924
+ )
1925
+ }
1926
+ ),
1927
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1928
+ import_material3.Box,
1929
+ {
1930
+ textAlign: "center",
1931
+ m: 2,
1932
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
1933
+ import_material3.Button,
1934
+ {
1935
+ variant: "outlined",
1936
+ color: "error",
1937
+ size: "large",
1938
+ onClick: onEndAllConferenceCalls,
1939
+ disabled: conferenceCallEndAll,
1940
+ sx: { px: 2, borderRadius: "20px", textTransform: "capitalize" },
1941
+ children: [
1942
+ conferenceCallEndAll ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1943
+ import_material3.CircularProgress,
1944
+ {
1945
+ size: "20px",
1946
+ color: "error",
1947
+ sx: {
1948
+ marginRight: "8px"
1949
+ }
1950
+ }
1951
+ ) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1952
+ import_material3.IconButton,
1953
+ {
1954
+ sx: {
1955
+ bgcolor: "error.main",
1956
+ "&:hover": { bgcolor: "error.dark" },
1957
+ marginRight: "8px",
1958
+ width: "28px",
1959
+ height: "28px",
1960
+ fontSize: "12px",
1961
+ fontWeight: "600",
1962
+ lineHeight: "16px",
1963
+ letterSpacing: "0.02em",
1964
+ textTransform: "capitalize",
1965
+ color: "white",
1966
+ display: "flex",
1967
+ alignItems: "center",
1968
+ justifyContent: "center",
1969
+ borderRadius: "50%"
1970
+ },
1971
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1972
+ import_icons_material.PhoneDisabled,
1973
+ {
1974
+ sx: {
1975
+ color: "white",
1976
+ fontSize: "16px",
1977
+ fontWeight: "600"
1978
+ }
1979
+ }
1980
+ )
1981
+ }
1982
+ ),
1983
+ "End Conference"
1984
+ ]
1985
+ }
1986
+ )
1987
+ }
1988
+ )
1989
+ ] })
1990
+ }
1991
+ ) });
1992
+ }
1993
+ function CallTransferDialog({ open }) {
1994
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
1995
+ const state = useSDKState();
1996
+ const [transferCall] = usePostRequest({
1997
+ onSuccess: () => {
1998
+ sdkStateManager.setOpenCallTransferDialog(false);
1999
+ }
2000
+ });
2001
+ const [currentselecteTab, setCurrentselecteTab] = (0, import_react10.useState)("process");
2002
+ const [getIdelAgentsList, { data: idleAgentsList, isLoading: isIdleAgentsListLoading }] = usePostRequest({
2003
+ disabledSuccessToast: true
2004
+ });
2005
+ const [
2006
+ getProcessAndQueuesList,
2007
+ { data: processAndQueuesList, isLoading: isProcessAndQueuesListLoading }
2008
+ ] = usePostRequest({
2009
+ disabledSuccessToast: true
2010
+ });
2011
+ const handleClose = () => {
2012
+ sdkStateManager.setOpenCallTransferDialog(false);
2013
+ };
2014
+ const handleTransferCall = (data, type) => {
2015
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G;
2016
+ if (type === "PROCESS") {
2017
+ const payload = {
2018
+ mobile_number: (_b2 = (_a3 = state.callData) == null ? void 0 : _a3.phone_number) != null ? _b2 : "",
2019
+ userid: (_d2 = (_c2 = state.callData) == null ? void 0 : _c2.agent_id) != null ? _d2 : "",
2020
+ type: "PROCESS",
2021
+ transfer_to: (_e2 = data == null ? void 0 : data.process_name) != null ? _e2 : "",
2022
+ callreferenceid: (_g2 = (_f2 = state.callData) == null ? void 0 : _f2.convox_id) != null ? _g2 : "",
2023
+ processid: String((_i2 = (_h2 = state.callData) == null ? void 0 : _h2.process_id) != null ? _i2 : ""),
2024
+ process_name: (_k2 = (_j2 = state.callData) == null ? void 0 : _j2.process_name) != null ? _k2 : ""
2025
+ };
2026
+ transferCall(END_POINT.TRANSFER_CALL, payload);
2027
+ } else if (type === "QUEUE") {
2028
+ const payload = {
2029
+ mobile_number: (_m = (_l2 = state.callData) == null ? void 0 : _l2.phone_number) != null ? _m : "",
2030
+ userid: (_o = (_n = state.callData) == null ? void 0 : _n.agent_id) != null ? _o : "",
2031
+ type: "QUEUE",
2032
+ transfer_to: (_p = data == null ? void 0 : data.queue_name) != null ? _p : "",
2033
+ callreferenceid: (_r = (_q = state.callData) == null ? void 0 : _q.convox_id) != null ? _r : "",
2034
+ processid: String((_t = (_s = state.callData) == null ? void 0 : _s.process_id) != null ? _t : ""),
2035
+ process_name: (_v = (_u = state.callData) == null ? void 0 : _u.process_name) != null ? _v : ""
2036
+ };
2037
+ transferCall(END_POINT.TRANSFER_CALL, payload);
2038
+ } else if (type === "AGENT") {
2039
+ const payload = {
2040
+ mobile_number: (_x = (_w = state.callData) == null ? void 0 : _w.phone_number) != null ? _x : "",
2041
+ userid: (_z = (_y = state.callData) == null ? void 0 : _y.agent_id) != null ? _z : "",
2042
+ type: "AGENT",
2043
+ transfer_to: (_A = data == null ? void 0 : data.user_id) != null ? _A : "",
2044
+ callreferenceid: (_C = (_B = state.callData) == null ? void 0 : _B.convox_id) != null ? _C : "",
2045
+ processid: String((_E = (_D = state.callData) == null ? void 0 : _D.process_id) != null ? _E : ""),
2046
+ process_name: (_G = (_F = state.callData) == null ? void 0 : _F.process_name) != null ? _G : ""
2047
+ };
2048
+ transferCall(END_POINT.TRANSFER_CALL, payload);
2049
+ }
2050
+ };
2051
+ (0, import_react10.useEffect)(() => {
2052
+ getIdelAgentsList(END_POINT.AGENTS_LIST, {
2053
+ status: "IDLE",
2054
+ active: true
2055
+ });
2056
+ getProcessAndQueuesList(END_POINT.TRANSFER_TO_DETAILS, {
2057
+ status: "ACTIVE",
2058
+ active: true
2059
+ });
2060
+ }, []);
2061
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2062
+ import_material3.Dialog,
2063
+ {
2064
+ open,
2065
+ "aria-labelledby": "alert-dialog-title",
2066
+ "aria-describedby": "alert-dialog-description",
2067
+ fullWidth: true,
2068
+ maxWidth: "md",
2069
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Paper, { sx: { borderRadius: 2 }, children: [
2070
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2071
+ import_material3.Box,
2072
+ {
2073
+ sx: {
2074
+ display: "flex",
2075
+ justifyContent: "space-between",
2076
+ alignItems: "center",
2077
+ padding: "4px 16px",
2078
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2079
+ },
2080
+ children: [
2081
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Typography, { variant: "body1", children: " Call Transfer" }),
2082
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.IconButton, { onClick: handleClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Close, {}) })
2083
+ ]
2084
+ }
2085
+ ),
2086
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2087
+ import_material3.Box,
2088
+ {
2089
+ sx: {
2090
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2091
+ padding: "6px 10px",
2092
+ margin: "10px",
2093
+ borderRadius: "10px"
2094
+ },
2095
+ children: [
2096
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Box, { sx: { display: "flex", gap: 1 }, children: [
2097
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2098
+ import_material3.Button,
2099
+ {
2100
+ variant: currentselecteTab === "process" ? "contained" : "outlined",
2101
+ onClick: () => {
2102
+ setCurrentselecteTab("process");
2103
+ getProcessAndQueuesList(END_POINT.TRANSFER_TO_DETAILS, {
2104
+ status: "ACTIVE",
2105
+ active: true
2106
+ });
2107
+ },
2108
+ children: "Process"
2109
+ }
2110
+ ),
2111
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2112
+ import_material3.Button,
2113
+ {
2114
+ variant: currentselecteTab === "queues" ? "contained" : "outlined",
2115
+ onClick: () => {
2116
+ setCurrentselecteTab("queues");
2117
+ getProcessAndQueuesList(END_POINT.TRANSFER_TO_DETAILS, {
2118
+ status: "ACTIVE",
2119
+ active: true
2120
+ });
2121
+ },
2122
+ children: "Queues"
2123
+ }
2124
+ ),
2125
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2126
+ import_material3.Button,
2127
+ {
2128
+ variant: currentselecteTab === "agents" ? "contained" : "outlined",
2129
+ onClick: () => {
2130
+ setCurrentselecteTab("agents");
2131
+ getIdelAgentsList(END_POINT.AGENTS_LIST, {
2132
+ status: "IDLE",
2133
+ active: true
2134
+ });
2135
+ },
2136
+ children: "Agents"
2137
+ }
2138
+ )
2139
+ ] }),
2140
+ (isProcessAndQueuesListLoading || isIdleAgentsListLoading) && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2141
+ import_material3.Box,
2142
+ {
2143
+ sx: {
2144
+ display: "flex",
2145
+ justifyContent: "center",
2146
+ alignItems: "center",
2147
+ height: "80px"
2148
+ },
2149
+ children: [
2150
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.CircularProgress, {}),
2151
+ " "
2152
+ ]
2153
+ }
2154
+ ),
2155
+ !isProcessAndQueuesListLoading && !isIdleAgentsListLoading && currentselecteTab === "process" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap" }, children: ((_a2 = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _a2.process) && ((_c = (_b = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _b.process) == null ? void 0 : _c.length) > 0 ? (_e = (_d = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _d.process) == null ? void 0 : _e.map((process, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2156
+ import_material3.Box,
2157
+ {
2158
+ sx: {
2159
+ p: 1,
2160
+ display: "flex",
2161
+ alignItems: "center",
2162
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2163
+ padding: "6px",
2164
+ borderRadius: "10px",
2165
+ "&:hover": { bgcolor: "action.selected" }
2166
+ },
2167
+ children: [
2168
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2169
+ import_material3.Typography,
2170
+ {
2171
+ variant: "body1",
2172
+ sx: {
2173
+ mx: 1,
2174
+ width: "200px",
2175
+ maxWidth: "250px",
2176
+ display: "flex",
2177
+ alignItems: "center"
2178
+ },
2179
+ children: [
2180
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.SupportAgent, { sx: { marginRight: "4px" } }),
2181
+ process.process_name
2182
+ ]
2183
+ }
2184
+ ),
2185
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2186
+ import_material3.IconButton,
2187
+ {
2188
+ color: "success",
2189
+ sx: {
2190
+ bgcolor: "action.hover",
2191
+ "&:hover": { bgcolor: "action.selected" }
2192
+ },
2193
+ onClick: () => {
2194
+ handleTransferCall(process, "PROCESS");
2195
+ },
2196
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Call, {})
2197
+ }
2198
+ )
2199
+ ]
2200
+ },
2201
+ index
2202
+ )) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2203
+ import_material3.Typography,
2204
+ {
2205
+ variant: "body1",
2206
+ sx: {
2207
+ fontSize: "16px",
2208
+ letterSpacing: "0.02em",
2209
+ textTransform: "capitalize",
2210
+ display: "flex",
2211
+ alignItems: "center",
2212
+ justifyContent: "center",
2213
+ width: "100%",
2214
+ margin: "10px 0px",
2215
+ color: "gray",
2216
+ height: "60px"
2217
+ },
2218
+ children: "No Process Found"
2219
+ }
2220
+ ) }),
2221
+ !isProcessAndQueuesListLoading && !isIdleAgentsListLoading && currentselecteTab === "queues" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap" }, children: ((_f = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _f.queue) && ((_h = (_g = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _g.queue) == null ? void 0 : _h.length) > 0 ? (_j = (_i = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _i.queue) == null ? void 0 : _j.map((queue, index) => {
2222
+ var _a3, _b2, _c2, _d2, _e2, _f2;
2223
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2224
+ import_material3.Box,
2225
+ {
2226
+ sx: {
2227
+ p: 1,
2228
+ display: "flex",
2229
+ alignItems: "center",
2230
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2231
+ padding: "6px",
2232
+ borderRadius: "10px",
2233
+ "&:hover": { bgcolor: "action.selected" }
2234
+ },
2235
+ children: [
2236
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2237
+ import_material3.Typography,
2238
+ {
2239
+ variant: "body1",
2240
+ sx: {
2241
+ mx: 1,
2242
+ width: "200px",
2243
+ maxWidth: "250px",
2244
+ display: "flex",
2245
+ alignItems: "center"
2246
+ },
2247
+ children: [
2248
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.SupportAgent, { sx: { marginRight: "4px" } }),
2249
+ queue.queue_name,
2250
+ ((_c2 = (_b2 = (_a3 = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _a3.process) == null ? void 0 : _b2.find(
2251
+ (process) => process.process_id === queue.process_id
2252
+ )) == null ? void 0 : _c2.process_name) ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2253
+ import_material3.Typography,
2254
+ {
2255
+ variant: "body1",
2256
+ sx: {
2257
+ fontSize: "12px",
2258
+ fontWeight: "600",
2259
+ letterSpacing: "0.02em",
2260
+ textTransform: "capitalize",
2261
+ color: "gray"
2262
+ },
2263
+ children: "(" + ((_f2 = (_e2 = (_d2 = processAndQueuesList == null ? void 0 : processAndQueuesList.data) == null ? void 0 : _d2.process) == null ? void 0 : _e2.find(
2264
+ (process) => process.process_id === queue.process_id
2265
+ )) == null ? void 0 : _f2.process_name) + ")"
2266
+ }
2267
+ ) : ""
2268
+ ]
2269
+ }
2270
+ ),
2271
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2272
+ import_material3.IconButton,
2273
+ {
2274
+ color: "success",
2275
+ sx: {
2276
+ bgcolor: "action.hover",
2277
+ "&:hover": { bgcolor: "action.selected" }
2278
+ },
2279
+ onClick: () => {
2280
+ handleTransferCall(queue, "QUEUE");
2281
+ },
2282
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Call, {})
2283
+ }
2284
+ )
2285
+ ]
2286
+ },
2287
+ index
2288
+ );
2289
+ }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2290
+ import_material3.Typography,
2291
+ {
2292
+ variant: "body1",
2293
+ sx: {
2294
+ fontSize: "16px",
2295
+ letterSpacing: "0.02em",
2296
+ textTransform: "capitalize",
2297
+ display: "flex",
2298
+ alignItems: "center",
2299
+ justifyContent: "center",
2300
+ width: "100%",
2301
+ margin: "10px 0px",
2302
+ color: "gray",
2303
+ height: "60px"
2304
+ },
2305
+ children: "No Queues Found"
2306
+ }
2307
+ ) }),
2308
+ !isProcessAndQueuesListLoading && !isIdleAgentsListLoading && currentselecteTab === "agents" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap" }, children: (idleAgentsList == null ? void 0 : idleAgentsList.data) && ((_k = idleAgentsList == null ? void 0 : idleAgentsList.data) == null ? void 0 : _k.length) > 0 ? (_l = idleAgentsList == null ? void 0 : idleAgentsList.data) == null ? void 0 : _l.map((agent, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2309
+ import_material3.Box,
2310
+ {
2311
+ sx: {
2312
+ p: 1,
2313
+ display: "flex",
2314
+ alignItems: "center",
2315
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2316
+ padding: "6px",
2317
+ borderRadius: "10px",
2318
+ "&:hover": { bgcolor: "action.selected" }
2319
+ },
2320
+ children: [
2321
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2322
+ import_material3.Typography,
2323
+ {
2324
+ variant: "body1",
2325
+ sx: {
2326
+ mx: 1,
2327
+ width: "200px",
2328
+ maxWidth: "250px",
2329
+ display: "flex",
2330
+ alignItems: "center"
2331
+ },
2332
+ children: [
2333
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.SupportAgent, { sx: { marginRight: "4px" } }),
2334
+ agent.name
2335
+ ]
2336
+ }
2337
+ ),
2338
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2339
+ import_material3.IconButton,
2340
+ {
2341
+ color: "success",
2342
+ sx: {
2343
+ bgcolor: "action.hover",
2344
+ "&:hover": { bgcolor: "action.selected" }
2345
+ },
2346
+ onClick: () => {
2347
+ handleTransferCall(agent, "AGENT");
2348
+ },
2349
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Call, {})
2350
+ }
2351
+ )
2352
+ ]
2353
+ },
2354
+ index
2355
+ )) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2356
+ import_material3.Typography,
2357
+ {
2358
+ variant: "body1",
2359
+ sx: {
2360
+ fontSize: "16px",
2361
+ letterSpacing: "0.02em",
2362
+ textTransform: "capitalize",
2363
+ display: "flex",
2364
+ alignItems: "center",
2365
+ justifyContent: "center",
2366
+ width: "100%",
2367
+ margin: "10px 0px",
2368
+ color: "gray",
2369
+ height: "60px"
2370
+ },
2371
+ children: "No Agents Found"
2372
+ }
2373
+ ) })
2374
+ ]
2375
+ }
2376
+ )
2377
+ ] })
2378
+ }
2379
+ ) });
2380
+ }
2381
+ function EndCallDispositionDialog({ open, setOpen, onSubmitDisposition }) {
2382
+ var _a2, _b, _c, _d;
2383
+ const [formData, setFormData] = (0, import_react10.useState)({
2384
+ disposition: { label: "Resolved", value: "RES" },
2385
+ followUp: { label: "No", value: "N" },
2386
+ callbackDate: "",
2387
+ callbackHrs: "",
2388
+ callbackMins: ""
2389
+ });
2390
+ const dispositionOptions = [
2391
+ { label: "Not Interested", value: "NI" },
2392
+ { label: "Resolved", value: "RES" }
2393
+ ];
2394
+ const followUpOptions = [
2395
+ { label: "Yes", value: "Y" },
2396
+ { label: "No", value: "N" }
2397
+ ];
2398
+ const handleChange = (field, value) => {
2399
+ setFormData((prev) => __spreadProps(__spreadValues({}, prev), { [field]: value }));
2400
+ };
2401
+ const handleReset = () => {
2402
+ setFormData({
2403
+ disposition: { label: "Resolved", value: "RES" },
2404
+ followUp: { label: "No", value: "N" },
2405
+ callbackDate: "",
2406
+ callbackHrs: "",
2407
+ callbackMins: ""
2408
+ });
2409
+ };
2410
+ const handleClose = () => {
2411
+ handleReset();
2412
+ setOpen(false);
2413
+ };
2414
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2415
+ import_material3.Dialog,
2416
+ {
2417
+ open,
2418
+ "aria-labelledby": "alert-dialog-title",
2419
+ "aria-describedby": "alert-dialog-description",
2420
+ fullWidth: true,
2421
+ maxWidth: "xs",
2422
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Paper, { sx: { borderRadius: 2 }, children: [
2423
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2424
+ import_material3.Box,
2425
+ {
2426
+ sx: {
2427
+ display: "flex",
2428
+ justifyContent: "center",
2429
+ alignItems: "center",
2430
+ padding: "4px 16px",
2431
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2432
+ },
2433
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2434
+ import_material3.Typography,
2435
+ {
2436
+ variant: "body1",
2437
+ m: 1,
2438
+ children: [
2439
+ " ",
2440
+ "Call Disposition"
2441
+ ]
2442
+ }
2443
+ )
2444
+ }
2445
+ ),
2446
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2447
+ import_material3.Box,
2448
+ {
2449
+ sx: {
2450
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2451
+ padding: "10px",
2452
+ margin: "10px",
2453
+ borderRadius: "10px"
2454
+ },
2455
+ children: [
2456
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2457
+ import_material3.Box,
2458
+ {
2459
+ display: "flex",
2460
+ gap: 2,
2461
+ children: [
2462
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2463
+ import_material3.Autocomplete,
2464
+ {
2465
+ value: formData.disposition,
2466
+ options: dispositionOptions,
2467
+ getOptionLabel: (opt) => opt.label,
2468
+ onChange: (_, val) => handleChange("disposition", val),
2469
+ size: "small",
2470
+ renderInput: (params) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2471
+ import_material3.TextField,
2472
+ __spreadProps(__spreadValues({}, params), {
2473
+ label: "Disposition",
2474
+ fullWidth: true
2475
+ })
2476
+ ),
2477
+ sx: { flex: 1 }
2478
+ }
2479
+ ),
2480
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2481
+ import_material3.Autocomplete,
2482
+ {
2483
+ options: followUpOptions,
2484
+ getOptionLabel: (opt) => opt.label,
2485
+ value: formData.followUp,
2486
+ onChange: (_, val) => handleChange("followUp", val),
2487
+ size: "small",
2488
+ renderInput: (params) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2489
+ import_material3.TextField,
2490
+ __spreadProps(__spreadValues({}, params), {
2491
+ label: "Follow Up",
2492
+ fullWidth: true
2493
+ })
2494
+ ),
2495
+ sx: { flex: 1 }
2496
+ }
2497
+ )
2498
+ ]
2499
+ }
2500
+ ),
2501
+ ((_b = (_a2 = formData == null ? void 0 : formData.followUp) == null ? void 0 : _a2.label) == null ? void 0 : _b.toLowerCase()) === "yes" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2502
+ import_material3.Box,
2503
+ {
2504
+ display: "flex",
2505
+ gap: 2,
2506
+ mt: 2,
2507
+ children: [
2508
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2509
+ import_material3.TextField,
2510
+ {
2511
+ size: "small",
2512
+ label: "Callback Date",
2513
+ type: "date",
2514
+ slotProps: {
2515
+ inputLabel: { shrink: true }
2516
+ },
2517
+ value: formData.callbackDate,
2518
+ onChange: (e) => handleChange("callbackDate", e.target.value),
2519
+ fullWidth: true,
2520
+ sx: { flex: 1 }
2521
+ }
2522
+ ),
2523
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2524
+ import_material3.TextField,
2525
+ {
2526
+ size: "small",
2527
+ label: "Hours (0-23)",
2528
+ type: "text",
2529
+ value: formData.callbackHrs,
2530
+ onChange: (e) => handleChange("callbackHrs", e.target.value),
2531
+ fullWidth: true,
2532
+ sx: { flex: 1 }
2533
+ }
2534
+ )
2535
+ ]
2536
+ }
2537
+ ),
2538
+ ((_d = (_c = formData == null ? void 0 : formData.followUp) == null ? void 0 : _c.label) == null ? void 0 : _d.toLowerCase()) === "yes" && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2539
+ import_material3.Box,
2540
+ {
2541
+ display: "flex",
2542
+ gap: 2,
2543
+ mt: 2,
2544
+ children: [
2545
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2546
+ import_material3.TextField,
2547
+ {
2548
+ size: "small",
2549
+ label: "Minutes (0-59)",
2550
+ type: "text",
2551
+ value: formData.callbackMins,
2552
+ onChange: (e) => handleChange("callbackMins", e.target.value),
2553
+ fullWidth: true,
2554
+ sx: { flex: 1 }
2555
+ }
2556
+ ),
2557
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Box, { sx: { flex: 1 } })
2558
+ ]
2559
+ }
2560
+ )
2561
+ ]
2562
+ }
2563
+ ),
2564
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2565
+ import_material3.Box,
2566
+ {
2567
+ textAlign: "right",
2568
+ m: 2,
2569
+ children: [
2570
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2571
+ import_material3.Button,
2572
+ {
2573
+ variant: "outlined",
2574
+ color: "error",
2575
+ size: "large",
2576
+ onClick: handleClose,
2577
+ sx: {
2578
+ px: 2,
2579
+ mx: 1,
2580
+ borderRadius: "10px",
2581
+ textTransform: "capitalize"
2582
+ },
2583
+ children: "cancel"
2584
+ }
2585
+ ),
2586
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2587
+ import_material3.Button,
2588
+ {
2589
+ variant: "contained",
2590
+ color: "primary",
2591
+ size: "large",
2592
+ onClick: () => onSubmitDisposition(formData),
2593
+ sx: { px: 2, borderRadius: "10px", textTransform: "capitalize" },
2594
+ children: "Submit"
2595
+ }
2596
+ )
2597
+ ]
2598
+ }
2599
+ )
2600
+ ] })
2601
+ }
2602
+ ) });
2603
+ }
2604
+ function ProcessorListDialog({
2605
+ open,
2606
+ setOpen,
2607
+ processList = null,
2608
+ handleSelectedProcessor
2609
+ }) {
2610
+ const handleClose = () => {
2611
+ setOpen(false);
2612
+ };
2613
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2614
+ import_material3.Dialog,
2615
+ {
2616
+ open,
2617
+ "aria-labelledby": "alert-dialog-title",
2618
+ "aria-describedby": "alert-dialog-description",
2619
+ maxWidth: "xs",
2620
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Paper, { sx: { borderRadius: 2 }, children: [
2621
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2622
+ import_material3.Box,
2623
+ {
2624
+ sx: {
2625
+ display: "flex",
2626
+ justifyContent: "space-between",
2627
+ alignItems: "center",
2628
+ padding: "4px 16px",
2629
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2630
+ },
2631
+ children: [
2632
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Typography, { variant: "body1", children: " Process List" }),
2633
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.IconButton, { onClick: handleClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Close, {}) })
2634
+ ]
2635
+ }
2636
+ ),
2637
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2638
+ import_material3.Box,
2639
+ {
2640
+ sx: {
2641
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2642
+ padding: "6px 10px",
2643
+ margin: "10px",
2644
+ borderRadius: "10px"
2645
+ },
2646
+ children: processList.length > 0 ? processList == null ? void 0 : processList.map((process, index) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2647
+ import_material3.Box,
2648
+ {
2649
+ sx: {
2650
+ p: 1,
2651
+ display: "flex",
2652
+ alignItems: "center",
2653
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2654
+ padding: "6px",
2655
+ margin: "10px 0px",
2656
+ borderRadius: "10px",
2657
+ cursor: "pointer",
2658
+ "&:hover": { bgcolor: "action.selected" }
2659
+ },
2660
+ onClick: () => {
2661
+ handleSelectedProcessor(process);
2662
+ },
2663
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2664
+ import_material3.Typography,
2665
+ {
2666
+ variant: "body1",
2667
+ sx: {
2668
+ mx: 1,
2669
+ width: "200px",
2670
+ maxWidth: "250px",
2671
+ display: "flex",
2672
+ alignItems: "center"
2673
+ },
2674
+ children: [
2675
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.SupportAgent, { sx: { marginRight: "4px" } }),
2676
+ process.process_name
2677
+ ]
2678
+ }
2679
+ )
2680
+ },
2681
+ index
2682
+ )) : null
2683
+ }
2684
+ )
2685
+ ] })
2686
+ }
2687
+ ) });
2688
+ }
2689
+ function CallHistoryDialog({ open, setOpen }) {
2690
+ const handleClose = () => {
2691
+ setOpen(false);
2692
+ };
2693
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2694
+ import_material3.Dialog,
2695
+ {
2696
+ open,
2697
+ "aria-labelledby": "alert-dialog-title",
2698
+ "aria-describedby": "alert-dialog-description",
2699
+ fullWidth: true,
2700
+ maxWidth: "md",
2701
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_material3.Paper, { sx: { borderRadius: 2 }, children: [
2702
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
2703
+ import_material3.Box,
2704
+ {
2705
+ sx: {
2706
+ display: "flex",
2707
+ justifyContent: "space-between",
2708
+ alignItems: "center",
2709
+ padding: "4px 16px",
2710
+ boxShadow: "0px 1px 2px #f5f5f5ff"
2711
+ },
2712
+ children: [
2713
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.Typography, { variant: "body1", children: " Call History" }),
2714
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_material3.IconButton, { onClick: handleClose, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons_material.Close, {}) })
2715
+ ]
2716
+ }
2717
+ ),
2718
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
2719
+ import_material3.Box,
2720
+ {
2721
+ sx: {
2722
+ boxShadow: "1px 1px 4px #d3d3d3ff",
2723
+ margin: "10px",
2724
+ borderRadius: "10px",
2725
+ textAlign: "center",
2726
+ fontSize: "16px",
2727
+ fontWeight: "bold"
2728
+ },
2729
+ p: 6,
2730
+ children: "Coming Soon..."
2731
+ }
2732
+ )
2733
+ ] })
2734
+ }
2735
+ ) });
2736
+ }
2737
+
2738
+ // call-control-sdk/lib/utils/audioLoader.ts
2739
+ var import_incoming = __toESM(require("./incoming-4WP3FJI4.mp3"));
2740
+ var audioBlobUrl = null;
2741
+ var audioBuffer = null;
2742
+ async function loadAudioAsBlob() {
2743
+ if (audioBlobUrl) {
2744
+ return audioBlobUrl;
2745
+ }
2746
+ if (import_incoming.default.startsWith("data:") || import_incoming.default.startsWith("http://") || import_incoming.default.startsWith("https://") || import_incoming.default.startsWith("blob:")) {
2747
+ return import_incoming.default;
2748
+ }
2749
+ try {
2750
+ const response = await fetch(import_incoming.default);
2751
+ if (!response.ok) {
2752
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
2753
+ }
2754
+ const blob = await response.blob();
2755
+ if (blob.size === 0) {
2756
+ throw new Error("Empty blob");
2757
+ }
2758
+ audioBlobUrl = URL.createObjectURL(blob);
2759
+ return audioBlobUrl;
2760
+ } catch (error) {
2761
+ console.warn("Could not create blob URL, using direct URL:", error);
2762
+ return import_incoming.default;
2763
+ }
2764
+ }
2765
+ async function createAudioElement() {
2766
+ const audio = new Audio();
2767
+ audio.loop = true;
2768
+ audio.volume = 0.7;
2769
+ audio.preload = "auto";
2770
+ let audioUrl = "";
2771
+ try {
2772
+ audioUrl = await loadAudioAsBlob();
2773
+ } catch (error) {
2774
+ console.warn("Failed to load audio as blob, trying direct URL:", error);
2775
+ audioUrl = import_incoming.default;
2776
+ }
2777
+ const tryLoadAudio = async (url) => {
2778
+ return new Promise((resolve) => {
2779
+ const checkCanPlay = () => {
2780
+ const canPlay = audio.readyState >= HTMLMediaElement.HAVE_FUTURE_DATA;
2781
+ if (canPlay) {
2782
+ resolve(true);
2783
+ return;
2784
+ }
2785
+ if (audio.error) {
2786
+ resolve(false);
2787
+ return;
2788
+ }
2789
+ setTimeout(checkCanPlay, 100);
2790
+ };
2791
+ audio.addEventListener("canplay", () => resolve(true), { once: true });
2792
+ audio.addEventListener("error", () => resolve(false), { once: true });
2793
+ audio.src = url;
2794
+ audio.load();
2795
+ setTimeout(() => resolve(false), 2e3);
2796
+ });
2797
+ };
2798
+ let loaded = await tryLoadAudio(audioUrl);
2799
+ if (!loaded && audioUrl !== import_incoming.default) {
2800
+ console.log("Primary URL failed, trying original import URL:", import_incoming.default);
2801
+ loaded = await tryLoadAudio(import_incoming.default);
2802
+ if (loaded) {
2803
+ audioUrl = import_incoming.default;
2804
+ }
2805
+ }
2806
+ if (!loaded) {
2807
+ console.error("Failed to load audio with all methods. URL:", audioUrl);
2808
+ }
2809
+ return audio;
2810
+ }
2811
+ function cleanupAudioResources() {
2812
+ if (audioBlobUrl) {
2813
+ URL.revokeObjectURL(audioBlobUrl);
2814
+ audioBlobUrl = null;
2815
+ }
2816
+ audioBuffer = null;
2817
+ }
2818
+
2819
+ // call-control-sdk/lib/components/callControls.tsx
2820
+ var import_jsx_runtime3 = require("react/jsx-runtime");
2821
+ var getCombineConfrenceData = (localState, apiData) => {
2822
+ const localConfrenceData = localState == null ? void 0 : localState.conferenceLine;
2823
+ const apiConferenceData = apiData == null ? void 0 : apiData.conferencestatus;
2824
+ const updatedConferenceData = localConfrenceData.map((item) => {
2825
+ var _a2, _b, _c, _d;
2826
+ if ((item == null ? void 0 : item.line) === 1) {
2827
+ const statusKey = `line_${item.line}_status`;
2828
+ return __spreadProps(__spreadValues({}, item), {
2829
+ line: 1,
2830
+ status: (_a2 = apiConferenceData[statusKey]) != null ? _a2 : item == null ? void 0 : item.status,
2831
+ phone: (_c = (_b = localState == null ? void 0 : localState.callData) == null ? void 0 : _b.phone_number) != null ? _c : ""
2832
+ });
2833
+ } else {
2834
+ const statusKey = `line_${item.line}_status`;
2835
+ const phoneKey = `line_${item.line}_phonenumber`;
2836
+ return __spreadProps(__spreadValues({}, item), {
2837
+ status: (_d = apiConferenceData[statusKey]) != null ? _d : item.status,
2838
+ phone: apiConferenceData[phoneKey] === null || apiConferenceData[phoneKey] === "0" ? item.phone : apiConferenceData[phoneKey]
2839
+ });
2840
+ }
2841
+ });
2842
+ return updatedConferenceData;
2843
+ };
2844
+ var formatDuration = (seconds) => {
2845
+ const mins = Math.floor(seconds / 60);
2846
+ const secs = seconds % 60;
2847
+ return `${mins.toString().padStart(2, "0")}:${secs.toString().padStart(2, "0")}`;
2848
+ };
2849
+ function CallControls({ onDataChange }) {
2850
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I, _J, _K, _L, _M, _N, _O, _P, _Q, _R, _S, _T, _U, _V, _W, _X, _Y, _Z, __, _$, _aa, _ba, _ca, _da, _ea, _fa, _ga, _ha, _ia, _ja, _ka, _la, _ma, _na, _oa, _pa, _qa, _ra, _sa, _ta, _ua, _va, _wa, _xa, _ya, _za, _Aa;
2851
+ const theme = (0, import_material4.useTheme)();
2852
+ const state = useSDKState();
2853
+ const { showToast } = useToast();
2854
+ const { disabled, enabled, outlined } = styles_default({
2855
+ disabled: ((_a2 = state.sdkConfig) == null ? void 0 : _a2.disabled) || {},
2856
+ enabled: ((_b = state.sdkConfig) == null ? void 0 : _b.enabled) || {},
2857
+ outlined: ((_c = state.sdkConfig) == null ? void 0 : _c.outlined) || {}
2858
+ });
2859
+ const webSocketRef = (0, import_react11.useRef)(null);
2860
+ const audioRef = (0, import_react11.useRef)(null);
2861
+ const reconnectTimeoutRef = (0, import_react11.useRef)(null);
2862
+ const pingIntervalRef = (0, import_react11.useRef)(null);
2863
+ const reconnectAttemptsRef = (0, import_react11.useRef)(0);
2864
+ const maxReconnectAttempts = 60;
2865
+ const baseReconnectDelay = 2e3;
2866
+ const maxReconnectDelay = 3e4;
2867
+ const [anchorEl, setAnchorEl] = (0, import_react11.useState)(null);
2868
+ const [showIframe, setShowIframe] = (0, import_react11.useState)(true);
2869
+ const [statusAnchorEl, setStatusAnchorEl] = (0, import_react11.useState)(null);
2870
+ const [dialerAnchorEl, setDialerAnchorEl] = (0, import_react11.useState)(null);
2871
+ const [openCallDisposition, setOpenCallDisposition] = (0, import_react11.useState)(false);
2872
+ const [openProcessorDialog, setOpenProcessorDialog] = (0, import_react11.useState)(false);
2873
+ const [openCallHistoryDialog, setOpenCallHistoryDialog] = (0, import_react11.useState)(false);
2874
+ const [processList, setProcessList] = (0, import_react11.useState)(null);
2875
+ const [phoneNumber, setPhoneNumber] = (0, import_react11.useState)("");
2876
+ const [callDuration, setCallDuration] = (0, import_react11.useState)(0);
2877
+ const { position, isDragging, dragRef, handleMouseDown, handleTouchStart } = useDraggable(
2878
+ state.controlPanelPosition,
2879
+ (newPosition) => sdkStateManager.setControlPanelPosition(newPosition)
2880
+ );
2881
+ const {
2882
+ position: iframePosition,
2883
+ isDragging: iframeIsDragging,
2884
+ dragRef: iframeDragRef,
2885
+ handleMouseDown: iframeHandleMouseDown,
2886
+ handleTouchStart: iframeHandleTouchStart
2887
+ } = useDraggable(
2888
+ state.iframePosition,
2889
+ (newPosition) => sdkStateManager.setIframePosition(newPosition)
2890
+ );
2891
+ const [clickToCall, { isLoading: clickToCallLoading }] = usePostRequest({
2892
+ onSuccess: () => {
2893
+ setPhoneNumber("");
2894
+ setDialerAnchorEl(null);
2895
+ }
2896
+ });
2897
+ const [holdOrUnHold, { isLoading: holdOrUnHoldLoading }] = usePostRequest({
2898
+ onSuccess: () => {
2899
+ sdkStateManager.setHolding(!state.isHolding);
2900
+ },
2901
+ onError: (error) => {
2902
+ console.log("\u274C Hold operation error:", error);
2903
+ }
2904
+ });
2905
+ const [muteOrUnMute, { isLoading: muteOrUnMuteLoading }] = usePostRequest({
2906
+ onSuccess: () => {
2907
+ sdkStateManager.setMuted(!state.isMuted);
2908
+ },
2909
+ onError: (error) => {
2910
+ console.log("\u274C Mute operation error:", error);
2911
+ }
2912
+ });
2913
+ const [readyAgentStatus, { isLoading: agentReadyLoading }] = usePostRequest();
2914
+ const [updateAgentStatus, { isLoading }] = usePostRequest();
2915
+ const [endCall, { isLoading: endCallLoading }] = usePostRequest();
2916
+ const handleCloseQueueCounts = () => {
2917
+ setAnchorEl(null);
2918
+ };
2919
+ const handleOpenDialer = (event) => {
2920
+ setShowIframe(true);
2921
+ setDialerAnchorEl(event.currentTarget);
2922
+ sdkStateManager.setStatus("dial");
2923
+ };
2924
+ const handleCloseDialer = () => {
2925
+ if (state.status !== "on call") {
2926
+ sdkStateManager.setStatus("idle");
2927
+ }
2928
+ setDialerAnchorEl(null);
2929
+ };
2930
+ const handleOpenAgentStatus = (event) => {
2931
+ setStatusAnchorEl(event.currentTarget);
2932
+ };
2933
+ const handleCloseAgentStatus = () => {
2934
+ setStatusAnchorEl(null);
2935
+ };
2936
+ const handleAgentReady = () => {
2937
+ const payload = {
2938
+ action: "READYAGENT",
2939
+ userId: state.agentId
2940
+ };
2941
+ readyAgentStatus(END_POINT.READY_AGENT, payload);
2942
+ };
2943
+ const handleUpdateAgentStatus = (status) => {
2944
+ setStatusAnchorEl(null);
2945
+ const payload = {
2946
+ action: "AGENTBREAK",
2947
+ break_type: status,
2948
+ userId: state.agentId
2949
+ };
2950
+ updateAgentStatus(END_POINT.UPDATE_AGENT_BREAK, payload);
2951
+ };
2952
+ const handleStartCall = (number) => {
2953
+ if (number.length !== 10) {
2954
+ showToast("Invalid phone number", "error");
2955
+ } else if (!/^\d+$/.test(number)) {
2956
+ showToast("Invalid phone number", "error");
2957
+ } else {
2958
+ const payload = {
2959
+ action: "CALL",
2960
+ phone_number: number,
2961
+ userId: state.agentId
2962
+ };
2963
+ clickToCall(END_POINT.CLICK_TO_CALL, payload);
2964
+ }
2965
+ };
2966
+ const handleHoldToggle = () => {
2967
+ const payload = {
2968
+ action: state.isHolding ? "UNHOLD" : "HOLD",
2969
+ userId: state.agentId
2970
+ };
2971
+ holdOrUnHold(END_POINT.HOLD_CALL, payload);
2972
+ };
2973
+ const handleMuteToggle = () => {
2974
+ const payload = {
2975
+ action: state.isMuted ? "UNMUTE" : "MUTE",
2976
+ userId: state.agentId
2977
+ };
2978
+ muteOrUnMute(END_POINT.MUTE_CALL, payload);
2979
+ };
2980
+ const handleEndCall = (data) => {
2981
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2, _m2, _n2, _o2, _p2;
2982
+ const payload = {
2983
+ action: "ENDCALL",
2984
+ userId: state.agentId,
2985
+ processid: (_c2 = (_b2 = (_a3 = state.process) == null ? void 0 : _a3.process_id) == null ? void 0 : _b2.toString()) != null ? _c2 : "",
2986
+ process_name: (_e2 = (_d2 = state.process) == null ? void 0 : _d2.process_name) != null ? _e2 : "",
2987
+ callreferenceid: (_g2 = (_f2 = state.callData) == null ? void 0 : _f2.convox_id) != null ? _g2 : "",
2988
+ mobile_number: (_i2 = (_h2 = state.callData) == null ? void 0 : _h2.phone_number) != null ? _i2 : "",
2989
+ disposition: (_k2 = (_j2 = data == null ? void 0 : data.disposition) == null ? void 0 : _j2.value) != null ? _k2 : "",
2990
+ set_followUp: (_m2 = (_l2 = data == null ? void 0 : data.followUp) == null ? void 0 : _l2.value) != null ? _m2 : "",
2991
+ callback_date: (_n2 = data == null ? void 0 : data.callbackDate) != null ? _n2 : "",
2992
+ callback_hrs: (_o2 = data == null ? void 0 : data.callbackHrs) != null ? _o2 : "",
2993
+ callback_mins: (_p2 = data == null ? void 0 : data.callbackMins) != null ? _p2 : "",
2994
+ endcall_type: "CLOSE"
2995
+ };
2996
+ setPhoneNumber("");
2997
+ endCall(END_POINT.END_CALL, payload);
2998
+ sdkStateManager.endCall();
2999
+ setOpenCallDisposition(false);
3000
+ };
3001
+ (0, import_react11.useEffect)(() => {
3002
+ const handleBeforeUnload = (e) => {
3003
+ e.preventDefault();
3004
+ };
3005
+ window.addEventListener("beforeunload", handleBeforeUnload);
3006
+ return () => {
3007
+ window.removeEventListener("beforeunload", handleBeforeUnload);
3008
+ };
3009
+ }, []);
3010
+ (0, import_react11.useEffect)(() => {
3011
+ let interval;
3012
+ if (state.callData.status && state.callData.status === "ONCALL") {
3013
+ interval = setInterval(() => {
3014
+ const elapsed = Math.floor((Date.now() - state.callStartTime) / 1e3);
3015
+ setCallDuration(elapsed);
3016
+ }, 1e3);
3017
+ } else {
3018
+ setCallDuration(0);
3019
+ }
3020
+ return () => {
3021
+ if (interval) clearInterval(interval);
3022
+ };
3023
+ }, [state.callData.status]);
3024
+ (0, import_react11.useEffect)(() => {
3025
+ createAudioElement().then((audio) => {
3026
+ audioRef.current = audio;
3027
+ }).catch((error) => {
3028
+ console.error("Failed to load audio element:", error);
3029
+ });
3030
+ return () => {
3031
+ if (audioRef.current) {
3032
+ audioRef.current.pause();
3033
+ audioRef.current.currentTime = 0;
3034
+ audioRef.current.src = "";
3035
+ audioRef.current = null;
3036
+ }
3037
+ cleanupAudioResources();
3038
+ };
3039
+ }, []);
3040
+ (0, import_react11.useEffect)(() => {
3041
+ if (onDataChange && state.callData) {
3042
+ const { process_id, process_name, status, phone_number, agent_id, convox_id } = state.callData;
3043
+ const callData = {
3044
+ phone_number,
3045
+ status,
3046
+ callReferenceId: convox_id,
3047
+ agent_id,
3048
+ process_id,
3049
+ process_name
3050
+ };
3051
+ onDataChange(callData);
3052
+ }
3053
+ }, [state.callData, onDataChange]);
3054
+ (0, import_react11.useEffect)(() => {
3055
+ if (state.agentId) {
3056
+ axios_default.post(END_POINT.PROCESS_LIST, {
3057
+ userId: state.agentId,
3058
+ action: "GETAGENTPROCESSLIST",
3059
+ refno: "1234221233"
3060
+ }).then((res) => {
3061
+ var _a3, _b2;
3062
+ if (res && res.data && ((_a3 = res == null ? void 0 : res.data) == null ? void 0 : _a3.length) > 1) {
3063
+ setProcessList(res.data.data);
3064
+ setOpenProcessorDialog(true);
3065
+ } else {
3066
+ sdkStateManager.setProcess((_b2 = res == null ? void 0 : res.data) == null ? void 0 : _b2.data[0]);
3067
+ setOpenProcessorDialog(false);
3068
+ }
3069
+ }).catch((err) => {
3070
+ showToast(err.response.data.message, "error");
3071
+ });
3072
+ } else {
3073
+ console.log("No agentId available, skipping API call");
3074
+ }
3075
+ }, [state.agentId]);
3076
+ const connectWebSocket = () => {
3077
+ if (!state.agentId) {
3078
+ console.log("No agentId available, cannot connect WebSocket");
3079
+ return;
3080
+ }
3081
+ if (reconnectTimeoutRef.current) {
3082
+ clearTimeout(reconnectTimeoutRef.current);
3083
+ reconnectTimeoutRef.current = null;
3084
+ }
3085
+ try {
3086
+ webSocketRef.current = new WebSocket(`${WS_END_POINT.WS}?agent_id=${state.agentId}`);
3087
+ webSocketRef.current.onopen = () => {
3088
+ console.log("\u{1F310} WebSocket connection established");
3089
+ reconnectAttemptsRef.current = 0;
3090
+ if (pingIntervalRef.current) {
3091
+ clearInterval(pingIntervalRef.current);
3092
+ }
3093
+ pingIntervalRef.current = setInterval(() => {
3094
+ if (webSocketRef.current && webSocketRef.current.readyState === WebSocket.OPEN) {
3095
+ try {
3096
+ webSocketRef.current.send(JSON.stringify({ type: "ping" }));
3097
+ console.log("\u{1F4E1} WebSocket ping sent");
3098
+ } catch (error) {
3099
+ console.error("Failed to send ping:", error);
3100
+ }
3101
+ }
3102
+ }, 3e4);
3103
+ };
3104
+ webSocketRef.current.onmessage = (event) => {
3105
+ try {
3106
+ const data = JSON.parse(event.data);
3107
+ if (data.type === "pong") {
3108
+ console.log("\u{1F4E1} WebSocket pong received");
3109
+ return;
3110
+ }
3111
+ const rls = localStorage.getItem("call-control-sdk-state");
3112
+ const confrence = getCombineConfrenceData(JSON.parse(rls || "{}"), data);
3113
+ sdkStateManager.updateCallData(data);
3114
+ sdkStateManager.updateConferenceData([...confrence]);
3115
+ if (data.status === "RINGING" || data.status === "DIALING") {
3116
+ if (audioRef.current) {
3117
+ audioRef.current.play().catch((error) => {
3118
+ console.error("Failed to play ringtone:", error);
3119
+ });
3120
+ }
3121
+ } else {
3122
+ if (audioRef.current) {
3123
+ audioRef.current.pause();
3124
+ audioRef.current.currentTime = 0;
3125
+ }
3126
+ }
3127
+ if (data.status === "ONCALL") {
3128
+ sdkStateManager.startCall();
3129
+ if (!showIframe) {
3130
+ setShowIframe(true);
3131
+ }
3132
+ }
3133
+ if (data.status === "WRAPUP") {
3134
+ sdkStateManager.endCall();
3135
+ }
3136
+ } catch (e) {
3137
+ console.log("\u{1F4E8} Raw message:", event.data);
3138
+ }
3139
+ };
3140
+ webSocketRef.current.onclose = (event) => {
3141
+ console.log("\u{1F50C} WebSocket connection closed", event.code, event.reason);
3142
+ if (pingIntervalRef.current) {
3143
+ clearInterval(pingIntervalRef.current);
3144
+ pingIntervalRef.current = null;
3145
+ }
3146
+ if (event.code !== 1e3 && reconnectAttemptsRef.current < maxReconnectAttempts) {
3147
+ reconnectAttemptsRef.current += 1;
3148
+ const delay = Math.min(
3149
+ baseReconnectDelay * Math.pow(2, reconnectAttemptsRef.current - 1),
3150
+ maxReconnectDelay
3151
+ );
3152
+ console.log(
3153
+ `\u{1F504} Attempting to reconnect WebSocket (attempt ${reconnectAttemptsRef.current}/${maxReconnectAttempts}) in ${delay}ms`
3154
+ );
3155
+ reconnectTimeoutRef.current = setTimeout(() => {
3156
+ connectWebSocket();
3157
+ }, delay);
3158
+ } else if (reconnectAttemptsRef.current >= maxReconnectAttempts) {
3159
+ console.error("\u274C Maximum reconnection attempts reached. Please refresh the page.");
3160
+ showToast("WebSocket connection failed. Please refresh the page.", "error");
3161
+ }
3162
+ };
3163
+ webSocketRef.current.onerror = (error) => {
3164
+ console.error("\u274C WebSocket error:", error);
3165
+ };
3166
+ } catch (error) {
3167
+ console.error("\u274C Failed to create WebSocket:", error);
3168
+ if (reconnectAttemptsRef.current < maxReconnectAttempts) {
3169
+ reconnectAttemptsRef.current += 1;
3170
+ const delay = Math.min(
3171
+ baseReconnectDelay * Math.pow(2, reconnectAttemptsRef.current - 1),
3172
+ maxReconnectDelay
3173
+ );
3174
+ reconnectTimeoutRef.current = setTimeout(() => {
3175
+ connectWebSocket();
3176
+ }, delay);
3177
+ }
3178
+ }
3179
+ };
3180
+ (0, import_react11.useEffect)(() => {
3181
+ if (state.agentId) {
3182
+ connectWebSocket();
3183
+ }
3184
+ return () => {
3185
+ if (reconnectTimeoutRef.current) {
3186
+ clearTimeout(reconnectTimeoutRef.current);
3187
+ reconnectTimeoutRef.current = null;
3188
+ }
3189
+ if (pingIntervalRef.current) {
3190
+ clearInterval(pingIntervalRef.current);
3191
+ pingIntervalRef.current = null;
3192
+ }
3193
+ if (webSocketRef.current) {
3194
+ webSocketRef.current.close(1e3, "Component unmounting");
3195
+ webSocketRef.current = null;
3196
+ }
3197
+ reconnectAttemptsRef.current = 0;
3198
+ };
3199
+ }, [state.agentId]);
3200
+ if (!state.isInitialized || !state.process) {
3201
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Box, { children: Boolean(openProcessorDialog) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3202
+ ProcessorListDialog,
3203
+ {
3204
+ processList,
3205
+ open: openProcessorDialog,
3206
+ setOpen: setOpenProcessorDialog,
3207
+ handleSelectedProcessor: (data) => {
3208
+ sdkStateManager.setProcess(data);
3209
+ }
3210
+ }
3211
+ ) });
3212
+ }
3213
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
3214
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3215
+ import_material4.Fade,
3216
+ {
3217
+ in: true,
3218
+ timeout: 300,
3219
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3220
+ import_material4.Paper,
3221
+ {
3222
+ ref: ((_d = state.sdkConfig) == null ? void 0 : _d.isDraggable) ? dragRef : null,
3223
+ elevation: isDragging ? 4 : ((_e = state.sdkConfig) == null ? void 0 : _e.isDraggable) ? 1 : 0,
3224
+ sx: {
3225
+ position: ((_f = state.sdkConfig) == null ? void 0 : _f.isDraggable) ? "fixed" : "relative",
3226
+ left: ((_g = state.sdkConfig) == null ? void 0 : _g.isDraggable) ? position.x : "auto",
3227
+ top: ((_h = state.sdkConfig) == null ? void 0 : _h.isDraggable) ? position.y : "auto",
3228
+ display: "inline-block",
3229
+ width: "auto",
3230
+ flexShrink: 0,
3231
+ whiteSpace: "nowrap",
3232
+ p: 0.5,
3233
+ borderRadius: 3,
3234
+ bgcolor: "background.paper",
3235
+ zIndex: ((_i = state.sdkConfig) == null ? void 0 : _i.isDraggable) ? Number.MAX_SAFE_INTEGER : 0,
3236
+ transition: theme.transitions.create(["box-shadow", "transform"], {
3237
+ duration: theme.transitions.duration.short
3238
+ }),
3239
+ userSelect: "none"
3240
+ },
3241
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3242
+ import_material4.Box,
3243
+ {
3244
+ sx: {
3245
+ display: "flex",
3246
+ alignItems: "center"
3247
+ },
3248
+ children: [
3249
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3250
+ import_material4.Box,
3251
+ {
3252
+ sx: {
3253
+ display: "flex",
3254
+ alignItems: "center",
3255
+ gap: 1,
3256
+ margin: "0px 10px"
3257
+ },
3258
+ children: [
3259
+ ((_j = state.sdkConfig) == null ? void 0 : _j.isDraggable) && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3260
+ import_material4.IconButton,
3261
+ {
3262
+ component: "div",
3263
+ size: "small",
3264
+ sx: {
3265
+ cursor: "all-scroll"
3266
+ },
3267
+ onMouseDown: handleMouseDown,
3268
+ onTouchStart: handleTouchStart,
3269
+ children: [
3270
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.DragIndicator, {}),
3271
+ " "
3272
+ ]
3273
+ }
3274
+ ),
3275
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Box, { children: !((_k = state.sdkConfig) == null ? void 0 : _k.disabledDialButton) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Tooltip, { title: "Dial", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3276
+ import_material4.IconButton,
3277
+ {
3278
+ size: "small",
3279
+ onClick: (e) => {
3280
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2, _h2;
3281
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) !== "ONCALL" && ((_d2 = (_c2 = state.callData) == null ? void 0 : _c2.status) == null ? void 0 : _d2.toUpperCase()) !== "BREAK" && ((_f2 = (_e2 = state.callData) == null ? void 0 : _e2.status) == null ? void 0 : _f2.toUpperCase()) !== "RINGING" && ((_h2 = (_g2 = state.callData) == null ? void 0 : _g2.status) == null ? void 0 : _h2.toUpperCase()) !== "WRAPUP") {
3282
+ handleOpenDialer(e);
3283
+ }
3284
+ },
3285
+ sx: {
3286
+ bgcolor: "action.hover",
3287
+ "&:hover": {
3288
+ bgcolor: "warning"
3289
+ }
3290
+ },
3291
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3292
+ import_icons_material2.WifiCalling3,
3293
+ {
3294
+ sx: {
3295
+ color: ((_m = (_l = state.callData) == null ? void 0 : _l.status) == null ? void 0 : _m.toUpperCase()) === "ONCALL" || ((_o = (_n = state.callData) == null ? void 0 : _n.status) == null ? void 0 : _o.toUpperCase()) === "BREAK" || ((_q = (_p = state.callData) == null ? void 0 : _p.status) == null ? void 0 : _q.toUpperCase()) === "RINGING" || ((_s = (_r = state.callData) == null ? void 0 : _r.status) == null ? void 0 : _s.toUpperCase()) === "WRAPUP" ? "action.selected" : "success.main"
3296
+ }
3297
+ }
3298
+ )
3299
+ }
3300
+ ) }) }),
3301
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3302
+ import_material4.Typography,
3303
+ {
3304
+ sx: {
3305
+ color: "success.main",
3306
+ width: "40px",
3307
+ marginRight: "10px",
3308
+ fontSize: "18px",
3309
+ fontWeight: "600"
3310
+ },
3311
+ children: formatDuration(callDuration)
3312
+ }
3313
+ ),
3314
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3315
+ import_material4.Chip,
3316
+ {
3317
+ sx: {
3318
+ padding: "18px 0px"
3319
+ },
3320
+ label: isLoading || agentReadyLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3321
+ import_material4.Box,
3322
+ {
3323
+ sx: {
3324
+ fontWeight: "bold",
3325
+ width: "60px",
3326
+ display: "flex",
3327
+ alignItems: "center",
3328
+ justifyContent: "center"
3329
+ },
3330
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.CircularProgress, { size: "20px" })
3331
+ }
3332
+ ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3333
+ import_material4.Typography,
3334
+ {
3335
+ variant: "body2",
3336
+ sx: {
3337
+ fontWeight: "bold",
3338
+ width: "60px",
3339
+ textAlign: "center"
3340
+ },
3341
+ children: (_v = (_u = (_t = state.callData) == null ? void 0 : _t.status) == null ? void 0 : _u.toUpperCase()) != null ? _v : "N/A"
3342
+ }
3343
+ ),
3344
+ onClick: handleOpenAgentStatus,
3345
+ deleteIcon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.KeyboardArrowDown, { color: "primary" }),
3346
+ onDelete: handleOpenAgentStatus
3347
+ }
3348
+ )
3349
+ ]
3350
+ }
3351
+ ),
3352
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3353
+ import_material4.Box,
3354
+ {
3355
+ sx: {
3356
+ display: "flex",
3357
+ gap: 1,
3358
+ justifyContent: "center",
3359
+ alignItems: "center"
3360
+ },
3361
+ children: [
3362
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Tooltip, { title: "Agent Ready", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3363
+ import_material4.Button,
3364
+ {
3365
+ variant: ((_x = (_w = state.callData) == null ? void 0 : _w.status) == null ? void 0 : _x.toUpperCase()) === "BREAK" || ((_z = (_y = state.callData) == null ? void 0 : _y.status) == null ? void 0 : _z.toUpperCase()) === "MISSED" ? "outlined" : "contained",
3366
+ onClick: (e) => {
3367
+ var _a3, _b2, _c2, _d2;
3368
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "BREAK" || ((_d2 = (_c2 = state.callData) == null ? void 0 : _c2.status) == null ? void 0 : _d2.toUpperCase()) === "MISSED") {
3369
+ e.stopPropagation();
3370
+ handleAgentReady();
3371
+ }
3372
+ },
3373
+ classes: {
3374
+ root: ((_B = (_A = state.callData) == null ? void 0 : _A.status) == null ? void 0 : _B.toUpperCase()) === "BREAK" || ((_D = (_C = state.callData) == null ? void 0 : _C.status) == null ? void 0 : _D.toUpperCase()) === "MISSED" ? "outlined" : "enabled"
3375
+ },
3376
+ sx: __spreadValues({}, ((_F = (_E = state.callData) == null ? void 0 : _E.status) == null ? void 0 : _F.toUpperCase()) === "BREAK" || ((_H = (_G = state.callData) == null ? void 0 : _G.status) == null ? void 0 : _H.toUpperCase()) === "MISSED" ? outlined : enabled),
3377
+ disabled: agentReadyLoading,
3378
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.SupportAgent, {})
3379
+ }
3380
+ ) }),
3381
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Tooltip, { title: state.isHolding ? "Resume" : "Hold", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3382
+ import_material4.Button,
3383
+ {
3384
+ variant: state.isHolding && ((_J = (_I = state.callData) == null ? void 0 : _I.status) == null ? void 0 : _J.toUpperCase()) === "ONCALL" ? "contained" : "outlined",
3385
+ onClick: (e) => {
3386
+ e.stopPropagation();
3387
+ handleHoldToggle();
3388
+ },
3389
+ sx: state.isHolding && ((_L = (_K = state.callData) == null ? void 0 : _K.status) == null ? void 0 : _L.toUpperCase()) === "ONCALL" ? __spreadValues({}, enabled) : ((_N = (_M = state.callData) == null ? void 0 : _M.status) == null ? void 0 : _N.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3390
+ disabled: ((_P = (_O = state.callData) == null ? void 0 : _O.status) == null ? void 0 : _P.toUpperCase()) !== "ONCALL" && !state.isHolding || holdOrUnHoldLoading,
3391
+ children: holdOrUnHoldLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3392
+ import_material4.CircularProgress,
3393
+ {
3394
+ size: "20px",
3395
+ sx: {
3396
+ color: theme.palette.primary.main
3397
+ }
3398
+ }
3399
+ ) : state.isHolding ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.PlayArrow, {}) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Pause, {})
3400
+ }
3401
+ ) }),
3402
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Tooltip, { title: state.isMuted ? "Unmute" : "Mute", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3403
+ import_material4.Button,
3404
+ {
3405
+ variant: state.isHolding ? "outlined" : state.isMuted && ((_R = (_Q = state.callData) == null ? void 0 : _Q.status) == null ? void 0 : _R.toUpperCase()) === "ONCALL" ? "contained" : "outlined",
3406
+ onClick: (e) => {
3407
+ e.stopPropagation();
3408
+ handleMuteToggle();
3409
+ },
3410
+ sx: state.isHolding ? __spreadValues({}, disabled) : state.isMuted && ((_T = (_S = state.callData) == null ? void 0 : _S.status) == null ? void 0 : _T.toUpperCase()) === "ONCALL" ? __spreadValues({}, enabled) : ((_V = (_U = state.callData) == null ? void 0 : _U.status) == null ? void 0 : _V.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3411
+ disabled: ((_X = (_W = state.callData) == null ? void 0 : _W.status) == null ? void 0 : _X.toUpperCase()) !== "ONCALL" && !state.isMuted || muteOrUnMuteLoading || state.isHolding,
3412
+ children: muteOrUnMuteLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3413
+ import_material4.CircularProgress,
3414
+ {
3415
+ size: "20px",
3416
+ sx: {
3417
+ color: theme.palette.primary.main
3418
+ }
3419
+ }
3420
+ ) : state.isMuted ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.MicOff, {}) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Mic, {})
3421
+ }
3422
+ ) }),
3423
+ !((_Y = state.sdkConfig) == null ? void 0 : _Y.disableCallTransferButton) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Tooltip, { title: "Transfer Call", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3424
+ import_material4.Button,
3425
+ {
3426
+ variant: state.openCallTransferDialog ? "contained" : "outlined",
3427
+ onClick: (e) => {
3428
+ var _a3, _b2;
3429
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "ONCALL") {
3430
+ e.stopPropagation();
3431
+ sdkStateManager.setOpenCallTransferDialog(true);
3432
+ }
3433
+ },
3434
+ sx: state.openCallTransferDialog ? __spreadValues({}, enabled) : ((__ = (_Z = state.callData) == null ? void 0 : _Z.status) == null ? void 0 : __.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3435
+ disabled: ((_aa = (_$ = state.callData) == null ? void 0 : _$.status) == null ? void 0 : _aa.toUpperCase()) !== "ONCALL",
3436
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.TransferWithinAStation, {})
3437
+ }
3438
+ ) }),
3439
+ !((_ba = state.sdkConfig) == null ? void 0 : _ba.disableConferenceButton) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Tooltip, { title: "Conference Call", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3440
+ import_material4.Button,
3441
+ {
3442
+ variant: state.openConferenceDialog ? "contained" : "outlined",
3443
+ onClick: (e) => {
3444
+ var _a3, _b2;
3445
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "ONCALL") {
3446
+ e.stopPropagation();
3447
+ sdkStateManager.setOpenConferenceDialog(true);
3448
+ }
3449
+ },
3450
+ sx: state.openConferenceDialog ? __spreadValues({}, enabled) : ((_da = (_ca = state.callData) == null ? void 0 : _ca.status) == null ? void 0 : _da.toUpperCase()) === "ONCALL" ? __spreadValues({}, outlined) : __spreadValues({}, disabled),
3451
+ disabled: ((_fa = (_ea = state.callData) == null ? void 0 : _ea.status) == null ? void 0 : _fa.toUpperCase()) !== "ONCALL",
3452
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Group, {})
3453
+ }
3454
+ ) }),
3455
+ !((_ga = state.sdkConfig) == null ? void 0 : _ga.disableEndCallButton) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Tooltip, { title: "End Call", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3456
+ import_material4.Button,
3457
+ {
3458
+ variant: ((_ia = (_ha = state.callData) == null ? void 0 : _ha.status) == null ? void 0 : _ia.toUpperCase()) === "ONCALL" || ((_ka = (_ja = state.callData) == null ? void 0 : _ja.status) == null ? void 0 : _ka.toUpperCase()) === "RINGING" || ((_ma = (_la = state.callData) == null ? void 0 : _la.status) == null ? void 0 : _ma.toUpperCase()) === "WRAPUP" ? "contained" : "outlined",
3459
+ onClick: (e) => {
3460
+ var _a3, _b2, _c2, _d2, _e2, _f2;
3461
+ if (((_b2 = (_a3 = state.callData) == null ? void 0 : _a3.status) == null ? void 0 : _b2.toUpperCase()) === "ONCALL" || ((_d2 = (_c2 = state.callData) == null ? void 0 : _c2.status) == null ? void 0 : _d2.toUpperCase()) === "RINGING" || ((_f2 = (_e2 = state.callData) == null ? void 0 : _e2.status) == null ? void 0 : _f2.toUpperCase()) === "WRAPUP") {
3462
+ e.stopPropagation();
3463
+ setOpenCallDisposition(true);
3464
+ }
3465
+ },
3466
+ sx: ((_oa = (_na = state.callData) == null ? void 0 : _na.status) == null ? void 0 : _oa.toUpperCase()) === "ONCALL" || ((_qa = (_pa = state.callData) == null ? void 0 : _pa.status) == null ? void 0 : _qa.toUpperCase()) === "RINGING" || ((_sa = (_ra = state.callData) == null ? void 0 : _ra.status) == null ? void 0 : _sa.toUpperCase()) === "WRAPUP" ? __spreadProps(__spreadValues({}, enabled), {
3467
+ borderRight: "1px",
3468
+ backgroundColor: "error.main",
3469
+ minWidth: "60px !important",
3470
+ boxShadow: " 0px 2px 1px #5f3f3f",
3471
+ border: `1px solid ${theme.palette.error.light}`,
3472
+ height: "40px",
3473
+ "&:hover": {
3474
+ bgcolor: "error.light",
3475
+ boxShadow: " 0px 2px 1px #5f3f3f",
3476
+ border: `0px solid ${theme.palette.error.light}`
3477
+ },
3478
+ "&:active": {
3479
+ bgcolor: "error.light",
3480
+ boxShadow: `inset 1px -2px 4px ${theme.palette.primary.light}`
3481
+ }
3482
+ }) : __spreadProps(__spreadValues({}, disabled), {
3483
+ minWidth: "60px !important"
3484
+ }),
3485
+ disabled: ((_ua = (_ta = state.callData) == null ? void 0 : _ta.status) == null ? void 0 : _ua.toUpperCase()) !== "ONCALL" && ((_wa = (_va = state.callData) == null ? void 0 : _va.status) == null ? void 0 : _wa.toUpperCase()) !== "RINGING" && ((_ya = (_xa = state.callData) == null ? void 0 : _xa.status) == null ? void 0 : _ya.toUpperCase()) !== "WRAPUP" || endCallLoading,
3486
+ children: endCallLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3487
+ import_material4.CircularProgress,
3488
+ {
3489
+ size: "20px",
3490
+ color: "error"
3491
+ }
3492
+ ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.CallEnd, {})
3493
+ }
3494
+ ) })
3495
+ ]
3496
+ }
3497
+ )
3498
+ ]
3499
+ }
3500
+ )
3501
+ }
3502
+ )
3503
+ }
3504
+ ) }),
3505
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3506
+ import_material4.Fade,
3507
+ {
3508
+ in: true,
3509
+ timeout: 300,
3510
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3511
+ import_material4.Paper,
3512
+ {
3513
+ ref: iframeDragRef,
3514
+ elevation: iframeIsDragging ? 4 : 1,
3515
+ sx: {
3516
+ position: "absolute",
3517
+ left: iframePosition.x,
3518
+ top: iframePosition.y,
3519
+ borderRadius: 2,
3520
+ bgcolor: "background.paper",
3521
+ zIndex: Number.MAX_SAFE_INTEGER,
3522
+ transition: theme.transitions.create(["box-shadow", "transform"], {
3523
+ duration: theme.transitions.duration.short
3524
+ }),
3525
+ visibility: showIframe && !((_za = state.sdkConfig) == null ? void 0 : _za.disableSoftPhone) ? "visible" : "hidden",
3526
+ userSelect: "none"
3527
+ },
3528
+ children: [
3529
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3530
+ import_material4.Box,
3531
+ {
3532
+ sx: {
3533
+ display: "flex",
3534
+ alignItems: "center",
3535
+ justifyContent: "space-between",
3536
+ cursor: "all-scroll",
3537
+ padding: "0px 10px"
3538
+ },
3539
+ onMouseDown: iframeHandleMouseDown,
3540
+ onTouchStart: iframeHandleTouchStart,
3541
+ children: [
3542
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3543
+ import_icons_material2.DragIndicator,
3544
+ {
3545
+ sx: {
3546
+ transform: "rotate(90deg)",
3547
+ color: "#7b7b7b"
3548
+ }
3549
+ }
3550
+ ),
3551
+ " ",
3552
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.IconButton, { onClick: () => setShowIframe(false), children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Close, {}) })
3553
+ ]
3554
+ }
3555
+ ),
3556
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.Box, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3557
+ "iframe",
3558
+ {
3559
+ src: `https://${IP}/ConVoxCCS/iframe?agent_id=${state.agentId}&process_id=${(_Aa = state.process) == null ? void 0 : _Aa.process_id}`,
3560
+ height: 380,
3561
+ width: 420,
3562
+ allow: "camera; microphone; autoplay",
3563
+ style: {
3564
+ border: "none"
3565
+ }
3566
+ }
3567
+ ) })
3568
+ ]
3569
+ }
3570
+ )
3571
+ }
3572
+ ),
3573
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3574
+ import_material4.Menu,
3575
+ {
3576
+ anchorEl: dialerAnchorEl,
3577
+ open: Boolean(dialerAnchorEl),
3578
+ onClose: handleCloseDialer,
3579
+ onClick: (e) => e.stopPropagation(),
3580
+ sx: {
3581
+ zIndex: 99999
3582
+ },
3583
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3584
+ import_material4.Box,
3585
+ {
3586
+ sx: {
3587
+ all: "unset",
3588
+ padding: "10px",
3589
+ "&hover": {
3590
+ backgroundColor: "white"
3591
+ }
3592
+ },
3593
+ children: [
3594
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3595
+ import_material4.TextField,
3596
+ {
3597
+ size: "small",
3598
+ value: phoneNumber,
3599
+ placeholder: "Enter Mobile No.",
3600
+ onChange: (e) => {
3601
+ setPhoneNumber(e.target.value);
3602
+ }
3603
+ }
3604
+ ),
3605
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3606
+ import_material4.IconButton,
3607
+ {
3608
+ color: "info",
3609
+ onClick: () => {
3610
+ handleStartCall(phoneNumber);
3611
+ },
3612
+ children: clickToCallLoading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3613
+ import_material4.CircularProgress,
3614
+ {
3615
+ size: "20px",
3616
+ sx: {
3617
+ color: theme.palette.success.main
3618
+ }
3619
+ }
3620
+ ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Phone, { color: "success" })
3621
+ }
3622
+ )
3623
+ ]
3624
+ }
3625
+ )
3626
+ }
3627
+ ),
3628
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3629
+ import_material4.Menu,
3630
+ {
3631
+ anchorEl: statusAnchorEl,
3632
+ open: Boolean(statusAnchorEl),
3633
+ onClose: handleCloseAgentStatus,
3634
+ onClick: (e) => e.stopPropagation(),
3635
+ sx: {
3636
+ zIndex: 99999
3637
+ },
3638
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_material4.MenuItem, { onClick: () => handleUpdateAgentStatus("Lunch"), children: "- Break" })
3639
+ }
3640
+ ),
3641
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3642
+ import_material4.Menu,
3643
+ {
3644
+ anchorEl,
3645
+ open: Boolean(anchorEl),
3646
+ onClose: handleCloseQueueCounts,
3647
+ onClick: (e) => e.stopPropagation(),
3648
+ sx: {
3649
+ zIndex: 99999
3650
+ },
3651
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
3652
+ import_material4.Box,
3653
+ {
3654
+ sx: {
3655
+ display: "flex",
3656
+ justifyContent: "flex-start",
3657
+ flexDirection: "column",
3658
+ padding: "0px 10px",
3659
+ "&hover": {
3660
+ backgroundColor: "white"
3661
+ }
3662
+ },
3663
+ children: [
3664
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3665
+ import_material4.Chip,
3666
+ {
3667
+ icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Layers, { color: "secondary" }),
3668
+ variant: "outlined",
3669
+ label: "Waiting - 25",
3670
+ sx: {
3671
+ margin: "4px 2px"
3672
+ }
3673
+ }
3674
+ ),
3675
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3676
+ import_material4.Chip,
3677
+ {
3678
+ icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Pending, { color: "info" }),
3679
+ label: "Pending - 99+",
3680
+ variant: "outlined",
3681
+ sx: {
3682
+ margin: "4px 2px"
3683
+ }
3684
+ }
3685
+ ),
3686
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3687
+ import_material4.Chip,
3688
+ {
3689
+ icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons_material2.Upcoming, { color: "success" }),
3690
+ variant: "outlined",
3691
+ label: "Upcoming - 66",
3692
+ sx: {
3693
+ margin: "4px 2px"
3694
+ }
3695
+ }
3696
+ )
3697
+ ]
3698
+ }
3699
+ )
3700
+ }
3701
+ ),
3702
+ Boolean(state.openConferenceDialog) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConferenceDialog, {}),
3703
+ Boolean(state.openCallTransferDialog) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CallTransferDialog, { open: state.openCallTransferDialog }),
3704
+ Boolean(openCallDisposition) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3705
+ EndCallDispositionDialog,
3706
+ {
3707
+ open: openCallDisposition,
3708
+ setOpen: setOpenCallDisposition,
3709
+ onSubmitDisposition: handleEndCall
3710
+ }
3711
+ ),
3712
+ Boolean(openCallHistoryDialog) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
3713
+ CallHistoryDialog,
3714
+ {
3715
+ open: openCallHistoryDialog,
3716
+ setOpen: setOpenCallHistoryDialog
3717
+ }
3718
+ )
3719
+ ] });
3720
+ }
3721
+
3722
+ // call-control-sdk/lib/components/SDKProvider.tsx
3723
+ var import_react12 = require("react");
3724
+ var import_jsx_runtime4 = require("react/jsx-runtime");
3725
+ var SDKProvider = (0, import_react12.memo)(({ children }) => {
3726
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { children });
3727
+ });
3728
+ SDKProvider.displayName = "SDKProvider";
3729
+
3730
+ // call-control-sdk/lib/components/callControlPanel.tsx
3731
+ var import_jsx_runtime5 = require("react/jsx-runtime");
3732
+ var CallControlPanel = (0, import_react13.memo)(({ onDataChange }) => {
3733
+ const handleDataChange = (0, import_react13.useCallback)(
3734
+ (data) => {
3735
+ try {
3736
+ if (onDataChange && typeof onDataChange === "function") {
3737
+ onDataChange(data);
3738
+ }
3739
+ } catch (error) {
3740
+ console.error("Error in CallControlPanel data change handler:", error);
3741
+ }
3742
+ },
3743
+ [onDataChange]
3744
+ );
3745
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SDKProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CallControls, { onDataChange: handleDataChange }) });
3746
+ });
3747
+ CallControlPanel.displayName = "CallControlPanel";
3748
+
3749
+ // call-control-sdk/index.ts
3750
+ async function initSDK({
3751
+ apiKey,
3752
+ tenantId,
3753
+ agentId,
3754
+ sdkConfig
3755
+ }) {
3756
+ if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
3757
+ throw new Error(
3758
+ "SDK initialization failed: API key is required and must be a non-empty string"
3759
+ );
3760
+ }
3761
+ if (!tenantId || typeof tenantId !== "string" || tenantId.trim().length === 0) {
3762
+ throw new Error(
3763
+ "SDK initialization failed: Tenant ID is required and must be a non-empty string"
3764
+ );
3765
+ }
3766
+ if (!agentId || typeof agentId !== "string" || agentId.trim().length === 0) {
3767
+ throw new Error(
3768
+ "SDK initialization failed: Agent ID is required and must be a non-empty string"
3769
+ );
3770
+ }
3771
+ try {
3772
+ const initResult = await eventTracker.init({
3773
+ apiKey: apiKey.trim(),
3774
+ tenantId: tenantId.trim(),
3775
+ agentId: agentId.trim(),
3776
+ baseUrl: BASE_URL
3777
+ });
3778
+ if (initResult) {
3779
+ console.log("SDK initialized successfully");
3780
+ sdkStateManager.initialize(
3781
+ apiKey.trim(),
3782
+ tenantId.trim(),
3783
+ agentId.trim(),
3784
+ sdkConfig,
3785
+ initResult
3786
+ );
3787
+ } else {
3788
+ console.error("SDK initialization failed: Event tracker initialization returned false");
3789
+ sdkStateManager.setInitCheck();
3790
+ throw new Error(
3791
+ "SDK initialization failed: Unable to establish connection with the CTI system"
3792
+ );
3793
+ }
3794
+ } catch (error) {
3795
+ console.error("SDK initialization error:", error);
3796
+ sdkStateManager.setInitCheck();
3797
+ if (error instanceof Error) {
3798
+ throw error;
3799
+ } else {
3800
+ throw new Error(`SDK initialization failed: ${String(error)}`);
3801
+ }
3802
+ }
3803
+ }
3804
+ function getSDKVersion() {
3805
+ return "6.x.x";
3806
+ }
3807
+ function isSDKInitialized() {
3808
+ return sdkStateManager.getState().isInitialized;
3809
+ }
3810
+ // Annotate the CommonJS export names for ESM import in node:
3811
+ 0 && (module.exports = {
3812
+ CallControlPanel,
3813
+ getSDKVersion,
3814
+ initSDK,
3815
+ isSDKInitialized,
3816
+ useClickToCall,
3817
+ useEndCall,
3818
+ useGetAuthorizationToken,
3819
+ useGetCallerData,
3820
+ useLogout
3821
+ });
2
3822
  //# sourceMappingURL=index.js.map