import { t as React, r as reactExports, b8 as SmetaModalsButtonsContext, j as jsxRuntimeExports, b9 as SectionDocuments, a7 as TabItem, ab as formEdit, G as Grid, aI as Tabs } from "./index-D15x63tD.js";
function DialogDocTabs({ props, smetaModalId = "" }) {
  const buttonsRef = React.useRef([]);
  const documents = React.useRef();
  const mainBlock = React.useRef();
  const tabPanel = React.useRef(null);
  const [content, setContent] = React.useState();
  const [multipage, setMultipage] = React.useState();
  const setButtons = reactExports.useContext(SmetaModalsButtonsContext);
  React.useEffect(() => {
    if (props.SelectDocument) {
      setMultipage({ Pages: props.SelectDocument });
    }
    setButtons({
      1: { label: "Выбрать", onClick: onSelect },
      2: {
        label: "Закрыть"
      }
    });
  }, [setButtons, tabPanel, props.SelectDocument]);
  React.useEffect(() => {
    if (multipage) {
      firstLoadContent();
    }
  }, [multipage]);
  function firstLoadContent() {
    if (multipage && multipage.Pages !== void 0) {
      const elements = [];
      multipage.Pages.forEach((Page, index) => {
        if (Page.DocCfgID) {
          const innerContent = index === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx(
            SectionDocuments,
            {
              id: props.SectionID,
              docName: Page.Name,
              DocCfgID: Page.DocCfgID,
              HideParams: props.CLSID === "{03338F11-FC1E-11D4-A605-0000E8D9CBDB}" || props.section ? false : true,
              SectionToolsJS: false,
              setRecorcCount: () => {
              },
              footerID: `footerData_${props.SectionID}`,
              buttonsContainerRef: buttonsRef.current[index]
            }
          ) : null;
          elements.push(
            /* @__PURE__ */ jsxRuntimeExports.jsx(TabItem, { style: { height: "100%", width: "100%" }, label: Page.Name, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { height: "100%", width: "100%" }, children: innerContent }) }, `multipage-${index}`)
          );
        }
      });
      setContent([...elements]);
      buttonsRef.current[0].current.classList.remove("hideButtonDiv");
      buttonsRef.current[0].current.classList.add("showButtonDiv");
      return;
    }
    setContent(/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {}));
  }
  function updatePage(ev) {
    if (ev.target !== null) return;
    if (content) {
      const id = tabPanel.current.selectedIndex ? tabPanel.current.selectedIndex : 0;
      const Page = multipage.Pages[id];
      const innerContent = /* @__PURE__ */ jsxRuntimeExports.jsx(
        SectionDocuments,
        {
          id: props.SectionID,
          DocCfgID: Page.DocCfgID,
          docName: Page.Name,
          HideParams: props.CLSID === "{03338F11-FC1E-11D4-A605-0000E8D9CBDB}" || props.section ? false : true,
          SectionToolsJS: false,
          setRecorcCount: () => {
          },
          footerID: `footerData_${props.SectionID}`,
          buttonsContainerRef: buttonsRef.current[id]
        }
      );
      content[id] = /* @__PURE__ */ jsxRuntimeExports.jsx(TabItem, { style: { height: "100%", width: "100%" }, label: Page.Name, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { style: { height: "100%", width: "100%" }, children: innerContent }) }, `multipage-${id}`);
      setContent([...content]);
      let oldButtonsBlock = mainBlock.current.querySelector(".showButtonDiv");
      oldButtonsBlock.classList.remove("showButtonDiv");
      oldButtonsBlock.classList.add("hideButtonDiv");
      buttonsRef.current[id].current.classList.remove("hideButtonDiv");
      buttonsRef.current[id].current.classList.add("showButtonDiv");
    }
  }
  async function onSelect() {
    if (props.onEdit) {
      const gridObject = tabPanel.current.nativeElement.getTabContent(tabPanel.current.selectedIndex).querySelector(".grid-main-parent").grid;
      if (!gridObject) return;
      props.onEdit({
        value: "",
        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
      });
      return;
    }
    if (props.RequestID) {
      const gridObject = tabPanel.current.nativeElement.getTabContent(tabPanel.current.selectedIndex).querySelector(".grid-main-parent").grid;
      await formEdit(
        "1",
        props.func,
        { Name: "ObjRef", Value: gridObject.source.getFieldTextSync("ID") },
        props.RequestID,
        props.from
      );
      return;
    }
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
    Grid,
    {
      id: "mainElement",
      ref: mainBlock,
      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: "35px"
            },
            children: /* @__PURE__ */ jsxRuntimeExports.jsx(
              Grid,
              {
                id: "mainElement",
                container: true,
                direction: "row",
                justifyContent: "flex-start",
                alignItems: "flex-start",
                style: { position: "relative", height: "100%" },
                children: multipage && multipage.Pages ? multipage.Pages.map((item, index) => {
                  return /* @__PURE__ */ jsxRuntimeExports.jsx(
                    Grid,
                    {
                      container: true,
                      direction: "row",
                      justifyContent: "flex-start",
                      alignItems: "center",
                      ref: (el) => {
                        buttonsRef.current[index] = { current: el };
                      },
                      className: "hideButtonDiv",
                      style: {
                        width: "100%",
                        height: "100%"
                      }
                    },
                    `buttoons-container_${index}`
                  );
                }) : null
              }
            )
          }
        ),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(
          Grid,
          {
            container: true,
            item: true,
            direction: "row",
            justifyContent: "flex-start",
            alignItems: "stretch",
            style: {
              height: "calc(100% - 35px - 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(
                    Tabs,
                    {
                      ref: tabPanel,
                      enableMouseWheelAction: true,
                      onChange: (ev) => updatePage(ev),
                      animation: "none",
                      style: {
                        height: "100%",
                        width: "100%",
                        backgroundColor: "s"
                      },
                      children: content
                    }
                  )
                }
              ) }),
              /* @__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 {
  DialogDocTabs as default
};
//# sourceMappingURL=DialogDocTabs-ExyRNCmU.js.map
