@enerex/template-studio 1.1.37 → 1.1.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
- import { jsx as l, jsxs as $, Fragment as De } from "react/jsx-runtime";
2
- import O, { useContext as we, useState as S, useRef as qe, useEffect as v } from "react";
3
- import { QueryClient as $e, QueryClientProvider as Re, useQuery as J, useMutation as ve, useQueryClient as Be } from "@tanstack/react-query";
4
- import me from "axios";
5
- import { Spinner as Y, Form as H, Card as ue, Row as ke, Col as M, Button as se } from "react-bootstrap";
6
- import { Controller as Ue, useForm as Me } from "react-hook-form";
7
- import fe, { components as He } from "react-select";
8
- const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
1
+ import { jsx as n, jsxs as S, Fragment as Ee } from "react/jsx-runtime";
2
+ import M, { useContext as qe, useState as w, useRef as st, useEffect as E } from "react";
3
+ import { QueryClient as it, QueryClientProvider as at, useQuery as ce, useMutation as Te, useQueryClient as lt } from "@tanstack/react-query";
4
+ import _e from "axios";
5
+ import { Spinner as z, Form as H, Card as ke, Row as ot, Col as U, Button as J } from "react-bootstrap";
6
+ import { Controller as dt, useForm as ct } from "react-hook-form";
7
+ import Ae, { components as Le } from "react-select";
8
+ const de = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
9
9
  <html\r
10
10
  dir="ltr"\r
11
11
  xmlns:o="urn:schemas-microsoft-com:office:office"\r
@@ -361,159 +361,160 @@ const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
361
361
  </div>\r
362
362
  </body>\r
363
363
  </html>\r
364
- `, xe = O.createContext(
364
+ `, Re = M.createContext(
365
365
  void 0
366
- ), Fe = ({
366
+ ), pt = ({
367
367
  children: t,
368
368
  configs: s
369
369
  }) => {
370
- const [o, i] = O.useState(s.clientId), [r, e] = O.useState(s.apiKey), [a, c] = O.useState(
370
+ const [l, a] = M.useState(s.clientId), [i, e] = M.useState(s.apiKey), [d, o] = M.useState(
371
371
  s.enerexIdentifier
372
- ), [T, y] = O.useState(s.projectId), [C, f] = O.useState(s.userEmail), [_, P] = O.useState(s.isAdmin), [x, g] = O.useState(s.meBaseUrl), [h, u] = O.useState(
372
+ ), [b, D] = M.useState(s.projectId), [A, m] = M.useState(s.userEmail), [_, u] = M.useState(s.isAdmin), [j, h] = M.useState(s.meBaseUrl), [v, y] = M.useState(
373
373
  s.defaultSelector
374
- ), m = (b) => {
375
- e(b.apiKey), i(b.clientId), y(b.projectId), c(b.enerexIdentifier), f(b.userEmail), P(b.isAdmin), u(b.defaultSelector), g(b.meBaseUrl);
374
+ ), f = (g) => {
375
+ e(g.apiKey), a(g.clientId), D(g.projectId), o(g.enerexIdentifier), m(g.userEmail), u(g.isAdmin), y(g.defaultSelector), h(g.meBaseUrl);
376
376
  };
377
- return /* @__PURE__ */ l(
378
- xe.Provider,
377
+ return /* @__PURE__ */ n(
378
+ Re.Provider,
379
379
  {
380
380
  value: {
381
- clientId: o,
382
- apiKey: r,
383
- setConfiguration: m,
384
- enerexIdentifier: a,
385
- projectId: T,
386
- userEmail: C,
381
+ clientId: l,
382
+ apiKey: i,
383
+ setConfiguration: f,
384
+ enerexIdentifier: d,
385
+ projectId: b,
386
+ userEmail: A,
387
387
  isAdmin: _,
388
- defaultSelector: h,
389
- meBaseUrl: x
388
+ defaultSelector: v,
389
+ meBaseUrl: j
390
390
  },
391
391
  children: t
392
392
  }
393
393
  );
394
- }, R = () => {
395
- const t = we(xe);
394
+ }, B = () => {
395
+ const t = qe(Re);
396
396
  if (!t)
397
397
  throw new Error("widgetConfig must be used within a ConfigProvider");
398
398
  return t;
399
- }, Se = (t = "", s) => ({ get: async (r, e) => {
399
+ }, Me = (t = "", s) => ({ get: async (i, e) => {
400
400
  try {
401
- const a = await me.get(
402
- `${t}${r}`,
401
+ const d = await _e.get(
402
+ `${t}${i}`,
403
403
  e ?? s
404
404
  );
405
- if (a.status === 200)
406
- return a.data;
407
- } catch (a) {
408
- throw a;
405
+ if (d.status === 200)
406
+ return d.data;
407
+ } catch (d) {
408
+ throw d;
409
409
  }
410
- }, post: async (r, e, a) => {
410
+ }, post: async (i, e, d) => {
411
411
  try {
412
- const c = await me.post(
413
- `${t}${r}`,
412
+ const o = await _e.post(
413
+ `${t}${i}`,
414
414
  e,
415
- a ?? s
415
+ d ?? s
416
416
  );
417
- if (c.status === 200)
418
- return c.data;
419
- } catch (c) {
420
- throw c;
417
+ if (o.status === 200)
418
+ return o.data;
419
+ } catch (o) {
420
+ throw o;
421
421
  }
422
- } }), Ce = O.createContext({
422
+ } }), Be = M.createContext({
423
423
  get: () => {
424
424
  throw new Error("HttpClientContext.get not implemented");
425
425
  },
426
426
  post: () => {
427
427
  throw new Error("HttpClientContext.post not implemented");
428
428
  }
429
- }), Ge = ({ children: t }) => {
430
- const { clientId: s, apiKey: o, isAdmin: i, meBaseUrl: r } = R(), e = {
429
+ }), mt = ({ children: t }) => {
430
+ const { clientId: s, apiKey: l, isAdmin: a, meBaseUrl: i } = B(), e = {
431
431
  headers: {
432
432
  client_id: s,
433
- "x-api-key": o,
434
- "Security-Context": i ? "admin" : "viewer"
433
+ "x-api-key": l,
434
+ "Security-Context": a ? "admin" : "viewer"
435
435
  }
436
- }, { get: a, post: c } = Se(r, e);
437
- return /* @__PURE__ */ l(Ce.Provider, { value: { get: a, post: c }, children: t });
438
- }, Ve = ({ children: t }) => {
439
- const s = new $e();
440
- return /* @__PURE__ */ l(Ge, { children: /* @__PURE__ */ l(Re, { client: s, children: t }) });
441
- }, ie = {
436
+ }, { get: d, post: o } = Me(i, e);
437
+ return /* @__PURE__ */ n(Be.Provider, { value: { get: d, post: o }, children: t });
438
+ }, ut = ({ children: t }) => {
439
+ const s = new it();
440
+ return /* @__PURE__ */ n(mt, { children: /* @__PURE__ */ n(at, { client: s, children: t }) });
441
+ }, he = {
442
442
  EDITOR_SCRIPT_URL: "https://plugins.stripo.email/resources/uieditor/latest/UIEditor.js",
443
443
  EDITOR_PLUGIN_ID: "1afdc3161ec7409a8627a1c8561d45f5",
444
444
  EDITOR_SECRET_KEY: "54ba748ed7e94f2e929555783acb03da"
445
- }, Ke = (t) => {
446
- const s = Array.from(new Set(t.map((i) => i.category))), o = [];
447
- return s.forEach((i) => {
448
- const r = t.filter((e) => e.category === i).map((e) => ({
445
+ }, ft = (t) => {
446
+ const s = Array.from(new Set(t.map((a) => a.category))), l = [];
447
+ return s.forEach((a) => {
448
+ const i = t.filter((e) => e.category === a).map((e) => ({
449
449
  label: e.label,
450
450
  value: e.value,
451
451
  hint: e.hint,
452
452
  hidden: e.hidden
453
453
  }));
454
- o.push({ category: i, entries: r });
455
- }), o;
456
- }, G = () => {
457
- const t = we(Ce);
454
+ l.push({ category: a, entries: i });
455
+ }), l;
456
+ }, V = () => {
457
+ const t = qe(Be);
458
458
  if (t)
459
459
  return t;
460
460
  throw new Error("useHttpClient must be used within a HttpClientProvider");
461
- }, V = {
461
+ }, G = {
462
462
  Template_list: "/Template/list/",
463
463
  Template: "/Template/GetTemplate/",
464
464
  MergeTags: "/Template/TemplateMergeTags/",
465
465
  ExcludeCategory: "/Template/GetExcludeCategories/",
466
466
  SaveTemplate: "/Template/save-update/",
467
- TemplateTypes: "/Template/TemplateTypes/"
468
- }, Qe = () => {
469
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
470
- return J({
467
+ TemplateTypes: "/Template/TemplateTypes/",
468
+ markFavourite: "/Template/MarkFavourite/"
469
+ }, yt = () => {
470
+ const t = V(), { enerexIdentifier: s, projectId: l } = B();
471
+ return ce({
471
472
  queryKey: ["getTemplateTags"],
472
- queryFn: async (r) => await t.get(
473
- `${V.MergeTags}${o}/${s}`
473
+ queryFn: async (i) => await t.get(
474
+ `${G.MergeTags}${l}/${s}`
474
475
  )
475
476
  });
476
- }, We = () => {
477
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
478
- return J({
477
+ }, gt = () => {
478
+ const t = V(), { enerexIdentifier: s, projectId: l } = B();
479
+ return ce({
479
480
  queryKey: ["getExcludeCategory"],
480
- queryFn: async (r) => await t.get(
481
- `${V.ExcludeCategory}${o}/${s}`
481
+ queryFn: async (i) => await t.get(
482
+ `${G.ExcludeCategory}${l}/${s}`
482
483
  )
483
484
  });
484
- }, Ye = ({
485
+ }, ht = ({
485
486
  templateHTML: t,
486
487
  className: s = "",
487
- loading: o = !1,
488
- onEditorInitialized: i
488
+ loading: l = !1,
489
+ onEditorInitialized: a
489
490
  }) => {
490
- const { post: r } = Se(), { data: e } = Qe(), { data: a } = We(), [c, T] = S(
491
- t ?? { html: z, css: "" }
492
- ), { userEmail: y } = R(), C = qe(null), f = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", _ = "https://plugins.stripo.email/api/v1/auth";
493
- v(() => {
494
- (async () => (await P(), e && a && await x(ie.EDITOR_SCRIPT_URL)))();
495
- }, [e, a]);
496
- async function P() {
497
- window.Zone || await new Promise((h, u) => {
498
- const m = document.createElement("script");
499
- m.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
500
- const b = document.querySelector("script[nonce]")?.nonce;
501
- b && m.setAttribute("nonce", b), m.onload = () => h(), m.onerror = () => u(new Error("Failed to load zone.js")), document.head.appendChild(m);
491
+ const { post: i } = Me(), { data: e } = yt(), { data: d } = gt(), [o, b] = w(
492
+ t ?? { html: de, css: "" }
493
+ ), { userEmail: D } = B(), A = st(null), m = "https://plugin.stripocdn.email/content/guids/CABINET_eab4e7d5a4603ac03f4120652a3a5a540f0c79c688514939f095f67433ed4a67/images/photo256.png", _ = "https://plugins.stripo.email/api/v1/auth";
494
+ E(() => {
495
+ (async () => (await u(), e && d && await j(he.EDITOR_SCRIPT_URL)))();
496
+ }, [e, d]);
497
+ async function u() {
498
+ window.Zone || await new Promise((v, y) => {
499
+ const f = document.createElement("script");
500
+ f.src = "https://unpkg.com/zone.js@0.13.1/bundles/zone.umd.min.js";
501
+ const g = document.querySelector("script[nonce]")?.nonce;
502
+ g && f.setAttribute("nonce", g), f.onload = () => v(), f.onerror = () => y(new Error("Failed to load zone.js")), document.head.appendChild(f);
502
503
  });
503
504
  }
504
- async function x(h) {
505
- let u = document.getElementById(
505
+ async function j(v) {
506
+ let y = document.getElementById(
506
507
  "UiEditorScript"
507
508
  );
508
- u || (u = document.createElement("script"), u.id = "UiEditorScript", u.src = h, u.onload = async () => {
509
- await g();
510
- }, document.body.appendChild(u)), await new Promise(
511
- (m) => u.addEventListener("load", () => m(), { once: !0 })
509
+ y || (y = document.createElement("script"), y.id = "UiEditorScript", y.src = v, y.onload = async () => {
510
+ await h();
511
+ }, document.body.appendChild(y)), await new Promise(
512
+ (f) => y.addEventListener("load", () => f(), { once: !0 })
512
513
  );
513
514
  }
514
- const g = async () => {
515
- const h = C.current;
516
- if (!h) {
515
+ const h = async () => {
516
+ const v = A.current;
517
+ if (!v) {
517
518
  console.error("Missing #stripoEditorContainer in DOM");
518
519
  return;
519
520
  }
@@ -521,181 +522,261 @@ const z = `<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:
521
522
  console.error("UIEditor script not loaded or not exposing initEditor");
522
523
  return;
523
524
  }
524
- const u = {
525
- html: c.html,
526
- css: c.css,
527
- modulesExcludedCategories: a ?? [],
525
+ const y = {
526
+ html: o.html,
527
+ css: o.css,
528
+ modulesExcludedCategories: d ?? [],
528
529
  forceRecreate: !0,
529
530
  metadata: {
530
- emailId: y,
531
+ emailId: D,
531
532
  userId: "1",
532
533
  // username: userName,
533
- avatarUrl: f
534
+ avatarUrl: m
534
535
  },
535
536
  locale: "en",
536
- onTokenRefreshRequest: async (m) => {
537
- const b = {
538
- pluginId: ie.EDITOR_PLUGIN_ID,
539
- secretKey: ie.EDITOR_SECRET_KEY,
540
- userId: y,
537
+ onTokenRefreshRequest: async (f) => {
538
+ const g = {
539
+ pluginId: he.EDITOR_PLUGIN_ID,
540
+ secretKey: he.EDITOR_SECRET_KEY,
541
+ userId: D,
541
542
  role: "user"
542
- }, B = await r(
543
+ }, T = await i(
543
544
  _,
544
- b
545
+ g
545
546
  );
546
- B?.token && m(B.token);
547
+ T?.token && f(T.token);
547
548
  },
548
549
  onTemplateLoaded: () => {
549
- i && i(!0);
550
+ a && a(!0);
550
551
  },
551
- mergeTags: Ke(e ?? [])
552
+ mergeTags: ft(e ?? [])
552
553
  };
553
- for (const [m, b] of Object.entries({
554
+ for (const [f, g] of Object.entries({
554
555
  codeEditorButtonSelector: "#codeEditor",
555
556
  undoButtonSelector: "#undoButton",
556
557
  redoButtonSelector: "#redoButton",
557
558
  mobileViewButtonSelector: "#mobileViewButton",
558
559
  desktopViewButtonSelector: "#desktopViewButton"
559
560
  }))
560
- h.ownerDocument && h.getRootNode() instanceof ShadowRoot && h.getRootNode().querySelector(b) && (u[m] = b);
561
- await window.UIEditor.initEditor(h, u);
561
+ v.ownerDocument && v.getRootNode() instanceof ShadowRoot && v.getRootNode().querySelector(g) && (y[f] = g);
562
+ await window.UIEditor.initEditor(v, y);
562
563
  };
563
- return /* @__PURE__ */ l("div", { className: "position-relative", children: /* @__PURE__ */ $("div", { className: `editor-container ${s}`, children: [
564
- o && /* @__PURE__ */ l("div", { className: "loading-overlay", children: /* @__PURE__ */ l(
565
- Y,
564
+ return /* @__PURE__ */ n("div", { className: "position-relative", children: /* @__PURE__ */ S("div", { className: `editor-container ${s}`, children: [
565
+ l && /* @__PURE__ */ n("div", { className: "loading-overlay", children: /* @__PURE__ */ n(
566
+ z,
566
567
  {
567
568
  animation: "border",
568
569
  style: { width: "11px", height: "11px" },
569
570
  size: "sm",
570
571
  role: "status",
571
572
  className: "me-1",
572
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
573
+ children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
573
574
  }
574
575
  ) }),
575
- /* @__PURE__ */ l("div", { id: "externalSystemContainer" }),
576
- /* @__PURE__ */ l("div", { id: "stripoEditorContainer", ref: C })
576
+ /* @__PURE__ */ n("div", { id: "externalSystemContainer" }),
577
+ /* @__PURE__ */ n("div", { id: "stripoEditorContainer", ref: A })
577
578
  ] }) });
578
- }, ye = ({
579
+ }, je = ({
579
580
  label: t,
580
581
  register: s,
581
- validation: o,
582
- required: i = !1,
583
- name: r,
582
+ validation: l,
583
+ required: a = !1,
584
+ name: i,
584
585
  error: e,
585
- className: a = "",
586
- ...c
587
- }) => /* @__PURE__ */ $(H.Group, { className: a + " mb-1", children: [
588
- t ? /* @__PURE__ */ $(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
586
+ className: d = "",
587
+ ...o
588
+ }) => /* @__PURE__ */ S(H.Group, { className: d + " mb-1", style: { width: "100%" }, children: [
589
+ t ? /* @__PURE__ */ S(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
589
590
  t,
590
- i && /* @__PURE__ */ l("label", { className: "text-danger", children: "*" })
591
+ a && /* @__PURE__ */ n("label", { className: "text-danger", children: "*" })
591
592
  ] }) : null,
592
- /* @__PURE__ */ l(
593
+ /* @__PURE__ */ n(
593
594
  H.Control,
594
595
  {
595
- name: r,
596
+ name: i,
596
597
  type: "text",
597
- ...c,
598
- isInvalid: !!(e && e[r]),
599
- ...s ? s(r, {
600
- ...o
598
+ ...o,
599
+ isInvalid: !!(e && e[i]),
600
+ ...s ? s(i, {
601
+ ...l
601
602
  }) : {},
602
- className: `react-select__control ${e && e[r] && "border border-danger"}`
603
+ className: `react-select__control ${e && e[i] && "border border-danger"}`
603
604
  }
604
605
  ),
605
- e && e[r] ? /* @__PURE__ */ l(H.Control.Feedback, { type: "invalid", children: e[r].message }) : null
606
- ] }), ze = () => {
607
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
608
- return J({
606
+ e && e[i] ? /* @__PURE__ */ n(H.Control.Feedback, { type: "invalid", children: e[i].message }) : null
607
+ ] }), bt = ({
608
+ show: t,
609
+ variant: s,
610
+ title: l = "Are you sure?",
611
+ message: a,
612
+ label: i = "Name",
613
+ value: e = "",
614
+ placeholder: d = "",
615
+ requiredMessage: o = "This field is required",
616
+ externalError: b = !1,
617
+ externalErrorMessage: D = "",
618
+ confirmText: A = "Ok",
619
+ cancelText: m = "Cancel",
620
+ confirmButtonVariant: _ = "danger",
621
+ onConfirm: u,
622
+ onCancel: j,
623
+ onInputChange: h
624
+ }) => {
625
+ const [v, y] = w(e), [f, g] = w(!1);
626
+ if (E(() => {
627
+ t && (y(e), g(!1));
628
+ }, [t, e]), E(() => {
629
+ b && g(!0);
630
+ }, [b]), !t) return null;
631
+ const T = s === "input" && !v.trim(), P = s === "input" && (T || b), pe = T ? o : b ? D : "", K = () => {
632
+ if (P) {
633
+ g(!0);
634
+ return;
635
+ }
636
+ u(v.trim());
637
+ };
638
+ return /* @__PURE__ */ n("div", { className: "template-studio-modal-overlay", children: /* @__PURE__ */ S("div", { className: "template-studio-modal", children: [
639
+ /* @__PURE__ */ S("div", { className: "template-studio-modal-header", children: [
640
+ /* @__PURE__ */ n("h4", { children: l }),
641
+ /* @__PURE__ */ n("button", { className: "template-studio-modal-close", onClick: j, children: "✕" })
642
+ ] }),
643
+ /* @__PURE__ */ S("div", { className: "template-studio-modal-body", children: [
644
+ a && /* @__PURE__ */ n("p", { children: a }),
645
+ s === "input" && /* @__PURE__ */ S("div", { className: "mb-3", children: [
646
+ /* @__PURE__ */ S("label", { className: "form-label", children: [
647
+ i,
648
+ /* @__PURE__ */ n("span", { className: "text-danger", children: "*" })
649
+ ] }),
650
+ /* @__PURE__ */ n(
651
+ "input",
652
+ {
653
+ type: "text",
654
+ className: `form-control ${f && P ? "is-invalid" : ""}`,
655
+ placeholder: d,
656
+ value: v,
657
+ onChange: (ee) => {
658
+ y(ee.target.value), f && g(!1), h?.(ee.target.value);
659
+ },
660
+ autoFocus: !0
661
+ }
662
+ ),
663
+ f && P && /* @__PURE__ */ n("div", { className: "invalid-feedback d-block", children: pe })
664
+ ] })
665
+ ] }),
666
+ /* @__PURE__ */ S("div", { className: "template-studio-modal-footer", children: [
667
+ /* @__PURE__ */ n("button", { className: "btn btn-secondary", onClick: j, children: m }),
668
+ /* @__PURE__ */ n(
669
+ "button",
670
+ {
671
+ className: `btn btn-${_}`,
672
+ onClick: K,
673
+ children: A
674
+ }
675
+ )
676
+ ] })
677
+ ] }) });
678
+ }, vt = () => {
679
+ const t = V(), { enerexIdentifier: s, projectId: l } = B();
680
+ return ce({
609
681
  queryKey: ["getTemplatesList"],
610
- queryFn: async (r) => await t.get(
611
- `${V.Template_list}${o}/${s}`
682
+ queryFn: async (i) => await t.get(
683
+ `${G.Template_list}${l}/${s}`
612
684
  )
613
685
  });
614
686
  };
615
- function le(t) {
616
- return t.sort((s, o) => s.name.localeCompare(o.name));
687
+ function be(t) {
688
+ return t.sort((s, l) => s.name.localeCompare(l.name));
617
689
  }
618
- function Je(t) {
619
- const s = /* @__PURE__ */ new Map(), o = [];
690
+ function wt(t) {
691
+ const s = /* @__PURE__ */ new Map(), l = [];
620
692
  t.forEach((e) => s.set(e.id, e));
621
- let i = t.filter((e) => e.parent_id === 0), r = 0;
622
- for (; i.length > 0; ) {
623
- o.push({ level: r, data: i });
624
- const e = i.map((c) => c.id);
625
- i = t.filter(
626
- (c) => e.includes(c.parent_id)
627
- ), r++;
693
+ let a = t.filter((e) => e.parent_id === 0), i = 0;
694
+ for (; a.length > 0; ) {
695
+ l.push({ level: i, data: a });
696
+ const e = a.map((o) => o.id);
697
+ a = t.filter(
698
+ (o) => e.includes(o.parent_id)
699
+ ), i++;
628
700
  }
629
- return o;
701
+ return l;
630
702
  }
631
- function ae(t, s) {
632
- const i = Je(t).find((r) => r.level === s);
633
- return i ? i.data : [];
703
+ function ve(t, s) {
704
+ const a = wt(t).find((i) => i.level === s);
705
+ return a ? a.data : [];
634
706
  }
635
- const Xe = () => {
636
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
637
- return ve({
707
+ const Tt = () => {
708
+ const t = V(), { enerexIdentifier: s, projectId: l } = B();
709
+ return Te({
710
+ mutationKey: ["markFavourite"],
711
+ mutationFn: async (i) => await t.post(
712
+ `${G.markFavourite}${l}/${s}`,
713
+ i
714
+ )
715
+ });
716
+ }, xt = () => {
717
+ const t = V(), { enerexIdentifier: s, projectId: l } = B();
718
+ return Te({
638
719
  mutationKey: ["getTemplate"],
639
- mutationFn: async ({ id: r }) => {
640
- if (r)
720
+ mutationFn: async ({ id: i }) => {
721
+ if (i)
641
722
  return await t.get(
642
- `${V.Template}${s}/${r}/${o}`
723
+ `${G.Template}${s}/${i}/${l}`
643
724
  );
644
725
  }
645
726
  });
646
- }, Ze = () => {
647
- const t = G(), { enerexIdentifier: s, projectId: o } = R();
648
- return J({
727
+ }, St = () => {
728
+ const t = V(), { enerexIdentifier: s, projectId: l } = B();
729
+ return ce({
649
730
  queryKey: ["getTemplateTypes"],
650
- queryFn: async (r) => await t.get(
651
- `${V.TemplateTypes}${s}/${o}`
731
+ queryFn: async (i) => await t.get(
732
+ `${G.TemplateTypes}${s}/${l}`
652
733
  )
653
734
  });
654
735
  };
655
- function et(t) {
736
+ function Ct(t) {
656
737
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
657
738
  }
658
- var oe = { exports: {} };
739
+ var we = { exports: {} };
659
740
  /*!
660
741
  Copyright (c) 2018 Jed Watson.
661
742
  Licensed under the MIT License (MIT), see
662
743
  http://jedwatson.github.io/classnames
663
744
  */
664
- var ge;
665
- function tt() {
666
- return ge || (ge = 1, function(t) {
745
+ var Pe;
746
+ function Nt() {
747
+ return Pe || (Pe = 1, function(t) {
667
748
  (function() {
668
749
  var s = {}.hasOwnProperty;
669
- function o() {
670
- for (var e = "", a = 0; a < arguments.length; a++) {
671
- var c = arguments[a];
672
- c && (e = r(e, i(c)));
750
+ function l() {
751
+ for (var e = "", d = 0; d < arguments.length; d++) {
752
+ var o = arguments[d];
753
+ o && (e = i(e, a(o)));
673
754
  }
674
755
  return e;
675
756
  }
676
- function i(e) {
757
+ function a(e) {
677
758
  if (typeof e == "string" || typeof e == "number")
678
759
  return e;
679
760
  if (typeof e != "object")
680
761
  return "";
681
762
  if (Array.isArray(e))
682
- return o.apply(null, e);
763
+ return l.apply(null, e);
683
764
  if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]"))
684
765
  return e.toString();
685
- var a = "";
686
- for (var c in e)
687
- s.call(e, c) && e[c] && (a = r(a, c));
688
- return a;
766
+ var d = "";
767
+ for (var o in e)
768
+ s.call(e, o) && e[o] && (d = i(d, o));
769
+ return d;
689
770
  }
690
- function r(e, a) {
691
- return a ? e ? e + " " + a : e + a : e;
771
+ function i(e, d) {
772
+ return d ? e ? e + " " + d : e + d : e;
692
773
  }
693
- t.exports ? (o.default = o, t.exports = o) : window.classNames = o;
774
+ t.exports ? (l.default = l, t.exports = l) : window.classNames = l;
694
775
  })();
695
- }(oe)), oe.exports;
776
+ }(we)), we.exports;
696
777
  }
697
- var nt = tt();
698
- const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__ */ l("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ l(
778
+ var It = Nt();
779
+ const Oe = /* @__PURE__ */ Ct(It), $e = (t) => t.data.isSeparator ? /* @__PURE__ */ n("div", { style: { padding: 0, margin: "2px 0" }, children: /* @__PURE__ */ n(
699
780
  "hr",
700
781
  {
701
782
  style: {
@@ -705,34 +786,37 @@ const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__
705
786
  margin: 0
706
787
  }
707
788
  }
708
- ) }) : /* @__PURE__ */ l(He.Option, { ...t }), rt = ({
789
+ ) }) : t.data.icon ? /* @__PURE__ */ S("div", { className: "d-flex align-items-center", children: [
790
+ /* @__PURE__ */ n(Le.Option, { ...t }),
791
+ /* @__PURE__ */ n("span", { className: "px-1 template-studio-dropdown-postfix-icon", children: t.data.icon })
792
+ ] }) : /* @__PURE__ */ n(Le.Option, { ...t }), Et = ({
709
793
  name: t = "",
710
794
  control: s,
711
- options: o,
712
- multiple: i = !1,
713
- placeholder: r,
795
+ options: l,
796
+ multiple: a = !1,
797
+ placeholder: i,
714
798
  validation: e,
715
- labelKey: a = "name",
716
- disabled: c,
717
- isInvalid: T,
718
- value: y,
719
- onChange: C,
720
- uncontrolled: f,
799
+ labelKey: d = "name",
800
+ disabled: o,
801
+ isInvalid: b,
802
+ value: D,
803
+ onChange: A,
804
+ uncontrolled: m,
721
805
  menuPlacement: _ = "auto",
722
- closeOnSelect: P = !0
806
+ closeOnSelect: u = !0
723
807
  }) => {
724
- const x = {
725
- control: (g) => ({
726
- ...g,
808
+ const j = {
809
+ control: (h) => ({
810
+ ...h,
727
811
  minHeight: "33px",
728
812
  // state.isFocused can display different borderColor if you need it
729
- borderColor: T ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
730
- backgroundImage: T ? '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",
813
+ borderColor: b ? "var(--bs-form-invalid-border-color) !important" : "var(--ct-input-border-color)",
814
+ backgroundImage: b ? '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",
731
815
  backgroundRepeat: "no-repeat",
732
816
  backgroundPosition: "right calc(0.375em + 0.225rem) center",
733
817
  backgroundSize: "calc(0.75em + 0.45rem) calc(0.75em + 0.45rem)",
734
818
  "&:hover": {
735
- borderColor: T ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
819
+ borderColor: b ? "var(--bs-form-invalid-border-color)" : "var(--ct-input-border-color)"
736
820
  },
737
821
  "& .react-select__single-value": {
738
822
  color: "var(--ct-input-color) !important"
@@ -744,534 +828,708 @@ const he = /* @__PURE__ */ et(nt), be = (t) => t.data.isSeparator ? /* @__PURE__
744
828
  display: "none"
745
829
  }
746
830
  }),
747
- menu: (g) => ({
748
- ...g,
831
+ menu: (h) => ({
832
+ ...h,
749
833
  marginTop: 0,
750
834
  width: "max-content",
751
835
  minWidth: "100%"
752
836
  }),
753
- menuPortal: (g) => ({
754
- ...g,
837
+ menuPortal: (h) => ({
838
+ ...h,
755
839
  zIndex: 9999
756
840
  }),
757
- multiValueRemove: (g) => ({
758
- ...g,
759
- display: c ? "none" : "block"
841
+ multiValueRemove: (h) => ({
842
+ ...h,
843
+ display: o ? "none" : "block"
760
844
  })
761
845
  };
762
- return f ? /* @__PURE__ */ l(
763
- fe,
846
+ return m ? /* @__PURE__ */ n(
847
+ Ae,
764
848
  {
765
- components: { Option: be },
766
- isOptionDisabled: (g) => !!g.isSeparator,
767
- className: he({
768
- "is-invalid": T
849
+ components: { Option: $e },
850
+ isOptionDisabled: (h) => !!h.isSeparator,
851
+ className: Oe({
852
+ "is-invalid": b
769
853
  }),
770
- styles: x,
854
+ styles: j,
771
855
  classNamePrefix: "react-select",
772
- isMulti: i,
773
- options: o,
774
- onChange: C,
775
- placeholder: r,
856
+ isMulti: a,
857
+ options: l,
858
+ onChange: A,
859
+ placeholder: i,
776
860
  menuPortalTarget: document.body,
777
- value: y,
778
- getOptionLabel: typeof a == "string" ? (g) => g[a] : a,
779
- getOptionValue: (g) => g.id,
780
- isDisabled: c,
861
+ value: D,
862
+ getOptionLabel: typeof d == "string" ? (h) => h[d] : d,
863
+ getOptionValue: (h) => h.id,
864
+ isDisabled: o,
781
865
  menuPlacement: _,
782
- closeMenuOnSelect: P
866
+ closeMenuOnSelect: u
783
867
  }
784
- ) : /* @__PURE__ */ l(
785
- Ue,
868
+ ) : /* @__PURE__ */ n(
869
+ dt,
786
870
  {
787
871
  control: s,
788
872
  name: t,
789
873
  rules: e,
790
- render: ({ field: { onChange: g, value: h, onBlur: u } }) => /* @__PURE__ */ l(
791
- fe,
874
+ render: ({ field: { onChange: h, value: v, onBlur: y } }) => /* @__PURE__ */ n(
875
+ Ae,
792
876
  {
793
- components: { Option: be },
794
- isOptionDisabled: (m) => !!m.isSeparator,
795
- className: he({
796
- "is-invalid": T
877
+ components: { Option: $e },
878
+ isOptionDisabled: (f) => !!f.isSeparator,
879
+ className: Oe({
880
+ "is-invalid": b
797
881
  }),
798
- styles: x,
882
+ styles: j,
799
883
  classNamePrefix: "react-select",
800
- isMulti: i,
801
- options: o,
802
- onBlur: u,
803
- onChange: g,
804
- placeholder: r,
884
+ isMulti: a,
885
+ options: l,
886
+ onBlur: y,
887
+ onChange: h,
888
+ placeholder: i,
805
889
  menuPortalTarget: document.body,
806
- value: h,
807
- getOptionLabel: typeof a == "string" ? (m) => m[a] : a,
808
- getOptionValue: (m) => m.id,
809
- isDisabled: c,
890
+ value: v,
891
+ getOptionLabel: typeof d == "string" ? (f) => f[d] : d,
892
+ getOptionValue: (f) => f.id,
893
+ isDisabled: o,
810
894
  menuPlacement: _,
811
- closeMenuOnSelect: P
895
+ closeMenuOnSelect: u
812
896
  },
813
- h ? JSON.stringify(h) : "reset"
897
+ v ? v.id || v.value || JSON.stringify(v) : "reset"
814
898
  )
815
899
  }
816
900
  );
817
- }, W = ({
901
+ }, oe = ({
818
902
  label: t,
819
903
  name: s,
820
- validation: o,
821
- control: i,
822
- error: r,
904
+ validation: l,
905
+ control: a,
906
+ error: i,
823
907
  ...e
824
- }) => /* @__PURE__ */ $(H.Group, { className: "mb-1", children: [
825
- t && /* @__PURE__ */ $(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
908
+ }) => /* @__PURE__ */ S(H.Group, { className: "mb-1", children: [
909
+ t && /* @__PURE__ */ S(H.Label, { className: "mb-3 d-block form-label ts-label-height", children: [
826
910
  t,
827
911
  " ",
828
- e.required && /* @__PURE__ */ l("span", { className: "text-danger", children: "*" })
912
+ e.required && /* @__PURE__ */ n("span", { className: "text-danger", children: "*" })
829
913
  ] }),
830
- /* @__PURE__ */ l(
831
- rt,
914
+ /* @__PURE__ */ n(
915
+ Et,
832
916
  {
833
- control: i,
917
+ control: a,
834
918
  disabled: e.disabled,
835
919
  options: e.options ?? [],
836
- validation: o,
837
- isInvalid: r && !!r[s],
920
+ validation: l,
921
+ isInvalid: i && !!i[s],
838
922
  name: s
839
923
  }
840
924
  ),
841
- r && r[s] ? /* @__PURE__ */ l(H.Control.Feedback, { type: "invalid", children: r[s].message }) : null
842
- ] }), st = () => {
843
- const t = G();
844
- Be();
845
- const { enerexIdentifier: s, projectId: o } = R();
846
- return ve({
925
+ i && i[s] ? /* @__PURE__ */ n(H.Control.Feedback, { type: "invalid", children: i[s].message }) : null
926
+ ] }), _t = () => {
927
+ const t = V();
928
+ lt();
929
+ const { enerexIdentifier: s, projectId: l } = B();
930
+ return Te({
847
931
  mutationKey: ["saveTemplate"],
848
- mutationFn: async (r) => (r.enerexIdentifier = s ?? "", r.projectId = o ?? "", await t.post(
849
- `${V.SaveTemplate}`,
850
- r
932
+ mutationFn: async (i) => (i.enerexIdentifier = s ?? "", i.projectId = l ?? "", await t.post(
933
+ `${G.SaveTemplate}`,
934
+ i
851
935
  ))
852
936
  });
853
- }, K = {
937
+ }, X = (t) => {
938
+ let s = /* @__PURE__ */ n(
939
+ "span",
940
+ {
941
+ style: { width: "20px", height: "20px", display: "inline-block" }
942
+ }
943
+ );
944
+ return t.variant === "filled" ? s = /* @__PURE__ */ n(
945
+ "svg",
946
+ {
947
+ version: "1.0",
948
+ id: "Layer_1",
949
+ xmlns: "http://www.w3.org/2000/svg",
950
+ width: "20px",
951
+ height: "20px",
952
+ viewBox: "0 0 64 64",
953
+ "enable-background": "new 0 0 64 64",
954
+ children: /* @__PURE__ */ n(
955
+ "path",
956
+ {
957
+ fill: "#2196F3",
958
+ 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
959
+ 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
960
+ 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
961
+ 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
962
+ 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
963
+ C63.951,25.771,64.131,24.987,63.893,24.277z`
964
+ }
965
+ )
966
+ }
967
+ ) : t.variant === "outlined" && (s = /* @__PURE__ */ n(
968
+ "svg",
969
+ {
970
+ version: "1.0",
971
+ id: "Layer_1",
972
+ xmlns: "http://www.w3.org/2000/svg",
973
+ width: "20px",
974
+ height: "20px",
975
+ viewBox: "0 0 64 64",
976
+ enableBackground: "new 0 0 64 64",
977
+ children: /* @__PURE__ */ n(
978
+ "path",
979
+ {
980
+ fill: t.fill || "rgba(247, 216, 40, 0)",
981
+ stroke: t.stroke || "#000000",
982
+ strokeWidth: t.strokeWidth || "2",
983
+ 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
984
+ 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
985
+ 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
986
+ 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
987
+ 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
988
+ C63.951,25.771,64.131,24.987,63.893,24.277z`
989
+ }
990
+ )
991
+ }
992
+ )), s;
993
+ }, Z = {
854
994
  id: "",
855
995
  name: "New (Blank)"
856
- }, Te = {
996
+ }, De = {
857
997
  id: "",
858
998
  name: "Separator",
859
999
  isSeparator: !0
860
- }, it = ({
1000
+ }, kt = ({
861
1001
  onSelectItem: t,
862
1002
  templateLoading: s,
863
- onReset: o,
864
- editorInitialized: i
1003
+ onReset: l,
1004
+ editorInitialized: a
865
1005
  }) => {
866
- const { isAdmin: r, defaultSelector: e } = R(), {
867
- register: a,
868
- handleSubmit: c,
869
- clearErrors: T,
870
- setValue: y,
871
- control: C,
872
- watch: f,
873
- reset: _,
874
- setError: P,
875
- formState: { errors: x }
876
- } = Me({
1006
+ const { isAdmin: i, defaultSelector: e } = B(), { mutateAsync: d, isPending: o } = Tt(), {
1007
+ register: b,
1008
+ handleSubmit: D,
1009
+ clearErrors: A,
1010
+ setValue: m,
1011
+ control: _,
1012
+ watch: u,
1013
+ reset: j,
1014
+ setError: h,
1015
+ getValues: v,
1016
+ formState: { errors: y }
1017
+ } = ct({
877
1018
  defaultValues: {
878
1019
  templateName: "",
879
1020
  subTemplateType: void 0,
880
1021
  subTemplateType2: void 0,
881
1022
  subject: "",
882
1023
  templateType: void 0,
883
- template: K
1024
+ template: Z
884
1025
  },
885
1026
  mode: "onChange"
886
1027
  }), {
887
- data: g,
888
- refetch: h,
889
- isLoading: u
890
- } = ze(), [m, b] = S([]), [B, Ee] = S(!1), [k, X] = S(), [Q, F] = S(), { mutateAsync: Z, isPending: E } = Xe(), { mutateAsync: de, isPending: I } = st(), { data: U, isLoading: D } = Ze(), [ee, Ie] = S([]), [L, te] = S([]), [j, ne] = S([]);
891
- v(() => {
892
- if (U) {
893
- let n = U.filter((p) => p.id != null), d = ae(n, 0);
894
- Ie(le(d));
1028
+ data: f,
1029
+ refetch: g,
1030
+ isLoading: T
1031
+ } = vt(), [P, pe] = w([]), [K, ee] = w(!1), [L, te] = w(), [ne, re] = w(), { mutateAsync: me, isPending: N } = xt(), { mutateAsync: ue, isPending: I } = _t(), { data: F, isLoading: q } = St(), [fe, Fe] = w([]), [O, se] = w([]), [$, ie] = w([]), [Ue, ye] = w(!1), [W, He] = w("confirm"), [Ve, ge] = w(!1), [xe, Se] = w(!1);
1032
+ E(() => {
1033
+ if (F) {
1034
+ let r = F.filter((p) => p.id != null), c = ve(r, 0);
1035
+ Fe(be(c));
895
1036
  }
896
- }, [U]);
897
- const Ne = (n, d) => {
1037
+ }, [F]);
1038
+ const Ge = (r, c) => {
898
1039
  let p = [];
899
- return n.forEach((N, w) => {
900
- d.includes(w) && w !== 0 && p.push(Te), p.push(N);
1040
+ return r.forEach((C, k) => {
1041
+ c.includes(k) && k !== 0 && p.push(De), p.push(C);
901
1042
  }), p;
902
1043
  };
903
- v(() => {
904
- s(!!(u || E || I || D || !i));
905
- }, [u, E, I, D, i]), v(() => {
906
- g?.sort((n, d) => n.readonly !== d.readonly ? (n.readonly ? 0 : 1) - (d.readonly ? 0 : 1) : n.name.localeCompare(d.name)), b(g ?? []);
907
- }, [g]);
908
- const _e = async (n) => {
909
- X(n), n && (r || !n.readonly) ? (y("templateName", n?.name), T()) : (y("templateName", ""), y("subject", ""));
910
- const d = await Z({ id: n?.id });
911
- F(d || void 0);
1044
+ E(() => {
1045
+ s(!!(T || N || I || q || !a));
1046
+ }, [T, N, I, q, a]), E(() => {
1047
+ f?.sort((r, c) => r.readonly !== c.readonly ? (r.readonly ? 0 : 1) - (c.readonly ? 0 : 1) : r.name.localeCompare(c.name)), pe(f ?? []);
1048
+ }, [f]);
1049
+ const Ke = async (r) => {
1050
+ te(r), r && (i || !r.readonly) ? (m("templateName", r?.name), A()) : (m("templateName", ""), m("subject", ""));
1051
+ const c = await me({ id: r?.id });
1052
+ c ? re(c) : ae();
912
1053
  };
913
- v(() => {
914
- if ((e === void 0 || e.templateId === void 0 || B) && y("template", K), f("templateType")) {
915
- let n = U?.filter((p) => p.id !== void 0) ?? [], d = ae(n, 1);
916
- te(
917
- le(
918
- d.filter(
919
- (p) => p.parent_id.toString() === `${f("templateType")?.id}`
1054
+ E(() => {
1055
+ if ((e === void 0 || e.templateId === void 0 || K) && m("template", Z), u("templateType")) {
1056
+ let r = F?.filter((p) => p.id !== void 0) ?? [], c = ve(r, 1);
1057
+ se(
1058
+ be(
1059
+ c.filter(
1060
+ (p) => p.parent_id.toString() === `${u("templateType")?.id}`
920
1061
  )
921
1062
  )
922
- ), y("subTemplateType", void 0), y("subTemplateType2", void 0);
1063
+ ), m("subTemplateType", void 0), m("subTemplateType2", void 0);
923
1064
  }
924
- }, [f("templateType")]), v(() => {
925
- if ((e === void 0 || e.templateId === void 0) && y("template", K), f("subTemplateType")) {
926
- let n = U?.filter((p) => p.id !== void 0) ?? [], d = ae(n, 2);
927
- ne(
928
- le(
929
- d.filter(
930
- (p) => p.parent_id.toString() === `${f("subTemplateType")?.id}`
1065
+ }, [u("templateType")]), E(() => {
1066
+ if ((e === void 0 || e.templateId === void 0) && m("template", Z), u("subTemplateType")) {
1067
+ let r = F?.filter((p) => p.id !== void 0) ?? [], c = ve(r, 2);
1068
+ ie(
1069
+ be(
1070
+ c.filter(
1071
+ (p) => p.parent_id.toString() === `${u("subTemplateType")?.id}`
931
1072
  )
932
1073
  )
933
- ), y("subTemplateType2", void 0);
1074
+ ), m("subTemplateType2", void 0);
934
1075
  }
935
- }, [f("subTemplateType")]), v(() => {
936
- const n = pe();
937
- n.length > 0 && n[0].id !== "" ? (e === void 0 || e.templateId === void 0 || B) && y("template", n[0]) : (e === void 0 || e.templateId === void 0 || B) && y("template", K);
938
- }, [f("subTemplateType2")]), v(() => {
939
- let n = m.find((d) => d.id === f("template")?.id);
940
- _e(n);
941
- }, [f("template")]);
942
- const [Ae, ce] = S(!1);
943
- v(() => {
944
- Ae || (Q && k && i ? (ce(!0), t(Q), y("subject", Q.subject ?? ""), setTimeout(() => {
945
- ce(!1);
946
- }, 1e3)) : t(void 0));
947
- }, [Q, k, t, i]);
948
- const pe = () => {
949
- let n = [K], d = "templateType";
950
- j.length > 0 ? d = "subTemplateType2" : L.length > 0 && (d = "subTemplateType");
951
- let p = m.filter(
952
- (w) => (w.type?.toString() === f(d)?.id.toString() || w.type === null) && f(d)?.id != null
953
- ), N = Ne(p, [p.findIndex((w) => !w.readonly)]);
954
- return N.length > 0 && (N[0].readonly === !0 && !r ? n = [] : n.push(Te), n = [
955
- ...n,
956
- ...N.map((A) => ({
957
- id: A.id,
958
- name: Le(p, A.id),
959
- isSeparator: A.isSeparator
1076
+ }, [u("subTemplateType")]), E(() => {
1077
+ const r = Ne();
1078
+ r.length > 0 && r[0].id !== "" ? (e === void 0 || e.templateId === void 0 || K) && m("template", r[0]) : (e === void 0 || e.templateId === void 0 || K) && m("template", Z);
1079
+ }, [u("subTemplateType2")]), E(() => {
1080
+ let r = P.find((c) => c.id === u("template")?.id);
1081
+ Ke(r);
1082
+ }, [u("template")]);
1083
+ const [We, Ce] = w(!1);
1084
+ E(() => {
1085
+ xe || We || ne && L && a && (Ce(!0), t(ne), m("subject", ne.subject ?? ""), setTimeout(() => {
1086
+ Ce(!1);
1087
+ }, 1e3));
1088
+ }, [ne, L, a, xe]);
1089
+ const Ne = () => {
1090
+ let r = [Z], c = "templateType";
1091
+ $.length > 0 ? c = "subTemplateType2" : O.length > 0 && (c = "subTemplateType");
1092
+ let p = P.filter(
1093
+ (k) => (k.type?.toString() === u(c)?.id.toString() || k.type === null) && u(c)?.id != null
1094
+ ), C = Ge(p, [p.findIndex((k) => !k.readonly)]);
1095
+ return C.length > 0 && (C[0].readonly === !0 && !i ? r = [] : r.push(De), r = [
1096
+ ...r,
1097
+ ...C.map((x) => ({
1098
+ id: x.id,
1099
+ name: ze(p, x.id),
1100
+ icon: et(p, x.id) ? /* @__PURE__ */ n(X, { variant: "filled" }) : /* @__PURE__ */ n(X, { variant: "empty" }),
1101
+ isSeparator: x.isSeparator
960
1102
  }))
961
- ]), n.length ? n : [];
1103
+ ]), r.length ? r : [];
962
1104
  };
963
- v(() => {
1105
+ E(() => {
964
1106
  if (e && e.type1) {
965
- const n = ee?.find(
966
- (d) => `${d.id}` === e.type1
1107
+ const r = fe?.find(
1108
+ (c) => `${c.id}` === e.type1
967
1109
  );
968
- y("templateType", n);
1110
+ m("templateType", r);
969
1111
  }
970
- }, [U, ee]), v(() => {
1112
+ }, [F, fe]), E(() => {
971
1113
  if (e && e.type2) {
972
- const n = L?.find(
973
- (d) => `${d.id}` === e.type2
1114
+ const r = O?.find(
1115
+ (c) => `${c.id}` === e.type2
974
1116
  );
975
- y("subTemplateType", n);
1117
+ m("subTemplateType", r);
976
1118
  }
977
- }, [U, L]), v(() => {
1119
+ }, [F, O]), E(() => {
978
1120
  if (e && e.type3) {
979
- const n = j?.find(
980
- (d) => `${d.id}` === e.type3
1121
+ const r = $?.find(
1122
+ (c) => `${c.id}` === e.type3
981
1123
  );
982
- y("subTemplateType2", n);
1124
+ m("subTemplateType2", r);
983
1125
  }
984
- }, [U, j]), v(() => {
985
- if (e && e.templateId && m && m.length > 0 && !B && i) {
986
- const n = m?.find(
987
- (d) => `${d.id}` === e.templateId
1126
+ }, [F, $]), E(() => {
1127
+ if (e && e.templateId && P && P.length > 0 && !K && a) {
1128
+ const r = P?.find(
1129
+ (c) => `${c.id}` === e.templateId
988
1130
  );
989
- Ee(!0), n && (X(n), y("template", n));
1131
+ ee(!0), r && (te(r), m("template", r));
990
1132
  }
991
- }, [m, i]);
992
- const Le = (n, d) => {
993
- let p = n.find((N) => N.id === d);
1133
+ }, [P, a]);
1134
+ const ze = (r, c) => {
1135
+ let p = r.find((C) => C.id === c);
994
1136
  return p ? `${p.displayName}` : "";
995
- }, je = (n) => {
1137
+ }, Qe = (r) => {
996
1138
  window.StripoEditorApi.actionsApi.getTemplateData(
997
- async (d) => {
998
- let p = n.template.id, N = "";
999
- k?.readonly && (p = "", N = n.template.id);
1000
- let w = m.find(
1001
- (q) => q.name === n.templateName.trim()
1139
+ async (c) => {
1140
+ let p = r.template.id, C = "";
1141
+ L?.readonly && (p = "", C = r.template.id);
1142
+ let k = P.find(
1143
+ (R) => R.name === r.templateName.trim()
1002
1144
  );
1003
- if (w && w.id !== p) {
1004
- P("templateName", {
1145
+ if (k && k.id !== p) {
1146
+ h("templateName", {
1005
1147
  type: "validate",
1006
1148
  message: "Template name already exists. Please choose a different name."
1007
1149
  });
1008
1150
  return;
1009
1151
  }
1010
- let A = n.templateType.id;
1011
- j && j.length > 0 ? A = n.subTemplateType2.id : L && L.length > 0 && (A = n.subTemplateType.id);
1012
- const re = {
1152
+ let x = r.templateType.id;
1153
+ $ && $.length > 0 ? x = r.subTemplateType2.id : O && O.length > 0 && (x = r.subTemplateType.id);
1154
+ const Q = {
1013
1155
  enerexIdentifier: "",
1014
1156
  projectId: "",
1015
1157
  templateId: p,
1016
- templateType: A,
1017
- name: n.templateName.trim(),
1018
- html: d.html,
1019
- css: d.css,
1020
- subject: n.templateType.id === "2" ? n?.subject ?? "" : "",
1021
- parent_id: N
1158
+ templateType: x,
1159
+ name: r.templateName.trim(),
1160
+ html: c.html,
1161
+ css: c.css,
1162
+ subject: r.templateType.id === "2" ? r?.subject ?? "" : "",
1163
+ parent_id: C
1022
1164
  };
1023
- if (await de(re)) {
1024
- if (T(), k?.readonly && !r)
1025
- _(), te([]), ne([]);
1165
+ if (await ue(Q)) {
1166
+ if (A(), L?.readonly && !i)
1167
+ j(), se([]), ie([]);
1026
1168
  else {
1027
- const q = await Z({ id: p });
1028
- F(q || void 0);
1169
+ const R = await me({ id: p });
1170
+ R ? re(R) : ae();
1029
1171
  }
1030
- h();
1172
+ await g();
1031
1173
  }
1032
1174
  }
1033
1175
  );
1034
- }, Oe = (n) => {
1176
+ }, ae = () => {
1177
+ Se(!0), s(!1), re(void 0), t(void 0), setTimeout(() => {
1178
+ Se(!1);
1179
+ }, 0);
1180
+ }, Ye = (r, c) => {
1181
+ const p = c.trim(), C = "";
1182
+ if (P.find(
1183
+ (x) => x.name === p && x.id !== C
1184
+ )) {
1185
+ ge(!0);
1186
+ return;
1187
+ }
1188
+ ye(!1), window.StripoEditorApi.actionsApi.getTemplateData(
1189
+ async (x) => {
1190
+ const Q = r.template.id;
1191
+ let Y = r.templateType.id;
1192
+ $?.length ? Y = r.subTemplateType2.id : O?.length && (Y = r.subTemplateType.id);
1193
+ const R = {
1194
+ enerexIdentifier: "",
1195
+ projectId: "",
1196
+ templateId: C,
1197
+ templateType: Y,
1198
+ name: p,
1199
+ html: x.html,
1200
+ css: x.css,
1201
+ subject: r.templateType.id === "2" ? r?.subject ?? "" : "",
1202
+ parent_id: Q
1203
+ };
1204
+ await ue(R) && (A(), ae(), j(), se([]), ie([]), await g(), m("template", void 0));
1205
+ }
1206
+ );
1207
+ }, Je = (r) => {
1035
1208
  window.StripoEditorApi.actionsApi.getTemplateData(
1036
- async (d) => {
1037
- let p = n.template.id, N = "", w = m.find(
1038
- (q) => q.name === n.templateName.trim()
1209
+ async (c) => {
1210
+ let p = r.template.id, C = "", k = P.find(
1211
+ (R) => R.name === r.templateName.trim()
1039
1212
  );
1040
- if (w && w.id !== p) {
1041
- P("templateName", {
1213
+ if (k && k.id !== p) {
1214
+ h("templateName", {
1042
1215
  type: "validate",
1043
1216
  message: "Template name already exists. Please choose a different name."
1044
1217
  });
1045
1218
  return;
1046
1219
  }
1047
- let A = n.templateType.id;
1048
- j && j.length > 0 ? A = n.subTemplateType2.id : L && L.length > 0 && (A = n.subTemplateType.id);
1049
- const re = {
1220
+ let x = r.templateType.id;
1221
+ $ && $.length > 0 ? x = r.subTemplateType2.id : O && O.length > 0 && (x = r.subTemplateType.id);
1222
+ const Q = {
1050
1223
  enerexIdentifier: "",
1051
1224
  projectId: "",
1052
1225
  templateId: p,
1053
- templateType: A,
1054
- name: n.templateName.trim(),
1055
- html: d.html,
1056
- css: d.css,
1057
- subject: n.templateType.id === "2" ? n?.subject ?? "" : "",
1058
- parent_id: N
1226
+ templateType: x,
1227
+ name: r.templateName.trim(),
1228
+ html: c.html,
1229
+ css: c.css,
1230
+ subject: r.templateType.id === "2" ? r?.subject ?? "" : "",
1231
+ parent_id: C
1059
1232
  };
1060
- if (await de(re)) {
1061
- T();
1062
- const q = await Z({ id: p });
1063
- F(q || void 0), h();
1233
+ if (await ue(Q)) {
1234
+ A();
1235
+ const R = await me({ id: p });
1236
+ R ? re(R) : ae(), await g();
1064
1237
  }
1065
1238
  }
1066
1239
  );
1067
- };
1068
- return /* @__PURE__ */ l(ue, { className: "border border-0 text-start", children: /* @__PURE__ */ l(ue.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ l("form", { children: /* @__PURE__ */ l("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ $(ke, { children: [
1069
- /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1070
- W,
1071
- {
1072
- label: "Category",
1073
- control: C,
1074
- error: x,
1075
- options: ee,
1076
- required: !0,
1077
- disabled: u || E || I || D || !i,
1078
- validation: {
1079
- required: {
1080
- value: !0,
1081
- message: "Select a category"
1082
- }
1083
- },
1084
- ...a("templateType")
1085
- }
1086
- ) }),
1087
- L && L.length > 0 && /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1088
- W,
1089
- {
1090
- label: "Type",
1091
- control: C,
1092
- error: x,
1093
- options: L,
1094
- required: !0,
1095
- disabled: u || E || I || D || !i,
1096
- validation: {
1097
- required: {
1098
- value: !0,
1099
- message: "Select a type"
1100
- }
1101
- },
1102
- ...a("subTemplateType")
1103
- }
1104
- ) }),
1105
- j && j.length > 0 && /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1106
- W,
1107
- {
1108
- label: "Sub Type",
1109
- control: C,
1110
- error: x,
1111
- options: j,
1112
- required: !0,
1113
- disabled: u || E || I || D || !i,
1114
- validation: {
1115
- required: {
1116
- value: !0,
1117
- message: "Select a subtype"
1118
- }
1119
- },
1120
- ...a("subTemplateType2")
1121
- }
1122
- ) }),
1123
- /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1124
- W,
1125
- {
1126
- label: "Template",
1127
- control: C,
1128
- error: x,
1129
- disabled: u || E || I || D || !i,
1130
- options: pe(),
1131
- required: !1,
1132
- ...a("template")
1133
- }
1134
- ) }),
1135
- /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1136
- ye,
1137
- {
1138
- label: "Name",
1139
- register: a,
1140
- error: x,
1141
- required: !0,
1142
- name: "templateName",
1143
- validation: {
1144
- required: {
1145
- value: !0,
1146
- message: "Enter a name"
1147
- }
1240
+ }, Xe = () => {
1241
+ He("input"), ye(!0), ge(!1);
1242
+ }, Ze = (r) => {
1243
+ if (W === "input") {
1244
+ const c = v();
1245
+ Ye(c, r || "");
1246
+ return;
1247
+ }
1248
+ }, et = (r, c) => {
1249
+ let p = r.find((C) => C.id === c);
1250
+ if (p)
1251
+ return p.is_favourite;
1252
+ }, tt = async () => {
1253
+ let r = u("templateType")?.id;
1254
+ $ && $.length > 0 ? r = u("subTemplateType2")?.id : O && O.length > 0 && (r = u("subTemplateType")?.id), await d({
1255
+ categoryId: r ?? "",
1256
+ templateId: u("template")?.id ?? ""
1257
+ }), L && te({
1258
+ ...L,
1259
+ is_favourite: !0
1260
+ }), await g();
1261
+ }, le = u("templateType"), Ie = u("subTemplateType"), nt = u("subTemplateType2"), rt = u("template");
1262
+ return /* @__PURE__ */ S(Ee, { children: [
1263
+ /* @__PURE__ */ n(ke, { className: "border border-0 text-start", children: /* @__PURE__ */ n(ke.Body, { className: "pe-0 ps-2", children: /* @__PURE__ */ n("form", { children: /* @__PURE__ */ n("div", { className: "template-list-container gap-3", children: /* @__PURE__ */ S(ot, { children: [
1264
+ /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1265
+ oe,
1266
+ {
1267
+ label: "Category",
1268
+ control: _,
1269
+ error: y,
1270
+ options: fe,
1271
+ required: !0,
1272
+ disabled: T || N || I || q || o || !a,
1273
+ validation: {
1274
+ required: {
1275
+ value: !0,
1276
+ message: "Select a category"
1277
+ }
1278
+ },
1279
+ ...b("templateType")
1148
1280
  }
1149
- }
1150
- ) }),
1151
- f("templateType")?.id === "2" && /* @__PURE__ */ l(M, { children: /* @__PURE__ */ l(
1152
- ye,
1153
- {
1154
- label: "Subject",
1155
- register: a,
1156
- error: x,
1157
- required: !1,
1158
- name: "subject"
1159
- }
1160
- ) }),
1161
- /* @__PURE__ */ $(M, { className: "d-flex align-self-start justify-content-end gap-2 mb-1 btn-padding", children: [
1162
- /* @__PURE__ */ l(
1163
- se,
1281
+ ) }),
1282
+ O && O.length > 0 && /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1283
+ oe,
1164
1284
  {
1165
- style: { width: "70px" },
1166
- variant: "primary",
1167
- disabled: u || E || I || D || !i,
1168
- onClick: () => {
1169
- X(void 0), _(), te([]), ne([]), o();
1285
+ label: "Type",
1286
+ control: _,
1287
+ error: y,
1288
+ options: O,
1289
+ required: !0,
1290
+ disabled: T || N || I || q || o || !a,
1291
+ validation: {
1292
+ required: {
1293
+ value: !0,
1294
+ message: "Select a type"
1295
+ }
1170
1296
  },
1171
- children: E || I ? /* @__PURE__ */ l(
1172
- Y,
1173
- {
1174
- animation: "border",
1175
- style: { width: "11px", height: "11px" },
1176
- size: "sm",
1177
- role: "status",
1178
- className: "me-1",
1179
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
1297
+ ...b("subTemplateType")
1298
+ }
1299
+ ) }),
1300
+ $ && $.length > 0 && /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1301
+ oe,
1302
+ {
1303
+ label: "Sub Type",
1304
+ control: _,
1305
+ error: y,
1306
+ options: $,
1307
+ required: !0,
1308
+ disabled: T || N || I || q || o || !a,
1309
+ validation: {
1310
+ required: {
1311
+ value: !0,
1312
+ message: "Select a subtype"
1180
1313
  }
1181
- ) : "Clear"
1314
+ },
1315
+ ...b("subTemplateType2")
1316
+ }
1317
+ ) }),
1318
+ /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1319
+ oe,
1320
+ {
1321
+ label: "Template",
1322
+ control: _,
1323
+ error: y,
1324
+ disabled: T || N || I || q || o || !a,
1325
+ options: Ne(),
1326
+ required: !1,
1327
+ ...b("template")
1182
1328
  }
1183
- ),
1184
- (f("templateType")?.id.toString() !== "2" || (f("templateType")?.id.toString() === "2" && (k?.id ?? "")) !== "") && /* @__PURE__ */ $(De, { children: [
1185
- !(k?.readonly && r) && /* @__PURE__ */ l(
1186
- se,
1329
+ ) }),
1330
+ /* @__PURE__ */ S(U, { className: "d-flex align-self-start", children: [
1331
+ /* @__PURE__ */ n(
1332
+ je,
1187
1333
  {
1188
- type: "button",
1189
- onClick: c(je),
1190
- variant: "primary",
1191
- style: { width: "80px" },
1192
- disabled: u || E || I || D || !i,
1193
- children: E || I ? /* @__PURE__ */ l(
1194
- Y,
1334
+ label: "Name",
1335
+ register: b,
1336
+ error: y,
1337
+ required: !0,
1338
+ name: "templateName",
1339
+ validation: {
1340
+ required: {
1341
+ value: !0,
1342
+ message: "Enter a name"
1343
+ }
1344
+ }
1345
+ }
1346
+ ),
1347
+ Ie?.key?.toString() === "9" && /* @__PURE__ */ n(
1348
+ J,
1349
+ {
1350
+ className: "template-favourite-btn",
1351
+ style: { width: "26px", marginTop: "25px" },
1352
+ variant: "light",
1353
+ disabled: T || N || I || q || o || (L ? L?.is_favourite : !1),
1354
+ onClick: tt,
1355
+ children: N || I || o ? /* @__PURE__ */ n(
1356
+ z,
1195
1357
  {
1196
1358
  animation: "border",
1197
1359
  style: { width: "11px", height: "11px" },
1198
1360
  size: "sm",
1199
1361
  role: "status",
1200
1362
  className: "me-1",
1201
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
1363
+ children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1202
1364
  }
1203
- ) : k?.readonly ? "Save as" : "Save"
1365
+ ) : L ? L?.is_favourite ? /* @__PURE__ */ n(X, { variant: "filled" }) : /* @__PURE__ */ n(X, { variant: "outlined" }) : /* @__PURE__ */ n(X, { variant: "outlined" })
1204
1366
  }
1205
- ),
1206
- k?.readonly && r && /* @__PURE__ */ l(
1207
- se,
1367
+ )
1368
+ ] }),
1369
+ le?.key?.toString() === "12" && /* @__PURE__ */ n(U, { children: /* @__PURE__ */ n(
1370
+ je,
1371
+ {
1372
+ label: "Subject",
1373
+ register: b,
1374
+ error: y,
1375
+ required: !1,
1376
+ name: "subject"
1377
+ }
1378
+ ) }),
1379
+ /* @__PURE__ */ S(U, { className: "d-flex align-self-start justify-content-end gap-2 mb-1 btn-padding", children: [
1380
+ /* @__PURE__ */ n(
1381
+ J,
1208
1382
  {
1209
- type: "button",
1210
- onClick: c(Oe),
1383
+ style: { width: "70px" },
1211
1384
  variant: "primary",
1212
- style: { width: "80px" },
1213
- disabled: u || E || I || D || !i,
1214
- children: E || I ? /* @__PURE__ */ l(
1215
- Y,
1385
+ disabled: T || N || I || q || o || !a,
1386
+ onClick: () => {
1387
+ te(void 0), j(), se([]), ie([]), l();
1388
+ },
1389
+ children: N || I || o ? /* @__PURE__ */ n(
1390
+ z,
1216
1391
  {
1217
1392
  animation: "border",
1218
1393
  style: { width: "11px", height: "11px" },
1219
1394
  size: "sm",
1220
1395
  role: "status",
1221
1396
  className: "me-1",
1222
- children: /* @__PURE__ */ l("span", { className: "visually-hidden", children: "Loading..." })
1397
+ children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1223
1398
  }
1224
- ) : "Save"
1399
+ ) : "Clear"
1225
1400
  }
1226
- )
1401
+ ),
1402
+ (le?.key?.toString() !== "12" || (le?.key?.toString() === "12" && (L?.id ?? "")) !== "") && /* @__PURE__ */ S(Ee, { children: [
1403
+ !(L?.readonly && i) && /* @__PURE__ */ n(
1404
+ J,
1405
+ {
1406
+ type: "button",
1407
+ onClick: D(Qe),
1408
+ variant: "primary",
1409
+ style: { width: "80px" },
1410
+ disabled: T || N || I || q || o || !a,
1411
+ children: N || I || o ? /* @__PURE__ */ n(
1412
+ z,
1413
+ {
1414
+ animation: "border",
1415
+ style: { width: "11px", height: "11px" },
1416
+ size: "sm",
1417
+ role: "status",
1418
+ className: "me-1",
1419
+ children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1420
+ }
1421
+ ) : L?.readonly ? "Save as" : "Save"
1422
+ }
1423
+ ),
1424
+ (le?.key?.toString() === "28" || Ie?.key?.toString() === "9" && nt?.key?.toString() === "3" && (rt?.id ?? "") !== "") && /* @__PURE__ */ n(
1425
+ J,
1426
+ {
1427
+ type: "button",
1428
+ variant: "primary",
1429
+ style: { width: "80px" },
1430
+ onClick: () => Xe(),
1431
+ disabled: T || N || I || q || o || !a,
1432
+ children: N || I || o ? /* @__PURE__ */ n(
1433
+ z,
1434
+ {
1435
+ animation: "border",
1436
+ style: { width: "11px", height: "11px" },
1437
+ size: "sm",
1438
+ role: "status",
1439
+ className: "me-1",
1440
+ children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1441
+ }
1442
+ ) : "Save as"
1443
+ }
1444
+ ),
1445
+ L?.readonly && i && /* @__PURE__ */ n(
1446
+ J,
1447
+ {
1448
+ type: "button",
1449
+ onClick: D(Je),
1450
+ variant: "primary",
1451
+ style: { width: "80px" },
1452
+ disabled: T || N || I || q || o || !a,
1453
+ children: N || I || o ? /* @__PURE__ */ n(
1454
+ z,
1455
+ {
1456
+ animation: "border",
1457
+ style: { width: "11px", height: "11px" },
1458
+ size: "sm",
1459
+ role: "status",
1460
+ className: "me-1",
1461
+ children: /* @__PURE__ */ n("span", { className: "visually-hidden", children: "Loading..." })
1462
+ }
1463
+ ) : "Save"
1464
+ }
1465
+ )
1466
+ ] })
1227
1467
  ] })
1228
- ] })
1229
- ] }) }) }) }) });
1230
- }, ut = ({ config: t }) => {
1231
- const [s, o] = S(!1), [i, r] = S(), [e, a] = S(!1);
1232
- v(() => {
1233
- t.isAdmin || a(!0);
1468
+ ] }) }) }) }) }),
1469
+ /* @__PURE__ */ n(
1470
+ bt,
1471
+ {
1472
+ show: Ue,
1473
+ variant: W,
1474
+ title: W === "confirm" ? "Are you sure?" : "Save Template As",
1475
+ message: W === "confirm" ? 'Are you sure you want to remove custom template ""?' : "",
1476
+ label: "New Name",
1477
+ requiredMessage: "Enter a new name",
1478
+ externalError: Ve,
1479
+ externalErrorMessage: "Template name already exists. Please choose a different name",
1480
+ confirmText: W === "confirm" ? "Ok" : "Save as",
1481
+ confirmButtonVariant: W === "confirm" ? "danger" : "primary",
1482
+ onConfirm: Ze,
1483
+ onCancel: () => ye(!1),
1484
+ onInputChange: () => ge(!1)
1485
+ }
1486
+ )
1487
+ ] });
1488
+ }, Rt = ({ config: t }) => {
1489
+ const [s, l] = w(!1), [a, i] = w(), [e, d] = w(!1);
1490
+ E(() => {
1491
+ t.isAdmin || d(!0);
1234
1492
  }, []);
1235
- const [c, T] = S(!1);
1236
- return /* @__PURE__ */ l(Fe, { configs: t, children: /* @__PURE__ */ l(Ve, { children: /* @__PURE__ */ $("div", { className: "root-widget", children: [
1237
- /* @__PURE__ */ l(
1238
- it,
1493
+ const [o, b] = w(!1);
1494
+ return /* @__PURE__ */ n(pt, { configs: t, children: /* @__PURE__ */ n(ut, { children: /* @__PURE__ */ S("div", { className: "root-widget", children: [
1495
+ /* @__PURE__ */ n(
1496
+ kt,
1239
1497
  {
1240
- templateLoading: T,
1241
- onSelectItem: (f) => {
1242
- if (r(f), t.isAdmin && a(!0), window.StripoEditorApi && window.StripoEditorApi.actionsApi) {
1243
- let _ = z;
1244
- window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1245
- f?.html ?? _,
1246
- f?.css ?? "",
1498
+ templateLoading: b,
1499
+ onSelectItem: (m) => {
1500
+ if (i(m), t.isAdmin && d(!0), window.StripoEditorApi && window.StripoEditorApi.actionsApi) {
1501
+ let _ = de;
1502
+ console.log("selected template:"), window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1503
+ m?.html ?? _,
1504
+ m?.css ?? "",
1247
1505
  ""
1248
1506
  );
1249
1507
  }
1250
1508
  },
1251
1509
  editorInitialized: s,
1252
1510
  onReset: () => {
1253
- T(!1), r(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1254
- z,
1511
+ b(!1), i(void 0), window.StripoEditorApi && window.StripoEditorApi.actionsApi && window.StripoEditorApi.actionsApi.updateHtmlAndCss(
1512
+ de,
1255
1513
  "",
1256
1514
  ""
1257
1515
  );
1258
1516
  }
1259
1517
  }
1260
1518
  ),
1261
- e && /* @__PURE__ */ l(
1262
- Ye,
1519
+ e && /* @__PURE__ */ n(
1520
+ ht,
1263
1521
  {
1264
- onEditorInitialized: o,
1522
+ onEditorInitialized: l,
1265
1523
  templateHTML: {
1266
- css: i?.css ?? "",
1267
- html: i?.html ?? z
1524
+ css: a?.css ?? "",
1525
+ html: a?.html ?? de
1268
1526
  },
1269
- loading: c,
1527
+ loading: o,
1270
1528
  className: "col-span-5"
1271
1529
  }
1272
1530
  )
1273
1531
  ] }) }) });
1274
1532
  };
1275
1533
  export {
1276
- ut as EditorWidget
1534
+ Rt as EditorWidget
1277
1535
  };