import { jsx as e, jsxs as r, Fragment as Ge } from "react/jsx-runtime";
import { useState as N, useEffect as ue, Suspense as We, lazy as Qe } from "react";
import { Card as Ye, CardHeader as Q, Box as w, Typography as m, CardContent as He, FormControl as pe, Select as fe, MenuItem as V, Chip as q, Button as j, Divider as Y, Tooltip as Ze, IconButton as Ke, Autocomplete as Xe, TextField as ea } from "@mui/material";
import { showToast as M } from "@/common/toaster/toaster";
import { execute as O } from "@/common/services/GlobalApis";
import u from "@mui/material/Grid2";
import { useParams as aa, useNavigate as la } from "react-router";
import { useForm as ra, useFieldArray as ve, FormProvider as ia, Controller as H, get as E } from "react-hook-form";
import na from "@/views/custom-components/CustomCheckBox";
import { yupResolver as ta } from "@hookform/resolvers/yup";
import { useTranslateProvider as sa } from "@/common/languageTranslator/TranslationContext";
import oa from "@/views/custom-components/CustomAutoComplete";
import * as v from "yup";
import _ from "@/views/custom-components/CustomTextField";
import { f as da, l as ca } from "./ImmunizationSkeleton-D2tdv5k--B7SY-gnr.js";
import { faTrash as he, faInfoCircle as ma } from "@fortawesome/free-solid-svg-icons";
import { useSelector as ua } from "react-redux";
import { validateAOI as pa } from "@/common/services/Users";
import { FontAwesomeIcon as Z } from "@fortawesome/react-fontawesome";
import './manageImmunization-B4swS745.css';const fa = Qe(
  () => import("@/views/feature-components/LocationDirective/LocationDirectiveV2")
), $a = () => {
  var K;
  const { id: S } = aa(), { translate: s } = sa(), { user: X } = ua((a) => a.Authenticate), B = la(), { t: be } = da(), [R, ge] = N("days"), [ee, ye] = N([]), [F, xe] = N("days"), [L, Ne] = N("days"), [we, _e] = N("Add Immunization"), [Ce, ke] = N([]), ze = s("Requirement"), qe = s("Min Gap (In Days)"), Ie = s("Max Gap  (In Days)"), De = s("Message"), [Se, Re] = N([]), Ae = s("Select Vaccines"), [A, ae] = N({});
  let $e = 10;
  const [I, P] = N([]), [le, U] = N(!1), [re, Oe] = N([]), C = (a, l) => {
    const n = je();
    if (l === "fromDate") {
      const o = n == null ? void 0 : n.fromDate, d = JSON.parse(JSON.stringify(R)), p = k(o, d, a);
      g("fromDate", parseFloat(p.toFixed(1))), ge(a);
    }
    if (l === "toDate") {
      const o = n == null ? void 0 : n.toDate, d = JSON.parse(JSON.stringify(F)), p = k(o, d, a);
      g("toDate", parseFloat(p.toFixed(2))), xe(a);
    }
    if (l === "gapRange") {
      const o = n == null ? void 0 : n.gapRange, d = JSON.parse(JSON.stringify(L)), p = k(o, d, a);
      g("gapRange", parseFloat(p.toFixed(2))), Ne(a);
    }
  }, k = (a, l, n) => {
    if (!a)
      return 0;
    let o;
    switch (l) {
      case "months":
        o = a * 30;
        break;
      case "years":
        o = a * 365;
        break;
      default:
        o = Math.round(a);
    }
    let d;
    switch (n) {
      case "months":
        d = o / 30;
        break;
      case "years":
        d = o / 365;
        break;
      default:
        d = Math.round(o);
    }
    return d;
  }, Fe = async (a) => {
    var l, n, o;
    try {
      const d = {
        dependencies: ((l = a == null ? void 0 : a.dependencies) == null ? void 0 : l.map(
          ({ min_gap_days: y, max_gap_days: z, required: b, vaccine: i, ...$ }) => ({
            ...$,
            vaccine: i.map((D) => D.code),
            ...b !== "false" && { min_gap_days: y, max_gap_days: z },
            required: b
          })
        )) || []
      }, p = (a.filters || []).map((y) => ({
        filterName: y.filterName,
        queryCode: y.queryCode
      })), c = {
        ...(a == null ? void 0 : a.isRecursive) && {
          gapRange: a == null ? void 0 : a.gapRange,
          maxDoses: a.maxDoses
        }
      }, t = {
        code: a == null ? void 0 : a.code,
        name: a == null ? void 0 : a.name,
        isrecursive: a == null ? void 0 : a.isRecursive,
        fromAgeDays: parseInt(
          k(a == null ? void 0 : a.fromDate, R, "days")
        ),
        toAgeDays: parseInt(k(a == null ? void 0 : a.toDate, F, "days")),
        validations: JSON.stringify(d),
        filters: JSON.stringify(p),
        basedate: a == null ? void 0 : a.basedate,
        recursiveobject: JSON.stringify(c),
        locations: I ? JSON.stringify(I) : null,
        active: !0
      };
      S ? (await O({
        code: "update_immunization",
        parameters: { ...t, id: parseInt(S) }
      }), M({
        message: "Immunization Updated Successfully!",
        type: "success"
      }), B(-1)) : ((o = (n = (await O({
        code: "check_existing_code",
        parameters: { code: a == null ? void 0 : a.code }
      })).data) == null ? void 0 : n.result) == null ? void 0 : o.length) > 0 ? M({ message: "Code Already Exist", type: "error" }) : (await O({ code: "add_immunization", parameters: t }), M({
        message: "Immunization Added Successfully",
        type: "success"
      }), B(-1));
    } catch (d) {
      console.error(d), M({ message: "Error in adding Immunization", type: "error" });
    }
  }, Le = v.object().shape({
    code: v.string().required("Code is required"),
    // Code is required
    name: v.string().required("Name is required"),
    // Name is required
    basedate: v.string().required("Base date (name) is required"),
    // Basedate is required
    fromDate: v.number().transform(
      (a, l) => l === "" ? void 0 : a
    ).nullable().min(0, "From date must be 0 or a positive number"),
    toDate: v.number().transform(
      (a, l) => l === "" ? void 0 : a
    ).nullable().min(0, "To date must be 0 or a positive number").when("fromDate", (a, l) => l.test(
      "check-to-date",
      "To date must be greater than From date",
      (n) => n === 0 ? !0 : !(k(a, R, "days") !== void 0 && a > 0 && k(n, F, "days") <= k(a, R, "days"))
    )),
    gapRange: v.number().transform(
      (a, l) => l === "" ? void 0 : a
    ).nullable().min(0, "Must be 0 or a positive number").test(
      "is-less-than-6-months",
      "Gap range must be less than 6 months",
      function(a) {
        return a == null ? !0 : k(a, L, "days") < 182;
      }
    ),
    maxDoses: v.number().transform(
      (a, l) => l === "" ? void 0 : a
    ).nullable().min(0, "Must be 0 or a positive number"),
    dependencies: v.array().of(
      v.object().shape({
        vaccine: v.array().min(1, "At least one vaccine is required").required("Vaccine is required"),
        required: v.string().required("Please Select a vaccine"),
        min_gap_days: v.number().min(0, "No negative number").transform(
          (a, l) => l === "" ? void 0 : a
        ).nullable(),
        max_gap_days: v.number().min(0, "No negative number").transform(
          (a, l) => l === "" ? void 0 : a
        ).nullable().when("min_gap_days", (a, l) => l.test(
          "check-to-date",
          "Max days must be greater",
          (n) => n === 0 ? !0 : !(a > 0 && n <= a)
        )),
        message: v.string().nullable()
      })
    ),
    filters: v.array().of(
      v.object().shape({
        filterName: v.string().required("Filter name is required"),
        queryCode: v.string().required("Please select a query")
      })
    )
  }), ie = ra({
    defaultValues: {
      code: "",
      name: "",
      basedate: "",
      fromDate: 0,
      toDate: 0,
      isRecursive: !1,
      gapRange: 0,
      maxDoses: 0,
      dependencies: [],
      filters: []
    },
    resolver: ta(Le),
    mode: "onChange"
  }), {
    control: h,
    handleSubmit: Te,
    setValue: g,
    getValues: je,
    clearErrors: Me,
    watch: G,
    formState: { errors: f }
  } = ie, { fields: ne, append: te, remove: Ee } = ve({
    control: h,
    name: "dependencies"
  }), {
    fields: se,
    append: oe,
    remove: Je
  } = ve({
    control: h,
    name: "filters"
  }), T = G("dependencies"), W = G("isRecursive"), de = G("name");
  ue(() => {
    if (!S) {
      const a = de.replace(/\s+/g, "_").toUpperCase();
      g("code", a);
    }
  }, [de, S]), ue(() => {
    Ve();
  }, []);
  const Ve = async () => {
    var a, l, n, o, d;
    try {
      U((b) => !b);
      const p = await O({
        code: "imt_member_date_column"
      });
      ye((a = p == null ? void 0 : p.data) == null ? void 0 : a.result);
      const c = await O({
        code: "get_code_immunization",
        parameters: {}
      });
      let t = (l = c == null ? void 0 : c.data) == null ? void 0 : l.result;
      ke(t);
      const y = await O({
        code: "GET_MANAGE_IMMUNIZATION_FILTER_QUERIES",
        parameters: {}
      }), z = Object.values(
        (((n = y == null ? void 0 : y.data) == null ? void 0 : n.result) || []).reduce((b, i) => (b[i.queryCode] = i, b), {})
      );
      if (Oe(z), S) {
        _e("Edit Immunization");
        const b = await O({
          code: "get_immunization_by_id",
          parameters: {
            id: parseInt(S)
          }
        }), i = (o = b == null ? void 0 : b.data) == null ? void 0 : o.result[0];
        if (g("code", i == null ? void 0 : i.code), g("name", i == null ? void 0 : i.name), g("basedate", i == null ? void 0 : i.base_date), g("fromDate", i == null ? void 0 : i.from_age_days), g("toDate", i == null ? void 0 : i.to_age_days), g("isRecursive", i == null ? void 0 : i.is_recursive), P(i != null && i.locations ? JSON.parse(i == null ? void 0 : i.locations) : []), i.is_recursive) {
          const x = JSON.parse(i == null ? void 0 : i.recursive_object);
          g("gapRange", x == null ? void 0 : x.gapRange), g("maxDoses", x == null ? void 0 : x.maxDoses);
        }
        const $ = JSON.parse(i == null ? void 0 : i.validations);
        $ && ((d = $ == null ? void 0 : $.dependencies) == null || d.forEach((x) => {
          const J = ((x == null ? void 0 : x.vaccine) || []).map((ce) => {
            const me = t.find((Ue) => Ue.code === ce);
            return {
              code: ce,
              name: (me == null ? void 0 : me.name) || "Unknown"
              // Fallback to 'Unknown' if no match is found
            };
          });
          x.vaccine = J, te(x);
        }));
        const D = i != null && i.filters ? JSON.parse(i.filters) : [];
        D && D.length > 0 && D.forEach((x) => {
          oe({
            filterName: x.filterName || "",
            queryCode: x.queryCode || ""
          });
        });
      }
      U((b) => !b);
    } catch (p) {
      console.error(p), U((c) => !c);
    }
  }, Be = async () => {
    var a, l, n, o, d;
    try {
      const p = (l = (a = A == null ? void 0 : A.finalSelected) == null ? void 0 : a.optionSelected) == null ? void 0 : l.id, c = A.finalSelected.level, { id: t } = A.finalSelected.optionSelected;
      let y = !1, z = [], b = {
        ids: I.map((i) => i.locationId),
        idArr: I.map((i) => i.locationIdArr)
      };
      for (let i = 1; i <= c; i++)
        (o = b.ids) != null && o.includes(
          (n = A[`level${i}`]) == null ? void 0 : n.id
        ) ? y = !0 : z.push((d = A[`level${i}`]) == null ? void 0 : d.id);
      if (y)
        M({
          message: "Please select different parent location!",
          type: "info"
        });
      else {
        const { data: i } = await pa({
          roleId: X == null ? void 0 : X.roleId,
          toBeAdded: t
        });
        P(($) => {
          var D;
          return [
            ...$.filter(
              (x) => {
                var J;
                return !((J = x.locationIdArr) != null && J.includes(p));
              }
            ),
            {
              locationId: p,
              locationIdArr: z,
              locationList: (D = i == null ? void 0 : i.message) == null ? void 0 : D.replaceAll(",", " => ")
            }
          ];
        }), ae({
          finalSelected: null,
          optionsList: []
        });
      }
    } catch (p) {
      console.error(p);
    }
  }, Pe = (a) => {
    P((l) => l.filter((n) => n.locationId !== a));
  };
  return /* @__PURE__ */ e(ia, { ...ie, children: /* @__PURE__ */ e(
    Ye,
    {
      className: "mt-6 mr-3 mb-3",
      elevation: 5,
      component: "form",
      onSubmit: Te(Fe),
      noValidate: !0,
      children: /* @__PURE__ */ r(ca, { isLoading: le, children: [
        /* @__PURE__ */ e(u, { item: !0, container: !0, direction: "row", children: /* @__PURE__ */ e(u, { item: !0, size: { xs: 12 }, children: /* @__PURE__ */ e(
          Q,
          {
            className: "p-2.5 px-5 flex border-b",
            subheader: /* @__PURE__ */ e(
              w,
              {
                display: "flex",
                alignItems: "center",
                justifyContent: "space-between",
                children: /* @__PURE__ */ e(
                  m,
                  {
                    variant: "body2",
                    className: "font-bold text-lg text-customBlue",
                    "data-testid": "form-header",
                    children: be(we)
                  }
                )
              }
            ),
            slotProps: {
              subheader: { className: "subheader-style" }
            }
          }
        ) }) }),
        /* @__PURE__ */ r(He, { children: [
          /* @__PURE__ */ r(u, { container: !0, spacing: 2, children: [
            /* @__PURE__ */ e(u, { className: "w-full", children: /* @__PURE__ */ r(
              u,
              {
                container: !0,
                spacing: 2,
                className: "flex flex-col justify-between  w-full",
                children: [
                  /* @__PURE__ */ r("div", { className: "flex md:flex-row flex-col space-x-10 w-[100%]", children: [
                    /* @__PURE__ */ r("div", { className: "flex flex-col space-y-2 w-full md:w-1/2", children: [
                      /* @__PURE__ */ r(u, { className: "mb-3 mr-[5rem] w-full", children: [
                        /* @__PURE__ */ r(
                          m,
                          {
                            variant: "caption",
                            className: "p-3 pl-0 text-base",
                            children: [
                              s("Immunization Name"),
                              /* @__PURE__ */ e("span", { className: "text-red-500 ml-1", children: "*" })
                            ]
                          }
                        ),
                        /* @__PURE__ */ e(
                          _,
                          {
                            control: h,
                            id: "name",
                            name: "name",
                            className: "w-full",
                            errors: f,
                            label: "",
                            size: "small"
                          }
                        )
                      ] }),
                      /* @__PURE__ */ r(u, { className: "mb-3 mr-[5rem] w-full", children: [
                        /* @__PURE__ */ r(
                          m,
                          {
                            variant: "caption",
                            className: "p-3 pl-0 text-base",
                            children: [
                              s("Immunization Code"),
                              /* @__PURE__ */ e("span", { className: "text-red-500 ml-1", children: "*" })
                            ]
                          }
                        ),
                        /* @__PURE__ */ e(
                          _,
                          {
                            control: h,
                            id: "code",
                            name: "code",
                            className: "w-full",
                            errors: f,
                            label: "",
                            size: "small",
                            disabled: !!S
                          }
                        )
                      ] }),
                      /* @__PURE__ */ r(u, { className: "mb-3 mr-[5rem] w-full", children: [
                        /* @__PURE__ */ e("div", { className: "flex gap-2 items-center", children: /* @__PURE__ */ r(
                          m,
                          {
                            variant: "caption",
                            className: "p-3 pl-0 text-base",
                            children: [
                              s("Base Date"),
                              /* @__PURE__ */ e("span", { className: "text-red-500 ml-1", children: "*" })
                            ]
                          }
                        ) }),
                        /* @__PURE__ */ e(w, { className: "w-full", children: /* @__PURE__ */ r(pe, { fullWidth: !0, children: [
                          /* @__PURE__ */ e(
                            H,
                            {
                              className: "w-full",
                              name: "basedate",
                              control: h,
                              defaultValue: "",
                              render: ({ field: a }) => /* @__PURE__ */ e(
                                fe,
                                {
                                  ...a,
                                  className: "w-full",
                                  sx: {
                                    height: 38
                                  },
                                  error: f.basedate,
                                  "data-testid": "mobiletypeeventconfigmodal-notification-select",
                                  children: ee == null ? void 0 : ee.map((l, n) => /* @__PURE__ */ e(
                                    V,
                                    {
                                      value: l.column_name,
                                      children: /* @__PURE__ */ e(m, { variant: "body2", children: l.column_name })
                                    },
                                    n + 1
                                  ))
                                }
                              )
                            }
                          ),
                          (f == null ? void 0 : f.basedate) && /* @__PURE__ */ e("p", { className: "error-helper-text-immunization", children: (K = f == null ? void 0 : f.basedate) == null ? void 0 : K.message })
                        ] }) })
                      ] }),
                      /* @__PURE__ */ r(u, { className: "mb-3 mr-[5rem] w-full", children: [
                        /* @__PURE__ */ r("div", { className: "flex flex-col md:flex-row md:items-center gap-2 w-full", children: [
                          /* @__PURE__ */ e(
                            m,
                            {
                              variant: "caption",
                              className: "text-base md:whitespace-nowrap",
                              children: s("Eligible From ")
                            }
                          ),
                          /* @__PURE__ */ r(u, { className: "flex gap-2 flex-wrap", children: [
                            /* @__PURE__ */ e(
                              q,
                              {
                                size: "small",
                                label: "Days",
                                clickable: !0,
                                color: R === "days" ? "primary" : "default",
                                onClick: () => C("days", "fromDate")
                              }
                            ),
                            /* @__PURE__ */ e(
                              q,
                              {
                                size: "small",
                                label: "Months",
                                clickable: !0,
                                color: R === "months" ? "primary" : "default",
                                onClick: () => C("months", "fromDate")
                              }
                            ),
                            /* @__PURE__ */ e(
                              q,
                              {
                                size: "small",
                                label: "Years",
                                clickable: !0,
                                color: R === "years" ? "primary" : "default",
                                onClick: () => C("years", "fromDate")
                              }
                            )
                          ] })
                        ] }),
                        /* @__PURE__ */ e(
                          _,
                          {
                            control: h,
                            id: "fromDate",
                            name: "fromDate",
                            type: "number",
                            errors: f,
                            label: "",
                            size: "small"
                          }
                        )
                      ] }),
                      /* @__PURE__ */ r(u, { className: "mb-3 mr-[5rem] w-full", children: [
                        /* @__PURE__ */ r("div", { className: "flex flex-col md:flex-row md:items-center gap-2 w-full", children: [
                          /* @__PURE__ */ e(
                            m,
                            {
                              variant: "caption",
                              className: "text-base md:whitespace-nowrap",
                              children: s("Eligible To")
                            }
                          ),
                          /* @__PURE__ */ r("div", { className: "flex gap-2 flex-wrap", children: [
                            /* @__PURE__ */ e(
                              q,
                              {
                                size: "small",
                                label: "Days",
                                clickable: !0,
                                color: F === "days" ? "primary" : "default",
                                onClick: () => C("days", "toDate")
                              }
                            ),
                            /* @__PURE__ */ e(
                              q,
                              {
                                size: "small",
                                label: "Months",
                                clickable: !0,
                                color: F === "months" ? "primary" : "default",
                                onClick: () => C("months", "toDate")
                              }
                            ),
                            /* @__PURE__ */ e(
                              q,
                              {
                                size: "small",
                                label: "Years",
                                clickable: !0,
                                color: F === "years" ? "primary" : "default",
                                onClick: () => C("years", "toDate")
                              }
                            )
                          ] })
                        ] }),
                        /* @__PURE__ */ e(
                          _,
                          {
                            control: h,
                            id: "toDate",
                            name: "toDate",
                            type: "number",
                            errors: f,
                            label: "",
                            size: "small"
                          }
                        )
                      ] })
                    ] }),
                    /* @__PURE__ */ r(u, { className: "w-full md:w-1/2", children: [
                      /* @__PURE__ */ e(We, { children: /* @__PURE__ */ e(
                        fa,
                        {
                          selectedLocation: A,
                          setSelectedLocation: ae,
                          locations: Se,
                          setLocations: Re,
                          fetchUptoLevel: $e,
                          templateType: "inline",
                          fetchAccordingToUserAoi: !0,
                          demographicFilterRequired: !1,
                          requiredUptoLevel: 1,
                          childForm: !0,
                          disabled: le
                        }
                      ) }),
                      /* @__PURE__ */ e(
                        j,
                        {
                          variant: "contained",
                          color: "primary",
                          size: "small",
                          onClick: Be,
                          className: "mt-[1rem]",
                          children: s("Add Location")
                        }
                      ),
                      /* @__PURE__ */ r("div", { className: "w-full mt-8 p-6 bg-background2 border border-gray-300 rounded-2xl shadow-lg", children: [
                        /* @__PURE__ */ e("h2", { className: "text-xl font-semibold mb-4 text-customBlue", children: "📍 Selected Locations" }),
                        /* @__PURE__ */ r("ul", { className: "", children: [
                          I == null ? void 0 : I.map((a) => /* @__PURE__ */ r("li", { children: [
                            /* @__PURE__ */ e("span", { className: "text-xl leading-none", children: "• " }),
                            /* @__PURE__ */ e("span", { children: a != null && a.locationList ? a == null ? void 0 : a.locationList : "" }),
                            /* @__PURE__ */ e(
                              "button",
                              {
                                onClick: () => Pe(a == null ? void 0 : a.locationId),
                                className: "mx-3 cursor-pointer text-red-500 hover:text-red-700 font-bold text-xl",
                                children: "×"
                              }
                            )
                          ] }, a == null ? void 0 : a.locationId)),
                          (I == null ? void 0 : I.length) === 0 && /* @__PURE__ */ e("li", { className: "text-gray-400 italic text-center", children: "No locations selected." })
                        ] })
                      ] })
                    ] })
                  ] }),
                  /* @__PURE__ */ r(u, { className: "flex flex-col md:flex-row space-x-10 w-full", children: [
                    /* @__PURE__ */ e(u, { className: "mb-3 mt-8", children: /* @__PURE__ */ e(
                      na,
                      {
                        name: "isRecursive",
                        sx: { "& .MuiSvgIcon-root": { fontSize: 20 } },
                        label: s("Repeats"),
                        control: h,
                        labelSizeInRem: "1rem",
                        checked: !!W
                      }
                    ) }),
                    W && /* @__PURE__ */ r(u, { className: "mb-3", children: [
                      /* @__PURE__ */ r("div", { className: "flex flex-col md:flex-row md:items-center gap-2 w-full", children: [
                        /* @__PURE__ */ e(
                          m,
                          {
                            variant: "caption",
                            className: "text-base md:whitespace-nowrap",
                            children: s("Interval")
                          }
                        ),
                        /* @__PURE__ */ r("div", { className: "flex gap-2 flex-wrap", children: [
                          /* @__PURE__ */ e(
                            q,
                            {
                              size: "small",
                              label: "Days",
                              clickable: !0,
                              color: L === "days" ? "primary" : "default",
                              onClick: () => C("days", "gapRange")
                            }
                          ),
                          /* @__PURE__ */ e(
                            q,
                            {
                              size: "small",
                              label: "Months",
                              clickable: !0,
                              color: L === "months" ? "primary" : "default",
                              onClick: () => C("months", "gapRange")
                            }
                          ),
                          /* @__PURE__ */ e(
                            q,
                            {
                              size: "small",
                              label: "Years",
                              clickable: !0,
                              color: L === "years" ? "primary" : "default",
                              onClick: () => C("years", "gapRange")
                            }
                          )
                        ] })
                      ] }),
                      /* @__PURE__ */ e(
                        _,
                        {
                          control: h,
                          id: "gapRange",
                          name: "gapRange",
                          type: "number",
                          className: "w-full",
                          errors: f,
                          label: "",
                          size: "small"
                        }
                      )
                    ] }),
                    W && /* @__PURE__ */ r(u, { className: "mb-3", children: [
                      /* @__PURE__ */ e("div", { className: "flex flex-col md:flex-row md:items-center gap-2 w-full", children: /* @__PURE__ */ r(
                        m,
                        {
                          variant: "caption",
                          className: " pl-0 text-base",
                          children: [
                            s("Max Doses"),
                            /* @__PURE__ */ e("span", { className: "text-red-500 ml-1", children: "*" })
                          ]
                        }
                      ) }),
                      /* @__PURE__ */ e(
                        _,
                        {
                          control: h,
                          id: "maxDoses",
                          name: "maxDoses",
                          type: "number",
                          className: "w-full",
                          errors: f,
                          label: "",
                          size: "small"
                        }
                      )
                    ] })
                  ] }),
                  /* @__PURE__ */ r(u, { size: { xs: 12 }, className: "mb-3", children: [
                    /* @__PURE__ */ e(Y, {}),
                    /* @__PURE__ */ r(w, { className: "flex flex-row items-center justify-between", children: [
                      /* @__PURE__ */ e(
                        Q,
                        {
                          subheader: /* @__PURE__ */ e(
                            w,
                            {
                              display: "flex",
                              alignItems: "center",
                              justifyContent: "space-between",
                              children: /* @__PURE__ */ e(
                                m,
                                {
                                  variant: "body2",
                                  className: "font-bold text-lg text-customBlue",
                                  "data-testid": "form-header",
                                  children: s("Add Validations")
                                }
                              )
                            }
                          ),
                          slotProps: {
                            subheader: {
                              variant: "p",
                              sx: { fontWeight: "bold" }
                            }
                          }
                        }
                      ),
                      /* @__PURE__ */ e(
                        j,
                        {
                          variant: "contained",
                          size: "small",
                          className: "mr-2",
                          onClick: () => te({
                            vaccine: [],
                            min_gap_days: 0,
                            max_gap_days: 0,
                            message: "",
                            required: ""
                          }),
                          children: s("Add")
                        }
                      )
                    ] }),
                    ne.map((a, l) => {
                      var n, o, d, p, c;
                      return /* @__PURE__ */ e(
                        w,
                        {
                          sx: {
                            display: "flex",
                            justifyContent: "space-between",
                            mb: 2,
                            alignItems: "flex-start",
                            border: "1px solid var(--color-gray3)",
                            backgroundColor: "var(--color-background)",
                            padding: 2,
                            borderRadius: 2,
                            position: "relative",
                            marginLeft: "15px"
                          },
                          children: /* @__PURE__ */ e("div", { className: "w-full", children: /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-4 items-center w-full", children: [
                            /* @__PURE__ */ r("div", { className: "w-full md:w-[20%]", children: [
                              /* @__PURE__ */ e(
                                m,
                                {
                                  variant: "caption",
                                  className: "pb-1 text-base block",
                                  children: Ae
                                }
                              ),
                              /* @__PURE__ */ e(
                                oa,
                                {
                                  name: `dependencies.${l}.vaccine`,
                                  options: Ce,
                                  checkEquality: "code",
                                  className: "w-full",
                                  errors: f,
                                  getOptionLabel: (t) => t.name,
                                  control: h,
                                  value: (o = (n = T[l]) == null ? void 0 : n.vaccine) == null ? void 0 : o.map(
                                    (t) => t || []
                                  )
                                }
                              )
                            ] }),
                            /* @__PURE__ */ r("div", { className: "w-full md:w-[20%]", children: [
                              /* @__PURE__ */ e(
                                m,
                                {
                                  variant: "caption",
                                  className: "pb-1 text-base block",
                                  children: ze
                                }
                              ),
                              /* @__PURE__ */ e(pe, { fullWidth: !0, children: /* @__PURE__ */ e(
                                H,
                                {
                                  name: `dependencies.${l}.required`,
                                  control: h,
                                  defaultValue: "",
                                  render: ({ field: t }) => /* @__PURE__ */ r(
                                    fe,
                                    {
                                      ...t,
                                      className: "w-full",
                                      sx: { height: 38 },
                                      error: E(
                                        f,
                                        `dependencies.${l}.required`
                                      ),
                                      onChange: (y) => {
                                        var z, b;
                                        t.onChange(y.target.value), y.target.value === "false" ? (g(
                                          `dependencies.${l}.min_gap_days`,
                                          0
                                        ), g(
                                          `dependencies.${l}.max_gap_days`,
                                          0
                                        ), Me([
                                          `dependencies.${l}.min_gap_days`,
                                          `dependencies.${l}.max_gap_days`
                                        ])) : (g(
                                          `dependencies.${l}.min_gap_days`,
                                          ((z = T[l]) == null ? void 0 : z.min_gap_days) || 0
                                        ), g(
                                          `dependencies.${l}.max_gap_days`,
                                          ((b = T[l]) == null ? void 0 : b.max_gap_days) || 0
                                        ));
                                      },
                                      children: [
                                        /* @__PURE__ */ e(V, { value: "true", children: /* @__PURE__ */ e(m, { variant: "body2", children: s("Should be given") }) }),
                                        /* @__PURE__ */ e(V, { value: "false", children: /* @__PURE__ */ e(m, { variant: "body2", children: s("Should not be given") }) }),
                                        /* @__PURE__ */ e(V, { value: "Optional", children: /* @__PURE__ */ e(m, { variant: "body2", children: s("Optional") }) })
                                      ]
                                    }
                                  )
                                }
                              ) })
                            ] }),
                            ((d = T[l]) == null ? void 0 : d.required) !== "false" && /* @__PURE__ */ r("div", { className: "w-full md:w-[15%]", children: [
                              /* @__PURE__ */ e(
                                m,
                                {
                                  variant: "caption",
                                  className: "pb-1 text-base block",
                                  children: qe
                                }
                              ),
                              /* @__PURE__ */ e(
                                _,
                                {
                                  control: h,
                                  id: `dependencies.${l}.min_gap_days`,
                                  name: `dependencies.${l}.min_gap_days`,
                                  type: "number",
                                  errors: f,
                                  label: "",
                                  size: "small"
                                }
                              )
                            ] }),
                            ((p = T[l]) == null ? void 0 : p.required) !== "false" && /* @__PURE__ */ r("div", { className: "w-full md:w-[15%]", children: [
                              /* @__PURE__ */ e(
                                m,
                                {
                                  variant: "caption",
                                  className: "pb-1 text-base block",
                                  children: Ie
                                }
                              ),
                              /* @__PURE__ */ e(
                                _,
                                {
                                  control: h,
                                  id: `dependencies.${l}.max_gap_days`,
                                  name: `dependencies.${l}.max_gap_days`,
                                  type: "number",
                                  errors: f,
                                  label: "",
                                  size: "small"
                                }
                              )
                            ] }),
                            /* @__PURE__ */ r(u, { className: "w-full md:w-[24%]", children: [
                              /* @__PURE__ */ e(
                                m,
                                {
                                  variant: "caption",
                                  className: "pb-1 text-base block",
                                  children: De
                                }
                              ),
                              /* @__PURE__ */ e(
                                _,
                                {
                                  control: h,
                                  id: `dependencies.${l}.message`,
                                  name: `dependencies.${l}.message`,
                                  errors: f,
                                  label: "",
                                  size: "small"
                                }
                              ),
                              E(
                                f,
                                `dependencies.${l}.vaccine`
                              ) && /* @__PURE__ */ e(m, { variant: "caption", color: "error", children: (c = E(
                                f,
                                `dependencies.${l}.vaccine`
                              )) == null ? void 0 : c.message })
                            ] }),
                            /* @__PURE__ */ e(u, { className: "mt-8", children: /* @__PURE__ */ e(
                              Z,
                              {
                                icon: he,
                                color: "red",
                                className: "cursor-pointer p-1 text-xl",
                                onClick: () => Ee(l)
                              }
                            ) })
                          ] }) })
                        },
                        a.id
                      );
                    }),
                    ne.length === 0 && /* @__PURE__ */ e(
                      w,
                      {
                        sx: {
                          padding: 3,
                          marginLeft: "15px",
                          marginTop: 2,
                          textAlign: "center",
                          color: "text.secondary",
                          backgroundColor: "var(--color-background)",
                          borderRadius: 2,
                          border: "1px dashed var(--color-gray3)"
                        },
                        children: /* @__PURE__ */ e(m, { variant: "body2", color: "text.secondary", children: s("No dependencies added yet.") })
                      }
                    )
                  ] }),
                  /* @__PURE__ */ r(u, { size: { xs: 12 }, className: "mb-3", children: [
                    /* @__PURE__ */ e(Y, {}),
                    /* @__PURE__ */ r(w, { className: "flex flex-row items-center justify-between", children: [
                      /* @__PURE__ */ e(
                        Q,
                        {
                          subheader: /* @__PURE__ */ r(
                            w,
                            {
                              display: "flex",
                              alignItems: "center",
                              justifyContent: "space-between",
                              children: [
                                /* @__PURE__ */ e(
                                  m,
                                  {
                                    variant: "body2",
                                    className: "font-bold text-lg text-customBlue",
                                    "data-testid": "form-header",
                                    children: s("Add Filters")
                                  }
                                ),
                                /* @__PURE__ */ e(
                                  Ze,
                                  {
                                    arrow: !0,
                                    title: /* @__PURE__ */ r(Ge, { children: [
                                      "Queries with ",
                                      /* @__PURE__ */ e("b", { children: "params" }),
                                      " ",
                                      /* @__PURE__ */ e("i", { children: "{{member_id}}" }),
                                      " are shown here.",
                                      /* @__PURE__ */ e("br", {}),
                                      "The query must return a single boolean column named ",
                                      /* @__PURE__ */ e("code", { children: "filter_passed" }),
                                      ", e.g.",
                                      " ",
                                      /* @__PURE__ */ e("code", { children: "{ filter_passed: true }" }),
                                      "."
                                    ] }),
                                    children: /* @__PURE__ */ e(Ke, { size: "small", color: "info", children: /* @__PURE__ */ e(Z, { icon: ma }) })
                                  }
                                )
                              ]
                            }
                          ),
                          slotProps: {
                            subheader: {
                              variant: "p",
                              sx: { fontWeight: "bold" }
                            }
                          }
                        }
                      ),
                      /* @__PURE__ */ e(
                        j,
                        {
                          variant: "contained",
                          size: "small",
                          onClick: () => oe({
                            filterName: "",
                            queryCode: ""
                          }),
                          children: s("Add")
                        }
                      )
                    ] }),
                    se.map((a, l) => /* @__PURE__ */ e(
                      w,
                      {
                        sx: {
                          display: "flex",
                          justifyContent: "space-between",
                          mb: 2,
                          alignItems: "flex-start",
                          border: "1px solid var(--color-gray3)",
                          backgroundColor: "var(--color-background)",
                          padding: 2,
                          borderRadius: 2,
                          position: "relative",
                          marginLeft: "15px"
                        },
                        children: /* @__PURE__ */ e("div", { className: "w-full", children: /* @__PURE__ */ r("div", { className: "flex flex-wrap gap-4 items-center w-full", children: [
                          /* @__PURE__ */ r("div", { className: "w-full md:w-[45%]", children: [
                            /* @__PURE__ */ e(
                              m,
                              {
                                variant: "caption",
                                className: "pb-1 text-base block",
                                children: s("Filter Name")
                              }
                            ),
                            /* @__PURE__ */ e(
                              _,
                              {
                                control: h,
                                name: `filters.${l}.filterName`,
                                errors: f,
                                label: "",
                                size: "small"
                              }
                            )
                          ] }),
                          /* @__PURE__ */ r("div", { className: "w-full md:w-[50%]", children: [
                            /* @__PURE__ */ e(
                              m,
                              {
                                variant: "caption",
                                className: "pb-1 text-base block",
                                children: s("Query")
                              }
                            ),
                            /* @__PURE__ */ e(
                              H,
                              {
                                name: `filters.${l}.queryCode`,
                                control: h,
                                render: ({ field: n }) => {
                                  const [o, d] = N(""), p = re.find(
                                    (c) => c.queryCode === n.value
                                  ) || null;
                                  return /* @__PURE__ */ e(
                                    Xe,
                                    {
                                      options: re,
                                      getOptionLabel: (c) => c.queryCode || "",
                                      isOptionEqualToValue: (c, t) => (c == null ? void 0 : c.queryCode) === t,
                                      value: p,
                                      inputValue: o,
                                      onInputChange: (c, t) => {
                                        d(t);
                                      },
                                      onChange: (c, t) => {
                                        n.onChange(
                                          (t == null ? void 0 : t.queryCode) || ""
                                        ), d(
                                          (t == null ? void 0 : t.queryCode) || ""
                                        );
                                      },
                                      filterOptions: (c, { inputValue: t }) => c.filter(
                                        (y) => y.queryCode.toLowerCase().includes(
                                          t.toLowerCase()
                                        )
                                      ),
                                      renderOption: (c, t) => /* @__PURE__ */ e("li", { ...c, children: t.queryCode }),
                                      renderInput: (c) => {
                                        var t;
                                        return /* @__PURE__ */ e(
                                          ea,
                                          {
                                            ...c,
                                            size: "small",
                                            error: !!E(
                                              f,
                                              `filters.${l}.queryCode`
                                            ),
                                            helperText: (t = E(
                                              f,
                                              `filters.${l}.queryCode`
                                            )) == null ? void 0 : t.message
                                          }
                                        );
                                      }
                                    }
                                  );
                                }
                              }
                            )
                          ] }),
                          /* @__PURE__ */ e(u, { className: "mt-8", children: /* @__PURE__ */ e(
                            Z,
                            {
                              icon: he,
                              color: "red",
                              className: "cursor-pointer p-1 text-xl",
                              onClick: () => Je(l)
                            }
                          ) })
                        ] }) })
                      },
                      a.id
                    )),
                    se.length === 0 && /* @__PURE__ */ e(
                      w,
                      {
                        sx: {
                          padding: 3,
                          marginLeft: "15px",
                          marginTop: 2,
                          textAlign: "center",
                          color: "text.secondary",
                          backgroundColor: "var(--color-background)",
                          borderRadius: 2,
                          border: "1px dashed var(--color-gray3)"
                        },
                        children: /* @__PURE__ */ e(m, { variant: "body2", color: "text.secondary", children: s("No filters added yet.") })
                      }
                    )
                  ] })
                ]
              }
            ) }),
            /* @__PURE__ */ r(u, { size: { xs: 12 }, className: "mb-3", children: [
              /* @__PURE__ */ e(Y, { variant: "middle", className: "h-[0.625rem]" }),
              /* @__PURE__ */ e(u, { container: !0, spacing: 2 })
            ] })
          ] }),
          /* @__PURE__ */ r(u, { item: !0, container: !0, size: { xs: 12 }, justifyContent: "flex-end", children: [
            /* @__PURE__ */ e(
              j,
              {
                variant: "contained",
                color: "secondary",
                size: "small",
                onClick: () => {
                  B("/ui/medplat/manage/immunizationConfiguratorList");
                },
                "data-testid": "manageImmunization-close-button",
                children: /* @__PURE__ */ e(m, { variant: "caption", children: s("Back") })
              }
            ),
            /* @__PURE__ */ e(
              j,
              {
                className: "ml-2 mr-4",
                size: "small",
                variant: "contained",
                color: "primary",
                type: "submit",
                "data-testid": "submit-button",
                children: s("Submit")
              }
            )
          ] })
        ] })
      ] })
    }
  ) });
};
export {
  $a as default
};
//# sourceMappingURL=manageImmunization-B4swS745-JldexHrO.js.map
