import { jsx as r, jsxs as e } from "react/jsx-runtime";
import "react";
import c from "prop-types";
import { Modal as w, Box as s, TableContainer as f, Paper as N, Table as v, TableHead as q, TableRow as d, TableCell as l, TableBody as T, Typography as n, Button as y, Stack as C } from "@mui/material";
import { showToast as u } from "@/common/toaster/toaster";
import { useTranslateProvider as x } from "@/common/languageTranslator/TranslationContext";
const D = ({ historyList: i, open: m, handleClose: h }) => {
  const p = (t) => t ? "Yes" : "No", g = (t) => {
    try {
      navigator.clipboard.writeText(t), u({
        message: "Query Copied",
        type: "success"
      });
    } catch (o) {
      console.error(o), u({
        message: "Error in copying query",
        type: "error"
      });
    }
  }, b = (t) => {
    const o = {
      year: "numeric",
      month: "2-digit",
      day: "2-digit",
      hour: "2-digit",
      minute: "2-digit",
      second: "2-digit",
      hour12: !0
    };
    return new Date(t).toLocaleDateString("en-GB", o);
  }, { translate: a } = x();
  return /* @__PURE__ */ r(w, { open: m, onClose: h, "data-testid": "showqueryhistory-modal", className: "z-[1301]", children: /* @__PURE__ */ e(s, { className: "absolute top-[10%] left-1/2 transform -translate-x-1/2 w-3/5 bg-white container-fluid", children: [
    /* @__PURE__ */ e(s, { className: "max-h-[360px] w-full overflow-y-auto overflow-x-hidden row", children: [
      /* @__PURE__ */ r(s, { className: "col-12 padding-left-right-0", children: /* @__PURE__ */ r(f, { component: N, children: /* @__PURE__ */ e(v, { "aria-label": "query history table", children: [
        /* @__PURE__ */ r(q, { children: /* @__PURE__ */ e(d, { children: [
          /* @__PURE__ */ r(l, { className: "w-[5%] text-left align-top", children: a("Version") }),
          /* @__PURE__ */ r(l, { className: "w-[30%] text-left align-top", children: a("Description") }),
          /* @__PURE__ */ r(l, { className: "w-[65%] text-left align-top", children: a("Query") })
        ] }) }),
        /* @__PURE__ */ r(T, { children: i && i.length > 0 ? i.map((t, o) => /* @__PURE__ */ e(d, { "data-testid": `showqueryhistory-tablerow-${o}`, children: [
          /* @__PURE__ */ r(
            l,
            {
              className: " text-left align-top",
              "data-testid": `showqueryhistory-tablecell-version-${o}`,
              children: i.length - o
            }
          ),
          /* @__PURE__ */ e(
            l,
            {
              className: " text-left align-top",
              "data-testid": `showqueryhistory-tablecell-description-${o}`,
              children: [
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("Code"),
                    ":"
                  ] }),
                  " ",
                  t.oldCode || "N/A"
                ] }),
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("Date Time"),
                    ":"
                  ] }),
                  " ",
                  b(t.action_tstamp_tx)
                ] }),
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("description"),
                    ":"
                  ] }),
                  " ",
                  t.oldDescription || "N/A"
                ] }),
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("Status"),
                    ":"
                  ] }),
                  " ",
                  t.oldState || "N/A"
                ] }),
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("Parameters"),
                    ":"
                  ] }),
                  " ",
                  t.oldParams || "N/A"
                ] }),
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("Returns Result Set"),
                    ":"
                  ] }),
                  " ",
                  p(t.oldReturnsResultSet)
                ] }),
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("Is Public"),
                    ":"
                  ] }),
                  " ",
                  p(t.oldIsPublic)
                ] }),
                /* @__PURE__ */ e(n, { variant: "body2", children: [
                  /* @__PURE__ */ e("strong", { children: [
                    a("CRUD Op"),
                    ":"
                  ] }),
                  t.action === "I" && "Insert",
                  t.action === "U" && "Update",
                  t.action === "D" && "Delete",
                  t.action === "T" && "Truncate",
                  !t.action && "N/A"
                ] })
              ]
            }
          ),
          /* @__PURE__ */ e(
            l,
            {
              className: " text-left align-top",
              "data-testid": `showqueryhistory-tablecell-query-${o}`,
              children: [
                /* @__PURE__ */ r(
                  y,
                  {
                    variant: "contained",
                    color: "primary",
                    size: "small",
                    onClick: () => g(t.oldQuery),
                    "data-testid": `showqueryhistory-button-copyquery-${o}`,
                    children: a("Copy Query")
                  }
                ),
                /* @__PURE__ */ r(
                  n,
                  {
                    variant: "body2",
                    className: "whitespace-pre-wrap",
                    "data-testid": `showqueryhistory-typography-query-${o}`,
                    children: t.oldQuery
                  }
                )
              ]
            }
          )
        ] }, o + 1)) : /* @__PURE__ */ r(d, { children: /* @__PURE__ */ r(l, { colSpan: 3, align: "center", children: a("No queries History") }) }) })
      ] }) }) }),
      /* @__PURE__ */ r(s, { className: "col-12 padding-left-right-0 flex justify-end p-2" })
    ] }),
    /* @__PURE__ */ r(
      C,
      {
        direction: "row",
        spacing: 2,
        justifyContent: "flex-end",
        mt: 1,
        mr: 2,
        mb: 1,
        "data-testid": "showqueryhistory-stack",
        children: /* @__PURE__ */ r(
          y,
          {
            variant: "contained",
            color: "secondary",
            onClick: h,
            "data-testid": "showqueryhistory-button-close",
            children: /* @__PURE__ */ r(n, { variant: "body2", children: a("Close") })
          }
        )
      }
    )
  ] }) });
};
D.propTypes = {
  historyList: c.any,
  open: c.any,
  handleClose: c.any
};
export {
  D as default
};
//# sourceMappingURL=ShowQueryHistory-BDN0tzHg.js.map
