ahs-cti 0.0.8 → 0.0.9

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.
Files changed (139) hide show
  1. package/dist/agentDetailReport-F44HMQ5O.mjs +27 -0
  2. package/dist/agentDetailReport-F44HMQ5O.mjs.map +1 -0
  3. package/dist/{agentPerformanceReport-JZK5DN5E.mjs → agentPerformanceReport-TTOMNENK.mjs} +25 -15
  4. package/dist/{agentPerformanceReport-JZK5DN5E.mjs.map → agentPerformanceReport-TTOMNENK.mjs.map} +1 -1
  5. package/dist/auditReport-QTMAKVTN.mjs +26 -0
  6. package/dist/auditReport-QTMAKVTN.mjs.map +1 -0
  7. package/dist/{callHistory-T3M76D4B.mjs → callHistory-4J4J2XHA.mjs} +20 -10
  8. package/dist/{callHistory-T3M76D4B.mjs.map → callHistory-4J4J2XHA.mjs.map} +1 -1
  9. package/dist/{campaigns-5PVHXBSD.mjs → campaigns-N3UNUGQP.mjs} +23 -13
  10. package/dist/{campaigns-5PVHXBSD.mjs.map → campaigns-N3UNUGQP.mjs.map} +1 -1
  11. package/dist/{caroQualityAuditDashboard-EUDYZ3QY.mjs → caroQualityAuditDashboard-TNS4L2NR.mjs} +12 -2
  12. package/dist/{caroQualityAuditDashboard-EUDYZ3QY.mjs.map → caroQualityAuditDashboard-TNS4L2NR.mjs.map} +1 -1
  13. package/dist/{caroVoiceAI-GGJCVUIQ.mjs → caroVoiceAI-OUTAAIFE.mjs} +12 -2
  14. package/dist/{caroVoiceAI-GGJCVUIQ.mjs.map → caroVoiceAI-OUTAAIFE.mjs.map} +1 -1
  15. package/dist/{cdrReport-ZMDHSZUW.mjs → cdrReport-Z35OLYUL.mjs} +26 -16
  16. package/dist/{cdrReport-ZMDHSZUW.mjs.map → cdrReport-Z35OLYUL.mjs.map} +1 -1
  17. package/dist/chunk-3PNP6G5P.mjs +92 -0
  18. package/dist/chunk-3PNP6G5P.mjs.map +1 -0
  19. package/dist/{chunk-DF5EFKXC.mjs → chunk-45MLTWV7.mjs} +12 -2
  20. package/dist/{chunk-DF5EFKXC.mjs.map → chunk-45MLTWV7.mjs.map} +1 -1
  21. package/dist/chunk-635IIVZE.mjs +24 -0
  22. package/dist/{chunk-FRKV2U3I.mjs.map → chunk-635IIVZE.mjs.map} +1 -1
  23. package/dist/chunk-677RFPP5.mjs +24 -0
  24. package/dist/{chunk-7LE2VTAI.mjs.map → chunk-677RFPP5.mjs.map} +1 -1
  25. package/dist/{chunk-Q6G3MPS7.mjs → chunk-ERSNXW5X.mjs} +11 -1
  26. package/dist/{chunk-Q6G3MPS7.mjs.map → chunk-ERSNXW5X.mjs.map} +1 -1
  27. package/dist/{chunk-H7GRWLYI.mjs → chunk-G6KRLGGC.mjs} +13 -3
  28. package/dist/{chunk-H7GRWLYI.mjs.map → chunk-G6KRLGGC.mjs.map} +1 -1
  29. package/dist/chunk-GFVR3HLK.mjs +24 -0
  30. package/dist/{chunk-6WLG2PXL.mjs.map → chunk-GFVR3HLK.mjs.map} +1 -1
  31. package/dist/{chunk-E6KYWWAI.mjs → chunk-GTI2ZVQX.mjs} +12 -2
  32. package/dist/{chunk-E6KYWWAI.mjs.map → chunk-GTI2ZVQX.mjs.map} +1 -1
  33. package/dist/chunk-H22TUCN3.mjs +24 -0
  34. package/dist/{chunk-AOJRUZTO.mjs.map → chunk-H22TUCN3.mjs.map} +1 -1
  35. package/dist/{chunk-YAQYTUTX.mjs → chunk-HAOFUADN.mjs} +12 -2
  36. package/dist/{chunk-YAQYTUTX.mjs.map → chunk-HAOFUADN.mjs.map} +1 -1
  37. package/dist/{chunk-33QNSXP7.mjs → chunk-JHC7OUQG.mjs} +21 -11
  38. package/dist/chunk-JHC7OUQG.mjs.map +1 -0
  39. package/dist/chunk-KSVNZKRD.mjs +10930 -0
  40. package/dist/chunk-KSVNZKRD.mjs.map +1 -0
  41. package/dist/{chunk-VVDJLUYT.mjs → chunk-M7FJYZF6.mjs} +12 -2
  42. package/dist/{chunk-VVDJLUYT.mjs.map → chunk-M7FJYZF6.mjs.map} +1 -1
  43. package/dist/{chunk-DNTGBNZD.mjs → chunk-NDZDJWXY.mjs} +13 -3
  44. package/dist/{chunk-DNTGBNZD.mjs.map → chunk-NDZDJWXY.mjs.map} +1 -1
  45. package/dist/chunk-S2SMCH2C.mjs +71 -0
  46. package/dist/chunk-S2SMCH2C.mjs.map +1 -0
  47. package/dist/{chunk-IDZWA6HG.mjs → chunk-S34CQVTF.mjs} +14 -4
  48. package/dist/{chunk-IDZWA6HG.mjs.map → chunk-S34CQVTF.mjs.map} +1 -1
  49. package/dist/{chunk-2M3YEXYA.mjs → chunk-SUS5RUCA.mjs} +17 -7
  50. package/dist/{chunk-2M3YEXYA.mjs.map → chunk-SUS5RUCA.mjs.map} +1 -1
  51. package/dist/{chunk-3J7KQNEU.mjs → chunk-TCYBXDAP.mjs} +13 -3
  52. package/dist/{chunk-3J7KQNEU.mjs.map → chunk-TCYBXDAP.mjs.map} +1 -1
  53. package/dist/chunk-VII5JNA6.mjs +24 -0
  54. package/dist/{chunk-WTBVFN4H.mjs.map → chunk-VII5JNA6.mjs.map} +1 -1
  55. package/dist/chunk-W3ECDLUB.mjs +24 -0
  56. package/dist/{chunk-OHJIW3I3.mjs.map → chunk-W3ECDLUB.mjs.map} +1 -1
  57. package/dist/{chunk-VBIDPX5Z.mjs → chunk-Y4PAUTZ4.mjs} +13 -3
  58. package/dist/{chunk-VBIDPX5Z.mjs.map → chunk-Y4PAUTZ4.mjs.map} +1 -1
  59. package/dist/{chunk-NAZO4HKB.mjs → chunk-ZSRD3ZXF.mjs} +12 -2
  60. package/dist/{chunk-NAZO4HKB.mjs.map → chunk-ZSRD3ZXF.mjs.map} +1 -1
  61. package/dist/index.mjs +33 -23
  62. package/dist/index.mjs.map +1 -1
  63. package/dist/{liveStatus-YSBYSVOO.mjs → liveStatus-PRDEL7CK.mjs} +16 -6
  64. package/dist/{liveStatus-YSBYSVOO.mjs.map → liveStatus-PRDEL7CK.mjs.map} +1 -1
  65. package/dist/{loginReport-YIVBJVJD.mjs → loginReport-47QNACQU.mjs} +22 -12
  66. package/dist/{loginReport-YIVBJVJD.mjs.map → loginReport-47QNACQU.mjs.map} +1 -1
  67. package/dist/{managementDashboard-7EMQC2UA.mjs → managementDashboard-SZFYULKA.mjs} +22 -12
  68. package/dist/{managementDashboard-7EMQC2UA.mjs.map → managementDashboard-SZFYULKA.mjs.map} +1 -1
  69. package/dist/{qualityAuditDashboard-ENGQN2WQ.mjs → qualityAuditDashboard-FHRGB77R.mjs} +12 -2
  70. package/dist/{qualityAuditDashboard-ENGQN2WQ.mjs.map → qualityAuditDashboard-FHRGB77R.mjs.map} +1 -1
  71. package/dist-react/agentDetailReport-PDKQKJNL.mjs +23 -0
  72. package/dist-react/agentPerformanceReport-MU2FASNN.mjs +544 -0
  73. package/dist-react/agentPerformanceReport-MU2FASNN.mjs.map +1 -0
  74. package/dist-react/auditReport-WH2KDNYT.mjs +25 -0
  75. package/{dist/auditReport-6ZUJ4UFO.mjs.map → dist-react/auditReport-WH2KDNYT.mjs.map} +1 -1
  76. package/dist-react/callHistory-HXXRYUIV.mjs +832 -0
  77. package/dist-react/callHistory-HXXRYUIV.mjs.map +1 -0
  78. package/dist-react/campaigns-J7KIAATE.mjs +3139 -0
  79. package/dist-react/campaigns-J7KIAATE.mjs.map +1 -0
  80. package/dist-react/caroQualityAuditDashboard-THYPVOCP.mjs +76 -0
  81. package/dist-react/caroQualityAuditDashboard-THYPVOCP.mjs.map +1 -0
  82. package/dist-react/caroVoiceAI-XGDUETXI.mjs +31 -0
  83. package/dist-react/caroVoiceAI-XGDUETXI.mjs.map +1 -0
  84. package/dist-react/cdrReport-SX2FZAO6.mjs +858 -0
  85. package/dist-react/cdrReport-SX2FZAO6.mjs.map +1 -0
  86. package/dist-react/chunk-4YF4IDV6.mjs +72 -0
  87. package/dist-react/chunk-4YF4IDV6.mjs.map +1 -0
  88. package/dist-react/chunk-ADM2JJCP.mjs +190 -0
  89. package/dist-react/chunk-ADM2JJCP.mjs.map +1 -0
  90. package/dist-react/chunk-EN7HM2MD.mjs +688 -0
  91. package/dist-react/chunk-EN7HM2MD.mjs.map +1 -0
  92. package/{dist/chunk-LHE4QGJJ.mjs → dist-react/chunk-F7G2XFRU.mjs} +12 -2
  93. package/{dist/chunk-LHE4QGJJ.mjs.map → dist-react/chunk-F7G2XFRU.mjs.map} +1 -1
  94. package/{dist/chunk-DJP744FF.mjs → dist-react/chunk-GUMGXVIT.mjs} +12 -2
  95. package/{dist/chunk-DJP744FF.mjs.map → dist-react/chunk-GUMGXVIT.mjs.map} +1 -1
  96. package/dist-react/chunk-KRXHK4AU.mjs +127 -0
  97. package/dist-react/chunk-KRXHK4AU.mjs.map +1 -0
  98. package/{dist/chunk-U2UDKXMB.mjs → dist-react/chunk-LWDAC6QU.mjs} +12 -2
  99. package/{dist/chunk-U2UDKXMB.mjs.map → dist-react/chunk-LWDAC6QU.mjs.map} +1 -1
  100. package/dist-react/chunk-LX6I32Y4.mjs +106 -0
  101. package/dist-react/chunk-LX6I32Y4.mjs.map +1 -0
  102. package/dist-react/chunk-MCD5FQNY.mjs +428 -0
  103. package/dist-react/chunk-MCD5FQNY.mjs.map +1 -0
  104. package/dist-react/chunk-MD472UKG.mjs +757 -0
  105. package/{dist/chunk-33QNSXP7.mjs.map → dist-react/chunk-MD472UKG.mjs.map} +1 -1
  106. package/dist-react/chunk-ORNNWQI6.mjs +67 -0
  107. package/dist-react/chunk-ORNNWQI6.mjs.map +1 -0
  108. package/dist-react/chunk-S4J35V4B.mjs +126 -0
  109. package/dist-react/chunk-S4J35V4B.mjs.map +1 -0
  110. package/dist-react/chunk-T53WMN5A.mjs +126 -0
  111. package/dist-react/chunk-T53WMN5A.mjs.map +1 -0
  112. package/dist-react/chunk-UTSRABCL.mjs +96 -0
  113. package/dist-react/chunk-UTSRABCL.mjs.map +1 -0
  114. package/dist-react/incoming-4WP3FJI4.mp3 +0 -0
  115. package/dist-react/incoming.mp3 +0 -0
  116. package/dist-react/index.d.mts +2476 -0
  117. package/dist-react/index.d.ts +2477 -0
  118. package/dist-react/index.js +26713 -0
  119. package/dist-react/index.js.map +1 -0
  120. package/dist-react/index.mjs +4675 -0
  121. package/dist-react/index.mjs.map +1 -0
  122. package/dist-react/liveStatus-IDZ7CPYK.mjs +1087 -0
  123. package/dist-react/liveStatus-IDZ7CPYK.mjs.map +1 -0
  124. package/dist-react/loginReport-F47GUU53.mjs +990 -0
  125. package/dist-react/loginReport-F47GUU53.mjs.map +1 -0
  126. package/dist-react/managementDashboard-GC5E7NEL.mjs +540 -0
  127. package/dist-react/managementDashboard-GC5E7NEL.mjs.map +1 -0
  128. package/dist-react/qualityAuditDashboard-ZAM7HRNH.mjs +76 -0
  129. package/dist-react/qualityAuditDashboard-ZAM7HRNH.mjs.map +1 -0
  130. package/package.json +17 -2
  131. package/dist/agentDetailReport-ZR7U2LLB.mjs +0 -17
  132. package/dist/auditReport-6ZUJ4UFO.mjs +0 -16
  133. package/dist/chunk-6WLG2PXL.mjs +0 -14
  134. package/dist/chunk-7LE2VTAI.mjs +0 -14
  135. package/dist/chunk-AOJRUZTO.mjs +0 -14
  136. package/dist/chunk-FRKV2U3I.mjs +0 -14
  137. package/dist/chunk-OHJIW3I3.mjs +0 -14
  138. package/dist/chunk-WTBVFN4H.mjs +0 -14
  139. /package/{dist/agentDetailReport-ZR7U2LLB.mjs.map → dist-react/agentDetailReport-PDKQKJNL.mjs.map} +0 -0
@@ -0,0 +1,3139 @@
1
+ import * as __ext_react from "react";
2
+ import * as __ext_react_dom from "react-dom";
3
+ import * as __ext_react_jsx from "react/jsx-runtime";
4
+ var __cjsExternals = { "react": __ext_react, "react-dom": __ext_react_dom, "react/jsx-runtime": __ext_react_jsx };
5
+ var require = function (id) {
6
+ var mod = __cjsExternals[id];
7
+ if (mod) return mod.default || mod;
8
+ throw new Error('Dynamic require of "' + id + '" is not supported');
9
+ };
10
+
11
+ import {
12
+ useGetCallerData
13
+ } from "./chunk-ORNNWQI6.mjs";
14
+ import {
15
+ SDKPageHeader
16
+ } from "./chunk-T53WMN5A.mjs";
17
+ import {
18
+ getRecordingByCall
19
+ } from "./chunk-GUMGXVIT.mjs";
20
+ import {
21
+ SDKPermissionGuard,
22
+ useSDKPermissions
23
+ } from "./chunk-ADM2JJCP.mjs";
24
+ import {
25
+ DateRangePicker
26
+ } from "./chunk-UTSRABCL.mjs";
27
+ import {
28
+ SDKProvider,
29
+ useToast
30
+ } from "./chunk-4YF4IDV6.mjs";
31
+ import {
32
+ END_POINT,
33
+ SDK_PERMISSIONS,
34
+ axios_default,
35
+ deepFindArray,
36
+ deepFindTotal
37
+ } from "./chunk-F7G2XFRU.mjs";
38
+ import {
39
+ __spreadProps,
40
+ __spreadValues
41
+ } from "./chunk-S4J35V4B.mjs";
42
+
43
+ // call-control-sdk/lib/pages/campaigns/index.tsx
44
+ import { memo, useCallback as useCallback2, useEffect, useRef, useState as useState2 } from "react";
45
+ import {
46
+ Box,
47
+ Chip,
48
+ CircularProgress,
49
+ FormControl,
50
+ FormControlLabel,
51
+ Checkbox,
52
+ IconButton,
53
+ InputAdornment,
54
+ MenuItem,
55
+ OutlinedInput,
56
+ Paper,
57
+ Select,
58
+ Tab,
59
+ Table,
60
+ TableBody,
61
+ TableCell,
62
+ TableContainer,
63
+ TableHead,
64
+ TablePagination,
65
+ TableRow,
66
+ Tabs,
67
+ TextField,
68
+ Tooltip,
69
+ Typography,
70
+ useTheme as useTheme2
71
+ } from "@mui/material";
72
+ import AddIcon from "@mui/icons-material/Add";
73
+ import ArchiveIcon from "@mui/icons-material/Archive";
74
+ import ChevronLeftIcon from "@mui/icons-material/ChevronLeft";
75
+ import ChevronRightIcon from "@mui/icons-material/ChevronRight";
76
+ import DeleteIcon from "@mui/icons-material/Delete";
77
+ import DownloadIcon from "@mui/icons-material/Download";
78
+ import EditIcon from "@mui/icons-material/Edit";
79
+ import PauseIcon from "@mui/icons-material/Pause";
80
+ import PhoneIcon from "@mui/icons-material/Phone";
81
+ import PlayArrowIcon from "@mui/icons-material/PlayArrow";
82
+ import RefreshIcon from "@mui/icons-material/Refresh";
83
+ import SearchIcon from "@mui/icons-material/Search";
84
+ import SettingsIcon from "@mui/icons-material/Settings";
85
+ import UploadFileIcon from "@mui/icons-material/UploadFile";
86
+ import VisibilityOutlinedIcon from "@mui/icons-material/VisibilityOutlined";
87
+
88
+ // call-control-sdk/lib/components/SDKButton.tsx
89
+ import { Button, useTheme } from "@mui/material";
90
+ import { alpha } from "@mui/material/styles";
91
+ import { jsx } from "react/jsx-runtime";
92
+ var muiVariant = {
93
+ primary: "contained",
94
+ danger: "contained",
95
+ cancel: "text",
96
+ outlined: "outlined"
97
+ };
98
+ function SDKButton({
99
+ children,
100
+ variant = "primary",
101
+ onClick,
102
+ startIcon,
103
+ endIcon,
104
+ disabled = false,
105
+ type = "button",
106
+ size = "medium",
107
+ fullWidth = false,
108
+ sx
109
+ }) {
110
+ const theme = useTheme();
111
+ const primary = theme.palette.primary.main;
112
+ const primaryDark = theme.palette.primary.dark;
113
+ const styles = {
114
+ primary: {
115
+ textTransform: "none",
116
+ fontWeight: 600,
117
+ backgroundColor: primary,
118
+ borderRadius: "30px",
119
+ fontSize: "0.82rem",
120
+ px: 2,
121
+ boxShadow: `0 2px 8px ${alpha(primary, 0.25)}`,
122
+ "&:hover": {
123
+ backgroundColor: primaryDark,
124
+ boxShadow: `0 4px 12px ${alpha(primary, 0.35)}`
125
+ },
126
+ "&.Mui-disabled": {
127
+ backgroundColor: alpha(primary, 0.4),
128
+ color: "#fff"
129
+ }
130
+ },
131
+ danger: {
132
+ textTransform: "none",
133
+ fontWeight: 600,
134
+ backgroundColor: "#d32f2f",
135
+ borderRadius: "8px",
136
+ fontSize: "0.82rem",
137
+ px: 2,
138
+ "&:hover": { backgroundColor: "#b71c1c" },
139
+ "&.Mui-disabled": { backgroundColor: "#e57373", color: "#fff" }
140
+ },
141
+ cancel: {
142
+ textTransform: "none",
143
+ fontWeight: 600,
144
+ color: "#666",
145
+ borderRadius: "30px",
146
+ fontSize: "0.82rem",
147
+ px: 2,
148
+ border: "1px solid #d0d0d0",
149
+ "&:hover": { backgroundColor: "#f5f5f5", borderColor: "#bbb" }
150
+ },
151
+ outlined: {
152
+ textTransform: "none",
153
+ fontWeight: 600,
154
+ color: primary,
155
+ borderColor: primary,
156
+ borderRadius: "30px",
157
+ fontSize: "0.82rem",
158
+ px: 2,
159
+ "&:hover": { borderColor: primaryDark, backgroundColor: alpha(primary, 0.05) }
160
+ }
161
+ };
162
+ return /* @__PURE__ */ jsx(
163
+ Button,
164
+ {
165
+ variant: muiVariant[variant],
166
+ onClick,
167
+ startIcon,
168
+ endIcon,
169
+ disabled,
170
+ type,
171
+ size,
172
+ fullWidth,
173
+ sx: [styles[variant], ...Array.isArray(sx) ? sx : [sx]],
174
+ children
175
+ }
176
+ );
177
+ }
178
+
179
+ // call-control-sdk/lib/pages/campaigns/useCampaigns.ts
180
+ import { useState, useCallback } from "react";
181
+ function useCampaigns() {
182
+ const [campaigns, setCampaigns] = useState([]);
183
+ const [loading, setLoading] = useState(false);
184
+ const fetchCampaigns = useCallback(async () => {
185
+ setLoading(true);
186
+ try {
187
+ const res = await axios_default.get(END_POINT.CAMPAIGNS_GET_ALL);
188
+ setCampaigns(Array.isArray(res.data) ? res.data : []);
189
+ } catch (e) {
190
+ setCampaigns([]);
191
+ } finally {
192
+ setLoading(false);
193
+ }
194
+ }, []);
195
+ const getCampaignById = useCallback(async (id) => {
196
+ const res = await axios_default.get(END_POINT.CAMPAIGNS_GET_BY_ID(id));
197
+ return res.data;
198
+ }, []);
199
+ const createCampaign = useCallback(async (data) => {
200
+ const res = await axios_default.post(END_POINT.CAMPAIGNS_CREATE, data);
201
+ return res.data;
202
+ }, []);
203
+ const updateCampaign = useCallback(async (id, data) => {
204
+ const res = await axios_default.put(END_POINT.CAMPAIGNS_UPDATE(id), data);
205
+ return res.data;
206
+ }, []);
207
+ const activateCampaign = useCallback(async (id) => {
208
+ const res = await axios_default.post(END_POINT.CAMPAIGNS_ACTIVATE(id));
209
+ return res.data;
210
+ }, []);
211
+ const pauseCampaign = useCallback(async (id) => {
212
+ const res = await axios_default.post(END_POINT.CAMPAIGNS_PAUSE(id));
213
+ return res.data;
214
+ }, []);
215
+ const archiveCampaign = useCallback(async (id) => {
216
+ const res = await axios_default.post(END_POINT.CAMPAIGNS_ARCHIVE(id));
217
+ return res.data;
218
+ }, []);
219
+ return {
220
+ campaigns,
221
+ loading,
222
+ fetchCampaigns,
223
+ getCampaignById,
224
+ createCampaign,
225
+ updateCampaign,
226
+ activateCampaign,
227
+ pauseCampaign,
228
+ archiveCampaign
229
+ };
230
+ }
231
+ function useLeads() {
232
+ const [leads, setLeads] = useState([]);
233
+ const [leadTotal, setLeadTotal] = useState(0);
234
+ const [leadsMeta, setLeadsMeta] = useState(null);
235
+ const [loading, setLoading] = useState(false);
236
+ const fetchLeads = useCallback(async (campaignId, params, opts) => {
237
+ var _a, _b, _c, _d, _e, _f;
238
+ if (!(opts == null ? void 0 : opts.silent)) setLoading(true);
239
+ try {
240
+ const qs = new URLSearchParams();
241
+ if ((params == null ? void 0 : params.page) != null) qs.append("page", String(params.page));
242
+ if ((params == null ? void 0 : params.pageSize) != null) qs.append("pageSize", String(params.pageSize));
243
+ if (params == null ? void 0 : params.lead_status) qs.append("lead_status", params.lead_status);
244
+ if (params == null ? void 0 : params.search) qs.append("search", params.search);
245
+ if (params == null ? void 0 : params.start_date) qs.append("start_date", params.start_date);
246
+ if (params == null ? void 0 : params.end_date) qs.append("end_date", params.end_date);
247
+ const qsStr = qs.toString();
248
+ const url = `${END_POINT.CAMPAIGNS_LEADS(campaignId)}${qsStr ? `?${qsStr}` : ""}`;
249
+ const res = await axios_default.get(url);
250
+ const body = res.data;
251
+ const fetchedLeads = deepFindArray(body, ["leads"]);
252
+ setLeads(fetchedLeads);
253
+ const foundTotal = deepFindTotal(body);
254
+ setLeadTotal(foundTotal >= 0 ? foundTotal : fetchedLeads.length);
255
+ setLeadsMeta({
256
+ isDialerEnabled: (_b = body == null ? void 0 : body.isDialerEnabled) != null ? _b : (_a = body == null ? void 0 : body.data) == null ? void 0 : _a.isDialerEnabled,
257
+ dialingMode: (_d = body == null ? void 0 : body.dialingMode) != null ? _d : (_c = body == null ? void 0 : body.data) == null ? void 0 : _c.dialingMode,
258
+ campaignStatus: (_f = body == null ? void 0 : body.campaignStatus) != null ? _f : (_e = body == null ? void 0 : body.data) == null ? void 0 : _e.campaignStatus
259
+ });
260
+ } catch (e) {
261
+ setLeads([]);
262
+ setLeadTotal(0);
263
+ setLeadsMeta(null);
264
+ } finally {
265
+ setLoading(false);
266
+ }
267
+ }, []);
268
+ const createLead = useCallback(async (campaignId, data) => {
269
+ const res = await axios_default.post(END_POINT.CAMPAIGNS_LEADS(campaignId), data);
270
+ return res.data;
271
+ }, []);
272
+ const deleteLead = useCallback(async (campaignId, leadId) => {
273
+ await axios_default.delete(END_POINT.CAMPAIGNS_DELETE_LEAD(campaignId, leadId));
274
+ }, []);
275
+ const dialPreview = useCallback(async (campaignId, leadId) => {
276
+ const res = await axios_default.post(END_POINT.CAMPAIGNS_DIAL_PREVIEW(campaignId, leadId));
277
+ return res.data;
278
+ }, []);
279
+ const getLeadCallData = useCallback(async (callUuid) => {
280
+ var _a, _b;
281
+ const res = await axios_default.get(END_POINT.CALL_DATA_BY_CALL(callUuid));
282
+ return (_b = (_a = res.data) == null ? void 0 : _a.data) != null ? _b : res.data;
283
+ }, []);
284
+ const uploadLeadsExcel = useCallback(async (campaignId, file) => {
285
+ const formData = new FormData();
286
+ formData.append("file", file);
287
+ const res = await axios_default.post(END_POINT.CAMPAIGNS_LEADS_UPLOAD_EXCEL(campaignId), formData, {
288
+ headers: { "Content-Type": "multipart/form-data" }
289
+ });
290
+ return res.data;
291
+ }, []);
292
+ const downloadLeadTemplate = useCallback(async (campaignId) => {
293
+ const res = await axios_default.get(END_POINT.CAMPAIGNS_LEADS_TEMPLATE_EXCEL(campaignId), {
294
+ responseType: "blob"
295
+ });
296
+ const blob = res.data;
297
+ const url = window.URL.createObjectURL(blob);
298
+ const a = document.createElement("a");
299
+ a.href = url;
300
+ a.download = "lead_template.xlsx";
301
+ document.body.appendChild(a);
302
+ a.click();
303
+ a.remove();
304
+ window.URL.revokeObjectURL(url);
305
+ }, []);
306
+ const exportLeads = useCallback(async (campaignId) => {
307
+ const res = await axios_default.get(END_POINT.CAMPAIGNS_LEADS_EXPORT_EXCEL(campaignId), {
308
+ responseType: "blob"
309
+ });
310
+ const blob = res.data;
311
+ const url = window.URL.createObjectURL(blob);
312
+ const a = document.createElement("a");
313
+ a.href = url;
314
+ a.download = "leads_export.xlsx";
315
+ document.body.appendChild(a);
316
+ a.click();
317
+ a.remove();
318
+ window.URL.revokeObjectURL(url);
319
+ }, []);
320
+ return {
321
+ leads,
322
+ leadTotal,
323
+ leadsMeta,
324
+ loading,
325
+ fetchLeads,
326
+ createLead,
327
+ deleteLead,
328
+ dialPreview,
329
+ getLeadCallData,
330
+ uploadLeadsExcel,
331
+ downloadLeadTemplate,
332
+ exportLeads
333
+ };
334
+ }
335
+ function useQueues() {
336
+ const [queues, setQueues] = useState([]);
337
+ const [loading, setLoading] = useState(false);
338
+ const fetchQueues = useCallback(async () => {
339
+ var _a;
340
+ setLoading(true);
341
+ try {
342
+ const res = await axios_default.get(END_POINT.QUEUES_GET_ALL);
343
+ const list = Array.isArray(res.data) ? res.data : Array.isArray((_a = res.data) == null ? void 0 : _a.data) ? res.data.data : [];
344
+ setQueues(list);
345
+ return list;
346
+ } catch (e) {
347
+ setQueues([]);
348
+ return [];
349
+ } finally {
350
+ setLoading(false);
351
+ }
352
+ }, []);
353
+ const createQueue = useCallback(async (payload) => {
354
+ var _a, _b;
355
+ const res = await axios_default.post(END_POINT.QUEUES_CREATE, payload);
356
+ return (_b = (_a = res.data) == null ? void 0 : _a.data) != null ? _b : res.data;
357
+ }, []);
358
+ return { queues, loading, fetchQueues, createQueue };
359
+ }
360
+
361
+ // call-control-sdk/lib/pages/campaigns/index.tsx
362
+ import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
363
+ import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
364
+ import ClearIcon from "@mui/icons-material/Clear";
365
+
366
+ // call-control-sdk/lib/pages/campaigns/types.ts
367
+ var CAMPAIGN_TYPES = ["OUTBOUND_CAMPAIGN", "ABANDONED_CALLBACK"];
368
+ var DIALING_MODES_MAP = {
369
+ OUTBOUND_CAMPAIGN: ["PREVIEW", "AI_CALLBACK"],
370
+ ABANDONED_CALLBACK: ["PROGRESSIVE", "PREDICTIVE"]
371
+ };
372
+ var AGENT_TYPES = ["HUMAN", "AI", "HYBRID"];
373
+ var LEAD_PRIORITY_OPTIONS = [
374
+ { label: "HIGH", value: 10 },
375
+ { label: "MEDIUM", value: 5 },
376
+ { label: "LOW", value: 1 }
377
+ ];
378
+ var DAYS_OF_WEEK = [
379
+ { label: "Sun", value: 0 },
380
+ { label: "Mon", value: 1 },
381
+ { label: "Tue", value: 2 },
382
+ { label: "Wed", value: 3 },
383
+ { label: "Thu", value: 4 },
384
+ { label: "Fri", value: 5 },
385
+ { label: "Sat", value: 6 }
386
+ ];
387
+ var LEAD_STATUSES = [
388
+ "All states",
389
+ "PENDING",
390
+ "SCHEDULED",
391
+ "IN_PROGRESS",
392
+ "COMPLETED",
393
+ "FAILED",
394
+ "DO_NOT_CALL",
395
+ "INVALID",
396
+ "CANCELLED"
397
+ ];
398
+ var defaultFormData = {
399
+ name: "",
400
+ description: "",
401
+ campaignType: "OUTBOUND_CAMPAIGN",
402
+ dialingMode: "PREVIEW",
403
+ maxConcurrentCalls: 5,
404
+ callsPerAgent: 1,
405
+ startTime: "09:00",
406
+ endTime: "17:00",
407
+ daysOfWeek: [1, 2, 3, 4, 5],
408
+ timezone: "Asia/Kolkata",
409
+ scheduledStart: "",
410
+ scheduledEnd: "",
411
+ maxAttempts: 1,
412
+ retryIntervalMinutes: 15,
413
+ callerId: "",
414
+ ringTimeoutSeconds: 30,
415
+ answerTimeoutSeconds: 30,
416
+ agentType: "HUMAN",
417
+ aiBotId: null,
418
+ priority: 5,
419
+ settings: {},
420
+ queueLinks: []
421
+ };
422
+
423
+ // call-control-sdk/lib/pages/campaigns/styles.ts
424
+ var labelSx = {
425
+ fontWeight: 600,
426
+ fontSize: "0.85rem",
427
+ color: "#333",
428
+ mb: 0.5
429
+ };
430
+ var sectionTitleSx = {
431
+ fontWeight: 700,
432
+ fontSize: "1rem",
433
+ color: "#1a1a1a",
434
+ mb: 1.5,
435
+ mt: 0.5,
436
+ fontFamily: "poppins, Arial, sans-serif"
437
+ };
438
+ var headCellSx = {
439
+ fontFamily: "poppins, Arial, sans-serif",
440
+ bgcolor: "#f1f1f1",
441
+ color: "#333",
442
+ fontWeight: 600,
443
+ whiteSpace: "nowrap",
444
+ fontSize: "0.8rem",
445
+ py: "6px",
446
+ px: "12px"
447
+ };
448
+ var bodyCellSx = {
449
+ fontFamily: "poppins, Arial, sans-serif",
450
+ fontSize: "0.82rem",
451
+ py: "4px",
452
+ px: "12px"
453
+ };
454
+ var tableRowSx = {
455
+ "&:hover": { backgroundColor: "#f0f7f8" },
456
+ "&:last-child td, &:last-child th": { border: 0 }
457
+ };
458
+ var campaignCardBaseSx = {
459
+ p: 1.5,
460
+ mb: 0.75,
461
+ borderRadius: "12px",
462
+ cursor: "pointer",
463
+ border: "1px solid #e8e8e8",
464
+ backgroundColor: "#fff",
465
+ boxShadow: "0 1px 2px rgba(0,0,0,0.04)",
466
+ transition: "all 0.2s ease"
467
+ };
468
+ var campaignCardSelectedSx = __spreadProps(__spreadValues({}, campaignCardBaseSx), {
469
+ border: "2px solid #1A5F6C",
470
+ backgroundColor: "#f0f7f8",
471
+ boxShadow: "0 2px 8px rgba(26,95,108,0.12)"
472
+ });
473
+ var inputSx = {
474
+ "& .MuiOutlinedInput-root": {
475
+ borderRadius: "8px",
476
+ backgroundColor: "#fff",
477
+ "&:hover fieldset": { borderColor: "#1A5F6C" },
478
+ "&.Mui-focused fieldset": { borderColor: "#1A5F6C" }
479
+ }
480
+ };
481
+ var dialogHeaderSx = {
482
+ px: 2.5,
483
+ py: 1.5,
484
+ borderBottom: "1px solid #eee",
485
+ display: "flex",
486
+ alignItems: "center",
487
+ justifyContent: "space-between"
488
+ };
489
+ var dialogFooterSx = {
490
+ px: 2.5,
491
+ py: 1.5,
492
+ borderTop: "1px solid #eee",
493
+ display: "flex",
494
+ justifyContent: "flex-end",
495
+ gap: 1
496
+ };
497
+ var STATUS_COLORS = {
498
+ draft: "#9e9e9e",
499
+ active: "#4caf50",
500
+ paused: "#ff9800",
501
+ completed: "#2196f3",
502
+ archived: "#795548"
503
+ };
504
+ function statusChipSx(status) {
505
+ var _a;
506
+ const color = (_a = STATUS_COLORS[status == null ? void 0 : status.toLowerCase()]) != null ? _a : "#9e9e9e";
507
+ return {
508
+ height: 22,
509
+ fontSize: "0.68rem",
510
+ fontWeight: 700,
511
+ textTransform: "capitalize",
512
+ borderRadius: "6px",
513
+ backgroundColor: color + "18",
514
+ color,
515
+ border: `1px solid ${color}40`
516
+ };
517
+ }
518
+ function leadStatusChipSx(status) {
519
+ const s = status == null ? void 0 : status.toUpperCase();
520
+ return {
521
+ height: 22,
522
+ fontSize: "0.72rem",
523
+ fontWeight: 700,
524
+ textTransform: "capitalize",
525
+ borderRadius: "6px",
526
+ backgroundColor: s === "COMPLETED" ? "#e8f5e9" : s === "FAILED" ? "#ffebee" : s === "DIALING" ? "#e3f2fd" : "#f5f5f5",
527
+ color: s === "COMPLETED" ? "#2e7d32" : s === "FAILED" ? "#c62828" : s === "DIALING" ? "#1565c0" : "#666"
528
+ };
529
+ }
530
+ function leadPriorityChipSx(priority) {
531
+ const label = priority == null ? "\u2014" : priority >= 8 ? "HIGH" : priority >= 4 ? "MEDIUM" : "LOW";
532
+ return {
533
+ chip: {
534
+ height: 22,
535
+ fontSize: "0.72rem",
536
+ fontWeight: 700,
537
+ borderRadius: "6px",
538
+ backgroundColor: label === "HIGH" ? "#ffebee" : label === "MEDIUM" ? "#e3f2fd" : label === "LOW" ? "#e8f5e9" : "#f5f5f5",
539
+ color: label === "HIGH" ? "#c62828" : label === "MEDIUM" ? "#1565c0" : label === "LOW" ? "#2e7d32" : "#666"
540
+ },
541
+ label
542
+ };
543
+ }
544
+ function daychipSx(selected) {
545
+ return {
546
+ cursor: "pointer",
547
+ backgroundColor: selected ? "#1A5F6C" : "transparent",
548
+ color: selected ? "#fff" : "#333",
549
+ borderColor: "#1A5F6C",
550
+ fontWeight: 500,
551
+ "&:hover": {
552
+ backgroundColor: selected ? "#164e57" : "#E3F2F5"
553
+ }
554
+ };
555
+ }
556
+
557
+ // call-control-sdk/lib/pages/campaigns/index.tsx
558
+ import { Fragment, jsx as jsx2, jsxs } from "react/jsx-runtime";
559
+ function validatePhone(raw) {
560
+ const trimmed = (raw || "").trim();
561
+ if (!trimmed) return "Phone number is required";
562
+ const digits = trimmed.startsWith("+91") ? trimmed.slice(3) : trimmed.startsWith("91") && trimmed.length === 12 ? trimmed.slice(2) : trimmed;
563
+ if (!/^\d{10}$/.test(digits)) return "Must be 10 digits, 91+10, or +91+10";
564
+ return null;
565
+ }
566
+ function campaignToFormData(c) {
567
+ var _a, _b, _c, _d, _e, _f, _g;
568
+ return {
569
+ name: c.name || "",
570
+ description: c.description || "",
571
+ campaignType: (c.campaignType || "OUTBOUND_CAMPAIGN").toUpperCase(),
572
+ dialingMode: (c.dialingMode || "PREVIEW").toUpperCase(),
573
+ maxConcurrentCalls: (_a = c.maxConcurrentCalls) != null ? _a : 5,
574
+ callsPerAgent: (_b = c.callsPerAgent) != null ? _b : 1,
575
+ startTime: c.startTime ? c.startTime.slice(0, 5) : "09:00",
576
+ endTime: c.endTime ? c.endTime.slice(0, 5) : "17:00",
577
+ daysOfWeek: c.daysOfWeek || [1, 2, 3, 4, 5],
578
+ timezone: c.timezone || "Asia/Kolkata",
579
+ scheduledStart: c.scheduledStart || "",
580
+ scheduledEnd: c.scheduledEnd || "",
581
+ maxAttempts: (_c = c.maxAttempts) != null ? _c : 3,
582
+ retryIntervalMinutes: (_d = c.retryIntervalMinutes) != null ? _d : 15,
583
+ callerId: c.callerId || "",
584
+ ringTimeoutSeconds: (_e = c.ringTimeoutSeconds) != null ? _e : 30,
585
+ answerTimeoutSeconds: (_f = c.answerTimeoutSeconds) != null ? _f : 30,
586
+ agentType: c.agentType || "HUMAN",
587
+ aiBotId: null,
588
+ priority: (_g = c.priority) != null ? _g : 5,
589
+ settings: c.settings || {},
590
+ queueLinks: (c.campaignQueues || []).map((q) => {
591
+ var _a2, _b2;
592
+ return {
593
+ queueId: q.queueId,
594
+ priorityOverride: (_a2 = q.priorityOverride) != null ? _a2 : 1,
595
+ minWaitBeforeCallback: (_b2 = q.minWaitBeforeCallback) != null ? _b2 : 0
596
+ };
597
+ })
598
+ };
599
+ }
600
+ function BasicInfoTab({ formData, setFormData, isEditMode }) {
601
+ var _a;
602
+ const handleChange = (field, value) => {
603
+ setFormData((prev) => {
604
+ var _a2;
605
+ const updated = __spreadProps(__spreadValues({}, prev), { [field]: value });
606
+ if (field === "campaignType") {
607
+ updated.dialingMode = ((_a2 = DIALING_MODES_MAP[value]) == null ? void 0 : _a2[0]) || "";
608
+ }
609
+ return updated;
610
+ });
611
+ };
612
+ const mappedModes = DIALING_MODES_MAP[formData.campaignType] || [];
613
+ const availableModes = formData.dialingMode && !mappedModes.includes(formData.dialingMode) ? [formData.dialingMode, ...mappedModes] : mappedModes;
614
+ return /* @__PURE__ */ jsxs(Box, { sx: { p: 2.5 }, children: [
615
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitleSx, children: "Basic Info" }),
616
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "grid", gridTemplateColumns: { xs: "1fr", sm: "1.5fr 1fr", lg: "1.5fr 1fr 1fr" }, gap: 2, mb: 2 }, children: [
617
+ /* @__PURE__ */ jsxs(Box, { children: [
618
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
619
+ "Campaign Name ",
620
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
621
+ ] }),
622
+ /* @__PURE__ */ jsx2(
623
+ TextField,
624
+ {
625
+ fullWidth: true,
626
+ size: "small",
627
+ value: formData.name,
628
+ onChange: (e) => handleChange("name", e.target.value),
629
+ sx: inputSx
630
+ }
631
+ )
632
+ ] }),
633
+ /* @__PURE__ */ jsxs(Box, { children: [
634
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
635
+ "Campaign Type ",
636
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
637
+ ] }),
638
+ /* @__PURE__ */ jsx2(FormControl, { fullWidth: true, size: "small", children: /* @__PURE__ */ jsx2(
639
+ Select,
640
+ {
641
+ value: formData.campaignType,
642
+ onChange: (e) => handleChange("campaignType", e.target.value),
643
+ disabled: isEditMode,
644
+ children: CAMPAIGN_TYPES.map((t) => /* @__PURE__ */ jsx2(MenuItem, { value: t, children: t }, t))
645
+ }
646
+ ) })
647
+ ] })
648
+ ] }),
649
+ /* @__PURE__ */ jsxs(Box, { sx: { mb: 2 }, children: [
650
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Description" }),
651
+ /* @__PURE__ */ jsx2(
652
+ TextField,
653
+ {
654
+ fullWidth: true,
655
+ size: "small",
656
+ multiline: true,
657
+ rows: 3,
658
+ value: formData.description,
659
+ onChange: (e) => handleChange("description", e.target.value),
660
+ sx: inputSx
661
+ }
662
+ )
663
+ ] }),
664
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "grid", gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr", lg: "1fr 1fr 1fr" }, gap: 2 }, children: [
665
+ /* @__PURE__ */ jsxs(Box, { children: [
666
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
667
+ "Dialing Mode ",
668
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
669
+ ] }),
670
+ /* @__PURE__ */ jsx2(FormControl, { fullWidth: true, size: "small", children: /* @__PURE__ */ jsx2(
671
+ Select,
672
+ {
673
+ value: formData.dialingMode,
674
+ onChange: (e) => handleChange("dialingMode", e.target.value),
675
+ children: availableModes.map((m) => /* @__PURE__ */ jsx2(MenuItem, { value: m, children: m }, m))
676
+ }
677
+ ) })
678
+ ] }),
679
+ /* @__PURE__ */ jsxs(Box, { children: [
680
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Priority" }),
681
+ /* @__PURE__ */ jsx2(FormControl, { fullWidth: true, size: "small", children: /* @__PURE__ */ jsx2(
682
+ Select,
683
+ {
684
+ value: (_a = formData.priority) != null ? _a : 5,
685
+ onChange: (e) => handleChange("priority", Number(e.target.value)),
686
+ children: LEAD_PRIORITY_OPTIONS.map((o) => /* @__PURE__ */ jsx2(MenuItem, { value: o.value, children: o.label }, o.label))
687
+ }
688
+ ) })
689
+ ] })
690
+ ] })
691
+ ] });
692
+ }
693
+ function DialingConfigTab({ formData, setFormData }) {
694
+ const handleChange = (field, value) => setFormData((prev) => __spreadProps(__spreadValues({}, prev), { [field]: value }));
695
+ return /* @__PURE__ */ jsxs(Box, { sx: { p: 2.5 }, children: [
696
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitleSx, children: "Dialing Configuration" }),
697
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "grid", gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr", lg: "1fr 1fr 1fr" }, gap: 2 }, children: [
698
+ /* @__PURE__ */ jsxs(Box, { children: [
699
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
700
+ "Max Concurrent Calls ",
701
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
702
+ ] }),
703
+ /* @__PURE__ */ jsx2(
704
+ TextField,
705
+ {
706
+ fullWidth: true,
707
+ size: "small",
708
+ type: "number",
709
+ value: formData.maxConcurrentCalls,
710
+ onChange: (e) => handleChange("maxConcurrentCalls", parseInt(e.target.value) || 1),
711
+ slotProps: { htmlInput: { min: 1 } },
712
+ sx: inputSx
713
+ }
714
+ )
715
+ ] }),
716
+ /* @__PURE__ */ jsxs(Box, { children: [
717
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Calls Per Agent" }),
718
+ /* @__PURE__ */ jsx2(
719
+ TextField,
720
+ {
721
+ fullWidth: true,
722
+ size: "small",
723
+ type: "number",
724
+ value: formData.callsPerAgent,
725
+ onChange: (e) => handleChange("callsPerAgent", parseFloat(e.target.value) || 1),
726
+ slotProps: { htmlInput: { min: 0.1, step: 0.1 } },
727
+ sx: inputSx
728
+ }
729
+ )
730
+ ] }),
731
+ /* @__PURE__ */ jsxs(Box, { children: [
732
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Ring Timeout (sec)" }),
733
+ /* @__PURE__ */ jsx2(
734
+ TextField,
735
+ {
736
+ fullWidth: true,
737
+ size: "small",
738
+ type: "number",
739
+ value: formData.ringTimeoutSeconds,
740
+ onChange: (e) => handleChange("ringTimeoutSeconds", parseInt(e.target.value) || 30),
741
+ slotProps: { htmlInput: { min: 5 } },
742
+ sx: inputSx
743
+ }
744
+ )
745
+ ] }),
746
+ /* @__PURE__ */ jsxs(Box, { children: [
747
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Answer Timeout (sec)" }),
748
+ /* @__PURE__ */ jsx2(
749
+ TextField,
750
+ {
751
+ fullWidth: true,
752
+ size: "small",
753
+ type: "number",
754
+ value: formData.answerTimeoutSeconds,
755
+ onChange: (e) => handleChange("answerTimeoutSeconds", parseInt(e.target.value) || 0),
756
+ slotProps: { htmlInput: { min: 0 } },
757
+ sx: inputSx
758
+ }
759
+ )
760
+ ] }),
761
+ /* @__PURE__ */ jsxs(Box, { children: [
762
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
763
+ "Max Attempts ",
764
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
765
+ ] }),
766
+ /* @__PURE__ */ jsx2(
767
+ TextField,
768
+ {
769
+ fullWidth: true,
770
+ size: "small",
771
+ type: "number",
772
+ value: formData.maxAttempts || "",
773
+ onChange: (e) => handleChange("maxAttempts", parseInt(e.target.value) || 0),
774
+ slotProps: { htmlInput: { min: 1 } },
775
+ sx: inputSx
776
+ }
777
+ )
778
+ ] }),
779
+ /* @__PURE__ */ jsxs(Box, { children: [
780
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Retry Interval (min)" }),
781
+ /* @__PURE__ */ jsx2(
782
+ TextField,
783
+ {
784
+ fullWidth: true,
785
+ size: "small",
786
+ type: "number",
787
+ value: formData.retryIntervalMinutes,
788
+ onChange: (e) => handleChange("retryIntervalMinutes", parseInt(e.target.value) || 5),
789
+ slotProps: { htmlInput: { min: 1 } },
790
+ sx: inputSx
791
+ }
792
+ )
793
+ ] }),
794
+ /* @__PURE__ */ jsxs(Box, { children: [
795
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Agent Type" }),
796
+ /* @__PURE__ */ jsx2(FormControl, { fullWidth: true, size: "small", children: /* @__PURE__ */ jsx2(
797
+ Select,
798
+ {
799
+ value: formData.agentType,
800
+ onChange: (e) => handleChange("agentType", e.target.value),
801
+ children: AGENT_TYPES.map((t) => /* @__PURE__ */ jsx2(MenuItem, { value: t, children: t }, t))
802
+ }
803
+ ) })
804
+ ] })
805
+ ] })
806
+ ] });
807
+ }
808
+ function ScheduleTab({ formData, setFormData }) {
809
+ const handleChange = (field, value) => setFormData((prev) => __spreadProps(__spreadValues({}, prev), { [field]: value }));
810
+ const toggleDay = (day) => setFormData((prev) => __spreadProps(__spreadValues({}, prev), {
811
+ daysOfWeek: prev.daysOfWeek.includes(day) ? prev.daysOfWeek.filter((d) => d !== day) : [...prev.daysOfWeek, day].sort()
812
+ }));
813
+ return /* @__PURE__ */ jsxs(Box, { sx: { p: 2.5 }, children: [
814
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitleSx, children: "Operating Schedule" }),
815
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "grid", gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr", lg: "1fr 1fr 1fr" }, gap: 2, mb: 2 }, children: [
816
+ /* @__PURE__ */ jsxs(Box, { children: [
817
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
818
+ "Start Time ",
819
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
820
+ ] }),
821
+ /* @__PURE__ */ jsx2(
822
+ TextField,
823
+ {
824
+ fullWidth: true,
825
+ size: "small",
826
+ type: "time",
827
+ value: formData.startTime,
828
+ onChange: (e) => handleChange("startTime", e.target.value),
829
+ sx: inputSx
830
+ }
831
+ )
832
+ ] }),
833
+ /* @__PURE__ */ jsxs(Box, { children: [
834
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
835
+ "End Time ",
836
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
837
+ ] }),
838
+ /* @__PURE__ */ jsx2(
839
+ TextField,
840
+ {
841
+ fullWidth: true,
842
+ size: "small",
843
+ type: "time",
844
+ value: formData.endTime,
845
+ onChange: (e) => handleChange("endTime", e.target.value),
846
+ sx: inputSx
847
+ }
848
+ )
849
+ ] })
850
+ ] }),
851
+ /* @__PURE__ */ jsxs(Box, { sx: { mb: 2 }, children: [
852
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Timezone" }),
853
+ /* @__PURE__ */ jsx2(FormControl, { fullWidth: true, size: "small", children: /* @__PURE__ */ jsx2(Select, { value: formData.timezone, onChange: (e) => handleChange("timezone", e.target.value), children: [
854
+ "Etc/UTC",
855
+ "US/Eastern",
856
+ "US/Central",
857
+ "US/Mountain",
858
+ "US/Pacific",
859
+ "Europe/London",
860
+ "Europe/Berlin",
861
+ "Asia/Kolkata",
862
+ "Asia/Tokyo",
863
+ "Australia/Sydney"
864
+ ].map((tz) => /* @__PURE__ */ jsx2(MenuItem, { value: tz, children: tz }, tz)) }) })
865
+ ] }),
866
+ /* @__PURE__ */ jsxs(Box, { children: [
867
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Days of Week" }),
868
+ /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap", mt: 0.5 }, children: DAYS_OF_WEEK.map((day) => /* @__PURE__ */ jsx2(
869
+ Chip,
870
+ {
871
+ label: day.label,
872
+ onClick: () => toggleDay(day.value),
873
+ variant: formData.daysOfWeek.includes(day.value) ? "filled" : "outlined",
874
+ size: "small",
875
+ sx: daychipSx(formData.daysOfWeek.includes(day.value))
876
+ },
877
+ day.value
878
+ )) })
879
+ ] })
880
+ ] });
881
+ }
882
+ function QueueLinkingTab({
883
+ formData,
884
+ setFormData,
885
+ editingCampaign,
886
+ parentQueueNameMap,
887
+ onQueuesRefreshed
888
+ }) {
889
+ const { showToast } = useToast();
890
+ const { fetchQueues, createQueue } = useQueues();
891
+ const queueLinks = formData.queueLinks || [];
892
+ const isEditMode = !!editingCampaign;
893
+ const campaignQueues = (editingCampaign == null ? void 0 : editingCampaign.campaignQueues) || [];
894
+ const [allQueues, setAllQueues] = useState2([]);
895
+ const [queueNames, setQueueNames] = useState2({});
896
+ const [selectedQueueIds, setSelectedQueueIds] = useState2([]);
897
+ const [createOpen, setCreateOpen] = useState2(false);
898
+ const [newQueue, setNewQueue] = useState2({ name: "", description: "" });
899
+ const [creatingQueue, setCreatingQueue] = useState2(false);
900
+ const loadQueues = useCallback2(async () => {
901
+ const list = await fetchQueues();
902
+ setAllQueues(list);
903
+ const map = {};
904
+ list.forEach((q) => {
905
+ map[q.id] = q.name;
906
+ });
907
+ setQueueNames(map);
908
+ onQueuesRefreshed == null ? void 0 : onQueuesRefreshed(list);
909
+ }, [fetchQueues, onQueuesRefreshed]);
910
+ useEffect(() => {
911
+ loadQueues();
912
+ }, [loadQueues]);
913
+ const handleCreateQueue = async () => {
914
+ var _a, _b;
915
+ if (!newQueue.name.trim()) {
916
+ showToast("Queue name is required", "warning");
917
+ return;
918
+ }
919
+ setCreatingQueue(true);
920
+ try {
921
+ await createQueue(newQueue);
922
+ showToast("Queue created successfully", "success");
923
+ setCreateOpen(false);
924
+ setNewQueue({ name: "", description: "" });
925
+ loadQueues();
926
+ } catch (err) {
927
+ showToast(((_b = (_a = err == null ? void 0 : err.response) == null ? void 0 : _a.data) == null ? void 0 : _b.message) || (err == null ? void 0 : err.message) || "Failed to create queue", "error");
928
+ } finally {
929
+ setCreatingQueue(false);
930
+ }
931
+ };
932
+ const linkedIds = new Set(
933
+ isEditMode ? campaignQueues.map((q) => q.queueId) : queueLinks.map((q) => q.queueId)
934
+ );
935
+ const availableQueues = allQueues.filter((q) => !linkedIds.has(q.id));
936
+ const handleAddQueues = () => {
937
+ if (selectedQueueIds.length === 0) return;
938
+ const newLinks = selectedQueueIds.map((qId) => ({
939
+ queueId: qId,
940
+ priorityOverride: 5,
941
+ minWaitBeforeCallback: 0
942
+ }));
943
+ setFormData((prev) => __spreadProps(__spreadValues({}, prev), { queueLinks: [...prev.queueLinks || [], ...newLinks] }));
944
+ showToast(`${selectedQueueIds.length} queue(s) added`, "success");
945
+ setSelectedQueueIds([]);
946
+ };
947
+ const handleRemoveQueue = (queueId) => {
948
+ setFormData((prev) => __spreadProps(__spreadValues({}, prev), {
949
+ queueLinks: (prev.queueLinks || []).filter((q) => q.queueId !== queueId)
950
+ }));
951
+ showToast("Queue removed", "success");
952
+ };
953
+ const handleCellUpdate = (queueId, field, value) => {
954
+ const numVal = parseInt(value) || 0;
955
+ setFormData((prev) => __spreadProps(__spreadValues({}, prev), {
956
+ queueLinks: (prev.queueLinks || []).map(
957
+ (q) => q.queueId === queueId ? __spreadProps(__spreadValues({}, q), { [field]: numVal }) : q
958
+ )
959
+ }));
960
+ };
961
+ return /* @__PURE__ */ jsxs(Box, { sx: { p: 2.5 }, children: [
962
+ createOpen && /* @__PURE__ */ jsx2(
963
+ Box,
964
+ {
965
+ sx: {
966
+ position: "fixed",
967
+ inset: 0,
968
+ zIndex: 1600,
969
+ backgroundColor: "rgba(0,0,0,0.45)",
970
+ display: "flex",
971
+ alignItems: "center",
972
+ justifyContent: "center"
973
+ },
974
+ onClick: (e) => e.stopPropagation(),
975
+ children: /* @__PURE__ */ jsxs(Paper, { elevation: 6, sx: { width: { xs: "90vw", sm: 420 }, borderRadius: "16px", overflow: "hidden", boxShadow: "0 8px 32px rgba(26,95,108,0.18)" }, children: [
976
+ /* @__PURE__ */ jsxs(Box, { sx: __spreadProps(__spreadValues({}, dialogHeaderSx), { backgroundColor: "#1A5F6C", color: "#fff" }), children: [
977
+ /* @__PURE__ */ jsx2(Typography, { fontWeight: 700, fontSize: "1rem", fontFamily: "poppins, Arial, sans-serif", children: "Create New Queue" }),
978
+ /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: () => !creatingQueue && setCreateOpen(false), sx: { color: "#fff" }, children: "\u2715" })
979
+ ] }),
980
+ /* @__PURE__ */ jsxs(Box, { sx: { p: 2.5, display: "flex", flexDirection: "column", gap: 1.5 }, children: [
981
+ /* @__PURE__ */ jsxs(Box, { children: [
982
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
983
+ "Queue Name ",
984
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
985
+ ] }),
986
+ /* @__PURE__ */ jsx2(
987
+ TextField,
988
+ {
989
+ fullWidth: true,
990
+ size: "small",
991
+ value: newQueue.name,
992
+ onChange: (e) => setNewQueue(__spreadProps(__spreadValues({}, newQueue), { name: e.target.value })),
993
+ sx: inputSx
994
+ }
995
+ )
996
+ ] }),
997
+ /* @__PURE__ */ jsxs(Box, { children: [
998
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Description" }),
999
+ /* @__PURE__ */ jsx2(
1000
+ TextField,
1001
+ {
1002
+ fullWidth: true,
1003
+ size: "small",
1004
+ multiline: true,
1005
+ rows: 3,
1006
+ value: newQueue.description,
1007
+ onChange: (e) => setNewQueue(__spreadProps(__spreadValues({}, newQueue), { description: e.target.value })),
1008
+ sx: inputSx
1009
+ }
1010
+ )
1011
+ ] })
1012
+ ] }),
1013
+ /* @__PURE__ */ jsxs(Box, { sx: dialogFooterSx, children: [
1014
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "cancel", onClick: () => setCreateOpen(false), disabled: creatingQueue, children: "Cancel" }),
1015
+ /* @__PURE__ */ jsx2(
1016
+ SDKButton,
1017
+ {
1018
+ onClick: handleCreateQueue,
1019
+ disabled: creatingQueue,
1020
+ startIcon: creatingQueue ? /* @__PURE__ */ jsx2(CircularProgress, { size: 14, color: "inherit" }) : void 0,
1021
+ children: "Create"
1022
+ }
1023
+ )
1024
+ ] })
1025
+ ] })
1026
+ }
1027
+ ),
1028
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2 }, children: [
1029
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitleSx, children: "Linked Queues" }),
1030
+ /* @__PURE__ */ jsx2(SDKButton, { startIcon: /* @__PURE__ */ jsx2(AddIcon, {}), onClick: () => setCreateOpen(true), children: "Create New Queue" })
1031
+ ] }),
1032
+ /* @__PURE__ */ jsxs(Box, { sx: {
1033
+ display: "flex",
1034
+ alignItems: { xs: "stretch", sm: "center" },
1035
+ flexDirection: { xs: "column", sm: "row" },
1036
+ gap: 1.5,
1037
+ mb: 2
1038
+ }, children: [
1039
+ /* @__PURE__ */ jsx2(FormControl, { size: "small", sx: { flex: 2 }, children: /* @__PURE__ */ jsx2(
1040
+ Select,
1041
+ {
1042
+ multiple: true,
1043
+ value: selectedQueueIds,
1044
+ onChange: (e) => setSelectedQueueIds(e.target.value),
1045
+ displayEmpty: true,
1046
+ renderValue: (selected) => selected.length === 0 ? /* @__PURE__ */ jsx2(Typography, { sx: { color: "#999", fontSize: "0.85rem" }, children: "Select queues to link" }) : /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", flexWrap: "wrap", gap: 0.5 }, children: selected.map((id) => /* @__PURE__ */ jsx2(
1047
+ Chip,
1048
+ {
1049
+ size: "small",
1050
+ label: queueNames[id] || parentQueueNameMap[id] || `Queue #${id}`,
1051
+ sx: { height: 22, fontSize: "0.75rem", fontWeight: 600, backgroundColor: "#e0f2f1", color: "#00695c" }
1052
+ },
1053
+ id
1054
+ )) }),
1055
+ sx: {
1056
+ borderRadius: "8px",
1057
+ fontSize: "0.85rem",
1058
+ "& .MuiSelect-select": { display: "flex", flexWrap: "wrap", gap: 0.5, py: 0.75 }
1059
+ },
1060
+ MenuProps: {
1061
+ PaperProps: { sx: { maxHeight: 250, borderRadius: "8px", mt: 0.5, boxShadow: "0 4px 20px rgba(0,0,0,0.12)" } }
1062
+ },
1063
+ children: availableQueues.length === 0 ? /* @__PURE__ */ jsx2(MenuItem, { value: "", disabled: true, children: "No available queues" }) : availableQueues.map((q) => /* @__PURE__ */ jsxs(MenuItem, { value: q.id, sx: { py: 0.75, px: 1.5, fontSize: "0.85rem" }, children: [
1064
+ /* @__PURE__ */ jsx2(
1065
+ Checkbox,
1066
+ {
1067
+ size: "small",
1068
+ checked: selectedQueueIds.includes(q.id),
1069
+ sx: { p: 0.5, mr: 1, color: "#1A5F6C", "&.Mui-checked": { color: "#1A5F6C" } }
1070
+ }
1071
+ ),
1072
+ q.name,
1073
+ " (ID: ",
1074
+ q.id,
1075
+ ")"
1076
+ ] }, q.id))
1077
+ }
1078
+ ) }),
1079
+ /* @__PURE__ */ jsx2(SDKButton, { onClick: handleAddQueues, disabled: selectedQueueIds.length === 0, sx: { whiteSpace: "nowrap" }, children: "Add To List" })
1080
+ ] }),
1081
+ queueLinks.length === 0 ? /* @__PURE__ */ jsx2(Paper, { variant: "outlined", sx: { p: 3, textAlign: "center", borderRadius: 2, borderStyle: "dashed" }, children: /* @__PURE__ */ jsx2(Typography, { sx: { color: "#999", fontSize: "0.9rem" }, children: "No queues linked yet. Select queues above to add." }) }) : /* @__PURE__ */ jsx2(TableContainer, { component: Paper, variant: "outlined", sx: { borderRadius: 2, overflow: "visible" }, children: /* @__PURE__ */ jsxs(Table, { size: "small", children: [
1082
+ /* @__PURE__ */ jsx2(TableHead, { children: /* @__PURE__ */ jsxs(TableRow, { sx: { backgroundColor: "#f1f1f1" }, children: [
1083
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Queue Name" }),
1084
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Priority Override" }),
1085
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Min Wait Before Callback" }),
1086
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, headCellSx), { textAlign: "right" }), children: "Action" })
1087
+ ] }) }),
1088
+ /* @__PURE__ */ jsx2(TableBody, { children: queueLinks.map((q) => {
1089
+ var _a;
1090
+ return /* @__PURE__ */ jsxs(TableRow, { sx: tableRowSx, children: [
1091
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: queueNames[q.queueId] || parentQueueNameMap[q.queueId] || `Queue #${q.queueId}` }),
1092
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: /* @__PURE__ */ jsx2(FormControl, { size: "small", sx: { width: 120 }, children: /* @__PURE__ */ jsx2(
1093
+ Select,
1094
+ {
1095
+ value: (_a = q.priorityOverride) != null ? _a : 5,
1096
+ onChange: (e) => handleCellUpdate(q.queueId, "priorityOverride", String(e.target.value)),
1097
+ children: LEAD_PRIORITY_OPTIONS.map((opt) => /* @__PURE__ */ jsx2(MenuItem, { value: opt.value, children: opt.label }, opt.label))
1098
+ }
1099
+ ) }) }),
1100
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: /* @__PURE__ */ jsx2(
1101
+ TextField,
1102
+ {
1103
+ size: "small",
1104
+ type: "number",
1105
+ value: q.minWaitBeforeCallback,
1106
+ onChange: (e) => handleCellUpdate(q.queueId, "minWaitBeforeCallback", e.target.value),
1107
+ slotProps: {
1108
+ htmlInput: { min: 0, style: { fontSize: "0.85rem", padding: "4px 8px" } },
1109
+ input: {
1110
+ endAdornment: /* @__PURE__ */ jsx2(InputAdornment, { position: "end", children: /* @__PURE__ */ jsx2(Typography, { sx: { fontSize: "0.75rem", color: "#666" }, children: "s" }) })
1111
+ }
1112
+ },
1113
+ sx: { width: 100, "& .MuiOutlinedInput-root": { borderRadius: "4px" } }
1114
+ }
1115
+ ) }),
1116
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { textAlign: "right" }), children: /* @__PURE__ */ jsx2(SDKButton, { variant: "danger", size: "small", onClick: () => handleRemoveQueue(q.queueId), children: "Remove" }) })
1117
+ ] }, q.queueId);
1118
+ }) })
1119
+ ] }) })
1120
+ ] });
1121
+ }
1122
+ function LeadsTabInDialog({
1123
+ editingCampaign,
1124
+ onLeadsChange
1125
+ }) {
1126
+ var _a;
1127
+ const { showToast } = useToast();
1128
+ const showVoicemail = (editingCampaign == null ? void 0 : editingCampaign.campaignType) === "AFTER_HOURS_CALLBACK";
1129
+ const { leads, fetchLeads, createLead, uploadLeadsExcel, downloadLeadTemplate } = useLeads();
1130
+ const [adding, setAdding] = useState2(false);
1131
+ const [leadForm, setLeadForm] = useState2({ phoneNumber: "", callerName: "", priority: 5 });
1132
+ const [search, setSearch] = useState2("");
1133
+ const [uploadFile, setUploadFile] = useState2(null);
1134
+ const [uploading, setUploading] = useState2(false);
1135
+ const uploadRef = useRef(null);
1136
+ useEffect(() => {
1137
+ if (editingCampaign) fetchLeads(editingCampaign.id, { page: 1, pageSize: 100 });
1138
+ }, [editingCampaign, fetchLeads]);
1139
+ if (!editingCampaign) {
1140
+ return /* @__PURE__ */ jsx2(Box, { sx: { p: 4, textAlign: "center" }, children: /* @__PURE__ */ jsx2(Typography, { sx: { color: "#999", fontSize: "0.9rem", fontFamily: "poppins, Arial, sans-serif" }, children: "Save the campaign first, then you can add leads." }) });
1141
+ }
1142
+ const handleAddLead = async () => {
1143
+ var _a2, _b, _c;
1144
+ const err = validatePhone(leadForm.phoneNumber);
1145
+ if (err) {
1146
+ showToast(err, "warning");
1147
+ return;
1148
+ }
1149
+ setAdding(true);
1150
+ try {
1151
+ await createLead(editingCampaign.id, __spreadProps(__spreadValues({}, leadForm), { priority: (_a2 = leadForm.priority) != null ? _a2 : 5 }));
1152
+ showToast("Lead added successfully", "success");
1153
+ setLeadForm({ phoneNumber: "", callerName: "", priority: 5 });
1154
+ fetchLeads(editingCampaign.id, { page: 1, pageSize: 100 });
1155
+ onLeadsChange == null ? void 0 : onLeadsChange();
1156
+ } catch (err2) {
1157
+ showToast(((_c = (_b = err2 == null ? void 0 : err2.response) == null ? void 0 : _b.data) == null ? void 0 : _c.message) || (err2 == null ? void 0 : err2.message) || "Failed to add lead", "error");
1158
+ } finally {
1159
+ setAdding(false);
1160
+ }
1161
+ };
1162
+ const handleUpload = async () => {
1163
+ var _a2, _b;
1164
+ if (!uploadFile) return;
1165
+ setUploading(true);
1166
+ try {
1167
+ await uploadLeadsExcel(editingCampaign.id, uploadFile);
1168
+ showToast("Leads uploaded successfully", "success");
1169
+ setUploadFile(null);
1170
+ if (uploadRef.current) uploadRef.current.value = "";
1171
+ fetchLeads(editingCampaign.id, { page: 1, pageSize: 100 });
1172
+ onLeadsChange == null ? void 0 : onLeadsChange();
1173
+ } catch (err) {
1174
+ showToast(((_b = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b.message) || (err == null ? void 0 : err.message) || "Failed to upload leads", "error");
1175
+ } finally {
1176
+ setUploading(false);
1177
+ }
1178
+ };
1179
+ const handleDownload = async () => {
1180
+ var _a2, _b;
1181
+ try {
1182
+ await downloadLeadTemplate(editingCampaign.id);
1183
+ } catch (err) {
1184
+ showToast(((_b = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b.message) || (err == null ? void 0 : err.message) || "Download failed", "error");
1185
+ }
1186
+ };
1187
+ const filtered = leads.filter(
1188
+ (l) => {
1189
+ var _a2, _b;
1190
+ return !search || ((_a2 = l.callerName) == null ? void 0 : _a2.toLowerCase().includes(search.toLowerCase())) || ((_b = l.phoneNumber) == null ? void 0 : _b.includes(search));
1191
+ }
1192
+ );
1193
+ return /* @__PURE__ */ jsxs(Box, { sx: { p: 2.5 }, children: [
1194
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitleSx, children: "Add Lead Manually" }),
1195
+ /* @__PURE__ */ jsxs(Paper, { variant: "outlined", sx: { p: 2, mb: 2.5, borderRadius: 2 }, children: [
1196
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "grid", gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr", lg: "1fr 1fr 1fr" }, gap: 2, mb: 2 }, children: [
1197
+ /* @__PURE__ */ jsxs(Box, { children: [
1198
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
1199
+ "Phone Number ",
1200
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
1201
+ ] }),
1202
+ /* @__PURE__ */ jsx2(
1203
+ TextField,
1204
+ {
1205
+ fullWidth: true,
1206
+ size: "small",
1207
+ placeholder: "+1234567890",
1208
+ value: leadForm.phoneNumber,
1209
+ onChange: (e) => setLeadForm((p) => __spreadProps(__spreadValues({}, p), { phoneNumber: e.target.value.replace(/[^0-9+\-() ]/g, "") })),
1210
+ error: !!leadForm.phoneNumber && !!validatePhone(leadForm.phoneNumber),
1211
+ helperText: leadForm.phoneNumber ? validatePhone(leadForm.phoneNumber) || "" : "",
1212
+ sx: inputSx
1213
+ }
1214
+ )
1215
+ ] }),
1216
+ /* @__PURE__ */ jsxs(Box, { children: [
1217
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Caller Name" }),
1218
+ /* @__PURE__ */ jsx2(
1219
+ TextField,
1220
+ {
1221
+ fullWidth: true,
1222
+ size: "small",
1223
+ value: leadForm.callerName || "",
1224
+ onChange: (e) => setLeadForm((p) => __spreadProps(__spreadValues({}, p), { callerName: e.target.value })),
1225
+ sx: inputSx
1226
+ }
1227
+ )
1228
+ ] }),
1229
+ /* @__PURE__ */ jsxs(Box, { children: [
1230
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Source" }),
1231
+ /* @__PURE__ */ jsx2(
1232
+ TextField,
1233
+ {
1234
+ fullWidth: true,
1235
+ size: "small",
1236
+ value: leadForm.source || "",
1237
+ onChange: (e) => setLeadForm((p) => __spreadProps(__spreadValues({}, p), { source: e.target.value })),
1238
+ sx: inputSx
1239
+ }
1240
+ )
1241
+ ] }),
1242
+ /* @__PURE__ */ jsxs(Box, { children: [
1243
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Priority" }),
1244
+ /* @__PURE__ */ jsx2(FormControl, { fullWidth: true, size: "small", children: /* @__PURE__ */ jsx2(
1245
+ Select,
1246
+ {
1247
+ value: (_a = leadForm.priority) != null ? _a : 5,
1248
+ onChange: (e) => setLeadForm((p) => __spreadProps(__spreadValues({}, p), { priority: Number(e.target.value) })),
1249
+ children: LEAD_PRIORITY_OPTIONS.map((opt) => /* @__PURE__ */ jsx2(MenuItem, { value: opt.value, children: opt.label }, opt.label))
1250
+ }
1251
+ ) })
1252
+ ] }),
1253
+ /* @__PURE__ */ jsxs(Box, { sx: { gridColumn: "1 / -1" }, children: [
1254
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Notes" }),
1255
+ /* @__PURE__ */ jsx2(
1256
+ TextField,
1257
+ {
1258
+ fullWidth: true,
1259
+ size: "small",
1260
+ multiline: true,
1261
+ minRows: 2,
1262
+ maxRows: 8,
1263
+ value: leadForm.notes || "",
1264
+ onChange: (e) => setLeadForm((p) => __spreadProps(__spreadValues({}, p), { notes: e.target.value })),
1265
+ sx: inputSx
1266
+ }
1267
+ )
1268
+ ] })
1269
+ ] }),
1270
+ /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", justifyContent: "flex-end" }, children: /* @__PURE__ */ jsx2(
1271
+ SDKButton,
1272
+ {
1273
+ onClick: handleAddLead,
1274
+ disabled: adding,
1275
+ startIcon: adding ? /* @__PURE__ */ jsx2(CircularProgress, { size: 14, color: "inherit" }) : void 0,
1276
+ children: "Add Lead"
1277
+ }
1278
+ ) })
1279
+ ] }),
1280
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitleSx, children: "Upload Leads from File" }),
1281
+ /* @__PURE__ */ jsxs(Paper, { variant: "outlined", sx: { p: 2, mb: 2.5, borderRadius: 2 }, children: [
1282
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1.5, flexWrap: "wrap" }, children: [
1283
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "outlined", startIcon: /* @__PURE__ */ jsx2(UploadFileIcon, {}), onClick: () => {
1284
+ var _a2;
1285
+ return (_a2 = uploadRef.current) == null ? void 0 : _a2.click();
1286
+ }, children: "Choose File" }),
1287
+ /* @__PURE__ */ jsx2(
1288
+ "input",
1289
+ {
1290
+ ref: uploadRef,
1291
+ type: "file",
1292
+ accept: ".csv,.xlsx,.xls",
1293
+ hidden: true,
1294
+ onChange: (e) => {
1295
+ var _a2;
1296
+ const f = (_a2 = e.target.files) == null ? void 0 : _a2[0];
1297
+ if (!f) return;
1298
+ if (![".csv", ".xlsx", ".xls"].some((ext) => f.name.toLowerCase().endsWith(ext))) {
1299
+ showToast("Please select a CSV or Excel file", "warning");
1300
+ return;
1301
+ }
1302
+ setUploadFile(f);
1303
+ }
1304
+ }
1305
+ ),
1306
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontSize: "0.82rem", color: "#666", flex: 1, fontFamily: "poppins, Arial, sans-serif" }, children: uploadFile ? uploadFile.name : "No file chosen" }),
1307
+ uploadFile && /* @__PURE__ */ jsx2(
1308
+ SDKButton,
1309
+ {
1310
+ variant: "cancel",
1311
+ size: "small",
1312
+ onClick: () => {
1313
+ setUploadFile(null);
1314
+ if (uploadRef.current) uploadRef.current.value = "";
1315
+ },
1316
+ children: "Clear"
1317
+ }
1318
+ ),
1319
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "outlined", startIcon: /* @__PURE__ */ jsx2(DownloadIcon, {}), onClick: handleDownload, children: "Sample Template" })
1320
+ ] }),
1321
+ /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", justifyContent: "flex-end", mt: 1.5 }, children: /* @__PURE__ */ jsx2(
1322
+ SDKButton,
1323
+ {
1324
+ onClick: handleUpload,
1325
+ disabled: uploading || !uploadFile,
1326
+ startIcon: uploading ? /* @__PURE__ */ jsx2(CircularProgress, { size: 14, color: "inherit" }) : void 0,
1327
+ children: "Upload"
1328
+ }
1329
+ ) })
1330
+ ] }),
1331
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 1.5 }, children: [
1332
+ /* @__PURE__ */ jsxs(Typography, { sx: sectionTitleSx, children: [
1333
+ "Leads (",
1334
+ leads.length,
1335
+ ")"
1336
+ ] }),
1337
+ /* @__PURE__ */ jsx2(
1338
+ OutlinedInput,
1339
+ {
1340
+ size: "small",
1341
+ value: search,
1342
+ onChange: (e) => setSearch(e.target.value),
1343
+ placeholder: "Search...",
1344
+ sx: { width: 200, fontSize: "0.85rem", height: 34, borderRadius: "20px" },
1345
+ startAdornment: /* @__PURE__ */ jsx2(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx2(SearchIcon, { sx: { fontSize: 16, color: "#aaa" } }) })
1346
+ }
1347
+ )
1348
+ ] }),
1349
+ filtered.length === 0 ? /* @__PURE__ */ jsx2(Paper, { variant: "outlined", sx: { p: 3, textAlign: "center", borderRadius: 2, borderStyle: "dashed" }, children: /* @__PURE__ */ jsx2(Typography, { sx: { color: "#999", fontSize: "0.9rem" }, children: leads.length === 0 ? "No leads yet." : "No leads match your search." }) }) : /* @__PURE__ */ jsx2(TableContainer, { component: Paper, variant: "outlined", sx: { borderRadius: 2, overflow: "visible" }, children: /* @__PURE__ */ jsxs(Table, { size: "small", children: [
1350
+ /* @__PURE__ */ jsx2(TableHead, { children: /* @__PURE__ */ jsxs(TableRow, { sx: { backgroundColor: "#f1f1f1" }, children: [
1351
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Phone Number" }),
1352
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Status" }),
1353
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Source" }),
1354
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Attempts" }),
1355
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Last Outcome" }),
1356
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Notes" }),
1357
+ /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Outcome" }),
1358
+ showVoicemail && /* @__PURE__ */ jsx2(TableCell, { sx: headCellSx, children: "Voice Mail" })
1359
+ ] }) }),
1360
+ /* @__PURE__ */ jsx2(TableBody, { children: filtered.map((lead) => {
1361
+ var _a2;
1362
+ return /* @__PURE__ */ jsxs(TableRow, { sx: tableRowSx, children: [
1363
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.phoneNumber }),
1364
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: /* @__PURE__ */ jsx2(Chip, { label: lead.status || "pending", size: "small", sx: leadStatusChipSx(lead.status) }) }),
1365
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.source || "" }),
1366
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: (_a2 = lead.attemptCount) != null ? _a2 : 0 }),
1367
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.lastOutcome || "" }),
1368
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { maxWidth: 200, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }), children: lead.notes ? /* @__PURE__ */ jsx2(Tooltip, { title: lead.notes, arrow: true, placement: "top", children: /* @__PURE__ */ jsx2("span", { children: lead.notes }) }) : "" }),
1369
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.lastReason || "" }),
1370
+ showVoicemail && /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { minWidth: 180 }), children: lead.originalCallId ? /* @__PURE__ */ jsx2(CallRecording, { callUuid: lead.originalCallId, recordingPath: lead.voicemail, iconOnly: true }) : "" })
1371
+ ] }, lead.id);
1372
+ }) })
1373
+ ] }) })
1374
+ ] });
1375
+ }
1376
+ var CampaignDialog = memo(function CampaignDialog2({
1377
+ open,
1378
+ editingCampaign,
1379
+ formData,
1380
+ setFormData,
1381
+ saving,
1382
+ onSave,
1383
+ onClose,
1384
+ parentQueueNameMap,
1385
+ onQueuesRefreshed,
1386
+ onLeadsChange
1387
+ }) {
1388
+ const { showToast } = useToast();
1389
+ const [tab, setTab] = useState2(0);
1390
+ useEffect(() => {
1391
+ if (open) setTab(0);
1392
+ }, [open]);
1393
+ if (!open) return null;
1394
+ const TAB_LABELS = ["Basic Info", "Dialing Configuration", "Schedule & Operating Hours", "Queue Linking", "Leads"];
1395
+ const lastSaveTab = 3;
1396
+ const leadsTabDisabled = !editingCampaign;
1397
+ const isDirty = !editingCampaign || JSON.stringify(formData) !== JSON.stringify(campaignToFormData(editingCampaign));
1398
+ const validateTab = (t) => {
1399
+ if (t === 0) {
1400
+ if (!formData.name.trim()) {
1401
+ showToast("Please fill Campaign Name", "warning");
1402
+ return false;
1403
+ }
1404
+ if (!formData.campaignType) {
1405
+ showToast("Please fill Campaign Type", "warning");
1406
+ return false;
1407
+ }
1408
+ if (!formData.dialingMode) {
1409
+ showToast("Please fill Dialing Mode", "warning");
1410
+ return false;
1411
+ }
1412
+ }
1413
+ if (t === 1) {
1414
+ if (!formData.maxConcurrentCalls) {
1415
+ showToast("Please fill Max Concurrent Calls", "warning");
1416
+ return false;
1417
+ }
1418
+ if (!formData.maxAttempts) {
1419
+ showToast("Please fill Max Attempts", "warning");
1420
+ return false;
1421
+ }
1422
+ }
1423
+ if (t === 2) {
1424
+ if (!formData.startTime) {
1425
+ showToast("Please fill Start Time", "warning");
1426
+ return false;
1427
+ }
1428
+ if (!formData.endTime) {
1429
+ showToast("Please fill End Time", "warning");
1430
+ return false;
1431
+ }
1432
+ }
1433
+ return true;
1434
+ };
1435
+ const handleTabChange = (newTab) => {
1436
+ if (newTab === 4 && leadsTabDisabled) return;
1437
+ if (newTab > tab && !validateTab(tab)) return;
1438
+ setTab(newTab);
1439
+ };
1440
+ return /* @__PURE__ */ jsx2(
1441
+ Box,
1442
+ {
1443
+ sx: {
1444
+ position: "fixed",
1445
+ inset: 0,
1446
+ zIndex: 1300,
1447
+ backgroundColor: "rgba(0,0,0,0.45)",
1448
+ display: "flex",
1449
+ alignItems: "center",
1450
+ justifyContent: "center"
1451
+ },
1452
+ onClick: (e) => e.stopPropagation(),
1453
+ children: /* @__PURE__ */ jsxs(
1454
+ Paper,
1455
+ {
1456
+ elevation: 6,
1457
+ sx: {
1458
+ width: { xs: "95vw", sm: 720, md: 880 },
1459
+ maxHeight: "92vh",
1460
+ display: "flex",
1461
+ flexDirection: "column",
1462
+ borderRadius: "16px",
1463
+ overflow: "hidden",
1464
+ boxShadow: "0 8px 32px rgba(26,95,108,0.18)"
1465
+ },
1466
+ children: [
1467
+ /* @__PURE__ */ jsxs(Box, { sx: __spreadProps(__spreadValues({}, dialogHeaderSx), {
1468
+ backgroundColor: "#1A5F6C",
1469
+ color: "#fff",
1470
+ "& .MuiIconButton-root": { color: "#fff" }
1471
+ }), children: [
1472
+ /* @__PURE__ */ jsx2(Typography, { fontWeight: 700, fontSize: "1rem", fontFamily: "poppins, Arial, sans-serif", children: editingCampaign ? "Edit Campaign" : "Create Campaign" }),
1473
+ /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: onClose, sx: { color: "#fff" }, children: "\u2715" })
1474
+ ] }),
1475
+ /* @__PURE__ */ jsx2(
1476
+ Tabs,
1477
+ {
1478
+ value: tab,
1479
+ onChange: (_, v) => handleTabChange(v),
1480
+ variant: "scrollable",
1481
+ scrollButtons: "auto",
1482
+ sx: {
1483
+ borderBottom: "1px solid #eee",
1484
+ minHeight: 44,
1485
+ "& .MuiTab-root": {
1486
+ fontSize: "0.85rem",
1487
+ minHeight: 44,
1488
+ textTransform: "none",
1489
+ fontWeight: 600,
1490
+ fontFamily: "poppins, Arial, sans-serif"
1491
+ },
1492
+ "& .Mui-selected": { color: "#1A5F6C" }
1493
+ },
1494
+ TabIndicatorProps: { style: { height: 3, backgroundColor: "#1A5F6C", borderRadius: "3px 3px 0 0" } },
1495
+ children: TAB_LABELS.map((label, i) => /* @__PURE__ */ jsx2(Tab, { label, value: i, disabled: i === 4 && leadsTabDisabled }, label))
1496
+ }
1497
+ ),
1498
+ /* @__PURE__ */ jsxs(Box, { sx: { flex: 1, overflowY: "auto", minHeight: 380 }, children: [
1499
+ tab === 0 && /* @__PURE__ */ jsx2(BasicInfoTab, { formData, setFormData, isEditMode: !!editingCampaign }),
1500
+ tab === 1 && /* @__PURE__ */ jsx2(DialingConfigTab, { formData, setFormData }),
1501
+ tab === 2 && /* @__PURE__ */ jsx2(ScheduleTab, { formData, setFormData }),
1502
+ tab === 3 && /* @__PURE__ */ jsx2(
1503
+ QueueLinkingTab,
1504
+ {
1505
+ formData,
1506
+ setFormData,
1507
+ editingCampaign,
1508
+ parentQueueNameMap,
1509
+ onQueuesRefreshed
1510
+ }
1511
+ ),
1512
+ tab === 4 && /* @__PURE__ */ jsx2(
1513
+ LeadsTabInDialog,
1514
+ {
1515
+ editingCampaign,
1516
+ onLeadsChange
1517
+ }
1518
+ )
1519
+ ] }),
1520
+ /* @__PURE__ */ jsxs(Box, { sx: dialogFooterSx, children: [
1521
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "cancel", onClick: onClose, children: "Cancel" }),
1522
+ tab > 0 && /* @__PURE__ */ jsx2(SDKButton, { variant: "outlined", onClick: () => setTab((t) => t - 1), children: "Back" }),
1523
+ tab < lastSaveTab && /* @__PURE__ */ jsx2(SDKButton, { onClick: () => handleTabChange(tab + 1), children: "Next" }),
1524
+ tab === lastSaveTab && /* @__PURE__ */ jsx2(
1525
+ SDKPermissionGuard,
1526
+ {
1527
+ permissions: [
1528
+ editingCampaign ? SDK_PERMISSIONS.CAMPAIGNS_UPDATE : SDK_PERMISSIONS.CAMPAIGNS_CREATE,
1529
+ SDK_PERMISSIONS.CAMPAIGNS_MANAGE
1530
+ ],
1531
+ showFallback: false,
1532
+ children: /* @__PURE__ */ jsx2(
1533
+ SDKButton,
1534
+ {
1535
+ onClick: onSave,
1536
+ disabled: saving || !isDirty,
1537
+ startIcon: saving ? /* @__PURE__ */ jsx2(CircularProgress, { size: 14, color: "inherit" }) : void 0,
1538
+ children: editingCampaign ? "Update" : "Create"
1539
+ }
1540
+ )
1541
+ }
1542
+ )
1543
+ ] })
1544
+ ]
1545
+ }
1546
+ )
1547
+ }
1548
+ );
1549
+ });
1550
+ var AddLeadDialog = memo(function AddLeadDialog2({
1551
+ open,
1552
+ data,
1553
+ onChange,
1554
+ saving,
1555
+ onSave,
1556
+ onClose
1557
+ }) {
1558
+ var _a;
1559
+ if (!open) return null;
1560
+ const phoneError = data.phoneNumber ? validatePhone(data.phoneNumber) : null;
1561
+ return /* @__PURE__ */ jsx2(
1562
+ Box,
1563
+ {
1564
+ sx: {
1565
+ position: "fixed",
1566
+ inset: 0,
1567
+ zIndex: 1400,
1568
+ backgroundColor: "rgba(0,0,0,0.45)",
1569
+ display: "flex",
1570
+ alignItems: "center",
1571
+ justifyContent: "center"
1572
+ },
1573
+ onClick: (e) => e.stopPropagation(),
1574
+ children: /* @__PURE__ */ jsxs(Paper, { elevation: 6, sx: { width: { xs: "95vw", sm: 560, lg: 720 }, borderRadius: "16px", overflow: "hidden", boxShadow: "0 8px 32px rgba(26,95,108,0.18)" }, children: [
1575
+ /* @__PURE__ */ jsxs(Box, { sx: __spreadProps(__spreadValues({}, dialogHeaderSx), { backgroundColor: "#1A5F6C", color: "#fff" }), children: [
1576
+ /* @__PURE__ */ jsx2(Typography, { fontWeight: 700, fontSize: "1rem", fontFamily: "poppins, Arial, sans-serif", children: "Add Lead" }),
1577
+ /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: onClose, sx: { color: "#fff" }, children: "\u2715" })
1578
+ ] }),
1579
+ /* @__PURE__ */ jsx2(Box, { sx: { p: 2.5 }, children: /* @__PURE__ */ jsxs(Box, { sx: { display: "grid", gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr", lg: "1fr 1fr 1fr" }, gap: 2 }, children: [
1580
+ /* @__PURE__ */ jsxs(Box, { children: [
1581
+ /* @__PURE__ */ jsxs(Typography, { sx: labelSx, children: [
1582
+ "Phone Number ",
1583
+ /* @__PURE__ */ jsx2("span", { style: { color: "red" }, children: "*" })
1584
+ ] }),
1585
+ /* @__PURE__ */ jsx2(
1586
+ TextField,
1587
+ {
1588
+ fullWidth: true,
1589
+ size: "small",
1590
+ placeholder: "+1234567890",
1591
+ value: data.phoneNumber,
1592
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, data), { phoneNumber: e.target.value.replace(/[^0-9+\-() ]/g, "") })),
1593
+ error: !!phoneError,
1594
+ helperText: phoneError || "",
1595
+ sx: inputSx
1596
+ }
1597
+ )
1598
+ ] }),
1599
+ /* @__PURE__ */ jsxs(Box, { children: [
1600
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Caller Name" }),
1601
+ /* @__PURE__ */ jsx2(
1602
+ TextField,
1603
+ {
1604
+ fullWidth: true,
1605
+ size: "small",
1606
+ value: data.callerName || "",
1607
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, data), { callerName: e.target.value })),
1608
+ sx: inputSx
1609
+ }
1610
+ )
1611
+ ] }),
1612
+ /* @__PURE__ */ jsxs(Box, { children: [
1613
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Source" }),
1614
+ /* @__PURE__ */ jsx2(
1615
+ TextField,
1616
+ {
1617
+ fullWidth: true,
1618
+ size: "small",
1619
+ value: data.source || "",
1620
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, data), { source: e.target.value })),
1621
+ sx: inputSx
1622
+ }
1623
+ )
1624
+ ] }),
1625
+ /* @__PURE__ */ jsxs(Box, { children: [
1626
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Priority" }),
1627
+ /* @__PURE__ */ jsx2(FormControl, { fullWidth: true, size: "small", children: /* @__PURE__ */ jsx2(
1628
+ Select,
1629
+ {
1630
+ value: (_a = data.priority) != null ? _a : 5,
1631
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, data), { priority: Number(e.target.value) })),
1632
+ children: LEAD_PRIORITY_OPTIONS.map((o) => /* @__PURE__ */ jsx2(MenuItem, { value: o.value, children: o.label }, o.label))
1633
+ }
1634
+ ) })
1635
+ ] }),
1636
+ /* @__PURE__ */ jsxs(Box, { sx: { gridColumn: "1 / -1" }, children: [
1637
+ /* @__PURE__ */ jsx2(Typography, { sx: labelSx, children: "Notes" }),
1638
+ /* @__PURE__ */ jsx2(
1639
+ TextField,
1640
+ {
1641
+ fullWidth: true,
1642
+ size: "small",
1643
+ multiline: true,
1644
+ minRows: 2,
1645
+ maxRows: 8,
1646
+ value: data.notes || "",
1647
+ onChange: (e) => onChange(__spreadProps(__spreadValues({}, data), { notes: e.target.value })),
1648
+ sx: inputSx
1649
+ }
1650
+ )
1651
+ ] })
1652
+ ] }) }),
1653
+ /* @__PURE__ */ jsxs(Box, { sx: dialogFooterSx, children: [
1654
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "cancel", onClick: onClose, children: "Cancel" }),
1655
+ /* @__PURE__ */ jsx2(
1656
+ SDKButton,
1657
+ {
1658
+ onClick: onSave,
1659
+ disabled: saving,
1660
+ startIcon: saving ? /* @__PURE__ */ jsx2(CircularProgress, { size: 14, color: "inherit" }) : void 0,
1661
+ children: "Add Lead"
1662
+ }
1663
+ )
1664
+ ] })
1665
+ ] })
1666
+ }
1667
+ );
1668
+ });
1669
+ function ConfirmDialog({
1670
+ open,
1671
+ title,
1672
+ message,
1673
+ loading,
1674
+ onConfirm,
1675
+ onClose
1676
+ }) {
1677
+ if (!open) return null;
1678
+ return /* @__PURE__ */ jsx2(
1679
+ Box,
1680
+ {
1681
+ sx: { position: "fixed", inset: 0, zIndex: 1500, backgroundColor: "rgba(0,0,0,0.45)", display: "flex", alignItems: "center", justifyContent: "center" },
1682
+ onClick: (e) => e.stopPropagation(),
1683
+ children: /* @__PURE__ */ jsxs(Paper, { elevation: 6, sx: { width: { xs: "90vw", sm: 400 }, borderRadius: "16px", overflow: "hidden", boxShadow: "0 8px 32px rgba(0,0,0,0.18)" }, children: [
1684
+ /* @__PURE__ */ jsxs(Box, { sx: __spreadProps(__spreadValues({}, dialogHeaderSx), { borderBottom: "none", pb: 0 }), children: [
1685
+ /* @__PURE__ */ jsx2(Typography, { fontWeight: 700, fontSize: "1rem", fontFamily: "poppins, Arial, sans-serif", children: title }),
1686
+ /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: onClose, children: "\u2715" })
1687
+ ] }),
1688
+ /* @__PURE__ */ jsx2(Box, { sx: { px: 2.5, py: 1.5 }, children: /* @__PURE__ */ jsx2(Typography, { fontSize: "0.85rem", color: "#555", fontFamily: "poppins, Arial, sans-serif", children: message }) }),
1689
+ /* @__PURE__ */ jsxs(Box, { sx: dialogFooterSx, children: [
1690
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "cancel", onClick: onClose, children: "Cancel" }),
1691
+ /* @__PURE__ */ jsx2(
1692
+ SDKButton,
1693
+ {
1694
+ variant: "danger",
1695
+ onClick: onConfirm,
1696
+ disabled: loading,
1697
+ startIcon: loading ? /* @__PURE__ */ jsx2(CircularProgress, { size: 14, color: "inherit" }) : void 0,
1698
+ children: "Confirm"
1699
+ }
1700
+ )
1701
+ ] })
1702
+ ] })
1703
+ }
1704
+ );
1705
+ }
1706
+ var fmtRecordingDuration = (s) => {
1707
+ if (!isFinite(s) || s < 0) return "";
1708
+ const m = Math.floor(s / 60);
1709
+ const sec = Math.floor(s % 60);
1710
+ return `${m}:${sec.toString().padStart(2, "0")}`;
1711
+ };
1712
+ var activePlayers = /* @__PURE__ */ new Set();
1713
+ var notifyPlay = (activeId) => {
1714
+ activePlayers.forEach((fn) => fn(activeId));
1715
+ };
1716
+ function CallRecording({ callUuid, recordingPath, iconOnly = false }) {
1717
+ const [audioUrl, setAudioUrl] = useState2(null);
1718
+ const [loading, setLoading] = useState2(false);
1719
+ const [error, setError] = useState2(false);
1720
+ const [durationSec, setDurationSec] = useState2(null);
1721
+ const [currentSec, setCurrentSec] = useState2(0);
1722
+ const unavailable = !recordingPath;
1723
+ const totalLabel = durationSec != null ? fmtRecordingDuration(durationSec) : "";
1724
+ const closePlayer = useCallback2(() => {
1725
+ setAudioUrl((prev) => {
1726
+ if (prev && prev.startsWith("blob:")) URL.revokeObjectURL(prev);
1727
+ return null;
1728
+ });
1729
+ setCurrentSec(0);
1730
+ setDurationSec(null);
1731
+ }, []);
1732
+ useEffect(() => {
1733
+ const onPlay = (activeId) => {
1734
+ if (activeId !== callUuid) closePlayer();
1735
+ };
1736
+ activePlayers.add(onPlay);
1737
+ return () => {
1738
+ activePlayers.delete(onPlay);
1739
+ };
1740
+ }, [callUuid, closePlayer]);
1741
+ const handlePlay = async () => {
1742
+ if (audioUrl) return;
1743
+ notifyPlay(callUuid);
1744
+ try {
1745
+ setLoading(true);
1746
+ setError(false);
1747
+ const blob = await getRecordingByCall(callUuid);
1748
+ setAudioUrl(URL.createObjectURL(blob));
1749
+ } catch (e) {
1750
+ setError(true);
1751
+ } finally {
1752
+ setLoading(false);
1753
+ }
1754
+ };
1755
+ const handleDownload = async () => {
1756
+ try {
1757
+ const blob = audioUrl ? await fetch(audioUrl).then((r) => r.blob()) : await getRecordingByCall(callUuid);
1758
+ const url = URL.createObjectURL(blob);
1759
+ const a = document.createElement("a");
1760
+ a.href = url;
1761
+ a.download = `recording_${callUuid}.wav`;
1762
+ a.click();
1763
+ URL.revokeObjectURL(url);
1764
+ } catch (e) {
1765
+ }
1766
+ };
1767
+ if (iconOnly) {
1768
+ if (audioUrl) {
1769
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5 }, children: [
1770
+ /* @__PURE__ */ jsx2(
1771
+ "audio",
1772
+ {
1773
+ controls: true,
1774
+ autoPlay: true,
1775
+ src: audioUrl,
1776
+ onLoadedMetadata: (e) => setDurationSec(e.currentTarget.duration),
1777
+ onTimeUpdate: (e) => setCurrentSec(e.currentTarget.currentTime),
1778
+ onEnded: closePlayer,
1779
+ style: { height: 32, maxWidth: 170 }
1780
+ }
1781
+ ),
1782
+ totalLabel && /* @__PURE__ */ jsxs(Typography, { sx: { fontSize: 12, fontWeight: 600, color: "#1A5F6C", whiteSpace: "nowrap" }, children: [
1783
+ fmtRecordingDuration(currentSec),
1784
+ " / ",
1785
+ totalLabel
1786
+ ] }),
1787
+ /* @__PURE__ */ jsx2(Tooltip, { title: "Download", children: /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: handleDownload, sx: { color: "#1565c0" }, children: /* @__PURE__ */ jsx2(DownloadIcon, { sx: { fontSize: 16 } }) }) })
1788
+ ] });
1789
+ }
1790
+ return /* @__PURE__ */ jsx2(Tooltip, { title: unavailable ? "No recording available for this call." : error ? "Recording unavailable" : "Play voicemail", children: /* @__PURE__ */ jsx2("span", { children: /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: handlePlay, disabled: unavailable || loading || error, sx: { color: unavailable ? "#bdbdbd" : "#1A5F6C" }, children: loading ? /* @__PURE__ */ jsx2(CircularProgress, { size: 16, color: "inherit" }) : /* @__PURE__ */ jsx2(PlayArrowIcon, { sx: { fontSize: 18 } }) }) }) });
1791
+ }
1792
+ if (unavailable) {
1793
+ return /* @__PURE__ */ jsx2(Typography, { sx: { fontSize: "0.82rem", color: "#999" }, fontFamily: "poppins, Arial, sans-serif", children: "No recording available for this call." });
1794
+ }
1795
+ if (audioUrl) {
1796
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
1797
+ /* @__PURE__ */ jsx2("audio", { controls: true, autoPlay: true, src: audioUrl, onEnded: closePlayer, style: { height: 38, flex: 1 } }),
1798
+ /* @__PURE__ */ jsx2(Tooltip, { title: "Download", children: /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: handleDownload, sx: { color: "#1565c0" }, children: /* @__PURE__ */ jsx2(DownloadIcon, { sx: { fontSize: 18 } }) }) })
1799
+ ] });
1800
+ }
1801
+ return /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
1802
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "outlined", onClick: handlePlay, disabled: loading || error, startIcon: loading ? /* @__PURE__ */ jsx2(CircularProgress, { size: 16, color: "inherit" }) : /* @__PURE__ */ jsx2(PlayArrowIcon, { sx: { fontSize: 16 } }), children: error ? "Recording unavailable" : "Play recording" }),
1803
+ /* @__PURE__ */ jsx2(Tooltip, { title: "Download", children: /* @__PURE__ */ jsx2("span", { children: /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: handleDownload, disabled: loading || error, sx: { color: "#1565c0" }, children: /* @__PURE__ */ jsx2(DownloadIcon, { sx: { fontSize: 18 } }) }) }) })
1804
+ ] });
1805
+ }
1806
+ function CallDataDialog({
1807
+ open,
1808
+ lead,
1809
+ data,
1810
+ loading,
1811
+ error,
1812
+ onClose
1813
+ }) {
1814
+ if (!open) return null;
1815
+ const fmt = (v) => v ? new Date(v).toLocaleString() : "\u2014";
1816
+ const fieldCardSx = {
1817
+ display: "flex",
1818
+ flexDirection: "column",
1819
+ gap: 0.25,
1820
+ p: 1,
1821
+ borderRadius: "8px",
1822
+ backgroundColor: "#fafafa",
1823
+ border: "1px solid #eee"
1824
+ };
1825
+ const fieldLabelSx = {
1826
+ fontSize: "0.66rem",
1827
+ fontWeight: 600,
1828
+ color: "#888",
1829
+ textTransform: "uppercase",
1830
+ letterSpacing: 0.3
1831
+ };
1832
+ const fieldValueSx = {
1833
+ fontSize: "0.82rem",
1834
+ fontWeight: 600,
1835
+ color: "#1a1a1a",
1836
+ wordBreak: "break-word"
1837
+ };
1838
+ const sectionTitle = {
1839
+ fontSize: "0.7rem",
1840
+ fontWeight: 700,
1841
+ color: "#1A5F6C",
1842
+ textTransform: "uppercase",
1843
+ letterSpacing: 0.5,
1844
+ mb: 0.75
1845
+ };
1846
+ const fieldCard = (label, value, full) => /* @__PURE__ */ jsxs(Box, { sx: __spreadValues(__spreadValues({}, fieldCardSx), full ? { gridColumn: "1 / -1" } : {}), children: [
1847
+ /* @__PURE__ */ jsx2(Typography, { sx: fieldLabelSx, fontFamily: "poppins, Arial, sans-serif", children: label }),
1848
+ /* @__PURE__ */ jsx2(Typography, { sx: fieldValueSx, fontFamily: "poppins, Arial, sans-serif", children: value })
1849
+ ] }, label);
1850
+ const overview = data ? [
1851
+ ["Phone Number", data.phoneNumber || "\u2014"],
1852
+ ["Call Type", data.callType || "\u2014"],
1853
+ ["Call Status", data.callStatus || "\u2014"],
1854
+ ["Disposition", data.disposition || "\u2014"],
1855
+ ["Agent Disposition", data.agentSelectedDisposition || "\u2014"],
1856
+ ["Transferred", data.wasTransferred ? "Yes" : "No"],
1857
+ ["Hangup By", data.hangupInitiator || "\u2014"]
1858
+ ] : [];
1859
+ const agentQueue = data ? [
1860
+ ["Agent", data.agentName || "\u2014"],
1861
+ ["Agent ID", data.agentUserId || "\u2014"],
1862
+ ["Extension", data.extension || "\u2014"],
1863
+ ["Queue", data.queueName || "\u2014"]
1864
+ ] : [];
1865
+ const timing = data ? [
1866
+ ["Start Time", fmt(data.callStartTime)],
1867
+ ["Connect Time", fmt(data.connectTime)]
1868
+ ] : [];
1869
+ const durations = data ? [
1870
+ ["Talk", data.talkDurationFmt || "\u2014"],
1871
+ ["Ringing", data.ringingDurationFmt || "\u2014"],
1872
+ ["Hold", data.holdDurationFmt || "\u2014"],
1873
+ ["Mute", data.muteDurationFmt || "\u2014"],
1874
+ ["Wrap-up", data.wrapupDurationFmt || "\u2014"],
1875
+ ["Queue", data.queueDurationFmt || "\u2014"],
1876
+ ["IVR", data.ivrDurationFmt || "\u2014"]
1877
+ ] : [];
1878
+ const twoColGrid = { display: "grid", gridTemplateColumns: { xs: "1fr", sm: "1fr 1fr" }, gap: 1.25 };
1879
+ const compactGrid = { display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(96px, 1fr))", gap: 1.25 };
1880
+ return /* @__PURE__ */ jsx2(Box, { sx: { position: "fixed", inset: 0, zIndex: 1500, backgroundColor: "rgba(0,0,0,0.45)", display: "flex", alignItems: "center", justifyContent: "center" }, onClick: (e) => e.stopPropagation(), children: /* @__PURE__ */ jsxs(Paper, { elevation: 6, sx: { width: { xs: "92vw", sm: 600 }, maxHeight: "85vh", display: "flex", flexDirection: "column", borderRadius: "16px", overflow: "hidden", boxShadow: "0 8px 32px rgba(26,95,108,0.18)" }, children: [
1881
+ /* @__PURE__ */ jsxs(Box, { sx: __spreadProps(__spreadValues({}, dialogHeaderSx), { backgroundColor: "#1A5F6C", color: "#fff" }), children: [
1882
+ /* @__PURE__ */ jsxs(Box, { children: [
1883
+ /* @__PURE__ */ jsx2(Typography, { fontWeight: 700, fontSize: "1rem", fontFamily: "poppins, Arial, sans-serif", children: "Call Details" }),
1884
+ (lead == null ? void 0 : lead.phoneNumber) ? /* @__PURE__ */ jsxs(Typography, { fontSize: "0.72rem", sx: { opacity: 0.85 }, fontFamily: "poppins, Arial, sans-serif", children: [
1885
+ "Latest call for ",
1886
+ lead.phoneNumber
1887
+ ] }) : null
1888
+ ] }),
1889
+ /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: onClose, sx: { color: "#fff" }, children: "\u2715" })
1890
+ ] }),
1891
+ /* @__PURE__ */ jsx2(Box, { sx: { px: 2.5, py: 2, overflowY: "auto" }, children: loading ? /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", justifyContent: "center", py: 4 }, children: /* @__PURE__ */ jsx2(CircularProgress, { size: 30 }) }) : error ? /* @__PURE__ */ jsx2(Typography, { fontSize: "0.85rem", color: "#d32f2f", textAlign: "center", sx: { py: 3 }, fontFamily: "poppins, Arial, sans-serif", children: error }) : data ? /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: "column", gap: 2 }, children: [
1892
+ /* @__PURE__ */ jsxs(Box, { children: [
1893
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitle, fontFamily: "poppins, Arial, sans-serif", children: "Call Overview" }),
1894
+ /* @__PURE__ */ jsx2(Box, { sx: twoColGrid, children: overview.map(([l, v]) => fieldCard(l, v)) })
1895
+ ] }),
1896
+ /* @__PURE__ */ jsxs(Box, { children: [
1897
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitle, fontFamily: "poppins, Arial, sans-serif", children: "Agent & Queue" }),
1898
+ /* @__PURE__ */ jsx2(Box, { sx: twoColGrid, children: agentQueue.map(([l, v]) => fieldCard(l, v)) })
1899
+ ] }),
1900
+ /* @__PURE__ */ jsxs(Box, { children: [
1901
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitle, fontFamily: "poppins, Arial, sans-serif", children: "Timing" }),
1902
+ /* @__PURE__ */ jsx2(Box, { sx: twoColGrid, children: timing.map(([l, v]) => fieldCard(l, v)) })
1903
+ ] }),
1904
+ /* @__PURE__ */ jsxs(Box, { children: [
1905
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitle, fontFamily: "poppins, Arial, sans-serif", children: "Durations" }),
1906
+ /* @__PURE__ */ jsx2(Box, { sx: compactGrid, children: durations.map(([l, v]) => fieldCard(l, v)) })
1907
+ ] }),
1908
+ /* @__PURE__ */ jsxs(Box, { children: [
1909
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitle, fontFamily: "poppins, Arial, sans-serif", children: "Remarks" }),
1910
+ /* @__PURE__ */ jsx2(Box, { sx: __spreadProps(__spreadValues({}, fieldCardSx), { minHeight: 44 }), children: /* @__PURE__ */ jsx2(Typography, { sx: fieldValueSx, fontFamily: "poppins, Arial, sans-serif", children: data.remarks || "\u2014" }) })
1911
+ ] }),
1912
+ /* @__PURE__ */ jsxs(Box, { children: [
1913
+ /* @__PURE__ */ jsx2(Typography, { sx: sectionTitle, fontFamily: "poppins, Arial, sans-serif", children: "Recording" }),
1914
+ /* @__PURE__ */ jsx2(Box, { sx: fieldCardSx, children: /* @__PURE__ */ jsx2(CallRecording, { callUuid: data.callUuid, recordingPath: data.recordingPath }) })
1915
+ ] })
1916
+ ] }) : null }),
1917
+ /* @__PURE__ */ jsx2(Box, { sx: dialogFooterSx, children: /* @__PURE__ */ jsx2(SDKButton, { variant: "cancel", onClick: onClose, children: "Close" }) })
1918
+ ] }) });
1919
+ }
1920
+ function ImportLeadsDialog({
1921
+ open,
1922
+ file,
1923
+ onFileChange,
1924
+ uploading,
1925
+ onUpload,
1926
+ onDownloadTemplate,
1927
+ onClose
1928
+ }) {
1929
+ const fileRef = useRef(null);
1930
+ if (!open) return null;
1931
+ return /* @__PURE__ */ jsx2(
1932
+ Box,
1933
+ {
1934
+ sx: { position: "fixed", inset: 0, zIndex: 1400, backgroundColor: "rgba(0,0,0,0.45)", display: "flex", alignItems: "center", justifyContent: "center" },
1935
+ onClick: (e) => e.stopPropagation(),
1936
+ children: /* @__PURE__ */ jsxs(Paper, { elevation: 6, sx: { width: { xs: "90vw", sm: 460 }, borderRadius: "16px", overflow: "hidden", boxShadow: "0 8px 32px rgba(26,95,108,0.18)" }, children: [
1937
+ /* @__PURE__ */ jsxs(Box, { sx: __spreadProps(__spreadValues({}, dialogHeaderSx), { backgroundColor: "#1A5F6C", color: "#fff" }), children: [
1938
+ /* @__PURE__ */ jsx2(Typography, { fontWeight: 700, fontSize: "1rem", fontFamily: "poppins, Arial, sans-serif", children: "Import Leads" }),
1939
+ /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: onClose, sx: { color: "#fff" }, children: "\u2715" })
1940
+ ] }),
1941
+ /* @__PURE__ */ jsxs(Box, { sx: { p: 2.5 }, children: [
1942
+ /* @__PURE__ */ jsx2(Typography, { fontSize: "0.82rem", color: "#555", fontFamily: "poppins, Arial, sans-serif", mb: 2, children: "Upload a CSV or Excel file. Use the template for the correct format." }),
1943
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1.5, flexWrap: "wrap", mb: 1.5 }, children: [
1944
+ /* @__PURE__ */ jsx2(
1945
+ SDKButton,
1946
+ {
1947
+ variant: "outlined",
1948
+ startIcon: /* @__PURE__ */ jsx2(UploadFileIcon, {}),
1949
+ onClick: () => {
1950
+ var _a;
1951
+ return (_a = fileRef.current) == null ? void 0 : _a.click();
1952
+ },
1953
+ children: "Choose File"
1954
+ }
1955
+ ),
1956
+ /* @__PURE__ */ jsx2(
1957
+ "input",
1958
+ {
1959
+ ref: fileRef,
1960
+ type: "file",
1961
+ accept: ".csv,.xlsx,.xls",
1962
+ hidden: true,
1963
+ onChange: (e) => {
1964
+ var _a;
1965
+ const f = (_a = e.target.files) == null ? void 0 : _a[0];
1966
+ if (!f) return;
1967
+ if ([".csv", ".xlsx", ".xls"].some((ext) => f.name.toLowerCase().endsWith(ext))) onFileChange(f);
1968
+ }
1969
+ }
1970
+ ),
1971
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontSize: "0.82rem", color: "#666", flex: 1, fontFamily: "poppins, Arial, sans-serif" }, children: file ? file.name : "No file chosen" }),
1972
+ file && /* @__PURE__ */ jsx2(
1973
+ SDKButton,
1974
+ {
1975
+ variant: "cancel",
1976
+ size: "small",
1977
+ onClick: () => {
1978
+ onFileChange(null);
1979
+ if (fileRef.current) fileRef.current.value = "";
1980
+ },
1981
+ children: "Clear"
1982
+ }
1983
+ )
1984
+ ] }),
1985
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "outlined", startIcon: /* @__PURE__ */ jsx2(DownloadIcon, {}), onClick: onDownloadTemplate, children: "Download Template" })
1986
+ ] }),
1987
+ /* @__PURE__ */ jsxs(Box, { sx: dialogFooterSx, children: [
1988
+ /* @__PURE__ */ jsx2(SDKButton, { variant: "cancel", onClick: onClose, children: "Cancel" }),
1989
+ /* @__PURE__ */ jsx2(
1990
+ SDKButton,
1991
+ {
1992
+ onClick: onUpload,
1993
+ disabled: uploading || !file,
1994
+ startIcon: uploading ? /* @__PURE__ */ jsx2(CircularProgress, { size: 14, color: "inherit" }) : void 0,
1995
+ children: "Upload"
1996
+ }
1997
+ )
1998
+ ] })
1999
+ ] })
2000
+ }
2001
+ );
2002
+ }
2003
+ var CampaignsContent = memo(function CampaignsContent2() {
2004
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
2005
+ const theme = useTheme2();
2006
+ const { showToast } = useToast();
2007
+ const { isBitEnabled } = useSDKPermissions();
2008
+ const callerData = useGetCallerData();
2009
+ const isAgentIdle = callerData.status === "IDLE";
2010
+ const hasOutboundPermission = isBitEnabled("calls", SDK_PERMISSIONS.CALL_OUTBOUND);
2011
+ const {
2012
+ campaigns,
2013
+ loading,
2014
+ fetchCampaigns,
2015
+ getCampaignById,
2016
+ createCampaign,
2017
+ updateCampaign,
2018
+ activateCampaign,
2019
+ pauseCampaign,
2020
+ archiveCampaign
2021
+ } = useCampaigns();
2022
+ const {
2023
+ leads,
2024
+ leadTotal,
2025
+ leadsMeta,
2026
+ loading: leadsLoading,
2027
+ fetchLeads,
2028
+ createLead,
2029
+ deleteLead,
2030
+ dialPreview,
2031
+ getLeadCallData,
2032
+ uploadLeadsExcel,
2033
+ downloadLeadTemplate,
2034
+ exportLeads
2035
+ } = useLeads();
2036
+ const { fetchQueues } = useQueues();
2037
+ const [queueNameMap, setQueueNameMap] = useState2({});
2038
+ useEffect(() => {
2039
+ fetchQueues().then((qs) => {
2040
+ const map = {};
2041
+ qs.forEach((q) => {
2042
+ map[q.id] = q.name;
2043
+ });
2044
+ setQueueNameMap(map);
2045
+ }).catch(() => {
2046
+ });
2047
+ }, [fetchQueues]);
2048
+ const handleQueuesRefreshed = useCallback2((qs) => {
2049
+ const map = {};
2050
+ qs.forEach((q) => {
2051
+ map[q.id] = q.name;
2052
+ });
2053
+ setQueueNameMap(map);
2054
+ }, []);
2055
+ const [selectedId, setSelectedId] = useState2(null);
2056
+ const [showArchived, setShowArchived] = useState2(false);
2057
+ const [campaignListCollapsed, setCampaignListCollapsed] = useState2(false);
2058
+ const [dialogOpen, setDialogOpen] = useState2(false);
2059
+ const [editingCampaign, setEditingCampaign] = useState2(null);
2060
+ const [formData, setFormData] = useState2(defaultFormData);
2061
+ const [saving, setSaving] = useState2(false);
2062
+ const [archiveOpen, setArchiveOpen] = useState2(false);
2063
+ const [archiveTarget, setArchiveTarget] = useState2(null);
2064
+ const [archiving, setArchiving] = useState2(false);
2065
+ const [leadPage, setLeadPage] = useState2(0);
2066
+ const [leadRowsPerPage, setLeadRowsPerPage] = useState2(10);
2067
+ const [leadSearch, setLeadSearch] = useState2("");
2068
+ const [debouncedSearch, setDebouncedSearch] = useState2("");
2069
+ const [leadStatusFilter, setLeadStatusFilter] = useState2("All states");
2070
+ const [leadStartDate, setLeadStartDate] = useState2(null);
2071
+ const [leadEndDate, setLeadEndDate] = useState2(null);
2072
+ const debounceRef = useRef(null);
2073
+ const [addLeadOpen, setAddLeadOpen] = useState2(false);
2074
+ const [addLeadData, setAddLeadData] = useState2({ phoneNumber: "", callerName: "", priority: 5 });
2075
+ const [addLeadSaving, setAddLeadSaving] = useState2(false);
2076
+ const [importOpen, setImportOpen] = useState2(false);
2077
+ const [importFile, setImportFile] = useState2(null);
2078
+ const [importing, setImporting] = useState2(false);
2079
+ const [deleteLeadOpen, setDeleteLeadOpen] = useState2(false);
2080
+ const [deleteLeadTarget, setDeleteLeadTarget] = useState2(null);
2081
+ const [deletingLead, setDeletingLead] = useState2(false);
2082
+ const [callDataOpen, setCallDataOpen] = useState2(false);
2083
+ const [callDataLead, setCallDataLead] = useState2(null);
2084
+ const [callDataLoading, setCallDataLoading] = useState2(false);
2085
+ const [callData, setCallData] = useState2(null);
2086
+ const [callDataError, setCallDataError] = useState2(null);
2087
+ const handleViewCallData = useCallback2(async (lead) => {
2088
+ var _a2, _b2;
2089
+ const callId = lead.latestCallId;
2090
+ if (!callId) return;
2091
+ setCallDataLead(lead);
2092
+ setCallDataOpen(true);
2093
+ setCallData(null);
2094
+ setCallDataError(null);
2095
+ setCallDataLoading(true);
2096
+ try {
2097
+ const data = await getLeadCallData(callId);
2098
+ setCallData(data);
2099
+ } catch (e) {
2100
+ setCallDataError(((_b2 = (_a2 = e == null ? void 0 : e.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || "Failed to load call data");
2101
+ } finally {
2102
+ setCallDataLoading(false);
2103
+ }
2104
+ }, [getLeadCallData]);
2105
+ const [dialLoading, setDialLoading] = useState2(null);
2106
+ const selected = (_a = campaigns.find((c) => c.id === selectedId)) != null ? _a : null;
2107
+ const showVoicemail = (selected == null ? void 0 : selected.campaignType) === "AFTER_HOURS_CALLBACK";
2108
+ const visibleCampaigns = campaigns.filter(
2109
+ (c) => {
2110
+ var _a2;
2111
+ return showArchived ? true : ((_a2 = c.status) == null ? void 0 : _a2.toLowerCase()) !== "archived";
2112
+ }
2113
+ );
2114
+ const handleSelectCampaign = useCallback2((id) => {
2115
+ if (id === selectedId) return;
2116
+ setLeadStatusFilter("All states");
2117
+ setLeadSearch("");
2118
+ setDebouncedSearch("");
2119
+ setLeadStartDate(null);
2120
+ setLeadEndDate(null);
2121
+ setLeadPage(0);
2122
+ setSelectedId(id);
2123
+ }, [selectedId]);
2124
+ useEffect(() => {
2125
+ fetchCampaigns();
2126
+ }, [fetchCampaigns]);
2127
+ useEffect(() => {
2128
+ debounceRef.current = setTimeout(() => setDebouncedSearch(leadSearch.trim()), 400);
2129
+ return () => {
2130
+ if (debounceRef.current) clearTimeout(debounceRef.current);
2131
+ };
2132
+ }, [leadSearch]);
2133
+ useEffect(() => {
2134
+ if (!selectedId) return;
2135
+ setLeadPage(0);
2136
+ fetchLeads(selectedId, {
2137
+ page: 1,
2138
+ pageSize: leadRowsPerPage,
2139
+ lead_status: leadStatusFilter !== "All states" ? leadStatusFilter : void 0,
2140
+ search: debouncedSearch || void 0,
2141
+ start_date: leadStartDate ? leadStartDate.format("YYYY-MM-DDTHH:mm:ss") : void 0,
2142
+ end_date: leadEndDate ? leadEndDate.format("YYYY-MM-DDTHH:mm:ss") : void 0
2143
+ });
2144
+ }, [selectedId, leadRowsPerPage, leadStatusFilter, debouncedSearch, leadStartDate, leadEndDate, fetchLeads]);
2145
+ const refetchLeads = useCallback2((page = leadPage, silent = false) => {
2146
+ if (!selectedId) return;
2147
+ fetchLeads(selectedId, {
2148
+ page: page + 1,
2149
+ pageSize: leadRowsPerPage,
2150
+ lead_status: leadStatusFilter !== "All states" ? leadStatusFilter : void 0,
2151
+ search: debouncedSearch || void 0,
2152
+ start_date: leadStartDate ? leadStartDate.format("YYYY-MM-DDTHH:mm:ss") : void 0,
2153
+ end_date: leadEndDate ? leadEndDate.format("YYYY-MM-DDTHH:mm:ss") : void 0
2154
+ }, { silent });
2155
+ }, [selectedId, leadPage, leadRowsPerPage, leadStatusFilter, debouncedSearch, leadStartDate, leadEndDate, fetchLeads]);
2156
+ const clearLeadDates = () => {
2157
+ setLeadStartDate(null);
2158
+ setLeadEndDate(null);
2159
+ setLeadPage(0);
2160
+ };
2161
+ useEffect(() => {
2162
+ if (!selectedId) return;
2163
+ const intervalId = setInterval(() => {
2164
+ refetchLeads(leadPage, true);
2165
+ }, 3e3);
2166
+ return () => clearInterval(intervalId);
2167
+ }, [selectedId, leadPage, refetchLeads]);
2168
+ const handleOpenCreate = () => {
2169
+ setEditingCampaign(null);
2170
+ setFormData(defaultFormData);
2171
+ setDialogOpen(true);
2172
+ };
2173
+ const handleOpenEdit = async (c) => {
2174
+ setEditingCampaign(c);
2175
+ setFormData(campaignToFormData(c));
2176
+ setDialogOpen(true);
2177
+ try {
2178
+ const fresh = await getCampaignById(c.id);
2179
+ setEditingCampaign(fresh);
2180
+ setFormData(campaignToFormData(fresh));
2181
+ } catch (e) {
2182
+ }
2183
+ };
2184
+ const handleSave = async () => {
2185
+ var _a2, _b2, _c2, _d2, _e2;
2186
+ if (!formData.name.trim()) {
2187
+ showToast("Campaign name is required", "warning");
2188
+ return;
2189
+ }
2190
+ setSaving(true);
2191
+ const startTime = ((_a2 = formData.startTime) == null ? void 0 : _a2.length) === 5 ? `${formData.startTime}:00` : formData.startTime;
2192
+ const endTime = ((_b2 = formData.endTime) == null ? void 0 : _b2.length) === 5 ? `${formData.endTime}:00` : formData.endTime;
2193
+ const toIso = (d) => d ? new Date(d).toISOString() : void 0;
2194
+ const scheduledStart = toIso(formData.scheduledStart);
2195
+ const scheduledEnd = toIso(formData.scheduledEnd);
2196
+ try {
2197
+ if (editingCampaign) {
2198
+ const updatePayload = __spreadProps(__spreadValues({}, formData), { startTime, endTime });
2199
+ if (scheduledStart) updatePayload.scheduledStart = scheduledStart;
2200
+ else delete updatePayload.scheduledStart;
2201
+ if (scheduledEnd) updatePayload.scheduledEnd = scheduledEnd;
2202
+ else delete updatePayload.scheduledEnd;
2203
+ await updateCampaign(editingCampaign.id, updatePayload);
2204
+ showToast("Campaign updated", "success");
2205
+ } else {
2206
+ const payload = __spreadProps(__spreadValues({}, formData), { startTime, endTime });
2207
+ if (scheduledStart) payload.scheduledStart = scheduledStart;
2208
+ else delete payload.scheduledStart;
2209
+ if (scheduledEnd) payload.scheduledEnd = scheduledEnd;
2210
+ else delete payload.scheduledEnd;
2211
+ if (!payload.callerId) delete payload.callerId;
2212
+ if (!payload.answerTimeoutSeconds) delete payload.answerTimeoutSeconds;
2213
+ if (payload.aiBotId == null) delete payload.aiBotId;
2214
+ if (!((_c2 = payload.queueLinks) == null ? void 0 : _c2.length)) delete payload.queueLinks;
2215
+ if (payload.settings && !Object.keys(payload.settings).length) delete payload.settings;
2216
+ const created = await createCampaign(payload);
2217
+ showToast("Campaign created", "success");
2218
+ setSelectedId(created.id);
2219
+ }
2220
+ setDialogOpen(false);
2221
+ fetchCampaigns();
2222
+ } catch (err) {
2223
+ showToast(((_e2 = (_d2 = err == null ? void 0 : err.response) == null ? void 0 : _d2.data) == null ? void 0 : _e2.message) || (err == null ? void 0 : err.message) || "Failed to save campaign", "error");
2224
+ } finally {
2225
+ setSaving(false);
2226
+ }
2227
+ };
2228
+ const handleStart = async (c) => {
2229
+ var _a2, _b2;
2230
+ try {
2231
+ await activateCampaign(c.id);
2232
+ showToast("Campaign started", "success");
2233
+ fetchCampaigns();
2234
+ } catch (err) {
2235
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Failed to start", "error");
2236
+ }
2237
+ };
2238
+ const handlePause = async (c) => {
2239
+ var _a2, _b2;
2240
+ try {
2241
+ await pauseCampaign(c.id);
2242
+ showToast("Campaign paused", "success");
2243
+ fetchCampaigns();
2244
+ } catch (err) {
2245
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Failed to pause", "error");
2246
+ }
2247
+ };
2248
+ const confirmArchive = async () => {
2249
+ var _a2, _b2;
2250
+ if (!archiveTarget) return;
2251
+ setArchiving(true);
2252
+ try {
2253
+ await archiveCampaign(archiveTarget.id);
2254
+ showToast("Campaign archived", "success");
2255
+ setArchiveOpen(false);
2256
+ setArchiveTarget(null);
2257
+ fetchCampaigns();
2258
+ } catch (err) {
2259
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Failed to archive", "error");
2260
+ } finally {
2261
+ setArchiving(false);
2262
+ }
2263
+ };
2264
+ const handleAddLead = async () => {
2265
+ var _a2, _b2;
2266
+ if (!selectedId) return;
2267
+ const err = validatePhone(addLeadData.phoneNumber);
2268
+ if (err) {
2269
+ showToast(err, "warning");
2270
+ return;
2271
+ }
2272
+ setAddLeadSaving(true);
2273
+ try {
2274
+ await createLead(selectedId, addLeadData);
2275
+ showToast("Lead added", "success");
2276
+ setAddLeadOpen(false);
2277
+ setAddLeadData({ phoneNumber: "", callerName: "", priority: 5 });
2278
+ refetchLeads(0);
2279
+ setLeadPage(0);
2280
+ } catch (err2) {
2281
+ showToast(((_b2 = (_a2 = err2 == null ? void 0 : err2.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err2 == null ? void 0 : err2.message) || "Failed to add lead", "error");
2282
+ } finally {
2283
+ setAddLeadSaving(false);
2284
+ }
2285
+ };
2286
+ const handleImport = async () => {
2287
+ var _a2, _b2;
2288
+ if (!selectedId || !importFile) return;
2289
+ setImporting(true);
2290
+ try {
2291
+ const result = await uploadLeadsExcel(selectedId, importFile);
2292
+ showToast((result == null ? void 0 : result.message) || "Leads uploaded", "success");
2293
+ setImportFile(null);
2294
+ setImportOpen(false);
2295
+ refetchLeads(0);
2296
+ setLeadPage(0);
2297
+ } catch (err) {
2298
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Upload failed", "error");
2299
+ } finally {
2300
+ setImporting(false);
2301
+ }
2302
+ };
2303
+ const handleExport = async () => {
2304
+ var _a2, _b2;
2305
+ if (!selectedId) return;
2306
+ try {
2307
+ await exportLeads(selectedId);
2308
+ showToast("Leads exported", "success");
2309
+ } catch (err) {
2310
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Export failed", "error");
2311
+ }
2312
+ };
2313
+ const handleDownloadTemplate = async () => {
2314
+ var _a2, _b2;
2315
+ if (!selectedId) return;
2316
+ try {
2317
+ await downloadLeadTemplate(selectedId);
2318
+ } catch (err) {
2319
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Download failed", "error");
2320
+ }
2321
+ };
2322
+ const handleDialPreview = async (leadId) => {
2323
+ var _a2, _b2;
2324
+ if (!selectedId) return;
2325
+ setDialLoading(leadId);
2326
+ try {
2327
+ const res = await dialPreview(selectedId, leadId);
2328
+ showToast((res == null ? void 0 : res.message) || "Preview dial initiated", "success");
2329
+ } catch (err) {
2330
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Dial failed", "error");
2331
+ } finally {
2332
+ setDialLoading(null);
2333
+ }
2334
+ };
2335
+ const confirmDeleteLead = async () => {
2336
+ var _a2, _b2;
2337
+ if (!selectedId || !deleteLeadTarget) return;
2338
+ setDeletingLead(true);
2339
+ try {
2340
+ await deleteLead(selectedId, deleteLeadTarget.id);
2341
+ showToast("Lead deleted", "success");
2342
+ setDeleteLeadOpen(false);
2343
+ setDeleteLeadTarget(null);
2344
+ refetchLeads(leadPage);
2345
+ } catch (err) {
2346
+ showToast(((_b2 = (_a2 = err == null ? void 0 : err.response) == null ? void 0 : _a2.data) == null ? void 0 : _b2.message) || (err == null ? void 0 : err.message) || "Delete failed", "error");
2347
+ } finally {
2348
+ setDeletingLead(false);
2349
+ }
2350
+ };
2351
+ const sc = selected;
2352
+ const scActive = ((_b = sc == null ? void 0 : sc.status) == null ? void 0 : _b.toLowerCase()) === "active";
2353
+ const scDraft = ((_c = sc == null ? void 0 : sc.status) == null ? void 0 : _c.toLowerCase()) === "draft";
2354
+ const scPaused = ((_d = sc == null ? void 0 : sc.status) == null ? void 0 : _d.toLowerCase()) === "paused";
2355
+ const scArchived = ((_e = sc == null ? void 0 : sc.status) == null ? void 0 : _e.toLowerCase()) === "archived";
2356
+ return /* @__PURE__ */ jsxs(Box, { sx: { fontFamily: "poppins, Arial, sans-serif" }, children: [
2357
+ /* @__PURE__ */ jsx2(
2358
+ SDKPageHeader,
2359
+ {
2360
+ title: "Call Scheduling",
2361
+ actions: /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1 }, children: [
2362
+ /* @__PURE__ */ jsx2(
2363
+ SDKButton,
2364
+ {
2365
+ startIcon: /* @__PURE__ */ jsx2(RefreshIcon, {}),
2366
+ onClick: () => {
2367
+ fetchCampaigns();
2368
+ if (selectedId) refetchLeads();
2369
+ },
2370
+ children: "Refresh"
2371
+ }
2372
+ ),
2373
+ /* @__PURE__ */ jsx2(
2374
+ SDKPermissionGuard,
2375
+ {
2376
+ permissions: [
2377
+ SDK_PERMISSIONS.CAMPAIGNS_CREATE,
2378
+ SDK_PERMISSIONS.CAMPAIGNS_MANAGE
2379
+ ],
2380
+ showFallback: false,
2381
+ children: /* @__PURE__ */ jsx2(SDKButton, { startIcon: /* @__PURE__ */ jsx2(AddIcon, {}), onClick: handleOpenCreate, children: "New Campaign" })
2382
+ }
2383
+ )
2384
+ ] })
2385
+ }
2386
+ ),
2387
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", flexDirection: { xs: "column", md: "row" }, gap: 1.5, p: 1.5 }, children: [
2388
+ /* @__PURE__ */ jsx2(
2389
+ Paper,
2390
+ {
2391
+ elevation: 0,
2392
+ sx: {
2393
+ width: campaignListCollapsed ? { xs: "100%", md: 48 } : { xs: "100%", md: 280, lg: 320 },
2394
+ minWidth: campaignListCollapsed ? { xs: "auto", md: 48 } : { xs: "auto", md: 240 },
2395
+ flexShrink: 0,
2396
+ borderRadius: "16px",
2397
+ display: "flex",
2398
+ flexDirection: "column",
2399
+ maxHeight: { xs: campaignListCollapsed ? "auto" : 260, md: "calc(100vh - 160px)" },
2400
+ overflow: "hidden",
2401
+ border: "1px solid #e0e0e0",
2402
+ boxShadow: "0 1px 3px rgba(0,0,0,0.08)",
2403
+ transition: "width 0.2s ease, min-width 0.2s ease"
2404
+ },
2405
+ children: campaignListCollapsed ? /* @__PURE__ */ jsxs(Box, { sx: {
2406
+ display: "flex",
2407
+ flexDirection: { xs: "row", md: "column" },
2408
+ alignItems: "center",
2409
+ gap: 0.75,
2410
+ p: 0.75,
2411
+ height: "100%",
2412
+ overflowY: { xs: "visible", md: "auto" },
2413
+ overflowX: { xs: "auto", md: "visible" }
2414
+ }, children: [
2415
+ /* @__PURE__ */ jsx2(Tooltip, { title: "Expand campaigns", arrow: true, placement: "right", children: /* @__PURE__ */ jsx2(
2416
+ IconButton,
2417
+ {
2418
+ size: "small",
2419
+ onClick: () => setCampaignListCollapsed(false),
2420
+ sx: {
2421
+ color: "#1A5F6C",
2422
+ backgroundColor: "#f0f7f8",
2423
+ flexShrink: 0,
2424
+ "&:hover": { backgroundColor: "#e0eff1" }
2425
+ },
2426
+ children: /* @__PURE__ */ jsx2(ChevronRightIcon, { fontSize: "small" })
2427
+ }
2428
+ ) }),
2429
+ visibleCampaigns.map((c, idx) => {
2430
+ var _a2;
2431
+ const isSel = c.id === selectedId;
2432
+ const status = (c.status || "draft").toLowerCase();
2433
+ const statusColor = (_a2 = STATUS_COLORS[status]) != null ? _a2 : "#9e9e9e";
2434
+ return /* @__PURE__ */ jsx2(
2435
+ Tooltip,
2436
+ {
2437
+ arrow: true,
2438
+ placement: "right",
2439
+ title: `${c.name} \u2022 ${c.status || "draft"}`,
2440
+ children: /* @__PURE__ */ jsx2(
2441
+ Box,
2442
+ {
2443
+ onClick: () => handleSelectCampaign(c.id),
2444
+ sx: {
2445
+ width: 32,
2446
+ height: 32,
2447
+ borderRadius: "8px",
2448
+ display: "flex",
2449
+ alignItems: "center",
2450
+ justifyContent: "center",
2451
+ cursor: "pointer",
2452
+ flexShrink: 0,
2453
+ backgroundColor: isSel ? "#fff" : "#fafafa",
2454
+ color: "#333",
2455
+ fontFamily: "poppins, Arial, sans-serif",
2456
+ fontWeight: 700,
2457
+ fontSize: "0.8rem",
2458
+ borderLeft: `3px solid ${statusColor}`,
2459
+ boxShadow: isSel ? `-3px 0 8px ${statusColor}66` : `-2px 0 4px ${statusColor}33`,
2460
+ transition: "box-shadow 0.15s ease",
2461
+ "&:hover": {
2462
+ boxShadow: `-3px 0 8px ${statusColor}80`
2463
+ }
2464
+ },
2465
+ children: idx + 1
2466
+ }
2467
+ )
2468
+ },
2469
+ c.id
2470
+ );
2471
+ })
2472
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
2473
+ /* @__PURE__ */ jsxs(Box, { sx: {
2474
+ display: "flex",
2475
+ alignItems: "center",
2476
+ justifyContent: "space-between",
2477
+ px: 2,
2478
+ py: 1.25,
2479
+ borderBottom: "1px solid #eee",
2480
+ backgroundColor: "#fafafa",
2481
+ gap: 1
2482
+ }, children: [
2483
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.5, minWidth: 0 }, children: [
2484
+ /* @__PURE__ */ jsx2(Tooltip, { title: "Minimize", arrow: true, children: /* @__PURE__ */ jsx2(
2485
+ IconButton,
2486
+ {
2487
+ size: "small",
2488
+ onClick: () => setCampaignListCollapsed(true),
2489
+ sx: { p: 0.5, color: "#666" },
2490
+ children: /* @__PURE__ */ jsx2(ChevronLeftIcon, { fontSize: "small" })
2491
+ }
2492
+ ) }),
2493
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontWeight: 700, fontSize: "0.95rem", color: "#333", fontFamily: "poppins, Arial, sans-serif" }, children: "Campaigns" })
2494
+ ] }),
2495
+ /* @__PURE__ */ jsx2(
2496
+ FormControlLabel,
2497
+ {
2498
+ control: /* @__PURE__ */ jsx2(
2499
+ Checkbox,
2500
+ {
2501
+ size: "small",
2502
+ checked: showArchived,
2503
+ onChange: (e) => setShowArchived(e.target.checked),
2504
+ sx: { p: 0.5 }
2505
+ }
2506
+ ),
2507
+ label: /* @__PURE__ */ jsx2(Typography, { sx: { fontSize: "0.78rem", color: "#666" }, children: "Show archived" }),
2508
+ sx: { mr: 0 }
2509
+ }
2510
+ )
2511
+ ] }),
2512
+ /* @__PURE__ */ jsx2(Box, { sx: { flex: 1, overflow: "auto", p: 1 }, children: loading ? /* @__PURE__ */ jsx2(Box, { sx: { display: "flex", justifyContent: "center", py: 4 }, children: /* @__PURE__ */ jsx2(CircularProgress, { size: 24, sx: { color: "#1A5F6C" } }) }) : visibleCampaigns.length === 0 ? /* @__PURE__ */ jsx2(Typography, { sx: { textAlign: "center", py: 3, color: "#999", fontSize: "0.85rem" }, children: "No campaigns" }) : visibleCampaigns.map((c) => {
2513
+ var _a2, _b2;
2514
+ const isSel = c.id === selectedId;
2515
+ const wStr = `${((_a2 = c.startTime) == null ? void 0 : _a2.slice(0, 5)) || "09:00"}\u2013${((_b2 = c.endTime) == null ? void 0 : _b2.slice(0, 5)) || "17:00"}`;
2516
+ return /* @__PURE__ */ jsxs(
2517
+ Paper,
2518
+ {
2519
+ elevation: 0,
2520
+ onClick: () => handleSelectCampaign(c.id),
2521
+ sx: isSel ? campaignCardSelectedSx : __spreadProps(__spreadValues({}, campaignCardBaseSx), {
2522
+ "&:hover": { borderColor: "#1A5F6C", backgroundColor: "#f5fafb", boxShadow: "0 2px 6px rgba(26,95,108,0.1)" }
2523
+ }),
2524
+ children: [
2525
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", alignItems: "center", mb: 0.5 }, children: [
2526
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontWeight: 600, fontSize: "0.88rem", color: "#1a1a1a", fontFamily: "poppins, Arial, sans-serif" }, children: c.name }),
2527
+ /* @__PURE__ */ jsx2(Chip, { label: c.status || "draft", size: "small", sx: statusChipSx(c.status) })
2528
+ ] }),
2529
+ /* @__PURE__ */ jsxs(Typography, { sx: { fontSize: "0.73rem", color: "#999", fontFamily: "poppins, Arial, sans-serif" }, children: [
2530
+ c.dialingMode,
2531
+ " \xB7 TZ: ",
2532
+ c.timezone || "Etc/UTC",
2533
+ " \xB7 ",
2534
+ wStr
2535
+ ] })
2536
+ ]
2537
+ },
2538
+ c.id
2539
+ );
2540
+ }) })
2541
+ ] })
2542
+ }
2543
+ ),
2544
+ /* @__PURE__ */ jsx2(Box, { sx: { flex: 1, display: "flex", flexDirection: "column", gap: 1.5, minWidth: 0, overflow: "hidden" }, children: !sc ? /* @__PURE__ */ jsx2(
2545
+ Paper,
2546
+ {
2547
+ elevation: 0,
2548
+ sx: {
2549
+ borderRadius: "16px",
2550
+ display: "flex",
2551
+ alignItems: "center",
2552
+ justifyContent: "center",
2553
+ minHeight: 200,
2554
+ border: "2px dashed #d0d0d0",
2555
+ backgroundColor: "#fafafa"
2556
+ },
2557
+ children: /* @__PURE__ */ jsxs(Box, { sx: { textAlign: "center" }, children: [
2558
+ /* @__PURE__ */ jsx2(SettingsIcon, { sx: { fontSize: 40, color: "#ccc", mb: 1 } }),
2559
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontSize: "0.95rem", color: "#999", fontFamily: "poppins, Arial, sans-serif" }, children: "Select a campaign to view details" })
2560
+ ] })
2561
+ }
2562
+ ) : /* @__PURE__ */ jsxs(Fragment, { children: [
2563
+ /* @__PURE__ */ jsxs(
2564
+ Paper,
2565
+ {
2566
+ elevation: 0,
2567
+ sx: {
2568
+ borderRadius: "16px",
2569
+ p: { xs: 1.5, sm: 2.5 },
2570
+ border: "1px solid #e0e0e0",
2571
+ boxShadow: "0 1px 3px rgba(0,0,0,0.08)"
2572
+ },
2573
+ children: [
2574
+ /* @__PURE__ */ jsxs(Box, { sx: {
2575
+ display: "flex",
2576
+ alignItems: { xs: "flex-start", sm: "center" },
2577
+ justifyContent: "space-between",
2578
+ flexWrap: "wrap",
2579
+ gap: 1,
2580
+ mb: 2
2581
+ }, children: [
2582
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, flexWrap: "wrap" }, children: [
2583
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontWeight: 700, fontSize: { xs: "1rem", sm: "1.2rem" }, color: "#1a1a1a", fontFamily: "poppins, Arial, sans-serif" }, children: sc.name }),
2584
+ /* @__PURE__ */ jsx2(Chip, { label: sc.status || "draft", size: "small", sx: statusChipSx(sc.status) })
2585
+ ] }),
2586
+ !scArchived && /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", gap: 1, flexWrap: "wrap" }, children: [
2587
+ /* @__PURE__ */ jsx2(
2588
+ SDKPermissionGuard,
2589
+ {
2590
+ permissions: [
2591
+ SDK_PERMISSIONS.CAMPAIGNS_UPDATE,
2592
+ SDK_PERMISSIONS.CAMPAIGNS_MANAGE
2593
+ ],
2594
+ showFallback: false,
2595
+ children: /* @__PURE__ */ jsx2(
2596
+ SDKButton,
2597
+ {
2598
+ variant: "outlined",
2599
+ startIcon: /* @__PURE__ */ jsx2(EditIcon, {}),
2600
+ onClick: () => handleOpenEdit(sc),
2601
+ children: "Edit"
2602
+ }
2603
+ )
2604
+ }
2605
+ ),
2606
+ (scDraft || scPaused) && /* @__PURE__ */ jsx2(
2607
+ SDKPermissionGuard,
2608
+ {
2609
+ permissions: [
2610
+ SDK_PERMISSIONS.CAMPAIGNS_CONTROL,
2611
+ SDK_PERMISSIONS.CAMPAIGNS_MANAGE
2612
+ ],
2613
+ showFallback: false,
2614
+ children: /* @__PURE__ */ jsx2(
2615
+ SDKButton,
2616
+ {
2617
+ startIcon: /* @__PURE__ */ jsx2(PlayArrowIcon, {}),
2618
+ onClick: () => handleStart(sc),
2619
+ sx: { backgroundColor: "#4caf50", "&:hover": { backgroundColor: "#388e3c" } },
2620
+ children: "Start"
2621
+ }
2622
+ )
2623
+ }
2624
+ ),
2625
+ scActive && /* @__PURE__ */ jsx2(
2626
+ SDKPermissionGuard,
2627
+ {
2628
+ permissions: [
2629
+ SDK_PERMISSIONS.CAMPAIGNS_CONTROL,
2630
+ SDK_PERMISSIONS.CAMPAIGNS_MANAGE
2631
+ ],
2632
+ showFallback: false,
2633
+ children: /* @__PURE__ */ jsx2(
2634
+ SDKButton,
2635
+ {
2636
+ startIcon: /* @__PURE__ */ jsx2(PauseIcon, {}),
2637
+ onClick: () => handlePause(sc),
2638
+ sx: { backgroundColor: "#ff9800", boxShadow: "0 2px 8px rgba(255,152,0,0.25)", "&:hover": { backgroundColor: "#f57c00" } },
2639
+ children: "Pause"
2640
+ }
2641
+ )
2642
+ }
2643
+ ),
2644
+ /* @__PURE__ */ jsx2(
2645
+ SDKPermissionGuard,
2646
+ {
2647
+ permissions: [
2648
+ SDK_PERMISSIONS.CAMPAIGNS_DELETE,
2649
+ SDK_PERMISSIONS.CAMPAIGNS_MANAGE
2650
+ ],
2651
+ showFallback: false,
2652
+ children: /* @__PURE__ */ jsx2(
2653
+ SDKButton,
2654
+ {
2655
+ variant: "danger",
2656
+ startIcon: /* @__PURE__ */ jsx2(ArchiveIcon, {}),
2657
+ onClick: () => {
2658
+ setArchiveTarget(sc);
2659
+ setArchiveOpen(true);
2660
+ },
2661
+ children: "Archive"
2662
+ }
2663
+ )
2664
+ }
2665
+ )
2666
+ ] })
2667
+ ] }),
2668
+ sc.description && /* @__PURE__ */ jsx2(Typography, { sx: { fontSize: "0.85rem", color: "#666", mb: 1.5, fontFamily: "poppins, Arial, sans-serif", lineHeight: 1.5 }, children: sc.description }),
2669
+ /* @__PURE__ */ jsx2(
2670
+ Box,
2671
+ {
2672
+ sx: {
2673
+ overflowX: "auto",
2674
+ pb: 0.5,
2675
+ "&::-webkit-scrollbar": { height: 6 },
2676
+ "&::-webkit-scrollbar-track": { backgroundColor: "#f0f0f0", borderRadius: 3 },
2677
+ "&::-webkit-scrollbar-thumb": {
2678
+ backgroundColor: "#c0c0c0",
2679
+ borderRadius: 3,
2680
+ "&:hover": { backgroundColor: "#a0a0a0" }
2681
+ }
2682
+ },
2683
+ children: /* @__PURE__ */ jsx2(
2684
+ Box,
2685
+ {
2686
+ sx: {
2687
+ display: "flex",
2688
+ flexWrap: "nowrap",
2689
+ gap: 1.5
2690
+ },
2691
+ children: [
2692
+ {
2693
+ accent: "#1565c0",
2694
+ fields: [
2695
+ { label: "Type", value: sc.campaignType || "N/A" },
2696
+ { label: "Mode", value: sc.dialingMode || "N/A" }
2697
+ ]
2698
+ },
2699
+ {
2700
+ accent: "#2e7d32",
2701
+ fields: [
2702
+ { label: "Agent", value: sc.agentType || "HUMAN" },
2703
+ { label: "Dialer", value: (leadsMeta == null ? void 0 : leadsMeta.isDialerEnabled) ? "Enabled" : "Disabled" }
2704
+ ]
2705
+ },
2706
+ {
2707
+ accent: "#c62828",
2708
+ fields: [
2709
+ { label: "Priority", value: leadPriorityChipSx(sc.priority).label },
2710
+ { label: "Max Concurrent", value: String((_f = sc.maxConcurrentCalls) != null ? _f : 1) }
2711
+ ]
2712
+ },
2713
+ {
2714
+ accent: "#283593",
2715
+ fields: [
2716
+ { label: "Retry", value: `${(_g = sc.retryIntervalMinutes) != null ? _g : 15}min / ${(_h = sc.maxAttempts) != null ? _h : 3} attempts` },
2717
+ { label: "Leads", value: `${(_i = sc.totalLeads) != null ? _i : 0} total / ${(_j = sc.completedLeads) != null ? _j : 0} completed / ${(_k = sc.successfulCalls) != null ? _k : 0} success` }
2718
+ ]
2719
+ }
2720
+ ].map((card, idx) => /* @__PURE__ */ jsx2(
2721
+ Box,
2722
+ {
2723
+ sx: {
2724
+ display: "flex",
2725
+ flexDirection: "column",
2726
+ gap: 0.5,
2727
+ px: 1.5,
2728
+ py: 1,
2729
+ borderRadius: "10px",
2730
+ backgroundColor: "#fafafa",
2731
+ borderLeft: `3px solid ${card.accent}`,
2732
+ flex: "0 0 auto",
2733
+ minWidth: 180
2734
+ },
2735
+ children: card.fields.map((field) => /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 0.75 }, children: [
2736
+ /* @__PURE__ */ jsxs(Typography, { sx: { fontFamily: "poppins, Arial, sans-serif", fontSize: "0.72rem", fontWeight: 600, color: "#888", whiteSpace: "nowrap", flexShrink: 0 }, children: [
2737
+ field.label,
2738
+ ":"
2739
+ ] }),
2740
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontFamily: "poppins, Arial, sans-serif", fontSize: "0.75rem", fontWeight: 700, color: "#333", whiteSpace: "nowrap" }, children: field.value })
2741
+ ] }, field.label))
2742
+ },
2743
+ idx
2744
+ ))
2745
+ }
2746
+ )
2747
+ }
2748
+ )
2749
+ ]
2750
+ }
2751
+ ),
2752
+ /* @__PURE__ */ jsx2(SDKPermissionGuard, { permission: SDK_PERMISSIONS.CAMPAIGNS_LEADS_READ, showFallback: false, children: /* @__PURE__ */ jsxs(
2753
+ Paper,
2754
+ {
2755
+ elevation: 0,
2756
+ sx: {
2757
+ borderRadius: "16px",
2758
+ overflow: "hidden",
2759
+ border: "1px solid #e0e0e0",
2760
+ boxShadow: "0 1px 3px rgba(0,0,0,0.08)"
2761
+ },
2762
+ children: [
2763
+ /* @__PURE__ */ jsxs(Box, { sx: {
2764
+ display: "flex",
2765
+ flexDirection: "column",
2766
+ gap: 1.25,
2767
+ px: { xs: 1.5, sm: 2 },
2768
+ py: 1.5,
2769
+ borderBottom: "1px solid #eee",
2770
+ backgroundColor: "#fafafa"
2771
+ }, children: [
2772
+ /* @__PURE__ */ jsxs(Box, { sx: {
2773
+ display: "flex",
2774
+ alignItems: { xs: "flex-start", sm: "center" },
2775
+ justifyContent: "space-between",
2776
+ flexDirection: { xs: "column", sm: "row" },
2777
+ gap: 1
2778
+ }, children: [
2779
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, flexWrap: "wrap" }, children: [
2780
+ /* @__PURE__ */ jsx2(Typography, { sx: { fontWeight: 700, fontSize: "1rem", color: "#1a1a1a", fontFamily: "poppins, Arial, sans-serif" }, children: "Leads" }),
2781
+ /* @__PURE__ */ jsx2(
2782
+ SDKPermissionGuard,
2783
+ {
2784
+ permissions: [
2785
+ SDK_PERMISSIONS.CAMPAIGNS_LEADS_IMPORT
2786
+ ],
2787
+ showFallback: false,
2788
+ children: /* @__PURE__ */ jsx2(SDKButton, { variant: "outlined", onClick: () => setImportOpen(true), disabled: scArchived, startIcon: /* @__PURE__ */ jsx2(UploadFileIcon, { sx: { fontSize: 15 } }), size: "small", sx: { height: 36 }, children: "Import Leads" })
2789
+ }
2790
+ ),
2791
+ /* @__PURE__ */ jsx2(
2792
+ SDKPermissionGuard,
2793
+ {
2794
+ permissions: [
2795
+ SDK_PERMISSIONS.CAMPAIGNS_LEADS_CREATE
2796
+ ],
2797
+ showFallback: false,
2798
+ children: /* @__PURE__ */ jsx2(SDKButton, { variant: "primary", onClick: () => setAddLeadOpen(true), disabled: scArchived, startIcon: /* @__PURE__ */ jsx2(AddIcon, { sx: { fontSize: 15 } }), size: "small", sx: { height: 36 }, children: "Add Lead" })
2799
+ }
2800
+ )
2801
+ ] }),
2802
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: 1, flexWrap: "wrap", width: { xs: "100%", sm: "auto" } }, children: [
2803
+ /* @__PURE__ */ jsx2(
2804
+ OutlinedInput,
2805
+ {
2806
+ size: "small",
2807
+ value: leadSearch,
2808
+ onChange: (e) => {
2809
+ setLeadSearch(e.target.value);
2810
+ setLeadPage(0);
2811
+ },
2812
+ placeholder: "Search number...",
2813
+ sx: { width: { xs: "100%", sm: 200 }, fontSize: "0.85rem", height: 36, borderRadius: "20px" },
2814
+ startAdornment: /* @__PURE__ */ jsx2(InputAdornment, { position: "start", children: /* @__PURE__ */ jsx2(SearchIcon, { sx: { fontSize: 16, color: "#aaa" } }) })
2815
+ }
2816
+ ),
2817
+ /* @__PURE__ */ jsx2(FormControl, { size: "small", sx: { minWidth: 130 }, children: /* @__PURE__ */ jsx2(
2818
+ Select,
2819
+ {
2820
+ value: leadStatusFilter,
2821
+ onChange: (e) => {
2822
+ setLeadStatusFilter(e.target.value);
2823
+ setLeadPage(0);
2824
+ },
2825
+ sx: { height: 36, borderRadius: "30px", fontSize: "0.85rem" },
2826
+ children: LEAD_STATUSES.map((s) => /* @__PURE__ */ jsx2(MenuItem, { value: s, children: s }, s))
2827
+ }
2828
+ ) })
2829
+ ] })
2830
+ ] }),
2831
+ /* @__PURE__ */ jsxs(Box, { sx: { display: "flex", alignItems: "center", justifyContent: "space-between", gap: 1, flexWrap: "wrap" }, children: [
2832
+ /* @__PURE__ */ jsxs(
2833
+ Box,
2834
+ {
2835
+ sx: {
2836
+ display: "flex",
2837
+ alignItems: "center",
2838
+ gap: 0.75,
2839
+ flexWrap: "wrap",
2840
+ px: 1,
2841
+ py: 0.5,
2842
+ borderRadius: "30px",
2843
+ border: "1px solid #e0e4ea",
2844
+ backgroundColor: "#f7f9fb"
2845
+ },
2846
+ children: [
2847
+ /* @__PURE__ */ jsx2(LocalizationProvider, { dateAdapter: AdapterDayjs, children: /* @__PURE__ */ jsx2(
2848
+ DateRangePicker,
2849
+ {
2850
+ startDate: leadStartDate,
2851
+ endDate: leadEndDate,
2852
+ onStartChange: (v) => {
2853
+ setLeadStartDate(v);
2854
+ setLeadPage(0);
2855
+ },
2856
+ onEndChange: (v) => {
2857
+ setLeadEndDate(v);
2858
+ setLeadPage(0);
2859
+ }
2860
+ }
2861
+ ) }),
2862
+ (leadStartDate || leadEndDate) && /* @__PURE__ */ jsx2(Tooltip, { title: "Clear dates", children: /* @__PURE__ */ jsx2(IconButton, { size: "small", onClick: clearLeadDates, sx: { p: 0.5, color: "#7a8599" }, children: /* @__PURE__ */ jsx2(ClearIcon, { sx: { fontSize: 16 } }) }) })
2863
+ ]
2864
+ }
2865
+ ),
2866
+ /* @__PURE__ */ jsx2(
2867
+ SDKPermissionGuard,
2868
+ {
2869
+ permissions: [
2870
+ SDK_PERMISSIONS.CAMPAIGNS_READ,
2871
+ SDK_PERMISSIONS.CAMPAIGNS_MANAGE
2872
+ ],
2873
+ showFallback: false,
2874
+ children: /* @__PURE__ */ jsx2(SDKButton, { variant: "primary", onClick: handleExport, disabled: leadsLoading || leadTotal === 0, startIcon: /* @__PURE__ */ jsx2(DownloadIcon, { sx: { fontSize: 15 } }), size: "small", sx: { height: 36 }, children: "Export Excel" })
2875
+ }
2876
+ )
2877
+ ] })
2878
+ ] }),
2879
+ /* @__PURE__ */ jsx2(Box, { sx: {
2880
+ overflowX: "auto",
2881
+ overflowY: "visible",
2882
+ WebkitOverflowScrolling: "touch",
2883
+ "&::-webkit-scrollbar": { height: 4 },
2884
+ "&::-webkit-scrollbar-thumb": { backgroundColor: "#ccc", borderRadius: 2 }
2885
+ }, children: /* @__PURE__ */ jsxs(Table, { size: "small", sx: { minWidth: 980 }, children: [
2886
+ /* @__PURE__ */ jsx2(TableHead, { children: /* @__PURE__ */ jsx2(TableRow, { sx: { backgroundColor: "#f1f1f1" }, children: [
2887
+ "Number",
2888
+ "Status",
2889
+ "Priority",
2890
+ "Source",
2891
+ "Call ID",
2892
+ "Queue Name",
2893
+ "Attempts",
2894
+ "Created At",
2895
+ "Last Attempt",
2896
+ "Next Attempt",
2897
+ "Last Outcome",
2898
+ "Completed At",
2899
+ "Notes",
2900
+ "Outcome",
2901
+ ...showVoicemail ? ["Voice Mail"] : [],
2902
+ "Actions"
2903
+ ].map((col) => /* @__PURE__ */ jsx2(TableCell, { sx: __spreadValues(__spreadValues({}, headCellSx), col === "Actions" ? { textAlign: "center" } : {}), children: col }, col)) }) }),
2904
+ /* @__PURE__ */ jsx2(TableBody, { children: leadsLoading ? /* @__PURE__ */ jsx2(TableRow, { children: /* @__PURE__ */ jsx2(TableCell, { colSpan: showVoicemail ? 16 : 15, align: "center", sx: { py: 4 }, children: /* @__PURE__ */ jsx2(CircularProgress, { size: 24, sx: { color: "#1A5F6C" } }) }) }) : leads.length === 0 ? /* @__PURE__ */ jsx2(TableRow, { children: /* @__PURE__ */ jsx2(
2905
+ TableCell,
2906
+ {
2907
+ colSpan: showVoicemail ? 16 : 15,
2908
+ align: "center",
2909
+ sx: { py: 4, color: "#999", fontFamily: "poppins, Arial, sans-serif" },
2910
+ children: 'No leads found. Add leads using "Add Lead" or "Import Leads".'
2911
+ }
2912
+ ) }) : leads.map((lead) => {
2913
+ var _a2;
2914
+ const nonDeletable = ["IN_PROGRESS", "COMPLETED", "FAILED", "DO_NOT_CALL"];
2915
+ const leadStatus = (lead.status || "").toUpperCase();
2916
+ const deleteDisabled = nonDeletable.includes(leadStatus);
2917
+ const isDialerEnabled = !!(leadsMeta == null ? void 0 : leadsMeta.isDialerEnabled);
2918
+ const isCompleted = leadStatus === "COMPLETED";
2919
+ const isInProgress = leadStatus === "IN_PROGRESS";
2920
+ const isDialable = isDialerEnabled && hasOutboundPermission && isAgentIdle && !isCompleted && !isInProgress && dialLoading !== lead.id;
2921
+ const dialTooltip = !isDialerEnabled ? "Dialer is not enabled" : !hasOutboundPermission ? "No outbound call permission" : isCompleted ? "Lead is completed" : isInProgress ? "Lead is in progress" : !isAgentIdle ? "Agent is not idle" : dialLoading === lead.id ? "Dialing\u2026" : `Call ${lead.phoneNumber}`;
2922
+ const { chip: prioChip, label: prioLabel } = leadPriorityChipSx(lead.priority);
2923
+ return /* @__PURE__ */ jsxs(TableRow, { sx: tableRowSx, children: [
2924
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.phoneNumber }),
2925
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: /* @__PURE__ */ jsx2(Chip, { label: lead.status || "pending", size: "small", sx: leadStatusChipSx(lead.status) }) }),
2926
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: /* @__PURE__ */ jsx2(Chip, { label: prioLabel, size: "small", sx: prioChip }) }),
2927
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.source || "" }),
2928
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { maxWidth: 140, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }), children: /* @__PURE__ */ jsx2(Tooltip, { title: lead.originalCallId || "", children: /* @__PURE__ */ jsx2("span", { children: lead.originalCallId || "" }) }) }),
2929
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.queueName || "" }),
2930
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: (_a2 = lead.attemptCount) != null ? _a2 : 0 }),
2931
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { whiteSpace: "nowrap" }), children: lead.createdAt ? new Date(lead.createdAt).toLocaleString() : "" }),
2932
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { whiteSpace: "nowrap" }), children: lead.lastAttemptAt ? new Date(lead.lastAttemptAt).toLocaleString() : "" }),
2933
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { whiteSpace: "nowrap" }), children: lead.nextAttemptAt ? new Date(lead.nextAttemptAt).toLocaleString() : "" }),
2934
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.lastOutcome || "" }),
2935
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { whiteSpace: "nowrap" }), children: lead.completedAt ? new Date(lead.completedAt).toLocaleString() : "" }),
2936
+ /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { maxWidth: 150, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }), children: lead.notes ? /* @__PURE__ */ jsx2(Tooltip, { title: lead.notes, arrow: true, placement: "top", children: /* @__PURE__ */ jsx2("span", { children: lead.notes }) }) : "" }),
2937
+ /* @__PURE__ */ jsx2(TableCell, { sx: bodyCellSx, children: lead.lastReason || "" }),
2938
+ showVoicemail && /* @__PURE__ */ jsx2(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { minWidth: 180 }), children: lead.originalCallId ? /* @__PURE__ */ jsx2(CallRecording, { callUuid: lead.originalCallId, recordingPath: lead.voicemail, iconOnly: true }) : "" }),
2939
+ /* @__PURE__ */ jsxs(TableCell, { sx: __spreadProps(__spreadValues({}, bodyCellSx), { textAlign: "center", whiteSpace: "nowrap" }), children: [
2940
+ /* @__PURE__ */ jsx2(Tooltip, { title: dialTooltip, children: /* @__PURE__ */ jsx2("span", { children: /* @__PURE__ */ jsx2(
2941
+ IconButton,
2942
+ {
2943
+ size: "small",
2944
+ onClick: () => handleDialPreview(lead.id),
2945
+ disabled: !isDialable,
2946
+ sx: {
2947
+ color: isDialable ? "#2e7d32" : "#bdbdbd",
2948
+ backgroundColor: isDialable ? "#e8f5e9" : "transparent",
2949
+ borderRadius: "50%",
2950
+ transition: "all 0.2s ease-in-out",
2951
+ "&:hover": {
2952
+ backgroundColor: isDialable ? "#43a047" : "transparent",
2953
+ color: isDialable ? "#fff" : "#bdbdbd",
2954
+ transform: isDialable ? "scale(1.2)" : "none",
2955
+ boxShadow: isDialable ? "0 0 8px rgba(67,160,71,0.5)" : "none"
2956
+ }
2957
+ },
2958
+ children: dialLoading === lead.id ? /* @__PURE__ */ jsx2(CircularProgress, { size: 16 }) : /* @__PURE__ */ jsx2(PhoneIcon, { sx: { fontSize: 18 } })
2959
+ }
2960
+ ) }) }),
2961
+ /* @__PURE__ */ jsx2(Tooltip, { title: lead.latestCallId ? "View call details" : "No call data available", children: /* @__PURE__ */ jsx2("span", { children: /* @__PURE__ */ jsx2(
2962
+ IconButton,
2963
+ {
2964
+ size: "small",
2965
+ onClick: () => handleViewCallData(lead),
2966
+ disabled: !lead.latestCallId,
2967
+ sx: {
2968
+ ml: 0.5,
2969
+ color: lead.latestCallId ? "#1A5F6C" : "#bdbdbd",
2970
+ "&:hover": { backgroundColor: "transparent" }
2971
+ },
2972
+ children: /* @__PURE__ */ jsx2(VisibilityOutlinedIcon, { sx: { fontSize: 18 } })
2973
+ }
2974
+ ) }) }),
2975
+ /* @__PURE__ */ jsx2(
2976
+ SDKPermissionGuard,
2977
+ {
2978
+ permissions: [
2979
+ SDK_PERMISSIONS.CAMPAIGNS_LEADS_DELETE
2980
+ ],
2981
+ showFallback: false,
2982
+ children: /* @__PURE__ */ jsx2(Tooltip, { title: deleteDisabled ? `Cannot delete \u2014 status is ${leadStatus.toLowerCase().replace("_", " ")}` : `Delete lead ${lead.phoneNumber}`, children: /* @__PURE__ */ jsx2("span", { children: /* @__PURE__ */ jsx2(
2983
+ IconButton,
2984
+ {
2985
+ size: "small",
2986
+ onClick: () => {
2987
+ setDeleteLeadTarget(lead);
2988
+ setDeleteLeadOpen(true);
2989
+ },
2990
+ disabled: deleteDisabled,
2991
+ sx: {
2992
+ ml: 0.5,
2993
+ color: deleteDisabled ? "#bdbdbd" : "#c62828",
2994
+ backgroundColor: deleteDisabled ? "transparent" : "#ffebee",
2995
+ borderRadius: "50%",
2996
+ transition: "all 0.2s ease-in-out",
2997
+ "&:hover": {
2998
+ backgroundColor: deleteDisabled ? "transparent" : "#d32f2f",
2999
+ color: deleteDisabled ? "#bdbdbd" : "#fff",
3000
+ transform: deleteDisabled ? "none" : "scale(1.2)",
3001
+ boxShadow: deleteDisabled ? "none" : "0 0 8px rgba(211,47,47,0.5)"
3002
+ }
3003
+ },
3004
+ children: /* @__PURE__ */ jsx2(DeleteIcon, { sx: { fontSize: 18 } })
3005
+ }
3006
+ ) }) })
3007
+ }
3008
+ )
3009
+ ] })
3010
+ ] }, lead.id);
3011
+ }) })
3012
+ ] }) }),
3013
+ leads.length > 0 && /* @__PURE__ */ jsx2(
3014
+ TablePagination,
3015
+ {
3016
+ component: "div",
3017
+ count: leadTotal,
3018
+ page: leadPage,
3019
+ rowsPerPage: leadRowsPerPage,
3020
+ onPageChange: (_, p) => {
3021
+ setLeadPage(p);
3022
+ refetchLeads(p);
3023
+ },
3024
+ onRowsPerPageChange: (e) => {
3025
+ setLeadRowsPerPage(parseInt(e.target.value, 10));
3026
+ setLeadPage(0);
3027
+ },
3028
+ rowsPerPageOptions: [10, 15, 25, 50, 100],
3029
+ sx: {
3030
+ fontSize: "0.82rem",
3031
+ "& .MuiTablePagination-toolbar": { minHeight: 40, px: 1 },
3032
+ "& .MuiTablePagination-selectLabel, & .MuiTablePagination-displayedRows": { fontSize: "0.82rem" }
3033
+ }
3034
+ }
3035
+ )
3036
+ ]
3037
+ }
3038
+ ) })
3039
+ ] }) })
3040
+ ] }),
3041
+ /* @__PURE__ */ jsx2(
3042
+ CampaignDialog,
3043
+ {
3044
+ open: dialogOpen,
3045
+ editingCampaign,
3046
+ formData,
3047
+ setFormData,
3048
+ saving,
3049
+ onSave: handleSave,
3050
+ onClose: () => setDialogOpen(false),
3051
+ parentQueueNameMap: queueNameMap,
3052
+ onQueuesRefreshed: handleQueuesRefreshed,
3053
+ onLeadsChange: () => {
3054
+ fetchCampaigns();
3055
+ if (selectedId) refetchLeads();
3056
+ }
3057
+ }
3058
+ ),
3059
+ /* @__PURE__ */ jsx2(
3060
+ AddLeadDialog,
3061
+ {
3062
+ open: addLeadOpen,
3063
+ data: addLeadData,
3064
+ onChange: setAddLeadData,
3065
+ saving: addLeadSaving,
3066
+ onSave: handleAddLead,
3067
+ onClose: () => {
3068
+ setAddLeadOpen(false);
3069
+ setAddLeadData({ phoneNumber: "", callerName: "", priority: 5 });
3070
+ }
3071
+ }
3072
+ ),
3073
+ /* @__PURE__ */ jsx2(
3074
+ ImportLeadsDialog,
3075
+ {
3076
+ open: importOpen,
3077
+ file: importFile,
3078
+ onFileChange: setImportFile,
3079
+ uploading: importing,
3080
+ onUpload: handleImport,
3081
+ onDownloadTemplate: handleDownloadTemplate,
3082
+ onClose: () => {
3083
+ setImportOpen(false);
3084
+ setImportFile(null);
3085
+ }
3086
+ }
3087
+ ),
3088
+ /* @__PURE__ */ jsx2(
3089
+ ConfirmDialog,
3090
+ {
3091
+ open: archiveOpen,
3092
+ title: "Archive Campaign",
3093
+ message: `Archive "${archiveTarget == null ? void 0 : archiveTarget.name}"? It will no longer run.`,
3094
+ loading: archiving,
3095
+ onConfirm: confirmArchive,
3096
+ onClose: () => {
3097
+ setArchiveOpen(false);
3098
+ setArchiveTarget(null);
3099
+ }
3100
+ }
3101
+ ),
3102
+ /* @__PURE__ */ jsx2(
3103
+ ConfirmDialog,
3104
+ {
3105
+ open: deleteLeadOpen,
3106
+ title: "Delete Lead",
3107
+ message: `Delete lead ${deleteLeadTarget == null ? void 0 : deleteLeadTarget.phoneNumber}? This cannot be undone.`,
3108
+ loading: deletingLead,
3109
+ onConfirm: confirmDeleteLead,
3110
+ onClose: () => {
3111
+ setDeleteLeadOpen(false);
3112
+ setDeleteLeadTarget(null);
3113
+ }
3114
+ }
3115
+ ),
3116
+ /* @__PURE__ */ jsx2(
3117
+ CallDataDialog,
3118
+ {
3119
+ open: callDataOpen,
3120
+ lead: callDataLead,
3121
+ data: callData,
3122
+ loading: callDataLoading,
3123
+ error: callDataError,
3124
+ onClose: () => {
3125
+ setCallDataOpen(false);
3126
+ setCallData(null);
3127
+ setCallDataError(null);
3128
+ setCallDataLead(null);
3129
+ }
3130
+ }
3131
+ )
3132
+ ] });
3133
+ });
3134
+ var Campaigns = () => /* @__PURE__ */ jsx2(SDKProvider, { children: /* @__PURE__ */ jsx2(CampaignsContent, {}) });
3135
+ var campaigns_default = Campaigns;
3136
+ export {
3137
+ campaigns_default as default
3138
+ };
3139
+ //# sourceMappingURL=campaigns-J7KIAATE.mjs.map