import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { I as InfiniteScroll } from "./index.es-BTZFX8B-.js";
import { u as useStyles$1 } from "./styles-BC5VOxAU.js";
import { T as Tr, a as Th } from "./index-Zaude47i.js";
import { z as zq, i as i$ } from "./vendor-icons-xWhXK_Ui.js";
import { c as createStyles, Z as alpha, _ as useDirection, F as Flex, h as ActionIcon, b as Box, g as Loader, T as Text, $ as Table } from "./vendor-mantine-h0WlM2Mj.js";
import { O as themeColors } from "./index-DfebxkL9.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
const useStyles = createStyles((theme, {
  nestingLevel = 0
}, utils) => ({
  tr: {
    padding: "0 !important",
    height: "72px",
    position: "relative",
    backgroundColor: "white",
    cursor: "pointer",
    "td:first-of-type": {
      maxWidth: "400px",
      "& .mantine-ActionIcon-root": {
        margin: "0 4px"
      },
      "& .mantine-Text-root": {
        wordBreak: "break-all",
        width: "100%",
        boxSizing: "border-box"
      }
    },
    "&:hover": {
      [utils.dark]: {
        backgroundColor: theme.colors.dark[6]
      },
      [utils.light]: {
        backgroundColor: theme.colors.backgroundGray[6]
      },
      "& .action-icon": {
        opacity: 1
      }
    },
    "& .action-icon": {
      opacity: 0
    }
  },
  td: {
    padding: "17px 16px !important",
    borderTop: `1px solid ${theme.colors.backgroundGray[6]} !important`
  },
  rowSelected: {
    [utils.dark]: {
      backgroundColor: alpha(theme.colors[theme.primaryColor][7], 0.2)
    },
    [utils.light]: {
      backgroundColor: theme.colors.mainBlue[0]
    }
  },
  pinnedCOlumn: {
    fontWeight: 600
  },
  hasChildren: {
    "& td:first-of-type": {
      paddingLeft: `${nestingLevel * 12 - 12}px !important`
    }
  },
  noChildren: {
    "& td:first-of-type": {
      paddingLeft: `${nestingLevel * 12 + 24}px !important`
    }
  },
  contentContainer: {
    width: "90%"
  }
}));
const ExpandedTR = (t0) => {
  const $ = compilerRuntimeExports.c(54);
  const {
    columns,
    row,
    selection,
    handleRowClick,
    nestingLevel: t1
  } = t0;
  const nestingLevel = t1 === void 0 ? 1 : t1;
  const {
    dir
  } = useDirection();
  let t2;
  if ($[0] !== nestingLevel) {
    t2 = {
      nestingLevel
    };
    $[0] = nestingLevel;
    $[1] = t2;
  } else {
    t2 = $[1];
  }
  const {
    classes,
    cx
  } = useStyles(t2);
  let t3;
  if ($[2] !== row.Children) {
    t3 = row.Children ? row.Children : [];
    $[2] = row.Children;
    $[3] = t3;
  } else {
    t3 = $[3];
  }
  const children = t3;
  const hasChildren = children.length > 0;
  let t4;
  if ($[4] !== row.Id || $[5] !== selection) {
    t4 = selection == null ? void 0 : selection.includes(row.Id);
    $[4] = row.Id;
    $[5] = selection;
    $[6] = t4;
  } else {
    t4 = $[6];
  }
  const isSelected = !!t4;
  const [showChildren, setShowChildren] = reactExports.useState(row.IsOpen);
  let t5;
  let t6;
  if ($[7] !== row.IsOpen) {
    t5 = () => {
      setShowChildren(row.IsOpen);
    };
    t6 = [row.IsOpen];
    $[7] = row.IsOpen;
    $[8] = t5;
    $[9] = t6;
  } else {
    t5 = $[8];
    t6 = $[9];
  }
  reactExports.useEffect(t5, t6);
  let t7;
  if ($[10] !== handleRowClick || $[11] !== row.Id) {
    t7 = (e) => {
      const currentTarget = e.currentTarget;
      const target = e.target;
      if (currentTarget.contains(target) && handleRowClick) {
        handleRowClick(Number(row == null ? void 0 : row.Id));
      }
    };
    $[10] = handleRowClick;
    $[11] = row.Id;
    $[12] = t7;
  } else {
    t7 = $[12];
  }
  const clickRow = t7;
  const t8 = row == null ? void 0 : row.Id;
  const t9 = !hasChildren;
  let t10;
  if ($[13] !== classes.hasChildren || $[14] !== classes.noChildren || $[15] !== classes.rowSelected || $[16] !== classes.tr || $[17] !== cx || $[18] !== hasChildren || $[19] !== isSelected || $[20] !== t9) {
    t10 = cx(classes.tr, {
      [classes.rowSelected]: isSelected,
      [classes.hasChildren]: hasChildren,
      [classes.noChildren]: t9
    });
    $[13] = classes.hasChildren;
    $[14] = classes.noChildren;
    $[15] = classes.rowSelected;
    $[16] = classes.tr;
    $[17] = cx;
    $[18] = hasChildren;
    $[19] = isSelected;
    $[20] = t9;
    $[21] = t10;
  } else {
    t10 = $[21];
  }
  let t11;
  if ($[22] !== classes.contentContainer || $[23] !== classes.td || $[24] !== columns || $[25] !== dir || $[26] !== hasChildren || $[27] !== row || $[28] !== selection || $[29] !== showChildren) {
    let t122;
    if ($[31] !== classes.contentContainer || $[32] !== classes.td || $[33] !== dir || $[34] !== hasChildren || $[35] !== row || $[36] !== selection || $[37] !== showChildren) {
      t122 = (col, colIndex) => {
        const currentValue = col.render && col.render(row, selection);
        return /* @__PURE__ */ jsxRuntimeExports.jsx("td", { className: classes.td, children: colIndex === 0 ? hasChildren ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(ActionIcon, { sx: {
            "&:hover": {
              backgroundColor: "#ffffff"
            }
          }, onClick: (e_0) => {
            e_0.stopPropagation();
            setShowChildren(!showChildren);
          }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(zq, { size: 18, color: "#98A2B3", style: {
            transform: showChildren ? "rotate(90deg)" : "none"
          } }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.contentContainer, children: currentValue })
        ] }) : currentValue : currentValue }, colIndex);
      };
      $[31] = classes.contentContainer;
      $[32] = classes.td;
      $[33] = dir;
      $[34] = hasChildren;
      $[35] = row;
      $[36] = selection;
      $[37] = showChildren;
      $[38] = t122;
    } else {
      t122 = $[38];
    }
    t11 = columns.map(t122);
    $[22] = classes.contentContainer;
    $[23] = classes.td;
    $[24] = columns;
    $[25] = dir;
    $[26] = hasChildren;
    $[27] = row;
    $[28] = selection;
    $[29] = showChildren;
    $[30] = t11;
  } else {
    t11 = $[30];
  }
  let t12;
  if ($[39] !== clickRow || $[40] !== t10 || $[41] !== t11 || $[42] !== t8) {
    t12 = /* @__PURE__ */ jsxRuntimeExports.jsx("tr", { "data-id": t8, onClick: clickRow, className: t10, children: t11 });
    $[39] = clickRow;
    $[40] = t10;
    $[41] = t11;
    $[42] = t8;
    $[43] = t12;
  } else {
    t12 = $[43];
  }
  let t13;
  if ($[44] !== children || $[45] !== columns || $[46] !== handleRowClick || $[47] !== hasChildren || $[48] !== nestingLevel || $[49] !== showChildren) {
    t13 = hasChildren && showChildren ? children.map((child, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(ExpandedTR, { columns, row: child, handleRowClick, nestingLevel: nestingLevel + 1 }, index)) : null;
    $[44] = children;
    $[45] = columns;
    $[46] = handleRowClick;
    $[47] = hasChildren;
    $[48] = nestingLevel;
    $[49] = showChildren;
    $[50] = t13;
  } else {
    t13 = $[50];
  }
  let t14;
  if ($[51] !== t12 || $[52] !== t13) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
      t12,
      t13
    ] });
    $[51] = t12;
    $[52] = t13;
    $[53] = t14;
  } else {
    t14 = $[53];
  }
  return t14;
};
const SimpleTable = (t0) => {
  const $ = compilerRuntimeExports.c(73);
  const {
    dataCy: t1,
    rowData,
    columns,
    minWidth,
    height,
    width,
    selection,
    handleRowClick,
    getNextData,
    allDataLength,
    error,
    scrollRef,
    isLoading,
    isFetching,
    sort,
    setSort,
    isExpanded
  } = t0;
  const dataCy = t1 === void 0 ? "simpleTable" : t1;
  const {
    classes,
    cx
  } = useStyles$1();
  const [scrolled, setScrolled] = reactExports.useState(false);
  const {
    t
  } = useTranslation();
  let t2;
  if ($[0] !== setSort || $[1] !== sort) {
    t2 = (field) => {
      if (setSort) {
        setSort({
          SortOrder: field === (sort == null ? void 0 : sort.SortField) ? !sort.SortOrder : false,
          SortField: field
        });
      }
    };
    $[0] = setSort;
    $[1] = sort;
    $[2] = t2;
  } else {
    t2 = $[2];
  }
  const setSorting = t2;
  let t3;
  if ($[3] !== columns || $[4] !== handleRowClick || $[5] !== isExpanded || $[6] !== rowData || $[7] !== selection) {
    t3 = rowData == null ? void 0 : rowData.map((row, index) => isExpanded ? /* @__PURE__ */ jsxRuntimeExports.jsx(ExpandedTR, { columns, row, selection, handleRowClick }, index) : /* @__PURE__ */ jsxRuntimeExports.jsx(Tr, { columns, row, selection, handleRowClick }, index));
    $[3] = columns;
    $[4] = handleRowClick;
    $[5] = isExpanded;
    $[6] = rowData;
    $[7] = selection;
    $[8] = t3;
  } else {
    t3 = $[8];
  }
  const rows = t3;
  let t4;
  if ($[9] !== columns || $[10] !== setSorting || $[11] !== (sort == null ? void 0 : sort.SortField) || $[12] !== (sort == null ? void 0 : sort.SortOrder)) {
    let t52;
    if ($[14] !== setSorting || $[15] !== (sort == null ? void 0 : sort.SortField) || $[16] !== (sort == null ? void 0 : sort.SortOrder)) {
      t52 = (col) => /* @__PURE__ */ jsxRuntimeExports.jsx(Th, { width: col.width, sorted: (sort == null ? void 0 : sort.SortField) === col.dataIndex, reversed: !!(sort == null ? void 0 : sort.SortOrder), onSort: () => col.hasSort && col.title && setSorting(col.dataIndex), hideSort: !col.hasSort, hideColumn: col.hideColumn, children: col.title }, col.dataIndex);
      $[14] = setSorting;
      $[15] = sort == null ? void 0 : sort.SortField;
      $[16] = sort == null ? void 0 : sort.SortOrder;
      $[17] = t52;
    } else {
      t52 = $[17];
    }
    t4 = columns.map(t52);
    $[9] = columns;
    $[10] = setSorting;
    $[11] = sort == null ? void 0 : sort.SortField;
    $[12] = sort == null ? void 0 : sort.SortOrder;
    $[13] = t4;
  } else {
    t4 = $[13];
  }
  const columnsRender = t4;
  let t5;
  if ($[18] === Symbol.for("react.memo_cache_sentinel")) {
    t5 = () => {
      setScrolled(true);
    };
    $[18] = t5;
  } else {
    t5 = $[18];
  }
  const handleScroll = t5;
  let t6;
  if ($[19] !== width) {
    t6 = {
      width
    };
    $[19] = width;
    $[20] = t6;
  } else {
    t6 = $[20];
  }
  const t7 = rowData == null ? void 0 : rowData.length;
  const t8 = allDataLength > rowData.length;
  let t9;
  if ($[21] !== classes.infiniteScrollMoreData || $[22] !== rowData.length) {
    t9 = Boolean(rowData.length) && /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.infiniteScrollMoreData, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "sm" }) });
    $[21] = classes.infiniteScrollMoreData;
    $[22] = rowData.length;
    $[23] = t9;
  } else {
    t9 = $[23];
  }
  let t10;
  if ($[24] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: t9 });
    $[24] = t9;
    $[25] = t10;
  } else {
    t10 = $[25];
  }
  const t11 = classes.infiniteScroll;
  let t12;
  if ($[26] !== minWidth) {
    t12 = {
      minWidth
    };
    $[26] = minWidth;
    $[27] = t12;
  } else {
    t12 = $[27];
  }
  let t13;
  if ($[28] !== classes.header || $[29] !== classes.scrolled || $[30] !== cx || $[31] !== scrolled) {
    t13 = cx(classes.header, {
      [classes.scrolled]: scrolled
    });
    $[28] = classes.header;
    $[29] = classes.scrolled;
    $[30] = cx;
    $[31] = scrolled;
    $[32] = t13;
  } else {
    t13 = $[32];
  }
  let t14;
  if ($[33] !== columnsRender) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsx("tr", { children: columnsRender });
    $[33] = columnsRender;
    $[34] = t14;
  } else {
    t14 = $[34];
  }
  let t15;
  if ($[35] !== t13 || $[36] !== t14) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsx("thead", { className: t13, children: t14 });
    $[35] = t13;
    $[36] = t14;
    $[37] = t15;
  } else {
    t15 = $[37];
  }
  let t16;
  if ($[38] !== classes.infiniteScrollMoreData || $[39] !== classes.tr || $[40] !== columns.length || $[41] !== height || $[42] !== isFetching || $[43] !== isLoading) {
    t16 = (isLoading || isFetching) && /* @__PURE__ */ jsxRuntimeExports.jsx("tr", { className: classes.tr, style: {
      height
    }, children: /* @__PURE__ */ jsxRuntimeExports.jsx("td", { colSpan: columns.length, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.infiniteScrollMoreData, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader, { size: "sm" }) }) }) });
    $[38] = classes.infiniteScrollMoreData;
    $[39] = classes.tr;
    $[40] = columns.length;
    $[41] = height;
    $[42] = isFetching;
    $[43] = isLoading;
    $[44] = t16;
  } else {
    t16 = $[44];
  }
  let t17;
  if ($[45] !== classes.tr || $[46] !== columns.length || $[47] !== error || $[48] !== height || $[49] !== rowData.length || $[50] !== t) {
    t17 = (rowData == null ? void 0 : rowData.length) === 0 && /* @__PURE__ */ jsxRuntimeExports.jsx("tr", { className: classes.tr, style: {
      height
    }, children: /* @__PURE__ */ jsxRuntimeExports.jsx("td", { colSpan: columns.length, children: error ? /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: "center", align: "center", gap: "5px", children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(i$, { color: themeColors.brandGray[0], stroke: 1.8 }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: 500, ta: "center", c: themeColors.brandGray[0], children: t("dataError") })
    ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: 500, ta: "center", c: themeColors.brandGray[0], children: t("noData") }) }) });
    $[45] = classes.tr;
    $[46] = columns.length;
    $[47] = error;
    $[48] = height;
    $[49] = rowData.length;
    $[50] = t;
    $[51] = t17;
  } else {
    t17 = $[51];
  }
  const t18 = (rowData == null ? void 0 : rowData.length) > 0 && !isLoading && rows;
  let t19;
  if ($[52] !== t16 || $[53] !== t17 || $[54] !== t18) {
    t19 = /* @__PURE__ */ jsxRuntimeExports.jsxs("tbody", { children: [
      t16,
      t17,
      t18
    ] });
    $[52] = t16;
    $[53] = t17;
    $[54] = t18;
    $[55] = t19;
  } else {
    t19 = $[55];
  }
  let t20;
  if ($[56] !== dataCy || $[57] !== t12 || $[58] !== t15 || $[59] !== t19) {
    t20 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Table, { horizontalSpacing: "md", "data-atribute": dataCy, verticalSpacing: "xs", sx: t12, children: [
      t15,
      t19
    ] });
    $[56] = dataCy;
    $[57] = t12;
    $[58] = t15;
    $[59] = t19;
    $[60] = t20;
  } else {
    t20 = $[60];
  }
  let t21;
  if ($[61] !== classes.infiniteScroll || $[62] !== getNextData || $[63] !== height || $[64] !== scrollRef || $[65] !== t10 || $[66] !== t20 || $[67] !== t7 || $[68] !== t8) {
    t21 = /* @__PURE__ */ jsxRuntimeExports.jsx(InfiniteScroll, { ref: scrollRef, dataLength: t7, next: getNextData, hasMore: t8, loader: t10, className: t11, height, onScroll: handleScroll, children: t20 });
    $[61] = classes.infiniteScroll;
    $[62] = getNextData;
    $[63] = height;
    $[64] = scrollRef;
    $[65] = t10;
    $[66] = t20;
    $[67] = t7;
    $[68] = t8;
    $[69] = t21;
  } else {
    t21 = $[69];
  }
  let t22;
  if ($[70] !== t21 || $[71] !== t6) {
    t22 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { sx: t6, children: t21 });
    $[70] = t21;
    $[71] = t6;
    $[72] = t22;
  } else {
    t22 = $[72];
  }
  return t22;
};
export {
  SimpleTable as S
};
//# sourceMappingURL=index-DOqL4InQ.js.map
