call-control-sdk 5.0.4 → 5.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var Ko=Object.defineProperty,jo=Object.defineProperties;var Yo=Object.getOwnPropertyDescriptors;var To=Object.getOwnPropertySymbols;var Xo=Object.prototype.hasOwnProperty,Jo=Object.prototype.propertyIsEnumerable;var jt=(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)&&jt(r,n,t[n]);if(To)for(var n of To(t))Jo.call(t,n)&&jt(r,n,t[n]);return r},M=(r,t)=>jo(r,Yo(t));var W=(r,t,n)=>jt(r,typeof t!="symbol"?t+"":t,n);import{ArrowDropDown as vn,CallEnd as Cn,Close as bn,DragIndicator as Mo,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 Vt,Fade as Bo,IconButton as Gt,Menu as Zt,MenuItem as Ho,Paper as $o,TextField as On,Tooltip as nt,Typography as zo,useTheme as Un}from"@mui/material";import{useCallback as Mn,useEffect as Kt,useRef as Bn,useState as G}from"react";var Yt=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||[]}},S=new Yt;import{useCallback as $t,useRef as Xt,useState as Lo}from"react";function Jt(r,t){let[n,i]=Lo(r),[c,e]=Lo(!1),u=Xt(),m=Xt({x:0,y:0}),C=Xt({x:0,y:0}),h=$t(b=>{let k=u.current;if(!k)return;let U=k.getBoundingClientRect(),O=window.innerWidth,o=window.innerHeight,g={x:Math.max(0,Math.min(b.x,O-U.width)),y:Math.max(0,Math.min(b.y,o-U.height))};i(g),t==null||t(g)},[t]),E=$t((b,k)=>{e(!0),m.current={x:b,y:k},C.current=n;let U=(f,p)=>{let x=f-m.current.x,T=p-m.current.y;h({x:C.current.x+x,y:C.current.y+T})},O=f=>{f.preventDefault(),U(f.clientX,f.clientY)},o=f=>{f.preventDefault();let p=f.touches[0];p&&U(p.clientX,p.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=$t(b=>{b.preventDefault(),E(b.clientX,b.clientY)},[E]),v=$t(b=>{b.preventDefault();let k=b.touches[0];k&&E(k.clientX,k.clientY)},[E]);return{position:n,isDragging:c,dragRef:u,handleMouseDown:P,handleTouchStart:v}}import{useState as Qo,useEffect as Vo}from"react";function at(){let[r,t]=Qo(S.getState());return Vo(()=>S.subscribe(()=>{t(S.getState())}),[]),r}var R="http://192.168.101.177:8095",Zo="ws://192.168.101.177: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-break?provider=convox`,CLICK_TO_CALL:`${R}${N.v1}/cti/click-to-call?provider=convox`,HOLD_CALL:`${R}${N.v1}/cti/hold-call?provider=convox`,MUTE_CALL:`${R}${N.v1}/cti/mute-call?provider=convox`,UNMUTE_CALL:`${R}${N.v1}/cti/unmute-call?provider=convox`,END_CALL:`${R}${N.v1}/cti/end-call?provider=convox`,LOGOUT:`${R}${N.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${R}${N.v1}/cti/conference-call?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${R}${N.v1}/cti/conference-call/hold-unhold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${R}${N.v1}/cti/conference-call/mute-unmute?provider=convox`,CONFERENCE_CALL_END:`${R}${N.v1}/cti/conference-call/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${R}${N.v1}/cti/conference-call/hangup-all-call?provider=convox`,TRANSFER_CALL:`${R}${N.v1}/cti/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/trasnfer-to-details?provider=convox`},Do={WS:`${Zo}${N.v1}/cti/ws`};import{useCallback as sn,useReducer as rn}from"react";import tn from"axios";var en="12345",Qt=tn.create({baseURL:R,headers:{"Content-Type":"application/json",Authorization:en},timeout:1e4});Qt.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))));Qt.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 j=Qt;import{Alert as on,Snackbar as nn}from"@mui/material";import{useState as an}from"react";import{jsx as Io}from"react/jsx-runtime";function ft(){let[r,t]=an(!1),n=(c,e)=>{e!=="clickaway"&&t(!1)};return{showToast:(c,e)=>(t(!0),Io(nn,{anchorOrigin:{vertical:"top",horizontal:"right"},open:r,onClose:n,children:Io(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}=ft(),[c,e]=rn(cn,ln);return[sn((m,C,h={})=>{e({type:"isLoading",payload:!0}),j.post(m,C,h).then(E=>{e({type:"isSuccess",payload:E.data}),t==null||t(E.data,C)}).catch(E=>{var v,b,k,U,O,o,g,f,p,x,T,L;let P={status:(b=(v=E.response)==null?void 0:v.status)!=null?b:500,message:((U=(k=E.response)==null?void 0:k.data)==null?void 0:U.detail)||((o=(O=E.response)==null?void 0:O.data)==null?void 0:o.message)||E.message||"An unknown error occurred",data:(f=(g=E.response)==null?void 0:g.data)!=null?f:null,statusText:(x=(p=E.response)==null?void 0:p.statusText)!=null?x:"",code:(T=E==null?void 0:E.code)!=null?T:"",name:(L=E==null?void 0:E.name)!=null?L:""};i(P.message,"error"),e({type:"isError",payload:P}),n==null||n(P,C)}).finally(()=>{e({type:"isLoading",payload:!1})})},[t,n,i]),c]};import{Call as Wt,CallEnd as Ro,CallSplit as un,Close as Ft,Mic as gn,MicOff as fn,Pause as mn,PhoneDisabled as xn,PlayArrow as hn,SupportAgent as qt}from"@mui/icons-material";import{Box as _,Button as z,Dialog as xt,IconButton as tt,Paper as ht,TextField as rt,Typography as B,Autocomplete as wo,Grid as it,Tooltip as mt,useTheme as yn}from"@mui/material";import{useEffect as _o,useState as ko}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}`}}}},zt=dn;import{Fragment as lt,jsx as s,jsxs as I}from"react/jsx-runtime";function Ao({open:r,setOpen:t}){var U,O;let n=at(),{disabled:i,enabled:c,outlined:e}=zt(),u=yn(),m=()=>{t(!1)},C=(o,g)=>{S.setConferenceLine(l(l({},o),g))},h=(o,g)=>{var x,T,L,D;let f=l(l({},o),g),p={action:"EXTERNAL_CONFERENCE",operation:`CALL${f.line}`,line_used:String(f.line),thirdparty_no:f.phone,userid:(T=(x=n.callData)==null?void 0:x.agent_id)!=null?T:"",process:(D=(L=n.callData)==null?void 0:L.process_name)!=null?D:""};j.post(w.CONFERENCE_CALL,p).then(()=>{S.setConferenceLine(l(l({},o),g))})},E=(o,g)=>{var x,T,L,D;let f=l(l({},o),g),p={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(f.line),thirdparty_no:f.phone,userid:(T=(x=n.callData)==null?void 0:x.agent_id)!=null?T:"",process:(D=(L=n.callData)==null?void 0:L.process_name)!=null?D:""};j.post(w.CONFERENCE_CALL,p).then(()=>{S.setConferenceLine(l(l({},o),g))})},P=(o,g,f)=>{var T,L,D,H;let p=l(l({},o),g),x={action:"EXTERNAL_CONFERENCE",operation:f,hold_channel_no:f==="HOLDUSER"?`hold${p.line}`:`unhold${p.line}`,userid:(L=(T=n.callData)==null?void 0:T.agent_id)!=null?L:"",process:(H=(D=n.callData)==null?void 0:D.process_name)!=null?H:""};j.post(w.CONFERENCE_CALL_HOLD_OR_UN_HOLD,x).then(()=>{S.setConferenceLine(l(l({},o),g))})},v=(o,g,f)=>{var T,L,D,H;let p=l(l({},o),g),x={action:"EXTERNAL_CONFERENCE",operation:f,channel_no:f==="MUTEUSER"?`mute${p.line}`:`play${p.line}`,userid:(L=(T=n.callData)==null?void 0:T.agent_id)!=null?L:"",thirdparty_no:p.phone,process:(H=(D=n.callData)==null?void 0:D.process_name)!=null?H:""};j.post(w.CONFERENCE_CALL_MUTE_OT_UN_MUTE,x).then(()=>{S.setConferenceLine(l(l({},o),g))})},b=(o,g)=>{var x,T,L,D;let f=l(l({},o),g),p={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(f.line-1),user_type:`THIRDPARTY${f.line-1}`,thirdparty_no:f.phone,userid:(T=(x=n.callData)==null?void 0:x.agent_id)!=null?T:"",process:(D=(L=n.callData)==null?void 0:L.process_name)!=null?D:""};j.post(w.CONFERENCE_CALL_END,p).then(()=>{S.setConferenceLine(l(l({},o),g))})},k=()=>{var g,f,p,x;let o={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(f=(g=n.callData)==null?void 0:g.agent_id)!=null?f:"",process:(x=(p=n.callData)==null?void 0:p.process_name)!=null?x:""};j.post(w.CONFERENCE_CALL_END_ALL,o).then(()=>{S.resetConferenceLines(),m()})};return _o(()=>{var g,f,p,x;let o={line:1,status:(f=(g=n.callData)==null?void 0:g.status)!=null?f:"",type:"internal",phone:(x=(p=n.callData)==null?void 0:p.phone_number)!=null?x:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};S.setConferenceLine(o)},[]),s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:I(ht,{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(Ft,{})})]}),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,p;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:(p=o==null?void 0:o.status)!=null?p:""}),s(z,{sx:{textTransform:"capitalize"},size:"small",children:s(B,{variant:"body2",children:(o==null?void 0:o.line)===1?"Internal":"External"})}),s(rt,{size:"small",placeholder:"Phone Number",value:(o==null?void 0:o.phone)||"",disabled:(o==null?void 0:o.line)===1,onChange:x=>{C(o,{phone:x.target.value})}}),s(mt,{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:"error.light",boxShadow:`0px 2px 1px ${u.palette.success.light}`,border:`0px solid ${u.palette.success.light}`},"&:active":{bgcolor:"error.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(Wt,{sx:{color:o!=null&&o.isCallStart?"defalult":"#fff"}})})}),s(mt,{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:()=>{E(o,{isMergeCall:!0,status:"ONCALL"})},disabled:!(o!=null&&o.isCallStart),children:s(un,{})})}),s(mt,{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(mt,{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?v(o,{isMute:!1},"PLAYUSER"):v(o,{isMute:!0},"MUTEUSER")},disabled:!(o!=null&&o.isCallStart),children:o.isMute?s(fn,{}):s(gn,{})})}),s(mt,{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:()=>{b(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:s(Ro,{})}):s(z,{variant:o!=null&&o.isCallStart?"contained":"outlined",sx:M(l({},i),{visibility:"hidden",minWidth:"60px !important"}),onClick:()=>{b(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:s(B,{children:s(Ro,{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 No({open:r,setOpen:t}){var v,b,k,U,O,o,g,f;let[n]=$({onSuccess:p=>{console.log("res",p),t(!1)},onError:p=>{console.log("error",p)}}),i=at(),[c,e]=ko("process"),[u,{data:m}]=$(),[C,{data:h}]=$(),E=()=>{t(!1)},P=(p,x)=>{var T,L,D,H,Y,X,J,ct,pt,yt,vt,Ct,bt,dt,St,Et,Tt,Lt,Dt,st,It,Rt,wt,_t,kt,At,Nt,Pt,Ot,Ut,Mt,Bt,Ht;if(console.log(p,"data34"),x==="PROCESS"){let Q={mobile_number:(L=(T=i.callData)==null?void 0:T.phone_number)!=null?L:"",userid:(H=(D=i.callData)==null?void 0:D.agent_id)!=null?H:"",type:"PROCESS",transfer_to:(Y=p==null?void 0:p.process_name)!=null?Y:"",callreferenceid:(J=(X=i.callData)==null?void 0:X.convox_id)!=null?J:"",processid:String((pt=(ct=i.callData)==null?void 0:ct.process_id)!=null?pt:""),process_name:(vt=(yt=i.callData)==null?void 0:yt.process_name)!=null?vt:""};n(w.TRANSFER_CALL,Q)}else if(x==="QUEUE"){let Q={mobile_number:(bt=(Ct=i.callData)==null?void 0:Ct.phone_number)!=null?bt:"",userid:(St=(dt=i.callData)==null?void 0:dt.agent_id)!=null?St:"",type:"QUEUE",transfer_to:(Et=p==null?void 0:p.queue_name)!=null?Et:"",callreferenceid:(Lt=(Tt=i.callData)==null?void 0:Tt.convox_id)!=null?Lt:"",processid:String((st=(Dt=i.callData)==null?void 0:Dt.process_id)!=null?st:""),process_name:(Rt=(It=i.callData)==null?void 0:It.process_name)!=null?Rt:""};n(w.TRANSFER_CALL,Q)}else if(x==="AGENT"){let Q={mobile_number:(_t=(wt=i.callData)==null?void 0:wt.phone_number)!=null?_t:"",userid:(At=(kt=i.callData)==null?void 0:kt.agent_id)!=null?At:"",type:"AGENT",transfer_to:(Nt=p==null?void 0:p.user_id)!=null?Nt:"",callreferenceid:(Ot=(Pt=i.callData)==null?void 0:Pt.convox_id)!=null?Ot:"",processid:String((Mt=(Ut=i.callData)==null?void 0:Ut.process_id)!=null?Mt:""),process_name:(Ht=(Bt=i.callData)==null?void 0:Bt.process_name)!=null?Ht:""};n(w.TRANSFER_CALL,Q)}};return _o(()=>{u(w.AGENTS_LIST,{status:"IDLE",active:!0}),C(w.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:I(ht,{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:E,children:s(Ft,{})})]}),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:((b=(v=h==null?void 0:h.data)==null?void 0:v.process)==null?void 0:b.length)>0?(U=(k=h==null?void 0:h.data)==null?void 0:k.process)==null?void 0:U.map((p,x)=>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(qt,{sx:{marginRight:"4px"}}),p.process_name]}),s(tt,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{P(p,"PROCESS")},children:s(Wt,{})})]},x)):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((p,x)=>{var T,L,D,H,Y,X;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(qt,{sx:{marginRight:"4px"}}),p.queue_name,(D=(L=(T=h==null?void 0:h.data)==null?void 0:T.process)==null?void 0:L.find(J=>J.process_id===p.process_id))!=null&&D.process_name?s(B,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((X=(Y=(H=h==null?void 0:h.data)==null?void 0:H.process)==null?void 0:Y.find(J=>J.process_id===p.process_id))==null?void 0:X.process_name)+")"}):""]}),s(tt,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{P(p,"QUEUE")},children:s(Wt,{})})]},x)}):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:(m==null?void 0:m.length)>0?m.map((p,x)=>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(qt,{sx:{marginRight:"4px"}}),p.name]}),s(tt,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{P(p,"AGENT")},children:s(Wt,{})})]},x)):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 Po({open:r,setOpen:t,onSubmitDisposition:n}){var E,P;let[i,c]=ko({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=(v,b)=>{c(k=>M(l({},k),{[v]:b}))},C=()=>{c({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},h=()=>{C(),t(!1)};return s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:I(ht,{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(it,{container:!0,spacing:2,children:[s(it,{size:6,children:s(wo,{value:i.disposition,options:e,getOptionLabel:v=>v.label,onChange:(v,b)=>m("disposition",b),size:"small",renderInput:v=>s(rt,M(l({},v),{label:"Disposition",fullWidth:!0}))})}),s(it,{size:6,children:s(wo,{options:u,getOptionLabel:v=>v.label,value:i.followUp,onChange:(v,b)=>m("followUp",b),size:"small",renderInput:v=>s(rt,M(l({},v),{label:"Follow Up",fullWidth:!0}))})}),((P=(E=i==null?void 0:i.followUp)==null?void 0:E.label)==null?void 0:P.toLowerCase())==="yes"&&I(lt,{children:[s(it,{size:6,children:s(rt,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:i.callbackDate,onChange:v=>m("callbackDate",v.target.value),fullWidth:!0})}),s(it,{size:6,children:s(rt,{size:"small",label:"Hours (0-23)",type:"text",inputProps:{min:0,max:23},value:i.callbackHrs,onChange:v=>m("callbackHrs",v.target.value),fullWidth:!0})}),s(it,{size:6,children:s(rt,{size:"small",label:"Minutes (0-59)",type:"text",inputProps:{min:0,max:59},value:i.callbackMins,onChange:v=>m("callbackMins",v.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 Oo({open:r,setOpen:t,processList:n=[],handleSelectedProcessor:i}){return s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:I(ht,{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(Ft,{})})]}),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(qt,{sx:{marginRight:"4px"}}),e.process_name]})},u)):null})]})})})}function Uo({open:r,setOpen:t}){return s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:I(ht,{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(Ft,{})})]}),s(_,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Comming Soon..."})]})})})}import{Fragment as $n,jsx as d,jsxs as K}from"react/jsx-runtime";function Hn({onDataChange:r}){var oe,ne,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;let t=Un(),{disabled:n,enabled:i,outlined:c}=zt(),e=at(),{showToast:u}=ft(),m=Bn(null),[C,h]=G(null),[E,P]=G(!0),[v,b]=G(null),[k,U]=G(null),[O,o]=G(!1),[g,f]=G(!1),[p,x]=G(!1),[T,L]=G(!1),[D,H]=G(!1),[Y,X]=G(""),[J,ct]=G(0),{position:pt,isDragging:yt,dragRef:vt,handleMouseDown:Ct,handleTouchStart:bt}=Jt(e.controlPanelPosition,a=>S.setControlPanelPosition(a)),{position:dt,isDragging:St,dragRef:Et,handleMouseDown:Tt,handleTouchStart:Lt}=Jt(e.iframePosition,a=>S.setIframePosition(a)),[Dt,{data:st}]=$({onSuccess:a=>{var y;console.log("res",a),a&&a.processes&&((y=a==null?void 0:a.processes)==null?void 0:y.length)>1?L(!0):(S.setProcess(a==null?void 0:a.processes[0]),L(!1))},onError:()=>{L(!1)}}),[It]=$(),[Rt]=$({onSuccess:()=>{S.setHolding(!e.isHolding)},onError:a=>{console.log("error",a)}}),[wt]=$({onSuccess:()=>{S.setMuted(!e.isMuted)},onError:a=>{console.log("error",a)}}),[_t]=$(),[kt]=$(),[At]=$(),Nt=Mn(a=>{let y=Math.floor(a/60),A=a%60;return`${y.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`},[]),Pt=()=>{h(null)},Ot=a=>{P(!0),U(a.currentTarget),S.setStatus("dial")},Ut=()=>{e.status!=="on call"&&S.setStatus("idle"),U(null)},Mt=a=>{b(a.currentTarget)},Bt=()=>{b(null)},Ht=()=>{let a={action:"READYAGENT",userId:e.agentId};_t(w.READY_AGENT,a)},Q=a=>{b(null);let y={action:"AGENTBREAK",break_type:a,userId:e.agentId};kt(w.UPDATE_AGENT_BREAK,y)},Wo=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};It(w.CLICK_TO_CALL,y)}},qo=()=>{let a={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};Rt(w.HOLD_CALL,a)},Fo=()=>{let a={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};wt(w.MUTE_CALL,a)},Go=a=>{var A,q,F,V,Z,ut,gt,mo,xo,ho,yo,vo,Co,bo,So,Eo;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:(gt=(ut=e.callData)==null?void 0:ut.convox_id)!=null?gt:"",mobile_number:(xo=(mo=e.callData)==null?void 0:mo.phone_number)!=null?xo:"",disposition:(yo=(ho=a==null?void 0:a.disposition)==null?void 0:ho.value)!=null?yo:"",set_followUp:(Co=(vo=a==null?void 0:a.followUp)==null?void 0:vo.value)!=null?Co:"",callback_date:(bo=a==null?void 0:a.callbackDate)!=null?bo:"",callback_hrs:(So=a==null?void 0:a.callbackHrs)!=null?So:"",callback_mins:(Eo=a==null?void 0:a.callbackMins)!=null?Eo:"",endcall_type:"CLOSE"};X(""),At(w.END_CALL,y),S.endCall(),x(!1)};return Kt(()=>{let a;return e.callData.status&&e.callData.status==="ONCALL"?a=setInterval(()=>{let y=Math.floor((Date.now()-e.callStartTime)/1e3);ct(y)},1e3):ct(0),()=>{a&&clearInterval(a)}},[e.callData.status]),Kt(()=>{r&&r(e.callData)},[e.callData,r]),Kt(()=>{e.agentId?Dt(w.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}):console.log("No agentId available, skipping API call")},[e.agentId]),Kt(()=>(e.agentId&&(m.current=new WebSocket(`${Do.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),S.updateCallData(y),y.status==="ONCALL"&&S.startCall(),y.status==="WRAPUP"&&S.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?d(et,{children:!!T&&d(Oo,{processList:st==null?void 0:st.processes,open:T,setOpen:L,handleSelectedProcessor:a=>{S.setProcess(a)}})}):K($n,{children:[d(Bo,{in:!0,timeout:300,children:d($o,{ref:vt,elevation:yt?4:1,sx:{position:"fixed",left:pt.x,top:pt.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:K(et,{sx:{display:"flex",alignItems:"center"},children:[K(et,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[K(Gt,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:Ct,onTouchStart:bt,children:[d(Mo,{})," "]}),d(et,{sx:{marginRight:"10px"},children:d(nt,{title:"Dial",children:d(Gt,{size:"small",onClick:a=>{var y,A,q,F,V,Z,ut,gt;((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"&&((gt=(ut=e.callData)==null?void 0:ut.status)==null?void 0:gt.toUpperCase())!=="WRAPUP"&&Ot(a)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:d(Pn,{sx:{color:((ne=(oe=e.callData)==null?void 0:oe.status)==null?void 0:ne.toUpperCase())==="ONCALL"||((se=(ae=e.callData)==null?void 0:ae.status)==null?void 0:se.toUpperCase())==="BREAK"||((re=(ie=e.callData)==null?void 0:ie.status)==null?void 0:re.toUpperCase())==="RINGING"||((ce=(le=e.callData)==null?void 0:le.status)==null?void 0:ce.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),d(zo,{sx:{color:"success.main",width:"40px",marginRight:"10px"},children:Nt(J)}),d(zo,{variant:"body2",sx:{fontWeight:"bold"},children:(ue=(de=(pe=e.callData)==null?void 0:pe.status)==null?void 0:de.toUpperCase())!=null?ue:"N/A"}),K(ot,{size:"small",variant:"text",onClick:Mt,disabled:!!e.callStartTime,children:[d(vn,{})," "]})]}),K(et,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[d(nt,{title:"Agent Ready",children:d(ot,{variant:((fe=(ge=e.callData)==null?void 0:ge.status)==null?void 0:fe.toUpperCase())==="BREAK"||((xe=(me=e.callData)==null?void 0:me.status)==null?void 0:xe.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(),Ht())},classes:{root:((ye=(he=e.callData)==null?void 0:he.status)==null?void 0:ye.toUpperCase())==="BREAK"||((Ce=(ve=e.callData)==null?void 0:ve.status)==null?void 0:Ce.toUpperCase())==="MISSED"?"outlined":"enabled"},sx:l({},((Se=(be=e.callData)==null?void 0:be.status)==null?void 0:Se.toUpperCase())==="BREAK"||((Te=(Ee=e.callData)==null?void 0:Ee.status)==null?void 0:Te.toUpperCase())==="MISSED"?c:i),children:d(kn,{})})}),d(nt,{title:e.isHolding?"Resume":"Hold",children:d(ot,{variant:e.isHolding&&((De=(Le=e.callData)==null?void 0:Le.status)==null?void 0:De.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),qo()},sx:e.isHolding&&((Re=(Ie=e.callData)==null?void 0:Ie.status)==null?void 0:Re.toUpperCase())==="ONCALL"?l({},i):((_e=(we=e.callData)==null?void 0:we.status)==null?void 0:_e.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:((Ae=(ke=e.callData)==null?void 0:ke.status)==null?void 0:Ae.toUpperCase())!=="ONCALL"&&!e.isHolding,children:e.isHolding?d(_n,{}):d(In,{})})}),d(nt,{title:e.isMuted?"Unmute":"Mute",children:d(ot,{variant:e.isMuted&&((Pe=(Ne=e.callData)==null?void 0:Ne.status)==null?void 0:Pe.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),Fo()},sx:e.isMuted&&((Ue=(Oe=e.callData)==null?void 0:Oe.status)==null?void 0:Ue.toUpperCase())==="ONCALL"?l({},i):((Be=(Me=e.callData)==null?void 0:Me.status)==null?void 0:Be.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:(($e=(He=e.callData)==null?void 0:He.status)==null?void 0:$e.toUpperCase())!=="ONCALL"&&!e.isMuted,children:e.isMuted?d(Dn,{}):d(Ln,{})})}),d(nt,{title:"Transfer Call",children:d(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):((We=(ze=e.callData)==null?void 0:ze.status)==null?void 0:We.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:((Fe=(qe=e.callData)==null?void 0:qe.status)==null?void 0:Fe.toUpperCase())!=="ONCALL",children:d(An,{})})}),d(nt,{title:"Conference Call",children:d(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):((Ke=(Ge=e.callData)==null?void 0:Ge.status)==null?void 0:Ke.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:((Ye=(je=e.callData)==null?void 0:je.status)==null?void 0:Ye.toUpperCase())!=="ONCALL",children:d(Sn,{})})}),d(nt,{title:"Call History",children:d(ot,{variant:D?"contained":"outlined",onClick:a=>{a.stopPropagation(),H(!0)},sx:D?l({},i):l({},c),children:d(En,{})})}),d(nt,{title:"End Call",children:d(ot,{variant:((Je=(Xe=e.callData)==null?void 0:Xe.status)==null?void 0:Je.toUpperCase())==="ONCALL"||((Ve=(Qe=e.callData)==null?void 0:Qe.status)==null?void 0:Ve.toUpperCase())==="RINGING"||((to=(Ze=e.callData)==null?void 0:Ze.status)==null?void 0:to.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(),x(!0))},sx:((oo=(eo=e.callData)==null?void 0:eo.status)==null?void 0:oo.toUpperCase())==="ONCALL"||((ao=(no=e.callData)==null?void 0:no.status)==null?void 0:ao.toUpperCase())==="RINGING"||((io=(so=e.callData)==null?void 0:so.status)==null?void 0:io.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:((lo=(ro=e.callData)==null?void 0:ro.status)==null?void 0:lo.toUpperCase())!=="ONCALL"&&((po=(co=e.callData)==null?void 0:co.status)==null?void 0:po.toUpperCase())!=="RINGING"&&((go=(uo=e.callData)==null?void 0:uo.status)==null?void 0:go.toUpperCase())!=="WRAPUP",children:d(Cn,{})})})]})]})})}),d(Bo,{in:!0,timeout:300,children:K($o,{ref:Et,elevation:St?4:1,sx:{position:"fixed",left:dt.x,top:dt.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:E?"visible":"hidden",userSelect:"none"},children:[K(et,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll"},onMouseDown:Tt,onTouchStart:Lt,children:[d(Mo,{sx:{transform:"rotate(90deg)"}})," ",d(Gt,{onClick:()=>P(!1),children:d(bn,{})})]}),d("iframe",{src:`https://h68.deepijatel.in/ConVoxCCS/iframe?agent_id=${e.agentId}&process_id=${(fo=e.process)==null?void 0:fo.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay"})]})}),d(Zt,{anchorEl:k,open:!!k,onClose:Ut,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:K(et,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[d(On,{size:"small",value:Y,placeholder:"Enter Mobile No.",onChange:a=>{X(a.target.value)}}),d(Gt,{color:"info",onClick:()=>{Wo(Y)},children:d(wn,{color:"success"})})]})}),K(Zt,{anchorEl:v,open:!!v,onClose:Bt,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:[d(Ho,{onClick:()=>Q("Lunch"),children:"- Lunch"}),d(Ho,{onClick:()=>Q("Tea"),children:"- Tea"})]}),d(Zt,{anchorEl:C,open:!!C,onClose:Pt,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:[d(Vt,{icon:d(Tn,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),d(Vt,{icon:d(Rn,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),d(Vt,{icon:d(Nn,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!O&&d(Ao,{open:O,setOpen:o}),!!g&&d(No,{open:g,setOpen:f}),!!p&&d(Po,{open:p,setOpen:x,onSubmitDisposition:Go}),!!D&&d(Uo,{open:D,setOpen:H})]})}var te=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 C=Math.min(1e3*Math.pow(2,u-1),1e4);await new Promise(h=>setTimeout(h,C))}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((C,h)=>{m[h]=C.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(C=>console.warn("Failed to track form submission:",C))}),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(C=>console.warn("Failed to track field change:",C))},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)}},ee=new te;typeof window!="undefined"&&(window.EventTracker=ee);import{useCallback as zn}from"react";var Wn=(r={})=>{let{onSuccess:t,onError:n,onComplete:i}=r,c=at(),[e,u]=$({onSuccess:C=>{t==null||t(C),i==null||i(),S.clearStorageAndReset(),localStorage.clear()},onError:C=>{n==null||n(C),i==null||i()}});return{logout:zn(()=>{let C={action:"LOGOUTUSER",userId:c.agentId||""};e(w.LOGOUT,C)},[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}){S.initialize(r,n),ee.init({apiKey:r,tenantId:t,agentId:n,baseUrl:R})}export{Hn as CallControlPanel,Va as initSDK,qn as useLogout};
|
|
1
|
+
var Ko=Object.defineProperty,jo=Object.defineProperties;var Yo=Object.getOwnPropertyDescriptors;var To=Object.getOwnPropertySymbols;var Xo=Object.prototype.hasOwnProperty,Jo=Object.prototype.propertyIsEnumerable;var jt=(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)&&jt(r,n,t[n]);if(To)for(var n of To(t))Jo.call(t,n)&&jt(r,n,t[n]);return r},M=(r,t)=>jo(r,Yo(t));var W=(r,t,n)=>jt(r,typeof t!="symbol"?t+"":t,n);import{ArrowDropDown as vn,CallEnd as Cn,Close as bn,DragIndicator as Mo,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 Vt,Fade as Bo,IconButton as Gt,Menu as Zt,MenuItem as Ho,Paper as $o,TextField as On,Tooltip as nt,Typography as zo,useTheme as Un}from"@mui/material";import{useCallback as Mn,useEffect as Kt,useRef as Bn,useState as G}from"react";var Yt=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||[]}},S=new Yt;import{useCallback as $t,useRef as Xt,useState as Lo}from"react";function Jt(r,t){let[n,i]=Lo(r),[c,e]=Lo(!1),u=Xt(),m=Xt({x:0,y:0}),C=Xt({x:0,y:0}),h=$t(b=>{let k=u.current;if(!k)return;let U=k.getBoundingClientRect(),O=window.innerWidth,o=window.innerHeight,g={x:Math.max(0,Math.min(b.x,O-U.width)),y:Math.max(0,Math.min(b.y,o-U.height))};i(g),t==null||t(g)},[t]),E=$t((b,k)=>{e(!0),m.current={x:b,y:k},C.current=n;let U=(f,p)=>{let x=f-m.current.x,T=p-m.current.y;h({x:C.current.x+x,y:C.current.y+T})},O=f=>{f.preventDefault(),U(f.clientX,f.clientY)},o=f=>{f.preventDefault();let p=f.touches[0];p&&U(p.clientX,p.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=$t(b=>{b.preventDefault(),E(b.clientX,b.clientY)},[E]),v=$t(b=>{b.preventDefault();let k=b.touches[0];k&&E(k.clientX,k.clientY)},[E]);return{position:n,isDragging:c,dragRef:u,handleMouseDown:P,handleTouchStart:v}}import{useState as Qo,useEffect as Vo}from"react";function at(){let[r,t]=Qo(S.getState());return Vo(()=>S.subscribe(()=>{t(S.getState())}),[]),r}var R="http://192.168.101.177:8095",Zo="ws://192.168.101.177: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-break?provider=convox`,CLICK_TO_CALL:`${R}${N.v1}/cti/click-to-call?provider=convox`,HOLD_CALL:`${R}${N.v1}/cti/hold-call?provider=convox`,MUTE_CALL:`${R}${N.v1}/cti/mute-call?provider=convox`,UNMUTE_CALL:`${R}${N.v1}/cti/unmute-call?provider=convox`,END_CALL:`${R}${N.v1}/cti/end-call?provider=convox`,LOGOUT:`${R}${N.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${R}${N.v1}/cti/conference-call?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${R}${N.v1}/cti/conference-call/hold-unhold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${R}${N.v1}/cti/conference-call/mute-unmute?provider=convox`,CONFERENCE_CALL_END:`${R}${N.v1}/cti/conference-call/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${R}${N.v1}/cti/conference-call/hangup-all-call?provider=convox`,TRANSFER_CALL:`${R}${N.v1}/cti/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/trasnfer-to-details?provider=convox`},Do={WS:`${Zo}${N.v1}/cti/ws`};import{useCallback as sn,useReducer as rn}from"react";import tn from"axios";var en="12345",Qt=tn.create({baseURL:R,headers:{"Content-Type":"application/json",Authorization:en},timeout:1e4});Qt.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))));Qt.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 j=Qt;import{Alert as on,Snackbar as nn}from"@mui/material";import{useState as an}from"react";import{jsx as Io}from"react/jsx-runtime";function ft(){let[r,t]=an(!1),n=(c,e)=>{e!=="clickaway"&&t(!1)};return{showToast:(c,e)=>(t(!0),Io(nn,{anchorOrigin:{vertical:"top",horizontal:"right"},open:r,onClose:n,children:Io(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}=ft(),[c,e]=rn(cn,ln);return[sn((m,C,h={})=>{e({type:"isLoading",payload:!0}),j.post(m,C,h).then(E=>{e({type:"isSuccess",payload:E.data}),t==null||t(E.data,C)}).catch(E=>{var v,b,k,U,O,o,g,f,p,x,T,L;let P={status:(b=(v=E.response)==null?void 0:v.status)!=null?b:500,message:((U=(k=E.response)==null?void 0:k.data)==null?void 0:U.detail)||((o=(O=E.response)==null?void 0:O.data)==null?void 0:o.message)||E.message||"An unknown error occurred",data:(f=(g=E.response)==null?void 0:g.data)!=null?f:null,statusText:(x=(p=E.response)==null?void 0:p.statusText)!=null?x:"",code:(T=E==null?void 0:E.code)!=null?T:"",name:(L=E==null?void 0:E.name)!=null?L:""};i(P.message,"error"),e({type:"isError",payload:P}),n==null||n(P,C)}).finally(()=>{e({type:"isLoading",payload:!1})})},[t,n,i]),c]};import{Call as Wt,CallEnd as Ro,CallSplit as un,Close as Ft,Mic as gn,MicOff as fn,Pause as mn,PhoneDisabled as xn,PlayArrow as hn,SupportAgent as qt}from"@mui/icons-material";import{Box as _,Button as z,Dialog as xt,IconButton as tt,Paper as ht,TextField as rt,Typography as B,Autocomplete as wo,Grid as it,Tooltip as mt,useTheme as yn}from"@mui/material";import{useEffect as _o,useState as ko}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}`}}}},zt=dn;import{Fragment as lt,jsx as s,jsxs as I}from"react/jsx-runtime";function Ao({open:r,setOpen:t}){var U,O;let n=at(),{disabled:i,enabled:c,outlined:e}=zt(),u=yn(),m=()=>{t(!1)},C=(o,g)=>{S.setConferenceLine(l(l({},o),g))},h=(o,g)=>{var x,T,L,D;let f=l(l({},o),g),p={action:"EXTERNAL_CONFERENCE",operation:`CALL${f.line}`,line_used:String(f.line),thirdparty_no:f.phone,userid:(T=(x=n.callData)==null?void 0:x.agent_id)!=null?T:"",process:(D=(L=n.callData)==null?void 0:L.process_name)!=null?D:""};j.post(w.CONFERENCE_CALL,p).then(()=>{S.setConferenceLine(l(l({},o),g))})},E=(o,g)=>{var x,T,L,D;let f=l(l({},o),g),p={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(f.line),thirdparty_no:f.phone,userid:(T=(x=n.callData)==null?void 0:x.agent_id)!=null?T:"",process:(D=(L=n.callData)==null?void 0:L.process_name)!=null?D:""};j.post(w.CONFERENCE_CALL,p).then(()=>{S.setConferenceLine(l(l({},o),g))})},P=(o,g,f)=>{var T,L,D,H;let p=l(l({},o),g),x={action:"EXTERNAL_CONFERENCE",operation:f,hold_channel_no:f==="HOLDUSER"?`hold${p.line}`:`unhold${p.line}`,userid:(L=(T=n.callData)==null?void 0:T.agent_id)!=null?L:"",process:(H=(D=n.callData)==null?void 0:D.process_name)!=null?H:""};j.post(w.CONFERENCE_CALL_HOLD_OR_UN_HOLD,x).then(()=>{S.setConferenceLine(l(l({},o),g))})},v=(o,g,f)=>{var T,L,D,H;let p=l(l({},o),g),x={action:"EXTERNAL_CONFERENCE",operation:f,channel_no:f==="MUTEUSER"?`mute${p.line}`:`play${p.line}`,userid:(L=(T=n.callData)==null?void 0:T.agent_id)!=null?L:"",thirdparty_no:p.phone,process:(H=(D=n.callData)==null?void 0:D.process_name)!=null?H:""};j.post(w.CONFERENCE_CALL_MUTE_OT_UN_MUTE,x).then(()=>{S.setConferenceLine(l(l({},o),g))})},b=(o,g)=>{var x,T,L,D;let f=l(l({},o),g),p={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(f.line-1),user_type:`THIRDPARTY${f.line-1}`,thirdparty_no:f.phone,userid:(T=(x=n.callData)==null?void 0:x.agent_id)!=null?T:"",process:(D=(L=n.callData)==null?void 0:L.process_name)!=null?D:""};j.post(w.CONFERENCE_CALL_END,p).then(()=>{S.setConferenceLine(l(l({},o),g))})},k=()=>{var g,f,p,x;let o={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(f=(g=n.callData)==null?void 0:g.agent_id)!=null?f:"",process:(x=(p=n.callData)==null?void 0:p.process_name)!=null?x:""};j.post(w.CONFERENCE_CALL_END_ALL,o).then(()=>{S.resetConferenceLines(),m()})};return _o(()=>{var g,f,p,x;let o={line:1,status:(f=(g=n.callData)==null?void 0:g.status)!=null?f:"",type:"internal",phone:(x=(p=n.callData)==null?void 0:p.phone_number)!=null?x:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};S.setConferenceLine(o)},[]),s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:I(ht,{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(Ft,{})})]}),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,p;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:(p=o==null?void 0:o.status)!=null?p:""}),s(z,{sx:{textTransform:"capitalize"},size:"small",children:s(B,{variant:"body2",children:(o==null?void 0:o.line)===1?"Internal":"External"})}),s(rt,{size:"small",placeholder:"Phone Number",value:(o==null?void 0:o.phone)||"",disabled:(o==null?void 0:o.line)===1,onChange:x=>{C(o,{phone:x.target.value})}}),s(mt,{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(Wt,{sx:{color:o!=null&&o.isCallStart?"default":"#fff"}})})}),s(mt,{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:()=>{E(o,{isMergeCall:!0,status:"ONCALL"})},disabled:!(o!=null&&o.isCallStart),children:s(un,{})})}),s(mt,{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(mt,{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?v(o,{isMute:!1},"PLAYUSER"):v(o,{isMute:!0},"MUTEUSER")},disabled:!(o!=null&&o.isCallStart),children:o.isMute?s(fn,{}):s(gn,{})})}),s(mt,{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:()=>{b(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:s(Ro,{})}):s(z,{variant:o!=null&&o.isCallStart?"contained":"outlined",sx:M(l({},i),{visibility:"hidden",minWidth:"60px !important"}),onClick:()=>{b(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:s(B,{children:s(Ro,{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 No({open:r,setOpen:t}){var v,b,k,U,O,o,g,f;let[n]=$({onSuccess:p=>{console.log("res",p),t(!1)},onError:p=>{console.log("error",p)}}),i=at(),[c,e]=ko("process"),[u,{data:m}]=$(),[C,{data:h}]=$(),E=()=>{t(!1)},P=(p,x)=>{var T,L,D,H,Y,X,J,ct,pt,yt,vt,Ct,bt,dt,St,Et,Tt,Lt,Dt,st,It,Rt,wt,_t,kt,At,Nt,Pt,Ot,Ut,Mt,Bt,Ht;if(console.log(p,"data34"),x==="PROCESS"){let Q={mobile_number:(L=(T=i.callData)==null?void 0:T.phone_number)!=null?L:"",userid:(H=(D=i.callData)==null?void 0:D.agent_id)!=null?H:"",type:"PROCESS",transfer_to:(Y=p==null?void 0:p.process_name)!=null?Y:"",callreferenceid:(J=(X=i.callData)==null?void 0:X.convox_id)!=null?J:"",processid:String((pt=(ct=i.callData)==null?void 0:ct.process_id)!=null?pt:""),process_name:(vt=(yt=i.callData)==null?void 0:yt.process_name)!=null?vt:""};n(w.TRANSFER_CALL,Q)}else if(x==="QUEUE"){let Q={mobile_number:(bt=(Ct=i.callData)==null?void 0:Ct.phone_number)!=null?bt:"",userid:(St=(dt=i.callData)==null?void 0:dt.agent_id)!=null?St:"",type:"QUEUE",transfer_to:(Et=p==null?void 0:p.queue_name)!=null?Et:"",callreferenceid:(Lt=(Tt=i.callData)==null?void 0:Tt.convox_id)!=null?Lt:"",processid:String((st=(Dt=i.callData)==null?void 0:Dt.process_id)!=null?st:""),process_name:(Rt=(It=i.callData)==null?void 0:It.process_name)!=null?Rt:""};n(w.TRANSFER_CALL,Q)}else if(x==="AGENT"){let Q={mobile_number:(_t=(wt=i.callData)==null?void 0:wt.phone_number)!=null?_t:"",userid:(At=(kt=i.callData)==null?void 0:kt.agent_id)!=null?At:"",type:"AGENT",transfer_to:(Nt=p==null?void 0:p.user_id)!=null?Nt:"",callreferenceid:(Ot=(Pt=i.callData)==null?void 0:Pt.convox_id)!=null?Ot:"",processid:String((Mt=(Ut=i.callData)==null?void 0:Ut.process_id)!=null?Mt:""),process_name:(Ht=(Bt=i.callData)==null?void 0:Bt.process_name)!=null?Ht:""};n(w.TRANSFER_CALL,Q)}};return _o(()=>{u(w.AGENTS_LIST,{status:"IDLE",active:!0}),C(w.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:I(ht,{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:E,children:s(Ft,{})})]}),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:((b=(v=h==null?void 0:h.data)==null?void 0:v.process)==null?void 0:b.length)>0?(U=(k=h==null?void 0:h.data)==null?void 0:k.process)==null?void 0:U.map((p,x)=>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(qt,{sx:{marginRight:"4px"}}),p.process_name]}),s(tt,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{P(p,"PROCESS")},children:s(Wt,{})})]},x)):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((p,x)=>{var T,L,D,H,Y,X;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(qt,{sx:{marginRight:"4px"}}),p.queue_name,(D=(L=(T=h==null?void 0:h.data)==null?void 0:T.process)==null?void 0:L.find(J=>J.process_id===p.process_id))!=null&&D.process_name?s(B,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((X=(Y=(H=h==null?void 0:h.data)==null?void 0:H.process)==null?void 0:Y.find(J=>J.process_id===p.process_id))==null?void 0:X.process_name)+")"}):""]}),s(tt,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{P(p,"QUEUE")},children:s(Wt,{})})]},x)}):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:(m==null?void 0:m.length)>0?m.map((p,x)=>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(qt,{sx:{marginRight:"4px"}}),p.name]}),s(tt,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{P(p,"AGENT")},children:s(Wt,{})})]},x)):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 Po({open:r,setOpen:t,onSubmitDisposition:n}){var E,P;let[i,c]=ko({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=(v,b)=>{c(k=>M(l({},k),{[v]:b}))},C=()=>{c({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},h=()=>{C(),t(!1)};return s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:I(ht,{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(it,{container:!0,spacing:2,children:[s(it,{size:6,children:s(wo,{value:i.disposition,options:e,getOptionLabel:v=>v.label,onChange:(v,b)=>m("disposition",b),size:"small",renderInput:v=>s(rt,M(l({},v),{label:"Disposition",fullWidth:!0}))})}),s(it,{size:6,children:s(wo,{options:u,getOptionLabel:v=>v.label,value:i.followUp,onChange:(v,b)=>m("followUp",b),size:"small",renderInput:v=>s(rt,M(l({},v),{label:"Follow Up",fullWidth:!0}))})}),((P=(E=i==null?void 0:i.followUp)==null?void 0:E.label)==null?void 0:P.toLowerCase())==="yes"&&I(lt,{children:[s(it,{size:6,children:s(rt,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:i.callbackDate,onChange:v=>m("callbackDate",v.target.value),fullWidth:!0})}),s(it,{size:6,children:s(rt,{size:"small",label:"Hours (0-23)",type:"text",inputProps:{min:0,max:23},value:i.callbackHrs,onChange:v=>m("callbackHrs",v.target.value),fullWidth:!0})}),s(it,{size:6,children:s(rt,{size:"small",label:"Minutes (0-59)",type:"text",inputProps:{min:0,max:59},value:i.callbackMins,onChange:v=>m("callbackMins",v.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 Oo({open:r,setOpen:t,processList:n=[],handleSelectedProcessor:i}){return s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:I(ht,{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(Ft,{})})]}),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(qt,{sx:{marginRight:"4px"}}),e.process_name]})},u)):null})]})})})}function Uo({open:r,setOpen:t}){return s(lt,{children:s(xt,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:I(ht,{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(Ft,{})})]}),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 d,jsxs as K}from"react/jsx-runtime";function Hn({onDataChange:r}){var oe,ne,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;let t=Un(),{disabled:n,enabled:i,outlined:c}=zt(),e=at(),{showToast:u}=ft(),m=Bn(null),[C,h]=G(null),[E,P]=G(!0),[v,b]=G(null),[k,U]=G(null),[O,o]=G(!1),[g,f]=G(!1),[p,x]=G(!1),[T,L]=G(!1),[D,H]=G(!1),[Y,X]=G(""),[J,ct]=G(0),{position:pt,isDragging:yt,dragRef:vt,handleMouseDown:Ct,handleTouchStart:bt}=Jt(e.controlPanelPosition,a=>S.setControlPanelPosition(a)),{position:dt,isDragging:St,dragRef:Et,handleMouseDown:Tt,handleTouchStart:Lt}=Jt(e.iframePosition,a=>S.setIframePosition(a)),[Dt,{data:st}]=$({onSuccess:a=>{var y;console.log("res",a),a&&a.processes&&((y=a==null?void 0:a.processes)==null?void 0:y.length)>1?L(!0):(S.setProcess(a==null?void 0:a.processes[0]),L(!1))},onError:()=>{L(!1)}}),[It]=$(),[Rt]=$({onSuccess:()=>{S.setHolding(!e.isHolding)},onError:a=>{console.log("error",a)}}),[wt]=$({onSuccess:()=>{S.setMuted(!e.isMuted)},onError:a=>{console.log("error",a)}}),[_t]=$(),[kt]=$(),[At]=$(),Nt=Mn(a=>{let y=Math.floor(a/60),A=a%60;return`${y.toString().padStart(2,"0")}:${A.toString().padStart(2,"0")}`},[]),Pt=()=>{h(null)},Ot=a=>{P(!0),U(a.currentTarget),S.setStatus("dial")},Ut=()=>{e.status!=="on call"&&S.setStatus("idle"),U(null)},Mt=a=>{b(a.currentTarget)},Bt=()=>{b(null)},Ht=()=>{let a={action:"READYAGENT",userId:e.agentId};_t(w.READY_AGENT,a)},Q=a=>{b(null);let y={action:"AGENTBREAK",break_type:a,userId:e.agentId};kt(w.UPDATE_AGENT_BREAK,y)},Wo=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};It(w.CLICK_TO_CALL,y)}},qo=()=>{let a={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};Rt(w.HOLD_CALL,a)},Fo=()=>{let a={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};wt(w.MUTE_CALL,a)},Go=a=>{var A,q,F,V,Z,ut,gt,mo,xo,ho,yo,vo,Co,bo,So,Eo;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:(gt=(ut=e.callData)==null?void 0:ut.convox_id)!=null?gt:"",mobile_number:(xo=(mo=e.callData)==null?void 0:mo.phone_number)!=null?xo:"",disposition:(yo=(ho=a==null?void 0:a.disposition)==null?void 0:ho.value)!=null?yo:"",set_followUp:(Co=(vo=a==null?void 0:a.followUp)==null?void 0:vo.value)!=null?Co:"",callback_date:(bo=a==null?void 0:a.callbackDate)!=null?bo:"",callback_hrs:(So=a==null?void 0:a.callbackHrs)!=null?So:"",callback_mins:(Eo=a==null?void 0:a.callbackMins)!=null?Eo:"",endcall_type:"CLOSE"};X(""),At(w.END_CALL,y),S.endCall(),x(!1)};return Kt(()=>{let a;return e.callData.status&&e.callData.status==="ONCALL"?a=setInterval(()=>{let y=Math.floor((Date.now()-e.callStartTime)/1e3);ct(y)},1e3):ct(0),()=>{a&&clearInterval(a)}},[e.callData.status]),Kt(()=>{r&&r(e.callData)},[e.callData,r]),Kt(()=>{e.agentId?Dt(w.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}):console.log("No agentId available, skipping API call")},[e.agentId]),Kt(()=>(e.agentId&&(m.current=new WebSocket(`${Do.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),S.updateCallData(y),y.status==="ONCALL"&&S.startCall(),y.status==="WRAPUP"&&S.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?d(et,{children:!!T&&d(Oo,{processList:st==null?void 0:st.processes,open:T,setOpen:L,handleSelectedProcessor:a=>{S.setProcess(a)}})}):K($n,{children:[d(Bo,{in:!0,timeout:300,children:d($o,{ref:vt,elevation:yt?4:1,sx:{position:"fixed",left:pt.x,top:pt.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:K(et,{sx:{display:"flex",alignItems:"center"},children:[K(et,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[K(Gt,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:Ct,onTouchStart:bt,children:[d(Mo,{})," "]}),d(et,{sx:{marginRight:"10px"},children:d(nt,{title:"Dial",children:d(Gt,{size:"small",onClick:a=>{var y,A,q,F,V,Z,ut,gt;((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"&&((gt=(ut=e.callData)==null?void 0:ut.status)==null?void 0:gt.toUpperCase())!=="WRAPUP"&&Ot(a)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:d(Pn,{sx:{color:((ne=(oe=e.callData)==null?void 0:oe.status)==null?void 0:ne.toUpperCase())==="ONCALL"||((se=(ae=e.callData)==null?void 0:ae.status)==null?void 0:se.toUpperCase())==="BREAK"||((re=(ie=e.callData)==null?void 0:ie.status)==null?void 0:re.toUpperCase())==="RINGING"||((ce=(le=e.callData)==null?void 0:le.status)==null?void 0:ce.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),d(zo,{sx:{color:"success.main",width:"40px",marginRight:"10px"},children:Nt(J)}),d(zo,{variant:"body2",sx:{fontWeight:"bold"},children:(ue=(de=(pe=e.callData)==null?void 0:pe.status)==null?void 0:de.toUpperCase())!=null?ue:"N/A"}),K(ot,{size:"small",variant:"text",onClick:Mt,disabled:!!e.callStartTime,children:[d(vn,{})," "]})]}),K(et,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[d(nt,{title:"Agent Ready",children:d(ot,{variant:((fe=(ge=e.callData)==null?void 0:ge.status)==null?void 0:fe.toUpperCase())==="BREAK"||((xe=(me=e.callData)==null?void 0:me.status)==null?void 0:xe.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(),Ht())},classes:{root:((ye=(he=e.callData)==null?void 0:he.status)==null?void 0:ye.toUpperCase())==="BREAK"||((Ce=(ve=e.callData)==null?void 0:ve.status)==null?void 0:Ce.toUpperCase())==="MISSED"?"outlined":"enabled"},sx:l({},((Se=(be=e.callData)==null?void 0:be.status)==null?void 0:Se.toUpperCase())==="BREAK"||((Te=(Ee=e.callData)==null?void 0:Ee.status)==null?void 0:Te.toUpperCase())==="MISSED"?c:i),children:d(kn,{})})}),d(nt,{title:e.isHolding?"Resume":"Hold",children:d(ot,{variant:e.isHolding&&((De=(Le=e.callData)==null?void 0:Le.status)==null?void 0:De.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),qo()},sx:e.isHolding&&((Re=(Ie=e.callData)==null?void 0:Ie.status)==null?void 0:Re.toUpperCase())==="ONCALL"?l({},i):((_e=(we=e.callData)==null?void 0:we.status)==null?void 0:_e.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:((Ae=(ke=e.callData)==null?void 0:ke.status)==null?void 0:Ae.toUpperCase())!=="ONCALL"&&!e.isHolding,children:e.isHolding?d(_n,{}):d(In,{})})}),d(nt,{title:e.isMuted?"Unmute":"Mute",children:d(ot,{variant:e.isMuted&&((Pe=(Ne=e.callData)==null?void 0:Ne.status)==null?void 0:Pe.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:a=>{a.stopPropagation(),Fo()},sx:e.isMuted&&((Ue=(Oe=e.callData)==null?void 0:Oe.status)==null?void 0:Ue.toUpperCase())==="ONCALL"?l({},i):((Be=(Me=e.callData)==null?void 0:Me.status)==null?void 0:Be.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:(($e=(He=e.callData)==null?void 0:He.status)==null?void 0:$e.toUpperCase())!=="ONCALL"&&!e.isMuted,children:e.isMuted?d(Dn,{}):d(Ln,{})})}),d(nt,{title:"Transfer Call",children:d(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):((We=(ze=e.callData)==null?void 0:ze.status)==null?void 0:We.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:((Fe=(qe=e.callData)==null?void 0:qe.status)==null?void 0:Fe.toUpperCase())!=="ONCALL",children:d(An,{})})}),d(nt,{title:"Conference Call",children:d(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):((Ke=(Ge=e.callData)==null?void 0:Ge.status)==null?void 0:Ke.toUpperCase())==="ONCALL"?l({},c):l({},n),disabled:((Ye=(je=e.callData)==null?void 0:je.status)==null?void 0:Ye.toUpperCase())!=="ONCALL",children:d(Sn,{})})}),d(nt,{title:"Call History",children:d(ot,{variant:D?"contained":"outlined",onClick:a=>{a.stopPropagation(),H(!0)},sx:D?l({},i):l({},c),children:d(En,{})})}),d(nt,{title:"End Call",children:d(ot,{variant:((Je=(Xe=e.callData)==null?void 0:Xe.status)==null?void 0:Je.toUpperCase())==="ONCALL"||((Ve=(Qe=e.callData)==null?void 0:Qe.status)==null?void 0:Ve.toUpperCase())==="RINGING"||((to=(Ze=e.callData)==null?void 0:Ze.status)==null?void 0:to.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(),x(!0))},sx:((oo=(eo=e.callData)==null?void 0:eo.status)==null?void 0:oo.toUpperCase())==="ONCALL"||((ao=(no=e.callData)==null?void 0:no.status)==null?void 0:ao.toUpperCase())==="RINGING"||((io=(so=e.callData)==null?void 0:so.status)==null?void 0:io.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:((lo=(ro=e.callData)==null?void 0:ro.status)==null?void 0:lo.toUpperCase())!=="ONCALL"&&((po=(co=e.callData)==null?void 0:co.status)==null?void 0:po.toUpperCase())!=="RINGING"&&((go=(uo=e.callData)==null?void 0:uo.status)==null?void 0:go.toUpperCase())!=="WRAPUP",children:d(Cn,{})})})]})]})})}),d(Bo,{in:!0,timeout:300,children:K($o,{ref:Et,elevation:St?4:1,sx:{position:"fixed",left:dt.x,top:dt.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:E?"visible":"hidden",userSelect:"none"},children:[K(et,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll"},onMouseDown:Tt,onTouchStart:Lt,children:[d(Mo,{sx:{transform:"rotate(90deg)"}})," ",d(Gt,{onClick:()=>P(!1),children:d(bn,{})})]}),d("iframe",{src:`https://h68.deepijatel.in/ConVoxCCS/iframe?agent_id=${e.agentId}&process_id=${(fo=e.process)==null?void 0:fo.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay"})]})}),d(Zt,{anchorEl:k,open:!!k,onClose:Ut,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:K(et,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[d(On,{size:"small",value:Y,placeholder:"Enter Mobile No.",onChange:a=>{X(a.target.value)}}),d(Gt,{color:"info",onClick:()=>{Wo(Y)},children:d(wn,{color:"success"})})]})}),K(Zt,{anchorEl:v,open:!!v,onClose:Bt,onClick:a=>a.stopPropagation(),sx:{zIndex:99999},children:[d(Ho,{onClick:()=>Q("Lunch"),children:"- Lunch"}),d(Ho,{onClick:()=>Q("Tea"),children:"- Tea"})]}),d(Zt,{anchorEl:C,open:!!C,onClose:Pt,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:[d(Vt,{icon:d(Tn,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),d(Vt,{icon:d(Rn,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),d(Vt,{icon:d(Nn,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!O&&d(Ao,{open:O,setOpen:o}),!!g&&d(No,{open:g,setOpen:f}),!!p&&d(Po,{open:p,setOpen:x,onSubmitDisposition:Go}),!!D&&d(Uo,{open:D,setOpen:H})]})}var te=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 C=Math.min(1e3*Math.pow(2,u-1),1e4);await new Promise(h=>setTimeout(h,C))}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((C,h)=>{m[h]=C.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(C=>console.warn("Failed to track form submission:",C))}),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(C=>console.warn("Failed to track field change:",C))},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)}},ee=new te;typeof window!="undefined"&&(window.EventTracker=ee);import{useCallback as zn}from"react";var Wn=(r={})=>{let{onSuccess:t,onError:n,onComplete:i}=r,c=at(),[e,u]=$({onSuccess:C=>{t==null||t(C),i==null||i(),S.clearStorageAndReset(),localStorage.clear()},onError:C=>{n==null||n(C),i==null||i()}});return{logout:zn(()=>{let C={action:"LOGOUTUSER",userId:c.agentId||""};e(w.LOGOUT,C)},[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}){S.initialize(r,n),ee.init({apiKey:r,tenantId:t,agentId:n,baseUrl:R})}export{Hn as CallControlPanel,Va as initSDK,qn as useLogout};
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|