call-control-sdk 5.4.4 → 5.4.6

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