@enerex/template-studio 1.1.41 → 1.1.44

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.
@@ -1,92 +1,92 @@
1
- import { jsx as t, jsxs as c, Fragment as fe } from "react/jsx-runtime";
2
- import W, { useContext as Se, useEffect as L, useState as N, useRef as J, useCallback as xe, createContext as je, memo as qe, useMemo as re } from "react";
3
- import { QueryClient as Ue, QueryClientProvider as Ve, useQuery as he, useMutation as oe, useQueryClient as He } from "@tanstack/react-query";
4
- import be from "axios";
5
- import { Spinner as Ke } from "react-bootstrap";
6
- import { Controller as Ge, useForm as We } from "react-hook-form";
7
- import Le, { components as Pe } from "react-select";
8
- const Me = W.createContext(
1
+ import { jsx as t, jsxs as d, Fragment as ye } from "react/jsx-runtime";
2
+ import G, { useContext as ke, useEffect as L, useState as C, useRef as te, useCallback as Se, createContext as He, memo as ze, useMemo as ae } from "react";
3
+ import { QueryClient as Ge, QueryClientProvider as We, useQuery as ge, useMutation as ce, useQueryClient as Ye } from "@tanstack/react-query";
4
+ import we from "axios";
5
+ import { Spinner as Qe } from "react-bootstrap";
6
+ import { Controller as Xe, useForm as Je } from "react-hook-form";
7
+ import $e, { components as Ae } from "react-select";
8
+ const Fe = G.createContext(
9
9
  void 0
10
- ), ze = ({
10
+ ), Ze = ({
11
11
  children: e,
12
12
  configs: n
13
13
  }) => {
14
- const [s, a] = W.useState(n.clientId), [i, r] = W.useState(n.apiKey), [l, o] = W.useState(
14
+ const [r, a] = G.useState(n.clientId), [i, s] = G.useState(n.apiKey), [l, o] = G.useState(
15
15
  n.enerexIdentifier
16
- ), [d, y] = W.useState(n.projectId), [m, T] = W.useState(n.userEmail), [w, E] = W.useState(n.isAdmin), [A, h] = W.useState(n.meBaseUrl), [g, b] = W.useState(
16
+ ), [c, v] = G.useState(n.projectId), [E, I] = G.useState(n.userEmail), [b, x] = G.useState(n.isAdmin), [u, p] = G.useState(n.meBaseUrl), [T, h] = G.useState(
17
17
  n.defaultSelector
18
- ), p = (v) => {
19
- r(v.apiKey), a(v.clientId), y(v.projectId), o(v.enerexIdentifier), T(v.userEmail), E(v.isAdmin), b(v.defaultSelector), h(v.meBaseUrl);
18
+ ), y = (g) => {
19
+ s(g.apiKey), a(g.clientId), v(g.projectId), o(g.enerexIdentifier), I(g.userEmail), x(g.isAdmin), h(g.defaultSelector), p(g.meBaseUrl);
20
20
  };
21
21
  return /* @__PURE__ */ t(
22
- Me.Provider,
22
+ Fe.Provider,
23
23
  {
24
24
  value: {
25
- clientId: s,
25
+ clientId: r,
26
26
  apiKey: i,
27
- setConfiguration: p,
27
+ setConfiguration: y,
28
28
  enerexIdentifier: l,
29
- projectId: d,
30
- userEmail: m,
31
- isAdmin: w,
32
- defaultSelector: g,
33
- meBaseUrl: A
29
+ projectId: c,
30
+ userEmail: E,
31
+ isAdmin: b,
32
+ defaultSelector: T,
33
+ meBaseUrl: u
34
34
  },
35
35
  children: e
36
36
  }
37
37
  );
38
- }, q = () => {
39
- const e = Se(Me);
38
+ }, V = () => {
39
+ const e = ke(Fe);
40
40
  if (!e)
41
41
  throw new Error("widgetConfig must be used within a ConfigProvider");
42
42
  return e;
43
- }, Qe = ({
43
+ }, et = ({
44
44
  message: e,
45
45
  type: n = "info",
46
- duration: s = 3e3,
46
+ duration: r = 3e3,
47
47
  onClose: a
48
48
  }) => (L(() => {
49
- const i = setTimeout(a, s);
49
+ const i = setTimeout(a, r);
50
50
  return () => clearTimeout(i);
51
- }, [s, a]), /* @__PURE__ */ c("div", { className: `ts-toast ts-toast-${n}`, children: [
51
+ }, [r, a]), /* @__PURE__ */ d("div", { className: `ts-toast ts-toast-${n}`, children: [
52
52
  /* @__PURE__ */ t("span", { className: "ts-toast-message", children: e }),
53
53
  /* @__PURE__ */ t("button", { className: "ts-toast-close", onClick: a, children: "×" })
54
- ] })), Xe = () => {
55
- const [e, n] = N(null), s = J(null);
56
- return { showNotification: xe(
57
- (r, l = "info") => {
58
- s.current !== r && (s.current = r, n({ message: r, type: l }));
54
+ ] })), tt = () => {
55
+ const [e, n] = C(null), r = te(null);
56
+ return { showNotification: Se(
57
+ (s, l = "info") => {
58
+ r.current !== s && (r.current = s, n({ message: s, type: l }));
59
59
  },
60
60
  []
61
61
  ), NotificationRenderer: () => e ? /* @__PURE__ */ t(
62
- Qe,
62
+ et,
63
63
  {
64
64
  message: e.message,
65
65
  type: e.type,
66
66
  onClose: () => {
67
- s.current = null, n(null);
67
+ r.current = null, n(null);
68
68
  }
69
69
  }
70
70
  ) : null };
71
- }, Re = je(null), Ye = ({
71
+ }, Oe = He(null), nt = ({
72
72
  children: e
73
73
  }) => {
74
- const n = Xe();
75
- return /* @__PURE__ */ c(Re.Provider, { value: n, children: [
74
+ const n = tt();
75
+ return /* @__PURE__ */ d(Oe.Provider, { value: n, children: [
76
76
  e,
77
77
  /* @__PURE__ */ t(n.NotificationRenderer, {})
78
78
  ] });
79
- }, ke = () => {
80
- const e = Se(Re);
79
+ }, ve = () => {
80
+ const e = ke(Oe);
81
81
  if (!e)
82
82
  throw new Error(
83
83
  "useGlobalNotification must be used within NotificationProvider"
84
84
  );
85
85
  return e;
86
- }, Oe = (e = "", n) => ({ get: async (r, l) => {
86
+ }, je = (e = "", n) => ({ get: async (s, l) => {
87
87
  try {
88
- const o = await be.get(
89
- `${e}${r}`,
88
+ const o = await we.get(
89
+ `${e}${s}`,
90
90
  l ?? n
91
91
  );
92
92
  if (o.status === 200)
@@ -94,22 +94,22 @@ const Me = W.createContext(
94
94
  } catch (o) {
95
95
  throw o;
96
96
  }
97
- }, post: async (r, l, o) => {
97
+ }, post: async (s, l, o) => {
98
98
  try {
99
- const d = await be.post(
100
- `${e}${r}`,
99
+ const c = await we.post(
100
+ `${e}${s}`,
101
101
  l,
102
102
  o ?? n
103
103
  );
104
- if (d.status === 200)
105
- return d.data;
106
- } catch (d) {
107
- throw d;
104
+ if (c.status === 200)
105
+ return c.data;
106
+ } catch (c) {
107
+ throw c;
108
108
  }
109
- }, delete: async (r, l) => {
109
+ }, delete: async (s, l) => {
110
110
  try {
111
- const o = await be.delete(
112
- `${e}${r}`,
111
+ const o = await we.delete(
112
+ `${e}${s}`,
113
113
  l ?? n
114
114
  );
115
115
  if (o.status === 200 || o.status === 204)
@@ -117,7 +117,7 @@ const Me = W.createContext(
117
117
  } catch (o) {
118
118
  throw o;
119
119
  }
120
- } }), Be = W.createContext({
120
+ } }), qe = G.createContext({
121
121
  get: () => {
122
122
  throw new Error("HttpClientContext.get not implemented");
123
123
  },
@@ -127,20 +127,20 @@ const Me = W.createContext(
127
127
  delete: () => {
128
128
  throw new Error("HttpClientContext.delete not implemented");
129
129
  }
130
- }), Je = ({ children: e }) => {
131
- const { clientId: n, apiKey: s, isAdmin: a, meBaseUrl: i } = q(), r = {
130
+ }), rt = ({ children: e }) => {
131
+ const { clientId: n, apiKey: r, isAdmin: a, meBaseUrl: i } = V(), s = {
132
132
  headers: {
133
133
  client_id: n,
134
- "x-api-key": s,
134
+ "x-api-key": r,
135
135
  "Security-Context": a ? "admin" : "viewer"
136
136
  }
137
- }, { get: l, post: o, delete: d } = Oe(i, r);
138
- return /* @__PURE__ */ t(Be.Provider, { value: { get: l, post: o, delete: d }, children: e });
139
- }, Ze = ({ children: e }) => {
140
- const n = new Ue();
141
- return /* @__PURE__ */ t(Je, { children: /* @__PURE__ */ t(Ve, { client: n, children: e }) });
142
- }, z = () => {
143
- const e = Se(Be);
137
+ }, { get: l, post: o, delete: c } = je(i, s);
138
+ return /* @__PURE__ */ t(qe.Provider, { value: { get: l, post: o, delete: c }, children: e });
139
+ }, st = ({ children: e }) => {
140
+ const n = new Ge();
141
+ return /* @__PURE__ */ t(rt, { children: /* @__PURE__ */ t(We, { client: n, children: e }) });
142
+ }, Y = () => {
143
+ const e = ke(qe);
144
144
  if (e)
145
145
  return e;
146
146
  throw new Error("useHttpClient must be used within a HttpClientProvider");
@@ -154,56 +154,56 @@ const Me = W.createContext(
154
154
  markFavourite: "/Template/MarkFavourite/",
155
155
  deleteTemplate: "/Template/DeleteTemplate/",
156
156
  duplicateTemplate: "/Template/DuplicateTemplate/"
157
- }, et = () => {
158
- const e = z(), { enerexIdentifier: n, projectId: s } = q();
159
- return he({
157
+ }, at = () => {
158
+ const e = Y(), { enerexIdentifier: n, projectId: r } = V();
159
+ return ge({
160
160
  queryKey: ["getTemplatesList"],
161
161
  queryFn: async (i) => await e.get(
162
- `${Q.Template_list}${s}/${n}`
162
+ `${Q.Template_list}${r}/${n}`
163
163
  ),
164
164
  refetchOnWindowFocus: !1,
165
165
  refetchOnReconnect: !1,
166
166
  refetchOnMount: !1
167
167
  });
168
- }, tt = () => {
169
- const e = z(), { enerexIdentifier: n, projectId: s } = q();
170
- return he({
168
+ }, it = () => {
169
+ const e = Y(), { enerexIdentifier: n, projectId: r } = V();
170
+ return ge({
171
171
  queryKey: ["getTemplateTypes"],
172
172
  queryFn: async (i) => await e.get(
173
- `${Q.TemplateTypes}${n}/${s}`
173
+ `${Q.TemplateTypes}${n}/${r}`
174
174
  ),
175
175
  refetchOnWindowFocus: !1,
176
176
  refetchOnReconnect: !1,
177
177
  refetchOnMount: !1
178
178
  });
179
- }, nt = () => {
180
- const e = z(), { enerexIdentifier: n, projectId: s } = q();
181
- return oe({
179
+ }, lt = () => {
180
+ const e = Y(), { enerexIdentifier: n, projectId: r } = V();
181
+ return ce({
182
182
  mutationKey: ["getTemplate"],
183
183
  mutationFn: async ({ id: i }) => {
184
184
  if (i)
185
185
  return await e.get(
186
- `${Q.Template}${n}/${i}/${s}`
186
+ `${Q.Template}${n}/${i}/${r}`
187
187
  );
188
188
  }
189
189
  });
190
- }, se = ({
190
+ }, ie = ({
191
191
  size: e = "md",
192
192
  center: n = !1,
193
- overlay: s = !1
193
+ overlay: r = !1
194
194
  }) => {
195
195
  const a = /* @__PURE__ */ t("div", { className: `ts-loader ts-loader-${e}` });
196
- return s ? /* @__PURE__ */ t("div", { className: "ts-loader-overlay", children: a }) : n ? /* @__PURE__ */ t("div", { className: "ts-loader-center", children: a }) : a;
197
- }, Fe = () => {
198
- const e = z(), { enerexIdentifier: n, projectId: s } = q();
199
- return oe({
196
+ return r ? /* @__PURE__ */ t("div", { className: "ts-loader-overlay", children: a }) : n ? /* @__PURE__ */ t("div", { className: "ts-loader-center", children: a }) : a;
197
+ }, Ue = () => {
198
+ const e = Y(), { enerexIdentifier: n, projectId: r } = V();
199
+ return ce({
200
200
  mutationKey: ["markFavourite"],
201
201
  mutationFn: async (i) => await e.post(
202
- `${Q.markFavourite}${s}/${n}`,
202
+ `${Q.markFavourite}${r}/${n}`,
203
203
  i
204
204
  )
205
205
  });
206
- }, Ee = (e) => {
206
+ }, Le = (e) => {
207
207
  let n = /* @__PURE__ */ t(
208
208
  "span",
209
209
  {
@@ -216,8 +216,8 @@ const Me = W.createContext(
216
216
  version: "1.0",
217
217
  id: "Layer_1",
218
218
  xmlns: "http://www.w3.org/2000/svg",
219
- width: "20px",
220
- height: "20px",
219
+ width: "18px",
220
+ height: "18px",
221
221
  viewBox: "0 0 64 64",
222
222
  "enable-background": "new 0 0 64 64",
223
223
  children: /* @__PURE__ */ t(
@@ -239,8 +239,8 @@ const Me = W.createContext(
239
239
  version: "1.0",
240
240
  id: "Layer_1",
241
241
  xmlns: "http://www.w3.org/2000/svg",
242
- width: "20px",
243
- height: "20px",
242
+ width: "18px",
243
+ height: "18px",
244
244
  viewBox: "0 0 64 64",
245
245
  enableBackground: "new 0 0 64 64",
246
246
  children: /* @__PURE__ */ t(
@@ -260,99 +260,151 @@ const Me = W.createContext(
260
260
  }
261
261
  )), n;
262
262
  };
263
- function rt({
263
+ function Te(e) {
264
+ return e.sort((n, r) => n.name.localeCompare(r.name));
265
+ }
266
+ function ot(e) {
267
+ const n = /* @__PURE__ */ new Map(), r = [];
268
+ e.forEach((s) => n.set(s.id, s));
269
+ let a = e.filter((s) => s.parent_id === 0), i = 0;
270
+ for (; a.length > 0; ) {
271
+ r.push({ level: i, data: a });
272
+ const s = a.map((o) => o.id);
273
+ a = e.filter(
274
+ (o) => s.includes(o.parent_id)
275
+ ), i++;
276
+ }
277
+ return r;
278
+ }
279
+ function Ne(e, n) {
280
+ const a = ot(e).find((i) => i.level === n);
281
+ return a ? a.data : [];
282
+ }
283
+ const ct = (e) => {
284
+ if (!e) return "";
285
+ const n = new Date(e);
286
+ if (isNaN(n.getTime())) return "";
287
+ const r = String(n.getMonth() + 1).padStart(2, "0"), a = String(n.getDate()).padStart(2, "0"), i = String(n.getFullYear()).slice(-2);
288
+ return `${r}/${a}/${i}`;
289
+ }, dt = (e) => /* @__PURE__ */ t(
290
+ "svg",
291
+ {
292
+ "aria-hidden": "true",
293
+ focusable: "false",
294
+ role: "img",
295
+ xmlns: "http://www.w3.org/2000/svg",
296
+ viewBox: "0 0 128 512",
297
+ height: "11px",
298
+ width: "14px",
299
+ ...e,
300
+ children: /* @__PURE__ */ t(
301
+ "path",
302
+ {
303
+ fill: "#6c757d",
304
+ d: "M64 360a56 56 0 1 0 0 112 56 56 0 1 0 0-112zm0-160a56 56 0 1 0 0 112 56 56 0 1 0 0-112zM120 96A56 56 0 1 0 8 96a56 56 0 1 0 112 0z"
305
+ }
306
+ )
307
+ }
308
+ );
309
+ function ut({
264
310
  template: e,
265
311
  openActionId: n,
266
- setOpenActionId: s,
312
+ setOpenActionId: r,
267
313
  onEdit: a,
268
314
  onDuplicate: i,
269
- onRemove: r,
315
+ onRemove: s,
270
316
  onPreview: l,
271
317
  onRefresh: o
272
318
  }) {
273
- const { isAdmin: d } = q(), y = n === e.id, m = J(null), T = J(null), [w, E, A] = e.categoryChain, { mutateAsync: h, isPending: g } = Fe(), { showNotification: b } = ke(), p = E?.key, v = A?.key, O = p === 9, M = d || v !== 2, P = d || v !== 2;
319
+ const { isAdmin: c } = V(), v = n === e.id, E = te(null), I = te(null), [b, x, u] = e.categoryChain, { mutateAsync: p, isPending: T } = Ue(), { showNotification: h } = ve(), y = x?.key, g = u?.key, R = !c && y === 9, B = c || g !== 2, _ = c || g !== 2;
274
320
  L(() => {
275
- function C(k) {
276
- y && m.current && !m.current.contains(k.target) && !T.current?.contains(k.target) && s(null);
321
+ function S(D) {
322
+ v && E.current && !E.current.contains(D.target) && !I.current?.contains(D.target) && r(null);
277
323
  }
278
- return document.addEventListener("mousedown", C), () => document.removeEventListener("mousedown", C);
279
- }, [y, s]), L(() => {
280
- function C(k) {
281
- k.key === "Escape" && s(null);
324
+ return document.addEventListener("mousedown", S), () => document.removeEventListener("mousedown", S);
325
+ }, [v, r]), L(() => {
326
+ function S(D) {
327
+ D.key === "Escape" && r(null);
282
328
  }
283
- return y && document.addEventListener("keydown", C), () => document.removeEventListener("keydown", C);
284
- }, [y, s]), L(() => {
285
- if (!y || !m.current) return;
286
- const C = Array.from(
287
- m.current.querySelectorAll('[role="menuitem"]')
329
+ return v && document.addEventListener("keydown", S), () => document.removeEventListener("keydown", S);
330
+ }, [v, r]), L(() => {
331
+ if (!v || !E.current) return;
332
+ const S = Array.from(
333
+ E.current.querySelectorAll('[role="menuitem"]')
288
334
  );
289
- if (!C.length) return;
290
- let k = 0;
291
- C[0].focus();
292
- function x($) {
293
- $.key === "ArrowDown" && (k = (k + 1) % C.length, C[k].focus(), $.preventDefault()), $.key === "ArrowUp" && (k = (k - 1 + C.length) % C.length, C[k].focus(), $.preventDefault());
335
+ if (!S.length) return;
336
+ let D = 0;
337
+ S[0].focus();
338
+ function M(w) {
339
+ w.key === "ArrowDown" && (D = (D + 1) % S.length, S[D].focus(), w.preventDefault()), w.key === "ArrowUp" && (D = (D - 1 + S.length) % S.length, S[D].focus(), w.preventDefault());
294
340
  }
295
- return document.addEventListener("keydown", x), () => document.removeEventListener("keydown", x);
296
- }, [y]);
297
- const U = async () => {
341
+ return document.addEventListener("keydown", M), () => document.removeEventListener("keydown", M);
342
+ }, [v]);
343
+ const A = async () => {
298
344
  try {
299
- await h({
300
- categoryId: v?.toString() ?? "",
345
+ await p({
346
+ categoryId: g?.toString() ?? "",
301
347
  templateId: e.id ?? ""
302
- }), o(), b(
348
+ }), o(), h(
303
349
  `Template "${e?.name}" marked as favourite`,
304
350
  "success"
305
351
  );
306
- } catch (C) {
307
- console.error(C), b(
352
+ } catch (S) {
353
+ console.error(S), h(
308
354
  "Unable to mark template as favourite. Please try again.",
309
355
  "error"
310
356
  );
311
357
  }
312
358
  };
313
- return /* @__PURE__ */ t(fe, { children: /* @__PURE__ */ c("tr", { className: "ts-table-row", children: [
314
- /* @__PURE__ */ t("td", { children: /* @__PURE__ */ c("div", { className: "ts-name-cell", children: [
315
- O && /* @__PURE__ */ t(
316
- "button",
317
- {
318
- type: "button",
319
- className: "ts-fav-btn ts-btn-light",
320
- disabled: e.is_favourite,
321
- onClick: U,
322
- title: "Mark as favourite",
323
- children: g ? /* @__PURE__ */ t(se, { size: "sm" }) : e.is_favourite ? /* @__PURE__ */ t(Ee, { variant: "filled" }) : /* @__PURE__ */ t(Ee, { variant: "outlined" })
324
- }
325
- ),
326
- /* @__PURE__ */ t(
327
- "span",
328
- {
329
- className: e.readonly ? "ts-badge default" : "ts-badge custom",
330
- children: e.readonly ? "Default" : "Custom"
331
- }
332
- ),
333
- /* @__PURE__ */ t("span", { className: "ts-template-name", children: e.name })
334
- ] }) }),
335
- /* @__PURE__ */ t("td", { children: w?.name ?? "" }),
336
- /* @__PURE__ */ t("td", { children: E?.name ?? "" }),
337
- /* @__PURE__ */ t("td", { children: A?.name ?? "" }),
359
+ return /* @__PURE__ */ t(ye, { children: /* @__PURE__ */ d("tr", { className: "ts-table-row", children: [
360
+ /* @__PURE__ */ d("td", { children: [
361
+ " ",
362
+ /* @__PURE__ */ d("div", { className: "ts-name-cell", children: [
363
+ R && /* @__PURE__ */ t(
364
+ "button",
365
+ {
366
+ type: "button",
367
+ className: "ts-fav-btn ts-btn-light",
368
+ disabled: e.is_favourite,
369
+ onClick: A,
370
+ title: "Mark as favourite",
371
+ children: T ? /* @__PURE__ */ t(ie, { size: "sm" }) : e.is_favourite ? /* @__PURE__ */ t(Le, { variant: "filled" }) : /* @__PURE__ */ t(Le, { variant: "outlined" })
372
+ }
373
+ ),
374
+ /* @__PURE__ */ t(
375
+ "span",
376
+ {
377
+ className: e.readonly ? "ts-badge default" : "ts-badge custom",
378
+ children: e.readonly ? "Default" : "Custom"
379
+ }
380
+ )
381
+ ] })
382
+ ] }),
383
+ /* @__PURE__ */ t("td", { children: /* @__PURE__ */ t("div", { className: "", children: /* @__PURE__ */ t("span", { className: "ts-template-name", children: e.name }) }) }),
384
+ c && /* @__PURE__ */ t("td", { children: e?.id ?? "" }),
385
+ /* @__PURE__ */ t("td", { children: b?.name ?? "" }),
386
+ /* @__PURE__ */ t("td", { children: x?.name ?? "" }),
387
+ /* @__PURE__ */ t("td", { children: u?.name ?? "" }),
388
+ c && /* @__PURE__ */ t("td", { children: e?.companyName ?? "" }),
338
389
  /* @__PURE__ */ t("td", { children: e?.updatedByName ?? "" }),
339
- /* @__PURE__ */ t("td", { className: "ts-actions-cell", children: /* @__PURE__ */ c("div", { className: "ts-actions-wrapper", children: [
390
+ /* @__PURE__ */ t("td", { children: ct(e.updatedDateTime) }),
391
+ /* @__PURE__ */ t("td", { className: "ts-actions-cell", children: /* @__PURE__ */ d("div", { className: "ts-actions-wrapper", children: [
340
392
  /* @__PURE__ */ t(
341
393
  "button",
342
394
  {
343
- ref: T,
395
+ ref: I,
344
396
  className: "ts-actions-btn",
345
397
  "aria-haspopup": "true",
346
- "aria-expanded": y,
347
- onClick: () => s(y ? null : e.id),
348
- children: "⋯"
398
+ "aria-expanded": v,
399
+ onClick: () => r(v ? null : e.id),
400
+ children: /* @__PURE__ */ t(dt, {})
349
401
  }
350
402
  ),
351
- /* @__PURE__ */ c(
403
+ /* @__PURE__ */ d(
352
404
  "div",
353
405
  {
354
- ref: m,
355
- className: `ts-actions-menu ${y ? "open" : ""}`,
406
+ ref: E,
407
+ className: `ts-actions-menu ${v ? "open" : ""}`,
356
408
  role: "menu",
357
409
  children: [
358
410
  /* @__PURE__ */ t(
@@ -362,19 +414,19 @@ function rt({
362
414
  role: "menuitem",
363
415
  className: "ts-menu-item",
364
416
  onClick: () => {
365
- s(null), l(e);
417
+ r(null), l(e);
366
418
  },
367
419
  children: "Preview"
368
420
  }
369
421
  ),
370
- M && /* @__PURE__ */ t(
422
+ B && /* @__PURE__ */ t(
371
423
  "button",
372
424
  {
373
425
  type: "button",
374
426
  role: "menuitem",
375
427
  className: "ts-menu-item",
376
428
  onClick: () => {
377
- s(null), a(e);
429
+ r(null), a(e);
378
430
  },
379
431
  children: "Edit"
380
432
  }
@@ -386,19 +438,19 @@ function rt({
386
438
  role: "menuitem",
387
439
  className: "ts-menu-item",
388
440
  onClick: () => {
389
- s(null), i(e);
441
+ r(null), i(e);
390
442
  },
391
443
  children: "Duplicate"
392
444
  }
393
445
  ),
394
- P && /* @__PURE__ */ t(
446
+ _ && /* @__PURE__ */ t(
395
447
  "button",
396
448
  {
397
449
  type: "button",
398
450
  role: "menuitem",
399
451
  className: "ts-menu-item danger",
400
452
  onClick: () => {
401
- s(null), r(e);
453
+ r(null), s(e);
402
454
  },
403
455
  children: "Remove"
404
456
  }
@@ -409,144 +461,214 @@ function rt({
409
461
  ] }) })
410
462
  ] }) });
411
463
  }
412
- const st = qe(rt), ve = 5, at = ({
464
+ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
465
+ "svg",
466
+ {
467
+ xmlns: "http://www.w3.org/2000/svg",
468
+ viewBox: "0 0 320 512",
469
+ width: "6.01px",
470
+ height: "9.63px",
471
+ ...e,
472
+ children: /* @__PURE__ */ t(
473
+ "path",
474
+ {
475
+ fill: e.fill || "#6c757d",
476
+ d: "M182.6 41.4c-12.5-12.5-32.8-12.5-45.3 0l-128 128c-9.2 9.2-11.9 22.9-6.9 34.9s16.6 19.8 29.6 19.8H288c12.9 0 24.6-7.8 29.6-19.8s2.2-25.7-6.9-34.9l-128-128z"
477
+ }
478
+ )
479
+ }
480
+ ), ft = (e) => /* @__PURE__ */ t(
481
+ "svg",
482
+ {
483
+ xmlns: "http://www.w3.org/2000/svg",
484
+ viewBox: "0 0 320 512",
485
+ width: "6.01px",
486
+ height: "9.63px",
487
+ ...e,
488
+ children: /* @__PURE__ */ t(
489
+ "path",
490
+ {
491
+ fill: e.fill || "#6c757d",
492
+ d: "M182.6 470.6c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-9.2-9.2-11.9-22.9-6.9-34.9s16.6-19.8 29.6-19.8H288c12.9 0 24.6 7.8 29.6 19.8s2.2 25.7-6.9 34.9l-128 128z"
493
+ }
494
+ )
495
+ }
496
+ ), J = ({
497
+ label: e,
498
+ sortKey: n,
499
+ sortBy: r,
500
+ sortOrder: a,
501
+ onSort: i
502
+ }) => /* @__PURE__ */ t("th", { onClick: () => i(n), className: "ts-sortable", children: /* @__PURE__ */ d("div", { className: "ts-th-sort", children: [
503
+ e,
504
+ /* @__PURE__ */ d("div", { className: "ts-sort-icons", children: [
505
+ /* @__PURE__ */ t(
506
+ pt,
507
+ {
508
+ fill: r === n && a === "asc" ? "#007bff" : "#6c757d",
509
+ className: r === n && a === "asc" ? "active" : ""
510
+ }
511
+ ),
512
+ /* @__PURE__ */ t(
513
+ ft,
514
+ {
515
+ style: { marginTop: -9.6 },
516
+ fill: r === n && a === "desc" ? "#007bff" : "#6c757d",
517
+ className: r === n && a === "desc" ? "active" : ""
518
+ }
519
+ )
520
+ ] })
521
+ ] }) }), Ce = 5, ht = ({
413
522
  page: e,
414
523
  pageSize: n,
415
- totalRecords: s,
524
+ totalRecords: r,
416
525
  onPageChange: a,
417
526
  onPageSizeChange: i
418
527
  }) => {
419
- const r = Math.ceil(s / n), o = r <= ve ? Array.from({ length: r }, (m, T) => T + 1) : Array.from({ length: ve }, (m, T) => T + 1), d = r > ve, y = r;
420
- return /* @__PURE__ */ c("div", { className: "ts-pagination-bar", children: [
421
- /* @__PURE__ */ c("div", { className: "ts-page-container", children: [
422
- /* @__PURE__ */ c("div", { className: "ts-page-size", children: [
423
- "Display:",
528
+ const s = Math.ceil(r / n), o = s <= Ce ? Array.from({ length: s }, (u, p) => p + 1) : Array.from({ length: Ce }, (u, p) => p + 1), c = s > Ce, v = s, { showNotification: E } = ve(), [I, b] = C(String(e));
529
+ L(() => {
530
+ b(String(e));
531
+ }, [e]);
532
+ const x = () => {
533
+ const u = Number(I);
534
+ if (!u || u < 1 || u > s) {
535
+ E("Page out of range", "error"), b(String(e));
536
+ return;
537
+ }
538
+ a(u);
539
+ };
540
+ return /* @__PURE__ */ d("div", { className: "ts-pagination-bar", children: [
541
+ /* @__PURE__ */ d("div", { className: "ts-page-container", children: [
542
+ /* @__PURE__ */ d("div", { className: "ts-page-size", children: [
543
+ /* @__PURE__ */ t("label", { children: "Display:" }),
424
544
  /* @__PURE__ */ t(
425
545
  "select",
426
546
  {
427
547
  value: n,
428
- onChange: (m) => {
429
- i(Number(m.target.value)), a(1);
548
+ onChange: (u) => {
549
+ i(Number(u.target.value)), a(1);
430
550
  },
431
- children: [10, 25, 50, 100].map((m) => /* @__PURE__ */ t("option", { value: m, children: m }, m))
551
+ children: [10, 25, 50, 100].map((u) => /* @__PURE__ */ t("option", { value: u, children: u }, u))
432
552
  }
433
553
  )
434
554
  ] }),
435
- /* @__PURE__ */ c("div", { className: "ts-page-info", children: [
555
+ /* @__PURE__ */ d("div", { className: "ts-page-info", children: [
436
556
  "Page ",
437
- e,
438
- " of ",
439
- r
557
+ /* @__PURE__ */ d("span", { children: [
558
+ e,
559
+ " of ",
560
+ s
561
+ ] })
440
562
  ] }),
441
- /* @__PURE__ */ c("div", { className: "ts-go-to", children: [
442
- "Go to page:",
563
+ /* @__PURE__ */ d("div", { className: "ts-go-to", children: [
564
+ /* @__PURE__ */ t("span", { children: "Go to page:" }),
443
565
  /* @__PURE__ */ t(
444
566
  "input",
445
567
  {
446
568
  type: "number",
447
- min: 1,
448
- max: r,
449
- value: e,
450
- onChange: (m) => {
451
- const T = Number(m.target.value);
452
- T >= 1 && T <= r && a(T);
569
+ value: I,
570
+ onChange: (u) => b(u.target.value),
571
+ onBlur: x,
572
+ onKeyDown: (u) => {
573
+ u.key === "Enter" && x();
453
574
  }
454
575
  }
455
576
  )
456
577
  ] })
457
578
  ] }),
458
- /* @__PURE__ */ c("div", { className: "ts-total", children: [
459
- "Total: ",
460
- s
579
+ /* @__PURE__ */ d("div", { className: "ts-total", children: [
580
+ /* @__PURE__ */ t("span", { children: "Total:" }),
581
+ " ",
582
+ r
461
583
  ] }),
462
- /* @__PURE__ */ c("div", { className: "ts-page-buttons", children: [
584
+ /* @__PURE__ */ d("div", { className: "ts-page-buttons", children: [
463
585
  /* @__PURE__ */ t("button", { disabled: e === 1, onClick: () => a(e - 1), children: "‹" }),
464
- o.map((m) => /* @__PURE__ */ t(
586
+ o.map((u) => /* @__PURE__ */ t(
465
587
  "button",
466
588
  {
467
- className: m === e ? "active" : "",
468
- onClick: () => a(m),
469
- children: m
589
+ className: u === e ? "active" : "",
590
+ onClick: () => a(u),
591
+ children: u
470
592
  },
471
- m
593
+ u
472
594
  )),
473
- d && /* @__PURE__ */ t("span", { style: { padding: "0 6px" }, children: "…" }),
474
- d && /* @__PURE__ */ t(
595
+ c && /* @__PURE__ */ t("span", { style: { padding: "0 6px" }, children: "…" }),
596
+ c && /* @__PURE__ */ t(
475
597
  "button",
476
598
  {
477
- className: e === y ? "active" : "",
478
- onClick: () => a(y),
479
- children: y
599
+ className: e === v ? "active" : "",
600
+ onClick: () => a(v),
601
+ children: v
480
602
  }
481
603
  ),
482
604
  /* @__PURE__ */ t(
483
605
  "button",
484
606
  {
485
- disabled: e === r,
607
+ disabled: e === s,
486
608
  onClick: () => a(e + 1),
487
609
  children: "›"
488
610
  }
489
611
  )
490
612
  ] })
491
613
  ] });
492
- }, it = ({
614
+ }, yt = ({
493
615
  show: e,
494
616
  variant: n,
495
- title: s = "Are you sure?",
617
+ title: r = "Are you sure?",
496
618
  message: a,
497
619
  label: i = "Name",
498
- value: r = "",
620
+ value: s = "",
499
621
  placeholder: l = "",
500
622
  requiredMessage: o = "This field is required",
501
- externalError: d = !1,
502
- externalErrorMessage: y = "",
503
- confirmText: m = "Ok",
504
- cancelText: T = "Cancel",
505
- confirmButtonVariant: w = "danger",
506
- disableConfirm: E = !1,
507
- onConfirm: A,
508
- onCancel: h,
509
- onInputChange: g
623
+ externalError: c = !1,
624
+ externalErrorMessage: v = "",
625
+ confirmText: E = "Ok",
626
+ cancelText: I = "Cancel",
627
+ confirmButtonVariant: b = "danger",
628
+ disableConfirm: x = !1,
629
+ onConfirm: u,
630
+ onCancel: p,
631
+ onInputChange: T
510
632
  }) => {
511
- const [b, p] = N(r), [v, O] = N(!1), M = J(null);
633
+ const [h, y] = C(s), [g, R] = C(!1), B = te(null);
512
634
  if (L(() => {
513
635
  if (!e) return;
514
- const x = ($) => {
515
- $.key === "Escape" && h();
636
+ const M = (w) => {
637
+ w.key === "Escape" && p();
516
638
  };
517
- return document.addEventListener("keydown", x), () => document.removeEventListener("keydown", x);
518
- }, [e, h]), L(() => {
639
+ return document.addEventListener("keydown", M), () => document.removeEventListener("keydown", M);
640
+ }, [e, p]), L(() => {
519
641
  if (!e) return;
520
- const x = ($) => {
521
- M.current && !M.current.contains($.target) && h();
642
+ const M = (w) => {
643
+ B.current && !B.current.contains(w.target) && p();
522
644
  };
523
- return document.addEventListener("mousedown", x), () => document.removeEventListener("mousedown", x);
524
- }, [e, h]), L(() => {
645
+ return document.addEventListener("mousedown", M), () => document.removeEventListener("mousedown", M);
646
+ }, [e, p]), L(() => {
525
647
  if (e)
526
648
  return document.body.style.overflow = "hidden", () => {
527
649
  document.body.style.overflow = "";
528
650
  };
529
651
  }, [e]), L(() => {
530
- e && (p(r), O(!1));
531
- }, [e, r]), L(() => {
532
- d && O(!0);
533
- }, [d]), !e) return null;
534
- const P = n === "input" && !b.trim(), U = n === "input" && (P || d), C = P ? o : d ? y : "", k = () => {
535
- if (U || E) {
536
- O(!0);
652
+ e && (y(s), R(!1));
653
+ }, [e, s]), L(() => {
654
+ c && R(!0);
655
+ }, [c]), !e) return null;
656
+ const _ = n === "input" && !h.trim(), A = n === "input" && (_ || c), S = _ ? o : c ? v : "", D = () => {
657
+ if (A || x) {
658
+ R(!0);
537
659
  return;
538
660
  }
539
- A(b.trim());
661
+ u(h.trim());
540
662
  };
541
- return /* @__PURE__ */ t("div", { className: "ts-modal-overlay", children: /* @__PURE__ */ c("div", { ref: M, className: "ts-modal", children: [
542
- /* @__PURE__ */ c("div", { className: "ts-modal-header", children: [
543
- /* @__PURE__ */ t("h4", { className: "ts-modal-title ", children: s }),
544
- /* @__PURE__ */ t("button", { className: "ts-modal-close", onClick: h, children: "✕" })
663
+ return /* @__PURE__ */ t("div", { className: "ts-modal-overlay", children: /* @__PURE__ */ d("div", { ref: B, className: "ts-modal", children: [
664
+ /* @__PURE__ */ d("div", { className: "ts-modal-header", children: [
665
+ /* @__PURE__ */ t("h4", { className: "ts-modal-title ", children: r }),
666
+ /* @__PURE__ */ t("button", { className: "ts-modal-close", onClick: p, children: "✕" })
545
667
  ] }),
546
- /* @__PURE__ */ c("div", { className: "ts-modal-body", children: [
668
+ /* @__PURE__ */ d("div", { className: "ts-modal-body", children: [
547
669
  a && /* @__PURE__ */ t("p", { className: "ts-modal-message", children: a }),
548
- n === "input" && /* @__PURE__ */ c("div", { className: "ts-form-group", children: [
549
- /* @__PURE__ */ c("label", { className: "ts-label", children: [
670
+ n === "input" && /* @__PURE__ */ d("div", { className: "ts-form-group", children: [
671
+ /* @__PURE__ */ d("label", { className: "ts-label", children: [
550
672
  i,
551
673
  /* @__PURE__ */ t("span", { className: "ts-required", children: "*" })
552
674
  ] }),
@@ -554,62 +676,62 @@ const st = qe(rt), ve = 5, at = ({
554
676
  "input",
555
677
  {
556
678
  type: "text",
557
- className: `ts-input ${v && U ? "ts-input-error" : ""}`,
679
+ className: `ts-input ${g && A ? "ts-input-error" : ""}`,
558
680
  placeholder: l,
559
- value: b,
560
- onChange: (x) => {
561
- p(x.target.value), v && O(!1), g?.(x.target.value);
681
+ value: h,
682
+ onChange: (M) => {
683
+ y(M.target.value), g && R(!1), T?.(M.target.value);
562
684
  },
563
685
  autoFocus: !0,
564
686
  style: { paddingBlock: "0", paddingInline: "0" }
565
687
  }
566
688
  ),
567
- v && U && /* @__PURE__ */ t("div", { className: "ts-error-text", children: C })
689
+ g && A && /* @__PURE__ */ t("div", { className: "ts-error-text", children: S })
568
690
  ] })
569
691
  ] }),
570
- /* @__PURE__ */ c("div", { className: "ts-modal-footer", children: [
692
+ /* @__PURE__ */ d("div", { className: "ts-modal-footer", children: [
571
693
  /* @__PURE__ */ t(
572
694
  "button",
573
695
  {
574
696
  type: "button",
575
697
  className: "ts-btn ts-btn-secondary",
576
- onClick: h,
577
- children: T
698
+ onClick: p,
699
+ children: I
578
700
  }
579
701
  ),
580
702
  /* @__PURE__ */ t(
581
703
  "button",
582
704
  {
583
705
  type: "button",
584
- className: `ts-btn ts-btn-${w}`,
585
- onClick: k,
586
- disabled: E,
587
- children: m
706
+ className: `ts-btn ts-btn-${b}`,
707
+ onClick: D,
708
+ disabled: x,
709
+ children: E
588
710
  }
589
711
  )
590
712
  ] })
591
713
  ] }) });
592
- }, lt = () => /* @__PURE__ */ t(
714
+ }, gt = () => /* @__PURE__ */ t(
593
715
  "svg",
594
716
  {
595
717
  xmlns: "http://www.w3.org/2000/svg",
596
718
  viewBox: "0 0 512 512",
597
- width: "16px",
598
- height: "16px",
719
+ width: "11px",
720
+ height: "11px",
599
721
  children: /* @__PURE__ */ t("path", { fill: "#ffffff", d: "M368 208A160 160 0 1 0 48 208a160 160 0 1 0 320 0zM337.1 371.1C301.7 399.2 256.8 416 208 416C93.1 416 0 322.9 0 208S93.1 0 208 0S416 93.1 416 208c0 48.8-16.8 93.7-44.9 129.1L505 471c9.4 9.4 9.4 24.6 0 33.9s-24.6 9.4-33.9 0L337.1 371.1z" })
600
722
  }
601
- ), ot = () => {
602
- const e = z(), { enerexIdentifier: n, projectId: s, userEmail: a } = q();
603
- return oe({
723
+ ), vt = () => {
724
+ const e = Y(), { enerexIdentifier: n, projectId: r, userEmail: a } = V();
725
+ return ce({
604
726
  mutationKey: ["duplicateTemplate"],
605
- mutationFn: async ({ templateId: r, request: l }) => (l.enerexIdentifier = n ?? "", l.projectId = s ?? "", l.updatedBy = a ?? "", await e.post(
606
- `${Q.duplicateTemplate}${r}`,
727
+ mutationFn: async ({ templateId: s, request: l }) => (l.enerexIdentifier = n ?? "", l.projectId = r ?? "", l.updatedBy = a ?? "", await e.post(
728
+ `${Q.duplicateTemplate}${s}`,
607
729
  l
608
730
  ))
609
731
  });
610
- }, ct = () => {
611
- const e = z();
612
- return oe({
732
+ }, bt = () => {
733
+ const e = Y();
734
+ return ce({
613
735
  mutationKey: ["deleteTemplate"],
614
736
  mutationFn: async (n) => {
615
737
  await e.delete(
@@ -617,309 +739,305 @@ const st = qe(rt), ve = 5, at = ({
617
739
  );
618
740
  }
619
741
  });
620
- }, dt = ({
742
+ }, wt = ({
621
743
  data: e,
622
744
  page: n,
623
- pageSize: s
745
+ pageSize: r
624
746
  }) => {
625
- const a = re(() => Math.ceil(e.length / s), [e.length, s]);
626
- return { pagedData: re(() => {
627
- const r = (n - 1) * s, l = n * s;
628
- return e.slice(r, l);
629
- }, [e, n, s]), totalPages: a };
630
- }, mt = ({
747
+ const a = ae(() => Math.ceil(e.length / r), [e.length, r]);
748
+ return { pagedData: ae(() => {
749
+ const s = (n - 1) * r, l = n * r;
750
+ return e.slice(s, l);
751
+ }, [e, n, r]), totalPages: a };
752
+ }, Tt = ({
631
753
  templates: e,
632
754
  templateTypes: n,
633
- onRefresh: s,
755
+ onRefresh: r,
634
756
  onAdd: a,
635
757
  onEdit: i,
636
- onPreview: r
758
+ onPreview: s
637
759
  }) => {
638
- const { mutateAsync: l, isPending: o } = ot(), { mutateAsync: d, isPending: y } = ct(), [m, T] = N(""), [w, E] = N(""), [A, h] = N(null), [g, b] = N(e), [p, v] = N(n), [O, M] = N(!1), [P, U] = N("input"), [C, k] = N(!1), [x, $] = N(null), [B, ce] = N("asc"), V = (u) => {
639
- x === u ? ce((S) => S === "asc" ? "desc" : "asc") : ($(u), ce("asc")), ie(1);
640
- }, [K, G] = N(null);
760
+ const { isAdmin: l } = V(), { mutateAsync: o, isPending: c } = vt(), { mutateAsync: v, isPending: E } = bt(), [I, b] = C(""), [x, u] = C(""), [p, T] = C(null), [h, y] = C(e), [g, R] = C(n), [B, _] = C(!1), [A, S] = C("input"), [D, M] = C(!1), [w, ne] = C(null), [U, W] = C("asc"), K = (m) => {
761
+ w === m ? W((N) => N === "asc" ? "desc" : "asc") : (ne(m), W("asc")), ee(1);
762
+ }, [O, re] = C(null);
641
763
  L(() => {
642
- const u = [...e].sort((S, R) => {
643
- if (S.is_favourite !== R.is_favourite)
644
- return Number(R.is_favourite) - Number(S.is_favourite);
645
- const D = new Date(R.updatedDateTime).getTime() - new Date(S.updatedDateTime).getTime();
646
- return D !== 0 ? D : S.readonly !== R.readonly ? Number(S.readonly) - Number(R.readonly) : S.name.localeCompare(R.name);
764
+ const m = [...e].sort((N, $) => {
765
+ if (!l && N.is_favourite !== $.is_favourite)
766
+ return Number($.is_favourite) - Number(N.is_favourite);
767
+ const P = new Date($.updatedDateTime).getTime() - new Date(N.updatedDateTime).getTime();
768
+ return P !== 0 ? P : N.readonly !== $.readonly ? Number(N.readonly) - Number($.readonly) : N.name.localeCompare($.name);
647
769
  });
648
- b(u), $(null);
770
+ y(m), ne(null);
649
771
  }, [e]), L(() => {
650
- v(n.filter((u) => u.id != null));
772
+ R(n.filter((m) => m.id != null));
651
773
  }, [n]);
652
- const Z = re(() => {
653
- const u = /* @__PURE__ */ new Map();
654
- return p.forEach((S) => u.set(S.id, S)), u;
655
- }, [p]), ye = xe(
656
- (u) => {
657
- const S = [], R = /* @__PURE__ */ new Set();
658
- let D = Z.get(u);
659
- for (; D && !(R.has(D.id) || (R.add(D.id), S.push({ id: D.id, name: D.name, key: D.key }), !D.parent_id)); )
660
- D = Z.get(D.parent_id);
661
- return S.reverse();
774
+ const le = ae(() => {
775
+ const m = /* @__PURE__ */ new Map();
776
+ return g.forEach((N) => m.set(N.id, N)), m;
777
+ }, [g]), de = Se(
778
+ (m) => {
779
+ const N = [], $ = /* @__PURE__ */ new Set();
780
+ let P = le.get(m);
781
+ for (; P && !($.has(P.id) || ($.add(P.id), N.push({ id: P.id, name: P.name, key: P.key }), !P.parent_id)); )
782
+ P = le.get(P.parent_id);
783
+ return N.reverse();
662
784
  },
663
- [Z]
664
- ), ee = re(() => !g.length || !p.length ? [] : g.map((u) => ({
665
- ...u,
666
- categoryChain: ye(u.type)
667
- })), [g, p]);
785
+ [le]
786
+ ), Z = ae(() => !h.length || !g.length ? [] : h.map((m) => ({
787
+ ...m,
788
+ categoryChain: de(m.type)
789
+ })), [h, g]);
668
790
  L(() => {
669
- const u = setTimeout(() => {
670
- E(m), ie(1);
791
+ const m = setTimeout(() => {
792
+ u(I), ee(1);
671
793
  }, 300);
672
- return () => clearTimeout(u);
673
- }, [m]);
674
- const [te, ae] = N(10), [H, ie] = N(1), ne = re(() => {
675
- const u = w.trim().toLowerCase();
676
- return u ? ee.filter((S) => {
677
- const R = S.name.toLowerCase().includes(u), D = S.categoryChain?.some(
678
- (Y) => Y.name.toLowerCase().includes(u)
794
+ return () => clearTimeout(m);
795
+ }, [I]);
796
+ const [se, H] = C(25), [ue, ee] = C(1), me = ae(() => {
797
+ const m = x.trim().toLowerCase();
798
+ return m ? Z.filter((N) => {
799
+ const $ = N.name.toLowerCase().includes(m), P = N.categoryChain?.some(
800
+ (z) => z.name.toLowerCase().includes(m)
679
801
  );
680
- return R || D;
681
- }) : ee;
682
- }, [ee, w]), de = re(() => {
683
- const u = [...ne];
684
- return u.sort((S, R) => {
685
- let D = "", Y = "";
686
- switch (x) {
802
+ return $ || P;
803
+ }) : Z;
804
+ }, [Z, x]), pe = ae(() => {
805
+ const m = [...me];
806
+ return m.sort((N, $) => {
807
+ if (w === "lastUpdatedOn") {
808
+ const Ve = new Date(N.updatedDateTime).getTime(), Ke = new Date($.updatedDateTime).getTime(), Pe = Ve - Ke;
809
+ return U === "asc" ? Pe : -Pe;
810
+ }
811
+ let P = "", z = "";
812
+ switch (w) {
687
813
  case "name":
688
- D = S.name, Y = R.name;
814
+ P = N.name, z = $.name;
689
815
  break;
690
816
  case "category":
691
- D = S.categoryChain?.[0]?.name ?? "", Y = R.categoryChain?.[0]?.name ?? "";
817
+ P = N.categoryChain?.[0]?.name ?? "", z = $.categoryChain?.[0]?.name ?? "";
692
818
  break;
693
819
  case "type":
694
- D = S.categoryChain?.[1]?.name ?? "", Y = R.categoryChain?.[1]?.name ?? "";
820
+ P = N.categoryChain?.[1]?.name ?? "", z = $.categoryChain?.[1]?.name ?? "";
695
821
  break;
696
822
  case "subtype":
697
- D = S.categoryChain?.[2]?.name ?? "", Y = R.categoryChain?.[2]?.name ?? "";
823
+ P = N.categoryChain?.[2]?.name ?? "", z = $.categoryChain?.[2]?.name ?? "";
824
+ break;
825
+ case "templateId":
826
+ P = N.id ?? "", z = $.id ?? "";
827
+ break;
828
+ case "companyName":
829
+ P = N.companyName ?? "", z = $.companyName ?? "";
830
+ break;
831
+ case "lastUpdatedBy":
832
+ P = N.updatedByName ?? "", z = $.updatedByName ?? "";
698
833
  break;
699
834
  }
700
- const Ie = D.localeCompare(Y, void 0, {
835
+ const De = P.localeCompare(z, void 0, {
701
836
  sensitivity: "base"
702
837
  });
703
- return B === "asc" ? Ie : -Ie;
704
- }), u;
705
- }, [ne, x, B]), { pagedData: le } = dt({
706
- data: de,
707
- page: H,
708
- pageSize: te
709
- }), ge = xe(
710
- (u) => g.some(
711
- (S) => S.name.trim().toLowerCase() === u.trim().toLowerCase()
838
+ return U === "asc" ? De : -De;
839
+ }), m;
840
+ }, [me, w, U]), { pagedData: be } = wt({
841
+ data: pe,
842
+ page: ue,
843
+ pageSize: se
844
+ }), f = Se(
845
+ (m) => h.some(
846
+ (N) => N.name.trim().toLowerCase() === m.trim().toLowerCase()
712
847
  ),
713
- [g]
714
- ), f = (u) => {
715
- G(u), k(!1), U("input"), M(!0);
716
- }, I = (u) => {
717
- G(u), U("confirm"), M(!0);
718
- }, { showNotification: _ } = ke(), j = async (u) => {
719
- if (K)
848
+ [h]
849
+ ), k = (m) => {
850
+ re(m), M(!1), S("input"), _(!0);
851
+ }, F = (m) => {
852
+ re(m), S("confirm"), _(!0);
853
+ }, { showNotification: j } = ve(), X = async (m) => {
854
+ if (O)
720
855
  try {
721
- if (P === "input") {
722
- if (!u) return;
723
- if (ge(u)) {
724
- k(!0);
856
+ if (A === "input") {
857
+ if (!m) return;
858
+ if (f(m)) {
859
+ M(!0);
725
860
  return;
726
861
  }
727
- await l({
728
- templateId: K.id,
862
+ await o({
863
+ templateId: O.id,
729
864
  request: {
730
865
  projectId: "",
731
866
  enerexIdentifier: "",
732
- newName: u,
733
- parent_id: K.id ?? null
867
+ newName: m,
868
+ parent_id: O.id ?? null
734
869
  }
735
- }), _(
736
- `Template "${u}" duplicated successfully`,
870
+ }), j(
871
+ `Template "${m}" duplicated successfully`,
737
872
  "success"
738
873
  );
739
874
  }
740
- P === "confirm" && (await d(K.id), _(
741
- `Template "${K.name}" deleted successfully`,
875
+ A === "confirm" && (await v(O.id), j(
876
+ `Template "${O.name}" deleted successfully`,
742
877
  "success"
743
- )), M(!1), G(null), s();
878
+ )), _(!1), re(null), r();
744
879
  } catch {
745
- _(
746
- P === "confirm" ? "Failed to delete template. Please try again." : "Failed to duplicate template. Please try again.",
880
+ j(
881
+ A === "confirm" ? "Failed to delete template. Please try again." : "Failed to duplicate template. Please try again.",
747
882
  "error"
748
883
  );
749
884
  }
750
- }, X = K?.categoryChain?.[2]?.name?.toLowerCase() ?? "this", F = K?.name?.toLowerCase() ?? "";
751
- return /* @__PURE__ */ c(fe, { children: [
752
- (o || y) && /* @__PURE__ */ t(se, { overlay: !0 }),
753
- /* @__PURE__ */ c("div", { className: "ts-page", children: [
754
- /* @__PURE__ */ c("div", { className: "ts-header", children: [
885
+ }, q = O?.categoryChain?.[2]?.name?.toLowerCase() ?? "this", oe = O?.name?.toLowerCase() ?? "";
886
+ return /* @__PURE__ */ d(ye, { children: [
887
+ (c || E) && /* @__PURE__ */ t(ie, { overlay: !0 }),
888
+ /* @__PURE__ */ d("div", { className: "ts-page", children: [
889
+ /* @__PURE__ */ d("div", { className: "ts-header", children: [
755
890
  /* @__PURE__ */ t("h1", { className: "ts-title", children: "Templates" }),
756
891
  /* @__PURE__ */ t("button", { className: "ts-btn ts-btn-primary", onClick: a, children: "+ Add Template" })
757
892
  ] }),
758
- /* @__PURE__ */ t("div", { className: "ts-search", children: /* @__PURE__ */ c("div", { className: "ts-search-box", children: [
759
- /* @__PURE__ */ t(
760
- "input",
761
- {
762
- type: "text",
763
- placeholder: "Search...",
764
- value: m,
765
- onChange: (u) => T(u.target.value)
766
- }
767
- ),
768
- m && /* @__PURE__ */ t(
769
- "button",
770
- {
771
- className: "ts-clear-btn",
772
- "aria-label": "Clear search",
773
- onClick: () => T(""),
774
- children: "×"
775
- }
776
- ),
777
- /* @__PURE__ */ t("button", { className: "ts-search-btn", "aria-label": "Search", children: /* @__PURE__ */ t(lt, {}) })
778
- ] }) }),
779
- /* @__PURE__ */ c("div", { className: "ts-table-wrapper", children: [
780
- /* @__PURE__ */ c("table", { className: "ts-table", children: [
781
- /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ c("tr", { children: [
782
- /* @__PURE__ */ t("th", { onClick: () => V("name"), className: "ts-sortable", children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
783
- "Name",
784
- /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
785
- /* @__PURE__ */ t(
786
- "span",
787
- {
788
- className: x === "name" && B === "asc" ? "active" : "",
789
- children: ""
790
- }
791
- ),
792
- /* @__PURE__ */ t(
793
- "span",
794
- {
795
- className: x === "name" && B === "desc" ? "active" : "",
796
- children: "▼"
797
- }
798
- )
799
- ] })
893
+ /* @__PURE__ */ t("div", { className: "ts-search-container", children: /* @__PURE__ */ d("div", { className: "ts-search-container-inner", children: [
894
+ /* @__PURE__ */ t("div", { className: "ts-search", children: /* @__PURE__ */ d("div", { className: "ts-search-box", children: [
895
+ /* @__PURE__ */ t(
896
+ "input",
897
+ {
898
+ type: "text",
899
+ placeholder: "Search...",
900
+ value: I,
901
+ onChange: (m) => b(m.target.value)
902
+ }
903
+ ),
904
+ /* @__PURE__ */ t("button", { className: "ts-search-btn", "aria-label": "Search", children: /* @__PURE__ */ t(gt, {}) })
905
+ ] }) }),
906
+ /* @__PURE__ */ d("div", { className: "ts-table-wrapper", children: [
907
+ /* @__PURE__ */ d("table", { className: "ts-table", children: [
908
+ /* @__PURE__ */ t("thead", { children: /* @__PURE__ */ d("tr", { children: [
909
+ /* @__PURE__ */ t("th", { className: "ts-cursor-default" }),
910
+ /* @__PURE__ */ t(
911
+ J,
912
+ {
913
+ label: "Name",
914
+ sortKey: "name",
915
+ sortBy: w,
916
+ sortOrder: U,
917
+ onSort: K
918
+ }
919
+ ),
920
+ l && /* @__PURE__ */ t(
921
+ J,
922
+ {
923
+ label: "Template Id",
924
+ sortKey: "templateId",
925
+ sortBy: w,
926
+ sortOrder: U,
927
+ onSort: K
928
+ }
929
+ ),
930
+ /* @__PURE__ */ t(
931
+ J,
932
+ {
933
+ label: "Category",
934
+ sortKey: "category",
935
+ sortBy: w,
936
+ sortOrder: U,
937
+ onSort: K
938
+ }
939
+ ),
940
+ /* @__PURE__ */ t(
941
+ J,
942
+ {
943
+ label: "Type",
944
+ sortKey: "type",
945
+ sortBy: w,
946
+ sortOrder: U,
947
+ onSort: K
948
+ }
949
+ ),
950
+ /* @__PURE__ */ t(
951
+ J,
952
+ {
953
+ label: "Subtype",
954
+ sortKey: "subtype",
955
+ sortBy: w,
956
+ sortOrder: U,
957
+ onSort: K
958
+ }
959
+ ),
960
+ l && /* @__PURE__ */ t(
961
+ J,
962
+ {
963
+ label: "Company Name",
964
+ sortKey: "companyName",
965
+ sortBy: w,
966
+ sortOrder: U,
967
+ onSort: K
968
+ }
969
+ ),
970
+ /* @__PURE__ */ t(
971
+ J,
972
+ {
973
+ label: "Last Updated by",
974
+ sortKey: "lastUpdatedBy",
975
+ sortBy: w,
976
+ sortOrder: U,
977
+ onSort: K
978
+ }
979
+ ),
980
+ /* @__PURE__ */ t(
981
+ J,
982
+ {
983
+ label: "Last Updated on",
984
+ sortKey: "lastUpdatedOn",
985
+ sortBy: w,
986
+ sortOrder: U,
987
+ onSort: K
988
+ }
989
+ ),
990
+ /* @__PURE__ */ t("th", { className: "ts-cursor-default", children: "Actions" })
800
991
  ] }) }),
801
- /* @__PURE__ */ t(
802
- "th",
992
+ /* @__PURE__ */ t("tbody", { children: be.map((m) => /* @__PURE__ */ t(
993
+ mt,
803
994
  {
804
- onClick: () => V("category"),
805
- className: "ts-sortable",
806
- children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
807
- "Category",
808
- /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
809
- /* @__PURE__ */ t(
810
- "span",
811
- {
812
- className: x === "category" && B === "asc" ? "active" : "",
813
- children: "▲"
814
- }
815
- ),
816
- /* @__PURE__ */ t(
817
- "span",
818
- {
819
- className: x === "category" && B === "desc" ? "active" : "",
820
- children: "▼"
821
- }
822
- )
823
- ] })
824
- ] })
825
- }
826
- ),
827
- /* @__PURE__ */ t("th", { onClick: () => V("type"), className: "ts-sortable", children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
828
- "Type",
829
- /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
830
- /* @__PURE__ */ t(
831
- "span",
832
- {
833
- className: x === "type" && B === "asc" ? "active" : "",
834
- children: "▲"
835
- }
836
- ),
837
- /* @__PURE__ */ t(
838
- "span",
839
- {
840
- className: x === "type" && B === "desc" ? "active" : "",
841
- children: "▼"
842
- }
843
- )
844
- ] })
845
- ] }) }),
846
- /* @__PURE__ */ t(
847
- "th",
848
- {
849
- onClick: () => V("subtype"),
850
- className: "ts-sortable",
851
- children: /* @__PURE__ */ c("div", { className: "ts-th-sort", children: [
852
- "Subtype",
853
- /* @__PURE__ */ c("span", { className: "ts-sort-icons", children: [
854
- /* @__PURE__ */ t(
855
- "span",
856
- {
857
- className: x === "subtype" && B === "asc" ? "active" : "",
858
- children: "▲"
859
- }
860
- ),
861
- /* @__PURE__ */ t(
862
- "span",
863
- {
864
- className: x === "subtype" && B === "desc" ? "active" : "",
865
- children: "▼"
866
- }
867
- )
868
- ] })
869
- ] })
870
- }
871
- ),
872
- /* @__PURE__ */ t("th", { children: "Updated by" }),
873
- /* @__PURE__ */ t("th", { className: "align-right", children: "Actions" })
874
- ] }) }),
875
- /* @__PURE__ */ t("tbody", { children: le.map((u) => /* @__PURE__ */ t(
876
- st,
995
+ template: m,
996
+ openActionId: p,
997
+ setOpenActionId: T,
998
+ onDuplicate: k,
999
+ onEdit: i,
1000
+ onRemove: F,
1001
+ onPreview: s,
1002
+ onRefresh: r
1003
+ },
1004
+ m.id
1005
+ )) })
1006
+ ] }),
1007
+ /* @__PURE__ */ t(
1008
+ ht,
877
1009
  {
878
- template: u,
879
- openActionId: A,
880
- setOpenActionId: h,
881
- onDuplicate: f,
882
- onEdit: i,
883
- onRemove: I,
884
- onPreview: r,
885
- onRefresh: s
886
- },
887
- u.id
888
- )) })
889
- ] }),
890
- /* @__PURE__ */ t(
891
- at,
892
- {
893
- page: H,
894
- pageSize: te,
895
- totalRecords: de.length,
896
- onPageChange: ie,
897
- onPageSizeChange: ae
898
- }
899
- )
900
- ] })
1010
+ page: ue,
1011
+ pageSize: se,
1012
+ totalRecords: pe.length,
1013
+ onPageChange: ee,
1014
+ onPageSizeChange: H
1015
+ }
1016
+ )
1017
+ ] })
1018
+ ] }) })
901
1019
  ] }),
902
1020
  /* @__PURE__ */ t(
903
- it,
1021
+ yt,
904
1022
  {
905
- show: O,
906
- variant: P,
907
- title: P === "confirm" ? "Are you sure?" : "Save Template As",
908
- message: P === "confirm" ? `Are you sure you want to remove ${X} template "${F}"?` : "",
909
- placeholder: P === "input" ? "New name" : "",
1023
+ show: B,
1024
+ variant: A,
1025
+ title: A === "confirm" ? "Are you sure?" : "Save Template As",
1026
+ message: A === "confirm" ? `Are you sure you want to remove ${q} template "${oe}"?` : "",
1027
+ placeholder: A === "input" ? "New name" : "",
910
1028
  label: "New Name",
911
1029
  requiredMessage: "Enter a new name",
912
- externalError: C,
1030
+ externalError: D,
913
1031
  externalErrorMessage: "Template name already exists. Please choose a different name",
914
- confirmText: P === "confirm" ? "Ok" : "Save as",
915
- confirmButtonVariant: P === "confirm" ? "danger" : "primary",
916
- onConfirm: j,
917
- onCancel: () => M(!1),
918
- onInputChange: P === "input" ? () => k(!1) : void 0
1032
+ confirmText: A === "confirm" ? "Ok" : "Save as",
1033
+ confirmButtonVariant: A === "confirm" ? "danger" : "primary",
1034
+ onConfirm: X,
1035
+ onCancel: () => _(!1),
1036
+ onInputChange: A === "input" ? () => M(!1) : void 0
919
1037
  }
920
1038
  )
921
1039
  ] });
922
- }, pe = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
1040
+ }, he = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
923
1041
  <html\r
924
1042
  dir="ltr"\r
925
1043
  xmlns:o="urn:schemas-microsoft-com:office:office"\r
@@ -1275,70 +1393,70 @@ const st = qe(rt), ve = 5, at = ({
1275
1393
  </div>\r
1276
1394
  </body>\r
1277
1395
  </html>\r
1278
- `, we = {
1396
+ `, xe = {
1279
1397
  EDITOR_SCRIPT_URL: "https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",
1280
1398
  EDITOR_PLUGIN_ID: "1afdc3161ec7409a8627a1c8561d45f5",
1281
1399
  EDITOR_SECRET_KEY: "54ba748ed7e94f2e929555783acb03da"
1282
- }, ut = (e) => {
1283
- const n = Array.from(new Set(e.map((a) => a.category))), s = [];
1400
+ }, Nt = (e) => {
1401
+ const n = Array.from(new Set(e.map((a) => a.category))), r = [];
1284
1402
  return n.forEach((a) => {
1285
- const i = e.filter((r) => r.category === a).map((r) => ({
1286
- label: r.label,
1287
- value: r.value,
1288
- hint: r.hint,
1289
- hidden: r.hidden
1403
+ const i = e.filter((s) => s.category === a).map((s) => ({
1404
+ label: s.label,
1405
+ value: s.value,
1406
+ hint: s.hint,
1407
+ hidden: s.hidden
1290
1408
  }));
1291
- s.push({ category: a, entries: i });
1292
- }), s;
1293
- }, pt = () => {
1294
- const e = z(), { enerexIdentifier: n, projectId: s } = q();
1295
- return he({
1409
+ r.push({ category: a, entries: i });
1410
+ }), r;
1411
+ }, Ct = () => {
1412
+ const e = Y(), { enerexIdentifier: n, projectId: r } = V();
1413
+ return ge({
1296
1414
  queryKey: ["getTemplateTags"],
1297
1415
  queryFn: async (i) => await e.get(
1298
- `${Q.MergeTags}${s}/${n}`
1416
+ `${Q.MergeTags}${r}/${n}`
1299
1417
  )
1300
1418
  });
1301
- }, ft = () => {
1302
- const e = z(), { enerexIdentifier: n, projectId: s } = q();
1303
- return he({
1419
+ }, xt = () => {
1420
+ const e = Y(), { enerexIdentifier: n, projectId: r } = V();
1421
+ return ge({
1304
1422
  queryKey: ["getExcludeCategory"],
1305
1423
  queryFn: async (i) => await e.get(
1306
- `${Q.ExcludeCategory}${s}/${n}`
1424
+ `${Q.ExcludeCategory}${r}/${n}`
1307
1425
  )
1308
1426
  });
1309
- }, ht = ({
1427
+ }, Et = ({
1310
1428
  templateHTML: e,
1311
1429
  className: n = "",
1312
- loading: s = !1,
1430
+ loading: r = !1,
1313
1431
  onEditorInitialized: a
1314
1432
  }) => {
1315
- const { post: i } = Oe(), { data: r } = pt(), { data: l } = ft(), [o, d] = N(
1316
- e ?? { html: pe, css: "" }
1317
- ), { userEmail: y } = q(), m = J(null), T = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", w = "https://plugins.stripo.email/api/v1/auth";
1433
+ const { post: i } = je(), { data: s } = Ct(), { data: l } = xt(), [o, c] = C(
1434
+ e ?? { html: he, css: "" }
1435
+ ), { userEmail: v } = V(), E = te(null), I = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", b = "https://plugins.stripo.email/api/v1/auth";
1318
1436
  L(() => {
1319
- (async () => (await E(), r && l && await A(we.EDITOR_SCRIPT_URL)))();
1320
- }, [r, l]);
1321
- async function E() {
1322
- window.Zone || await new Promise((g, b) => {
1323
- const p = document.createElement("script");
1324
- p.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
1325
- const v = document.querySelector("script[nonce]")?.nonce;
1326
- v && p.setAttribute("nonce", v), p.onload = () => g(), p.onerror = () => b(new Error("Failed to load zone.js")), document.head.appendChild(p);
1437
+ (async () => (await x(), s && l && await u(xe.EDITOR_SCRIPT_URL)))();
1438
+ }, [s, l]);
1439
+ async function x() {
1440
+ window.Zone || await new Promise((T, h) => {
1441
+ const y = document.createElement("script");
1442
+ y.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
1443
+ const g = document.querySelector("script[nonce]")?.nonce;
1444
+ g && y.setAttribute("nonce", g), y.onload = () => T(), y.onerror = () => h(new Error("Failed to load zone.js")), document.head.appendChild(y);
1327
1445
  });
1328
1446
  }
1329
- async function A(g) {
1330
- let b = document.getElementById(
1447
+ async function u(T) {
1448
+ let h = document.getElementById(
1331
1449
  "UiEditorScript"
1332
1450
  );
1333
- b || (b = document.createElement("script"), b.id = "UiEditorScript", b.src = g, b.onload = async () => {
1334
- await h();
1335
- }, document.body.appendChild(b)), await new Promise(
1336
- (p) => b.addEventListener("load", () => p(), { once: !0 })
1451
+ h || (h = document.createElement("script"), h.id = "UiEditorScript", h.src = T, h.onload = async () => {
1452
+ await p();
1453
+ }, document.body.appendChild(h)), await new Promise(
1454
+ (y) => h.addEventListener("load", () => y(), { once: !0 })
1337
1455
  );
1338
1456
  }
1339
- const h = async () => {
1340
- const g = m.current;
1341
- if (!g) {
1457
+ const p = async () => {
1458
+ const T = E.current;
1459
+ if (!T) {
1342
1460
  console.error("Missing #stripoEditorContainer in DOM");
1343
1461
  return;
1344
1462
  }
@@ -1346,48 +1464,48 @@ const st = qe(rt), ve = 5, at = ({
1346
1464
  console.error("UIEditor script not loaded or not exposing initEditor");
1347
1465
  return;
1348
1466
  }
1349
- const b = {
1467
+ const h = {
1350
1468
  html: o.html,
1351
1469
  css: o.css,
1352
1470
  modulesExcludedCategories: l ?? [],
1353
1471
  forceRecreate: !0,
1354
1472
  metadata: {
1355
- emailId: y,
1473
+ emailId: v,
1356
1474
  userId: "1",
1357
1475
  // username: userName,
1358
- avatarUrl: T
1476
+ avatarUrl: I
1359
1477
  },
1360
1478
  locale: "en",
1361
- onTokenRefreshRequest: async (p) => {
1362
- const v = {
1363
- pluginId: we.EDITOR_PLUGIN_ID,
1364
- secretKey: we.EDITOR_SECRET_KEY,
1365
- userId: y,
1479
+ onTokenRefreshRequest: async (y) => {
1480
+ const g = {
1481
+ pluginId: xe.EDITOR_PLUGIN_ID,
1482
+ secretKey: xe.EDITOR_SECRET_KEY,
1483
+ userId: v,
1366
1484
  role: "user"
1367
- }, O = await i(
1368
- w,
1369
- v
1485
+ }, R = await i(
1486
+ b,
1487
+ g
1370
1488
  );
1371
- O?.token && p(O.token);
1489
+ R?.token && y(R.token);
1372
1490
  },
1373
1491
  onTemplateLoaded: () => {
1374
1492
  a && a(!0);
1375
1493
  },
1376
- mergeTags: ut(r ?? [])
1494
+ mergeTags: Nt(s ?? [])
1377
1495
  };
1378
- for (const [p, v] of Object.entries({
1496
+ for (const [y, g] of Object.entries({
1379
1497
  codeEditorButtonSelector: "#codeEditor",
1380
1498
  undoButtonSelector: "#undoButton",
1381
1499
  redoButtonSelector: "#redoButton",
1382
1500
  mobileViewButtonSelector: "#mobileViewButton",
1383
1501
  desktopViewButtonSelector: "#desktopViewButton"
1384
1502
  }))
1385
- g.ownerDocument && g.getRootNode() instanceof ShadowRoot && g.getRootNode().querySelector(v) && (b[p] = v);
1386
- await window.UIEditor.initEditor(g, b);
1503
+ T.ownerDocument && T.getRootNode() instanceof ShadowRoot && T.getRootNode().querySelector(g) && (h[y] = g);
1504
+ await window.UIEditor.initEditor(T, h);
1387
1505
  };
1388
- return /* @__PURE__ */ t("div", { className: "position-relative", children: /* @__PURE__ */ c("div", { className: `editor-container ${n}`, children: [
1389
- s && /* @__PURE__ */ t("div", { className: "loading-overlay", children: /* @__PURE__ */ t(
1390
- Ke,
1506
+ return /* @__PURE__ */ t("div", { className: "position-relative", children: /* @__PURE__ */ d("div", { className: `editor-container ${n}`, children: [
1507
+ r && /* @__PURE__ */ t("div", { className: "loading-overlay", children: /* @__PURE__ */ t(
1508
+ Qe,
1391
1509
  {
1392
1510
  animation: "border",
1393
1511
  style: { width: "11px", height: "11px" },
@@ -1398,21 +1516,21 @@ const st = qe(rt), ve = 5, at = ({
1398
1516
  }
1399
1517
  ) }),
1400
1518
  /* @__PURE__ */ t("div", { id: "externalSystemContainer" }),
1401
- /* @__PURE__ */ t("div", { id: "stripoEditorContainer", ref: m })
1519
+ /* @__PURE__ */ t("div", { id: "stripoEditorContainer", ref: E })
1402
1520
  ] }) });
1403
- }, $e = ({
1521
+ }, Me = ({
1404
1522
  label: e,
1405
1523
  register: n,
1406
- validation: s,
1524
+ validation: r,
1407
1525
  required: a = !1,
1408
1526
  name: i,
1409
- error: r,
1527
+ error: s,
1410
1528
  className: l = "",
1411
1529
  ...o
1412
1530
  }) => {
1413
- const d = !!(r && r[i]);
1414
- return /* @__PURE__ */ c("div", { className: `ts-form-group ${l}`, children: [
1415
- e && /* @__PURE__ */ c("label", { className: "ts-form-label", children: [
1531
+ const c = !!(s && s[i]);
1532
+ return /* @__PURE__ */ d("div", { className: `ts-form-group ${l}`, children: [
1533
+ e && /* @__PURE__ */ d("label", { className: "ts-form-label", children: [
1416
1534
  e,
1417
1535
  a && /* @__PURE__ */ t("span", { className: "ts-required", children: "*" })
1418
1536
  ] }),
@@ -1423,79 +1541,59 @@ const st = qe(rt), ve = 5, at = ({
1423
1541
  type: "text",
1424
1542
  ...o,
1425
1543
  ...n ? n(i, {
1426
- ...s
1544
+ ...r
1427
1545
  }) : {},
1428
- className: `ts-input ${d ? "ts-input-error" : ""}`,
1429
- "aria-invalid": d
1546
+ className: `ts-input ${c ? "ts-input-error" : ""}`,
1547
+ "aria-invalid": c
1430
1548
  }
1431
1549
  ),
1432
- d && /* @__PURE__ */ t("div", { className: "ts-error-text", children: r?.[i]?.message })
1550
+ c && /* @__PURE__ */ t("div", { className: "ts-error-text", children: s?.[i]?.message })
1433
1551
  ] });
1434
1552
  };
1435
- function Ne(e) {
1436
- return e.sort((n, s) => n.name.localeCompare(s.name));
1437
- }
1438
- function yt(e) {
1439
- const n = /* @__PURE__ */ new Map(), s = [];
1440
- e.forEach((r) => n.set(r.id, r));
1441
- let a = e.filter((r) => r.parent_id === 0), i = 0;
1442
- for (; a.length > 0; ) {
1443
- s.push({ level: i, data: a });
1444
- const r = a.map((o) => o.id);
1445
- a = e.filter(
1446
- (o) => r.includes(o.parent_id)
1447
- ), i++;
1448
- }
1449
- return s;
1450
- }
1451
- function Te(e, n) {
1452
- const a = yt(e).find((i) => i.level === n);
1453
- return a ? a.data : [];
1454
- }
1455
- function gt(e) {
1553
+ function St(e) {
1456
1554
  return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
1457
1555
  }
1458
- var Ce = { exports: {} };
1556
+ var Ee = { exports: {} };
1459
1557
  /*!
1460
1558
  Copyright (c) 2018 Jed Watson.
1461
1559
  Licensed under the MIT License (MIT), see
1462
1560
  http://jedwatson.github.io/classnames
1463
1561
  */
1464
- var Ae;
1465
- function bt() {
1466
- return Ae || (Ae = 1, function(e) {
1562
+ var _e;
1563
+ function Lt() {
1564
+ return _e || (_e = 1, function(e) {
1467
1565
  (function() {
1468
1566
  var n = {}.hasOwnProperty;
1469
- function s() {
1470
- for (var r = "", l = 0; l < arguments.length; l++) {
1567
+ function r() {
1568
+ for (var s = "", l = 0; l < arguments.length; l++) {
1471
1569
  var o = arguments[l];
1472
- o && (r = i(r, a(o)));
1570
+ o && (s = i(s, a(o)));
1473
1571
  }
1474
- return r;
1572
+ return s;
1475
1573
  }
1476
- function a(r) {
1477
- if (typeof r == "string" || typeof r == "number")
1478
- return r;
1479
- if (typeof r != "object")
1574
+ function a(s) {
1575
+ if (typeof s == "string" || typeof s == "number")
1576
+ return s;
1577
+ if (typeof s != "object")
1480
1578
  return "";
1481
- if (Array.isArray(r))
1482
- return s.apply(null, r);
1483
- if (r.toString !== Object.prototype.toString && !r.toString.toString().includes("[native code]"))
1484
- return r.toString();
1579
+ if (Array.isArray(s))
1580
+ return r.apply(null, s);
1581
+ if (s.toString !== Object.prototype.toString && !s.toString.toString().includes("[native code]"))
1582
+ return s.toString();
1485
1583
  var l = "";
1486
- for (var o in r)
1487
- n.call(r, o) && r[o] && (l = i(l, o));
1584
+ for (var o in s)
1585
+ n.call(s, o) && s[o] && (l = i(l, o));
1488
1586
  return l;
1489
1587
  }
1490
- function i(r, l) {
1491
- return l ? r ? r + " " + l : r + l : r;
1588
+ function i(s, l) {
1589
+ return l ? s ? s + " " + l : s + l : s;
1492
1590
  }
1493
- e.exports ? (s.default = s, e.exports = s) : window.classNames = s;
1591
+ e.exports ? (r.default = r, e.exports = r) : window.classNames = r;
1494
1592
  })();
1495
- }(Ce)), Ce.exports;
1593
+ }(Ee)), Ee.exports;
1496
1594
  }
1497
- var vt = bt();
1498
- const _e = /* @__PURE__ */ gt(vt), De = (e) => e.data.isSeparator ? /* @__PURE__ */ t("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ t(
1595
+ var kt = Lt();
1596
+ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__ */ t("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ t(
1499
1597
  "hr",
1500
1598
  {
1501
1599
  style: {
@@ -1505,37 +1603,37 @@ const _e = /* @__PURE__ */ gt(vt), De = (e) => e.data.isSeparator ? /* @__PURE__
1505
1603
  margin: 0
1506
1604
  }
1507
1605
  }
1508
- ) }) : e.data.icon ? /* @__PURE__ */ c("div", { className: "d-flex align-items-center", children: [
1509
- /* @__PURE__ */ t(Pe.Option, { ...e }),
1606
+ ) }) : e.data.icon ? /* @__PURE__ */ d("div", { className: "d-flex align-items-center", children: [
1607
+ /* @__PURE__ */ t(Ae.Option, { ...e }),
1510
1608
  /* @__PURE__ */ t("span", { className: "px-1 template-studio-dropdown-postfix-icon", children: e.data.icon })
1511
- ] }) : /* @__PURE__ */ t(Pe.Option, { ...e }), wt = ({
1609
+ ] }) : /* @__PURE__ */ t(Ae.Option, { ...e }), It = ({
1512
1610
  name: e = "",
1513
1611
  control: n,
1514
- options: s,
1612
+ options: r,
1515
1613
  multiple: a = !1,
1516
1614
  placeholder: i,
1517
- validation: r,
1615
+ validation: s,
1518
1616
  labelKey: l = "name",
1519
1617
  disabled: o,
1520
- isInvalid: d,
1521
- value: y,
1522
- onChange: m,
1523
- uncontrolled: T,
1524
- menuPlacement: w = "auto",
1525
- closeOnSelect: E = !0
1618
+ isInvalid: c,
1619
+ value: v,
1620
+ onChange: E,
1621
+ uncontrolled: I,
1622
+ menuPlacement: b = "auto",
1623
+ closeOnSelect: x = !0
1526
1624
  }) => {
1527
- const A = {
1528
- control: (h) => ({
1529
- ...h,
1625
+ const u = {
1626
+ control: (p) => ({
1627
+ ...p,
1530
1628
  minHeight: "33px",
1531
1629
  // state.isFocused can display different borderColor if you need it
1532
- borderColor: d ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
1533
- backgroundImage: d ? 'url("data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 12 12%27 width=%2712%27 height=%2712%27 fill=%27none%27 stroke=%27%23fa5c7c%27%3e%3ccircle cx=%276%27 cy=%276%27 r=%274.5%27/%3e%3cpath stroke-linejoin=%27round%27 d=%27M5.8 3.6h.4L6 6.5z%27/%3e%3ccircle cx=%276%27 cy=%278.2%27 r=%27.6%27 fill=%27%23fa5c7c%27 stroke=%27none%27/%3e%3c/svg%3e")' : "none",
1630
+ borderColor: c ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
1631
+ backgroundImage: c ? 'url("data:image/svg+xml,%3csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 12 12%27 width=%2712%27 height=%2712%27 fill=%27none%27 stroke=%27%23fa5c7c%27%3e%3ccircle cx=%276%27 cy=%276%27 r=%274.5%27/%3e%3cpath stroke-linejoin=%27round%27 d=%27M5.8 3.6h.4L6 6.5z%27/%3e%3ccircle cx=%276%27 cy=%278.2%27 r=%27.6%27 fill=%27%23fa5c7c%27 stroke=%27none%27/%3e%3c/svg%3e")' : "none",
1534
1632
  backgroundRepeat: "no-repeat",
1535
1633
  backgroundPosition: "right calc(0.375em + 0.225rem) center",
1536
1634
  backgroundSize: "calc(0.75em + 0.45rem) calc(0.75em + 0.45rem)",
1537
1635
  "&:hover": {
1538
- borderColor: d ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
1636
+ borderColor: c ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
1539
1637
  },
1540
1638
  "& .react-select__single-value": {
1541
1639
  color: "var(--ct-input-color) !important"
@@ -1547,344 +1645,342 @@ const _e = /* @__PURE__ */ gt(vt), De = (e) => e.data.isSeparator ? /* @__PURE__
1547
1645
  display: "none"
1548
1646
  }
1549
1647
  }),
1550
- menu: (h) => ({
1551
- ...h,
1648
+ menu: (p) => ({
1649
+ ...p,
1552
1650
  marginTop: 0,
1553
1651
  width: "max-content",
1554
1652
  minWidth: "100%"
1555
1653
  }),
1556
- menuPortal: (h) => ({
1557
- ...h,
1654
+ menuPortal: (p) => ({
1655
+ ...p,
1558
1656
  zIndex: 1e4
1559
1657
  }),
1560
- multiValueRemove: (h) => ({
1561
- ...h,
1658
+ multiValueRemove: (p) => ({
1659
+ ...p,
1562
1660
  display: o ? "none" : "block"
1563
1661
  })
1564
1662
  };
1565
- return T ? /* @__PURE__ */ t(
1566
- Le,
1663
+ return I ? /* @__PURE__ */ t(
1664
+ $e,
1567
1665
  {
1568
- components: { Option: De },
1569
- isOptionDisabled: (h) => !!h.isSeparator,
1570
- className: _e({
1571
- "is-invalid": d
1666
+ components: { Option: Be },
1667
+ isOptionDisabled: (p) => !!p.isSeparator,
1668
+ className: Re({
1669
+ "is-invalid": c
1572
1670
  }),
1573
- styles: A,
1671
+ styles: u,
1574
1672
  classNamePrefix: "react-select",
1575
1673
  isMulti: a,
1576
- options: s,
1577
- onChange: m,
1674
+ options: r,
1675
+ onChange: E,
1578
1676
  placeholder: i,
1579
1677
  menuPortalTarget: document.body,
1580
- value: y,
1581
- getOptionLabel: typeof l == "string" ? (h) => h[l] : l,
1582
- getOptionValue: (h) => h.id,
1678
+ value: v,
1679
+ getOptionLabel: typeof l == "string" ? (p) => p[l] : l,
1680
+ getOptionValue: (p) => p.id,
1583
1681
  isDisabled: o,
1584
- menuPlacement: w,
1585
- closeMenuOnSelect: E
1682
+ menuPlacement: b,
1683
+ closeMenuOnSelect: x
1586
1684
  }
1587
1685
  ) : /* @__PURE__ */ t(
1588
- Ge,
1686
+ Xe,
1589
1687
  {
1590
1688
  control: n,
1591
1689
  name: e,
1592
- rules: r,
1593
- render: ({ field: { onChange: h, value: g, onBlur: b } }) => /* @__PURE__ */ t(
1594
- Le,
1690
+ rules: s,
1691
+ render: ({ field: { onChange: p, value: T, onBlur: h } }) => /* @__PURE__ */ t(
1692
+ $e,
1595
1693
  {
1596
- components: { Option: De },
1597
- isOptionDisabled: (p) => !!p.isSeparator,
1598
- className: _e({
1599
- "is-invalid": d
1694
+ components: { Option: Be },
1695
+ isOptionDisabled: (y) => !!y.isSeparator,
1696
+ className: Re({
1697
+ "is-invalid": c
1600
1698
  }),
1601
- styles: A,
1699
+ styles: u,
1602
1700
  classNamePrefix: "react-select",
1603
1701
  isMulti: a,
1604
- options: s,
1605
- onBlur: b,
1606
- onChange: h,
1702
+ options: r,
1703
+ onBlur: h,
1704
+ onChange: p,
1607
1705
  placeholder: i,
1608
1706
  menuPortalTarget: document.body,
1609
- value: g,
1610
- getOptionLabel: typeof l == "string" ? (p) => p[l] : l,
1611
- getOptionValue: (p) => p.id,
1707
+ value: T,
1708
+ getOptionLabel: typeof l == "string" ? (y) => y[l] : l,
1709
+ getOptionValue: (y) => y.id,
1612
1710
  isDisabled: o,
1613
- menuPlacement: w,
1614
- closeMenuOnSelect: E
1711
+ menuPlacement: b,
1712
+ closeMenuOnSelect: x
1615
1713
  },
1616
- g ? g.id || g.value || JSON.stringify(g) : "reset"
1714
+ T ? T.id || T.value || JSON.stringify(T) : "reset"
1617
1715
  )
1618
1716
  }
1619
1717
  );
1620
- }, ue = ({
1718
+ }, fe = ({
1621
1719
  label: e,
1622
1720
  name: n,
1623
- validation: s,
1721
+ validation: r,
1624
1722
  control: a,
1625
1723
  error: i,
1626
- options: r = [],
1724
+ options: s = [],
1627
1725
  required: l = !1,
1628
1726
  disabled: o = !1,
1629
- className: d = ""
1727
+ className: c = ""
1630
1728
  }) => {
1631
- const y = !!(i && i[n]);
1632
- return /* @__PURE__ */ c("div", { className: `ts-form-group ${d}`, children: [
1633
- e && /* @__PURE__ */ c("label", { className: "ts-form-label", children: [
1729
+ const v = !!(i && i[n]);
1730
+ return /* @__PURE__ */ d("div", { className: `ts-form-group ${c}`, children: [
1731
+ e && /* @__PURE__ */ d("label", { className: "ts-form-label", children: [
1634
1732
  e,
1635
1733
  l && /* @__PURE__ */ t("span", { className: "ts-required", children: "*" })
1636
1734
  ] }),
1637
1735
  /* @__PURE__ */ t(
1638
- wt,
1736
+ It,
1639
1737
  {
1640
1738
  name: n,
1641
1739
  control: a,
1642
- options: r,
1643
- validation: s,
1740
+ options: s,
1741
+ validation: r,
1644
1742
  disabled: o,
1645
- isInvalid: y
1743
+ isInvalid: v
1646
1744
  }
1647
1745
  ),
1648
- y && /* @__PURE__ */ t("div", { className: "ts-error-text", children: i?.[n]?.message })
1746
+ v && /* @__PURE__ */ t("div", { className: "ts-error-text", children: i?.[n]?.message })
1649
1747
  ] });
1650
- }, Nt = () => {
1651
- const e = z();
1652
- He();
1653
- const { enerexIdentifier: n, projectId: s } = q();
1654
- return oe({
1748
+ }, Dt = () => {
1749
+ const e = Y();
1750
+ Ye();
1751
+ const { enerexIdentifier: n, projectId: r } = V();
1752
+ return ce({
1655
1753
  mutationKey: ["saveTemplate"],
1656
- mutationFn: async (i) => (i.enerexIdentifier = n ?? "", i.projectId = s ?? "", await e.post(
1754
+ mutationFn: async (i) => (i.enerexIdentifier = n ?? "", i.projectId = r ?? "", await e.post(
1657
1755
  `${Q.SaveTemplate}`,
1658
1756
  i
1659
1757
  ))
1660
1758
  });
1661
- }, Tt = {
1759
+ }, Pt = {
1662
1760
  id: "",
1663
1761
  name: "New (Blank)"
1664
- }, Ct = ({
1762
+ }, $t = ({
1665
1763
  onReset: e,
1666
1764
  editorInitialized: n,
1667
- mode: s,
1765
+ mode: r,
1668
1766
  templateTypes: a,
1669
1767
  templateList: i,
1670
- template: r,
1768
+ template: s,
1671
1769
  onRefresh: l,
1672
1770
  closeEditorModal: o
1673
1771
  }) => {
1674
- const { defaultSelector: d, isAdmin: y, userEmail: m } = q(), { mutateAsync: T, isPending: w } = Fe(), {
1675
- register: E,
1676
- handleSubmit: A,
1677
- clearErrors: h,
1678
- setValue: g,
1679
- control: b,
1680
- watch: p,
1681
- reset: v,
1682
- setError: O,
1683
- formState: { errors: M }
1684
- } = We({
1772
+ const { defaultSelector: c, isAdmin: v, userEmail: E } = V(), { mutateAsync: I, isPending: b } = Ue(), {
1773
+ register: x,
1774
+ handleSubmit: u,
1775
+ clearErrors: p,
1776
+ setValue: T,
1777
+ control: h,
1778
+ watch: y,
1779
+ reset: g,
1780
+ setError: R,
1781
+ formState: { errors: B }
1782
+ } = Je({
1685
1783
  defaultValues: {
1686
1784
  templateName: "",
1687
1785
  subTemplateType: void 0,
1688
1786
  subTemplateType2: void 0,
1689
1787
  subject: "",
1690
1788
  templateType: void 0,
1691
- template: Tt
1789
+ template: Pt
1692
1790
  },
1693
1791
  mode: "onChange"
1694
- }), [P, U] = N([]), [C, k] = N(), { mutateAsync: x, isPending: $ } = Nt(), [B, ce] = N([]), [V, K] = N([]), [G, Z] = N([]), [ye, ee] = N(!1), te = J(!1), { showNotification: ae } = ke(), H = s === "edit", ie = ye || $ || w || !n;
1792
+ }), [_, A] = C([]), [S, D] = C(), { mutateAsync: M, isPending: w } = Dt(), [ne, U] = C([]), [W, K] = C([]), [O, re] = C([]), [le, de] = C(!1), Z = te(!1), { showNotification: se } = ve(), H = r === "edit", ue = le || w || b || !n;
1695
1793
  L(() => {
1696
1794
  if (a) {
1697
- let f = a.filter((_) => _.id != null), I = Te(f, 0);
1698
- ce(Ne(I));
1795
+ let f = a.filter((F) => F.id != null), k = Ne(f, 0);
1796
+ U(Te(k));
1699
1797
  }
1700
1798
  }, [a]), L(() => {
1701
- s === "edit" && !te.current && ee(!0);
1702
- }, [s]), L(() => {
1703
- if (s !== "edit" || !r || !n || !a.length || !P.length || te.current) return;
1704
- const f = P.find((F) => F.id === r.templateID);
1799
+ r === "edit" && !Z.current && de(!0);
1800
+ }, [r]), L(() => {
1801
+ if (r !== "edit" || !s || !n || !a.length || !_.length || Z.current) return;
1802
+ const f = _.find((q) => q.id === s.templateID);
1705
1803
  if (!f) return;
1706
- const I = a.filter((F) => F.id != null), _ = I.find((F) => `${F.id}` == `${f.type}`), j = _ ? I.find((F) => `${F.id}` == `${_.parent_id}`) : void 0, X = j ? I.find((F) => `${F.id}` == `${j.parent_id}`) : void 0;
1707
- v({
1708
- templateType: X ? ne(X) : void 0,
1709
- subTemplateType: j ? ne(j) : void 0,
1710
- subTemplateType2: _ ? ne(_) : void 0,
1804
+ const k = a.filter((q) => q.id != null), F = k.find((q) => `${q.id}` == `${f.type}`), j = F ? k.find((q) => `${q.id}` == `${F.parent_id}`) : void 0, X = j ? k.find((q) => `${q.id}` == `${j.parent_id}`) : void 0;
1805
+ g({
1806
+ templateType: X ? ee(X) : void 0,
1807
+ subTemplateType: j ? ee(j) : void 0,
1808
+ subTemplateType2: F ? ee(F) : void 0,
1711
1809
  template: f,
1712
- templateName: r.name ?? "",
1713
- subject: r.subject ?? ""
1714
- }), k(f), te.current = !0, ee(!1);
1715
- }, [s, r, n, a, P, v]);
1716
- const ne = (f) => ({
1810
+ templateName: s.name ?? "",
1811
+ subject: s.subject ?? ""
1812
+ }), D(f), Z.current = !0, de(!1);
1813
+ }, [r, s, n, a, _, g]);
1814
+ const ee = (f) => ({
1717
1815
  id: String(f.id),
1718
1816
  name: f.name,
1719
1817
  key: f.key
1720
1818
  });
1721
1819
  L(() => {
1722
- i?.sort((f, I) => f.readonly !== I.readonly ? (f.readonly ? 0 : 1) - (I.readonly ? 0 : 1) : f.name.localeCompare(I.name)), U(i ?? []);
1820
+ i?.sort((f, k) => f.readonly !== k.readonly ? (f.readonly ? 0 : 1) - (k.readonly ? 0 : 1) : f.name.localeCompare(k.name)), A(i ?? []);
1723
1821
  }, [i]), L(() => {
1724
- if (!p("templateType")) return;
1725
- const f = Te(a, 1);
1822
+ if (!y("templateType")) return;
1823
+ const f = Ne(a, 1);
1726
1824
  K(
1727
- Ne(
1728
- f.filter((I) => `${I.parent_id}` == `${p("templateType")?.id}`)
1825
+ Te(
1826
+ f.filter((k) => `${k.parent_id}` == `${y("templateType")?.id}`)
1729
1827
  )
1730
- );
1731
- }, [p("templateType"), a]), L(() => {
1732
- const f = p("subTemplateType");
1828
+ ), T("subTemplateType", void 0);
1829
+ }, [y("templateType"), a]), L(() => {
1830
+ const f = y("subTemplateType");
1733
1831
  if (!f) return;
1734
- const I = Te(a, 2);
1735
- let _ = Ne(
1736
- I.filter((j) => `${j.parent_id}` == `${f.id}`)
1832
+ const k = Ne(a, 2);
1833
+ let F = Te(
1834
+ k.filter((j) => `${j.parent_id}` == `${f.id}`)
1737
1835
  );
1738
- s !== "edit" && !y && (_ = _.filter((j) => j.key !== 2)), Z(_);
1739
- }, [p("subTemplateType"), a, s]), L(() => {
1740
- if (d && d.type1) {
1741
- const f = B?.find(
1742
- (I) => `${I.id}` === d.type1
1836
+ r !== "edit" && !v && (F = F.filter((j) => j.key !== 2)), re(F);
1837
+ }, [y("subTemplateType"), a, r]), L(() => {
1838
+ if (c && c.type1) {
1839
+ const f = ne?.find(
1840
+ (k) => `${k.id}` === c.type1
1743
1841
  );
1744
- g("templateType", f);
1842
+ T("templateType", f);
1745
1843
  }
1746
- }, [a, B]), L(() => {
1747
- if (d && d.type2) {
1748
- const f = V?.find(
1749
- (I) => `${I.id}` === d.type2
1844
+ }, [a, ne]), L(() => {
1845
+ if (c && c.type2) {
1846
+ const f = W?.find(
1847
+ (k) => `${k.id}` === c.type2
1750
1848
  );
1751
- g("subTemplateType", f);
1849
+ T("subTemplateType", f);
1752
1850
  }
1753
- }, [a, V]), L(() => {
1754
- if (d && d.type3) {
1755
- const f = G?.find(
1756
- (I) => `${I.id}` === d.type3
1851
+ }, [a, W]), L(() => {
1852
+ if (c && c.type3) {
1853
+ const f = O?.find(
1854
+ (k) => `${k.id}` === c.type3
1757
1855
  );
1758
- g("subTemplateType2", f);
1856
+ T("subTemplateType2", f);
1759
1857
  }
1760
- }, [a, G]);
1761
- const de = (f) => {
1858
+ }, [a, O]);
1859
+ const me = (f) => {
1762
1860
  window.StripoEditorApi.actionsApi.getTemplateData(
1763
- async (I) => {
1861
+ async (k) => {
1764
1862
  try {
1765
- let _ = f.template.id, j = "";
1766
- const X = f.templateName.trim();
1767
- C?.readonly && (_ = "", j = f.template.id);
1768
- const F = P.find(
1769
- (R) => R.name === f.templateName.trim()
1863
+ let F = f.template.id, j = "";
1864
+ const X = f.templateName.trim(), q = _.find(
1865
+ (N) => N.name === f.templateName.trim()
1770
1866
  );
1771
- if (F && F.id !== _) {
1772
- O("templateName", {
1867
+ if (q && q?.id !== f.template.id) {
1868
+ R("templateName", {
1773
1869
  type: "validate",
1774
1870
  message: "Template name already exists. Please choose a different name."
1775
1871
  });
1776
1872
  return;
1777
1873
  }
1778
- let me = f.templateType.id;
1779
- G?.length > 0 ? me = f.subTemplateType2.id : V?.length > 0 && (me = f.subTemplateType.id);
1780
- const u = {
1874
+ let oe = f.templateType.id;
1875
+ O?.length > 0 ? oe = f.subTemplateType2.id : W?.length > 0 && (oe = f.subTemplateType.id);
1876
+ const Ie = {
1781
1877
  enerexIdentifier: "",
1782
1878
  projectId: "",
1783
- templateId: _,
1784
- templateType: me,
1879
+ templateId: F,
1880
+ templateType: oe,
1785
1881
  name: X,
1786
- html: I.html,
1787
- css: I.css,
1882
+ html: k.html,
1883
+ css: k.css,
1788
1884
  subject: f.templateType.id === "2" ? f?.subject ?? "" : "",
1789
1885
  parent_id: j,
1790
- updatedBy: m ?? ""
1886
+ updatedBy: E ?? ""
1791
1887
  };
1792
- if (!await x(u)) {
1793
- ae(
1888
+ if (!await M(Ie)) {
1889
+ se(
1794
1890
  "Failed to save template. Please try again.",
1795
1891
  "error"
1796
1892
  );
1797
1893
  return;
1798
1894
  }
1799
- ae(
1895
+ se(
1800
1896
  H ? `Template "${X}" updated successfully.` : `Template "${X}" created successfully.`,
1801
1897
  "success"
1802
- ), h(), l(), o();
1803
- } catch (_) {
1804
- console.error(_), ae(
1898
+ ), p(), l(), o();
1899
+ } catch (F) {
1900
+ console.error(F), se(
1805
1901
  "Something went wrong while saving the template.",
1806
1902
  "error"
1807
1903
  );
1808
1904
  }
1809
1905
  }
1810
1906
  );
1811
- }, le = p("templateType"), ge = p("subTemplateType");
1812
- return /* @__PURE__ */ c(fe, { children: [
1813
- ie && /* @__PURE__ */ t(se, { overlay: !0 }),
1814
- /* @__PURE__ */ t("div", { className: "ts-card", children: /* @__PURE__ */ t("div", { className: "ts-card-body", children: /* @__PURE__ */ t("form", { children: /* @__PURE__ */ t("div", { className: "template-list-container", children: /* @__PURE__ */ c("div", { className: "ts-row", children: [
1907
+ }, pe = y("templateType"), be = y("subTemplateType");
1908
+ return /* @__PURE__ */ d(ye, { children: [
1909
+ ue && /* @__PURE__ */ t(ie, { overlay: !0 }),
1910
+ /* @__PURE__ */ t("div", { className: "ts-card", children: /* @__PURE__ */ t("div", { className: "ts-card-body", children: /* @__PURE__ */ t("form", { children: /* @__PURE__ */ t("div", { className: "template-list-container", children: /* @__PURE__ */ d("div", { className: "ts-row", children: [
1815
1911
  /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1816
- ue,
1912
+ fe,
1817
1913
  {
1818
1914
  label: "Category",
1819
- control: b,
1820
- error: M,
1821
- options: B,
1915
+ control: h,
1916
+ error: B,
1917
+ options: ne,
1822
1918
  required: !0,
1823
- disabled: H || $ || w || !n,
1919
+ disabled: H || w || b || !n,
1824
1920
  validation: {
1825
1921
  required: {
1826
1922
  value: !0,
1827
1923
  message: "Select a category"
1828
1924
  }
1829
1925
  },
1830
- ...E("templateType")
1926
+ ...x("templateType")
1831
1927
  }
1832
1928
  ) }),
1833
- V && V.length > 0 && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1834
- ue,
1929
+ W && W.length > 0 && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1930
+ fe,
1835
1931
  {
1836
1932
  label: "Type",
1837
- control: b,
1838
- error: M,
1839
- options: V,
1933
+ control: h,
1934
+ error: B,
1935
+ options: W,
1840
1936
  required: !0,
1841
- disabled: H || $ || w || !n,
1937
+ disabled: H || w || b || !n,
1842
1938
  validation: {
1843
1939
  required: {
1844
1940
  value: !0,
1845
1941
  message: "Select a type"
1846
1942
  }
1847
1943
  },
1848
- ...E("subTemplateType")
1944
+ ...x("subTemplateType")
1849
1945
  }
1850
1946
  ) }),
1851
- G && G.length > 0 && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1852
- ue,
1947
+ O && O.length > 0 && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1948
+ fe,
1853
1949
  {
1854
1950
  label: "Sub Type",
1855
- control: b,
1856
- error: M,
1857
- options: G,
1951
+ control: h,
1952
+ error: B,
1953
+ options: O,
1858
1954
  required: !0,
1859
- disabled: H || $ || w || !n,
1955
+ disabled: H || w || b || !n,
1860
1956
  validation: {
1861
1957
  required: {
1862
1958
  value: !0,
1863
1959
  message: "Select a subtype"
1864
1960
  }
1865
1961
  },
1866
- ...E("subTemplateType2")
1962
+ ...x("subTemplateType2")
1867
1963
  }
1868
1964
  ) }),
1869
1965
  /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1870
- ue,
1966
+ fe,
1871
1967
  {
1872
1968
  label: "Template",
1873
- control: b,
1874
- error: M,
1875
- disabled: H || !H || $ || w || !n,
1969
+ control: h,
1970
+ error: B,
1971
+ disabled: H || !H || w || b || !n,
1876
1972
  options: [],
1877
1973
  required: !1,
1878
- ...E("template")
1974
+ ...x("template")
1879
1975
  }
1880
1976
  ) }),
1881
- /* @__PURE__ */ c("div", { className: "ts-col ts-template-name-col", children: [
1977
+ /* @__PURE__ */ d("div", { className: "ts-col ts-template-name-col", children: [
1882
1978
  /* @__PURE__ */ t(
1883
- $e,
1979
+ Me,
1884
1980
  {
1885
1981
  label: "Name",
1886
- register: E,
1887
- error: M,
1982
+ register: x,
1983
+ error: B,
1888
1984
  required: !0,
1889
1985
  name: "templateName",
1890
1986
  validation: {
@@ -1895,141 +1991,117 @@ const _e = /* @__PURE__ */ gt(vt), De = (e) => e.data.isSeparator ? /* @__PURE__
1895
1991
  }
1896
1992
  }
1897
1993
  ),
1898
- ge?.key?.toString() === "9" && H && C?.is_favourite && // <button
1899
- // type="button"
1900
- // className="template-favourite-btn ts-btn-light"
1901
- // disabled={
1902
- // loading3 ||
1903
- // loading5 ||
1904
- // (selectedTemplateMeta
1905
- // ? selectedTemplateMeta?.is_favourite
1906
- // : false)
1907
- // }
1908
- // onClick={handlemarkFavourite}
1909
- // >
1910
- // {loading3 || loading5 ? (
1911
- // <Loader size="sm" />
1912
- // ) : selectedTemplateMeta ? (
1913
- // selectedTemplateMeta?.is_favourite ? (
1914
- // <StarIcon variant="filled" />
1915
- // ) : (
1916
- // <StarIcon variant="outlined" />
1917
- // )
1918
- // ) : (
1919
- // <StarIcon variant="outlined" />
1920
- // )}
1921
- // </button>
1922
- /* @__PURE__ */ t("span", { className: "ts-favourite-icon", children: /* @__PURE__ */ t(Ee, { variant: "filled" }) })
1994
+ be?.key?.toString() === "9" && H && !v && S?.is_favourite && /* @__PURE__ */ t("span", { className: "ts-favourite-icon", children: /* @__PURE__ */ t(Le, { variant: "filled" }) })
1923
1995
  ] }),
1924
- le?.key?.toString() === "12" && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1925
- $e,
1996
+ pe?.key?.toString() === "12" && /* @__PURE__ */ t("div", { className: "ts-col", children: /* @__PURE__ */ t(
1997
+ Me,
1926
1998
  {
1927
1999
  label: "Subject",
1928
- register: E,
1929
- error: M,
2000
+ register: x,
2001
+ error: B,
1930
2002
  required: !1,
1931
2003
  name: "subject"
1932
2004
  }
1933
2005
  ) }),
1934
- /* @__PURE__ */ c("div", { className: "ts-col ts-actions btn-padding", children: [
2006
+ /* @__PURE__ */ d("div", { className: "ts-col ts-actions btn-padding", children: [
1935
2007
  !H && /* @__PURE__ */ t(
1936
2008
  "button",
1937
2009
  {
1938
2010
  type: "button",
1939
2011
  className: "ts-btn ts-btn-primary",
1940
- disabled: $ || w || !n,
2012
+ disabled: w || b || !n,
1941
2013
  onClick: () => {
1942
- k(void 0), v(), K([]), Z([]), e();
2014
+ D(void 0), g(), K([]), re([]), e();
1943
2015
  },
1944
- children: $ || w ? /* @__PURE__ */ t(se, { size: "sm" }) : "Clear"
2016
+ children: w || b ? /* @__PURE__ */ t(ie, { size: "sm" }) : "Clear"
1945
2017
  }
1946
2018
  ),
1947
- (le?.key?.toString() !== "12" || (le?.key?.toString() === "12" && (C?.id ?? "")) !== "") && /* @__PURE__ */ t(
2019
+ /* @__PURE__ */ t(
1948
2020
  "button",
1949
2021
  {
1950
2022
  type: "button",
1951
2023
  className: "ts-btn ts-btn-primary",
1952
- disabled: $ || w || !n,
1953
- onClick: A(de),
1954
- children: $ || w ? (
2024
+ disabled: w || b || !n,
2025
+ onClick: u(me),
2026
+ children: w || b ? (
1955
2027
  // <span className="ts-spinner" />
1956
- /* @__PURE__ */ t(se, { size: "sm" })
2028
+ /* @__PURE__ */ t(ie, { size: "sm" })
1957
2029
  ) : "Save"
1958
2030
  }
1959
2031
  )
1960
2032
  ] })
1961
2033
  ] }) }) }) }) })
1962
2034
  ] });
1963
- }, xt = ({
2035
+ }, At = (e) => /* @__PURE__ */ t("svg", { xmlns: "http://www.w3.org/2000/svg", height: "20px", width: "20px", viewBox: "0 0 640 640", ...e, children: /* @__PURE__ */ t("path", { fill: "#6c757d", d: "M560 144L240 144L240 176L192 176L192 96L608 96L608 416L496 416L496 368L560 368L560 144zM80 352L80 496L400 496L400 352L80 352zM80 224L448 224L448 544L32 544L32 224L80 224z" }) }), Mt = (e) => /* @__PURE__ */ t("svg", { xmlns: "http://www.w3.org/2000/svg", height: "20px", width: "20px", viewBox: "0 0 640 640", ...e, children: /* @__PURE__ */ t("path", { fill: "#6c757d", d: "M112 288L112 464L528 464L528 288L112 288zM64 128L576 128L576 512L64 512L64 128z" }) }), _t = ({
1964
2036
  show: e,
1965
2037
  mode: n,
1966
- template: s,
2038
+ template: r,
1967
2039
  templateTypes: a,
1968
2040
  templateList: i,
1969
- editorInitialized: r,
2041
+ editorInitialized: s,
1970
2042
  previewHtml: l,
1971
2043
  onEditorInitialized: o,
1972
- onClose: d,
1973
- onRefresh: y
2044
+ onClose: c,
2045
+ onRefresh: v
1974
2046
  }) => {
1975
- const m = J(null), [T, w] = N(!1);
2047
+ const E = te(null), [I, b] = C(!1);
1976
2048
  L(() => {
1977
- e && r && window.StripoEditorApi?.actionsApi && (n === "add" ? window.StripoEditorApi.actionsApi.updateHtmlAndCss(pe, "", "") : n === "edit" && s && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1978
- s.html ?? pe,
1979
- s.css ?? "",
2049
+ e && s && window.StripoEditorApi?.actionsApi && (n === "add" ? window.StripoEditorApi.actionsApi.updateHtmlAndCss(he, "", "") : n === "edit" && r && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
2050
+ r.html ?? he,
2051
+ r.css ?? "",
1980
2052
  ""
1981
2053
  ));
1982
- }, [e, r, n, s]), L(() => {
1983
- e || w(!1);
2054
+ }, [e, s, n, r]), L(() => {
2055
+ e || b(!1);
1984
2056
  }, [e]);
1985
- const E = () => {
1986
- window.StripoEditorApi.actionsApi.updateHtmlAndCss(pe, "", "");
2057
+ const x = () => {
2058
+ window.StripoEditorApi.actionsApi.updateHtmlAndCss(he, "", "");
1987
2059
  };
1988
- return e ? /* @__PURE__ */ t("div", { className: "ts-editor-modal-overlay", children: /* @__PURE__ */ c(
2060
+ return e ? /* @__PURE__ */ t("div", { className: "ts-editor-modal-overlay", children: /* @__PURE__ */ d(
1989
2061
  "div",
1990
2062
  {
1991
- className: `ts-editor-modal ${T ? "ts-editor-modal--fullscreen" : ""}`,
1992
- ref: m,
2063
+ className: `ts-editor-modal ${I ? "ts-editor-modal--fullscreen" : ""}`,
2064
+ ref: E,
1993
2065
  children: [
1994
- /* @__PURE__ */ c("div", { className: "ts-editor-modal-header", children: [
1995
- /* @__PURE__ */ c("h3", { className: "ts-modal-title", children: [
2066
+ /* @__PURE__ */ d("div", { className: "ts-editor-modal-header", children: [
2067
+ /* @__PURE__ */ d("h3", { className: "ts-modal-title", children: [
1996
2068
  n === "add" && "Create Template",
1997
2069
  n === "edit" && "Edit Template",
1998
2070
  n === "preview" && "Preview Template"
1999
2071
  ] }),
2000
- /* @__PURE__ */ c("div", { className: "ts-editor-header-actions", children: [
2072
+ /* @__PURE__ */ d("div", { className: "ts-editor-header-actions", children: [
2001
2073
  /* @__PURE__ */ t(
2002
2074
  "button",
2003
2075
  {
2004
2076
  className: "ts-editor-fullscreen-btn",
2005
- onClick: () => w((A) => !A),
2077
+ onClick: () => b((u) => !u),
2006
2078
  "aria-label": "Toggle fullscreen",
2007
- children: T ? "🗗" : "🗖"
2079
+ children: I ? /* @__PURE__ */ t(At, { style: { display: "block" } }) : /* @__PURE__ */ t(Mt, { style: { display: "block" } })
2008
2080
  }
2009
2081
  ),
2010
2082
  /* @__PURE__ */ t(
2011
2083
  "button",
2012
2084
  {
2013
2085
  className: "ts-editor-close-btn",
2014
- onClick: d,
2086
+ onClick: c,
2015
2087
  "aria-label": "Close editor",
2016
2088
  children: "✕"
2017
2089
  }
2018
2090
  )
2019
2091
  ] })
2020
2092
  ] }),
2021
- /* @__PURE__ */ c("div", { className: "ts-editor-modal-body", children: [
2093
+ /* @__PURE__ */ d("div", { className: "ts-editor-modal-body", children: [
2022
2094
  n !== "preview" && /* @__PURE__ */ t(
2023
- Ct,
2095
+ $t,
2024
2096
  {
2025
2097
  mode: n,
2026
- template: s,
2098
+ template: r,
2027
2099
  templateTypes: a,
2028
2100
  templateList: i,
2029
- editorInitialized: r,
2030
- onReset: E,
2031
- onRefresh: y,
2032
- closeEditorModal: d
2101
+ editorInitialized: s,
2102
+ onReset: x,
2103
+ onRefresh: v,
2104
+ closeEditorModal: c
2033
2105
  }
2034
2106
  ),
2035
2107
  n === "preview" ? /* @__PURE__ */ t("div", { className: "ts-template-preview", children: /* @__PURE__ */ t(
@@ -2040,7 +2112,7 @@ const _e = /* @__PURE__ */ gt(vt), De = (e) => e.data.isSeparator ? /* @__PURE__
2040
2112
  srcDoc: l ?? ""
2041
2113
  }
2042
2114
  ) }) : /* @__PURE__ */ t(
2043
- ht,
2115
+ Et,
2044
2116
  {
2045
2117
  onEditorInitialized: o,
2046
2118
  loading: !1,
@@ -2051,61 +2123,61 @@ const _e = /* @__PURE__ */ gt(vt), De = (e) => e.data.isSeparator ? /* @__PURE__
2051
2123
  ]
2052
2124
  }
2053
2125
  ) }) : null;
2054
- }, Et = () => {
2126
+ }, Rt = () => {
2055
2127
  const {
2056
2128
  data: e,
2057
2129
  isLoading: n,
2058
- isFetching: s,
2130
+ isFetching: r,
2059
2131
  refetch: a
2060
- } = et(), {
2132
+ } = at(), {
2061
2133
  data: i,
2062
- isLoading: r,
2134
+ isLoading: s,
2063
2135
  isFetching: l
2064
- } = tt(), { mutateAsync: o, isPending: d } = nt(), [y, m] = N(!1), [T, w] = N("add"), [E, A] = N(!1), [h, g] = N(""), [b, p] = N(), v = () => {
2065
- w("add"), m(!0);
2066
- }, O = async (C) => {
2067
- const k = await o({ id: C.id });
2068
- p({ ...k }), w("edit"), m(!0);
2069
- }, M = (C) => {
2136
+ } = it(), { mutateAsync: o, isPending: c } = lt(), [v, E] = C(!1), [I, b] = C("add"), [x, u] = C(!1), [p, T] = C(""), [h, y] = C(), g = () => {
2137
+ b("add"), E(!0);
2138
+ }, R = async (S) => {
2139
+ const D = await o({ id: S.id });
2140
+ y({ ...D }), b("edit"), E(!0);
2141
+ }, B = (S) => {
2070
2142
  if (!e || e.length === 0) return;
2071
- const k = e.find((x) => x.id === C.id);
2072
- g(k?.html ?? ""), w("preview"), m(!0);
2073
- }, P = () => {
2074
- m(!1), A(!1), document.getElementById("UiEditorScript")?.remove();
2143
+ const D = e.find((M) => M.id === S.id);
2144
+ T(D?.html + "<style>" + D?.css + "</style>"), b("preview"), E(!0);
2145
+ }, _ = () => {
2146
+ E(!1), u(!1), document.getElementById("UiEditorScript")?.remove();
2075
2147
  };
2076
- return /* @__PURE__ */ c(fe, { children: [
2077
- (n || r || s || l || d) && /* @__PURE__ */ t(se, { overlay: !0 }),
2148
+ return /* @__PURE__ */ d(ye, { children: [
2149
+ (n || s || r || l || c) && /* @__PURE__ */ t(ie, { overlay: !0 }),
2078
2150
  /* @__PURE__ */ t(
2079
- mt,
2151
+ Tt,
2080
2152
  {
2081
2153
  templates: e ?? [],
2082
2154
  templateTypes: i ?? [],
2083
2155
  onRefresh: a,
2084
- onAdd: v,
2085
- onEdit: O,
2086
- onPreview: M
2156
+ onAdd: g,
2157
+ onEdit: R,
2158
+ onPreview: B
2087
2159
  }
2088
2160
  ),
2089
2161
  /* @__PURE__ */ t(
2090
- xt,
2162
+ _t,
2091
2163
  {
2092
- show: y,
2093
- mode: T,
2094
- template: b,
2164
+ show: v,
2165
+ mode: I,
2166
+ template: h,
2095
2167
  templateTypes: i ?? [],
2096
2168
  templateList: e ?? [],
2097
- editorInitialized: E,
2098
- onEditorInitialized: A,
2099
- onClose: P,
2169
+ editorInitialized: x,
2170
+ onEditorInitialized: u,
2171
+ onClose: _,
2100
2172
  onSaved: () => {
2101
- P(), a();
2173
+ _(), a();
2102
2174
  },
2103
2175
  onRefresh: a,
2104
- previewHtml: h
2176
+ previewHtml: p
2105
2177
  }
2106
2178
  )
2107
2179
  ] });
2108
- }, _t = ({ config: e }) => /* @__PURE__ */ t(ze, { configs: e, children: /* @__PURE__ */ t(Ze, { children: /* @__PURE__ */ t(Ye, { children: /* @__PURE__ */ t("div", { className: "root-widget", children: /* @__PURE__ */ t(Et, {}) }) }) }) });
2180
+ }, Kt = ({ config: e }) => /* @__PURE__ */ t(Ze, { configs: e, children: /* @__PURE__ */ t(st, { children: /* @__PURE__ */ t(nt, { children: /* @__PURE__ */ t("div", { className: "root-widget", children: /* @__PURE__ */ t(Rt, {}) }) }) }) });
2109
2181
  export {
2110
- _t as EditorWidget
2182
+ Kt as EditorWidget
2111
2183
  };