@enerex/template-studio 1.1.43 → 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.
@@ -13,7 +13,7 @@ const Fe = G.createContext(
13
13
  }) => {
14
14
  const [r, a] = G.useState(n.clientId), [i, s] = G.useState(n.apiKey), [l, o] = G.useState(
15
15
  n.enerexIdentifier
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), [w, h] = G.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
18
  ), y = (g) => {
19
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);
@@ -29,7 +29,7 @@ const Fe = G.createContext(
29
29
  projectId: c,
30
30
  userEmail: E,
31
31
  isAdmin: b,
32
- defaultSelector: w,
32
+ defaultSelector: T,
33
33
  meBaseUrl: u
34
34
  },
35
35
  children: e
@@ -316,7 +316,7 @@ function ut({
316
316
  onPreview: l,
317
317
  onRefresh: o
318
318
  }) {
319
- const { isAdmin: c } = V(), v = n === e.id, E = te(null), I = te(null), [b, x, u] = e.categoryChain, { mutateAsync: p, isPending: w } = Ue(), { showNotification: h } = ve(), y = x?.key, g = u?.key, R = !c && y === 9, B = c || g !== 2, _ = c || g !== 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;
320
320
  L(() => {
321
321
  function S(D) {
322
322
  v && E.current && !E.current.contains(D.target) && !I.current?.contains(D.target) && r(null);
@@ -335,8 +335,8 @@ function ut({
335
335
  if (!S.length) return;
336
336
  let D = 0;
337
337
  S[0].focus();
338
- function M(T) {
339
- T.key === "ArrowDown" && (D = (D + 1) % S.length, S[D].focus(), T.preventDefault()), T.key === "ArrowUp" && (D = (D - 1 + S.length) % S.length, S[D].focus(), T.preventDefault());
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());
340
340
  }
341
341
  return document.addEventListener("keydown", M), () => document.removeEventListener("keydown", M);
342
342
  }, [v]);
@@ -368,7 +368,7 @@ function ut({
368
368
  disabled: e.is_favourite,
369
369
  onClick: A,
370
370
  title: "Mark as favourite",
371
- children: w ? /* @__PURE__ */ t(ie, { size: "sm" }) : e.is_favourite ? /* @__PURE__ */ t(Le, { variant: "filled" }) : /* @__PURE__ */ t(Le, { variant: "outlined" })
371
+ children: T ? /* @__PURE__ */ t(ie, { size: "sm" }) : e.is_favourite ? /* @__PURE__ */ t(Le, { variant: "filled" }) : /* @__PURE__ */ t(Le, { variant: "outlined" })
372
372
  }
373
373
  ),
374
374
  /* @__PURE__ */ t(
@@ -628,19 +628,19 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
628
628
  disableConfirm: x = !1,
629
629
  onConfirm: u,
630
630
  onCancel: p,
631
- onInputChange: w
631
+ onInputChange: T
632
632
  }) => {
633
633
  const [h, y] = C(s), [g, R] = C(!1), B = te(null);
634
634
  if (L(() => {
635
635
  if (!e) return;
636
- const M = (T) => {
637
- T.key === "Escape" && p();
636
+ const M = (w) => {
637
+ w.key === "Escape" && p();
638
638
  };
639
639
  return document.addEventListener("keydown", M), () => document.removeEventListener("keydown", M);
640
640
  }, [e, p]), L(() => {
641
641
  if (!e) return;
642
- const M = (T) => {
643
- B.current && !B.current.contains(T.target) && p();
642
+ const M = (w) => {
643
+ B.current && !B.current.contains(w.target) && p();
644
644
  };
645
645
  return document.addEventListener("mousedown", M), () => document.removeEventListener("mousedown", M);
646
646
  }, [e, p]), L(() => {
@@ -680,7 +680,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
680
680
  placeholder: l,
681
681
  value: h,
682
682
  onChange: (M) => {
683
- y(M.target.value), g && R(!1), w?.(M.target.value);
683
+ y(M.target.value), g && R(!1), T?.(M.target.value);
684
684
  },
685
685
  autoFocus: !0,
686
686
  style: { paddingBlock: "0", paddingInline: "0" }
@@ -757,8 +757,8 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
757
757
  onEdit: i,
758
758
  onPreview: s
759
759
  }) => {
760
- const { isAdmin: l } = V(), { mutateAsync: o, isPending: c } = vt(), { mutateAsync: v, isPending: E } = bt(), [I, b] = C(""), [x, u] = C(""), [p, w] = C(null), [h, y] = C(e), [g, R] = C(n), [B, _] = C(!1), [A, S] = C("input"), [D, M] = C(!1), [T, ne] = C(null), [U, W] = C("asc"), K = (m) => {
761
- T === m ? W((N) => N === "asc" ? "desc" : "asc") : (ne(m), W("asc")), ee(1);
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
762
  }, [O, re] = C(null);
763
763
  L(() => {
764
764
  const m = [...e].sort((N, $) => {
@@ -804,12 +804,12 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
804
804
  }, [Z, x]), pe = ae(() => {
805
805
  const m = [...me];
806
806
  return m.sort((N, $) => {
807
- if (T === "lastUpdatedOn") {
807
+ if (w === "lastUpdatedOn") {
808
808
  const Ve = new Date(N.updatedDateTime).getTime(), Ke = new Date($.updatedDateTime).getTime(), Pe = Ve - Ke;
809
809
  return U === "asc" ? Pe : -Pe;
810
810
  }
811
811
  let P = "", z = "";
812
- switch (T) {
812
+ switch (w) {
813
813
  case "name":
814
814
  P = N.name, z = $.name;
815
815
  break;
@@ -837,7 +837,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
837
837
  });
838
838
  return U === "asc" ? De : -De;
839
839
  }), m;
840
- }, [me, T, U]), { pagedData: be } = wt({
840
+ }, [me, w, U]), { pagedData: be } = wt({
841
841
  data: pe,
842
842
  page: ue,
843
843
  pageSize: se
@@ -912,7 +912,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
912
912
  {
913
913
  label: "Name",
914
914
  sortKey: "name",
915
- sortBy: T,
915
+ sortBy: w,
916
916
  sortOrder: U,
917
917
  onSort: K
918
918
  }
@@ -922,7 +922,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
922
922
  {
923
923
  label: "Template Id",
924
924
  sortKey: "templateId",
925
- sortBy: T,
925
+ sortBy: w,
926
926
  sortOrder: U,
927
927
  onSort: K
928
928
  }
@@ -932,7 +932,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
932
932
  {
933
933
  label: "Category",
934
934
  sortKey: "category",
935
- sortBy: T,
935
+ sortBy: w,
936
936
  sortOrder: U,
937
937
  onSort: K
938
938
  }
@@ -942,7 +942,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
942
942
  {
943
943
  label: "Type",
944
944
  sortKey: "type",
945
- sortBy: T,
945
+ sortBy: w,
946
946
  sortOrder: U,
947
947
  onSort: K
948
948
  }
@@ -952,7 +952,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
952
952
  {
953
953
  label: "Subtype",
954
954
  sortKey: "subtype",
955
- sortBy: T,
955
+ sortBy: w,
956
956
  sortOrder: U,
957
957
  onSort: K
958
958
  }
@@ -962,7 +962,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
962
962
  {
963
963
  label: "Company Name",
964
964
  sortKey: "companyName",
965
- sortBy: T,
965
+ sortBy: w,
966
966
  sortOrder: U,
967
967
  onSort: K
968
968
  }
@@ -972,7 +972,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
972
972
  {
973
973
  label: "Last Updated by",
974
974
  sortKey: "lastUpdatedBy",
975
- sortBy: T,
975
+ sortBy: w,
976
976
  sortOrder: U,
977
977
  onSort: K
978
978
  }
@@ -982,7 +982,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
982
982
  {
983
983
  label: "Last Updated on",
984
984
  sortKey: "lastUpdatedOn",
985
- sortBy: T,
985
+ sortBy: w,
986
986
  sortOrder: U,
987
987
  onSort: K
988
988
  }
@@ -994,7 +994,7 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
994
994
  {
995
995
  template: m,
996
996
  openActionId: p,
997
- setOpenActionId: w,
997
+ setOpenActionId: T,
998
998
  onDuplicate: k,
999
999
  onEdit: i,
1000
1000
  onRemove: F,
@@ -1437,26 +1437,26 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
1437
1437
  (async () => (await x(), s && l && await u(xe.EDITOR_SCRIPT_URL)))();
1438
1438
  }, [s, l]);
1439
1439
  async function x() {
1440
- window.Zone || await new Promise((w, h) => {
1440
+ window.Zone || await new Promise((T, h) => {
1441
1441
  const y = document.createElement("script");
1442
1442
  y.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
1443
1443
  const g = document.querySelector("script[nonce]")?.nonce;
1444
- g && y.setAttribute("nonce", g), y.onload = () => w(), y.onerror = () => h(new Error("Failed to load zone.js")), document.head.appendChild(y);
1444
+ g && y.setAttribute("nonce", g), y.onload = () => T(), y.onerror = () => h(new Error("Failed to load zone.js")), document.head.appendChild(y);
1445
1445
  });
1446
1446
  }
1447
- async function u(w) {
1447
+ async function u(T) {
1448
1448
  let h = document.getElementById(
1449
1449
  "UiEditorScript"
1450
1450
  );
1451
- h || (h = document.createElement("script"), h.id = "UiEditorScript", h.src = w, h.onload = async () => {
1451
+ h || (h = document.createElement("script"), h.id = "UiEditorScript", h.src = T, h.onload = async () => {
1452
1452
  await p();
1453
1453
  }, document.body.appendChild(h)), await new Promise(
1454
1454
  (y) => h.addEventListener("load", () => y(), { once: !0 })
1455
1455
  );
1456
1456
  }
1457
1457
  const p = async () => {
1458
- const w = E.current;
1459
- if (!w) {
1458
+ const T = E.current;
1459
+ if (!T) {
1460
1460
  console.error("Missing #stripoEditorContainer in DOM");
1461
1461
  return;
1462
1462
  }
@@ -1500,8 +1500,8 @@ const mt = ze(ut), pt = (e) => /* @__PURE__ */ t(
1500
1500
  mobileViewButtonSelector: "#mobileViewButton",
1501
1501
  desktopViewButtonSelector: "#desktopViewButton"
1502
1502
  }))
1503
- w.ownerDocument && w.getRootNode() instanceof ShadowRoot && w.getRootNode().querySelector(g) && (h[y] = g);
1504
- await window.UIEditor.initEditor(w, h);
1503
+ T.ownerDocument && T.getRootNode() instanceof ShadowRoot && T.getRootNode().querySelector(g) && (h[y] = g);
1504
+ await window.UIEditor.initEditor(T, h);
1505
1505
  };
1506
1506
  return /* @__PURE__ */ t("div", { className: "position-relative", children: /* @__PURE__ */ d("div", { className: `editor-container ${n}`, children: [
1507
1507
  r && /* @__PURE__ */ t("div", { className: "loading-overlay", children: /* @__PURE__ */ t(
@@ -1688,7 +1688,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1688
1688
  control: n,
1689
1689
  name: e,
1690
1690
  rules: s,
1691
- render: ({ field: { onChange: p, value: w, onBlur: h } }) => /* @__PURE__ */ t(
1691
+ render: ({ field: { onChange: p, value: T, onBlur: h } }) => /* @__PURE__ */ t(
1692
1692
  $e,
1693
1693
  {
1694
1694
  components: { Option: Be },
@@ -1704,14 +1704,14 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1704
1704
  onChange: p,
1705
1705
  placeholder: i,
1706
1706
  menuPortalTarget: document.body,
1707
- value: w,
1707
+ value: T,
1708
1708
  getOptionLabel: typeof l == "string" ? (y) => y[l] : l,
1709
1709
  getOptionValue: (y) => y.id,
1710
1710
  isDisabled: o,
1711
1711
  menuPlacement: b,
1712
1712
  closeMenuOnSelect: x
1713
1713
  },
1714
- w ? w.id || w.value || JSON.stringify(w) : "reset"
1714
+ T ? T.id || T.value || JSON.stringify(T) : "reset"
1715
1715
  )
1716
1716
  }
1717
1717
  );
@@ -1773,7 +1773,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1773
1773
  register: x,
1774
1774
  handleSubmit: u,
1775
1775
  clearErrors: p,
1776
- setValue: w,
1776
+ setValue: T,
1777
1777
  control: h,
1778
1778
  watch: y,
1779
1779
  reset: g,
@@ -1789,7 +1789,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1789
1789
  template: Pt
1790
1790
  },
1791
1791
  mode: "onChange"
1792
- }), [_, A] = C([]), [S, D] = C(), { mutateAsync: M, isPending: T } = 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 || T || b || !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;
1793
1793
  L(() => {
1794
1794
  if (a) {
1795
1795
  let f = a.filter((F) => F.id != null), k = Ne(f, 0);
@@ -1825,7 +1825,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1825
1825
  Te(
1826
1826
  f.filter((k) => `${k.parent_id}` == `${y("templateType")?.id}`)
1827
1827
  )
1828
- ), w("subTemplateType", void 0), w("subTemplateType2", void 0);
1828
+ ), T("subTemplateType", void 0);
1829
1829
  }, [y("templateType"), a]), L(() => {
1830
1830
  const f = y("subTemplateType");
1831
1831
  if (!f) return;
@@ -1833,27 +1833,27 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1833
1833
  let F = Te(
1834
1834
  k.filter((j) => `${j.parent_id}` == `${f.id}`)
1835
1835
  );
1836
- r !== "edit" && !v && (F = F.filter((j) => j.key !== 2)), re(F), w("subTemplateType2", void 0);
1836
+ r !== "edit" && !v && (F = F.filter((j) => j.key !== 2)), re(F);
1837
1837
  }, [y("subTemplateType"), a, r]), L(() => {
1838
1838
  if (c && c.type1) {
1839
1839
  const f = ne?.find(
1840
1840
  (k) => `${k.id}` === c.type1
1841
1841
  );
1842
- w("templateType", f);
1842
+ T("templateType", f);
1843
1843
  }
1844
1844
  }, [a, ne]), L(() => {
1845
1845
  if (c && c.type2) {
1846
1846
  const f = W?.find(
1847
1847
  (k) => `${k.id}` === c.type2
1848
1848
  );
1849
- w("subTemplateType", f);
1849
+ T("subTemplateType", f);
1850
1850
  }
1851
1851
  }, [a, W]), L(() => {
1852
1852
  if (c && c.type3) {
1853
1853
  const f = O?.find(
1854
1854
  (k) => `${k.id}` === c.type3
1855
1855
  );
1856
- w("subTemplateType2", f);
1856
+ T("subTemplateType2", f);
1857
1857
  }
1858
1858
  }, [a, O]);
1859
1859
  const me = (f) => {
@@ -1916,7 +1916,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1916
1916
  error: B,
1917
1917
  options: ne,
1918
1918
  required: !0,
1919
- disabled: H || T || b || !n,
1919
+ disabled: H || w || b || !n,
1920
1920
  validation: {
1921
1921
  required: {
1922
1922
  value: !0,
@@ -1934,7 +1934,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1934
1934
  error: B,
1935
1935
  options: W,
1936
1936
  required: !0,
1937
- disabled: H || T || b || !n,
1937
+ disabled: H || w || b || !n,
1938
1938
  validation: {
1939
1939
  required: {
1940
1940
  value: !0,
@@ -1952,7 +1952,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1952
1952
  error: B,
1953
1953
  options: O,
1954
1954
  required: !0,
1955
- disabled: H || T || b || !n,
1955
+ disabled: H || w || b || !n,
1956
1956
  validation: {
1957
1957
  required: {
1958
1958
  value: !0,
@@ -1968,7 +1968,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
1968
1968
  label: "Template",
1969
1969
  control: h,
1970
1970
  error: B,
1971
- disabled: H || !H || T || b || !n,
1971
+ disabled: H || !H || w || b || !n,
1972
1972
  options: [],
1973
1973
  required: !1,
1974
1974
  ...x("template")
@@ -2009,11 +2009,11 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
2009
2009
  {
2010
2010
  type: "button",
2011
2011
  className: "ts-btn ts-btn-primary",
2012
- disabled: T || b || !n,
2012
+ disabled: w || b || !n,
2013
2013
  onClick: () => {
2014
2014
  D(void 0), g(), K([]), re([]), e();
2015
2015
  },
2016
- children: T || b ? /* @__PURE__ */ t(ie, { size: "sm" }) : "Clear"
2016
+ children: w || b ? /* @__PURE__ */ t(ie, { size: "sm" }) : "Clear"
2017
2017
  }
2018
2018
  ),
2019
2019
  /* @__PURE__ */ t(
@@ -2021,9 +2021,9 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
2021
2021
  {
2022
2022
  type: "button",
2023
2023
  className: "ts-btn ts-btn-primary",
2024
- disabled: T || b || !n,
2024
+ disabled: w || b || !n,
2025
2025
  onClick: u(me),
2026
- children: T || b ? (
2026
+ children: w || b ? (
2027
2027
  // <span className="ts-spinner" />
2028
2028
  /* @__PURE__ */ t(ie, { size: "sm" })
2029
2029
  ) : "Save"
@@ -2133,7 +2133,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
2133
2133
  data: i,
2134
2134
  isLoading: s,
2135
2135
  isFetching: l
2136
- } = it(), { mutateAsync: o, isPending: c } = lt(), [v, E] = C(!1), [I, b] = C("add"), [x, u] = C(!1), [p, w] = C(""), [h, y] = C(), g = () => {
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
2137
  b("add"), E(!0);
2138
2138
  }, R = async (S) => {
2139
2139
  const D = await o({ id: S.id });
@@ -2141,7 +2141,7 @@ const Re = /* @__PURE__ */ St(kt), Be = (e) => e.data.isSeparator ? /* @__PURE__
2141
2141
  }, B = (S) => {
2142
2142
  if (!e || e.length === 0) return;
2143
2143
  const D = e.find((M) => M.id === S.id);
2144
- w(D?.html + "<style>" + D?.css + "</style>"), b("preview"), E(!0);
2144
+ T(D?.html + "<style>" + D?.css + "</style>"), b("preview"), E(!0);
2145
2145
  }, _ = () => {
2146
2146
  E(!1), u(!1), document.getElementById("UiEditorScript")?.remove();
2147
2147
  };
@@ -1,4 +1,4 @@
1
- (function(j,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("@tanstack/react-query"),require("axios"),require("react-bootstrap"),require("react-hook-form"),require("react-select")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@tanstack/react-query","axios","react-bootstrap","react-hook-form","react-select"],e):(j=typeof globalThis<"u"?globalThis:j||self,e(j.EnerexTemplateEditor={},j.jsxRuntime,j.React,j.reactQuery,j.axios,j.reactBootstrap,j.reactHookForm,j.Select$1))})(this,function(j,e,o,K,me,_e,Ee,oe){"use strict";const Se=o.createContext(void 0),Be=({children:t,configs:n})=>{const[r,a]=o.useState(n.clientId),[l,s]=o.useState(n.apiKey),[i,c]=o.useState(n.enerexIdentifier),[d,v]=o.useState(n.projectId),[S,k]=o.useState(n.userEmail),[b,E]=o.useState(n.isAdmin),[p,f]=o.useState(n.meBaseUrl),[w,h]=o.useState(n.defaultSelector),y=g=>{s(g.apiKey),a(g.clientId),v(g.projectId),c(g.enerexIdentifier),k(g.userEmail),E(g.isAdmin),h(g.defaultSelector),f(g.meBaseUrl)};return e.jsx(Se.Provider,{value:{clientId:r,apiKey:l,setConfiguration:y,enerexIdentifier:i,projectId:d,userEmail:S,isAdmin:b,defaultSelector:w,meBaseUrl:p},children:t})},U=()=>{const t=o.useContext(Se);if(!t)throw new Error("widgetConfig must be used within a ConfigProvider");return t},qe=({message:t,type:n="info",duration:r=3e3,onClose:a})=>(o.useEffect(()=>{const l=setTimeout(a,r);return()=>clearTimeout(l)},[r,a]),e.jsxs("div",{className:`ts-toast ts-toast-${n}`,children:[e.jsx("span",{className:"ts-toast-message",children:t}),e.jsx("button",{className:"ts-toast-close",onClick:a,children:"×"})]})),Fe=()=>{const[t,n]=o.useState(null),r=o.useRef(null);return{showNotification:o.useCallback((s,i="info")=>{r.current!==s&&(r.current=s,n({message:s,type:i}))},[]),NotificationRenderer:()=>t?e.jsx(qe,{message:t.message,type:t.type,onClose:()=>{r.current=null,n(null)}}):null}},Ce=o.createContext(null),Oe=({children:t})=>{const n=Fe();return e.jsxs(Ce.Provider,{value:n,children:[t,e.jsx(n.NotificationRenderer,{})]})},le=()=>{const t=o.useContext(Ce);if(!t)throw new Error("useGlobalNotification must be used within NotificationProvider");return t},xe=(t="",n)=>({get:async(s,i)=>{try{const c=await me.get(`${t}${s}`,i??n);if(c.status===200)return c.data}catch(c){throw c}},post:async(s,i,c)=>{try{const d=await me.post(`${t}${s}`,i,c??n);if(d.status===200)return d.data}catch(d){throw d}},delete:async(s,i)=>{try{const c=await me.delete(`${t}${s}`,i??n);if(c.status===200||c.status===204)return c.data}catch(c){throw c}}}),ke=o.createContext({get:()=>{throw new Error("HttpClientContext.get not implemented")},post:()=>{throw new Error("HttpClientContext.post not implemented")},delete:()=>{throw new Error("HttpClientContext.delete not implemented")}}),je=({children:t})=>{const{clientId:n,apiKey:r,isAdmin:a,meBaseUrl:l}=U(),s={headers:{client_id:n,"x-api-key":r,"Security-Context":a?"admin":"viewer"}},{get:i,post:c,delete:d}=xe(l,s);return e.jsx(ke.Provider,{value:{get:i,post:c,delete:d},children:t})},Ue=({children:t})=>{const n=new K.QueryClient;return e.jsx(je,{children:e.jsx(K.QueryClientProvider,{client:n,children:t})})},W=()=>{const t=o.useContext(ke);if(t)return t;throw new Error("useHttpClient must be used within a HttpClientProvider")},Y={Template_list:"/Template/list/",Template:"/Template/GetTemplate/",MergeTags:"/Template/TemplateMergeTags/",ExcludeCategory:"/Template/GetExcludeCategories/",SaveTemplate:"/Template/save-update/",TemplateTypes:"/Template/TemplateTypes/",markFavourite:"/Template/MarkFavourite/",deleteTemplate:"/Template/DeleteTemplate/",duplicateTemplate:"/Template/DuplicateTemplate/"},Ve=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getTemplatesList"],queryFn:async l=>await t.get(`${Y.Template_list}${r}/${n}`),refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},Ke=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getTemplateTypes"],queryFn:async l=>await t.get(`${Y.TemplateTypes}${n}/${r}`),refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},He=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useMutation({mutationKey:["getTemplate"],mutationFn:async({id:l})=>{if(l)return await t.get(`${Y.Template}${n}/${l}/${r}`)}})},ee=({size:t="md",center:n=!1,overlay:r=!1})=>{const a=e.jsx("div",{className:`ts-loader ts-loader-${t}`});return r?e.jsx("div",{className:"ts-loader-overlay",children:a}):n?e.jsx("div",{className:"ts-loader-center",children:a}):a},Le=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useMutation({mutationKey:["markFavourite"],mutationFn:async l=>await t.post(`${Y.markFavourite}${r}/${n}`,l)})},he=t=>{let n=e.jsx("span",{style:{width:"20px",height:"20px",display:"inline-block"}});return t.variant==="filled"?n=e.jsx("svg",{version:"1.0",id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",width:"18px",height:"18px",viewBox:"0 0 64 64","enable-background":"new 0 0 64 64",children:e.jsx("path",{fill:"#2196F3",d:`M63.893,24.277c-0.238-0.711-0.854-1.229-1.595-1.343l-19.674-3.006L33.809,1.15\r
1
+ (function(j,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react"),require("@tanstack/react-query"),require("axios"),require("react-bootstrap"),require("react-hook-form"),require("react-select")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@tanstack/react-query","axios","react-bootstrap","react-hook-form","react-select"],e):(j=typeof globalThis<"u"?globalThis:j||self,e(j.EnerexTemplateEditor={},j.jsxRuntime,j.React,j.reactQuery,j.axios,j.reactBootstrap,j.reactHookForm,j.Select$1))})(this,function(j,e,o,K,me,_e,Ee,oe){"use strict";const Se=o.createContext(void 0),Be=({children:t,configs:n})=>{const[r,a]=o.useState(n.clientId),[l,s]=o.useState(n.apiKey),[i,c]=o.useState(n.enerexIdentifier),[d,v]=o.useState(n.projectId),[S,k]=o.useState(n.userEmail),[b,E]=o.useState(n.isAdmin),[p,f]=o.useState(n.meBaseUrl),[T,h]=o.useState(n.defaultSelector),y=g=>{s(g.apiKey),a(g.clientId),v(g.projectId),c(g.enerexIdentifier),k(g.userEmail),E(g.isAdmin),h(g.defaultSelector),f(g.meBaseUrl)};return e.jsx(Se.Provider,{value:{clientId:r,apiKey:l,setConfiguration:y,enerexIdentifier:i,projectId:d,userEmail:S,isAdmin:b,defaultSelector:T,meBaseUrl:p},children:t})},U=()=>{const t=o.useContext(Se);if(!t)throw new Error("widgetConfig must be used within a ConfigProvider");return t},qe=({message:t,type:n="info",duration:r=3e3,onClose:a})=>(o.useEffect(()=>{const l=setTimeout(a,r);return()=>clearTimeout(l)},[r,a]),e.jsxs("div",{className:`ts-toast ts-toast-${n}`,children:[e.jsx("span",{className:"ts-toast-message",children:t}),e.jsx("button",{className:"ts-toast-close",onClick:a,children:"×"})]})),Fe=()=>{const[t,n]=o.useState(null),r=o.useRef(null);return{showNotification:o.useCallback((s,i="info")=>{r.current!==s&&(r.current=s,n({message:s,type:i}))},[]),NotificationRenderer:()=>t?e.jsx(qe,{message:t.message,type:t.type,onClose:()=>{r.current=null,n(null)}}):null}},Ce=o.createContext(null),Oe=({children:t})=>{const n=Fe();return e.jsxs(Ce.Provider,{value:n,children:[t,e.jsx(n.NotificationRenderer,{})]})},le=()=>{const t=o.useContext(Ce);if(!t)throw new Error("useGlobalNotification must be used within NotificationProvider");return t},xe=(t="",n)=>({get:async(s,i)=>{try{const c=await me.get(`${t}${s}`,i??n);if(c.status===200)return c.data}catch(c){throw c}},post:async(s,i,c)=>{try{const d=await me.post(`${t}${s}`,i,c??n);if(d.status===200)return d.data}catch(d){throw d}},delete:async(s,i)=>{try{const c=await me.delete(`${t}${s}`,i??n);if(c.status===200||c.status===204)return c.data}catch(c){throw c}}}),ke=o.createContext({get:()=>{throw new Error("HttpClientContext.get not implemented")},post:()=>{throw new Error("HttpClientContext.post not implemented")},delete:()=>{throw new Error("HttpClientContext.delete not implemented")}}),je=({children:t})=>{const{clientId:n,apiKey:r,isAdmin:a,meBaseUrl:l}=U(),s={headers:{client_id:n,"x-api-key":r,"Security-Context":a?"admin":"viewer"}},{get:i,post:c,delete:d}=xe(l,s);return e.jsx(ke.Provider,{value:{get:i,post:c,delete:d},children:t})},Ue=({children:t})=>{const n=new K.QueryClient;return e.jsx(je,{children:e.jsx(K.QueryClientProvider,{client:n,children:t})})},W=()=>{const t=o.useContext(ke);if(t)return t;throw new Error("useHttpClient must be used within a HttpClientProvider")},Y={Template_list:"/Template/list/",Template:"/Template/GetTemplate/",MergeTags:"/Template/TemplateMergeTags/",ExcludeCategory:"/Template/GetExcludeCategories/",SaveTemplate:"/Template/save-update/",TemplateTypes:"/Template/TemplateTypes/",markFavourite:"/Template/MarkFavourite/",deleteTemplate:"/Template/DeleteTemplate/",duplicateTemplate:"/Template/DuplicateTemplate/"},Ve=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getTemplatesList"],queryFn:async l=>await t.get(`${Y.Template_list}${r}/${n}`),refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},Ke=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getTemplateTypes"],queryFn:async l=>await t.get(`${Y.TemplateTypes}${n}/${r}`),refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1})},He=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useMutation({mutationKey:["getTemplate"],mutationFn:async({id:l})=>{if(l)return await t.get(`${Y.Template}${n}/${l}/${r}`)}})},ee=({size:t="md",center:n=!1,overlay:r=!1})=>{const a=e.jsx("div",{className:`ts-loader ts-loader-${t}`});return r?e.jsx("div",{className:"ts-loader-overlay",children:a}):n?e.jsx("div",{className:"ts-loader-center",children:a}):a},Le=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useMutation({mutationKey:["markFavourite"],mutationFn:async l=>await t.post(`${Y.markFavourite}${r}/${n}`,l)})},he=t=>{let n=e.jsx("span",{style:{width:"20px",height:"20px",display:"inline-block"}});return t.variant==="filled"?n=e.jsx("svg",{version:"1.0",id:"Layer_1",xmlns:"http://www.w3.org/2000/svg",width:"18px",height:"18px",viewBox:"0 0 64 64","enable-background":"new 0 0 64 64",children:e.jsx("path",{fill:"#2196F3",d:`M63.893,24.277c-0.238-0.711-0.854-1.229-1.595-1.343l-19.674-3.006L33.809,1.15\r
2
2
  C33.479,0.448,32.773,0,31.998,0s-1.48,0.448-1.811,1.15l-8.815,18.778L1.698,22.935c-0.741,0.113-1.356,0.632-1.595,1.343\r
3
3
  c-0.238,0.71-0.059,1.494,0.465,2.031l14.294,14.657L11.484,61.67c-0.124,0.756,0.195,1.517,0.822,1.957\r
4
4
  c0.344,0.243,0.747,0.366,1.151,0.366c0.332,0,0.666-0.084,0.968-0.25l17.572-9.719l17.572,9.719c0.302,0.166,0.636,0.25,0.968,0.25\r
@@ -8,7 +8,7 @@
8
8
  c-0.238,0.71-0.059,1.494,0.465,2.031l14.294,14.657L11.484,61.67c-0.124,0.756,0.195,1.517,0.822,1.957\r
9
9
  c0.344,0.243,0.747,0.366,1.151,0.366c0.332,0,0.666-0.084,0.968-0.25l17.572-9.719l17.572,9.719c0.302,0.166,0.636,0.25,0.968,0.25\r
10
10
  c0.404,0,0.808-0.123,1.151-0.366c0.627-0.44,0.946-1.201,0.822-1.957l-3.378-20.704l14.294-14.657\r
11
- C63.951,25.771,64.131,24.987,63.893,24.277z`})})),n};function ye(t){return t.sort((n,r)=>n.name.localeCompare(r.name))}function ze(t){const n=new Map,r=[];t.forEach(s=>n.set(s.id,s));let a=t.filter(s=>s.parent_id===0),l=0;for(;a.length>0;){r.push({level:l,data:a});const s=a.map(c=>c.id);a=t.filter(c=>s.includes(c.parent_id)),l++}return r}function ge(t,n){const a=ze(t).find(l=>l.level===n);return a?a.data:[]}const Ge=t=>{if(!t)return"";const n=new Date(t);if(isNaN(n.getTime()))return"";const r=String(n.getMonth()+1).padStart(2,"0"),a=String(n.getDate()).padStart(2,"0"),l=String(n.getFullYear()).slice(-2);return`${r}/${a}/${l}`},We=t=>e.jsx("svg",{"aria-hidden":"true",focusable:"false",role:"img",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 128 512",height:"11px",width:"14px",...t,children:e.jsx("path",{fill:"#6c757d",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"})});function Ye({template:t,openActionId:n,setOpenActionId:r,onEdit:a,onDuplicate:l,onRemove:s,onPreview:i,onRefresh:c}){const{isAdmin:d}=U(),v=n===t.id,S=o.useRef(null),k=o.useRef(null),[b,E,p]=t.categoryChain,{mutateAsync:f,isPending:w}=Le(),{showNotification:h}=le(),y=E?.key,g=p?.key,$=!d&&y===9,_=d||g!==2,A=d||g!==2;o.useEffect(()=>{function C(L){v&&S.current&&!S.current.contains(L.target)&&!k.current?.contains(L.target)&&r(null)}return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[v,r]),o.useEffect(()=>{function C(L){L.key==="Escape"&&r(null)}return v&&document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[v,r]),o.useEffect(()=>{if(!v||!S.current)return;const C=Array.from(S.current.querySelectorAll('[role="menuitem"]'));if(!C.length)return;let L=0;C[0].focus();function D(T){T.key==="ArrowDown"&&(L=(L+1)%C.length,C[L].focus(),T.preventDefault()),T.key==="ArrowUp"&&(L=(L-1+C.length)%C.length,C[L].focus(),T.preventDefault())}return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[v]);const M=async()=>{try{await f({categoryId:g?.toString()??"",templateId:t.id??""}),c(),h(`Template "${t?.name}" marked as favourite`,"success")}catch(C){console.error(C),h("Unable to mark template as favourite. Please try again.","error")}};return e.jsx(e.Fragment,{children:e.jsxs("tr",{className:"ts-table-row",children:[e.jsxs("td",{children:[" ",e.jsxs("div",{className:"ts-name-cell",children:[$&&e.jsx("button",{type:"button",className:"ts-fav-btn ts-btn-light",disabled:t.is_favourite,onClick:M,title:"Mark as favourite",children:w?e.jsx(ee,{size:"sm"}):t.is_favourite?e.jsx(he,{variant:"filled"}):e.jsx(he,{variant:"outlined"})}),e.jsx("span",{className:t.readonly?"ts-badge default":"ts-badge custom",children:t.readonly?"Default":"Custom"})]})]}),e.jsx("td",{children:e.jsx("div",{className:"",children:e.jsx("span",{className:"ts-template-name",children:t.name})})}),d&&e.jsx("td",{children:t?.id??""}),e.jsx("td",{children:b?.name??""}),e.jsx("td",{children:E?.name??""}),e.jsx("td",{children:p?.name??""}),d&&e.jsx("td",{children:t?.companyName??""}),e.jsx("td",{children:t?.updatedByName??""}),e.jsx("td",{children:Ge(t.updatedDateTime)}),e.jsx("td",{className:"ts-actions-cell",children:e.jsxs("div",{className:"ts-actions-wrapper",children:[e.jsx("button",{ref:k,className:"ts-actions-btn","aria-haspopup":"true","aria-expanded":v,onClick:()=>r(v?null:t.id),children:e.jsx(We,{})}),e.jsxs("div",{ref:S,className:`ts-actions-menu ${v?"open":""}`,role:"menu",children:[e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item",onClick:()=>{r(null),i(t)},children:"Preview"}),_&&e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item",onClick:()=>{r(null),a(t)},children:"Edit"}),e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item",onClick:()=>{r(null),l(t)},children:"Duplicate"}),A&&e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item danger",onClick:()=>{r(null),s(t)},children:"Remove"})]})]})})]})})}const Xe=o.memo(Ye),Je=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"6.01px",height:"9.63px",...t,children:e.jsx("path",{fill:t.fill||"#6c757d",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"})}),Ze=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"6.01px",height:"9.63px",...t,children:e.jsx("path",{fill:t.fill||"#6c757d",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"})}),J=({label:t,sortKey:n,sortBy:r,sortOrder:a,onSort:l})=>e.jsx("th",{onClick:()=>l(n),className:"ts-sortable",children:e.jsxs("div",{className:"ts-th-sort",children:[t,e.jsxs("div",{className:"ts-sort-icons",children:[e.jsx(Je,{fill:r===n&&a==="asc"?"#007bff":"#6c757d",className:r===n&&a==="asc"?"active":""}),e.jsx(Ze,{style:{marginTop:-9.6},fill:r===n&&a==="desc"?"#007bff":"#6c757d",className:r===n&&a==="desc"?"active":""})]})]})}),ve=5,Qe=({page:t,pageSize:n,totalRecords:r,onPageChange:a,onPageSizeChange:l})=>{const s=Math.ceil(r/n),c=s<=ve?Array.from({length:s},(p,f)=>f+1):Array.from({length:ve},(p,f)=>f+1),d=s>ve,v=s,{showNotification:S}=le(),[k,b]=o.useState(String(t));o.useEffect(()=>{b(String(t))},[t]);const E=()=>{const p=Number(k);if(!p||p<1||p>s){S("Page out of range","error"),b(String(t));return}a(p)};return e.jsxs("div",{className:"ts-pagination-bar",children:[e.jsxs("div",{className:"ts-page-container",children:[e.jsxs("div",{className:"ts-page-size",children:[e.jsx("label",{children:"Display:"}),e.jsx("select",{value:n,onChange:p=>{l(Number(p.target.value)),a(1)},children:[10,25,50,100].map(p=>e.jsx("option",{value:p,children:p},p))})]}),e.jsxs("div",{className:"ts-page-info",children:["Page ",e.jsxs("span",{children:[t," of ",s]})]}),e.jsxs("div",{className:"ts-go-to",children:[e.jsx("span",{children:"Go to page:"}),e.jsx("input",{type:"number",value:k,onChange:p=>b(p.target.value),onBlur:E,onKeyDown:p=>{p.key==="Enter"&&E()}})]})]}),e.jsxs("div",{className:"ts-total",children:[e.jsx("span",{children:"Total:"})," ",r]}),e.jsxs("div",{className:"ts-page-buttons",children:[e.jsx("button",{disabled:t===1,onClick:()=>a(t-1),children:"‹"}),c.map(p=>e.jsx("button",{className:p===t?"active":"",onClick:()=>a(p),children:p},p)),d&&e.jsx("span",{style:{padding:"0 6px"},children:"…"}),d&&e.jsx("button",{className:t===v?"active":"",onClick:()=>a(v),children:v}),e.jsx("button",{disabled:t===s,onClick:()=>a(t+1),children:"›"})]})]})},Re=({show:t,variant:n,title:r="Are you sure?",message:a,label:l="Name",value:s="",placeholder:i="",requiredMessage:c="This field is required",externalError:d=!1,externalErrorMessage:v="",confirmText:S="Ok",cancelText:k="Cancel",confirmButtonVariant:b="danger",disableConfirm:E=!1,onConfirm:p,onCancel:f,onInputChange:w})=>{const[h,y]=o.useState(s),[g,$]=o.useState(!1),_=o.useRef(null);if(o.useEffect(()=>{if(!t)return;const D=T=>{T.key==="Escape"&&f()};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[t,f]),o.useEffect(()=>{if(!t)return;const D=T=>{_.current&&!_.current.contains(T.target)&&f()};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[t,f]),o.useEffect(()=>{if(t)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[t]),o.useEffect(()=>{t&&(y(s),$(!1))},[t,s]),o.useEffect(()=>{d&&$(!0)},[d]),!t)return null;const A=n==="input"&&!h.trim(),M=n==="input"&&(A||d),C=A?c:d?v:"",L=()=>{if(M||E){$(!0);return}p(h.trim())};return e.jsx("div",{className:"ts-modal-overlay",children:e.jsxs("div",{ref:_,className:"ts-modal",children:[e.jsxs("div",{className:"ts-modal-header",children:[e.jsx("h4",{className:"ts-modal-title ",children:r}),e.jsx("button",{className:"ts-modal-close",onClick:f,children:"✕"})]}),e.jsxs("div",{className:"ts-modal-body",children:[a&&e.jsx("p",{className:"ts-modal-message",children:a}),n==="input"&&e.jsxs("div",{className:"ts-form-group",children:[e.jsxs("label",{className:"ts-label",children:[l,e.jsx("span",{className:"ts-required",children:"*"})]}),e.jsx("input",{type:"text",className:`ts-input ${g&&M?"ts-input-error":""}`,placeholder:i,value:h,onChange:D=>{y(D.target.value),g&&$(!1),w?.(D.target.value)},autoFocus:!0,style:{paddingBlock:"0",paddingInline:"0"}}),g&&M&&e.jsx("div",{className:"ts-error-text",children:C})]})]}),e.jsxs("div",{className:"ts-modal-footer",children:[e.jsx("button",{type:"button",className:"ts-btn ts-btn-secondary",onClick:f,children:k}),e.jsx("button",{type:"button",className:`ts-btn ts-btn-${b}`,onClick:L,disabled:E,children:S})]})]})})},et=()=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",width:"11px",height:"11px",children:e.jsx("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"})}),tt=()=>{const t=W(),{enerexIdentifier:n,projectId:r,userEmail:a}=U();return K.useMutation({mutationKey:["duplicateTemplate"],mutationFn:async({templateId:s,request:i})=>(i.enerexIdentifier=n??"",i.projectId=r??"",i.updatedBy=a??"",await t.post(`${Y.duplicateTemplate}${s}`,i))})},nt=()=>{const t=W();return K.useMutation({mutationKey:["deleteTemplate"],mutationFn:async n=>{await t.delete(`${Y.deleteTemplate}${n}`)}})},rt=({data:t,page:n,pageSize:r})=>{const a=o.useMemo(()=>Math.ceil(t.length/r),[t.length,r]);return{pagedData:o.useMemo(()=>{const s=(n-1)*r,i=n*r;return t.slice(s,i)},[t,n,r]),totalPages:a}},st=({templates:t,templateTypes:n,onRefresh:r,onAdd:a,onEdit:l,onPreview:s})=>{const{isAdmin:i}=U(),{mutateAsync:c,isPending:d}=tt(),{mutateAsync:v,isPending:S}=nt(),[k,b]=o.useState(""),[E,p]=o.useState(""),[f,w]=o.useState(null),[h,y]=o.useState(t),[g,$]=o.useState(n),[_,A]=o.useState(!1),[M,C]=o.useState("input"),[L,D]=o.useState(!1),[T,te]=o.useState(null),[V,X]=o.useState("asc"),H=u=>{T===u?X(N=>N==="asc"?"desc":"asc"):(te(u),X("asc")),R(1)},[q,ne]=o.useState(null);o.useEffect(()=>{const u=[...t].sort((N,P)=>{if(!i&&N.is_favourite!==P.is_favourite)return Number(P.is_favourite)-Number(N.is_favourite);const I=new Date(P.updatedDateTime).getTime()-new Date(N.updatedDateTime).getTime();return I!==0?I:N.readonly!==P.readonly?Number(N.readonly)-Number(P.readonly):N.name.localeCompare(P.name)});y(u),te(null)},[t]),o.useEffect(()=>{$(n.filter(u=>u.id!=null))},[n]);const se=o.useMemo(()=>{const u=new Map;return g.forEach(N=>u.set(N.id,N)),u},[g]),de=o.useCallback(u=>{const N=[],P=new Set;let I=se.get(u);for(;I&&!(P.has(I.id)||(P.add(I.id),N.push({id:I.id,name:I.name,key:I.key}),!I.parent_id));)I=se.get(I.parent_id);return N.reverse()},[se]),Q=o.useMemo(()=>!h.length||!g.length?[]:h.map(u=>({...u,categoryChain:de(u.type)})),[h,g]);o.useEffect(()=>{const u=setTimeout(()=>{p(k),R(1)},300);return()=>clearTimeout(u)},[k]);const[re,z]=o.useState(25),[pe,R]=o.useState(1),ue=o.useMemo(()=>{const u=E.trim().toLowerCase();return u?Q.filter(N=>{const P=N.name.toLowerCase().includes(u),I=N.categoryChain?.some(G=>G.name.toLowerCase().includes(u));return P||I}):Q},[Q,E]),fe=o.useMemo(()=>{const u=[...ue];return u.sort((N,P)=>{if(T==="lastUpdatedOn"){const Tt=new Date(N.updatedDateTime).getTime(),Nt=new Date(P.updatedDateTime).getTime(),$e=Tt-Nt;return V==="asc"?$e:-$e}let I="",G="";switch(T){case"name":I=N.name,G=P.name;break;case"category":I=N.categoryChain?.[0]?.name??"",G=P.categoryChain?.[0]?.name??"";break;case"type":I=N.categoryChain?.[1]?.name??"",G=P.categoryChain?.[1]?.name??"";break;case"subtype":I=N.categoryChain?.[2]?.name??"",G=P.categoryChain?.[2]?.name??"";break;case"templateId":I=N.id??"",G=P.id??"";break;case"companyName":I=N.companyName??"",G=P.companyName??"";break;case"lastUpdatedBy":I=N.updatedByName??"",G=P.updatedByName??"";break}const Ae=I.localeCompare(G,void 0,{sensitivity:"base"});return V==="asc"?Ae:-Ae}),u},[ue,T,V]),{pagedData:Te}=rt({data:fe,page:pe,pageSize:re}),m=o.useCallback(u=>h.some(N=>N.name.trim().toLowerCase()===u.trim().toLowerCase()),[h]),x=u=>{ne(u),D(!1),C("input"),A(!0)},B=u=>{ne(u),C("confirm"),A(!0)},{showNotification:F}=le(),Z=async u=>{if(q)try{if(M==="input"){if(!u)return;if(m(u)){D(!0);return}await c({templateId:q.id,request:{projectId:"",enerexIdentifier:"",newName:u,parent_id:q.id??null}}),F(`Template "${u}" duplicated successfully`,"success")}M==="confirm"&&(await v(q.id),F(`Template "${q.name}" deleted successfully`,"success")),A(!1),ne(null),r()}catch{F(M==="confirm"?"Failed to delete template. Please try again.":"Failed to duplicate template. Please try again.","error")}},O=q?.categoryChain?.[2]?.name?.toLowerCase()??"this",ae=q?.name?.toLowerCase()??"",Ne=d||S;return e.jsxs(e.Fragment,{children:[Ne&&e.jsx(ee,{overlay:!0}),e.jsxs("div",{className:"ts-page",children:[e.jsxs("div",{className:"ts-header",children:[e.jsx("h1",{className:"ts-title",children:"Templates"}),e.jsx("button",{className:"ts-btn ts-btn-primary",onClick:a,children:"+ Add Template"})]}),e.jsx("div",{className:"ts-search-container",children:e.jsxs("div",{className:"ts-search-container-inner",children:[e.jsx("div",{className:"ts-search",children:e.jsxs("div",{className:"ts-search-box",children:[e.jsx("input",{type:"text",placeholder:"Search...",value:k,onChange:u=>b(u.target.value)}),e.jsx("button",{className:"ts-search-btn","aria-label":"Search",children:e.jsx(et,{})})]})}),e.jsxs("div",{className:"ts-table-wrapper",children:[e.jsxs("table",{className:"ts-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"ts-cursor-default"}),e.jsx(J,{label:"Name",sortKey:"name",sortBy:T,sortOrder:V,onSort:H}),i&&e.jsx(J,{label:"Template Id",sortKey:"templateId",sortBy:T,sortOrder:V,onSort:H}),e.jsx(J,{label:"Category",sortKey:"category",sortBy:T,sortOrder:V,onSort:H}),e.jsx(J,{label:"Type",sortKey:"type",sortBy:T,sortOrder:V,onSort:H}),e.jsx(J,{label:"Subtype",sortKey:"subtype",sortBy:T,sortOrder:V,onSort:H}),i&&e.jsx(J,{label:"Company Name",sortKey:"companyName",sortBy:T,sortOrder:V,onSort:H}),e.jsx(J,{label:"Last Updated by",sortKey:"lastUpdatedBy",sortBy:T,sortOrder:V,onSort:H}),e.jsx(J,{label:"Last Updated on",sortKey:"lastUpdatedOn",sortBy:T,sortOrder:V,onSort:H}),e.jsx("th",{className:"ts-cursor-default",children:"Actions"})]})}),e.jsx("tbody",{children:Te.map(u=>e.jsx(Xe,{template:u,openActionId:f,setOpenActionId:w,onDuplicate:x,onEdit:l,onRemove:B,onPreview:s,onRefresh:r},u.id))})]}),e.jsx(Qe,{page:pe,pageSize:re,totalRecords:fe.length,onPageChange:R,onPageSizeChange:z})]})]})})]}),e.jsx(Re,{show:_,variant:M,title:M==="confirm"?"Are you sure?":"Save Template As",message:M==="confirm"?`Are you sure you want to remove ${O} template "${ae}"?`:"",placeholder:M==="input"?"New name":"",label:"New Name",requiredMessage:"Enter a new name",externalError:L,externalErrorMessage:"Template name already exists. Please choose a different name",confirmText:M==="confirm"?"Ok":"Save as",confirmButtonVariant:M==="confirm"?"danger":"primary",onConfirm:Z,onCancel:()=>A(!1),onInputChange:M==="input"?()=>D(!1):void 0})]})},ie=`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
11
+ C63.951,25.771,64.131,24.987,63.893,24.277z`})})),n};function ye(t){return t.sort((n,r)=>n.name.localeCompare(r.name))}function ze(t){const n=new Map,r=[];t.forEach(s=>n.set(s.id,s));let a=t.filter(s=>s.parent_id===0),l=0;for(;a.length>0;){r.push({level:l,data:a});const s=a.map(c=>c.id);a=t.filter(c=>s.includes(c.parent_id)),l++}return r}function ge(t,n){const a=ze(t).find(l=>l.level===n);return a?a.data:[]}const Ge=t=>{if(!t)return"";const n=new Date(t);if(isNaN(n.getTime()))return"";const r=String(n.getMonth()+1).padStart(2,"0"),a=String(n.getDate()).padStart(2,"0"),l=String(n.getFullYear()).slice(-2);return`${r}/${a}/${l}`},We=t=>e.jsx("svg",{"aria-hidden":"true",focusable:"false",role:"img",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 128 512",height:"11px",width:"14px",...t,children:e.jsx("path",{fill:"#6c757d",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"})});function Ye({template:t,openActionId:n,setOpenActionId:r,onEdit:a,onDuplicate:l,onRemove:s,onPreview:i,onRefresh:c}){const{isAdmin:d}=U(),v=n===t.id,S=o.useRef(null),k=o.useRef(null),[b,E,p]=t.categoryChain,{mutateAsync:f,isPending:T}=Le(),{showNotification:h}=le(),y=E?.key,g=p?.key,$=!d&&y===9,_=d||g!==2,A=d||g!==2;o.useEffect(()=>{function C(L){v&&S.current&&!S.current.contains(L.target)&&!k.current?.contains(L.target)&&r(null)}return document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[v,r]),o.useEffect(()=>{function C(L){L.key==="Escape"&&r(null)}return v&&document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[v,r]),o.useEffect(()=>{if(!v||!S.current)return;const C=Array.from(S.current.querySelectorAll('[role="menuitem"]'));if(!C.length)return;let L=0;C[0].focus();function D(w){w.key==="ArrowDown"&&(L=(L+1)%C.length,C[L].focus(),w.preventDefault()),w.key==="ArrowUp"&&(L=(L-1+C.length)%C.length,C[L].focus(),w.preventDefault())}return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[v]);const M=async()=>{try{await f({categoryId:g?.toString()??"",templateId:t.id??""}),c(),h(`Template "${t?.name}" marked as favourite`,"success")}catch(C){console.error(C),h("Unable to mark template as favourite. Please try again.","error")}};return e.jsx(e.Fragment,{children:e.jsxs("tr",{className:"ts-table-row",children:[e.jsxs("td",{children:[" ",e.jsxs("div",{className:"ts-name-cell",children:[$&&e.jsx("button",{type:"button",className:"ts-fav-btn ts-btn-light",disabled:t.is_favourite,onClick:M,title:"Mark as favourite",children:T?e.jsx(ee,{size:"sm"}):t.is_favourite?e.jsx(he,{variant:"filled"}):e.jsx(he,{variant:"outlined"})}),e.jsx("span",{className:t.readonly?"ts-badge default":"ts-badge custom",children:t.readonly?"Default":"Custom"})]})]}),e.jsx("td",{children:e.jsx("div",{className:"",children:e.jsx("span",{className:"ts-template-name",children:t.name})})}),d&&e.jsx("td",{children:t?.id??""}),e.jsx("td",{children:b?.name??""}),e.jsx("td",{children:E?.name??""}),e.jsx("td",{children:p?.name??""}),d&&e.jsx("td",{children:t?.companyName??""}),e.jsx("td",{children:t?.updatedByName??""}),e.jsx("td",{children:Ge(t.updatedDateTime)}),e.jsx("td",{className:"ts-actions-cell",children:e.jsxs("div",{className:"ts-actions-wrapper",children:[e.jsx("button",{ref:k,className:"ts-actions-btn","aria-haspopup":"true","aria-expanded":v,onClick:()=>r(v?null:t.id),children:e.jsx(We,{})}),e.jsxs("div",{ref:S,className:`ts-actions-menu ${v?"open":""}`,role:"menu",children:[e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item",onClick:()=>{r(null),i(t)},children:"Preview"}),_&&e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item",onClick:()=>{r(null),a(t)},children:"Edit"}),e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item",onClick:()=>{r(null),l(t)},children:"Duplicate"}),A&&e.jsx("button",{type:"button",role:"menuitem",className:"ts-menu-item danger",onClick:()=>{r(null),s(t)},children:"Remove"})]})]})})]})})}const Xe=o.memo(Ye),Je=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"6.01px",height:"9.63px",...t,children:e.jsx("path",{fill:t.fill||"#6c757d",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"})}),Ze=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 320 512",width:"6.01px",height:"9.63px",...t,children:e.jsx("path",{fill:t.fill||"#6c757d",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"})}),J=({label:t,sortKey:n,sortBy:r,sortOrder:a,onSort:l})=>e.jsx("th",{onClick:()=>l(n),className:"ts-sortable",children:e.jsxs("div",{className:"ts-th-sort",children:[t,e.jsxs("div",{className:"ts-sort-icons",children:[e.jsx(Je,{fill:r===n&&a==="asc"?"#007bff":"#6c757d",className:r===n&&a==="asc"?"active":""}),e.jsx(Ze,{style:{marginTop:-9.6},fill:r===n&&a==="desc"?"#007bff":"#6c757d",className:r===n&&a==="desc"?"active":""})]})]})}),ve=5,Qe=({page:t,pageSize:n,totalRecords:r,onPageChange:a,onPageSizeChange:l})=>{const s=Math.ceil(r/n),c=s<=ve?Array.from({length:s},(p,f)=>f+1):Array.from({length:ve},(p,f)=>f+1),d=s>ve,v=s,{showNotification:S}=le(),[k,b]=o.useState(String(t));o.useEffect(()=>{b(String(t))},[t]);const E=()=>{const p=Number(k);if(!p||p<1||p>s){S("Page out of range","error"),b(String(t));return}a(p)};return e.jsxs("div",{className:"ts-pagination-bar",children:[e.jsxs("div",{className:"ts-page-container",children:[e.jsxs("div",{className:"ts-page-size",children:[e.jsx("label",{children:"Display:"}),e.jsx("select",{value:n,onChange:p=>{l(Number(p.target.value)),a(1)},children:[10,25,50,100].map(p=>e.jsx("option",{value:p,children:p},p))})]}),e.jsxs("div",{className:"ts-page-info",children:["Page ",e.jsxs("span",{children:[t," of ",s]})]}),e.jsxs("div",{className:"ts-go-to",children:[e.jsx("span",{children:"Go to page:"}),e.jsx("input",{type:"number",value:k,onChange:p=>b(p.target.value),onBlur:E,onKeyDown:p=>{p.key==="Enter"&&E()}})]})]}),e.jsxs("div",{className:"ts-total",children:[e.jsx("span",{children:"Total:"})," ",r]}),e.jsxs("div",{className:"ts-page-buttons",children:[e.jsx("button",{disabled:t===1,onClick:()=>a(t-1),children:"‹"}),c.map(p=>e.jsx("button",{className:p===t?"active":"",onClick:()=>a(p),children:p},p)),d&&e.jsx("span",{style:{padding:"0 6px"},children:"…"}),d&&e.jsx("button",{className:t===v?"active":"",onClick:()=>a(v),children:v}),e.jsx("button",{disabled:t===s,onClick:()=>a(t+1),children:"›"})]})]})},Re=({show:t,variant:n,title:r="Are you sure?",message:a,label:l="Name",value:s="",placeholder:i="",requiredMessage:c="This field is required",externalError:d=!1,externalErrorMessage:v="",confirmText:S="Ok",cancelText:k="Cancel",confirmButtonVariant:b="danger",disableConfirm:E=!1,onConfirm:p,onCancel:f,onInputChange:T})=>{const[h,y]=o.useState(s),[g,$]=o.useState(!1),_=o.useRef(null);if(o.useEffect(()=>{if(!t)return;const D=w=>{w.key==="Escape"&&f()};return document.addEventListener("keydown",D),()=>document.removeEventListener("keydown",D)},[t,f]),o.useEffect(()=>{if(!t)return;const D=w=>{_.current&&!_.current.contains(w.target)&&f()};return document.addEventListener("mousedown",D),()=>document.removeEventListener("mousedown",D)},[t,f]),o.useEffect(()=>{if(t)return document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}},[t]),o.useEffect(()=>{t&&(y(s),$(!1))},[t,s]),o.useEffect(()=>{d&&$(!0)},[d]),!t)return null;const A=n==="input"&&!h.trim(),M=n==="input"&&(A||d),C=A?c:d?v:"",L=()=>{if(M||E){$(!0);return}p(h.trim())};return e.jsx("div",{className:"ts-modal-overlay",children:e.jsxs("div",{ref:_,className:"ts-modal",children:[e.jsxs("div",{className:"ts-modal-header",children:[e.jsx("h4",{className:"ts-modal-title ",children:r}),e.jsx("button",{className:"ts-modal-close",onClick:f,children:"✕"})]}),e.jsxs("div",{className:"ts-modal-body",children:[a&&e.jsx("p",{className:"ts-modal-message",children:a}),n==="input"&&e.jsxs("div",{className:"ts-form-group",children:[e.jsxs("label",{className:"ts-label",children:[l,e.jsx("span",{className:"ts-required",children:"*"})]}),e.jsx("input",{type:"text",className:`ts-input ${g&&M?"ts-input-error":""}`,placeholder:i,value:h,onChange:D=>{y(D.target.value),g&&$(!1),T?.(D.target.value)},autoFocus:!0,style:{paddingBlock:"0",paddingInline:"0"}}),g&&M&&e.jsx("div",{className:"ts-error-text",children:C})]})]}),e.jsxs("div",{className:"ts-modal-footer",children:[e.jsx("button",{type:"button",className:"ts-btn ts-btn-secondary",onClick:f,children:k}),e.jsx("button",{type:"button",className:`ts-btn ts-btn-${b}`,onClick:L,disabled:E,children:S})]})]})})},et=()=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",width:"11px",height:"11px",children:e.jsx("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"})}),tt=()=>{const t=W(),{enerexIdentifier:n,projectId:r,userEmail:a}=U();return K.useMutation({mutationKey:["duplicateTemplate"],mutationFn:async({templateId:s,request:i})=>(i.enerexIdentifier=n??"",i.projectId=r??"",i.updatedBy=a??"",await t.post(`${Y.duplicateTemplate}${s}`,i))})},nt=()=>{const t=W();return K.useMutation({mutationKey:["deleteTemplate"],mutationFn:async n=>{await t.delete(`${Y.deleteTemplate}${n}`)}})},rt=({data:t,page:n,pageSize:r})=>{const a=o.useMemo(()=>Math.ceil(t.length/r),[t.length,r]);return{pagedData:o.useMemo(()=>{const s=(n-1)*r,i=n*r;return t.slice(s,i)},[t,n,r]),totalPages:a}},st=({templates:t,templateTypes:n,onRefresh:r,onAdd:a,onEdit:l,onPreview:s})=>{const{isAdmin:i}=U(),{mutateAsync:c,isPending:d}=tt(),{mutateAsync:v,isPending:S}=nt(),[k,b]=o.useState(""),[E,p]=o.useState(""),[f,T]=o.useState(null),[h,y]=o.useState(t),[g,$]=o.useState(n),[_,A]=o.useState(!1),[M,C]=o.useState("input"),[L,D]=o.useState(!1),[w,te]=o.useState(null),[V,X]=o.useState("asc"),H=u=>{w===u?X(N=>N==="asc"?"desc":"asc"):(te(u),X("asc")),R(1)},[q,ne]=o.useState(null);o.useEffect(()=>{const u=[...t].sort((N,P)=>{if(!i&&N.is_favourite!==P.is_favourite)return Number(P.is_favourite)-Number(N.is_favourite);const I=new Date(P.updatedDateTime).getTime()-new Date(N.updatedDateTime).getTime();return I!==0?I:N.readonly!==P.readonly?Number(N.readonly)-Number(P.readonly):N.name.localeCompare(P.name)});y(u),te(null)},[t]),o.useEffect(()=>{$(n.filter(u=>u.id!=null))},[n]);const se=o.useMemo(()=>{const u=new Map;return g.forEach(N=>u.set(N.id,N)),u},[g]),de=o.useCallback(u=>{const N=[],P=new Set;let I=se.get(u);for(;I&&!(P.has(I.id)||(P.add(I.id),N.push({id:I.id,name:I.name,key:I.key}),!I.parent_id));)I=se.get(I.parent_id);return N.reverse()},[se]),Q=o.useMemo(()=>!h.length||!g.length?[]:h.map(u=>({...u,categoryChain:de(u.type)})),[h,g]);o.useEffect(()=>{const u=setTimeout(()=>{p(k),R(1)},300);return()=>clearTimeout(u)},[k]);const[re,z]=o.useState(25),[pe,R]=o.useState(1),ue=o.useMemo(()=>{const u=E.trim().toLowerCase();return u?Q.filter(N=>{const P=N.name.toLowerCase().includes(u),I=N.categoryChain?.some(G=>G.name.toLowerCase().includes(u));return P||I}):Q},[Q,E]),fe=o.useMemo(()=>{const u=[...ue];return u.sort((N,P)=>{if(w==="lastUpdatedOn"){const Tt=new Date(N.updatedDateTime).getTime(),Nt=new Date(P.updatedDateTime).getTime(),$e=Tt-Nt;return V==="asc"?$e:-$e}let I="",G="";switch(w){case"name":I=N.name,G=P.name;break;case"category":I=N.categoryChain?.[0]?.name??"",G=P.categoryChain?.[0]?.name??"";break;case"type":I=N.categoryChain?.[1]?.name??"",G=P.categoryChain?.[1]?.name??"";break;case"subtype":I=N.categoryChain?.[2]?.name??"",G=P.categoryChain?.[2]?.name??"";break;case"templateId":I=N.id??"",G=P.id??"";break;case"companyName":I=N.companyName??"",G=P.companyName??"";break;case"lastUpdatedBy":I=N.updatedByName??"",G=P.updatedByName??"";break}const Ae=I.localeCompare(G,void 0,{sensitivity:"base"});return V==="asc"?Ae:-Ae}),u},[ue,w,V]),{pagedData:Te}=rt({data:fe,page:pe,pageSize:re}),m=o.useCallback(u=>h.some(N=>N.name.trim().toLowerCase()===u.trim().toLowerCase()),[h]),x=u=>{ne(u),D(!1),C("input"),A(!0)},B=u=>{ne(u),C("confirm"),A(!0)},{showNotification:F}=le(),Z=async u=>{if(q)try{if(M==="input"){if(!u)return;if(m(u)){D(!0);return}await c({templateId:q.id,request:{projectId:"",enerexIdentifier:"",newName:u,parent_id:q.id??null}}),F(`Template "${u}" duplicated successfully`,"success")}M==="confirm"&&(await v(q.id),F(`Template "${q.name}" deleted successfully`,"success")),A(!1),ne(null),r()}catch{F(M==="confirm"?"Failed to delete template. Please try again.":"Failed to duplicate template. Please try again.","error")}},O=q?.categoryChain?.[2]?.name?.toLowerCase()??"this",ae=q?.name?.toLowerCase()??"",Ne=d||S;return e.jsxs(e.Fragment,{children:[Ne&&e.jsx(ee,{overlay:!0}),e.jsxs("div",{className:"ts-page",children:[e.jsxs("div",{className:"ts-header",children:[e.jsx("h1",{className:"ts-title",children:"Templates"}),e.jsx("button",{className:"ts-btn ts-btn-primary",onClick:a,children:"+ Add Template"})]}),e.jsx("div",{className:"ts-search-container",children:e.jsxs("div",{className:"ts-search-container-inner",children:[e.jsx("div",{className:"ts-search",children:e.jsxs("div",{className:"ts-search-box",children:[e.jsx("input",{type:"text",placeholder:"Search...",value:k,onChange:u=>b(u.target.value)}),e.jsx("button",{className:"ts-search-btn","aria-label":"Search",children:e.jsx(et,{})})]})}),e.jsxs("div",{className:"ts-table-wrapper",children:[e.jsxs("table",{className:"ts-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{className:"ts-cursor-default"}),e.jsx(J,{label:"Name",sortKey:"name",sortBy:w,sortOrder:V,onSort:H}),i&&e.jsx(J,{label:"Template Id",sortKey:"templateId",sortBy:w,sortOrder:V,onSort:H}),e.jsx(J,{label:"Category",sortKey:"category",sortBy:w,sortOrder:V,onSort:H}),e.jsx(J,{label:"Type",sortKey:"type",sortBy:w,sortOrder:V,onSort:H}),e.jsx(J,{label:"Subtype",sortKey:"subtype",sortBy:w,sortOrder:V,onSort:H}),i&&e.jsx(J,{label:"Company Name",sortKey:"companyName",sortBy:w,sortOrder:V,onSort:H}),e.jsx(J,{label:"Last Updated by",sortKey:"lastUpdatedBy",sortBy:w,sortOrder:V,onSort:H}),e.jsx(J,{label:"Last Updated on",sortKey:"lastUpdatedOn",sortBy:w,sortOrder:V,onSort:H}),e.jsx("th",{className:"ts-cursor-default",children:"Actions"})]})}),e.jsx("tbody",{children:Te.map(u=>e.jsx(Xe,{template:u,openActionId:f,setOpenActionId:T,onDuplicate:x,onEdit:l,onRemove:B,onPreview:s,onRefresh:r},u.id))})]}),e.jsx(Qe,{page:pe,pageSize:re,totalRecords:fe.length,onPageChange:R,onPageSizeChange:z})]})]})})]}),e.jsx(Re,{show:_,variant:M,title:M==="confirm"?"Are you sure?":"Save Template As",message:M==="confirm"?`Are you sure you want to remove ${O} template "${ae}"?`:"",placeholder:M==="input"?"New name":"",label:"New Name",requiredMessage:"Enter a new name",externalError:L,externalErrorMessage:"Template name already exists. Please choose a different name",confirmText:M==="confirm"?"Ok":"Save as",confirmButtonVariant:M==="confirm"?"danger":"primary",onConfirm:Z,onCancel:()=>A(!1),onInputChange:M==="input"?()=>D(!1):void 0})]})},ie=`<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
12
12
  <html\r
13
13
  dir="ltr"\r
14
14
  xmlns:o="urn:schemas-microsoft-com:office:office"\r
@@ -364,8 +364,8 @@
364
364
  </div>\r
365
365
  </body>\r
366
366
  </html>\r
367
- `,be={EDITOR_SCRIPT_URL:"https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",EDITOR_PLUGIN_ID:"1afdc3161ec7409a8627a1c8561d45f5",EDITOR_SECRET_KEY:"54ba748ed7e94f2e929555783acb03da"},at=t=>{const n=Array.from(new Set(t.map(a=>a.category))),r=[];return n.forEach(a=>{const l=t.filter(s=>s.category===a).map(s=>({label:s.label,value:s.value,hint:s.hint,hidden:s.hidden}));r.push({category:a,entries:l})}),r},ot=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getTemplateTags"],queryFn:async l=>await t.get(`${Y.MergeTags}${r}/${n}`)})},lt=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getExcludeCategory"],queryFn:async l=>await t.get(`${Y.ExcludeCategory}${r}/${n}`)})},it=({templateHTML:t,className:n="",loading:r=!1,onEditorInitialized:a})=>{const{post:l}=xe(),{data:s}=ot(),{data:i}=lt(),[c,d]=o.useState(t??{html:ie,css:""}),{userEmail:v}=U(),S=o.useRef(null),k="https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png",b="https://plugins.stripo.email/api/v1/auth";o.useEffect(()=>{(async()=>(await E(),s&&i&&await p(be.EDITOR_SCRIPT_URL)))()},[s,i]);async function E(){window.Zone||await new Promise((w,h)=>{const y=document.createElement("script");y.src="https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";const g=document.querySelector("script[nonce]")?.nonce;g&&y.setAttribute("nonce",g),y.onload=()=>w(),y.onerror=()=>h(new Error("Failed to load zone.js")),document.head.appendChild(y)})}async function p(w){let h=document.getElementById("UiEditorScript");h||(h=document.createElement("script"),h.id="UiEditorScript",h.src=w,h.onload=async()=>{await f()},document.body.appendChild(h)),await new Promise(y=>h.addEventListener("load",()=>y(),{once:!0}))}const f=async()=>{const w=S.current;if(!w){console.error("Missing #stripoEditorContainer in DOM");return}if(!window.UIEditor||typeof window.UIEditor.initEditor!="function"){console.error("UIEditor script not loaded or not exposing initEditor");return}const h={html:c.html,css:c.css,modulesExcludedCategories:i??[],forceRecreate:!0,metadata:{emailId:v,userId:"1",avatarUrl:k},locale:"en",onTokenRefreshRequest:async y=>{const g={pluginId:be.EDITOR_PLUGIN_ID,secretKey:be.EDITOR_SECRET_KEY,userId:v,role:"user"},$=await l(b,g);$?.token&&y($.token)},onTemplateLoaded:()=>{a&&a(!0)},mergeTags:at(s??[])};for(const[y,g]of Object.entries({codeEditorButtonSelector:"#codeEditor",undoButtonSelector:"#undoButton",redoButtonSelector:"#redoButton",mobileViewButtonSelector:"#mobileViewButton",desktopViewButtonSelector:"#desktopViewButton"}))w.ownerDocument&&w.getRootNode()instanceof ShadowRoot&&w.getRootNode().querySelector(g)&&(h[y]=g);await window.UIEditor.initEditor(w,h)};return e.jsx("div",{className:"position-relative",children:e.jsxs("div",{className:`editor-container ${n}`,children:[r&&e.jsx("div",{className:"loading-overlay",children:e.jsx(_e.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:e.jsx("span",{className:"visually-hidden",children:"Loading..."})})}),e.jsx("div",{id:"externalSystemContainer"}),e.jsx("div",{id:"stripoEditorContainer",ref:S})]})})},Ie=({label:t,register:n,validation:r,required:a=!1,name:l,error:s,className:i="",...c})=>{const d=!!(s&&s[l]);return e.jsxs("div",{className:`ts-form-group ${i}`,children:[t&&e.jsxs("label",{className:"ts-form-label",children:[t,a&&e.jsx("span",{className:"ts-required",children:"*"})]}),e.jsx("input",{name:l,type:"text",...c,...n?n(l,{...r}):{},className:`ts-input ${d?"ts-input-error":""}`,"aria-invalid":d}),d&&e.jsx("div",{className:"ts-error-text",children:s?.[l]?.message})]})};function ct(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var we={exports:{}};/*!
367
+ `,be={EDITOR_SCRIPT_URL:"https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",EDITOR_PLUGIN_ID:"1afdc3161ec7409a8627a1c8561d45f5",EDITOR_SECRET_KEY:"54ba748ed7e94f2e929555783acb03da"},at=t=>{const n=Array.from(new Set(t.map(a=>a.category))),r=[];return n.forEach(a=>{const l=t.filter(s=>s.category===a).map(s=>({label:s.label,value:s.value,hint:s.hint,hidden:s.hidden}));r.push({category:a,entries:l})}),r},ot=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getTemplateTags"],queryFn:async l=>await t.get(`${Y.MergeTags}${r}/${n}`)})},lt=()=>{const t=W(),{enerexIdentifier:n,projectId:r}=U();return K.useQuery({queryKey:["getExcludeCategory"],queryFn:async l=>await t.get(`${Y.ExcludeCategory}${r}/${n}`)})},it=({templateHTML:t,className:n="",loading:r=!1,onEditorInitialized:a})=>{const{post:l}=xe(),{data:s}=ot(),{data:i}=lt(),[c,d]=o.useState(t??{html:ie,css:""}),{userEmail:v}=U(),S=o.useRef(null),k="https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png",b="https://plugins.stripo.email/api/v1/auth";o.useEffect(()=>{(async()=>(await E(),s&&i&&await p(be.EDITOR_SCRIPT_URL)))()},[s,i]);async function E(){window.Zone||await new Promise((T,h)=>{const y=document.createElement("script");y.src="https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";const g=document.querySelector("script[nonce]")?.nonce;g&&y.setAttribute("nonce",g),y.onload=()=>T(),y.onerror=()=>h(new Error("Failed to load zone.js")),document.head.appendChild(y)})}async function p(T){let h=document.getElementById("UiEditorScript");h||(h=document.createElement("script"),h.id="UiEditorScript",h.src=T,h.onload=async()=>{await f()},document.body.appendChild(h)),await new Promise(y=>h.addEventListener("load",()=>y(),{once:!0}))}const f=async()=>{const T=S.current;if(!T){console.error("Missing #stripoEditorContainer in DOM");return}if(!window.UIEditor||typeof window.UIEditor.initEditor!="function"){console.error("UIEditor script not loaded or not exposing initEditor");return}const h={html:c.html,css:c.css,modulesExcludedCategories:i??[],forceRecreate:!0,metadata:{emailId:v,userId:"1",avatarUrl:k},locale:"en",onTokenRefreshRequest:async y=>{const g={pluginId:be.EDITOR_PLUGIN_ID,secretKey:be.EDITOR_SECRET_KEY,userId:v,role:"user"},$=await l(b,g);$?.token&&y($.token)},onTemplateLoaded:()=>{a&&a(!0)},mergeTags:at(s??[])};for(const[y,g]of Object.entries({codeEditorButtonSelector:"#codeEditor",undoButtonSelector:"#undoButton",redoButtonSelector:"#redoButton",mobileViewButtonSelector:"#mobileViewButton",desktopViewButtonSelector:"#desktopViewButton"}))T.ownerDocument&&T.getRootNode()instanceof ShadowRoot&&T.getRootNode().querySelector(g)&&(h[y]=g);await window.UIEditor.initEditor(T,h)};return e.jsx("div",{className:"position-relative",children:e.jsxs("div",{className:`editor-container ${n}`,children:[r&&e.jsx("div",{className:"loading-overlay",children:e.jsx(_e.Spinner,{animation:"border",style:{width:"11px",height:"11px"},size:"sm",role:"status",className:"me-1",children:e.jsx("span",{className:"visually-hidden",children:"Loading..."})})}),e.jsx("div",{id:"externalSystemContainer"}),e.jsx("div",{id:"stripoEditorContainer",ref:S})]})})},Ie=({label:t,register:n,validation:r,required:a=!1,name:l,error:s,className:i="",...c})=>{const d=!!(s&&s[l]);return e.jsxs("div",{className:`ts-form-group ${i}`,children:[t&&e.jsxs("label",{className:"ts-form-label",children:[t,a&&e.jsx("span",{className:"ts-required",children:"*"})]}),e.jsx("input",{name:l,type:"text",...c,...n?n(l,{...r}):{},className:`ts-input ${d?"ts-input-error":""}`,"aria-invalid":d}),d&&e.jsx("div",{className:"ts-error-text",children:s?.[l]?.message})]})};function ct(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var we={exports:{}};/*!
368
368
  Copyright (c) 2018 Jed Watson.
369
369
  Licensed under the MIT License (MIT), see
370
370
  http://jedwatson.github.io/classnames
371
- */var Me;function dt(){return Me||(Me=1,function(t){(function(){var n={}.hasOwnProperty;function r(){for(var s="",i=0;i<arguments.length;i++){var c=arguments[i];c&&(s=l(s,a(c)))}return s}function a(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return r.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var i="";for(var c in s)n.call(s,c)&&s[c]&&(i=l(i,c));return i}function l(s,i){return i?s?s+" "+i:s+i:s}t.exports?(r.default=r,t.exports=r):window.classNames=r})()}(we)),we.exports}var pt=dt();const Pe=ct(pt),De=t=>t.data.isSeparator?e.jsx("div",{style:{padding:0,margin:"2px 0"},children:e.jsx("hr",{style:{border:0,borderTop:"1px solid #bdbdbdff",padding:0,margin:0}})}):t.data.icon?e.jsxs("div",{className:"d-flex align-items-center",children:[e.jsx(oe.components.Option,{...t}),e.jsx("span",{className:"px-1 template-studio-dropdown-postfix-icon",children:t.data.icon})]}):e.jsx(oe.components.Option,{...t}),ut=({name:t="",control:n,options:r,multiple:a=!1,placeholder:l,validation:s,labelKey:i="name",disabled:c,isInvalid:d,value:v,onChange:S,uncontrolled:k,menuPlacement:b="auto",closeOnSelect:E=!0})=>{const p={control:f=>({...f,minHeight:"33px",borderColor:d?"var(--bs-form-invalid-border-color) !important":"var(--ct-input-border-color)",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",backgroundRepeat:"no-repeat",backgroundPosition:"right calc(0.375em + 0.225rem) center",backgroundSize:"calc(0.75em + 0.45rem) calc(0.75em + 0.45rem)","&:hover":{borderColor:d?"var(--bs-form-invalid-border-color)":"var(--ct-input-border-color)"},"& .react-select__single-value":{color:"var(--ct-input-color) !important"},"& .react-select__placeholder":{color:"var(--ct-input-placeholder-color) !important"},"& .react-select__indicators":{display:"none"}}),menu:f=>({...f,marginTop:0,width:"max-content",minWidth:"100%"}),menuPortal:f=>({...f,zIndex:1e4}),multiValueRemove:f=>({...f,display:c?"none":"block"})};return k?e.jsx(oe,{components:{Option:De},isOptionDisabled:f=>!!f.isSeparator,className:Pe({"is-invalid":d}),styles:p,classNamePrefix:"react-select",isMulti:a,options:r,onChange:S,placeholder:l,menuPortalTarget:document.body,value:v,getOptionLabel:typeof i=="string"?f=>f[i]:i,getOptionValue:f=>f.id,isDisabled:c,menuPlacement:b,closeMenuOnSelect:E}):e.jsx(Ee.Controller,{control:n,name:t,rules:s,render:({field:{onChange:f,value:w,onBlur:h}})=>e.jsx(oe,{components:{Option:De},isOptionDisabled:y=>!!y.isSeparator,className:Pe({"is-invalid":d}),styles:p,classNamePrefix:"react-select",isMulti:a,options:r,onBlur:h,onChange:f,placeholder:l,menuPortalTarget:document.body,value:w,getOptionLabel:typeof i=="string"?y=>y[i]:i,getOptionValue:y=>y.id,isDisabled:c,menuPlacement:b,closeMenuOnSelect:E},w?w.id||w.value||JSON.stringify(w):"reset")})},ce=({label:t,name:n,validation:r,control:a,error:l,options:s=[],required:i=!1,disabled:c=!1,className:d=""})=>{const v=!!(l&&l[n]);return e.jsxs("div",{className:`ts-form-group ${d}`,children:[t&&e.jsxs("label",{className:"ts-form-label",children:[t,i&&e.jsx("span",{className:"ts-required",children:"*"})]}),e.jsx(ut,{name:n,control:a,options:s,validation:r,disabled:c,isInvalid:v}),v&&e.jsx("div",{className:"ts-error-text",children:l?.[n]?.message})]})},ft=()=>{const t=W();K.useQueryClient();const{enerexIdentifier:n,projectId:r}=U();return K.useMutation({mutationKey:["saveTemplate"],mutationFn:async l=>(l.enerexIdentifier=n??"",l.projectId=r??"",await t.post(`${Y.SaveTemplate}`,l))})},mt={id:"",name:"New (Blank)"},ht=({onReset:t,editorInitialized:n,mode:r,templateTypes:a,templateList:l,template:s,onRefresh:i,closeEditorModal:c})=>{const{defaultSelector:d,isAdmin:v,userEmail:S}=U(),{mutateAsync:k,isPending:b}=Le(),{register:E,handleSubmit:p,clearErrors:f,setValue:w,control:h,watch:y,reset:g,setError:$,formState:{errors:_}}=Ee.useForm({defaultValues:{templateName:"",subTemplateType:void 0,subTemplateType2:void 0,subject:"",templateType:void 0,template:mt},mode:"onChange"}),[A,M]=o.useState([]),[C,L]=o.useState(),{mutateAsync:D,isPending:T}=ft(),[te,V]=o.useState([]),[X,H]=o.useState([]),[q,ne]=o.useState([]),[se,de]=o.useState(!1),Q=o.useRef(!1),{showNotification:re}=le(),z=r==="edit",pe=se||T||b||!n;o.useEffect(()=>{if(a){let m=a.filter(B=>B.id!=null),x=ge(m,0);V(ye(x))}},[a]),o.useEffect(()=>{r==="edit"&&!Q.current&&de(!0)},[r]),o.useEffect(()=>{if(r!=="edit"||!s||!n||!a.length||!A.length||Q.current)return;const m=A.find(O=>O.id===s.templateID);if(!m)return;const x=a.filter(O=>O.id!=null),B=x.find(O=>`${O.id}`==`${m.type}`),F=B?x.find(O=>`${O.id}`==`${B.parent_id}`):void 0,Z=F?x.find(O=>`${O.id}`==`${F.parent_id}`):void 0;g({templateType:Z?R(Z):void 0,subTemplateType:F?R(F):void 0,subTemplateType2:B?R(B):void 0,template:m,templateName:s.name??"",subject:s.subject??""}),L(m),Q.current=!0,de(!1)},[r,s,n,a,A,g]);const R=m=>({id:String(m.id),name:m.name,key:m.key});o.useEffect(()=>{l?.sort((m,x)=>m.readonly!==x.readonly?(m.readonly?0:1)-(x.readonly?0:1):m.name.localeCompare(x.name)),M(l??[])},[l]),o.useEffect(()=>{if(!y("templateType"))return;const m=ge(a,1);H(ye(m.filter(x=>`${x.parent_id}`==`${y("templateType")?.id}`))),w("subTemplateType",void 0),w("subTemplateType2",void 0)},[y("templateType"),a]),o.useEffect(()=>{const m=y("subTemplateType");if(!m)return;const x=ge(a,2);let B=ye(x.filter(F=>`${F.parent_id}`==`${m.id}`));r!=="edit"&&!v&&(B=B.filter(F=>F.key!==2)),ne(B),w("subTemplateType2",void 0)},[y("subTemplateType"),a,r]),o.useEffect(()=>{if(d&&d.type1){const m=te?.find(x=>`${x.id}`===d.type1);w("templateType",m)}},[a,te]),o.useEffect(()=>{if(d&&d.type2){const m=X?.find(x=>`${x.id}`===d.type2);w("subTemplateType",m)}},[a,X]),o.useEffect(()=>{if(d&&d.type3){const m=q?.find(x=>`${x.id}`===d.type3);w("subTemplateType2",m)}},[a,q]);const ue=m=>{window.StripoEditorApi.actionsApi.getTemplateData(async x=>{try{let B=m.template.id,F="";const Z=m.templateName.trim(),O=A.find(N=>N.name===m.templateName.trim());if(O&&O?.id!==m.template.id){$("templateName",{type:"validate",message:"Template name already exists. Please choose a different name."});return}let ae=m.templateType.id;q?.length>0?ae=m.subTemplateType2.id:X?.length>0&&(ae=m.subTemplateType.id);const Ne={enerexIdentifier:"",projectId:"",templateId:B,templateType:ae,name:Z,html:x.html,css:x.css,subject:m.templateType.id==="2"?m?.subject??"":"",parent_id:F,updatedBy:S??""};if(!await D(Ne)){re("Failed to save template. Please try again.","error");return}re(z?`Template "${Z}" updated successfully.`:`Template "${Z}" created successfully.`,"success"),f(),i(),c()}catch(B){console.error(B),re("Something went wrong while saving the template.","error")}})},fe=y("templateType"),Te=y("subTemplateType");return e.jsxs(e.Fragment,{children:[pe&&e.jsx(ee,{overlay:!0}),e.jsx("div",{className:"ts-card",children:e.jsx("div",{className:"ts-card-body",children:e.jsx("form",{children:e.jsx("div",{className:"template-list-container",children:e.jsxs("div",{className:"ts-row",children:[e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Category",control:h,error:_,options:te,required:!0,disabled:z||T||b||!n,validation:{required:{value:!0,message:"Select a category"}},...E("templateType")})}),X&&X.length>0&&e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Type",control:h,error:_,options:X,required:!0,disabled:z||T||b||!n,validation:{required:{value:!0,message:"Select a type"}},...E("subTemplateType")})}),q&&q.length>0&&e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Sub Type",control:h,error:_,options:q,required:!0,disabled:z||T||b||!n,validation:{required:{value:!0,message:"Select a subtype"}},...E("subTemplateType2")})}),e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Template",control:h,error:_,disabled:z||!z||T||b||!n,options:[],required:!1,...E("template")})}),e.jsxs("div",{className:"ts-col ts-template-name-col",children:[e.jsx(Ie,{label:"Name",register:E,error:_,required:!0,name:"templateName",validation:{required:{value:!0,message:"Enter a name"}}}),Te?.key?.toString()==="9"&&z&&!v&&C?.is_favourite&&e.jsx("span",{className:"ts-favourite-icon",children:e.jsx(he,{variant:"filled"})})]}),fe?.key?.toString()==="12"&&e.jsx("div",{className:"ts-col",children:e.jsx(Ie,{label:"Subject",register:E,error:_,required:!1,name:"subject"})}),e.jsxs("div",{className:"ts-col ts-actions btn-padding",children:[!z&&e.jsx("button",{type:"button",className:"ts-btn ts-btn-primary",disabled:T||b||!n,onClick:()=>{L(void 0),g(),H([]),ne([]),t()},children:T||b?e.jsx(ee,{size:"sm"}):"Clear"}),e.jsx("button",{type:"button",className:"ts-btn ts-btn-primary",disabled:T||b||!n,onClick:p(ue),children:T||b?e.jsx(ee,{size:"sm"}):"Save"})]})]})})})})})]})},yt=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",width:"20px",viewBox:"0 0 640 640",...t,children:e.jsx("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"})}),gt=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",width:"20px",viewBox:"0 0 640 640",...t,children:e.jsx("path",{fill:"#6c757d",d:"M112 288L112 464L528 464L528 288L112 288zM64 128L576 128L576 512L64 512L64 128z"})}),vt=({show:t,mode:n,template:r,templateTypes:a,templateList:l,editorInitialized:s,previewHtml:i,onEditorInitialized:c,onClose:d,onRefresh:v})=>{const S=o.useRef(null),[k,b]=o.useState(!1);o.useEffect(()=>{t&&s&&window.StripoEditorApi?.actionsApi&&(n==="add"?window.StripoEditorApi.actionsApi.updateHtmlAndCss(ie,"",""):n==="edit"&&r&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(r.html??ie,r.css??"",""))},[t,s,n,r]),o.useEffect(()=>{t||b(!1)},[t]);const E=()=>{window.StripoEditorApi.actionsApi.updateHtmlAndCss(ie,"","")};return t?e.jsx("div",{className:"ts-editor-modal-overlay",children:e.jsxs("div",{className:`ts-editor-modal ${k?"ts-editor-modal--fullscreen":""}`,ref:S,children:[e.jsxs("div",{className:"ts-editor-modal-header",children:[e.jsxs("h3",{className:"ts-modal-title",children:[n==="add"&&"Create Template",n==="edit"&&"Edit Template",n==="preview"&&"Preview Template"]}),e.jsxs("div",{className:"ts-editor-header-actions",children:[e.jsx("button",{className:"ts-editor-fullscreen-btn",onClick:()=>b(p=>!p),"aria-label":"Toggle fullscreen",children:k?e.jsx(yt,{style:{display:"block"}}):e.jsx(gt,{style:{display:"block"}})}),e.jsx("button",{className:"ts-editor-close-btn",onClick:d,"aria-label":"Close editor",children:"✕"})]})]}),e.jsxs("div",{className:"ts-editor-modal-body",children:[n!=="preview"&&e.jsx(ht,{mode:n,template:r,templateTypes:a,templateList:l,editorInitialized:s,onReset:E,onRefresh:v,closeEditorModal:d}),n==="preview"?e.jsx("div",{className:"ts-template-preview",children:e.jsx("iframe",{title:"Template Preview",className:"ts-template-preview-frame",srcDoc:i??""})}):e.jsx(it,{onEditorInitialized:c,loading:!1,className:"editor-container"})]})]})}):null},bt=()=>{const{data:t,isLoading:n,isFetching:r,refetch:a}=Ve(),{data:l,isLoading:s,isFetching:i}=Ke(),{mutateAsync:c,isPending:d}=He(),[v,S]=o.useState(!1),[k,b]=o.useState("add"),[E,p]=o.useState(!1),[f,w]=o.useState(""),[h,y]=o.useState(),g=()=>{b("add"),S(!0)},$=async C=>{const L=await c({id:C.id});y({...L}),b("edit"),S(!0)},_=C=>{if(!t||t.length===0)return;const L=t.find(D=>D.id===C.id);w(L?.html+"<style>"+L?.css+"</style>"),b("preview"),S(!0)},A=()=>{S(!1),p(!1),document.getElementById("UiEditorScript")?.remove()},M=n||s||r||i||d;return e.jsxs(e.Fragment,{children:[M&&e.jsx(ee,{overlay:!0}),e.jsx(st,{templates:t??[],templateTypes:l??[],onRefresh:a,onAdd:g,onEdit:$,onPreview:_}),e.jsx(vt,{show:v,mode:k,template:h,templateTypes:l??[],templateList:t??[],editorInitialized:E,onEditorInitialized:p,onClose:A,onSaved:()=>{A(),a()},onRefresh:a,previewHtml:f})]})},wt=({config:t})=>e.jsx(Be,{configs:t,children:e.jsx(Ue,{children:e.jsx(Oe,{children:e.jsx("div",{className:"root-widget",children:e.jsx(bt,{})})})})});j.EditorWidget=wt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
371
+ */var Me;function dt(){return Me||(Me=1,function(t){(function(){var n={}.hasOwnProperty;function r(){for(var s="",i=0;i<arguments.length;i++){var c=arguments[i];c&&(s=l(s,a(c)))}return s}function a(s){if(typeof s=="string"||typeof s=="number")return s;if(typeof s!="object")return"";if(Array.isArray(s))return r.apply(null,s);if(s.toString!==Object.prototype.toString&&!s.toString.toString().includes("[native code]"))return s.toString();var i="";for(var c in s)n.call(s,c)&&s[c]&&(i=l(i,c));return i}function l(s,i){return i?s?s+" "+i:s+i:s}t.exports?(r.default=r,t.exports=r):window.classNames=r})()}(we)),we.exports}var pt=dt();const Pe=ct(pt),De=t=>t.data.isSeparator?e.jsx("div",{style:{padding:0,margin:"2px 0"},children:e.jsx("hr",{style:{border:0,borderTop:"1px solid #bdbdbdff",padding:0,margin:0}})}):t.data.icon?e.jsxs("div",{className:"d-flex align-items-center",children:[e.jsx(oe.components.Option,{...t}),e.jsx("span",{className:"px-1 template-studio-dropdown-postfix-icon",children:t.data.icon})]}):e.jsx(oe.components.Option,{...t}),ut=({name:t="",control:n,options:r,multiple:a=!1,placeholder:l,validation:s,labelKey:i="name",disabled:c,isInvalid:d,value:v,onChange:S,uncontrolled:k,menuPlacement:b="auto",closeOnSelect:E=!0})=>{const p={control:f=>({...f,minHeight:"33px",borderColor:d?"var(--bs-form-invalid-border-color) !important":"var(--ct-input-border-color)",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",backgroundRepeat:"no-repeat",backgroundPosition:"right calc(0.375em + 0.225rem) center",backgroundSize:"calc(0.75em + 0.45rem) calc(0.75em + 0.45rem)","&:hover":{borderColor:d?"var(--bs-form-invalid-border-color)":"var(--ct-input-border-color)"},"& .react-select__single-value":{color:"var(--ct-input-color) !important"},"& .react-select__placeholder":{color:"var(--ct-input-placeholder-color) !important"},"& .react-select__indicators":{display:"none"}}),menu:f=>({...f,marginTop:0,width:"max-content",minWidth:"100%"}),menuPortal:f=>({...f,zIndex:1e4}),multiValueRemove:f=>({...f,display:c?"none":"block"})};return k?e.jsx(oe,{components:{Option:De},isOptionDisabled:f=>!!f.isSeparator,className:Pe({"is-invalid":d}),styles:p,classNamePrefix:"react-select",isMulti:a,options:r,onChange:S,placeholder:l,menuPortalTarget:document.body,value:v,getOptionLabel:typeof i=="string"?f=>f[i]:i,getOptionValue:f=>f.id,isDisabled:c,menuPlacement:b,closeMenuOnSelect:E}):e.jsx(Ee.Controller,{control:n,name:t,rules:s,render:({field:{onChange:f,value:T,onBlur:h}})=>e.jsx(oe,{components:{Option:De},isOptionDisabled:y=>!!y.isSeparator,className:Pe({"is-invalid":d}),styles:p,classNamePrefix:"react-select",isMulti:a,options:r,onBlur:h,onChange:f,placeholder:l,menuPortalTarget:document.body,value:T,getOptionLabel:typeof i=="string"?y=>y[i]:i,getOptionValue:y=>y.id,isDisabled:c,menuPlacement:b,closeMenuOnSelect:E},T?T.id||T.value||JSON.stringify(T):"reset")})},ce=({label:t,name:n,validation:r,control:a,error:l,options:s=[],required:i=!1,disabled:c=!1,className:d=""})=>{const v=!!(l&&l[n]);return e.jsxs("div",{className:`ts-form-group ${d}`,children:[t&&e.jsxs("label",{className:"ts-form-label",children:[t,i&&e.jsx("span",{className:"ts-required",children:"*"})]}),e.jsx(ut,{name:n,control:a,options:s,validation:r,disabled:c,isInvalid:v}),v&&e.jsx("div",{className:"ts-error-text",children:l?.[n]?.message})]})},ft=()=>{const t=W();K.useQueryClient();const{enerexIdentifier:n,projectId:r}=U();return K.useMutation({mutationKey:["saveTemplate"],mutationFn:async l=>(l.enerexIdentifier=n??"",l.projectId=r??"",await t.post(`${Y.SaveTemplate}`,l))})},mt={id:"",name:"New (Blank)"},ht=({onReset:t,editorInitialized:n,mode:r,templateTypes:a,templateList:l,template:s,onRefresh:i,closeEditorModal:c})=>{const{defaultSelector:d,isAdmin:v,userEmail:S}=U(),{mutateAsync:k,isPending:b}=Le(),{register:E,handleSubmit:p,clearErrors:f,setValue:T,control:h,watch:y,reset:g,setError:$,formState:{errors:_}}=Ee.useForm({defaultValues:{templateName:"",subTemplateType:void 0,subTemplateType2:void 0,subject:"",templateType:void 0,template:mt},mode:"onChange"}),[A,M]=o.useState([]),[C,L]=o.useState(),{mutateAsync:D,isPending:w}=ft(),[te,V]=o.useState([]),[X,H]=o.useState([]),[q,ne]=o.useState([]),[se,de]=o.useState(!1),Q=o.useRef(!1),{showNotification:re}=le(),z=r==="edit",pe=se||w||b||!n;o.useEffect(()=>{if(a){let m=a.filter(B=>B.id!=null),x=ge(m,0);V(ye(x))}},[a]),o.useEffect(()=>{r==="edit"&&!Q.current&&de(!0)},[r]),o.useEffect(()=>{if(r!=="edit"||!s||!n||!a.length||!A.length||Q.current)return;const m=A.find(O=>O.id===s.templateID);if(!m)return;const x=a.filter(O=>O.id!=null),B=x.find(O=>`${O.id}`==`${m.type}`),F=B?x.find(O=>`${O.id}`==`${B.parent_id}`):void 0,Z=F?x.find(O=>`${O.id}`==`${F.parent_id}`):void 0;g({templateType:Z?R(Z):void 0,subTemplateType:F?R(F):void 0,subTemplateType2:B?R(B):void 0,template:m,templateName:s.name??"",subject:s.subject??""}),L(m),Q.current=!0,de(!1)},[r,s,n,a,A,g]);const R=m=>({id:String(m.id),name:m.name,key:m.key});o.useEffect(()=>{l?.sort((m,x)=>m.readonly!==x.readonly?(m.readonly?0:1)-(x.readonly?0:1):m.name.localeCompare(x.name)),M(l??[])},[l]),o.useEffect(()=>{if(!y("templateType"))return;const m=ge(a,1);H(ye(m.filter(x=>`${x.parent_id}`==`${y("templateType")?.id}`))),T("subTemplateType",void 0)},[y("templateType"),a]),o.useEffect(()=>{const m=y("subTemplateType");if(!m)return;const x=ge(a,2);let B=ye(x.filter(F=>`${F.parent_id}`==`${m.id}`));r!=="edit"&&!v&&(B=B.filter(F=>F.key!==2)),ne(B)},[y("subTemplateType"),a,r]),o.useEffect(()=>{if(d&&d.type1){const m=te?.find(x=>`${x.id}`===d.type1);T("templateType",m)}},[a,te]),o.useEffect(()=>{if(d&&d.type2){const m=X?.find(x=>`${x.id}`===d.type2);T("subTemplateType",m)}},[a,X]),o.useEffect(()=>{if(d&&d.type3){const m=q?.find(x=>`${x.id}`===d.type3);T("subTemplateType2",m)}},[a,q]);const ue=m=>{window.StripoEditorApi.actionsApi.getTemplateData(async x=>{try{let B=m.template.id,F="";const Z=m.templateName.trim(),O=A.find(N=>N.name===m.templateName.trim());if(O&&O?.id!==m.template.id){$("templateName",{type:"validate",message:"Template name already exists. Please choose a different name."});return}let ae=m.templateType.id;q?.length>0?ae=m.subTemplateType2.id:X?.length>0&&(ae=m.subTemplateType.id);const Ne={enerexIdentifier:"",projectId:"",templateId:B,templateType:ae,name:Z,html:x.html,css:x.css,subject:m.templateType.id==="2"?m?.subject??"":"",parent_id:F,updatedBy:S??""};if(!await D(Ne)){re("Failed to save template. Please try again.","error");return}re(z?`Template "${Z}" updated successfully.`:`Template "${Z}" created successfully.`,"success"),f(),i(),c()}catch(B){console.error(B),re("Something went wrong while saving the template.","error")}})},fe=y("templateType"),Te=y("subTemplateType");return e.jsxs(e.Fragment,{children:[pe&&e.jsx(ee,{overlay:!0}),e.jsx("div",{className:"ts-card",children:e.jsx("div",{className:"ts-card-body",children:e.jsx("form",{children:e.jsx("div",{className:"template-list-container",children:e.jsxs("div",{className:"ts-row",children:[e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Category",control:h,error:_,options:te,required:!0,disabled:z||w||b||!n,validation:{required:{value:!0,message:"Select a category"}},...E("templateType")})}),X&&X.length>0&&e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Type",control:h,error:_,options:X,required:!0,disabled:z||w||b||!n,validation:{required:{value:!0,message:"Select a type"}},...E("subTemplateType")})}),q&&q.length>0&&e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Sub Type",control:h,error:_,options:q,required:!0,disabled:z||w||b||!n,validation:{required:{value:!0,message:"Select a subtype"}},...E("subTemplateType2")})}),e.jsx("div",{className:"ts-col",children:e.jsx(ce,{label:"Template",control:h,error:_,disabled:z||!z||w||b||!n,options:[],required:!1,...E("template")})}),e.jsxs("div",{className:"ts-col ts-template-name-col",children:[e.jsx(Ie,{label:"Name",register:E,error:_,required:!0,name:"templateName",validation:{required:{value:!0,message:"Enter a name"}}}),Te?.key?.toString()==="9"&&z&&!v&&C?.is_favourite&&e.jsx("span",{className:"ts-favourite-icon",children:e.jsx(he,{variant:"filled"})})]}),fe?.key?.toString()==="12"&&e.jsx("div",{className:"ts-col",children:e.jsx(Ie,{label:"Subject",register:E,error:_,required:!1,name:"subject"})}),e.jsxs("div",{className:"ts-col ts-actions btn-padding",children:[!z&&e.jsx("button",{type:"button",className:"ts-btn ts-btn-primary",disabled:w||b||!n,onClick:()=>{L(void 0),g(),H([]),ne([]),t()},children:w||b?e.jsx(ee,{size:"sm"}):"Clear"}),e.jsx("button",{type:"button",className:"ts-btn ts-btn-primary",disabled:w||b||!n,onClick:p(ue),children:w||b?e.jsx(ee,{size:"sm"}):"Save"})]})]})})})})})]})},yt=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",width:"20px",viewBox:"0 0 640 640",...t,children:e.jsx("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"})}),gt=t=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",height:"20px",width:"20px",viewBox:"0 0 640 640",...t,children:e.jsx("path",{fill:"#6c757d",d:"M112 288L112 464L528 464L528 288L112 288zM64 128L576 128L576 512L64 512L64 128z"})}),vt=({show:t,mode:n,template:r,templateTypes:a,templateList:l,editorInitialized:s,previewHtml:i,onEditorInitialized:c,onClose:d,onRefresh:v})=>{const S=o.useRef(null),[k,b]=o.useState(!1);o.useEffect(()=>{t&&s&&window.StripoEditorApi?.actionsApi&&(n==="add"?window.StripoEditorApi.actionsApi.updateHtmlAndCss(ie,"",""):n==="edit"&&r&&window.StripoEditorApi.actionsApi.updateHtmlAndCss(r.html??ie,r.css??"",""))},[t,s,n,r]),o.useEffect(()=>{t||b(!1)},[t]);const E=()=>{window.StripoEditorApi.actionsApi.updateHtmlAndCss(ie,"","")};return t?e.jsx("div",{className:"ts-editor-modal-overlay",children:e.jsxs("div",{className:`ts-editor-modal ${k?"ts-editor-modal--fullscreen":""}`,ref:S,children:[e.jsxs("div",{className:"ts-editor-modal-header",children:[e.jsxs("h3",{className:"ts-modal-title",children:[n==="add"&&"Create Template",n==="edit"&&"Edit Template",n==="preview"&&"Preview Template"]}),e.jsxs("div",{className:"ts-editor-header-actions",children:[e.jsx("button",{className:"ts-editor-fullscreen-btn",onClick:()=>b(p=>!p),"aria-label":"Toggle fullscreen",children:k?e.jsx(yt,{style:{display:"block"}}):e.jsx(gt,{style:{display:"block"}})}),e.jsx("button",{className:"ts-editor-close-btn",onClick:d,"aria-label":"Close editor",children:"✕"})]})]}),e.jsxs("div",{className:"ts-editor-modal-body",children:[n!=="preview"&&e.jsx(ht,{mode:n,template:r,templateTypes:a,templateList:l,editorInitialized:s,onReset:E,onRefresh:v,closeEditorModal:d}),n==="preview"?e.jsx("div",{className:"ts-template-preview",children:e.jsx("iframe",{title:"Template Preview",className:"ts-template-preview-frame",srcDoc:i??""})}):e.jsx(it,{onEditorInitialized:c,loading:!1,className:"editor-container"})]})]})}):null},bt=()=>{const{data:t,isLoading:n,isFetching:r,refetch:a}=Ve(),{data:l,isLoading:s,isFetching:i}=Ke(),{mutateAsync:c,isPending:d}=He(),[v,S]=o.useState(!1),[k,b]=o.useState("add"),[E,p]=o.useState(!1),[f,T]=o.useState(""),[h,y]=o.useState(),g=()=>{b("add"),S(!0)},$=async C=>{const L=await c({id:C.id});y({...L}),b("edit"),S(!0)},_=C=>{if(!t||t.length===0)return;const L=t.find(D=>D.id===C.id);T(L?.html+"<style>"+L?.css+"</style>"),b("preview"),S(!0)},A=()=>{S(!1),p(!1),document.getElementById("UiEditorScript")?.remove()},M=n||s||r||i||d;return e.jsxs(e.Fragment,{children:[M&&e.jsx(ee,{overlay:!0}),e.jsx(st,{templates:t??[],templateTypes:l??[],onRefresh:a,onAdd:g,onEdit:$,onPreview:_}),e.jsx(vt,{show:v,mode:k,template:h,templateTypes:l??[],templateList:t??[],editorInitialized:E,onEditorInitialized:p,onClose:A,onSaved:()=>{A(),a()},onRefresh:a,previewHtml:f})]})},wt=({config:t})=>e.jsx(Be,{configs:t,children:e.jsx(Ue,{children:e.jsx(Oe,{children:e.jsx("div",{className:"root-widget",children:e.jsx(bt,{})})})})});j.EditorWidget=wt,Object.defineProperty(j,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enerex/template-studio",
3
- "version": "1.1.43",
3
+ "version": "1.1.44",
4
4
  "main": "./dist/enerex-template-editor.umd.js",
5
5
  "module": "./dist/enerex-template-editor.es.js",
6
6
  "types": "./dist/types/index.d.ts",