import { jsx as r } from "react/jsx-runtime";
import { lazy as o } from "react";
import { createSlice as O } from "@reduxjs/toolkit";
import { execute as d, executeAll as z } from "@/common/services/GlobalApis";
import { api as S } from "@/common/interceptors/AxiosInterceptor";
import './index.css';const s = o(
  () => import("@/views/feature-components/VerifyRoute.jsx")
), v = o(() => import("./RoleManagement-C0feJCuq.js").then((e) => e.R)), G = o(
  () => import("./QueryBuilder-BPfavHH9.js").then((e) => e.Q)
), x = o(() => import("./UserList-S5Q76wO7.js")), y = o(() => import("./ManageUser-Dr3ptCYp.js").then((e) => e.M)), B = o(
  () => import("./QueryManagement-DXA73N2j.js")
), w = o(() => import("./FeatureMenu-Ds6lFg4w.js").then((e) => e.F)), P = o(() => import("./index-BFznsakV.js")), q = o(
  () => import("./NewServerManagement-5YcAtF-g.js")
), h = o(
  () => import("./ManageDynamicFeature-C2I7Ho7i.js")
), $ = o(
  () => import("./SecurityAuditLogList-DHTcOtbx.js")
), H = o(
  () => import("./EventConfigurations-jGCJ4LqP.js")
), N = o(
  () => import("./ManageEventConfiguration-BJxS2Su0.js")
), Z = o(
  () => import("./EntityManagement-D-x6Qzal.js")
), Q = o(
  () => import("./MobileMenuManagement-BmrO-7MN.js")
), X = o(
  () => import("./AddMenuConfiguration-QWfpcnuP.js")
), j = o(
  () => import("./ManageTranslation-BTxvSYKb.js").then((e) => e.M)
), W = o(
  () => import("./WidgetList-BSApErov.js")
), J = o(
  () => import("./NotificationList-BqibwMaM.js").then((e) => e.N)
), K = o(
  () => import("./ImmunizationConfigurationsList-CQnxWa09.js")
), E = o(
  () => import("./manageImmunization-B4swS745.js")
), Y = o(
  () => import("./ImmunizationConfigurationBase-DZ8EqXlF.js")
), Ce = [
  {
    path: "medplat/manage/role",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Roles",
        pageTitle: "General",
        url: "medplat/manage/role",
        component: v
      }
    )
  },
  {
    path: "medplat/manage/query",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Query Master",
        pageTitle: "General",
        url: "medplat/manage/query",
        component: G
      }
    )
  },
  {
    path: "medplat/manage/users",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Users",
        pageTitle: "UserList",
        url: "medplat/manage/users",
        component: x
      }
    )
  },
  {
    path: "medplat/manage/user",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Users",
        pageTitle: "ManageUser",
        url: "medplat/manage/users",
        component: y
      }
    )
  },
  {
    path: "medplat/manage/user/:id",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Users",
        pageTitle: "General",
        url: "medplat/manage/users",
        component: y
      }
    )
  },
  {
    path: "medplat/querymanagement",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Query Management",
        pageTitle: "General",
        url: "medplat/querymanagement",
        component: B
      }
    )
  },
  {
    path: "medplat/manage/menu",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Features",
        pageTitle: "General",
        url: "medplat/manage/menu",
        component: w
      }
    )
  },
  {
    path: "medplat/manage/menu/addfeature",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Features",
        pageTitle: "General",
        url: "medplat/manage/menu",
        component: h
      }
    )
  },
  {
    path: "medplat/manage/menu/addDynamicFeature",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Features",
        pageTitle: "General",
        url: "medplat/manage/menu",
        component: h
      }
    )
  },
  {
    path: "medplat/notification/all",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Event Configuration",
        pageTitle: "General",
        url: "medplat/notification/all",
        component: H
      }
    )
  },
  {
    path: "medplat/views/config",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Event Configuration",
        pageTitle: "General",
        url: "medplat/notification",
        component: N
      }
    )
  },
  {
    path: "medplat/views/config/:id",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Event Configuration",
        pageTitle: "General",
        url: "medplat/notification",
        component: N
      }
    )
  },
  {
    path: "medplat/admin/newServerManagement",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Server Management",
        url: "medplat/admin/newServerManagement",
        component: q
      }
    )
  },
  {
    path: "medplat/admin/mobileEntityManagement",
    element: /* @__PURE__ */ r(
      s,
      {
        pageTitle: "General",
        url: "medplat/admin/mobileEntityManagement",
        component: Z,
        headerTitle: "Mobile Database Management"
      }
    )
  },
  {
    path: "medplat/admin/mobileMenuManagement",
    element: /* @__PURE__ */ r(
      s,
      {
        url: "medplat/admin/mobileMenuManagement",
        component: /* @__PURE__ */ r(Q, {}),
        headerTitle: "Mobile Menu Management"
      }
    )
  },
  {
    path: "medplat/admin/mobileMenuManagement/addMenuConfiguration",
    element: /* @__PURE__ */ r(X, {})
  },
  {
    path: "medplat/manage/manageTranslation",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Manage Translation",
        pageTitle: "General",
        url: "medplat/manage/manageTranslation",
        component: j
      }
    )
  },
  {
    path: "medplat/manage/managewidgets",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Widgets",
        pageTitle: "General",
        url: "medplat/manage/manage-widgets",
        component: W
      }
    )
  },
  {
    path: "medplat/manage/notification",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Notification Configuration",
        pageTitle: "General",
        url: "medplat/manage/notification",
        component: J
      }
    )
  },
  {
    path: "medplat/manage/immunizationConfiguratorList",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Immunizations",
        pageTitle: "General",
        url: "medplat/manage/manageTranslation",
        component: K
      }
    )
  },
  {
    path: "medplat/manage/manageImmunization",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Immunizations",
        pageTitle: "General",
        url: "medplat/training/question",
        component: E
      }
    )
  },
  {
    path: "medplat/manage/manageImmunization/:id",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Immunizations",
        pageTitle: "General",
        url: "medplat/training/question",
        component: E
      }
    )
  },
  {
    path: "medplat/manage/immunizationConfiguration",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Immunization Configuration",
        pageTitle: "General",
        url: "medplat/manage/immunizationConfiguration",
        component: Y
      }
    )
  },
  {
    path: "medplat/manage/securityAuditLogs",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Security Audit Logs",
        pageTitle: "Security Audit Logs",
        url: "medplat/manage/securityAuditLogs",
        component: $
      }
    )
  },
  {
    path: "medplat/manage/activityAnalytics",
    element: /* @__PURE__ */ r(
      s,
      {
        headerTitle: "Activity Analytics",
        url: "medplat/manage/activityAnalytics",
        component: P
      }
    )
  }
], b = () => ({
  vaccines: [],
  selectedVaccineIds: [],
  views: [
    {
      id: "landing",
      name: "Dashboard"
    },
    {
      id: "schedule-config",
      name: "Schedule Config"
    },
    {
      id: "summary",
      name: "Configuration Summary"
    }
  ],
  currentViewId: "summary",
  scheduledVaccines: [],
  baseDateMaster: [],
  recipientMaster: [],
  dbTablesMaster: [],
  filtersMaster: [],
  featureRights: {},
  isConfigLoaded: !1,
  validationErrors: {}
}), k = b(), A = (e = [], t = {}) => {
  const n = e.findIndex(
    (a) => t.id !== void 0 && (a == null ? void 0 : a.id) === t.id || t.code && (a == null ? void 0 : a.code) === t.code
  );
  return n === -1 ? [...e, t] : e.map(
    (a, l) => l === n ? {
      ...a,
      ...t
    } : a
  );
}, V = O({
  name: "immunization",
  initialState: k,
  reducers: {
    toggleVaccine: (e, t) => {
      const n = t.payload;
      Array.isArray(e.selectedVaccineIds) || (e.selectedVaccineIds = []);
      const a = e.selectedVaccineIds.indexOf(n);
      a > -1 ? e.selectedVaccineIds.splice(a, 1) : e.selectedVaccineIds.push(n);
    },
    setVaccines: (e, t) => {
      const n = Array.isArray(t.payload) ? t.payload : [];
      e.vaccines = n, e.selectedVaccineIds.length === 0 && (e.selectedVaccineIds = n.filter((a) => a.isActive).map((a) => a.id));
    },
    setSelectedVaccineIds: (e, t) => {
      e.selectedVaccineIds = t.payload;
    },
    addCustomVaccine: (e, t) => {
      const n = t.payload || {}, {
        name: a,
        vaccine_name: l,
        disease: c,
        target_prevention: m,
        id: u,
        baseDateCode: i,
        base_date_code: p,
        recipientType: I,
        recipient_type: F
      } = n, U = a || l || "Unnamed Vaccine", R = c || m || "General", _ = (Array.isArray(e.vaccines) ? e.vaccines : []).map((g) => Number(g == null ? void 0 : g.id)).filter((g) => !Number.isNaN(g)), D = _.length > 0 ? Math.max(..._) + 1 : 1, L = {
        id: u || D,
        name: U,
        category: R,
        doses: 0,
        doseType: "FIXED",
        doseDetails: {},
        regions: [],
        dependencies: [],
        isActive: n.isActive !== void 0 ? n.isActive : !1,
        baseDateCode: i || p || null,
        recipientType: I || F || ""
      };
      Array.isArray(e.vaccines) || (e.vaccines = []), e.vaccines.push(L);
    },
    setCurrentView: (e, t) => {
      e.currentViewId = t.payload;
    },
    updateScheduledVaccine: (e, t) => {
      const n = t.payload, a = e.scheduledVaccines.findIndex((l) => l.id === n.id);
      a !== -1 ? e.scheduledVaccines[a] = {
        ...e.scheduledVaccines[a],
        ...n
      } : e.scheduledVaccines.push(n);
    },
    setBaseDatesMaster: (e, t) => {
      e.baseDateMaster = t.payload;
    },
    setRecipientMaster: (e, t) => {
      e.recipientMaster = t.payload;
    },
    setDbTablesMaster: (e, t) => {
      e.dbTablesMaster = t.payload;
    },
    setFiltersMaster: (e, t) => {
      e.filtersMaster = t.payload;
    },
    upsertBaseDateMasterItem: (e, t) => {
      e.baseDateMaster = A(e.baseDateMaster, t.payload);
    },
    upsertRecipientMasterItem: (e, t) => {
      e.recipientMaster = A(e.recipientMaster, t.payload);
    },
    updateBaseDateMasterStatus: (e, t) => {
      const { code: n, is_active: a } = t.payload;
      e.baseDateMaster = e.baseDateMaster.map(
        (l) => l.code === n ? { ...l, is_active: a } : l
      );
    },
    upsertFilterMasterItem: (e, t) => {
      e.filtersMaster = A(e.filtersMaster, t.payload);
    },
    updateFilterMasterStatus: (e, t) => {
      const { code: n, is_active: a } = t.payload;
      e.filtersMaster = e.filtersMaster.map(
        (l) => l.code === n ? { ...l, is_active: a } : l
      );
    },
    setFeatureRights: (e, t) => {
      e.featureRights = t.payload || {};
    },
    setImmunizationConfigLoaded: (e, t) => {
      e.isConfigLoaded = t.payload;
    },
    resetImmunizationState: () => b(),
    activateSelectedVaccines: (e) => {
      e.vaccines = e.vaccines.map((t) => ({
        ...t,
        isActive: e.selectedVaccineIds.includes(t.id)
      }));
    },
    setVaccineStatus: (e, t) => {
      const { vaccineId: n, status: a } = t.payload, l = e.vaccines.findIndex((m) => m.id === n);
      l !== -1 && (e.vaccines[l].isActive = a), Array.isArray(e.selectedVaccineIds) || (e.selectedVaccineIds = []);
      const c = e.selectedVaccineIds.indexOf(n);
      a && c === -1 ? e.selectedVaccineIds.push(n) : !a && c !== -1 && e.selectedVaccineIds.splice(c, 1);
    },
    setValidationErrors: (e, t) => {
      const { vaccineId: n, errors: a } = t.payload;
      e.validationErrors[n] = a;
    },
    clearValidationErrors: (e, t) => {
      const n = t.payload;
      n ? delete e.validationErrors[n] : e.validationErrors = {};
    }
  }
}), {
  toggleVaccine: Fe,
  setVaccines: Ue,
  addCustomVaccine: Re,
  setCurrentView: De,
  updateScheduledVaccine: Le,
  setBaseDatesMaster: Oe,
  setRecipientMaster: ze,
  setDbTablesMaster: ve,
  setFiltersMaster: Ge,
  upsertBaseDateMasterItem: xe,
  upsertRecipientMasterItem: Be,
  updateBaseDateMasterStatus: we,
  upsertFilterMasterItem: Pe,
  updateFilterMasterStatus: qe,
  setFeatureRights: $e,
  setImmunizationConfigLoaded: He,
  resetImmunizationState: Ze,
  activateSelectedVaccines: Qe,
  setSelectedVaccineIds: Xe,
  setValidationErrors: je,
  clearValidationErrors: We,
  setVaccineStatus: Je
} = V.actions, Ke = V.reducer, T = (e, t) => {
  if (e == null)
    return t;
  if (typeof e != "string")
    return e;
  try {
    return JSON.parse(e);
  } catch {
    return t;
  }
}, M = (...e) => e.filter(Boolean).join("_"), f = (e) => e == null || e === "" || e === "N.A." || e === "null days" ? "N.A." : e, C = (e, t = "FLEXIBLE", n = 1) => {
  if (n === 0 || !e)
    return "N.A.";
  if (t === "FIXED") {
    const c = Array.isArray(e) ? e[0] : e;
    if (!c)
      return "N.A.";
    const m = f(c.eligibleFrom), u = f(c.eligibleTo);
    return m === "N.A." && u === "N.A." ? "N.A." : `${m} to ${u}`;
  }
  if (!Array.isArray(e) || e.length === 0)
    return "N.A.";
  const a = f(e[0].eligibleFrom), l = f(
    e[e.length - 1].eligibleTo
  );
  return a === "N.A." && l === "N.A." ? "N.A." : `${a} to ${l}`;
}, ee = (e) => {
  const t = String(e.dose_type || "").toLowerCase(), a = t === "fixed" || t === "na" || !e.dose_type ? [
    {
      id: M("fixed", e.id),
      eligibleFrom: e.dose_eligible_from !== void 0 ? `${e.dose_eligible_from} days` : "",
      eligibleTo: e.dose_eligible_to !== void 0 ? `${e.dose_eligible_to} days` : "",
      interval: e.min_gap || 0
    }
  ] : T(e.dose, []).map((i, p) => ({
    id: i.id || M("dose", e.id, p),
    isBooster: i.isBooster === !0 || i.is_booster === !0 || typeof i.dose == "string" && i.dose.toUpperCase().startsWith("B"),
    alias: i.alias || i.booster_alias || "",
    eligibleFrom: i.eligible_from !== void 0 ? `${i.eligible_from} days` : "",
    eligibleTo: i.eligible_to !== void 0 ? `${i.eligible_to} days` : "",
    interval: i.min_gap || 0
  })), l = T(e.location, []).filter((i) => i && typeof i == "object").map((i, p) => {
    var I;
    return {
      id: M("region", e.id, p),
      locationId: i.locationId,
      locationIdArr: i.locationIdArr,
      locationList: i.locationList,
      fullPath: (I = i.locationList) == null ? void 0 : I.replaceAll(" => ", " → ")
    };
  }), c = T(e.validations, []).map(
    (i, p) => ({
      id: M("dep", e.id, p),
      vaccine: i.vaccine || "",
      requirement: i.requirement || "Should be given",
      minGap: Number.parseInt(i.minGap, 10) || 0,
      maxGap: Number.parseInt(i.maxGap, 10) || 0,
      message: i.message || ""
    })
  ), m = T(e.filters, []), u = Array.isArray(m) ? m : (m == null ? void 0 : m.codes) || [];
  return {
    ...e,
    name: e.vaccine_name || e.name || "N.A.",
    category: e.target_prevention || e.disease || e.category || "N.A.",
    doses: e.no_of_doses || 0,
    doseType: e.dose_type && e.dose_type !== "NA" ? e.dose_type : "FIXED",
    doseDetails: a,
    eligibility: C(
      a,
      e.dose_type,
      e.no_of_doses || 0
    ),
    isActive: e.is_active !== void 0 ? e.is_active : !0,
    regions: l,
    dependencies: c,
    filters: u,
    baseDateCode: e.base_date_code,
    recipientType: e.recipient_type || ""
  };
}, te = () => d({
  code: "FETCH_IMMUNISATION_MASTER",
  parameters: {}
}), ae = () => d({
  code: "FETCH_IMMUNISATION_BASE_DATE",
  parameters: {}
}), ne = () => d({
  code: "FETCH_IMMUNISATION_RECEPIENT_MASTER",
  parameters: {}
}), ie = () => z([
  {
    code: "FETCH_IMMUNISATION_BASE_DATE",
    parameters: {},
    sequence: 1
  },
  {
    code: "GET_ALL_IMMUNISATION_FILTERS",
    parameters: {},
    sequence: 2
  },
  {
    code: "FETCH_IMMUNISATION_MASTER",
    parameters: {},
    sequence: 3
  },
  {
    code: "FETCH_IMMUNISATION_RECEPIENT_MASTER",
    parameters: {},
    sequence: 4
  }
]), re = (e) => d({
  code: "INSERT_IMMUNIZATION_MASTER",
  parameters: e
}), se = (e) => d({
  code: "UPDATE_IMMUNIZATION_DOSE",
  ...e
}), oe = (e) => d({
  code: "CHECK_IMMUNIZATION_CONFIGURATION_INITIATION",
  ...e
}), le = (e) => d({
  code: "UPDATE_IMMUNIZATION_STATUS",
  ...e
}), de = (e) => d({
  code: "UPDATE_IMMUNIZATION_STATUS_FOR_ARRAY",
  ...e
}), me = (e) => d({
  code: "UPDATE_IMMUNIZATION_CONFIGURATION_INITIATION",
  ...e
}), ce = (e) => d({
  code: "SAVE_IMMUNISATION_BASE_DATE",
  parameters: e
}), pe = (e) => d({
  code: "SAVE_IMMUNISATION_RECEPIENT_MASTER",
  parameters: e
}), ue = (e) => d({
  code: "UPDATE_IMMUNISATION_RECEPIENT_MASTER",
  parameters: e
}), ge = (e) => d({
  code: "UPDATE_IMMUNISATION_BASE_DATE",
  parameters: e
}), Ie = () => d({
  code: "retrieve_all_tables_and_columns",
  parameters: {}
}), Te = () => d({
  code: "GET_ALL_IMMUNISATION_FILTERS",
  parameters: {}
}), Me = (e) => d({
  code: "ADD_IMMUNISATION_FILTER",
  parameters: e
}), fe = (e) => d({
  code: "UPDATE_IMMUNISATION_FILTER",
  parameters: e
}), Ae = (e) => S.post("/medplatform/v2/immunisation/list", e), _e = (e) => S.post("/medplatform/v2/immunisation/revalidate", e), Ye = {
  calculateOverallEligibility: C,
  mapImmunizationVaccineConfig: ee,
  getVaccines: te,
  getBaseDates: ae,
  getRecipients: ne,
  getImmunizationReferenceData: ie,
  addImmunization: re,
  updateImmunization: se,
  checkImmunizationConfigurationInitiation: oe,
  updateVaccineStatus: le,
  updateVaccineStatusFromArray: de,
  updateImmunizationConfigurationInitiation: me,
  saveBaseDate: ce,
  saveRecipient: pe,
  updateRecipient: ue,
  updateBaseDate: ge,
  getAllTablesAndColumns: Ie,
  getFilters: Te,
  addFilter: Me,
  updateFilter: fe,
  getImmunisationV2List: Ae,
  revalidateImmunisationV2List: _e
};
export {
  Ye as ImmunizationUtil,
  Ke as immunizationReducer,
  Ce as routes
};
//# sourceMappingURL=index.js.map
