call-control-sdk 5.4.4 → 5.4.5

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