import { jsx as t, jsxs as x } from "react/jsx-runtime";
import { useTranslateProvider as ce } from "@/common/languageTranslator/TranslationContext";
import { showToast as k } from "@/common/toaster/toaster.jsx";
import Se from "@/hooks/usePagination.js";
import De from "@/views/custom-components/CustomizedTable/CustomizedTableV2";
import Ce from "@/views/custom-components/SideOverlay.jsx";
import { useState as g, useEffect as ee, useMemo as we, useCallback as Ie } from "react";
import { Tooltip as Ee, Box as _, Typography as E, IconButton as ke, CircularProgress as ue, Dialog as Re, DialogTitle as $e, DialogContent as Oe, Button as te, useTheme as Me, alpha as S, TextField as L } from "@mui/material";
import { FontAwesomeIcon as w } from "@fortawesome/react-fontawesome";
import { faEye as Pe, faChartLine as Ye, faSync as ze, faFilePdf as pe, faFileExcel as Ue, faCalendar as Le, faSearch as We } from "@fortawesome/free-solid-svg-icons";
import { d as Be } from "./default-DlLB_mdl.js";
import { useTheme as Fe, alpha as X } from "@mui/material/styles";
import { execute as je } from "@/common/services/GlobalApis";
import d from "@mui/material/Grid2";
import { A as Ge } from "./FileSaver.min-CN9EpL2h-N-3OFAd7.js";
import Ve from "@/hooks/useTrackEvent";
import { E as j } from "./xlsx.min-D1LFqt_b-BGwkpd8r.js";
import Je from "@/hooks/useDownloadPdf.js";
import { C } from "./index-Dta_LKti.js";
import Z from "moment";
function qe({
  filter: A,
  setFilter: l,
  handleOverlayState: R
}) {
  const { translate: N } = ce(), o = Me(), W = o.palette.mode === "dark", [y, $] = g(A), [B, I] = g(!1), [G, O] = g([
    {
      startDate: A.startTime ? new Date(A.startTime) : /* @__PURE__ */ new Date(),
      endDate: A.endTime ? new Date(A.endTime) : /* @__PURE__ */ new Date(),
      key: "selection"
    }
  ]);
  ee(() => {
    $(A), O([
      {
        startDate: A.startTime ? new Date(A.startTime) : /* @__PURE__ */ new Date(),
        endDate: A.endTime ? new Date(A.endTime) : /* @__PURE__ */ new Date(),
        key: "selection"
      }
    ]);
  }, [A]);
  const V = (n) => {
    const { selection: b } = n;
    O([b]);
    const P = b.startDate ? M(b.startDate) : null, Y = b.endDate ? M(b.endDate) : null;
    $((z) => ({
      ...z,
      startTime: P,
      endTime: Y
    }));
  }, M = (n) => {
    if (!n) return null;
    const b = new Date(n);
    return `${b.getFullYear()}-${String(b.getMonth() + 1).padStart(2, "0")}-${String(b.getDate()).padStart(2, "0")}`;
  }, F = () => {
    if (!y.startTime && !y.endTime) return "Select date range";
    const n = y.startTime ? new Date(y.startTime).toLocaleDateString() : "", b = y.endTime ? new Date(y.endTime).toLocaleDateString() : "";
    return `${n} - ${b}`;
  }, u = (n, b) => {
    $((P) => ({ ...P, [n]: b }));
  }, J = () => {
    l(y), R();
  }, h = {
    "& .MuiInputLabel-root": {
      color: o.palette.text.secondary,
      fontSize: "0.85rem",
      fontWeight: 500,
      transform: "translate(0, -1.5px) scale(1)",
      "&.Mui-focused": { color: o.palette.primary.main }
    },
    "& .MuiInputBase-root": {
      backgroundColor: S(o.palette.text.primary, 0.05),
      borderRadius: "12px",
      color: o.palette.text.primary,
      marginTop: "20px",
      "& fieldset": {
        borderColor: S(o.palette.text.primary, 0.1),
        borderRadius: "12px"
      },
      "&:hover fieldset": { borderColor: S(o.palette.text.primary, 0.3) },
      "&.Mui-focused fieldset": { borderColor: o.palette.primary.main, borderWidth: "2px" }
    },
    "& .MuiInputBase-input": {
      padding: "10px 14px",
      colorScheme: W ? "dark" : "light"
    }
  };
  return /* @__PURE__ */ x(_, { className: "flex flex-col gap-6 p-6", children: [
    /* @__PURE__ */ x(_, { className: "flex flex-col gap-1.5 pt-1", children: [
      /* @__PURE__ */ t(E, { variant: "caption", sx: { color: o.palette.text.secondary, fontWeight: 500, fontSize: "0.85rem", transform: "translate(0, -1.5px)" }, children: N("Date Range") }),
      /* @__PURE__ */ x(
        _,
        {
          onClick: () => I(!B),
          className: "flex items-center justify-between gap-2 px-3 py-2.5 rounded-xl cursor-pointer transition-all",
          sx: {
            backgroundColor: S(o.palette.text.primary, 0.05),
            border: `1px solid ${S(o.palette.text.primary, 0.1)}`,
            "&:hover": { borderColor: S(o.palette.text.primary, 0.3) }
          },
          children: [
            /* @__PURE__ */ t(E, { variant: "body2", sx: { color: o.palette.text.primary, fontSize: "0.875rem" }, children: F() }),
            /* @__PURE__ */ t(w, { icon: Le, className: "opacity-50 text-sm" })
          ]
        }
      ),
      B && /* @__PURE__ */ t(
        _,
        {
          className: "mt-2 p-2 rounded-xl flex justify-center overflow-hidden border",
          sx: {
            backgroundColor: o.palette.background.paper,
            borderColor: S(o.palette.text.primary, 0.1),
            "& .rdrCalendarWrapper": {
              backgroundColor: o.palette.background.paper,
              color: o.palette.text.primary
            },
            "& .rdrDateDisplayWrapper": {
              backgroundColor: S(o.palette.text.primary, 0.05)
            },
            "& .rdrMonthAndYearWrapper": {
              color: o.palette.text.primary
            },
            "& .rdrMonthName": {
              color: o.palette.text.primary
            },
            "& .rdrDayNumber span": {
              color: o.palette.text.primary
            },
            "& .rdrDayDisabled": {
              backgroundColor: "transparent",
              "& .rdrDayNumber span": {
                color: S(o.palette.text.primary, 0.25)
              }
            },
            "& .rdrDayPassive": {
              "& .rdrDayNumber span": {
                color: S(o.palette.text.primary, 0.3)
              }
            }
          },
          children: /* @__PURE__ */ t(
            Be.DateRange,
            {
              editableDateInputs: !1,
              onChange: V,
              moveRangeOnFirstSelection: !1,
              ranges: G,
              rangeColors: [o.palette.primary.main]
            }
          )
        }
      )
    ] }),
    /* @__PURE__ */ x(_, { className: "flex flex-col gap-4 pt-2", children: [
      /* @__PURE__ */ t(
        L,
        {
          label: N("User ID"),
          placeholder: N("e.g. 101"),
          value: y.userId || "",
          onChange: (n) => u("userId", n.target.value),
          fullWidth: !0,
          size: "small",
          slotProps: { inputLabel: { shrink: !0 } },
          sx: h
        }
      ),
      /* @__PURE__ */ t(
        L,
        {
          label: N("IP Address"),
          placeholder: "192.168.1.1",
          value: y.ip || "",
          onChange: (n) => u("ip", n.target.value),
          fullWidth: !0,
          size: "small",
          slotProps: { inputLabel: { shrink: !0 } },
          sx: h
        }
      ),
      /* @__PURE__ */ t(
        L,
        {
          label: N("Session ID"),
          placeholder: N("e.g. E561890..."),
          value: y.sessionId || "",
          onChange: (n) => u("sessionId", n.target.value),
          fullWidth: !0,
          size: "small",
          slotProps: { inputLabel: { shrink: !0 } },
          sx: h
        }
      ),
      /* @__PURE__ */ t(
        L,
        {
          label: N("Event Type"),
          placeholder: "LOGIN_SUCCESS",
          value: y.eventType || "",
          onChange: (n) => u("eventType", n.target.value),
          fullWidth: !0,
          size: "small",
          slotProps: { inputLabel: { shrink: !0 } },
          sx: h
        }
      ),
      /* @__PURE__ */ t(
        L,
        {
          label: N("Resource Path"),
          placeholder: "/api/v1/...",
          value: y.resource || "",
          onChange: (n) => u("resource", n.target.value),
          fullWidth: !0,
          size: "small",
          slotProps: { inputLabel: { shrink: !0 } },
          sx: h
        }
      )
    ] }),
    /* @__PURE__ */ t(_, { className: "flex justify-stretch mt-4", children: /* @__PURE__ */ t(
      te,
      {
        variant: "contained",
        onClick: J,
        fullWidth: !0,
        startIcon: /* @__PURE__ */ t(w, { icon: We }),
        sx: {
          backgroundColor: o.palette.primary.main,
          height: "45px",
          borderRadius: "12px",
          fontWeight: "bold",
          textTransform: "uppercase",
          letterSpacing: "1px",
          "&:hover": { backgroundColor: o.palette.primary.dark }
        },
        children: N("Apply Filters")
      }
    ) })
  ] });
}
function bt() {
  const A = (e) => {
    if (!e) return "N/A";
    const i = Z(), s = Z(e), a = Z.duration(i.diff(s)), p = a.years(), r = a.months(), c = a.days(), m = a.hours(), v = a.minutes(), D = a.seconds();
    if (p > 0) return `${p} year${p > 1 ? "s" : ""} ago`;
    if (r > 0) return `${r} month${r > 1 ? "s" : ""} ago`;
    if (c > 0) return `${c} day${c > 1 ? "s" : ""} ago`;
    let T = [];
    return m > 0 && T.push(`${m} hour${m > 1 ? "s" : ""}`), v > 0 && T.push(`${v} minute${v > 1 ? "s" : ""}`), D > 0 && m === 0 && T.push(`${D} second${D > 1 ? "s" : ""}`), T.length === 0 ? "Just now" : T.join(" ") + " ago";
  };
  Ve();
  const l = Fe(), R = l.palette.mode === "dark", [N, o] = g(!1), [W, y] = g(""), [$, B] = g(""), [I, G] = g([]), [O, V] = g(!0), [M, F] = g(!1), [u, J] = g({
    sortColumn: "timestamp",
    sortOrder: "desc"
  }), [h, n] = g({
    startTime: null,
    endTime: null,
    userId: null,
    username: null,
    ip: null,
    sessionId: null,
    eventType: null,
    resource: null
  }), b = 50, { translate: P } = ce(), [Y, z] = g(!1), [me, q] = g(!1), [re, he] = g(null);
  ee(() => {
    const e = setTimeout(() => {
      B(W);
    }, 1e3);
    return () => clearTimeout(e);
  }, [W]);
  const be = we(
    () => [
      { field: "Sr. No.", label: "#", align: "left" },
      {
        field: "timestamp",
        label: "Time".toUpperCase(),
        sortable: !0,
        sortOrder: u.sortColumn === "timestamp" ? u.sortOrder : "asc",
        align: "left",
        render: (e) => /* @__PURE__ */ t(Ee, { title: A(e == null ? void 0 : e.timestamp), arrow: !0, placement: "top", children: /* @__PURE__ */ t(_, { className: "flex items-center h-full cursor-pointer", children: C(e == null ? void 0 : e.timestamp).format("DD/MM/YYYY hh:mm:ss A") }) })
      },
      {
        field: "session_id",
        label: "Session ID".toUpperCase(),
        align: "left",
        render: (e) => /* @__PURE__ */ t(E, { variant: "caption", className: "font-mono opacity-70", children: (e == null ? void 0 : e.session_id) || "N/A" })
      },
      {
        field: "user_id",
        label: "User ID".toUpperCase(),
        sortable: !0,
        sortOrder: u.sortColumn === "user_id" ? u.sortOrder : "asc",
        align: "left",
        render: (e) => /* @__PURE__ */ t(E, { variant: "body2", className: "font-bold", sx: { color: l.palette.text.primary }, children: (e == null ? void 0 : e.user_id) || "System" })
      },
      {
        field: "resource",
        label: "Resource".toUpperCase(),
        sortable: !0,
        sortOrder: u.sortColumn === "resource" ? u.sortOrder : "asc",
        align: "left",
        render: (e) => /* @__PURE__ */ t(_, { className: "max-w-xs truncate font-mono text-[0.7rem] opacity-80", title: e == null ? void 0 : e.resource, children: (e == null ? void 0 : e.resource) || "N/A" })
      },
      {
        field: "Actions",
        label: "View Details".toUpperCase(),
        align: "center"
      }
    ],
    [u]
  ), fe = Ie(
    (e) => [
      {
        label: "",
        icon: /* @__PURE__ */ t(w, { icon: Pe, size: "lg", title: "View Event Details" }),
        onClick: () => {
          he(e), q(!0);
        },
        iconColor: l.palette.primary.main,
        backgroundColor: X(l.palette.primary.main, 0.1),
        hoverBackgroundColor: l.palette.primary.main,
        hoverIconColor: "white",
        borderColor: l.palette.primary.main
      },
      {
        label: "Trace Detailed Session Logs",
        icon: /* @__PURE__ */ t(w, { icon: Ye, size: "lg", title: "Filter Activity Analytics by this Session ID" }),
        onClick: () => {
          if (e.session_id) {
            const i = window.location.origin + window.location.pathname.split("/medplat/")[0];
            let s = {};
            try {
              e.attributes && (s = JSON.parse(e.attributes));
            } catch {
            }
            e.user_id && (s.user_id = e.user_id);
            const a = `&attributes=${encodeURIComponent(JSON.stringify(s))}`, p = `${i}/medplat/manage/activityAnalytics?sessionId=${e.session_id}${a}`;
            window.open(p, "_blank");
          } else
            k({ message: "No Session ID available for this log", type: "warning" });
        },
        iconColor: l.palette.secondary.main,
        backgroundColor: X(l.palette.secondary.main, 0.1),
        hoverBackgroundColor: l.palette.secondary.main,
        hoverIconColor: "white",
        borderColor: l.palette.secondary.main
      }
    ],
    [l]
  ), ve = async (e) => {
    const i = u.sortColumn === e.field && u.sortOrder === "asc" ? "desc" : "asc";
    J({ sortColumn: e.field, sortOrder: i });
  }, ae = () => {
    F(!M);
  }, ge = () => {
    n({
      startTime: null,
      endTime: null,
      userId: null,
      username: null,
      ip: null,
      sessionId: null,
      eventType: null,
      resource: null
    }), y(""), F(!1);
  };
  async function ye(e, i) {
    var s;
    try {
      i && z(!0);
      const a = {
        limit: e.limit,
        offset: e.offset,
        userId: h.userId || null,
        ip: h.ip || null,
        sessionId: h.sessionId || null,
        eventType: h.eventType || null,
        resource: h.resource || null,
        startTime: h.startTime ? C(h.startTime).startOf("day").valueOf() : null,
        endTime: h.endTime ? C(h.endTime).endOf("day").valueOf() : null,
        sortBy: u.sortColumn,
        sortOrder: u.sortOrder
      }, p = await je(
        {
          code: "GET_SECURITY_AUDIT_LOGS",
          parameters: a
        },
        { showLoader: !1 }
      ), r = (((s = p == null ? void 0 : p.data) == null ? void 0 : s.result) || []).map((c) => {
        let m = null;
        if (c.attributes)
          try {
            m = JSON.parse(c.attributes);
          } catch {
          }
        return { ...c, parsedAttributes: m };
      });
      return i && z(!1), r;
    } catch (a) {
      return k({ message: `Error fetching logs: ${a.message}`, type: "error" }), z(!1), [];
    }
  }
  const {
    data: H,
    fetchNextPage: xe,
    hasNextPage: le
  } = Se({
    key: [
      "security_audit_logs",
      $,
      u.sortOrder,
      u.sortColumn,
      h,
      N
    ],
    queryFn: ({ pageParam: e }) => {
      const i = !(e != null && e.offset) || (e == null ? void 0 : e.offset) === 0;
      return ye(e, i);
    },
    limit: b
  });
  ee(() => {
    var e;
    const i = ((e = H == null ? void 0 : H.pages) == null ? void 0 : e.flat()) || [];
    V(i.length > 0 ? le : !1), G(i);
  }, [H, le]);
  const [oe, Q] = g(!1), Ae = async () => {
    try {
      let e = function(r) {
        const c = new ArrayBuffer(r.length), m = new Uint8Array(c);
        for (let v = 0; v !== r.length; ++v) m[v] = r.charCodeAt(v) & 255;
        return c;
      };
      if (I.length === 0) {
        k({ message: "No data to export", type: "warning" });
        return;
      }
      Q(!0);
      const i = [
        ["SECURITY AUDIT LOGS REPORT"],
        [`Server Instance: ${window.location.hostname || "NA"}`],
        [],
        // blank spacer row
        // Table Headers
        [
          "No.",
          "TIME",
          "EVENT CATEGORY",
          "EVENT TYPE",
          "SEVERITY",
          "USER ID",
          "USERNAME",
          "NAME",
          "ROLE ID",
          "IP ADDRESS",
          "SESSION ID",
          "HTTP METHOD",
          "RESOURCE",
          "RESPONSE CODE",
          "USER AGENT"
        ]
      ];
      I.forEach((r, c) => {
        var m, v, D, T, U;
        i.push([
          c + 1,
          C(r == null ? void 0 : r.timestamp).format("DD/MM/YYYY hh:mm:ss A"),
          (r == null ? void 0 : r.event_category) || "NA",
          (r == null ? void 0 : r.event_type) || "NA",
          (r == null ? void 0 : r.severity) || "NA",
          (r == null ? void 0 : r.user_id) || "NA",
          ((m = r == null ? void 0 : r.parsedAttributes) == null ? void 0 : m.user_name) || "NA",
          ((v = r == null ? void 0 : r.parsedAttributes) == null ? void 0 : v.name) || "NA",
          ((D = r == null ? void 0 : r.parsedAttributes) == null ? void 0 : D.role_id) || "NA",
          ((T = r == null ? void 0 : r.parsedAttributes) == null ? void 0 : T.ip) || (r == null ? void 0 : r.ip_address) || "NA",
          (r == null ? void 0 : r.session_id) || "NA",
          (r == null ? void 0 : r.http_method) || "NA",
          (r == null ? void 0 : r.resource) || "NA",
          (r == null ? void 0 : r.response_code) || "NA",
          ((U = r == null ? void 0 : r.parsedAttributes) == null ? void 0 : U.user_agent) || (r == null ? void 0 : r.user_agent) || "NA"
        ]);
      });
      const s = j.utils.aoa_to_sheet(i), a = j.utils.book_new();
      j.utils.book_append_sheet(a, s, "Logs");
      const p = j.write(a, { bookType: "xlsx", type: "binary" });
      Ge.saveAs(new Blob([e(p)], { type: "application/octet-stream" }), `SecurityAuditLogs-${(/* @__PURE__ */ new Date()).getTime()}.xlsx`), Q(!1);
    } catch {
      Q(!1), k({ message: "Error in downloading excel", type: "error" });
    }
  }, ie = Je(), [se, K] = g(!1), Ne = async () => {
    try {
      if (I.length === 0) {
        k({ message: "No data to export", type: "warning" });
        return;
      }
      K(!0);
      const e = ["TIME", "CATEGORY", "TYPE", "USER ID", "USERNAME", "IP", "STATUS", "METHOD", "URI"], i = ["timeStr", "event_category", "event_type", "user_id", "username", "ip_address", "response_code", "http_method", "request_uri"], s = I.map((a) => {
        var p, r;
        return {
          timeStr: C(a.timestamp).format("DD/MM/YYYY hh:mm:ss A"),
          event_category: a.event_category || "NA",
          event_type: a.event_type || "NA",
          user_id: a.user_id || "NA",
          username: ((p = a.parsedAttributes) == null ? void 0 : p.user_name) || "NA",
          ip_address: ((r = a.parsedAttributes) == null ? void 0 : r.ip) || a.ip_address || "NA",
          response_code: a.response_code || "NA",
          http_method: a.http_method || "NA",
          request_uri: a.resource || "NA"
        };
      });
      ie({
        title: [
          "SECURITY AUDIT LOGS REPORT",
          `Server Instance: ${window.location.hostname || "NA"}`
        ],
        columns: e,
        keys: i,
        data: s,
        fileName: `AuditLogs-${(/* @__PURE__ */ new Date()).getTime()}`,
        headerText: "Security Audit Logs",
        footerText: "Audit Log Report",
        orientation: "landscape"
      }), K(!1);
    } catch (e) {
      K(!1), console.error(e), k({ message: "Error in downloading pdf", type: "error" });
    }
  }, Te = (e) => {
    var i, s, a, p, r, c, m;
    if (!e) return;
    const v = [
      { label: "User ID", value: String(e.user_id || "N/A") },
      { label: "Username", value: String(((i = e.parsedAttributes) == null ? void 0 : i.user_name) || "N/A") },
      { label: "Name", value: String(((s = e.parsedAttributes) == null ? void 0 : s.name) || "N/A") },
      { label: "Role ID", value: String(((a = e.parsedAttributes) == null ? void 0 : a.role_id) || "N/A") },
      { label: "Role Name", value: String(((p = e.parsedAttributes) == null ? void 0 : p.role_name) || "N/A") },
      { label: "Role Code", value: String(((r = e.parsedAttributes) == null ? void 0 : r.role_code) || "N/A") },
      { label: "Event Timestamp", value: C(e.timestamp).format("DD/MM/YYYY hh:mm:ss A") },
      { label: "Event Category", value: String(e.event_category || "N/A") },
      { label: "Event Type", value: String(e.event_type || "N/A") },
      { label: "Severity", value: String(e.severity || "N/A") },
      { label: "IP Address", value: String(((c = e.parsedAttributes) == null ? void 0 : c.ip) || e.ip_address || "N/A") },
      { label: "Session ID", value: String(e.session_id || "N/A") },
      { label: "HTTP Method", value: String(e.http_method || "N/A") },
      { label: "Request URI", value: String(e.resource || "N/A") },
      { label: "Response Code", value: String(e.response_code || "N/A") },
      { label: "Server Instance", value: String(window.location.hostname || "N/A") },
      { label: "User Agent", value: String(((m = e.parsedAttributes) == null ? void 0 : m.user_agent) || e.user_agent || "N/A") }
    ];
    ie({
      columns: ["Field", "Value"],
      keys: ["label", "value"],
      data: v,
      fileName: `AuditLog_Detail_${e.id || (/* @__PURE__ */ new Date()).getTime()}`,
      headerText: `Security Audit Log - Entry #${e.id || ""}`,
      footerText: `Generated on ${(/* @__PURE__ */ new Date()).toLocaleString()}`,
      orientation: "portrait"
    });
  }, _e = (e) => {
    var i, s, a, p, r, c, m, v, D, T, U, ne, de;
    return e ? (C(e.timestamp).format("DD/MM/YYYY hh:mm:ss A"), e.event_category, e.event_type, e.severity, e.user_id, (i = e.parsedAttributes) == null || i.user_name, (s = e.parsedAttributes) == null || s.name, (a = e.parsedAttributes) == null || a.role_id, (p = e.parsedAttributes) == null || p.role_name, (r = e.parsedAttributes) == null || r.role_code, (c = e.parsedAttributes) != null && c.ip || e.ip_address, e.session_id, e.http_method, e.resource, e.response_code, /* @__PURE__ */ x(d, { container: !0, spacing: 2, children: [
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Event Category", value: e.event_category }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Event Type", value: e.event_type }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "User ID", value: e.user_id }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Username", value: ((m = e.parsedAttributes) == null ? void 0 : m.user_name) || "N/A" }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Name", value: ((v = e.parsedAttributes) == null ? void 0 : v.name) || "N/A" }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Role ID", value: ((D = e.parsedAttributes) == null ? void 0 : D.role_id) || "N/A" }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Role Name", value: ((T = e.parsedAttributes) == null ? void 0 : T.role_name) || "N/A" }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Role Code", value: ((U = e.parsedAttributes) == null ? void 0 : U.role_code) || "N/A" }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "HTTP Method", value: e.http_method }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Resource", value: e.resource }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Response Code", value: e.response_code }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Severity", value: e.severity }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "IP Address", value: ((ne = e.parsedAttributes) == null ? void 0 : ne.ip) || e.ip_address || "N/A" }) }),
      /* @__PURE__ */ t(d, { size: 6, children: /* @__PURE__ */ t(f, { label: "Timestamp", value: C(e.timestamp).format("DD/MM/YYYY hh:mm:ss A") }) }),
      /* @__PURE__ */ t(d, { size: 12, children: /* @__PURE__ */ t(f, { label: "Session ID", value: e.session_id || "N/A" }) }),
      /* @__PURE__ */ t(d, { size: 12, children: /* @__PURE__ */ t(f, { label: "User Agent", value: ((de = e.parsedAttributes) == null ? void 0 : de.user_agent) || e.user_agent || "N/A" }) })
    ] })) : null;
  }, f = ({ label: e, value: i, isCode: s }) => /* @__PURE__ */ x(_, { sx: { mb: 1, borderBottom: `1px solid ${l.palette.divider}`, pb: 0.5 }, children: [
    /* @__PURE__ */ t(E, { variant: "caption", sx: { color: l.palette.text.secondary, textTransform: "uppercase", fontWeight: "bold", fontSize: "0.65rem" }, children: e }),
    /* @__PURE__ */ t(
      E,
      {
        variant: "body2",
        sx: {
          color: l.palette.text.primary,
          wordBreak: "break-word",
          whiteSpace: s ? "pre-wrap" : "normal",
          fontFamily: s ? "monospace" : "inherit",
          fontSize: s ? "0.75rem" : "0.875rem"
        },
        children: String(i || "N/A")
      }
    )
  ] });
  return /* @__PURE__ */ x(d, { className: "w-[98%] mt-4", children: [
    /* @__PURE__ */ x(
      d,
      {
        container: !0,
        spacing: 2,
        className: "mb-4 justify-between items-center",
        children: [
          /* @__PURE__ */ t(d, { size: { xs: 12, md: 4 }, children: /* @__PURE__ */ t(
            E,
            {
              variant: "h6",
              sx: { fontWeight: "bold", color: l.palette.primary.main, textTransform: "uppercase" },
              children: P("Security Audit Logs")
            }
          ) }),
          /* @__PURE__ */ x(d, { size: { xs: 12, md: 8 }, className: "flex flex-col md:flex-row gap-3 justify-end items-center", children: [
            /* @__PURE__ */ t("div", { className: "flex items-center gap-3 w-full md:w-auto", children: /* @__PURE__ */ t(
              ke,
              {
                color: "primary",
                onClick: () => o((e) => !e),
                className: "rounded-xl border border-slate-200 dark:border-slate-800 shadow-sm",
                sx: {
                  backgroundColor: X(l.palette.primary.main, 0.1),
                  width: 40,
                  height: 40,
                  "&:hover": { backgroundColor: l.palette.primary.main, color: "white" }
                },
                children: /* @__PURE__ */ t(w, { icon: ze, className: "text-sm" })
              }
            ) }),
            /* @__PURE__ */ t("div", { className: "flex items-center gap-3", children: /* @__PURE__ */ x("div", { className: `flex items-center rounded-2xl p-1 shadow-sm transition-all border ${R ? "bg-slate-900 border-slate-800" : "bg-white border-slate-200"}`, children: [
              /* @__PURE__ */ x(
                "button",
                {
                  disabled: se || Y,
                  onClick: Ne,
                  className: `px-4 py-2 rounded-xl transition-all flex items-center gap-2 text-xs font-black uppercase tracking-wider ${R ? "text-slate-400 hover:text-slate-100 hover:bg-slate-800" : "text-slate-600 hover:text-red-600 hover:bg-slate-50"}`,
                  children: [
                    se ? /* @__PURE__ */ t(ue, { size: 14, sx: { color: "inherit" } }) : /* @__PURE__ */ t(w, { icon: pe }),
                    "Pdf"
                  ]
                }
              ),
              /* @__PURE__ */ x(
                "button",
                {
                  disabled: oe || Y,
                  onClick: Ae,
                  className: `px-4 py-2 rounded-xl transition-all flex items-center gap-2 text-xs font-black uppercase tracking-wider ml-1 ${R ? "bg-slate-800 text-slate-100 hover:bg-slate-700" : "bg-[#243A50] text-white hover:bg-[#1a2b3c]"}`,
                  children: [
                    oe ? /* @__PURE__ */ t(ue, { size: 14, sx: { color: "inherit" } }) : /* @__PURE__ */ t(w, { icon: Ue }),
                    "Excel Data"
                  ]
                }
              )
            ] }) })
          ] })
        ]
      }
    ),
    /* @__PURE__ */ t(
      De,
      {
        columns: be,
        tableData: I,
        actions: fe,
        paginationConfig: {
          pagination: !0,
          paginationType: "infinite-scroll",
          rowsPerPageInTable: b,
          hasMore: O,
          loadMore: () => O && xe({ cancelRefetch: !1 })
        },
        isLoading: Y,
        handleSort: ve
      }
    ),
    /* @__PURE__ */ t(
      Ce,
      {
        title: "Audit Filter",
        resetButtonLabel: "Reset",
        onResetClick: ge,
        FormBody: qe,
        handleOverlayState: ae,
        overlayOpen: M,
        dataTestId: "security-audit-log-filter",
        ModalProps: {
          sx: {
            "& .MuiDrawer-paper": {
              backgroundColor: l.palette.background.paper,
              color: l.palette.text.primary,
              "& .p-2\\.5": {
                backgroundColor: l.palette.background.paper,
                borderBottom: `1px solid ${l.palette.divider}`,
                color: l.palette.primary.main,
                fontWeight: "bold",
                letterSpacing: "1px"
              }
            }
          }
        },
        formProps: {
          filter: h,
          setFilter: n,
          handleOverlayState: ae
        }
      }
    ),
    /* @__PURE__ */ x(
      Re,
      {
        open: me,
        onClose: () => q(!1),
        maxWidth: "sm",
        fullWidth: !0,
        PaperProps: {
          sx: {
            backgroundColor: l.palette.background.paper,
            color: l.palette.text.primary
          }
        },
        children: [
          /* @__PURE__ */ t($e, { sx: { borderBottom: `1px solid ${l.palette.divider}`, fontWeight: "bold", color: l.palette.primary.main }, children: "Log Entry Details" }),
          /* @__PURE__ */ t(Oe, { dividers: !0, sx: { borderColor: l.palette.divider }, children: /* @__PURE__ */ t(_, { className: "p-2", children: _e(re) }) }),
          /* @__PURE__ */ x(_, { sx: { p: 2, display: "flex", justifyContent: "flex-end", gap: 2 }, children: [
            /* @__PURE__ */ t(
              te,
              {
                onClick: () => Te(re),
                variant: "outlined",
                color: "primary",
                startIcon: /* @__PURE__ */ t(w, { icon: pe }),
                sx: { borderRadius: "12px" },
                children: "Download PDF"
              }
            ),
            /* @__PURE__ */ t(te, { onClick: () => q(!1), variant: "contained", color: "primary", sx: { borderRadius: "12px" }, children: "Close" })
          ] })
        ]
      }
    )
  ] });
}
export {
  bt as default
};
//# sourceMappingURL=SecurityAuditLogList-DHTcOtbx-VvwDlRuu.js.map
