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