import { r as reactExports, j as jsxRuntimeExports, bM as SectionToolsJS, E as useAtom, b7 as selectedSectionAtom, X as updateOptionsForUser, G as Grid, bG as SmetaTabs, bH as SmetaTabItem } from "./index-D15x63tD.js";
import SectionReports from "./SectionReports-CR4VT6wR.js";
import SectionDocumentsChose from "./SectionDocumentsChose-CWNMUy0u.js";
const SectionReportsAndDocuments = ({
  defaultButton,
  id,
  noSectionTools,
  onBreadCrumbClick,
  CLSID
}) => {
  const [selectedIndex, setSelectedIndex] = reactExports.useState(0);
  const [selectedView, setSelectedView] = reactExports.useState(false);
  const [seacrhSelected, setSearchSelected] = reactExports.useState({});
  const sectol = reactExports.useRef(/* @__PURE__ */ jsxRuntimeExports.jsx(SectionToolsJS, { ID: id }));
  const [selectedSection, setSelectedSection] = useAtom(selectedSectionAtom);
  const saveDocInfo = reactExports.useRef();
  const docAndReportsContainer = reactExports.useRef();
  const setDocsTabIndex = reactExports.useRef(null);
  reactExports.useLayoutEffect(() => {
    if (id === selectedSection.ID) {
      if (selectedSection.Who) {
        setSearchSelected(selectedSection);
        if (selectedSection.Who === "Reports") {
          setSelectedIndex(1);
          setSelectedView("report");
          updateOptionsForUser({
            Selected: {}
          });
        }
      }
    }
  }, [selectedSection]);
  const onTabIndexChange = (index) => {
    var _a;
    if (index === 1) {
      const selectData = { Name: "Отчёты" };
      setSelectedSection({ ...selectedSection, Selected: selectData });
      setSelectedView(true);
    } else {
      setSelectedSection({ ...selectedSection, Selected: saveDocInfo.current });
      setSelectedView(!!((_a = saveDocInfo.current) == null ? void 0 : _a.DocCfgID));
    }
  };
  const onSelect = (data = {}, view) => {
    saveDocInfo.current = data;
    setSelectedView(view);
    if (!view) setSelectedIndex(0);
    if (onBreadCrumbClick) onBreadCrumbClick();
  };
  const onTabReClick = (index) => {
    if (index !== 0) return;
    setSelectedSection({ ...selectedSection, Selected: {} });
    setDocsTabIndex.current();
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
    Grid,
    {
      style: { height: "100%", flexWrap: "nowrap" },
      container: true,
      direction: "column",
      justifyContent: "flex-start",
      alignItems: "flex-start",
      ref: docAndReportsContainer,
      children: [
        selectedView && noSectionTools !== true ? sectol.current : null,
        /* @__PURE__ */ jsxRuntimeExports.jsxs(
          SmetaTabs,
          {
            class: "Tabs",
            tabIndex: selectedIndex,
            onTabReClick,
            onTabIndexChange,
            style: {
              height: "0px",
              width: "100%",
              flex: "1 1 auto"
            },
            id: "DocumentsAndReports" + id,
            children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(SmetaTabItem, { style: { textTransform: "none", paddingBottom: "0px", width: "100%" }, label: "Документы", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                SectionDocumentsChose,
                {
                  id,
                  sectionTools: false,
                  onSelect,
                  setParentFunc: (func) => {
                    setDocsTabIndex.current = func;
                  }
                }
              ) }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(SmetaTabItem, { style: { textTransform: "none" }, label: "Отчёты", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SectionReports, { CLSID, defaultButton, seacrhSelected, id }) })
            ]
          }
        )
      ]
    }
  );
};
export {
  SectionReportsAndDocuments as default
};
//# sourceMappingURL=SectionReportsAndDocuments-DT2N3iGP.js.map
