import { a0 as smetaStore, aY as configEnabledAtom, r as reactExports, a6 as GridLoader, j as jsxRuntimeExports, aG as styles, aU as ContextMenu, aV as getDefaultMenu, B as Button, ao as cn, ap as smetaModals, ab as formEdit } from "./index-D15x63tD.js";
function DialogDistractions({ props, smetaModalId }) {
  const configEnable = smetaStore.get(configEnabledAtom);
  const gridPanelRef = reactExports.useRef();
  const [mainGrid, setMainGrid] = reactExports.useState();
  const [selectedRecordID, setSelectedRecordID] = reactExports.useState();
  reactExports.useEffect(() => {
    GridLoader(
      gridPanelRef.current,
      { ...props, Module: "tables", ObjType: "2720" },
      {
        setSelectedRecord: setSelectedRecordID,
        distractions: true
      }
    ).then((res) => {
      res.grid.canModify = () => configEnable;
      setMainGrid(res);
      res.grid.onEditField = onEditField;
    });
  }, []);
  async function onEditField(editData) {
    const grid = gridPanelRef.current.grid;
    await grid.postSomeData("Color", {
      id: editData.tag,
      text: ""
    });
    await grid.postExicstedEditRec(true);
  }
  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.jsx(
      ContextMenu,
      {
        for: "distractions",
        Menu: getDefaultMenu("distractions"),
        children: /* @__PURE__ */ jsxRuntimeExports.jsx(
          "div",
          {
            id: `rcgrid_panel`,
            style: {
              height: "100%",
              width: "100%",
              position: "relative"
            },
            ref: gridPanelRef
          }
        )
      }
    ) }),
    /* @__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: () => {
            if (props.NewModalWindow) smetaModals.close(smetaModalId);
          },
          children: "Закрыть"
        }
      )
    ] })
  ] });
}
export {
  DialogDistractions as default
};
//# sourceMappingURL=DialogDistractions-r5QbDcRD.js.map
