import { t as React, r as reactExports, a6 as GridLoader, j as jsxRuntimeExports, aG as styles, ax as SplitterLocal, aU as ContextMenu, aV as getDefaultMenu, a3 as Tree, B as Button, ao as cn, aW as makeCallBacks, ap as smetaModals, aX as updateVisibleGrids, ab as formEdit } from "./index-D15x63tD.js";
function DialogPaytypes({ props, smetaModalId = "" }) {
  const treeRef = React.useRef();
  const gridPanelRef = React.useRef();
  const [mainGrid, setMainGrid] = reactExports.useState();
  const [collapsedTree, setCollapsedTree] = reactExports.useState();
  const [selectedRecordID, setSelectedRecordID] = reactExports.useState();
  reactExports.useEffect(() => {
    GridLoader(
      gridPanelRef.current,
      { ...props, Module: "paytypes", ObjType: "2290" },
      {
        setSelectedRecord: setSelectedRecordID,
        settings: true
      }
    ).then((res) => {
      setMainGrid(res);
    });
  }, []);
  reactExports.useEffect(() => {
    var _a;
    if (selectedRecordID === "") (_a = treeRef.current) == null ? void 0 : _a.updateMultiCheckState("0");
    if (selectedRecordID) treeRef.current.updateMultiCheckState(selectedRecordID);
  }, [selectedRecordID]);
  function refreshGrid() {
    updateVisibleGrids();
  }
  async function onSelect() {
    if (!mainGrid) return;
    if (props.onEdit && props.setValue && props.setInputValue) {
      props.onEdit({
        value: "",
        tag: selectedRecordID,
        name: props.Name,
        record: props.record,
        textchanged: "0",
        setValue: props.setValue,
        setInputValue: props.setInputValue,
        type: props.Module,
        requestId: props.RequestID,
        addInfo: props.addInfo,
        docID: true
      });
      if (props.NewModalWindow) smetaModals.close(smetaModalId);
      return;
    }
    if (props.RequestID) {
      await formEdit("1", props.func, { Name: "ObjRef", Value: selectedRecordID }, props.RequestID, props.from);
    }
    if (props.NewModalWindow) smetaModals.close(smetaModalId);
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.mainDialogBlock, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.fullDialogFlexContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
      SplitterLocal,
      {
        onResizeEnd: refreshGrid,
        onCollapse: refreshGrid,
        onExpand: refreshGrid,
        orientation: "vertical",
        style: {
          width: "100%",
          height: "100%"
        },
        transitionDuration: 251,
        primaryIndex: 0,
        collapsed: collapsedTree,
        sizeSecondary: "20%",
        hideButtons: true,
        children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: styles.fullDialogSpaceContainer, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
            ContextMenu,
            {
              for: "paytypes",
              Menu: getDefaultMenu("paytypes"),
              children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                "div",
                {
                  id: `rcgrid_panel`,
                  style: {
                    height: "100%",
                    width: "100%",
                    position: "relative"
                  },
                  ref: gridPanelRef
                }
              )
            }
          ) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "fullDialogSpaceContainer", children: mainGrid && /* @__PURE__ */ jsxRuntimeExports.jsx(
            Tree,
            {
              props: {
                MultiCheckSet: true,
                CheckSet: [1, 2],
                Module: "paytypes",
                ObjType: "2290",
                SectionID: props.SectionID,
                Info: "0",
                UsedDate: "0",
                ObjRef: "0",
                ref: treeRef
              }
            }
          ) })
        ]
      }
    ) }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: styles.dialogButtonsContainer, children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Button,
        {
          onClick: onSelect,
          size: "small",
          variant: "outlined",
          className: `${styles.dialogButton} button_Modal_Select ${cn(
            props.Buttons && (props.Buttons & 1) === 0 && "hidden"
          )}`,
          value: "1",
          children: "Выбрать"
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Button,
        {
          size: "small",
          variant: "outlined",
          value: "2",
          className: `${styles.dialogButton} button_Modal_Close`,
          onClick: () => {
            makeCallBacks().then((callBackResp) => {
              if (props.NewModalWindow && callBackResp) smetaModals.close(smetaModalId);
            });
          },
          children: "Закрыть"
        }
      )
    ] })
  ] });
}
export {
  DialogPaytypes as default
};
//# sourceMappingURL=DialogPayTypes-C6mpikMx.js.map
