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