import { jsxs as r, Fragment as nt, jsx as t } from "react/jsx-runtime";
import { S as it, N as rt, w as lt, m as ot, b as dt } from "./EventsSkeleton-BN7_0IGs-BAnd1Vug.js";
import { retrieveAllNotifications as st, getReportsList as ct } from "@/common/services/GlobalApis";
import { showToast as B } from "@/common/toaster/toaster";
import we from "@/views/custom-components/CustomTextArea";
import L from "@/views/custom-components/CustomTextField";
import { yupResolver as ut } from "@hookform/resolvers/yup";
import mt from "@/views/custom-components/CustomDropdown";
import { Card as ft, CardHeader as gt, CardContent as vt, FormControl as x, Typography as d, Box as C, Select as Y, MenuItem as v, Divider as G, Button as W, TableContainer as ht, Paper as pt, Table as yt, TableHead as bt, TableRow as xe, TableCell as S, TableBody as wt, CardActions as xt } from "@mui/material";
import g from "@mui/material/Grid2";
import { useRef as Ne, useState as u, useEffect as Te, Suspense as Ce, lazy as Z } from "react";
import { useForm as Nt, Controller as F } from "react-hook-form";
import { useNavigate as Tt } from "react-router";
import { useParams as Ct } from "react-router-dom";
import * as E from "yup";
import { useTranslateProvider as Et } from "@/common/languageTranslator/TranslationContext";
import It from "@/hooks/useTrackEvent";
import { FontAwesomeIcon as _ } from "@fortawesome/react-fontawesome";
import { faPen as Dt, faTrash as Ee, faPlus as Ie } from "@fortawesome/free-solid-svg-icons";
import './ManageEventConfiguration-BJxS2Su0.css';const Rt = Z(() => import("./ConditionConfig-GDCXIg3C-DuEy85LD.js")), Mt = Z(
  () => import("./MobileTypeEventConfigModal-ChhO_A4f-DfJDqFB9.js")
), qt = Z(
  () => import("./OtherTypeEventConfigModal-ZnCGWm9v-D7x0QObl.js")
);
function Kt() {
  var X, ee, te;
  const { translate: l } = Et(), ae = Ne(null), ne = Ne(!1), { id: O } = Ct(), ie = Tt(), [P, De] = u(null), [re, Re] = u(null), [le, Me] = u({}), [y, I] = u(
    []
  ), [oe, qe] = u(null), [H, Ae] = u(null), [Se, de] = u(null), [Oe, $e] = u(null), [D, $] = u(null), [Le, se] = u(null), [_e, ze] = u(null), [A, R] = u(null), [ce, ke] = u(!1), [ue, me] = u(!1), [fe, V] = u(!1), [z, M] = u([]), [Ue, k] = u(!1), [Be, Ye] = u([]), We = window.getComputedStyle(document.body).lineHeight, ge = () => ke(!ce), Fe = E.object().shape({
    name: E.string().required("Enter Name"),
    eventType: E.string().required("Select Event Type"),
    recursionInterval: E.number().typeError("Recursion Interval must be a number").when([], {
      is: () => m === "RECURSION",
      then: (e) => e.required("Recursion Interval is required").moreThan(0, "Recursion Interval must be greater than or equal to 1").lessThan(1441, "Recursion Interval must be less than or equal to 1440"),
      otherwise: (e) => e.notRequired()
    }),
    trigerWhen: E.string().test(
      "is-required",
      "trigerWhen is required",
      function(e) {
        return m === "TIMMER_BASED" ? !!e : !0;
      }
    ),
    day: E.string().test("is-required", "day is required", function(e) {
      return m === "TIMMER_BASED" && (f === "AFTER" || f === "MONTHLY") ? !!e : !0;
    }),
    hour: E.string().test(
      "is-required",
      "hour is required",
      function(e) {
        return m === "TIMMER_BASED" && (f === "AFTER" || f === "MONTHLY" || f === "DAILY") ? !!e : !0;
      }
    ),
    minute: E.string().notRequired()
    // notificationConfigDetails: Yup.array().of(
    //   Yup.object().shape({
    //     query: Yup.string().required('Query is required'), // Ensure query is present
    //     // condition: Yup.string().required('Condition is required'), // Ensure condition is present
    //     // action: Yup.string().required('Action is required'), // Ensure action is present
    //   })
    // ),
  }), {
    control: w,
    handleSubmit: Pe,
    setValue: U,
    setError: j,
    clearErrors: J,
    getValues: ve,
    watch: he,
    formState: { errors: s }
  } = Nt({
    defaultValues: {
      name: "",
      description: "",
      eventType: "",
      recursionInterval: 0,
      minute: 0
    },
    resolver: ut(Fe),
    mode: "onChange"
  }), m = he("eventType");
  let f = he("trigerWhen");
  Te(() => {
    let e = ae.current;
    return () => {
      Q("conversion_event", {
        form: e,
        form_name: "Manage Event Configuration",
        submit: ne.current
      });
    };
  }, []);
  const He = async (e) => {
    try {
      if (y.length > 0) {
        e.minute = Number(e.minute || 0), e.notificationConfigDetails = y;
        const a = m === "TIMMER_BASED", i = m === "FORM_SUBMITTED", n = m === "MANUAL", o = m === "RECURSION";
        a || (delete e.trigerWhen, delete e.day, delete e.hour, delete e.minute), i || delete e.formTypeId, !i && !n && (delete e.eventTypeDetailCode, delete e.eventTypeDetailId), o ? (delete e.formTypeId, e.trigerWhen = "RECURSION") : delete e.recursionInterval;
        const h = ["AFTER", "MONTHLY", "WEEKLY"], q = ["AFTER", "MONTHLY", "DAILY", "WEEKLY"];
        h.includes(f) || delete e.day, q.includes(f) || (delete e.day, delete e.hour), f === "IMMEDIATELY" && (delete e.day, delete e.hour, delete e.minute);
        const T = y.map((p) => {
          var c;
          return {
            ...p,
            conditions: (c = p.conditions) == null ? void 0 : c.map((b) => ({
              ...b,
              notificaitonConfigsType: b.notificaitonConfigsType ? b.notificaitonConfigsType.map((N) => ({
                ...N,
                queryCode: N.queryCode === "" ? null : N.queryCode
              })) : b.notificaitonConfigsType
            }))
          };
        });
        e.notificationConfigDetails = T, await dt(e), Q("button_click", {
          button_name: "manageeventconfiguration-save-button",
          button_type: "submit",
          button_id: "manageeventconfiguration-save-button"
        }), B({
          message: O ? "Event Configuration Updated successfully" : "submit successfully",
          type: "success"
        }), ne.current = !0, ie("/ui/medplat/notification/all");
      } else
        B({
          message: "Please add atleast query / condition for the configuration",
          type: "warn"
        });
    } catch {
      B({ message: "submit problem", type: "error" }), k((a) => !a);
    }
  };
  Te(() => {
    Ve();
  }, []);
  const Ve = async () => {
    var e, a, i, n;
    try {
      k((c) => !c);
      const o = await it({ is_active: !0 });
      De(o == null ? void 0 : o.data);
      const h = await rt();
      Re(h == null ? void 0 : h.data);
      const q = await st(!0);
      let T = {};
      (e = q == null ? void 0 : q.data) == null || e.forEach((c) => {
        T[c == null ? void 0 : c.id] = c == null ? void 0 : c.notificationName;
      }), Me(T);
      const { data: p } = await ct();
      if (Ye(p || []), O) {
        const c = await lt(O);
        (i = (a = c == null ? void 0 : c.data) == null ? void 0 : a.notificationConfigDetails) == null || i.forEach((N) => {
          pe(N);
        });
        let b = c == null ? void 0 : c.data;
        (n = Object.keys(b)) == null || n.forEach((N) => {
          b[N] !== void 0 && b[N] !== null && U(N, b[N]);
        }), I((b == null ? void 0 : b.notificationConfigDetails) || []);
      }
      k((c) => !c);
    } catch (o) {
      B({
        message: "Error in loading manage events",
        type: `Error:${o == null ? void 0 : o.message}`
      }), k((h) => !h);
    }
  }, pe = (e) => {
    e.implicitParam = ["#resourceId#"];
    const a = /\bFROM\b/gi, i = /\bSELECT\b/gi;
    if (e != null && e.query) {
      const n = (e.query.match(a) || []).length, o = (e.query.match(i) || []).length;
      let h;
      if (o > 0) {
        n > 1 && n === o ? h = e.query.substring(6, e.query.search(/\bfrom\b(?!(.|\n)*(from))/i)).match(/(\w*\(.*?\) as \w*|[^\(\),]+)(?=\s*,|\s*$)/g) : n !== o ? h = e.query.substring(6).match(/(\w*\(.*?\) as \w*|[^\(\),]+)(?=\s*,|\s*$)/gi) : n === 1 && n === o ? h = e.query.substring(6, e.query.toLowerCase().indexOf("from")).match(/(\w*\(.*?\) as \w*|[^\(\),]+)(?=\s*,|\s*$)/gi) : h = e.query.substring(6).match(/(\w*\(.*?\) as \w*|[^\(\),]+)(?=\s*,|\s*$)/gi);
        const q = h == null ? void 0 : h.filter(
          (T) => T.trim().length > 0
        );
        q == null || q.forEach((T) => {
          let p = T.trim();
          if (p.toLowerCase().indexOf("as") === 0 && (p = T), p.endsWith(";") && (p = p.slice(0, -1)), p !== "*") {
            const c = p.toLowerCase().lastIndexOf(" as ");
            if (c >= 0) {
              const b = p.substring(c + 4).trim();
              e.implicitParam.push("#" + b + "#");
            } else
              e.implicitParam.push("#" + p + "#");
          }
        });
      }
    }
  }, je = (e) => {
    const a = y == null ? void 0 : y.filter(
      (i, n) => n !== e
    );
    I(a);
  }, Je = (e, a) => {
    const i = [...y], n = i[e].conditions.filter((o, h) => h !== a);
    i[e].conditions = n, I(i);
  }, K = async (e, a, i, n) => {
    Ae(e), qe(a), i ? (de(i), se(!0), $(JSON.parse(JSON.stringify(i))), M((i == null ? void 0 : i.notificaitonConfigsType) || []), $e(n)) : (de({}), $({}), M([]), se(!1)), R({}), ge();
  }, Ke = (e, a) => {
    const i = [...y];
    i[e].query = a, I(i);
  }, Qe = async () => {
    let e = [...y], a = !0;
    y.forEach((i, n) => {
      if (i.query === "") {
        a = !1;
        const o = `notificationConfigDetails.${n}.query`;
        j(o, { type: "manual", message: "Query Required" });
      }
    }), a && (e.push({ query: "", conditions: [], queryParam: null }), I(e));
  }, ye = async (e, a) => {
    e ? (e.index = a, ze(e), R({
      ...JSON.parse(JSON.stringify(e)),
      implicitParam: H.implicitParam
    }), me(!0)) : (R({ ...A, implicitParam: H.implicitParam }), me(!1)), Ge();
  }, Ge = () => {
    V((e) => !e);
  }, be = (e) => {
    if (ue) {
      const a = z.map((i, n) => n === e.index ? { ...i, ...e } : i);
      M(a);
    } else
      M([...z, e]);
    et(e);
  }, Ze = (e) => {
    M(
      (a) => a.filter((i, n) => n !== e)
    );
  }, Xe = (e) => {
    ye(z[e], e);
  }, et = (e) => {
    let a = { ...D };
    D.notificaitonConfigsType || (a.notificaitonConfigsType = []), ue ? a.notificaitonConfigsType[_e.index] = e : a.notificaitonConfigsType.push(e), $(a), R({});
  }, Q = It(), tt = (e) => {
    if (Le) {
      const a = [...y];
      $({ ...D, ...e });
      let i = { ...D, ...e };
      a[oe].conditions[Oe] = i, I(a), M([]);
    } else {
      const a = [...y];
      $({ ...D, ...e });
      let i = { ...D, ...e };
      a[oe].conditions.push(i), I(a), M([]);
    }
  }, at = (e) => {
    R({ ...A, ...e });
  };
  return /* @__PURE__ */ r(nt, { children: [
    /* @__PURE__ */ t(ot, { isLoading: Ue, children: /* @__PURE__ */ r(
      ft,
      {
        className: "manage-eventConfiguration-type-body",
        component: "form",
        ref: ae,
        onSubmit: Pe(He),
        "data-testid": "manageeventconfiguration-form",
        children: [
          /* @__PURE__ */ t(
            gt,
            {
              className: "p-2.5 px-5 flex border-b text-customBlue",
              subheader: l(
                `${O ? "UPDATE" : "ADD"} EVENT CONFIGURATION`
              ),
              slotProps: {
                subheader: { className: "font-medium text-lg  text-customBlue" }
              },
              "data-testid": "manageeventconfiguration-cardheader-subheader"
            }
          ),
          /* @__PURE__ */ r(vt, { "data-testid": "manageeventconfiguration-cardcontent", children: [
            /* @__PURE__ */ r(g, { container: !0, spacing: 2, children: [
              /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-name-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ r(d, { variant: "body2", children: [
                      l("Name"),
                      /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" })
                    ] }),
                    /* @__PURE__ */ t(C, { className: "w-full", children: /* @__PURE__ */ t(
                      L,
                      {
                        control: w,
                        id: "name",
                        name: "name",
                        errors: s,
                        label: "",
                        size: "small",
                        dataTestId: "manageeventconfiguration-name-textfield"
                      }
                    ) })
                  ] })
                }
              ),
              /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-description-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ t(d, { variant: "body2", children: l("Description") }),
                    /* @__PURE__ */ t(C, { className: "w-full", children: /* @__PURE__ */ t(
                      we,
                      {
                        control: w,
                        id: "description",
                        name: "description",
                        errors: s,
                        label: "",
                        minRows: 2,
                        "data-testid": "manageeventconfiguration-description-textarea"
                      }
                    ) })
                  ] })
                }
              ),
              /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-eventtype-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ r(d, { variant: "body2", children: [
                      l("Event Type"),
                      /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" })
                    ] }),
                    /* @__PURE__ */ r(C, { className: "w-full", children: [
                      /* @__PURE__ */ t(
                        F,
                        {
                          name: "eventType",
                          control: w,
                          defaultValue: "",
                          className: "w-full",
                          render: ({ field: e }) => /* @__PURE__ */ r(
                            Y,
                            {
                              className: "w-full",
                              labelId: "event-type-label",
                              id: "reportgroup",
                              ...e,
                              error: s.eventType,
                              size: "small",
                              "data-testid": "manageeventconfiguration-eventtype-select",
                              children: [
                                /* @__PURE__ */ t(v, { value: "FORM_SUBMITTED", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Form Submitted") }) }),
                                /* @__PURE__ */ t(v, { value: "TIMMER_BASED", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Timer Based") }) }),
                                /* @__PURE__ */ t(v, { value: "MANUAL", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Manual") }) }),
                                /* @__PURE__ */ t(v, { value: "RECURSION", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Recursion") }) })
                              ]
                            }
                          )
                        }
                      ),
                      (s == null ? void 0 : s.eventType) && /* @__PURE__ */ t(
                        "p",
                        {
                          className: "error-helper-manage-event",
                          "data-testid": "custom-error-message",
                          children: (X = s == null ? void 0 : s.eventType) == null ? void 0 : X.message
                        }
                      )
                    ] })
                  ] })
                }
              ),
              m === "FORM_SUBMITTED" && /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-formtype-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ t(d, { variant: "body2", children: l("Form Type") }),
                    /* @__PURE__ */ t(C, { className: "w-full", children: /* @__PURE__ */ t(
                      F,
                      {
                        className: "w-full",
                        name: "formTypeId",
                        control: w,
                        defaultValue: "",
                        render: ({ field: e }) => /* @__PURE__ */ r(
                          Y,
                          {
                            ...e,
                            className: "w-full",
                            labelId: "event-type-label",
                            displayEmpty: !0,
                            size: "small",
                            onChange: (a) => {
                              const i = a.target.value;
                              e.onChange(i);
                              const n = P.find(
                                (o) => o.id === i
                              );
                              U(
                                "eventTypeDetailCode",
                                n == null ? void 0 : n.code
                              ), U(
                                "eventTypeDetailId",
                                (n == null ? void 0 : n.detaiId) || null
                              );
                            },
                            "data-testid": "manageeventconfiguration-formtype-select",
                            children: [
                              /* @__PURE__ */ t(v, { value: "", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Select") }) }),
                              P == null ? void 0 : P.map((a) => /* @__PURE__ */ t(v, { value: a.id, children: /* @__PURE__ */ t(d, { variant: "body2", children: l(a.name) }) }, a.id))
                            ]
                          }
                        )
                      }
                    ) })
                  ] })
                }
              ),
              m === "TIMMER_BASED" && /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-triggerwhen-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ r(d, { variant: "body2", children: [
                      l("Trigger When"),
                      /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" })
                    ] }),
                    /* @__PURE__ */ r(C, { className: "w-full", children: [
                      /* @__PURE__ */ t(
                        F,
                        {
                          name: "trigerWhen",
                          control: w,
                          defaultValue: "",
                          className: "w-full",
                          render: ({ field: e }) => /* @__PURE__ */ r(
                            Y,
                            {
                              className: "w-full",
                              ...e,
                              value: e.value,
                              error: s.trigerWhen,
                              size: "small",
                              "data-testid": "manageeventconfiguration-triggerwhen-select",
                              children: [
                                /* @__PURE__ */ t(v, { value: "", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Select") }) }),
                                /* @__PURE__ */ t(v, { value: "IMMEDIATELY", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Immediately") }) }),
                                /* @__PURE__ */ t(v, { value: "AFTER", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("After") }) }),
                                /* @__PURE__ */ t(v, { value: "MONTHLY", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Monthly") }) }),
                                /* @__PURE__ */ t(v, { value: "WEEKLY", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Weekly") }) }),
                                /* @__PURE__ */ t(v, { value: "DAILY", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Daily") }) }),
                                /* @__PURE__ */ t(v, { value: "HOURLY", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Hourly") }) }),
                                /* @__PURE__ */ t(v, { value: "MINUTE", children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Minutely") }) })
                              ]
                            }
                          )
                        }
                      ),
                      (s == null ? void 0 : s.trigerWhen) && /* @__PURE__ */ t(
                        "p",
                        {
                          className: "error-helper-manage-event",
                          "data-testid": "custom-error-message",
                          children: (ee = s == null ? void 0 : s.trigerWhen) == null ? void 0 : ee.message
                        }
                      )
                    ] })
                  ] })
                }
              ),
              m === "TIMMER_BASED" && (f === "AFTER" || f === "MONTHLY" || f === "WEEKLY") && /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-day-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ r(d, { variant: "body2", children: [
                      l("day"),
                      /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" })
                    ] }),
                    /* @__PURE__ */ t(
                      L,
                      {
                        control: w,
                        id: "day",
                        name: "day",
                        errors: s,
                        type: "number",
                        label: "",
                        size: "small",
                        dataTestId: "manageeventconfiguration-day-textfield"
                      }
                    )
                  ] })
                }
              ),
              m === "TIMMER_BASED" && (f === "AFTER" || f === "MONTHLY" || f === "DAILY" || f === "WEEKLY") && /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-hour-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ r(d, { variant: "body2", children: [
                      l("Hour"),
                      /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" })
                    ] }),
                    /* @__PURE__ */ t(
                      L,
                      {
                        control: w,
                        id: "hour",
                        name: "hour",
                        type: "number",
                        errors: s,
                        label: "",
                        size: "small",
                        dataTestId: "manageeventconfiguration-hour-textfield"
                      }
                    )
                  ] })
                }
              ),
              m === "TIMMER_BASED" && f && f !== "IMMEDIATELY" && /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-minute-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ t(d, { variant: "body2", children: l("Minute") }),
                    /* @__PURE__ */ t(
                      L,
                      {
                        control: w,
                        id: "minute",
                        name: "minute",
                        errors: s,
                        type: "number",
                        label: "",
                        size: "small",
                        dataTestId: "manageeventconfiguration-minute-textfield"
                      }
                    )
                  ] })
                }
              ),
              m === "RECURSION" && /* @__PURE__ */ t(g, { item: !0, size: { xs: 12, sm: 6 }, children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                /* @__PURE__ */ r(d, { variant: "body2", children: [
                  l("Recursion Interval (in Minutes)"),
                  /* @__PURE__ */ t("span", { className: "text-red-500 ml-1", children: "*" })
                ] }),
                /* @__PURE__ */ t(C, { className: "w-full", children: /* @__PURE__ */ t(
                  L,
                  {
                    type: "number",
                    control: w,
                    id: "recursionInterval",
                    name: "recursionInterval",
                    errors: s,
                    label: "",
                    size: "small",
                    dataTestId: "manageeventconfiguration-recursionInterval-textfield"
                  }
                ) })
              ] }) }),
              (m === "TIMMER_BASED" || m === "RECURSION") && /* @__PURE__ */ t(g, { item: !0, size: { xs: 12, sm: 6 }, children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                /* @__PURE__ */ t(d, { variant: "body2", children: l("Reports") }),
                /* @__PURE__ */ t(C, { className: "w-full", children: /* @__PURE__ */ t(
                  mt,
                  {
                    id: "reportUUID",
                    name: "reportUUID",
                    displayName: "name",
                    optionValue: "uuid",
                    multiple: !0,
                    control: w,
                    options: Be
                  }
                ) })
              ] }) }),
              m === "MANUAL" && /* @__PURE__ */ t(
                g,
                {
                  item: !0,
                  size: { xs: 12, sm: 6 },
                  "data-testid": "manageeventconfiguration-event-field",
                  children: /* @__PURE__ */ r(x, { variant: "outlined", className: "w-full", children: [
                    /* @__PURE__ */ t(d, { variant: "body2", children: l("Event") }),
                    /* @__PURE__ */ r(C, { className: "w-full", children: [
                      /* @__PURE__ */ t(
                        F,
                        {
                          name: "eventTypeDetailCode",
                          control: w,
                          className: "w-full",
                          render: ({ field: e }) => /* @__PURE__ */ r(
                            Y,
                            {
                              className: "w-full",
                              ...e,
                              value: e.value,
                              error: s.eventTypeDetailCode,
                              size: "small",
                              "data-testid": "manageeventconfiguration-eventtype-detail-select",
                              children: [
                                /* @__PURE__ */ t(v, { value: "", children: l("None") }),
                                re && Object.entries(re).map(([a, i]) => /* @__PURE__ */ t(v, { value: a, children: i }, a))
                              ]
                            }
                          )
                        }
                      ),
                      (s == null ? void 0 : s.eventTypeDetailCode) && /* @__PURE__ */ t(
                        "p",
                        {
                          className: "error-helper-manage-event",
                          "data-testid": "manageeventconfiguration-eventtype-detail-error",
                          children: (te = s == null ? void 0 : s.eventTypeDetailCode) == null ? void 0 : te.message
                        }
                      )
                    ] })
                  ] })
                }
              )
            ] }),
            /* @__PURE__ */ t(G, { className: "m-[20px_3px]" }),
            /* @__PURE__ */ r(
              g,
              {
                container: !0,
                spacing: 5,
                justifyContent: "space-between",
                alignItems: "center",
                "data-testid": "manageeventconfiguration-add-configuration",
                children: [
                  /* @__PURE__ */ t(g, { item: !0, children: /* @__PURE__ */ t(d, { variant: "body2", children: l("Add Configuration") }) }),
                  /* @__PURE__ */ t(g, { item: !0, children: /* @__PURE__ */ t(
                    W,
                    {
                      size: "small",
                      variant: "contained",
                      onClick: Qe,
                      "data-testid": "manageeventconfiguration-add-button",
                      children: l("Add")
                    }
                  ) })
                ]
              }
            ),
            /* @__PURE__ */ t(g, { container: !0, className: "w-full mt-5", children: /* @__PURE__ */ t(g, { item: !0, className: "w-full", children: /* @__PURE__ */ t(
              ht,
              {
                component: pt,
                className: "w-full",
                "data-testid": "manageeventconfiguration-table-container",
                children: /* @__PURE__ */ r(yt, { sx: { minWidth: 800 }, children: [
                  /* @__PURE__ */ t(bt, { children: /* @__PURE__ */ r(
                    xe,
                    {
                      sx: {
                        backgroundColor: (e) => e.palette.mode === "dark" ? e.palette.custom.tableHeader : "#f5f5f5"
                      },
                      children: [
                        /* @__PURE__ */ t(
                          S,
                          {
                            className: "border border-gray-300 align-top text-[13px]",
                            "data-testid": "manageeventconfiguration-table-header-query",
                            children: l("Query")
                          }
                        ),
                        /* @__PURE__ */ t(
                          S,
                          {
                            className: "border border-gray-300 align-top text-[13px]",
                            "data-testid": "manageeventconfiguration-table-header-condition",
                            children: l("Condition")
                          }
                        ),
                        /* @__PURE__ */ t(
                          S,
                          {
                            className: "border border-gray-300 align-top text-[13px]",
                            "data-testid": "manageeventconfiguration-table-header-action",
                            children: l("Actions")
                          }
                        )
                      ]
                    }
                  ) }),
                  /* @__PURE__ */ t(wt, { children: y == null ? void 0 : y.map((e, a) => {
                    var i;
                    return /* @__PURE__ */ r(
                      xe,
                      {
                        sx: {
                          backgroundColor: (n) => {
                            const o = n.palette.mode === "dark";
                            return a % 2 === 0 ? o ? n.palette.background.paper : "#fff" : o ? "#1C2128" : "#f9f9f9";
                          },
                          // Adding a hover state that works in both modes
                          "&:hover": {
                            backgroundColor: (n) => n.palette.mode === "dark" ? "#21262D" : "#f0f0f0"
                          }
                        },
                        "data-testid": `manageeventconfiguration-table-row-${a}`,
                        children: [
                          /* @__PURE__ */ t(
                            S,
                            {
                              className: "border border-gray-300 align-top",
                              style: { lineHeight: We },
                              "data-testid": `manageeventconfiguration-table-row-${a}-query`,
                              children: /* @__PURE__ */ r("div", { className: "flex flex-col items-start min-w-[300px]", children: [
                                /* @__PURE__ */ t(
                                  x,
                                  {
                                    variant: "outlined",
                                    className: "w-full",
                                    children: /* @__PURE__ */ t(C, { className: "w-full", children: /* @__PURE__ */ t(
                                      we,
                                      {
                                        required: !0,
                                        control: w,
                                        id: `notificationConfigDetails.${a}.query`,
                                        name: `notificationConfigDetails.${a}.query`,
                                        errors: s,
                                        value: e.query,
                                        onChange: (n) => {
                                          U(
                                            `notificationConfigDetails.${a}.query`,
                                            n.target.value
                                          ), Ke(a, n.target.value);
                                          const o = `notificationConfigDetails.${a}.query`;
                                          ve(o) === "" ? j(o, {
                                            type: "manual",
                                            message: "Query Required"
                                          }) : J(o);
                                        },
                                        onBlur: () => {
                                          const n = `notificationConfigDetails.${a}.query`;
                                          ve(n) === "" ? j(n, {
                                            type: "manual",
                                            message: "Query Required"
                                          }) : J(n), pe(e);
                                        },
                                        label: "",
                                        minRows: 5,
                                        maxRows: 20,
                                        "data-testid": `manageeventconfiguration-table-row-${a}-query-textarea`
                                      }
                                    ) })
                                  }
                                ),
                                /* @__PURE__ */ t(
                                  "td",
                                  {
                                    style: {
                                      whiteSpace: "normal",
                                      width: "100%",
                                      overflowWrap: "break-word"
                                    },
                                    children: /* @__PURE__ */ t("b", { children: e == null ? void 0 : e.implicitParam })
                                  }
                                )
                              ] })
                            }
                          ),
                          /* @__PURE__ */ t(
                            S,
                            {
                              className: "border border-gray-300 align-top",
                              "data-testid": `manageeventconfiguration-table-row-${a}-condition`,
                              children: /* @__PURE__ */ t(
                                "div",
                                {
                                  style: {
                                    display: "flex",
                                    flexDirection: "column",
                                    alignItems: "flex-start",
                                    width: "100%"
                                  },
                                  children: ((i = e == null ? void 0 : e.conditions) == null ? void 0 : i.length) > 0 ? e == null ? void 0 : e.conditions.map(
                                    (n, o) => /* @__PURE__ */ r(
                                      "div",
                                      {
                                        style: { width: "100%" },
                                        children: [
                                          /* @__PURE__ */ r(
                                            "div",
                                            {
                                              style: {
                                                display: "flex",
                                                alignItems: "center",
                                                width: "100%"
                                              },
                                              "data-testid": "manageeventconfiguration-condition-rows",
                                              children: [
                                                /* @__PURE__ */ t(
                                                  d,
                                                  {
                                                    className: "mr-1",
                                                    variant: "body2",
                                                    children: (n == null ? void 0 : n.condition) || "No condition specified"
                                                  }
                                                ),
                                                /* @__PURE__ */ t(
                                                  _,
                                                  {
                                                    className: "bg-[#cecfd0] text-gray-600 rounded-full p-[10px] w-[14px] h-[14px] mx-1 cursor-pointer hover:bg-gray-300 hover:text-[#11B666] transition-all",
                                                    icon: Dt,
                                                    onClick: () => K(
                                                      e,
                                                      a,
                                                      n,
                                                      o
                                                    ),
                                                    "data-testid": `manageeventconfiguration-table-row-${a}-condition-edit-${o}`
                                                  }
                                                ),
                                                /* @__PURE__ */ t(
                                                  _,
                                                  {
                                                    icon: Ee,
                                                    className: "bg-[#cecfd0] text-gray-600 rounded-full p-[10px] w-[14px] h-[14px] mx-1 cursor-pointer hover:bg-gray-300 hover:text-[var(--color-error)] transition-all",
                                                    onClick: () => Je(
                                                      a,
                                                      o
                                                    ),
                                                    "data-testid": `manageeventconfiguration-table-row-${a}-condition-delete-${o}`
                                                  }
                                                ),
                                                o === (e == null ? void 0 : e.conditions.length) - 1 && /* @__PURE__ */ t(
                                                  _,
                                                  {
                                                    icon: Ie,
                                                    onClick: () => K(e, a),
                                                    className: "bg-[#cecfd0] text-gray-600 rounded-full p-[10px] w-[14px] h-[14px] mx-1 cursor-pointer hover:bg-gray-300 hover:text-[var(--color-primary)] transition-all",
                                                    "data-testid": `manageeventconfiguration-table-row-${a}-condition-add`
                                                  }
                                                )
                                              ]
                                            }
                                          ),
                                          o < (e == null ? void 0 : e.conditions.length) - 1 && /* @__PURE__ */ t(G, { className: "w-full m-[10px_0px]" })
                                        ]
                                      },
                                      o + 1
                                    )
                                  ) : /* @__PURE__ */ r(
                                    "div",
                                    {
                                      className: "flex flex-row items-center justify-between w-full mt-2 sm:mt-0 text-[14px]",
                                      children: [
                                        /* @__PURE__ */ t("span", { className: "mr-3 flex-1", children: l("No Condition Added") }),
                                        /* @__PURE__ */ t("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ t(
                                          _,
                                          {
                                            icon: Ie,
                                            onClick: () => K(e, a),
                                            className: "bg-gray-200 text-gray-600 rounded-full p-2 w-[16px] h-[16px] cursor-pointer hover:bg-gray-300 hover:text-[var(--color-primary)] transition-all",
                                            "data-testid": `manageeventconfiguration-table-row-${a}-condition-add-empty`
                                          }
                                        ) })
                                      ]
                                    }
                                  )
                                }
                              )
                            }
                          ),
                          /* @__PURE__ */ t(
                            S,
                            {
                              className: "border border-gray-300 align-top",
                              "data-testid": `manageeventconfiguration-table-row-${a}-action`,
                              children: /* @__PURE__ */ t(
                                "div",
                                {
                                  style: {
                                    display: "flex",
                                    flexDirection: "column",
                                    alignItems: "flex-start"
                                  },
                                  children: /* @__PURE__ */ t(
                                    W,
                                    {
                                      onClick: () => {
                                        je(a);
                                        const n = `notificationConfigDetails.${a}.query`;
                                        J(n);
                                      },
                                      size: "small",
                                      "aria-label": "delete",
                                      "data-testid": `manageeventconfiguration-table-row-${a}-action-delete`,
                                      children: /* @__PURE__ */ t(
                                        _,
                                        {
                                          icon: Ee,
                                          className: "text-[19px] text-[var(--color-error)]"
                                        }
                                      )
                                    }
                                  )
                                }
                              )
                            }
                          )
                        ]
                      },
                      a + 1
                    );
                  }) })
                ] })
              }
            ) }) })
          ] }),
          /* @__PURE__ */ t(G, { className: "m-[8px_0px]" }),
          /* @__PURE__ */ r(
            xt,
            {
              className: "flex flex-col sm:flex-row justify-end gap-2",
              "data-testid": "manageeventconfiguration-cardactions",
              children: [
                /* @__PURE__ */ t(
                  W,
                  {
                    variant: "contained",
                    color: "secondary",
                    type: "button",
                    size: "small",
                    className: "w-full sm:w-auto",
                    onClick: () => {
                      Q("button_click", {
                        button_name: "manageeventconfiguration-back-button",
                        button_type: "cancel",
                        button_id: "manageeventconfiguration-back-button"
                      }), ie("/ui/medplat/notification/all");
                    },
                    "data-testid": "manageeventconfiguration-back-button",
                    children: l("Cancel")
                  }
                ),
                /* @__PURE__ */ t(
                  W,
                  {
                    size: "small",
                    variant: "contained",
                    type: "submit",
                    color: "primary",
                    className: "w-full sm:w-auto m-0",
                    "data-testid": "manageeventconfiguration-save-button",
                    children: l(`${O ? "Update" : "Save"}`)
                  }
                )
              ]
            }
          )
        ]
      }
    ) }),
    /* @__PURE__ */ t(Ce, { children: /* @__PURE__ */ t(
      Rt,
      {
        selectedConfig: H,
        notificationtypeMap: le,
        selectedCondition: Se,
        newCondition: D,
        handleTypeConfigurationDelete: Ze,
        handleTypeConfigurationEdit: Xe,
        addTypeConfig: ye,
        setNewConditionData: tt,
        typeConfigurationData: z,
        setNewTypeData: at,
        overlayOpen: ce,
        handleOverlayState: ge,
        "data-testid": "manageeventconfiguration-conditionconfig"
      }
    ) }),
    /* @__PURE__ */ t(Ce, { children: (A == null ? void 0 : A.type) === "MOBILE" ? /* @__PURE__ */ t(
      Mt,
      {
        type: A,
        open: fe,
        notificationtypeMap: le,
        handleClick: be,
        handleClose: () => {
          V((e) => !e), R({});
        },
        "data-testid": "manageeventconfiguration-mobiletypeeventconfigmodal"
      }
    ) : /* @__PURE__ */ t(
      qt,
      {
        type: A,
        open: fe,
        handleClick: be,
        handleClose: () => {
          V((e) => !e), R({});
        },
        "data-testid": "manageeventconfiguration-othertypeeventconfigmodal"
      }
    ) })
  ] });
}
export {
  Kt as default
};
//# sourceMappingURL=ManageEventConfiguration-BJxS2Su0-CRATBMym.js.map
