call-control-sdk 6.1.1 → 6.1.2

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