import { aj as requireInteropRequireDefault, ak as requireCreateSvgIcon, al as requireJsxRuntime, am as getDefaultExportFromCjs, t as React, j as jsxRuntimeExports, x as Grid2, V as isEmptyObject, d5 as Paper, cp as List, cm as ListItem, d6 as ListItemIcon, k as Checkbox, co as ListItemText, B as Button, ap as smetaModals, d7 as getLocalAuditParams, r as reactExports, ah as AxiosRequest, bM as SectionToolsJS, ax as SplitterLocal, aU as ContextMenu, d8 as DocColumnOption, af as parseColumns, cy as createRecordSource, cA as createGrid, I as IconButton, T as Tooltip, ct as Divider, d9 as ReactDOM, da as SaveIcon, ac as tokenProcessingTest } from "./index-D15x63tD.js";
import { L as LocalParams } from "./LocalParams-Dz-ktk1o.js";
/* empty css                            */
var ManageAccounts = {};
var hasRequiredManageAccounts;
function requireManageAccounts() {
  if (hasRequiredManageAccounts) return ManageAccounts;
  hasRequiredManageAccounts = 1;
  var _interopRequireDefault = requireInteropRequireDefault();
  Object.defineProperty(ManageAccounts, "__esModule", {
    value: true
  });
  ManageAccounts.default = void 0;
  var _createSvgIcon = _interopRequireDefault(/* @__PURE__ */ requireCreateSvgIcon());
  var _jsxRuntime = requireJsxRuntime();
  ManageAccounts.default = (0, _createSvgIcon.default)([/* @__PURE__ */ (0, _jsxRuntime.jsx)("circle", {
    cx: "10",
    cy: "8",
    r: "4"
  }, "0"), /* @__PURE__ */ (0, _jsxRuntime.jsx)("path", {
    d: "M10.67 13.02c-.22-.01-.44-.02-.67-.02-2.42 0-4.68.67-6.61 1.82-.88.52-1.39 1.5-1.39 2.53V20h9.26c-.79-1.13-1.26-2.51-1.26-4 0-1.07.25-2.07.67-2.98M20.75 16c0-.22-.03-.42-.06-.63l1.14-1.01-1-1.73-1.45.49c-.32-.27-.68-.48-1.08-.63L18 11h-2l-.3 1.49c-.4.15-.76.36-1.08.63l-1.45-.49-1 1.73 1.14 1.01c-.03.21-.06.41-.06.63s.03.42.06.63l-1.14 1.01 1 1.73 1.45-.49c.32.27.68.48 1.08.63L16 21h2l.3-1.49c.4-.15.76-.36 1.08-.63l1.45.49 1-1.73-1.14-1.01c.03-.21.06-.41.06-.63M17 18c-1.1 0-2-.9-2-2s.9-2 2-2 2 .9 2 2-.9 2-2 2"
  }, "1")], "ManageAccounts");
  return ManageAccounts;
}
var ManageAccountsExports = /* @__PURE__ */ requireManageAccounts();
const ManageAccountsIcon = /* @__PURE__ */ getDefaultExportFromCjs(ManageAccountsExports);
function AuditOptions({ data, setAuditOptions, smetaModalId = "" }) {
  const [fullData, setFullData] = React.useState({ events: {}, iplist: {} });
  const [jsx2, setJsx] = React.useState();
  React.useEffect(() => {
    setFullData(data);
  }, [data]);
  React.useEffect(() => {
    setJsx(
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid2, { children: [
        "Фиксируемые события:",
        customList(fullData.events, "events"),
        "Запретить запуск с рабочих станций:",
        customList(fullData.iplist, "iplist")
      ] })
    );
  }, [fullData]);
  const customList = (items, keyid) => {
    if (!isEmptyObject(items))
      return /* @__PURE__ */ jsxRuntimeExports.jsx(Paper, { sx: { height: 160, overflow: "auto", mb: 1 }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(List, { dense: true, component: "div", role: "list", children: items.items.map((value, index) => {
        const labelId = `transfer-list-item-${value.Text}-label`;
        return /* @__PURE__ */ jsxRuntimeExports.jsxs(ListItem, { role: "listitem", sx: { height: "30px" }, children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(ListItemIcon, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
            Checkbox,
            {
              checked: value.Checked === "1",
              tabIndex: -1,
              disableRipple: true,
              onChange: handleChangeCheckBox,
              id: `${keyid},${index}`,
              inputProps: {
                "aria-labelledby": labelId
              }
            }
          ) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(ListItemText, { id: labelId, primary: value.Text })
        ] }, value.Text);
      }) }) });
  };
  function handleChangeCheckBox(event) {
    let key = event.currentTarget.id.split(","), index, obj = fullData;
    index = key[1];
    key = key[0];
    obj[key].items[index].Checked = obj[key].items[index].Checked === "1" ? "0" : "1";
    setFullData(obj);
    setJsx(
      /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid2, { children: [
        "Фиксируемые события:",
        customList(obj.events, "events"),
        "Запретить запуск с рабочих станций:",
        customList(obj.iplist, "iplist")
      ] })
    );
  }
  function onSelect() {
    let bites = 0, arrOfIp = [];
    for (const [key, value] of Object.entries(fullData.events.items)) {
      if (value.Checked === "1") {
        if (key === "0") {
          bites += 1;
        } else {
          bites += Math.pow(2, Number(key));
        }
      }
    }
    for (const value of Object.values(fullData.iplist.items)) {
      if (value.Checked === "1") {
        delete value.Checked;
        arrOfIp.push(value);
      }
    }
    setAuditOptions(bites, arrOfIp);
    smetaModals.close(smetaModalId);
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid2, { container: true, sx: { flexDirection: "column", height: "100%" }, children: [
    jsx2,
    /* @__PURE__ */ jsxRuntimeExports.jsx(Grid2, { sx: { height: "51px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
      Grid2,
      {
        container: true,
        sx: {
          flexDirection: "row",
          justifyContent: "flex-end",
          height: "100%",
          alignItems: "center"
        },
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button,
            {
              size: "small",
              style: { textTransform: "none", marginLeft: 10 },
              variant: "outlined",
              className: "button_Modal_Select",
              value: "12",
              onClick: onSelect,
              children: "Установить"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button,
            {
              size: "small",
              style: { textTransform: "none", marginLeft: 10 },
              variant: "outlined",
              className: "button_Modal_Close",
              value: "12",
              onClick: () => {
                smetaModals.close(smetaModalId);
              },
              children: "Закрыть"
            }
          )
        ]
      }
    ) })
  ] });
}
function UsersAudit() {
  const [portal, setPortal] = React.useState([]);
  const [recordCountText, setRecordCountText] = React.useState(`Число записей: 0`);
  const MainGridRef = React.useRef(null);
  const localParamsBox = React.useRef(null);
  const paramsData = React.useRef(getLocalAuditParams());
  reactExports.useEffect(() => {
    getAuditOptions("0");
  }, []);
  const openAuditOptionsDialog = (data) => {
    smetaModals.open(/* @__PURE__ */ jsxRuntimeExports.jsx(AuditOptions, { data, setAuditOptions }), {
      onSelect: () => {
      },
      style: { height: "500px" },
      Title: "Параметры отслеживания",
      blockResize: true,
      blockMaximize: true,
      hiddenButton: true
    });
  };
  function getAuditOptions(tune) {
    let params = /* @__PURE__ */ new Map();
    params.set("prefix", "audit").set("comand", "GetAuditOptions").set("tune", tune);
    return AxiosRequest(true, params);
  }
  function HandleToolButton() {
    let params = /* @__PURE__ */ new Map();
    params.set("prefix", "audit").set("comand", "HandleToolButton").set("WSM", "1");
    AxiosRequest(true, params).then((res) => {
      tokenProcessingTest(res);
    });
  }
  function setAuditOptions(event, data) {
    let params = /* @__PURE__ */ new Map();
    params.set("prefix", "audit").set("comand", "setAuditOptions");
    params.set("event", event);
    AxiosRequest(true, params, { locks: data });
  }
  function onHandleRequestDocuments(wsm) {
    return async function(request, load, wsmFromGrid) {
      let params = /* @__PURE__ */ new Map();
      params.set("prefix", "audit");
      params.set("comand", "HandleTable");
      if (wsmFromGrid) params.set("WSM", "1");
      const result = await AxiosRequest(load === void 0 ? true : load, params, request);
      return result;
    };
  }
  async function GetAuditParamValues(fieldName) {
    const params = /* @__PURE__ */ new Map();
    params.set("prefix", "audit").set("comand", "GetAuditParamValues").set("FieldName", fieldName);
    let json = await AxiosRequest(true, params);
    json = Object.values(json);
    if (json.length) {
      return json.map((item, index) => {
        return { label: item, id: index };
      });
    }
  }
  async function ApplyAuditParams(data) {
    const params = /* @__PURE__ */ new Map();
    params.set("prefix", "audit").set("comand", "ApplyAuditParams");
    Object.entries(data).forEach(([key, value]) => {
      if (value !== void 0 && value !== "") {
        params.set(key, value);
      }
    });
    return AxiosRequest(true, params);
  }
  async function onApplyClick() {
    if (localParamsBox) {
      const paramBox = localParamsBox.current.querySelector("#paramsBox");
      if (paramBox) await paramBox.apply();
    }
    createGridForAudit().then(async () => {
      const source = MainGridRef.current.grid.source;
      if (source.fields.length === 0) {
        source.active = false;
        await source.open();
      }
      if (source.fields && source.fields.length > 0 && source.fields[1].fieldName === MainGridRef.current.grid.columns.title[0].fieldName.toUpperCase()) {
        setCollumsForGrid(MainGridRef.current.grid, true);
        updGridSize();
      }
    });
  }
  function setCollumsForGrid(grid, needUp) {
    let Columns = [
      { Title: "Время", FieldName: "eventtime", Width: "100" },
      {
        Title: "Конфигурация",
        FieldName: "configname",
        Width: "100",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.CanGroup
      },
      {
        Title: "Организация",
        FieldName: "orgname",
        Width: "100",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.Hidden + DocColumnOption.CanGroup
      },
      {
        Title: "Пользователь",
        FieldName: "username",
        Width: "150",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.CanGroup
      },
      {
        Title: "IP-адрес",
        FieldName: "address",
        Width: "100",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.CanGroup
      },
      {
        Title: "Компьютер",
        FieldName: "computer",
        Width: "100",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.CanGroup
      },
      {
        Title: "Событие",
        FieldName: "eventtype",
        Width: "100",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.CanGroup
      },
      {
        Title: "Тип объекта",
        FieldName: "objecttype",
        Width: "100",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.CanGroup
      },
      { Title: "Значение объекта", FieldName: "objectid", Width: "100" },
      { Title: "Информация", FieldName: "eventinfo", Width: "100" },
      { Title: "Дополнительно", FieldName: "sender", Width: "100" },
      { Title: "Количество", FieldName: "countof", Width: "100" },
      { Title: "Версия клиента", FieldName: "clientver", Width: "100" },
      {
        Title: "Рабочий сервер",
        FieldName: "stimwebsrv",
        Width: "100",
        Options: DocColumnOption.Filterable + DocColumnOption.Sortable + DocColumnOption.CanGroup
      },
      { Title: "Продолжительность", FieldName: "endtime", Width: "100" }
    ];
    if (needUp) {
      Columns = Columns.map((value) => {
        return { ...value, FieldName: value.FieldName.toUpperCase() };
      });
    }
    if (Columns) {
      const columns = parseColumns(
        { Columns },
        {
          docOpts: true,
          widthMultiply: 1.33
        }
      );
      grid && grid.setColumns(columns, true);
      return columns;
    } else grid.defaultColumns = true;
  }
  async function createGridForAudit() {
    let source, grid, needUp = false;
    if (MainGridRef.current && MainGridRef.current.grid) {
      await MainGridRef.current.grid.refreshSource("!");
      setRecordCountText(`Число записей: ${MainGridRef.current.grid.source.recordCount}`);
    } else {
      source = new createRecordSource();
      source.onHandleRequest = onHandleRequestDocuments();
      MainGridRef.current.grid = new createGrid(MainGridRef.current);
      grid = MainGridRef.current.grid;
      grid.onRecordCountChange = (me) => {
        setRecordCountText(`Число записей: ${me.source.recordCount}`);
      };
      await source.open();
      if (source.fields && source.fields.length > 0 && source.fields[1].fieldName === source.fields[1].fieldName.toUpperCase()) {
        needUp = true;
      }
      setCollumsForGrid(grid, needUp);
      await grid.setSource(source);
      grid.refreshSource("!");
      grid.setOptions(2);
      setRecordCountText(`Число записей: ${source.recordCount}`);
      ButtonsForAudit([
        {
          ID: "SaveToFile",
          Hint: "Сохранить текущую выборку в файл",
          Image: /* @__PURE__ */ jsxRuntimeExports.jsx(SaveIcon, { fontSize: "medium" })
        },
        {
          ID: "AuditOptions",
          Hint: "Параметры отслеживания",
          Image: /* @__PURE__ */ jsxRuntimeExports.jsx(ManageAccountsIcon, { fontSize: "medium" })
        },
        {
          Caption: "-"
        }
      ]);
    }
  }
  function ButtonsForAudit(json) {
    let items = [], iconbutton, buttonsBlock = document.getElementById("buttons_for_section-34");
    if (json !== void 0 && !isEmptyObject(json) && buttonsBlock) {
      for (const [key, value] of Object.entries(json)) {
        if (value.Caption !== "-") {
          let hintForButton = value.Hint;
          iconbutton = /* @__PURE__ */ jsxRuntimeExports.jsxs(
            IconButton,
            {
              id: value.ID,
              variant: "text",
              style: {
                width: value.Caption === void 0 ? "40px" : `${value.Width}px`,
                //value.Width === undefined ||
                fontSize: "13px"
              },
              component: "span",
              index: key,
              onClick: () => {
                clickSectionButton(value.ID);
              },
              children: [
                value.Image,
                value.Caption === void 0 ? "" : ` ${value.Caption}`
              ]
            },
            key
          );
          items.push(
            /* @__PURE__ */ jsxRuntimeExports.jsx(Grid2, { children: value.Hint ? /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip, { title: hintForButton, arrow: true, children: iconbutton }) : iconbutton }, key)
          );
        } else {
          items.push(/* @__PURE__ */ jsxRuntimeExports.jsx(Divider, { orientation: "vertical", flexItem: true, sx: { mr: 0.5 } }, key));
        }
      }
      setPortal(ReactDOM.createPortal(items, buttonsBlock));
    }
  }
  function clickSectionButton(id) {
    switch (id) {
      case "SaveToFile": {
        HandleToolButton();
        break;
      }
      case "AuditOptions": {
        getAuditOptions("1").then(openAuditOptionsDialog);
        break;
      }
    }
  }
  function updGridSize() {
    MainGridRef.current.grid.updateGridSize();
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Grid2, { container: true, sx: { height: "100%", flexDirection: "column" }, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(SectionToolsJS, { ID: "-34" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: portal }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(
      SplitterLocal,
      {
        style: {
          width: "100%",
          borderTop: "1px solid rgb(208, 208, 208)",
          flex: "1 1"
        },
        orientation: "vertical",
        onExpand: updGridSize,
        onCollapse: updGridSize,
        onResizeEnd: updGridSize,
        sizeSecondary: "20%",
        primaryIndex: 1,
        blockResize: false,
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: localParamsBox, style: { width: "100%", height: "calc(100% - 30px)" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(LocalParams, { onApply: ApplyAuditParams, onDropDownList: GetAuditParamValues, data: paramsData.current }) }),
            /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { width: "100%", height: "30px" }, children: /* @__PURE__ */ jsxRuntimeExports.jsx("button", { onClick: onApplyClick, className: "applyButton", children: "Применить" }) })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(ContextMenu, { for: "grid", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: MainGridRef }) })
        ]
      }
    ),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Grid2, { sx: { height: "30px", backgroundColor: "#eeeeee", p: 1 }, children: recordCountText })
  ] });
}
export {
  UsersAudit as default
};
//# sourceMappingURL=UsersAudit-CBH-hEaW.js.map
