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/README.md
CHANGED
|
@@ -69,6 +69,22 @@ function App() {
|
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
```
|
|
72
|
+
### 3. Use the useLogout function
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
import React from 'react';
|
|
76
|
+
import { useLogout } from 'call-control-sdk';
|
|
77
|
+
|
|
78
|
+
function App() {
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<div>
|
|
82
|
+
<button onClick={useLogout}>Logout</button>
|
|
83
|
+
</div>
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
- `useLogout` is used to logout the agent.
|
|
72
88
|
|
|
73
89
|
## API Reference
|
|
74
90
|
|
|
@@ -80,10 +96,10 @@ Initializes the SDK with an API key, tenantId, agentId, baseUrl. Must be called
|
|
|
80
96
|
- `apiKey` (string): Your API key for SDK authentication
|
|
81
97
|
- `tenantId` (string): Your Tenant Id key for Events authentication
|
|
82
98
|
- `agentId` (string): Agent Id for access call controls
|
|
83
|
-
- `baseUrl` (string): Base URL for save events info
|
|
84
99
|
|
|
85
100
|
**Throws:** Error if API key is missing or invalid
|
|
86
101
|
|
|
102
|
+
|
|
87
103
|
### `CallControlPanel`
|
|
88
104
|
|
|
89
105
|
The main draggable control panel component.
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var _o=Object.create;var lt=Object.defineProperty,ko=Object.defineProperties,Ao=Object.getOwnPropertyDescriptor,No=Object.getOwnPropertyDescriptors,Po=Object.getOwnPropertyNames,po=Object.getOwnPropertySymbols,Oo=Object.getPrototypeOf,uo=Object.prototype.hasOwnProperty,Uo=Object.prototype.propertyIsEnumerable;var Ut=(r,t,n)=>t in r?lt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n,d=(r,t)=>{for(var n in t||(t={}))uo.call(t,n)&&Ut(r,n,t[n]);if(po)for(var n of po(t))Uo.call(t,n)&&Ut(r,n,t[n]);return r},$=(r,t)=>ko(r,No(t));var Mo=(r,t)=>{for(var n in t)lt(r,n,{get:t[n],enumerable:!0})},go=(r,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of Po(t))!uo.call(r,p)&&p!==n&<(r,p,{get:()=>t[p],enumerable:!(l=Ao(t,p))||l.enumerable});return r};var Bo=(r,t,n)=>(n=r!=null?_o(Oo(r)):{},go(t||!r||!r.__esModule?lt(n,"default",{value:r,enumerable:!0}):n,r)),Ho=r=>go(lt({},"__esModule",{value:!0}),r);var q=(r,t,n)=>Ut(r,typeof t!="symbol"?t+"":t,n);var jo={};Mo(jo,{CallControlPanel:()=>Eo,initSDK:()=>Ko,useLogout:()=>Lo});module.exports=Ho(jo);var v=require("@mui/icons-material"),g=require("@mui/material"),P=require("react");var Mt=class{constructor(){q(this,"state");q(this,"listeners",[]);q(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=$(d({},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 d({},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=d(d({},this.state.callData),t),this.saveToStorage(),this.notifyListeners()}setConferenceLine(t){var l;(!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=(l=this.state.conferenceLine)==null?void 0:l.map(p=>p.line===t.line?t:p);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||[]}},L=new Mt;var F=require("react");function Bt(r,t){let[n,l]=(0,F.useState)(r),[p,e]=(0,F.useState)(!1),f=(0,F.useRef)(),h=(0,F.useRef)({x:0,y:0}),E=(0,F.useRef)({x:0,y:0}),C=(0,F.useCallback)(T=>{let N=f.current;if(!N)return;let H=N.getBoundingClientRect(),B=window.innerWidth,o=window.innerHeight,m={x:Math.max(0,Math.min(T.x,B-H.width)),y:Math.max(0,Math.min(T.y,o-H.height))};l(m),t==null||t(m)},[t]),I=(0,F.useCallback)((T,N)=>{e(!0),h.current={x:T,y:N},E.current=n;let H=(x,u)=>{let y=x-h.current.x,R=u-h.current.y;C({x:E.current.x+y,y:E.current.y+R})},B=x=>{x.preventDefault(),H(x.clientX,x.clientY)},o=x=>{x.preventDefault();let u=x.touches[0];u&&H(u.clientX,u.clientY)},m=()=>{e(!1),document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",m),document.removeEventListener("touchmove",o),document.removeEventListener("touchend",m)};document.addEventListener("mousemove",B),document.addEventListener("mouseup",m),document.addEventListener("touchmove",o,{passive:!1}),document.addEventListener("touchend",m)},[n,C]),M=(0,F.useCallback)(T=>{T.preventDefault(),I(T.clientX,T.clientY)},[I]),S=(0,F.useCallback)(T=>{T.preventDefault();let N=T.touches[0];N&&I(N.clientX,N.clientY)},[I]);return{position:n,isDragging:p,dragRef:f,handleMouseDown:M,handleTouchStart:S}}var At=require("react");function tt(){let[r,t]=(0,At.useState)(L.getState());return(0,At.useEffect)(()=>L.subscribe(()=>{t(L.getState())}),[]),r}var k="http://192.168.101.177:8095",$o="ws://192.168.101.177:8095",U={v1:"/api/v1"},A={LOGIN:`${k}${U.v1}/cti/login?provider=convox`,READY_AGENT:`${k}${U.v1}/cti/ready-agent?provider=convox`,UPDATE_AGENT_BREAK:`${k}${U.v1}/cti/update-agent-break?provider=convox`,CLICK_TO_CALL:`${k}${U.v1}/cti/click-to-call?provider=convox`,HOLD_CALL:`${k}${U.v1}/cti/hold-call?provider=convox`,MUTE_CALL:`${k}${U.v1}/cti/mute-call?provider=convox`,UNMUTE_CALL:`${k}${U.v1}/cti/unmute-call?provider=convox`,END_CALL:`${k}${U.v1}/cti/end-call?provider=convox`,LOGOUT:`${k}${U.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${k}${U.v1}/cti/conference-call?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${k}${U.v1}/cti/conference-call/hold-unhold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${k}${U.v1}/cti/conference-call/mute-unmute?provider=convox`,CONFERENCE_CALL_END:`${k}${U.v1}/cti/conference-call/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${k}${U.v1}/cti/conference-call/hangup-all-call?provider=convox`,TRANSFER_CALL:`${k}${U.v1}/cti/transfer?provider=convox`,AGENTS_LIST:`${k}${U.v1}/cti/users`,PROCESS_LIST:`${k}${U.v1}/cti/processes-list`,TRANSFER_TO_DETAILS:`${k}${U.v1}/cti/trasnfer-to-details?provider=convox`},fo={WS:`${$o}${U.v1}/cti/ws`};var Pt=require("react");var mo=Bo(require("axios"));var zo="12345",Ht=mo.default.create({baseURL:k,headers:{"Content-Type":"application/json",Authorization:zo},timeout:1e4});Ht.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))));Ht.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=Ht;var Nt=require("@mui/material"),xo=require("react"),$t=require("react/jsx-runtime");function ct(){let[r,t]=(0,xo.useState)(!1),n=(p,e)=>{e!=="clickaway"&&t(!1)};return{showToast:(p,e)=>(t(!0),(0,$t.jsx)(Nt.Snackbar,{anchorOrigin:{vertical:"top",horizontal:"right"},open:r,onClose:n,children:(0,$t.jsx)(Nt.Alert,{onClose:n,severity:e,variant:"filled",sx:{width:"100%"},children:p})}))}}var Wo={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},qo=(r,t)=>{if(t.type==="isLoading")return $(d({},r),{isLoading:t.payload});if(t.type==="isSuccess")return $(d({},r),{isSuccess:!0,data:t.payload});if(t.type==="isError")return $(d({},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 W=(r={})=>{let{onSuccess:t=null,onError:n=null}=r,{showToast:l}=ct(),[p,e]=(0,Pt.useReducer)(qo,Wo);return[(0,Pt.useCallback)((h,E,C={})=>{e({type:"isLoading",payload:!0}),j.post(h,E,C).then(I=>{e({type:"isSuccess",payload:I.data}),t==null||t(I.data,E)}).catch(I=>{var S,T,N,H,B,o,m,x,u,y,R,w;let M={status:(T=(S=I.response)==null?void 0:S.status)!=null?T:500,message:((H=(N=I.response)==null?void 0:N.data)==null?void 0:H.detail)||((o=(B=I.response)==null?void 0:B.data)==null?void 0:o.message)||I.message||"An unknown error occurred",data:(x=(m=I.response)==null?void 0:m.data)!=null?x:null,statusText:(y=(u=I.response)==null?void 0:u.statusText)!=null?y:"",code:(R=I==null?void 0:I.code)!=null?R:"",name:(w=I==null?void 0:I.name)!=null?w:""};l(M.message,"error"),e({type:"isError",payload:M}),n==null||n(M,E)}).finally(()=>{e({type:"isLoading",payload:!1})})},[t,n,l]),p]};var D=require("@mui/icons-material"),s=require("@mui/material"),ot=require("react");var ho=require("@mui/material"),Fo=()=>{let r=(0,ho.useTheme)();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}`}}}},Ot=Fo;var a=require("react/jsx-runtime");function yo({open:r,setOpen:t}){var H,B;let n=tt(),{disabled:l,enabled:p,outlined:e}=Ot(),f=(0,s.useTheme)(),h=()=>{t(!1)},E=(o,m)=>{L.setConferenceLine(d(d({},o),m))},C=(o,m)=>{var y,R,w,_;let x=d(d({},o),m),u={action:"EXTERNAL_CONFERENCE",operation:`CALL${x.line}`,line_used:String(x.line),thirdparty_no:x.phone,userid:(R=(y=n.callData)==null?void 0:y.agent_id)!=null?R:"",process:(_=(w=n.callData)==null?void 0:w.process_name)!=null?_:""};j.post(A.CONFERENCE_CALL,u).then(()=>{L.setConferenceLine(d(d({},o),m))})},I=(o,m)=>{var y,R,w,_;let x=d(d({},o),m),u={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(x.line),thirdparty_no:x.phone,userid:(R=(y=n.callData)==null?void 0:y.agent_id)!=null?R:"",process:(_=(w=n.callData)==null?void 0:w.process_name)!=null?_:""};j.post(A.CONFERENCE_CALL,u).then(()=>{L.setConferenceLine(d(d({},o),m))})},M=(o,m,x)=>{var R,w,_,z;let u=d(d({},o),m),y={action:"EXTERNAL_CONFERENCE",operation:x,hold_channel_no:x==="HOLDUSER"?`hold${u.line}`:`unhold${u.line}`,userid:(w=(R=n.callData)==null?void 0:R.agent_id)!=null?w:"",process:(z=(_=n.callData)==null?void 0:_.process_name)!=null?z:""};j.post(A.CONFERENCE_CALL_HOLD_OR_UN_HOLD,y).then(()=>{L.setConferenceLine(d(d({},o),m))})},S=(o,m,x)=>{var R,w,_,z;let u=d(d({},o),m),y={action:"EXTERNAL_CONFERENCE",operation:x,channel_no:x==="MUTEUSER"?`mute${u.line}`:`play${u.line}`,userid:(w=(R=n.callData)==null?void 0:R.agent_id)!=null?w:"",thirdparty_no:u.phone,process:(z=(_=n.callData)==null?void 0:_.process_name)!=null?z:""};j.post(A.CONFERENCE_CALL_MUTE_OT_UN_MUTE,y).then(()=>{L.setConferenceLine(d(d({},o),m))})},T=(o,m)=>{var y,R,w,_;let x=d(d({},o),m),u={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(x.line-1),user_type:`THIRDPARTY${x.line-1}`,thirdparty_no:x.phone,userid:(R=(y=n.callData)==null?void 0:y.agent_id)!=null?R:"",process:(_=(w=n.callData)==null?void 0:w.process_name)!=null?_:""};j.post(A.CONFERENCE_CALL_END,u).then(()=>{L.setConferenceLine(d(d({},o),m))})},N=()=>{var m,x,u,y;let o={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(x=(m=n.callData)==null?void 0:m.agent_id)!=null?x:"",process:(y=(u=n.callData)==null?void 0:u.process_name)!=null?y:""};j.post(A.CONFERENCE_CALL_END_ALL,o).then(()=>{L.resetConferenceLines(),h()})};return(0,ot.useEffect)(()=>{var m,x,u,y;let o={line:1,status:(x=(m=n.callData)==null?void 0:m.status)!=null?x:"",type:"internal",phone:(y=(u=n.callData)==null?void 0:u.phone_number)!=null?y:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};L.setConferenceLine(o)},[]),(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px"},children:[(0,a.jsxs)(s.Typography,{variant:"body1",children:[(H=n==null?void 0:n.agentId)!=null?H:""," conference"]}),(0,a.jsx)(s.IconButton,{onClick:h,children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsx)(s.Box,{sx:{boxShadow:"0px 1px 2px #e7e5e5ff",padding:"2px 6px",margin:"0px 10px",borderRadius:"20px"},children:(B=n==null?void 0:n.conferenceLine)==null?void 0:B.map((o,m)=>{var x,u;return(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[(0,a.jsx)(s.Box,{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:(0,a.jsx)(s.Typography,{children:(x=o==null?void 0:o.line)!=null?x:""})}),(0,a.jsx)(s.Typography,{variant:"body2",sx:{px:1,border:"2px solid gray",borderRadius:"10px",textAlign:"center",width:"80px",maxWidth:"100px"},children:(u=o==null?void 0:o.status)!=null?u:""}),(0,a.jsx)(s.Button,{sx:{textTransform:"capitalize"},size:"small",children:(0,a.jsx)(s.Typography,{variant:"body2",children:(o==null?void 0:o.line)===1?"Internal":"External"})}),(0,a.jsx)(s.TextField,{size:"small",placeholder:"Phone Number",value:(o==null?void 0:o.phone)||"",disabled:(o==null?void 0:o.line)===1,onChange:y=>{E(o,{phone:y.target.value})}}),(0,a.jsx)(s.Tooltip,{title:"Call",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isCallStart?"outlined":"contained",color:"success",sx:o!=null&&o.isCallStart?d({},l):$(d({},p),{border:`0px solid ${f.palette.success.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${f.palette.success.light}`,border:`0px solid ${f.palette.success.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${f.palette.primary.light}`}}),onClick:()=>{C(o,{isCallStart:!0,status:"ONCALL"})},disabled:o==null?void 0:o.isCallStart,children:(0,a.jsx)(D.Call,{sx:{color:o!=null&&o.isCallStart?"defalult":"#fff"}})})}),(0,a.jsx)(s.Tooltip,{title:"Merge Call",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isMergeCall?"contained":"outlined",sx:o!=null&&o.isMergeCall&&(o!=null&&o.isCallStart)?d({},l):o!=null&&o.isCallStart?d({},e):d({},l),onClick:()=>{I(o,{isMergeCall:!0,status:"ONCALL"})},disabled:!(o!=null&&o.isCallStart),children:(0,a.jsx)(D.CallSplit,{})})}),(0,a.jsx)(s.Tooltip,{title:o.isHold?"Hold":"Un Hold",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isHold?"contained":"outlined",sx:o!=null&&o.isHold&&(o!=null&&o.isCallStart)?d({},l):o!=null&&o.isCallStart?d({},e):d({},l),onClick:()=>{o.isHold?M(o,{isHold:!1},"UNHOLDUSER"):M(o,{isHold:!0},"HOLDUSER")},disabled:!(o!=null&&o.isCallStart),children:o.isHold?(0,a.jsx)(D.PlayArrow,{}):(0,a.jsx)(D.Pause,{})})}),(0,a.jsx)(s.Tooltip,{title:o.isMute?"Mute":"Un Mute",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isMute?"contained":"outlined",sx:o!=null&&o.isMute&&(o!=null&&o.isCallStart)?d({},l):o!=null&&o.isCallStart?d({},e):d({},l),onClick:()=>{o.isMute?S(o,{isMute:!1},"PLAYUSER"):S(o,{isMute:!0},"MUTEUSER")},disabled:!(o!=null&&o.isCallStart),children:o.isMute?(0,a.jsx)(D.MicOff,{}):(0,a.jsx)(D.Mic,{})})}),(0,a.jsx)(s.Tooltip,{title:"End Call",children:(o==null?void 0:o.line)!==1?(0,a.jsx)(s.Button,{variant:o!=null&&o.isCallStart?"contained":"outlined",color:"error",sx:o!=null&&o.isCallStart?$(d({},p),{minWidth:"60px !important",border:`0px solid ${f.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${f.palette.error.light}`,border:`0px solid ${f.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${f.palette.primary.light}`}}):$(d({},l),{minWidth:"60px !important"}),onClick:()=>{T(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:(0,a.jsx)(D.CallEnd,{})}):(0,a.jsx)(s.Button,{variant:o!=null&&o.isCallStart?"contained":"outlined",sx:$(d({},l),{visibility:"hidden",minWidth:"60px !important"}),onClick:()=>{T(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:(0,a.jsx)(s.Typography,{children:(0,a.jsx)(D.CallEnd,{sx:{visibility:"hidden"}})})})})]},m)})}),(0,a.jsx)(s.Box,{textAlign:"center",m:2,children:(0,a.jsxs)(s.Button,{variant:"outlined",color:"error",size:"large",onClick:N,sx:{px:2,borderRadius:"20px",textTransform:"capitalize"},children:[(0,a.jsx)(s.IconButton,{sx:{bgcolor:"error.main","&:hover":{bgcolor:"error.dark"},marginRight:"8px",width:"28px",height:"28px",fontSize:"12px",fontWeight:"600",lineHeight:"16px",letterSpacing:"0.02em",textTransform:"capitalize",color:"white",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%"},children:(0,a.jsx)(D.PhoneDisabled,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function vo({open:r,setOpen:t}){var S,T,N,H,B,o,m,x;let[n]=W({onSuccess:u=>{console.log("res",u),t(!1)},onError:u=>{console.log("error",u)}}),l=tt(),[p,e]=(0,ot.useState)("process"),[f,{data:h}]=W(),[E,{data:C}]=W(),I=()=>{t(!1)},M=(u,y)=>{var R,w,_,z,Y,X,J,nt,at,pt,dt,ut,gt,st,ft,mt,xt,ht,yt,et,vt,Ct,bt,St,Et,Tt,Lt,Dt,It,Rt,wt,_t,kt;if(console.log(u,"data34"),y==="PROCESS"){let Q={mobile_number:(w=(R=l.callData)==null?void 0:R.phone_number)!=null?w:"",userid:(z=(_=l.callData)==null?void 0:_.agent_id)!=null?z:"",type:"PROCESS",transfer_to:(Y=u==null?void 0:u.process_name)!=null?Y:"",callreferenceid:(J=(X=l.callData)==null?void 0:X.convox_id)!=null?J:"",processid:String((at=(nt=l.callData)==null?void 0:nt.process_id)!=null?at:""),process_name:(dt=(pt=l.callData)==null?void 0:pt.process_name)!=null?dt:""};n(A.TRANSFER_CALL,Q)}else if(y==="QUEUE"){let Q={mobile_number:(gt=(ut=l.callData)==null?void 0:ut.phone_number)!=null?gt:"",userid:(ft=(st=l.callData)==null?void 0:st.agent_id)!=null?ft:"",type:"QUEUE",transfer_to:(mt=u==null?void 0:u.queue_name)!=null?mt:"",callreferenceid:(ht=(xt=l.callData)==null?void 0:xt.convox_id)!=null?ht:"",processid:String((et=(yt=l.callData)==null?void 0:yt.process_id)!=null?et:""),process_name:(Ct=(vt=l.callData)==null?void 0:vt.process_name)!=null?Ct:""};n(A.TRANSFER_CALL,Q)}else if(y==="AGENT"){let Q={mobile_number:(St=(bt=l.callData)==null?void 0:bt.phone_number)!=null?St:"",userid:(Tt=(Et=l.callData)==null?void 0:Et.agent_id)!=null?Tt:"",type:"AGENT",transfer_to:(Lt=u==null?void 0:u.user_id)!=null?Lt:"",callreferenceid:(It=(Dt=l.callData)==null?void 0:Dt.convox_id)!=null?It:"",processid:String((wt=(Rt=l.callData)==null?void 0:Rt.process_id)!=null?wt:""),process_name:(kt=(_t=l.callData)==null?void 0:_t.process_name)!=null?kt:""};n(A.TRANSFER_CALL,Q)}};return(0,ot.useEffect)(()=>{f(A.AGENTS_LIST,{status:"IDLE",active:!0}),E(A.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,a.jsx)(s.Typography,{variant:"body1",children:" Call Transfer"}),(0,a.jsx)(s.IconButton,{onClick:I,children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsxs)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",gap:1},children:[(0,a.jsx)(s.Button,{variant:p==="process"?"contained":"outlined",onClick:()=>e("process"),children:"Process"}),(0,a.jsx)(s.Button,{variant:p==="queues"?"contained":"outlined",onClick:()=>e("queues"),children:"Queues"}),(0,a.jsx)(s.Button,{variant:p==="agents"?"contained":"outlined",onClick:()=>e("agents"),children:"Agents"})]}),p==="process"&&(0,a.jsx)(s.Box,{sx:{display:"flex",gap:1},children:((T=(S=C==null?void 0:C.data)==null?void 0:S.process)==null?void 0:T.length)>0?(H=(N=C==null?void 0:C.data)==null?void 0:N.process)==null?void 0:H.map((u,y)=>(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),u.process_name]}),(0,a.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{M(u,"PROCESS")},children:(0,a.jsx)(D.Call,{})})]},y)):(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",textAlign:"center",width:"100%",margin:"10px 0px",color:"gray"},children:"No Process Found"})}),p==="queues"&&(0,a.jsx)(s.Box,{sx:{display:"flex",gap:1},children:((o=(B=C==null?void 0:C.data)==null?void 0:B.queue)==null?void 0:o.length)>0?(x=(m=C==null?void 0:C.data)==null?void 0:m.queue)==null?void 0:x.map((u,y)=>{var R,w,_,z,Y,X;return(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),u.queue_name,(_=(w=(R=C==null?void 0:C.data)==null?void 0:R.process)==null?void 0:w.find(J=>J.process_id===u.process_id))!=null&&_.process_name?(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((X=(Y=(z=C==null?void 0:C.data)==null?void 0:z.process)==null?void 0:Y.find(J=>J.process_id===u.process_id))==null?void 0:X.process_name)+")"}):""]}),(0,a.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{M(u,"QUEUE")},children:(0,a.jsx)(D.Call,{})})]},y)}):(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",textAlign:"center",width:"100%",margin:"10px 0px",color:"gray"},children:"No Queues Found"})}),p==="agents"&&(0,a.jsx)(s.Box,{sx:{display:"flex",gap:1},children:(h==null?void 0:h.length)>0?h.map((u,y)=>(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),u.name]}),(0,a.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{M(u,"AGENT")},children:(0,a.jsx)(D.Call,{})})]},y)):(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",textAlign:"center",width:"100%",margin:"10px 0px",color:"gray"},children:"No Agents Found"})})]})]})})})}function Co({open:r,setOpen:t,onSubmitDisposition:n}){var I,M;let[l,p]=(0,ot.useState)({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),e=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],f=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],h=(S,T)=>{p(N=>$(d({},N),{[S]:T}))},E=()=>{p({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},C=()=>{E(),t(!1)};return(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsx)(s.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:(0,a.jsxs)(s.Typography,{variant:"body1",m:1,children:[" ","Call Disposition"]})}),(0,a.jsx)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"10px",margin:"10px",borderRadius:"10px"},children:(0,a.jsxs)(s.Grid,{container:!0,spacing:2,children:[(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.Autocomplete,{value:l.disposition,options:e,getOptionLabel:S=>S.label,onChange:(S,T)=>h("disposition",T),size:"small",renderInput:S=>(0,a.jsx)(s.TextField,$(d({},S),{label:"Disposition",fullWidth:!0}))})}),(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.Autocomplete,{options:f,getOptionLabel:S=>S.label,value:l.followUp,onChange:(S,T)=>h("followUp",T),size:"small",renderInput:S=>(0,a.jsx)(s.TextField,$(d({},S),{label:"Follow Up",fullWidth:!0}))})}),((M=(I=l==null?void 0:l.followUp)==null?void 0:I.label)==null?void 0:M.toLowerCase())==="yes"&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.TextField,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:l.callbackDate,onChange:S=>h("callbackDate",S.target.value),fullWidth:!0})}),(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.TextField,{size:"small",label:"Hours (0-23)",type:"text",inputProps:{min:0,max:23},value:l.callbackHrs,onChange:S=>h("callbackHrs",S.target.value),fullWidth:!0})}),(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.TextField,{size:"small",label:"Minutes (0-59)",type:"text",inputProps:{min:0,max:59},value:l.callbackMins,onChange:S=>h("callbackMins",S.target.value),fullWidth:!0})})]})]})}),(0,a.jsxs)(s.Box,{textAlign:"right",m:2,children:[(0,a.jsx)(s.Button,{variant:"outlined",color:"error",size:"large",onClick:C,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),(0,a.jsx)(s.Button,{variant:"contained",color:"primary",size:"large",onClick:()=>n(l),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function bo({open:r,setOpen:t,processList:n=[],handleSelectedProcessor:l}){return(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,a.jsx)(s.Typography,{variant:"body1",children:" Process List"}),(0,a.jsx)(s.IconButton,{onClick:()=>{t(!1)},children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsx)(s.Box,{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,f)=>(0,a.jsx)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px",cursor:"pointer","&:hover":{bgcolor:"action.selected"}},onClick:()=>{l(e)},children:(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),e.process_name]})},f)):null})]})})})}function So({open:r,setOpen:t}){return(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,a.jsx)(s.Typography,{variant:"body1",children:" Call History"}),(0,a.jsx)(s.IconButton,{onClick:()=>{t(!1)},children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsx)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Comming Soon..."})]})})})}var c=require("react/jsx-runtime");function Eo({onDataChange:r}){var qt,Ft,Gt,Kt,jt,Yt,Xt,Jt,Qt,Vt,Zt,te,ee,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;let t=(0,g.useTheme)(),{disabled:n,enabled:l,outlined:p}=Ot(),e=tt(),{showToast:f}=ct(),h=(0,P.useRef)(null),[E,C]=(0,P.useState)(null),[I,M]=(0,P.useState)(!0),[S,T]=(0,P.useState)(null),[N,H]=(0,P.useState)(null),[B,o]=(0,P.useState)(!1),[m,x]=(0,P.useState)(!1),[u,y]=(0,P.useState)(!1),[R,w]=(0,P.useState)(!1),[_,z]=(0,P.useState)(!1),[Y,X]=(0,P.useState)(""),[J,nt]=(0,P.useState)(0),{position:at,isDragging:pt,dragRef:dt,handleMouseDown:ut,handleTouchStart:gt}=Bt(e.controlPanelPosition,i=>L.setControlPanelPosition(i)),{position:st,isDragging:ft,dragRef:mt,handleMouseDown:xt,handleTouchStart:ht}=Bt(e.iframePosition,i=>L.setIframePosition(i)),[yt,{data:et}]=W({onSuccess:i=>{var b;console.log("res",i),i&&i.processes&&((b=i==null?void 0:i.processes)==null?void 0:b.length)>1?w(!0):(L.setProcess(i==null?void 0:i.processes[0]),w(!1))},onError:()=>{w(!1)}}),[vt]=W(),[Ct]=W({onSuccess:()=>{L.setHolding(!e.isHolding)},onError:i=>{console.log("error",i)}}),[bt]=W({onSuccess:()=>{L.setMuted(!e.isMuted)},onError:i=>{console.log("error",i)}}),[St]=W(),[Et]=W(),[Tt]=W(),Lt=(0,P.useCallback)(i=>{let b=Math.floor(i/60),O=i%60;return`${b.toString().padStart(2,"0")}:${O.toString().padStart(2,"0")}`},[]),Dt=()=>{C(null)},It=i=>{M(!0),H(i.currentTarget),L.setStatus("dial")},Rt=()=>{e.status!=="on call"&&L.setStatus("idle"),H(null)},wt=i=>{T(i.currentTarget)},_t=()=>{T(null)},kt=()=>{let i={action:"READYAGENT",userId:e.agentId};St(A.READY_AGENT,i)},Q=i=>{T(null);let b={action:"AGENTBREAK",break_type:i,userId:e.agentId};Et(A.UPDATE_AGENT_BREAK,b)},Do=i=>{if(i.length!==10)f("Invalid phone number","error"),alert("Invalid phone number");else if(!/^\d+$/.test(i))f("Invalid phone number","error");else{let b={action:"CALL",phone_number:i,userId:e.agentId};vt(A.CLICK_TO_CALL,b)}},Io=()=>{let i={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};Ct(A.HOLD_CALL,i)},Ro=()=>{let i={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};bt(A.MUTE_CALL,i)},wo=i=>{var O,G,K,V,Z,it,rt,eo,oo,no,ao,so,io,ro,lo,co;console.log("data",i);let b={action:"ENDCALL",userId:e.agentId,processid:(K=(G=(O=e.process)==null?void 0:O.process_id)==null?void 0:G.toString())!=null?K:"",process_name:(Z=(V=e.process)==null?void 0:V.process_name)!=null?Z:"",callreferenceid:(rt=(it=e.callData)==null?void 0:it.convox_id)!=null?rt:"",mobile_number:(oo=(eo=e.callData)==null?void 0:eo.phone_number)!=null?oo:"",disposition:(ao=(no=i==null?void 0:i.disposition)==null?void 0:no.value)!=null?ao:"",set_followUp:(io=(so=i==null?void 0:i.followUp)==null?void 0:so.value)!=null?io:"",callback_date:(ro=i==null?void 0:i.callbackDate)!=null?ro:"",callback_hrs:(lo=i==null?void 0:i.callbackHrs)!=null?lo:"",callback_mins:(co=i==null?void 0:i.callbackMins)!=null?co:"",endcall_type:"CLOSE"};X(""),Tt(A.END_CALL,b),L.endCall(),y(!1)};return(0,P.useEffect)(()=>{let i;return e.callData.status&&e.callData.status==="ONCALL"?i=setInterval(()=>{let b=Math.floor((Date.now()-e.callStartTime)/1e3);nt(b)},1e3):nt(0),()=>{i&&clearInterval(i)}},[e.callData.status]),(0,P.useEffect)(()=>{r&&r(e.callData)},[e.callData,r]),(0,P.useEffect)(()=>{e.agentId?yt(A.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}):console.log("No agentId available, skipping API call")},[e.agentId]),(0,P.useEffect)(()=>(e.agentId&&(h.current=new WebSocket(`${fo.WS}?agent_id=${e.agentId}`),h.current.onopen=()=>{console.log("WebSocket connection established")},h.current.onmessage=i=>{try{let b=JSON.parse(i.data);console.log("parsedJSON:",b),L.updateCallData(b),b.status==="ONCALL"&&L.startCall(),b.status==="WRAPUP"&&L.endCall()}catch(b){console.log("Raw message:",i.data)}},h.current.onclose=()=>{console.log("WebSocket connection closed")},h.current.onerror=i=>{console.error("WebSocket error:",i)}),()=>{var i;(i=h.current)==null||i.close()}),[e.agentId]),!e.isInitialized||!e.process?(0,c.jsx)(g.Box,{children:!!R&&(0,c.jsx)(bo,{processList:et==null?void 0:et.processes,open:R,setOpen:w,handleSelectedProcessor:i=>{L.setProcess(i)}})}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(g.Fade,{in:!0,timeout:300,children:(0,c.jsx)(g.Paper,{ref:dt,elevation:pt?4:1,sx:{position:"fixed",left:at.x,top:at.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:(0,c.jsxs)(g.Box,{sx:{display:"flex",alignItems:"center"},children:[(0,c.jsxs)(g.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsxs)(g.IconButton,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:ut,onTouchStart:gt,children:[(0,c.jsx)(v.DragIndicator,{})," "]}),(0,c.jsx)(g.Box,{sx:{marginRight:"10px"},children:(0,c.jsx)(g.Tooltip,{title:"Dial",children:(0,c.jsx)(g.IconButton,{size:"small",onClick:i=>{var b,O,G,K,V,Z,it,rt;((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())!=="ONCALL"&&((K=(G=e.callData)==null?void 0:G.status)==null?void 0:K.toUpperCase())!=="BREAK"&&((Z=(V=e.callData)==null?void 0:V.status)==null?void 0:Z.toUpperCase())!=="RINGING"&&((rt=(it=e.callData)==null?void 0:it.status)==null?void 0:rt.toUpperCase())!=="WRAPUP"&&It(i)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:(0,c.jsx)(v.WifiCalling3,{sx:{color:((Ft=(qt=e.callData)==null?void 0:qt.status)==null?void 0:Ft.toUpperCase())==="ONCALL"||((Kt=(Gt=e.callData)==null?void 0:Gt.status)==null?void 0:Kt.toUpperCase())==="BREAK"||((Yt=(jt=e.callData)==null?void 0:jt.status)==null?void 0:Yt.toUpperCase())==="RINGING"||((Jt=(Xt=e.callData)==null?void 0:Xt.status)==null?void 0:Jt.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),(0,c.jsx)(g.Typography,{sx:{color:"success.main",width:"40px",marginRight:"10px"},children:Lt(J)}),(0,c.jsx)(g.Typography,{variant:"body2",sx:{fontWeight:"bold"},children:(Zt=(Vt=(Qt=e.callData)==null?void 0:Qt.status)==null?void 0:Vt.toUpperCase())!=null?Zt:"N/A"}),(0,c.jsxs)(g.Button,{size:"small",variant:"text",onClick:wt,disabled:!!e.callStartTime,children:[(0,c.jsx)(v.ArrowDropDown,{})," "]})]}),(0,c.jsxs)(g.Box,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[(0,c.jsx)(g.Tooltip,{title:"Agent Ready",children:(0,c.jsx)(g.Button,{variant:((ee=(te=e.callData)==null?void 0:te.status)==null?void 0:ee.toUpperCase())==="BREAK"||((ne=(oe=e.callData)==null?void 0:oe.status)==null?void 0:ne.toUpperCase())==="MISSED"?"outlined":"contained",onClick:i=>{var b,O,G,K;(((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="BREAK"||((K=(G=e.callData)==null?void 0:G.status)==null?void 0:K.toUpperCase())==="MISSED")&&(i.stopPropagation(),kt())},classes:{root:((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())==="MISSED"?"outlined":"enabled"},sx:d({},((ce=(le=e.callData)==null?void 0:le.status)==null?void 0:ce.toUpperCase())==="BREAK"||((de=(pe=e.callData)==null?void 0:pe.status)==null?void 0:de.toUpperCase())==="MISSED"?p:l),children:(0,c.jsx)(v.SupportAgent,{})})}),(0,c.jsx)(g.Tooltip,{title:e.isHolding?"Resume":"Hold",children:(0,c.jsx)(g.Button,{variant:e.isHolding&&((ge=(ue=e.callData)==null?void 0:ue.status)==null?void 0:ge.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:i=>{i.stopPropagation(),Io()},sx:e.isHolding&&((me=(fe=e.callData)==null?void 0:fe.status)==null?void 0:me.toUpperCase())==="ONCALL"?d({},l):((he=(xe=e.callData)==null?void 0:xe.status)==null?void 0:he.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((ve=(ye=e.callData)==null?void 0:ye.status)==null?void 0:ve.toUpperCase())!=="ONCALL"&&!e.isHolding,children:e.isHolding?(0,c.jsx)(v.PlayArrow,{}):(0,c.jsx)(v.Pause,{})})}),(0,c.jsx)(g.Tooltip,{title:e.isMuted?"Unmute":"Mute",children:(0,c.jsx)(g.Button,{variant:e.isMuted&&((be=(Ce=e.callData)==null?void 0:Ce.status)==null?void 0:be.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:i=>{i.stopPropagation(),Ro()},sx:e.isMuted&&((Ee=(Se=e.callData)==null?void 0:Se.status)==null?void 0:Ee.toUpperCase())==="ONCALL"?d({},l):((Le=(Te=e.callData)==null?void 0:Te.status)==null?void 0:Le.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((Ie=(De=e.callData)==null?void 0:De.status)==null?void 0:Ie.toUpperCase())!=="ONCALL"&&!e.isMuted,children:e.isMuted?(0,c.jsx)(v.MicOff,{}):(0,c.jsx)(v.Mic,{})})}),(0,c.jsx)(g.Tooltip,{title:"Transfer Call",children:(0,c.jsx)(g.Button,{variant:m?"contained":"outlined",onClick:i=>{var b,O;((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="ONCALL"&&(i.stopPropagation(),x(!0))},sx:m?d({},l):((we=(Re=e.callData)==null?void 0:Re.status)==null?void 0:we.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((ke=(_e=e.callData)==null?void 0:_e.status)==null?void 0:ke.toUpperCase())!=="ONCALL",children:(0,c.jsx)(v.TransferWithinAStation,{})})}),(0,c.jsx)(g.Tooltip,{title:"Conference Call",children:(0,c.jsx)(g.Button,{variant:B?"contained":"outlined",onClick:i=>{var b,O;((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="ONCALL"&&(i.stopPropagation(),o(!0))},sx:B?d({},l):((Ne=(Ae=e.callData)==null?void 0:Ae.status)==null?void 0:Ne.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((Oe=(Pe=e.callData)==null?void 0:Pe.status)==null?void 0:Oe.toUpperCase())!=="ONCALL",children:(0,c.jsx)(v.Group,{})})}),(0,c.jsx)(g.Tooltip,{title:"Call History",children:(0,c.jsx)(g.Button,{variant:_?"contained":"outlined",onClick:i=>{i.stopPropagation(),z(!0)},sx:_?d({},l):d({},p),children:(0,c.jsx)(v.History,{})})}),(0,c.jsx)(g.Tooltip,{title:"End Call",children:(0,c.jsx)(g.Button,{variant:((Me=(Ue=e.callData)==null?void 0:Ue.status)==null?void 0:Me.toUpperCase())==="ONCALL"||((He=(Be=e.callData)==null?void 0:Be.status)==null?void 0:He.toUpperCase())==="RINGING"||((ze=($e=e.callData)==null?void 0:$e.status)==null?void 0:ze.toUpperCase())==="WRAPUP"?"contained":"outlined",onClick:i=>{var b,O,G,K,V,Z;(((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="ONCALL"||((K=(G=e.callData)==null?void 0:G.status)==null?void 0:K.toUpperCase())==="RINGING"||((Z=(V=e.callData)==null?void 0:V.status)==null?void 0:Z.toUpperCase())==="WRAPUP")&&(i.stopPropagation(),y(!0))},sx:((qe=(We=e.callData)==null?void 0:We.status)==null?void 0:qe.toUpperCase())==="ONCALL"||((Ge=(Fe=e.callData)==null?void 0:Fe.status)==null?void 0:Ge.toUpperCase())==="RINGING"||((je=(Ke=e.callData)==null?void 0:Ke.status)==null?void 0:je.toUpperCase())==="WRAPUP"?$(d({},l),{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}`}}):$(d({},n),{minWidth:"60px !important"}),disabled:((Xe=(Ye=e.callData)==null?void 0:Ye.status)==null?void 0:Xe.toUpperCase())!=="ONCALL"&&((Qe=(Je=e.callData)==null?void 0:Je.status)==null?void 0:Qe.toUpperCase())!=="RINGING"&&((Ze=(Ve=e.callData)==null?void 0:Ve.status)==null?void 0:Ze.toUpperCase())!=="WRAPUP",children:(0,c.jsx)(v.CallEnd,{})})})]})]})})}),(0,c.jsx)(g.Fade,{in:!0,timeout:300,children:(0,c.jsxs)(g.Paper,{ref:mt,elevation:ft?4:1,sx:{position:"fixed",left:st.x,top:st.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:I?"visible":"hidden",userSelect:"none"},children:[(0,c.jsxs)(g.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll"},onMouseDown:xt,onTouchStart:ht,children:[(0,c.jsx)(v.DragIndicator,{sx:{transform:"rotate(90deg)"}})," ",(0,c.jsx)(g.IconButton,{onClick:()=>M(!1),children:(0,c.jsx)(v.Close,{})})]}),(0,c.jsx)("iframe",{src:`https://h68.deepijatel.in/ConVoxCCS/iframe?agent_id=${e.agentId}&process_id=${(to=e.process)==null?void 0:to.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay"})]})}),(0,c.jsx)(g.Menu,{anchorEl:N,open:!!N,onClose:Rt,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:(0,c.jsxs)(g.Box,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[(0,c.jsx)(g.TextField,{size:"small",value:Y,placeholder:"Enter Mobile No.",onChange:i=>{X(i.target.value)}}),(0,c.jsx)(g.IconButton,{color:"info",onClick:()=>{Do(Y)},children:(0,c.jsx)(v.Phone,{color:"success"})})]})}),(0,c.jsxs)(g.Menu,{anchorEl:S,open:!!S,onClose:_t,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:[(0,c.jsx)(g.MenuItem,{onClick:()=>Q("Lunch"),children:"- Lunch"}),(0,c.jsx)(g.MenuItem,{onClick:()=>Q("Tea"),children:"- Tea"})]}),(0,c.jsx)(g.Menu,{anchorEl:E,open:!!E,onClose:Dt,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:(0,c.jsxs)(g.Box,{sx:{display:"flex",justifyContent:"flex-start",flexDirection:"column",padding:"0px 10px","&hover":{backgroundColor:"white"}},children:[(0,c.jsx)(g.Chip,{icon:(0,c.jsx)(v.Layers,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),(0,c.jsx)(g.Chip,{icon:(0,c.jsx)(v.Pending,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),(0,c.jsx)(g.Chip,{icon:(0,c.jsx)(v.Upcoming,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!B&&(0,c.jsx)(yo,{open:B,setOpen:o}),!!m&&(0,c.jsx)(vo,{open:m,setOpen:x}),!!u&&(0,c.jsx)(Co,{open:u,setOpen:y,onSubmitDisposition:wo}),!!_&&(0,c.jsx)(So,{open:_,setOpen:z})]})}var zt=class{constructor(){q(this,"config",null);q(this,"ticketId",null);q(this,"baseUrl","");q(this,"eventQueue",[]);q(this,"isOnline",!0);q(this,"retryQueue",[]);q(this,"flushTimer",null)}async init(t){this.config=d({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 l={eventType:t,eventData:n,timestamp:Date.now()};if(this.eventQueue.push(l),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift(),this.isOnline)try{await this.sendEvent(l)}catch(p){console.warn("Failed to send event, will retry later:",p)}}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 l=this.eventQueue.findIndex(p=>p.timestamp===t.timestamp);l>-1&&this.eventQueue.splice(l,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 l of t)await this.sendEvent(l);let n=[...this.retryQueue];this.retryQueue=[];for(let l of n)try{await l()}catch(p){console.error("Retry failed:",p)}}async makeRequest(t,n){var e;let l=`${this.baseUrl}${t}`,p=((e=this.config)==null?void 0:e.retryAttempts)||3;for(let f=1;f<=p;f++)try{return await fetch(l,n)}catch(h){if(f===p)throw h;let E=Math.min(1e3*Math.pow(2,f-1),1e4);await new Promise(C=>setTimeout(C,E))}throw new Error("Max retries exceeded")}setupAutoTracking(){var l;if(typeof window=="undefined"||!((l=this.config)!=null&&l.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(p=>console.warn("Failed to track page visit:",p)),t.clicks!==!1&&document.addEventListener("click",p=>{var f;let e=p.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:(f=e.textContent)==null?void 0:f.trim().substring(0,100),href:e.getAttribute("href"),id:e.id,className:e.className,role:e.getAttribute("role"),position:{x:p.clientX,y:p.clientY},timestamp:new Date().toISOString()}).catch(h=>console.warn("Failed to track click:",h))}),t.forms!==!1&&document.addEventListener("submit",p=>{let e=p.target,f=new FormData(e),h={};f.forEach((E,C)=>{h[C]=E.toString()}),this.logEvent("formSubmission",{formId:e.id,action:e.action,method:e.method,fields:Object.keys(h),fieldCount:Object.keys(h).length,timestamp:new Date().toISOString()}).catch(E=>console.warn("Failed to track form submission:",E))}),t.inputs!==!1){let p;document.addEventListener("input",e=>{let f=e.target;(f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.tagName==="SELECT")&&(clearTimeout(p),p=setTimeout(()=>{var h;this.logEvent("fieldChange",{element:f.tagName,type:f.getAttribute("type"),name:f.getAttribute("name"),id:f.id,valueLength:((h=f.value)==null?void 0:h.length)||0,timestamp:new Date().toISOString()}).catch(E=>console.warn("Failed to track field change:",E))},1e3))})}let n=Date.now();window.addEventListener("beforeunload",()=>{let p=Date.now()-n;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:p,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",p=>{this.logEvent("jsError",{message:p.message,filename:p.filename,lineno:p.lineno,colno:p.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",p=>{var e;this.logEvent("unhandledRejection",{reason:(e=p.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 p=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:p.type,redirectCount:p.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)}},Wt=new zt;typeof window!="undefined"&&(window.EventTracker=Wt);var To=require("react");var Go=(r={})=>{let{onSuccess:t,onError:n,onComplete:l}=r,p=tt(),[e,f]=W({onSuccess:E=>{t==null||t(E),l==null||l(),L.clearStorageAndReset(),localStorage.clear()},onError:E=>{n==null||n(E),l==null||l()}});return{logout:(0,To.useCallback)(()=>{let E={action:"LOGOUTUSER",userId:p.agentId||""};e(A.LOGOUT,E)},[e]),isLoading:f.isLoading,isSuccess:f.isSuccess,isError:f.isError,error:f.error,data:f.data}},Lo=Go;function Ko({apiKey:r,tenantId:t,agentId:n}){L.initialize(r,n),Wt.init({apiKey:r,tenantId:t,agentId:n,baseUrl:k})}0&&(module.exports={CallControlPanel,initSDK,useLogout});
|
|
1
|
+
"use strict";var _o=Object.create;var lt=Object.defineProperty,ko=Object.defineProperties,Ao=Object.getOwnPropertyDescriptor,No=Object.getOwnPropertyDescriptors,Po=Object.getOwnPropertyNames,po=Object.getOwnPropertySymbols,Oo=Object.getPrototypeOf,uo=Object.prototype.hasOwnProperty,Uo=Object.prototype.propertyIsEnumerable;var Ut=(r,t,n)=>t in r?lt(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n,d=(r,t)=>{for(var n in t||(t={}))uo.call(t,n)&&Ut(r,n,t[n]);if(po)for(var n of po(t))Uo.call(t,n)&&Ut(r,n,t[n]);return r},$=(r,t)=>ko(r,No(t));var Mo=(r,t)=>{for(var n in t)lt(r,n,{get:t[n],enumerable:!0})},go=(r,t,n,l)=>{if(t&&typeof t=="object"||typeof t=="function")for(let p of Po(t))!uo.call(r,p)&&p!==n&<(r,p,{get:()=>t[p],enumerable:!(l=Ao(t,p))||l.enumerable});return r};var Bo=(r,t,n)=>(n=r!=null?_o(Oo(r)):{},go(t||!r||!r.__esModule?lt(n,"default",{value:r,enumerable:!0}):n,r)),Ho=r=>go(lt({},"__esModule",{value:!0}),r);var q=(r,t,n)=>Ut(r,typeof t!="symbol"?t+"":t,n);var jo={};Mo(jo,{CallControlPanel:()=>Eo,initSDK:()=>Ko,useLogout:()=>Lo});module.exports=Ho(jo);var v=require("@mui/icons-material"),g=require("@mui/material"),P=require("react");var Mt=class{constructor(){q(this,"state");q(this,"listeners",[]);q(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=$(d({},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 d({},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=d(d({},this.state.callData),t),this.saveToStorage(),this.notifyListeners()}setConferenceLine(t){var l;(!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=(l=this.state.conferenceLine)==null?void 0:l.map(p=>p.line===t.line?t:p);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||[]}},L=new Mt;var F=require("react");function Bt(r,t){let[n,l]=(0,F.useState)(r),[p,e]=(0,F.useState)(!1),f=(0,F.useRef)(),h=(0,F.useRef)({x:0,y:0}),E=(0,F.useRef)({x:0,y:0}),C=(0,F.useCallback)(T=>{let N=f.current;if(!N)return;let H=N.getBoundingClientRect(),B=window.innerWidth,o=window.innerHeight,m={x:Math.max(0,Math.min(T.x,B-H.width)),y:Math.max(0,Math.min(T.y,o-H.height))};l(m),t==null||t(m)},[t]),I=(0,F.useCallback)((T,N)=>{e(!0),h.current={x:T,y:N},E.current=n;let H=(x,u)=>{let y=x-h.current.x,R=u-h.current.y;C({x:E.current.x+y,y:E.current.y+R})},B=x=>{x.preventDefault(),H(x.clientX,x.clientY)},o=x=>{x.preventDefault();let u=x.touches[0];u&&H(u.clientX,u.clientY)},m=()=>{e(!1),document.removeEventListener("mousemove",B),document.removeEventListener("mouseup",m),document.removeEventListener("touchmove",o),document.removeEventListener("touchend",m)};document.addEventListener("mousemove",B),document.addEventListener("mouseup",m),document.addEventListener("touchmove",o,{passive:!1}),document.addEventListener("touchend",m)},[n,C]),M=(0,F.useCallback)(T=>{T.preventDefault(),I(T.clientX,T.clientY)},[I]),S=(0,F.useCallback)(T=>{T.preventDefault();let N=T.touches[0];N&&I(N.clientX,N.clientY)},[I]);return{position:n,isDragging:p,dragRef:f,handleMouseDown:M,handleTouchStart:S}}var At=require("react");function tt(){let[r,t]=(0,At.useState)(L.getState());return(0,At.useEffect)(()=>L.subscribe(()=>{t(L.getState())}),[]),r}var k="http://192.168.101.177:8095",$o="ws://192.168.101.177:8095",U={v1:"/api/v1"},A={LOGIN:`${k}${U.v1}/cti/login?provider=convox`,READY_AGENT:`${k}${U.v1}/cti/ready-agent?provider=convox`,UPDATE_AGENT_BREAK:`${k}${U.v1}/cti/update-agent-break?provider=convox`,CLICK_TO_CALL:`${k}${U.v1}/cti/click-to-call?provider=convox`,HOLD_CALL:`${k}${U.v1}/cti/hold-call?provider=convox`,MUTE_CALL:`${k}${U.v1}/cti/mute-call?provider=convox`,UNMUTE_CALL:`${k}${U.v1}/cti/unmute-call?provider=convox`,END_CALL:`${k}${U.v1}/cti/end-call?provider=convox`,LOGOUT:`${k}${U.v1}/cti/logout?provider=convox`,CONFERENCE_CALL:`${k}${U.v1}/cti/conference-call?provider=convox`,CONFERENCE_CALL_HOLD_OR_UN_HOLD:`${k}${U.v1}/cti/conference-call/hold-unhold?provider=convox`,CONFERENCE_CALL_MUTE_OT_UN_MUTE:`${k}${U.v1}/cti/conference-call/mute-unmute?provider=convox`,CONFERENCE_CALL_END:`${k}${U.v1}/cti/conference-call/hangup?provider=convox`,CONFERENCE_CALL_END_ALL:`${k}${U.v1}/cti/conference-call/hangup-all-call?provider=convox`,TRANSFER_CALL:`${k}${U.v1}/cti/transfer?provider=convox`,AGENTS_LIST:`${k}${U.v1}/cti/users`,PROCESS_LIST:`${k}${U.v1}/cti/processes-list`,TRANSFER_TO_DETAILS:`${k}${U.v1}/cti/trasnfer-to-details?provider=convox`},fo={WS:`${$o}${U.v1}/cti/ws`};var Pt=require("react");var mo=Bo(require("axios"));var zo="12345",Ht=mo.default.create({baseURL:k,headers:{"Content-Type":"application/json",Authorization:zo},timeout:1e4});Ht.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))));Ht.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=Ht;var Nt=require("@mui/material"),xo=require("react"),$t=require("react/jsx-runtime");function ct(){let[r,t]=(0,xo.useState)(!1),n=(p,e)=>{e!=="clickaway"&&t(!1)};return{showToast:(p,e)=>(t(!0),(0,$t.jsx)(Nt.Snackbar,{anchorOrigin:{vertical:"top",horizontal:"right"},open:r,onClose:n,children:(0,$t.jsx)(Nt.Alert,{onClose:n,severity:e,variant:"filled",sx:{width:"100%"},children:p})}))}}var Wo={isLoading:!1,isSuccess:!1,isError:!1,error:null,data:null},qo=(r,t)=>{if(t.type==="isLoading")return $(d({},r),{isLoading:t.payload});if(t.type==="isSuccess")return $(d({},r),{isSuccess:!0,data:t.payload});if(t.type==="isError")return $(d({},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 W=(r={})=>{let{onSuccess:t=null,onError:n=null}=r,{showToast:l}=ct(),[p,e]=(0,Pt.useReducer)(qo,Wo);return[(0,Pt.useCallback)((h,E,C={})=>{e({type:"isLoading",payload:!0}),j.post(h,E,C).then(I=>{e({type:"isSuccess",payload:I.data}),t==null||t(I.data,E)}).catch(I=>{var S,T,N,H,B,o,m,x,u,y,R,w;let M={status:(T=(S=I.response)==null?void 0:S.status)!=null?T:500,message:((H=(N=I.response)==null?void 0:N.data)==null?void 0:H.detail)||((o=(B=I.response)==null?void 0:B.data)==null?void 0:o.message)||I.message||"An unknown error occurred",data:(x=(m=I.response)==null?void 0:m.data)!=null?x:null,statusText:(y=(u=I.response)==null?void 0:u.statusText)!=null?y:"",code:(R=I==null?void 0:I.code)!=null?R:"",name:(w=I==null?void 0:I.name)!=null?w:""};l(M.message,"error"),e({type:"isError",payload:M}),n==null||n(M,E)}).finally(()=>{e({type:"isLoading",payload:!1})})},[t,n,l]),p]};var D=require("@mui/icons-material"),s=require("@mui/material"),ot=require("react");var ho=require("@mui/material"),Fo=()=>{let r=(0,ho.useTheme)();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}`}}}},Ot=Fo;var a=require("react/jsx-runtime");function yo({open:r,setOpen:t}){var H,B;let n=tt(),{disabled:l,enabled:p,outlined:e}=Ot(),f=(0,s.useTheme)(),h=()=>{t(!1)},E=(o,m)=>{L.setConferenceLine(d(d({},o),m))},C=(o,m)=>{var y,R,w,_;let x=d(d({},o),m),u={action:"EXTERNAL_CONFERENCE",operation:`CALL${x.line}`,line_used:String(x.line),thirdparty_no:x.phone,userid:(R=(y=n.callData)==null?void 0:y.agent_id)!=null?R:"",process:(_=(w=n.callData)==null?void 0:w.process_name)!=null?_:""};j.post(A.CONFERENCE_CALL,u).then(()=>{L.setConferenceLine(d(d({},o),m))})},I=(o,m)=>{var y,R,w,_;let x=d(d({},o),m),u={action:"EXTERNAL_CONFERENCE",operation:"CONFERENCE",line_used:String(x.line),thirdparty_no:x.phone,userid:(R=(y=n.callData)==null?void 0:y.agent_id)!=null?R:"",process:(_=(w=n.callData)==null?void 0:w.process_name)!=null?_:""};j.post(A.CONFERENCE_CALL,u).then(()=>{L.setConferenceLine(d(d({},o),m))})},M=(o,m,x)=>{var R,w,_,z;let u=d(d({},o),m),y={action:"EXTERNAL_CONFERENCE",operation:x,hold_channel_no:x==="HOLDUSER"?`hold${u.line}`:`unhold${u.line}`,userid:(w=(R=n.callData)==null?void 0:R.agent_id)!=null?w:"",process:(z=(_=n.callData)==null?void 0:_.process_name)!=null?z:""};j.post(A.CONFERENCE_CALL_HOLD_OR_UN_HOLD,y).then(()=>{L.setConferenceLine(d(d({},o),m))})},S=(o,m,x)=>{var R,w,_,z;let u=d(d({},o),m),y={action:"EXTERNAL_CONFERENCE",operation:x,channel_no:x==="MUTEUSER"?`mute${u.line}`:`play${u.line}`,userid:(w=(R=n.callData)==null?void 0:R.agent_id)!=null?w:"",thirdparty_no:u.phone,process:(z=(_=n.callData)==null?void 0:_.process_name)!=null?z:""};j.post(A.CONFERENCE_CALL_MUTE_OT_UN_MUTE,y).then(()=>{L.setConferenceLine(d(d({},o),m))})},T=(o,m)=>{var y,R,w,_;let x=d(d({},o),m),u={action:"EXTERNAL_CONFERENCE",operation:"HANGUP_CHANNEL",line_used:String(x.line-1),user_type:`THIRDPARTY${x.line-1}`,thirdparty_no:x.phone,userid:(R=(y=n.callData)==null?void 0:y.agent_id)!=null?R:"",process:(_=(w=n.callData)==null?void 0:w.process_name)!=null?_:""};j.post(A.CONFERENCE_CALL_END,u).then(()=>{L.setConferenceLine(d(d({},o),m))})},N=()=>{var m,x,u,y;let o={action:"EXTERNAL_CONFERENCE",operation:"ENDCONFERENCE",userid:(x=(m=n.callData)==null?void 0:m.agent_id)!=null?x:"",process:(y=(u=n.callData)==null?void 0:u.process_name)!=null?y:""};j.post(A.CONFERENCE_CALL_END_ALL,o).then(()=>{L.resetConferenceLines(),h()})};return(0,ot.useEffect)(()=>{var m,x,u,y;let o={line:1,status:(x=(m=n.callData)==null?void 0:m.status)!=null?x:"",type:"internal",phone:(y=(u=n.callData)==null?void 0:u.phone_number)!=null?y:"",isMute:!1,isHold:!1,isMergeCall:!1,isCallStart:!0};L.setConferenceLine(o)},[]),(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px"},children:[(0,a.jsxs)(s.Typography,{variant:"body1",children:[(H=n==null?void 0:n.agentId)!=null?H:""," conference"]}),(0,a.jsx)(s.IconButton,{onClick:h,children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsx)(s.Box,{sx:{boxShadow:"0px 1px 2px #e7e5e5ff",padding:"2px 6px",margin:"0px 10px",borderRadius:"20px"},children:(B=n==null?void 0:n.conferenceLine)==null?void 0:B.map((o,m)=>{var x,u;return(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",justifyContent:"space-between",gap:1},children:[(0,a.jsx)(s.Box,{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:(0,a.jsx)(s.Typography,{children:(x=o==null?void 0:o.line)!=null?x:""})}),(0,a.jsx)(s.Typography,{variant:"body2",sx:{px:1,border:"2px solid gray",borderRadius:"10px",textAlign:"center",width:"80px",maxWidth:"100px"},children:(u=o==null?void 0:o.status)!=null?u:""}),(0,a.jsx)(s.Button,{sx:{textTransform:"capitalize"},size:"small",children:(0,a.jsx)(s.Typography,{variant:"body2",children:(o==null?void 0:o.line)===1?"Internal":"External"})}),(0,a.jsx)(s.TextField,{size:"small",placeholder:"Phone Number",value:(o==null?void 0:o.phone)||"",disabled:(o==null?void 0:o.line)===1,onChange:y=>{E(o,{phone:y.target.value})}}),(0,a.jsx)(s.Tooltip,{title:"Call",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isCallStart?"outlined":"contained",color:"success",sx:o!=null&&o.isCallStart?d({},l):$(d({},p),{border:`0px solid ${f.palette.success.light}`,"&:hover":{bgcolor:"success.light",boxShadow:`0px 2px 1px ${f.palette.success.light}`,border:`0px solid ${f.palette.success.light}`},"&:active":{bgcolor:"success.light",boxShadow:`inset 1px -2px 4px ${f.palette.primary.light}`}}),onClick:()=>{C(o,{isCallStart:!0,status:"ONCALL"})},disabled:o==null?void 0:o.isCallStart,children:(0,a.jsx)(D.Call,{sx:{color:o!=null&&o.isCallStart?"default":"#fff"}})})}),(0,a.jsx)(s.Tooltip,{title:"Merge Call",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isMergeCall?"contained":"outlined",sx:o!=null&&o.isMergeCall&&(o!=null&&o.isCallStart)?d({},l):o!=null&&o.isCallStart?d({},e):d({},l),onClick:()=>{I(o,{isMergeCall:!0,status:"ONCALL"})},disabled:!(o!=null&&o.isCallStart),children:(0,a.jsx)(D.CallSplit,{})})}),(0,a.jsx)(s.Tooltip,{title:o.isHold?"Hold":"Un Hold",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isHold?"contained":"outlined",sx:o!=null&&o.isHold&&(o!=null&&o.isCallStart)?d({},l):o!=null&&o.isCallStart?d({},e):d({},l),onClick:()=>{o.isHold?M(o,{isHold:!1},"UNHOLDUSER"):M(o,{isHold:!0},"HOLDUSER")},disabled:!(o!=null&&o.isCallStart),children:o.isHold?(0,a.jsx)(D.PlayArrow,{}):(0,a.jsx)(D.Pause,{})})}),(0,a.jsx)(s.Tooltip,{title:o.isMute?"Mute":"Un Mute",children:(0,a.jsx)(s.Button,{variant:o!=null&&o.isMute?"contained":"outlined",sx:o!=null&&o.isMute&&(o!=null&&o.isCallStart)?d({},l):o!=null&&o.isCallStart?d({},e):d({},l),onClick:()=>{o.isMute?S(o,{isMute:!1},"PLAYUSER"):S(o,{isMute:!0},"MUTEUSER")},disabled:!(o!=null&&o.isCallStart),children:o.isMute?(0,a.jsx)(D.MicOff,{}):(0,a.jsx)(D.Mic,{})})}),(0,a.jsx)(s.Tooltip,{title:"End Call",children:(o==null?void 0:o.line)!==1?(0,a.jsx)(s.Button,{variant:o!=null&&o.isCallStart?"contained":"outlined",color:"error",sx:o!=null&&o.isCallStart?$(d({},p),{minWidth:"60px !important",border:`0px solid ${f.palette.error.light}`,"&:hover":{bgcolor:"error.light",boxShadow:`0px 2px 1px ${f.palette.error.light}`,border:`0px solid ${f.palette.error.light}`},"&:active":{bgcolor:"error.light",boxShadow:`inset 1px -2px 4px ${f.palette.primary.light}`}}):$(d({},l),{minWidth:"60px !important"}),onClick:()=>{T(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:(0,a.jsx)(D.CallEnd,{})}):(0,a.jsx)(s.Button,{variant:o!=null&&o.isCallStart?"contained":"outlined",sx:$(d({},l),{visibility:"hidden",minWidth:"60px !important"}),onClick:()=>{T(o,{isCallStart:!1,isMergeCall:!1,isMute:!1,isHold:!1,status:"IDLE"})},disabled:!(o!=null&&o.isCallStart),children:(0,a.jsx)(s.Typography,{children:(0,a.jsx)(D.CallEnd,{sx:{visibility:"hidden"}})})})})]},m)})}),(0,a.jsx)(s.Box,{textAlign:"center",m:2,children:(0,a.jsxs)(s.Button,{variant:"outlined",color:"error",size:"large",onClick:N,sx:{px:2,borderRadius:"20px",textTransform:"capitalize"},children:[(0,a.jsx)(s.IconButton,{sx:{bgcolor:"error.main","&:hover":{bgcolor:"error.dark"},marginRight:"8px",width:"28px",height:"28px",fontSize:"12px",fontWeight:"600",lineHeight:"16px",letterSpacing:"0.02em",textTransform:"capitalize",color:"white",display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"50%"},children:(0,a.jsx)(D.PhoneDisabled,{sx:{color:"white",fontSize:"16px",fontWeight:"600"}})}),"End Conference"]})})]})})})}function vo({open:r,setOpen:t}){var S,T,N,H,B,o,m,x;let[n]=W({onSuccess:u=>{console.log("res",u),t(!1)},onError:u=>{console.log("error",u)}}),l=tt(),[p,e]=(0,ot.useState)("process"),[f,{data:h}]=W(),[E,{data:C}]=W(),I=()=>{t(!1)},M=(u,y)=>{var R,w,_,z,Y,X,J,nt,at,pt,dt,ut,gt,st,ft,mt,xt,ht,yt,et,vt,Ct,bt,St,Et,Tt,Lt,Dt,It,Rt,wt,_t,kt;if(console.log(u,"data34"),y==="PROCESS"){let Q={mobile_number:(w=(R=l.callData)==null?void 0:R.phone_number)!=null?w:"",userid:(z=(_=l.callData)==null?void 0:_.agent_id)!=null?z:"",type:"PROCESS",transfer_to:(Y=u==null?void 0:u.process_name)!=null?Y:"",callreferenceid:(J=(X=l.callData)==null?void 0:X.convox_id)!=null?J:"",processid:String((at=(nt=l.callData)==null?void 0:nt.process_id)!=null?at:""),process_name:(dt=(pt=l.callData)==null?void 0:pt.process_name)!=null?dt:""};n(A.TRANSFER_CALL,Q)}else if(y==="QUEUE"){let Q={mobile_number:(gt=(ut=l.callData)==null?void 0:ut.phone_number)!=null?gt:"",userid:(ft=(st=l.callData)==null?void 0:st.agent_id)!=null?ft:"",type:"QUEUE",transfer_to:(mt=u==null?void 0:u.queue_name)!=null?mt:"",callreferenceid:(ht=(xt=l.callData)==null?void 0:xt.convox_id)!=null?ht:"",processid:String((et=(yt=l.callData)==null?void 0:yt.process_id)!=null?et:""),process_name:(Ct=(vt=l.callData)==null?void 0:vt.process_name)!=null?Ct:""};n(A.TRANSFER_CALL,Q)}else if(y==="AGENT"){let Q={mobile_number:(St=(bt=l.callData)==null?void 0:bt.phone_number)!=null?St:"",userid:(Tt=(Et=l.callData)==null?void 0:Et.agent_id)!=null?Tt:"",type:"AGENT",transfer_to:(Lt=u==null?void 0:u.user_id)!=null?Lt:"",callreferenceid:(It=(Dt=l.callData)==null?void 0:Dt.convox_id)!=null?It:"",processid:String((wt=(Rt=l.callData)==null?void 0:Rt.process_id)!=null?wt:""),process_name:(kt=(_t=l.callData)==null?void 0:_t.process_name)!=null?kt:""};n(A.TRANSFER_CALL,Q)}};return(0,ot.useEffect)(()=>{f(A.AGENTS_LIST,{status:"IDLE",active:!0}),E(A.TRANSFER_TO_DETAILS,{status:"ACTIVE",active:!0})},[]),(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,a.jsx)(s.Typography,{variant:"body1",children:" Call Transfer"}),(0,a.jsx)(s.IconButton,{onClick:I,children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsxs)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px 10px",margin:"10px",borderRadius:"10px"},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",gap:1},children:[(0,a.jsx)(s.Button,{variant:p==="process"?"contained":"outlined",onClick:()=>e("process"),children:"Process"}),(0,a.jsx)(s.Button,{variant:p==="queues"?"contained":"outlined",onClick:()=>e("queues"),children:"Queues"}),(0,a.jsx)(s.Button,{variant:p==="agents"?"contained":"outlined",onClick:()=>e("agents"),children:"Agents"})]}),p==="process"&&(0,a.jsx)(s.Box,{sx:{display:"flex",gap:1},children:((T=(S=C==null?void 0:C.data)==null?void 0:S.process)==null?void 0:T.length)>0?(H=(N=C==null?void 0:C.data)==null?void 0:N.process)==null?void 0:H.map((u,y)=>(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),u.process_name]}),(0,a.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{M(u,"PROCESS")},children:(0,a.jsx)(D.Call,{})})]},y)):(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",textAlign:"center",width:"100%",margin:"10px 0px",color:"gray"},children:"No Process Found"})}),p==="queues"&&(0,a.jsx)(s.Box,{sx:{display:"flex",gap:1},children:((o=(B=C==null?void 0:C.data)==null?void 0:B.queue)==null?void 0:o.length)>0?(x=(m=C==null?void 0:C.data)==null?void 0:m.queue)==null?void 0:x.map((u,y)=>{var R,w,_,z,Y,X;return(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),u.queue_name,(_=(w=(R=C==null?void 0:C.data)==null?void 0:R.process)==null?void 0:w.find(J=>J.process_id===u.process_id))!=null&&_.process_name?(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",color:"gray"},children:"("+((X=(Y=(z=C==null?void 0:C.data)==null?void 0:z.process)==null?void 0:Y.find(J=>J.process_id===u.process_id))==null?void 0:X.process_name)+")"}):""]}),(0,a.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{M(u,"QUEUE")},children:(0,a.jsx)(D.Call,{})})]},y)}):(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",textAlign:"center",width:"100%",margin:"10px 0px",color:"gray"},children:"No Queues Found"})}),p==="agents"&&(0,a.jsx)(s.Box,{sx:{display:"flex",gap:1},children:(h==null?void 0:h.length)>0?h.map((u,y)=>(0,a.jsxs)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px","&:hover":{bgcolor:"action.selected"}},children:[(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),u.name]}),(0,a.jsx)(s.IconButton,{color:"success",sx:{bgcolor:"action.hover","&:hover":{bgcolor:"action.selected"}},onClick:()=>{M(u,"AGENT")},children:(0,a.jsx)(D.Call,{})})]},y)):(0,a.jsx)(s.Typography,{variant:"body1",sx:{fontSize:"12px",fontWeight:"600",letterSpacing:"0.02em",textTransform:"capitalize",textAlign:"center",width:"100%",margin:"10px 0px",color:"gray"},children:"No Agents Found"})})]})]})})})}function Co({open:r,setOpen:t,onSubmitDisposition:n}){var I,M;let[l,p]=(0,ot.useState)({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""}),e=[{label:"Not Interested",value:"NI"},{label:"Resolved",value:"RES"}],f=[{label:"Yes",value:"Y"},{label:"No",value:"N"}],h=(S,T)=>{p(N=>$(d({},N),{[S]:T}))},E=()=>{p({disposition:{label:"Resolved",value:"RES"},followUp:{label:"No",value:"N"},callbackDate:"",callbackHrs:"",callbackMins:""})},C=()=>{E(),t(!1)};return(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"xs",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsx)(s.Box,{sx:{display:"flex",justifyContent:"center",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:(0,a.jsxs)(s.Typography,{variant:"body1",m:1,children:[" ","Call Disposition"]})}),(0,a.jsx)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",padding:"10px",margin:"10px",borderRadius:"10px"},children:(0,a.jsxs)(s.Grid,{container:!0,spacing:2,children:[(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.Autocomplete,{value:l.disposition,options:e,getOptionLabel:S=>S.label,onChange:(S,T)=>h("disposition",T),size:"small",renderInput:S=>(0,a.jsx)(s.TextField,$(d({},S),{label:"Disposition",fullWidth:!0}))})}),(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.Autocomplete,{options:f,getOptionLabel:S=>S.label,value:l.followUp,onChange:(S,T)=>h("followUp",T),size:"small",renderInput:S=>(0,a.jsx)(s.TextField,$(d({},S),{label:"Follow Up",fullWidth:!0}))})}),((M=(I=l==null?void 0:l.followUp)==null?void 0:I.label)==null?void 0:M.toLowerCase())==="yes"&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.TextField,{size:"small",label:"Callback Date",type:"date",slotProps:{inputLabel:{shrink:!0}},value:l.callbackDate,onChange:S=>h("callbackDate",S.target.value),fullWidth:!0})}),(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.TextField,{size:"small",label:"Hours (0-23)",type:"text",inputProps:{min:0,max:23},value:l.callbackHrs,onChange:S=>h("callbackHrs",S.target.value),fullWidth:!0})}),(0,a.jsx)(s.Grid,{size:6,children:(0,a.jsx)(s.TextField,{size:"small",label:"Minutes (0-59)",type:"text",inputProps:{min:0,max:59},value:l.callbackMins,onChange:S=>h("callbackMins",S.target.value),fullWidth:!0})})]})]})}),(0,a.jsxs)(s.Box,{textAlign:"right",m:2,children:[(0,a.jsx)(s.Button,{variant:"outlined",color:"error",size:"large",onClick:C,sx:{px:2,mx:1,borderRadius:"10px",textTransform:"capitalize"},children:"cancel"}),(0,a.jsx)(s.Button,{variant:"contained",color:"primary",size:"large",onClick:()=>n(l),sx:{px:2,borderRadius:"10px",textTransform:"capitalize"},children:"Submit"})]})]})})})}function bo({open:r,setOpen:t,processList:n=[],handleSelectedProcessor:l}){return(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",maxWidth:"xs",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,a.jsx)(s.Typography,{variant:"body1",children:" Process List"}),(0,a.jsx)(s.IconButton,{onClick:()=>{t(!1)},children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsx)(s.Box,{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,f)=>(0,a.jsx)(s.Box,{sx:{p:1,display:"flex",alignItems:"center",boxShadow:"1px 1px 4px #d3d3d3ff",padding:"6px",margin:"10px 0px",borderRadius:"10px",cursor:"pointer","&:hover":{bgcolor:"action.selected"}},onClick:()=>{l(e)},children:(0,a.jsxs)(s.Typography,{variant:"body1",sx:{mx:1,width:"200px",maxWidth:"250px",display:"flex",alignItems:"center"},children:[(0,a.jsx)(D.SupportAgent,{sx:{marginRight:"4px"}}),e.process_name]})},f)):null})]})})})}function So({open:r,setOpen:t}){return(0,a.jsx)(a.Fragment,{children:(0,a.jsx)(s.Dialog,{open:r,"aria-labelledby":"alert-dialog-title","aria-describedby":"alert-dialog-description",fullWidth:!0,maxWidth:"md",children:(0,a.jsxs)(s.Paper,{sx:{borderRadius:2},children:[(0,a.jsxs)(s.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",padding:"4px 16px",boxShadow:"0px 1px 2px #f5f5f5ff"},children:[(0,a.jsx)(s.Typography,{variant:"body1",children:" Call History"}),(0,a.jsx)(s.IconButton,{onClick:()=>{t(!1)},children:(0,a.jsx)(D.Close,{})})]}),(0,a.jsx)(s.Box,{sx:{boxShadow:"1px 1px 4px #d3d3d3ff",margin:"10px",borderRadius:"10px",textAlign:"center",fontSize:"16px",fontWeight:"bold"},p:6,children:"Coming Soon..."})]})})})}var c=require("react/jsx-runtime");function Eo({onDataChange:r}){var qt,Ft,Gt,Kt,jt,Yt,Xt,Jt,Qt,Vt,Zt,te,ee,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;let t=(0,g.useTheme)(),{disabled:n,enabled:l,outlined:p}=Ot(),e=tt(),{showToast:f}=ct(),h=(0,P.useRef)(null),[E,C]=(0,P.useState)(null),[I,M]=(0,P.useState)(!0),[S,T]=(0,P.useState)(null),[N,H]=(0,P.useState)(null),[B,o]=(0,P.useState)(!1),[m,x]=(0,P.useState)(!1),[u,y]=(0,P.useState)(!1),[R,w]=(0,P.useState)(!1),[_,z]=(0,P.useState)(!1),[Y,X]=(0,P.useState)(""),[J,nt]=(0,P.useState)(0),{position:at,isDragging:pt,dragRef:dt,handleMouseDown:ut,handleTouchStart:gt}=Bt(e.controlPanelPosition,i=>L.setControlPanelPosition(i)),{position:st,isDragging:ft,dragRef:mt,handleMouseDown:xt,handleTouchStart:ht}=Bt(e.iframePosition,i=>L.setIframePosition(i)),[yt,{data:et}]=W({onSuccess:i=>{var b;console.log("res",i),i&&i.processes&&((b=i==null?void 0:i.processes)==null?void 0:b.length)>1?w(!0):(L.setProcess(i==null?void 0:i.processes[0]),w(!1))},onError:()=>{w(!1)}}),[vt]=W(),[Ct]=W({onSuccess:()=>{L.setHolding(!e.isHolding)},onError:i=>{console.log("error",i)}}),[bt]=W({onSuccess:()=>{L.setMuted(!e.isMuted)},onError:i=>{console.log("error",i)}}),[St]=W(),[Et]=W(),[Tt]=W(),Lt=(0,P.useCallback)(i=>{let b=Math.floor(i/60),O=i%60;return`${b.toString().padStart(2,"0")}:${O.toString().padStart(2,"0")}`},[]),Dt=()=>{C(null)},It=i=>{M(!0),H(i.currentTarget),L.setStatus("dial")},Rt=()=>{e.status!=="on call"&&L.setStatus("idle"),H(null)},wt=i=>{T(i.currentTarget)},_t=()=>{T(null)},kt=()=>{let i={action:"READYAGENT",userId:e.agentId};St(A.READY_AGENT,i)},Q=i=>{T(null);let b={action:"AGENTBREAK",break_type:i,userId:e.agentId};Et(A.UPDATE_AGENT_BREAK,b)},Do=i=>{if(i.length!==10)f("Invalid phone number","error"),alert("Invalid phone number");else if(!/^\d+$/.test(i))f("Invalid phone number","error");else{let b={action:"CALL",phone_number:i,userId:e.agentId};vt(A.CLICK_TO_CALL,b)}},Io=()=>{let i={action:e.isHolding?"UNHOLD":"HOLD",userId:e.agentId};Ct(A.HOLD_CALL,i)},Ro=()=>{let i={action:e.isMuted?"UNMUTE":"MUTE",userId:e.agentId};bt(A.MUTE_CALL,i)},wo=i=>{var O,G,K,V,Z,it,rt,eo,oo,no,ao,so,io,ro,lo,co;console.log("data",i);let b={action:"ENDCALL",userId:e.agentId,processid:(K=(G=(O=e.process)==null?void 0:O.process_id)==null?void 0:G.toString())!=null?K:"",process_name:(Z=(V=e.process)==null?void 0:V.process_name)!=null?Z:"",callreferenceid:(rt=(it=e.callData)==null?void 0:it.convox_id)!=null?rt:"",mobile_number:(oo=(eo=e.callData)==null?void 0:eo.phone_number)!=null?oo:"",disposition:(ao=(no=i==null?void 0:i.disposition)==null?void 0:no.value)!=null?ao:"",set_followUp:(io=(so=i==null?void 0:i.followUp)==null?void 0:so.value)!=null?io:"",callback_date:(ro=i==null?void 0:i.callbackDate)!=null?ro:"",callback_hrs:(lo=i==null?void 0:i.callbackHrs)!=null?lo:"",callback_mins:(co=i==null?void 0:i.callbackMins)!=null?co:"",endcall_type:"CLOSE"};X(""),Tt(A.END_CALL,b),L.endCall(),y(!1)};return(0,P.useEffect)(()=>{let i;return e.callData.status&&e.callData.status==="ONCALL"?i=setInterval(()=>{let b=Math.floor((Date.now()-e.callStartTime)/1e3);nt(b)},1e3):nt(0),()=>{i&&clearInterval(i)}},[e.callData.status]),(0,P.useEffect)(()=>{r&&r(e.callData)},[e.callData,r]),(0,P.useEffect)(()=>{e.agentId?yt(A.PROCESS_LIST,{userId:e.agentId,action:"GETAGENTPROCESSLIST",refno:"1234221233"}):console.log("No agentId available, skipping API call")},[e.agentId]),(0,P.useEffect)(()=>(e.agentId&&(h.current=new WebSocket(`${fo.WS}?agent_id=${e.agentId}`),h.current.onopen=()=>{console.log("WebSocket connection established")},h.current.onmessage=i=>{try{let b=JSON.parse(i.data);console.log("parsedJSON:",b),L.updateCallData(b),b.status==="ONCALL"&&L.startCall(),b.status==="WRAPUP"&&L.endCall()}catch(b){console.log("Raw message:",i.data)}},h.current.onclose=()=>{console.log("WebSocket connection closed")},h.current.onerror=i=>{console.error("WebSocket error:",i)}),()=>{var i;(i=h.current)==null||i.close()}),[e.agentId]),!e.isInitialized||!e.process?(0,c.jsx)(g.Box,{children:!!R&&(0,c.jsx)(bo,{processList:et==null?void 0:et.processes,open:R,setOpen:w,handleSelectedProcessor:i=>{L.setProcess(i)}})}):(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(g.Fade,{in:!0,timeout:300,children:(0,c.jsx)(g.Paper,{ref:dt,elevation:pt?4:1,sx:{position:"fixed",left:at.x,top:at.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:(0,c.jsxs)(g.Box,{sx:{display:"flex",alignItems:"center"},children:[(0,c.jsxs)(g.Box,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,c.jsxs)(g.IconButton,{component:"div",size:"small",sx:{cursor:"all-scroll"},onMouseDown:ut,onTouchStart:gt,children:[(0,c.jsx)(v.DragIndicator,{})," "]}),(0,c.jsx)(g.Box,{sx:{marginRight:"10px"},children:(0,c.jsx)(g.Tooltip,{title:"Dial",children:(0,c.jsx)(g.IconButton,{size:"small",onClick:i=>{var b,O,G,K,V,Z,it,rt;((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())!=="ONCALL"&&((K=(G=e.callData)==null?void 0:G.status)==null?void 0:K.toUpperCase())!=="BREAK"&&((Z=(V=e.callData)==null?void 0:V.status)==null?void 0:Z.toUpperCase())!=="RINGING"&&((rt=(it=e.callData)==null?void 0:it.status)==null?void 0:rt.toUpperCase())!=="WRAPUP"&&It(i)},sx:{bgcolor:"action.hover","&:hover":{bgcolor:"warning"}},children:(0,c.jsx)(v.WifiCalling3,{sx:{color:((Ft=(qt=e.callData)==null?void 0:qt.status)==null?void 0:Ft.toUpperCase())==="ONCALL"||((Kt=(Gt=e.callData)==null?void 0:Gt.status)==null?void 0:Kt.toUpperCase())==="BREAK"||((Yt=(jt=e.callData)==null?void 0:jt.status)==null?void 0:Yt.toUpperCase())==="RINGING"||((Jt=(Xt=e.callData)==null?void 0:Xt.status)==null?void 0:Jt.toUpperCase())==="WRAPUP"?"action.selected":"success.main"}})})})}),(0,c.jsx)(g.Typography,{sx:{color:"success.main",width:"40px",marginRight:"10px"},children:Lt(J)}),(0,c.jsx)(g.Typography,{variant:"body2",sx:{fontWeight:"bold"},children:(Zt=(Vt=(Qt=e.callData)==null?void 0:Qt.status)==null?void 0:Vt.toUpperCase())!=null?Zt:"N/A"}),(0,c.jsxs)(g.Button,{size:"small",variant:"text",onClick:wt,disabled:!!e.callStartTime,children:[(0,c.jsx)(v.ArrowDropDown,{})," "]})]}),(0,c.jsxs)(g.Box,{sx:{display:"flex",gap:1,justifyContent:"center",alignItems:"center"},children:[(0,c.jsx)(g.Tooltip,{title:"Agent Ready",children:(0,c.jsx)(g.Button,{variant:((ee=(te=e.callData)==null?void 0:te.status)==null?void 0:ee.toUpperCase())==="BREAK"||((ne=(oe=e.callData)==null?void 0:oe.status)==null?void 0:ne.toUpperCase())==="MISSED"?"outlined":"contained",onClick:i=>{var b,O,G,K;(((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="BREAK"||((K=(G=e.callData)==null?void 0:G.status)==null?void 0:K.toUpperCase())==="MISSED")&&(i.stopPropagation(),kt())},classes:{root:((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())==="MISSED"?"outlined":"enabled"},sx:d({},((ce=(le=e.callData)==null?void 0:le.status)==null?void 0:ce.toUpperCase())==="BREAK"||((de=(pe=e.callData)==null?void 0:pe.status)==null?void 0:de.toUpperCase())==="MISSED"?p:l),children:(0,c.jsx)(v.SupportAgent,{})})}),(0,c.jsx)(g.Tooltip,{title:e.isHolding?"Resume":"Hold",children:(0,c.jsx)(g.Button,{variant:e.isHolding&&((ge=(ue=e.callData)==null?void 0:ue.status)==null?void 0:ge.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:i=>{i.stopPropagation(),Io()},sx:e.isHolding&&((me=(fe=e.callData)==null?void 0:fe.status)==null?void 0:me.toUpperCase())==="ONCALL"?d({},l):((he=(xe=e.callData)==null?void 0:xe.status)==null?void 0:he.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((ve=(ye=e.callData)==null?void 0:ye.status)==null?void 0:ve.toUpperCase())!=="ONCALL"&&!e.isHolding,children:e.isHolding?(0,c.jsx)(v.PlayArrow,{}):(0,c.jsx)(v.Pause,{})})}),(0,c.jsx)(g.Tooltip,{title:e.isMuted?"Unmute":"Mute",children:(0,c.jsx)(g.Button,{variant:e.isMuted&&((be=(Ce=e.callData)==null?void 0:Ce.status)==null?void 0:be.toUpperCase())==="ONCALL"?"contained":"outlined",onClick:i=>{i.stopPropagation(),Ro()},sx:e.isMuted&&((Ee=(Se=e.callData)==null?void 0:Se.status)==null?void 0:Ee.toUpperCase())==="ONCALL"?d({},l):((Le=(Te=e.callData)==null?void 0:Te.status)==null?void 0:Le.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((Ie=(De=e.callData)==null?void 0:De.status)==null?void 0:Ie.toUpperCase())!=="ONCALL"&&!e.isMuted,children:e.isMuted?(0,c.jsx)(v.MicOff,{}):(0,c.jsx)(v.Mic,{})})}),(0,c.jsx)(g.Tooltip,{title:"Transfer Call",children:(0,c.jsx)(g.Button,{variant:m?"contained":"outlined",onClick:i=>{var b,O;((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="ONCALL"&&(i.stopPropagation(),x(!0))},sx:m?d({},l):((we=(Re=e.callData)==null?void 0:Re.status)==null?void 0:we.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((ke=(_e=e.callData)==null?void 0:_e.status)==null?void 0:ke.toUpperCase())!=="ONCALL",children:(0,c.jsx)(v.TransferWithinAStation,{})})}),(0,c.jsx)(g.Tooltip,{title:"Conference Call",children:(0,c.jsx)(g.Button,{variant:B?"contained":"outlined",onClick:i=>{var b,O;((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="ONCALL"&&(i.stopPropagation(),o(!0))},sx:B?d({},l):((Ne=(Ae=e.callData)==null?void 0:Ae.status)==null?void 0:Ne.toUpperCase())==="ONCALL"?d({},p):d({},n),disabled:((Oe=(Pe=e.callData)==null?void 0:Pe.status)==null?void 0:Oe.toUpperCase())!=="ONCALL",children:(0,c.jsx)(v.Group,{})})}),(0,c.jsx)(g.Tooltip,{title:"Call History",children:(0,c.jsx)(g.Button,{variant:_?"contained":"outlined",onClick:i=>{i.stopPropagation(),z(!0)},sx:_?d({},l):d({},p),children:(0,c.jsx)(v.History,{})})}),(0,c.jsx)(g.Tooltip,{title:"End Call",children:(0,c.jsx)(g.Button,{variant:((Me=(Ue=e.callData)==null?void 0:Ue.status)==null?void 0:Me.toUpperCase())==="ONCALL"||((He=(Be=e.callData)==null?void 0:Be.status)==null?void 0:He.toUpperCase())==="RINGING"||((ze=($e=e.callData)==null?void 0:$e.status)==null?void 0:ze.toUpperCase())==="WRAPUP"?"contained":"outlined",onClick:i=>{var b,O,G,K,V,Z;(((O=(b=e.callData)==null?void 0:b.status)==null?void 0:O.toUpperCase())==="ONCALL"||((K=(G=e.callData)==null?void 0:G.status)==null?void 0:K.toUpperCase())==="RINGING"||((Z=(V=e.callData)==null?void 0:V.status)==null?void 0:Z.toUpperCase())==="WRAPUP")&&(i.stopPropagation(),y(!0))},sx:((qe=(We=e.callData)==null?void 0:We.status)==null?void 0:qe.toUpperCase())==="ONCALL"||((Ge=(Fe=e.callData)==null?void 0:Fe.status)==null?void 0:Ge.toUpperCase())==="RINGING"||((je=(Ke=e.callData)==null?void 0:Ke.status)==null?void 0:je.toUpperCase())==="WRAPUP"?$(d({},l),{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}`}}):$(d({},n),{minWidth:"60px !important"}),disabled:((Xe=(Ye=e.callData)==null?void 0:Ye.status)==null?void 0:Xe.toUpperCase())!=="ONCALL"&&((Qe=(Je=e.callData)==null?void 0:Je.status)==null?void 0:Qe.toUpperCase())!=="RINGING"&&((Ze=(Ve=e.callData)==null?void 0:Ve.status)==null?void 0:Ze.toUpperCase())!=="WRAPUP",children:(0,c.jsx)(v.CallEnd,{})})})]})]})})}),(0,c.jsx)(g.Fade,{in:!0,timeout:300,children:(0,c.jsxs)(g.Paper,{ref:mt,elevation:ft?4:1,sx:{position:"fixed",left:st.x,top:st.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:I?"visible":"hidden",userSelect:"none"},children:[(0,c.jsxs)(g.Box,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"all-scroll"},onMouseDown:xt,onTouchStart:ht,children:[(0,c.jsx)(v.DragIndicator,{sx:{transform:"rotate(90deg)"}})," ",(0,c.jsx)(g.IconButton,{onClick:()=>M(!1),children:(0,c.jsx)(v.Close,{})})]}),(0,c.jsx)("iframe",{src:`https://h68.deepijatel.in/ConVoxCCS/iframe?agent_id=${e.agentId}&process_id=${(to=e.process)==null?void 0:to.process_id}`,height:380,width:420,allow:"camera; microphone; autoplay"})]})}),(0,c.jsx)(g.Menu,{anchorEl:N,open:!!N,onClose:Rt,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:(0,c.jsxs)(g.Box,{sx:{all:"unset",padding:"10px","&hover":{backgroundColor:"white"}},children:[(0,c.jsx)(g.TextField,{size:"small",value:Y,placeholder:"Enter Mobile No.",onChange:i=>{X(i.target.value)}}),(0,c.jsx)(g.IconButton,{color:"info",onClick:()=>{Do(Y)},children:(0,c.jsx)(v.Phone,{color:"success"})})]})}),(0,c.jsxs)(g.Menu,{anchorEl:S,open:!!S,onClose:_t,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:[(0,c.jsx)(g.MenuItem,{onClick:()=>Q("Lunch"),children:"- Lunch"}),(0,c.jsx)(g.MenuItem,{onClick:()=>Q("Tea"),children:"- Tea"})]}),(0,c.jsx)(g.Menu,{anchorEl:E,open:!!E,onClose:Dt,onClick:i=>i.stopPropagation(),sx:{zIndex:99999},children:(0,c.jsxs)(g.Box,{sx:{display:"flex",justifyContent:"flex-start",flexDirection:"column",padding:"0px 10px","&hover":{backgroundColor:"white"}},children:[(0,c.jsx)(g.Chip,{icon:(0,c.jsx)(v.Layers,{color:"secondary"}),variant:"outlined",label:"Waiting - 25",sx:{margin:"4px 2px"}}),(0,c.jsx)(g.Chip,{icon:(0,c.jsx)(v.Pending,{color:"info"}),label:"Pending - 99+",variant:"outlined",sx:{margin:"4px 2px"}}),(0,c.jsx)(g.Chip,{icon:(0,c.jsx)(v.Upcoming,{color:"success"}),variant:"outlined",label:"Upcoming - 66",sx:{margin:"4px 2px"}})]})}),!!B&&(0,c.jsx)(yo,{open:B,setOpen:o}),!!m&&(0,c.jsx)(vo,{open:m,setOpen:x}),!!u&&(0,c.jsx)(Co,{open:u,setOpen:y,onSubmitDisposition:wo}),!!_&&(0,c.jsx)(So,{open:_,setOpen:z})]})}var zt=class{constructor(){q(this,"config",null);q(this,"ticketId",null);q(this,"baseUrl","");q(this,"eventQueue",[]);q(this,"isOnline",!0);q(this,"retryQueue",[]);q(this,"flushTimer",null)}async init(t){this.config=d({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 l={eventType:t,eventData:n,timestamp:Date.now()};if(this.eventQueue.push(l),this.eventQueue.length>(this.config.queueSize||100)&&this.eventQueue.shift(),this.isOnline)try{await this.sendEvent(l)}catch(p){console.warn("Failed to send event, will retry later:",p)}}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 l=this.eventQueue.findIndex(p=>p.timestamp===t.timestamp);l>-1&&this.eventQueue.splice(l,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 l of t)await this.sendEvent(l);let n=[...this.retryQueue];this.retryQueue=[];for(let l of n)try{await l()}catch(p){console.error("Retry failed:",p)}}async makeRequest(t,n){var e;let l=`${this.baseUrl}${t}`,p=((e=this.config)==null?void 0:e.retryAttempts)||3;for(let f=1;f<=p;f++)try{return await fetch(l,n)}catch(h){if(f===p)throw h;let E=Math.min(1e3*Math.pow(2,f-1),1e4);await new Promise(C=>setTimeout(C,E))}throw new Error("Max retries exceeded")}setupAutoTracking(){var l;if(typeof window=="undefined"||!((l=this.config)!=null&&l.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(p=>console.warn("Failed to track page visit:",p)),t.clicks!==!1&&document.addEventListener("click",p=>{var f;let e=p.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:(f=e.textContent)==null?void 0:f.trim().substring(0,100),href:e.getAttribute("href"),id:e.id,className:e.className,role:e.getAttribute("role"),position:{x:p.clientX,y:p.clientY},timestamp:new Date().toISOString()}).catch(h=>console.warn("Failed to track click:",h))}),t.forms!==!1&&document.addEventListener("submit",p=>{let e=p.target,f=new FormData(e),h={};f.forEach((E,C)=>{h[C]=E.toString()}),this.logEvent("formSubmission",{formId:e.id,action:e.action,method:e.method,fields:Object.keys(h),fieldCount:Object.keys(h).length,timestamp:new Date().toISOString()}).catch(E=>console.warn("Failed to track form submission:",E))}),t.inputs!==!1){let p;document.addEventListener("input",e=>{let f=e.target;(f.tagName==="INPUT"||f.tagName==="TEXTAREA"||f.tagName==="SELECT")&&(clearTimeout(p),p=setTimeout(()=>{var h;this.logEvent("fieldChange",{element:f.tagName,type:f.getAttribute("type"),name:f.getAttribute("name"),id:f.id,valueLength:((h=f.value)==null?void 0:h.length)||0,timestamp:new Date().toISOString()}).catch(E=>console.warn("Failed to track field change:",E))},1e3))})}let n=Date.now();window.addEventListener("beforeunload",()=>{let p=Date.now()-n;this.logEvent("pageUnload",{url:window.location.href,sessionDuration:p,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",p=>{this.logEvent("jsError",{message:p.message,filename:p.filename,lineno:p.lineno,colno:p.colno,timestamp:new Date().toISOString()})}),window.addEventListener("unhandledrejection",p=>{var e;this.logEvent("unhandledRejection",{reason:(e=p.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 p=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:p.type,redirectCount:p.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)}},Wt=new zt;typeof window!="undefined"&&(window.EventTracker=Wt);var To=require("react");var Go=(r={})=>{let{onSuccess:t,onError:n,onComplete:l}=r,p=tt(),[e,f]=W({onSuccess:E=>{t==null||t(E),l==null||l(),L.clearStorageAndReset(),localStorage.clear()},onError:E=>{n==null||n(E),l==null||l()}});return{logout:(0,To.useCallback)(()=>{let E={action:"LOGOUTUSER",userId:p.agentId||""};e(A.LOGOUT,E)},[e]),isLoading:f.isLoading,isSuccess:f.isSuccess,isError:f.isError,error:f.error,data:f.data}},Lo=Go;function Ko({apiKey:r,tenantId:t,agentId:n}){L.initialize(r,n),Wt.init({apiKey:r,tenantId:t,agentId:n,baseUrl:k})}0&&(module.exports={CallControlPanel,initSDK,useLogout});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|