import { r as reactExports, b8 as SmetaModalsButtonsContext, ab as formEdit, j as jsxRuntimeExports, G as Grid, b9 as SectionDocuments, aE as ViewClass, ba as CheckMultiSelect } from "./index-D15x63tD.js";
function DialogDoc({ props, smetaModalId = "" }) {
  const buttonsRef = reactExports.useRef();
  const documents = reactExports.useRef();
  const setButtons = reactExports.useContext(SmetaModalsButtonsContext);
  reactExports.useEffect(() => {
    setButtons({
      1: { label: "Выбрать", onClick: onSelect },
      2: {
        label: "Закрыть"
      }
    });
  }, [setButtons, documents, props]);
  const getSelection = async (gridObject) => {
    if (!gridObject) return;
    if (gridObject.getMultiSelect().length === 0) {
      return;
    }
    return await CheckMultiSelect(gridObject, "ID", ",");
  };
  async function onSelect() {
    var _a;
    const gridObject = documents.current.querySelector("[rcsgrid_panel]").grid;
    if (!gridObject) return;
    const selection = await getSelection(gridObject);
    if (props.onEdit && props.setValue && props.setInputValue) {
      props.onEdit({
        value: gridObject.source.getFieldTextSync((_a = props == null ? void 0 : props.addInfo) == null ? void 0 : _a.FieldName) || "",
        tag: gridObject.source.getFieldTextSync("ID"),
        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,
        selection
      });
      return;
    }
    if (props.RequestID) {
      await formEdit(
        "1",
        props.func,
        { Name: "ObjRef", Value: gridObject.source.getFieldTextSync("ID"), Selection: selection },
        props.RequestID,
        props.from
      );
    }
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
    Grid,
    {
      id: "mainElement",
      container: true,
      direction: "column",
      justifyContent: "flex-start",
      alignItems: "stretch",
      style: { position: "relative", height: "100%" },
      children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          Grid,
          {
            item: true,
            style: {
              border: "1px solid #C8B58F",
              height: "40px"
            },
            children: /* @__PURE__ */ jsxRuntimeExports.jsx(
              Grid,
              {
                id: "mainElement",
                container: true,
                direction: "row",
                justifyContent: "flex-start",
                alignItems: "flex-start",
                style: { position: "relative", height: "100%" },
                children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                  Grid,
                  {
                    container: true,
                    direction: "row",
                    justifyContent: "flex-start",
                    alignItems: "center",
                    ref: buttonsRef,
                    style: { width: "100%", height: "100%" }
                  }
                )
              }
            )
          }
        ),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(
          Grid,
          {
            container: true,
            item: true,
            direction: "row",
            justifyContent: "flex-start",
            alignItems: "stretch",
            style: {
              height: "calc(100% - 40px - 21px)",
              width: "100%"
            },
            children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(Grid, { style: { height: "100%" }, container: true, direction: "row", justifyContent: "center", alignItems: "center", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                Grid,
                {
                  ref: documents,
                  style: {
                    height: "100%",
                    width: "100%",
                    borderLeft: "1px solid #C8B58F",
                    borderRight: "1px solid #C8B58F"
                  },
                  item: true,
                  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                    SectionDocuments,
                    {
                      id: props.SectionID,
                      docName: props.Value,
                      DocCfgID: props.ObjType || props.DocCfgID,
                      HideParams: props.CLSID === ViewClass.DocSite ? false : true,
                      SectionToolsJS: false,
                      PlaneView: props.PlaneView,
                      collapsedParams: props.PlaneView === "1" ? true : false,
                      setRecorcCount: () => {
                      },
                      footerID: `footerData_${props.SectionID}`,
                      buttonsContainerRef: buttonsRef,
                      disiableState: props.disiableState,
                      detailsOpen: props.detailsOpen,
                      ObjRef: props.ObjRef ? props.ObjRef : props.DocID ? props.DocID : void 0,
                      tree: {
                        CLSID: props.CLSID,
                        multiCheck: false,
                        Module: props.Module,
                        ObjType: props.ObjType,
                        SectionID: props.SectionID,
                        ObjRef: props.ObjRef ? props.ObjRef : props.DocID ? props.DocID : "0",
                        Info: "0",
                        UsedDate: "0",
                        Internal: "0"
                      }
                    }
                  )
                }
              ) }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                Grid,
                {
                  id: `footerData_${props.SectionID}`,
                  className: "css-11vzlf0-MuiGrid-root",
                  style: {
                    width: "100%",
                    paddingTop: "2px",
                    paddingLeft: "15px",
                    border: "1px solid #C8B58F",
                    borderTop: "0px",
                    height: "21px"
                  }
                }
              )
            ]
          }
        )
      ]
    }
  ) });
}
export {
  DialogDoc as default
};
//# sourceMappingURL=DialogDoc-BCKCegu0.js.map
