call-control-sdk 5.0.8 → 5.1.0

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