import { E as compilerRuntimeExports, r as reactExports, j as jsxRuntimeExports } from "./vendor-react-DYNCg6N5.js";
import { u as useStyles$1 } from "./styles-BC5VOxAU.js";
import { T as Tr, a as Th } from "./index-Zaude47i.js";
import { W as useMediaQuery, b as Box, g as Loader, T as Text, $ as Table, c as createStyles, F as Flex, a4 as Select, G as Group, R as Radio } from "./vendor-mantine-h0WlM2Mj.js";
import { u as useTranslation } from "./vendor-i18n-wisIXUFi.js";
import { O as themeColors } from "./index-DfebxkL9.js";
import { T as TableColumnsAction } from "./index-lR9_AURi.js";
const PaginatedTable = (t0) => {
  const $ = compilerRuntimeExports.c(60);
  const {
    rowData,
    columns,
    search,
    minWidth,
    height,
    width,
    selection,
    error,
    isLoading,
    sort,
    setSort,
    layout
  } = t0;
  const {
    classes,
    cx
  } = useStyles$1();
  const [scrolled] = reactExports.useState(false);
  const isMobile = useMediaQuery("(max-width: 1200px)");
  const {
    t
  } = useTranslation();
  let t1;
  if ($[0] !== setSort || $[1] !== sort) {
    t1 = (field) => {
      if (setSort) {
        setSort({
          SortOrder: field === (sort == null ? void 0 : sort.SortField) ? !sort.SortOrder : false,
          SortField: field
        });
      }
    };
    $[0] = setSort;
    $[1] = sort;
    $[2] = t1;
  } else {
    t1 = $[2];
  }
  const setSorting = t1;
  let t2;
  if ($[3] !== columns || $[4] !== rowData || $[5] !== selection) {
    t2 = rowData == null ? void 0 : rowData.map((row, index) => /* @__PURE__ */ jsxRuntimeExports.jsx(Tr, { columns, row, selection }, index));
    $[3] = columns;
    $[4] = rowData;
    $[5] = selection;
    $[6] = t2;
  } else {
    t2 = $[6];
  }
  const rows = t2;
  let t3;
  if ($[7] !== columns || $[8] !== setSorting || $[9] !== (sort == null ? void 0 : sort.SortField) || $[10] !== (sort == null ? void 0 : sort.SortOrder)) {
    let t42;
    if ($[12] !== setSorting || $[13] !== (sort == null ? void 0 : sort.SortField) || $[14] !== (sort == null ? void 0 : sort.SortOrder)) {
      t42 = (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.title && setSorting(col.dataIndex), hideSort: !col.hasSort, hideColumn: col.hideColumn, children: col.title }, col.dataIndex);
      $[12] = setSorting;
      $[13] = sort == null ? void 0 : sort.SortField;
      $[14] = sort == null ? void 0 : sort.SortOrder;
      $[15] = t42;
    } else {
      t42 = $[15];
    }
    t3 = columns.map(t42);
    $[7] = columns;
    $[8] = setSorting;
    $[9] = sort == null ? void 0 : sort.SortField;
    $[10] = sort == null ? void 0 : sort.SortOrder;
    $[11] = t3;
  } else {
    t3 = $[11];
  }
  const columnsRender = t3;
  let t4;
  if ($[16] !== height || $[17] !== width) {
    t4 = {
      width,
      height,
      display: "flex",
      flexDirection: "column"
    };
    $[16] = height;
    $[17] = width;
    $[18] = t4;
  } else {
    t4 = $[18];
  }
  const t5 = classes.wrapper;
  const t6 = isMobile ? "800px" : minWidth;
  let t7;
  if ($[19] !== layout || $[20] !== t6) {
    t7 = {
      width: t6,
      tableLayout: layout
    };
    $[19] = layout;
    $[20] = t6;
    $[21] = t7;
  } else {
    t7 = $[21];
  }
  let t8;
  if ($[22] !== classes.header || $[23] !== classes.scrolled || $[24] !== cx || $[25] !== scrolled) {
    t8 = cx(classes.header, {
      [classes.scrolled]: scrolled
    });
    $[22] = classes.header;
    $[23] = classes.scrolled;
    $[24] = cx;
    $[25] = scrolled;
    $[26] = t8;
  } else {
    t8 = $[26];
  }
  let t9;
  if ($[27] !== columnsRender) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsx("tr", { children: columnsRender });
    $[27] = columnsRender;
    $[28] = t9;
  } else {
    t9 = $[28];
  }
  let t10;
  if ($[29] !== t8 || $[30] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsx("thead", { className: t8, children: t9 });
    $[29] = t8;
    $[30] = t9;
    $[31] = t10;
  } else {
    t10 = $[31];
  }
  let t11;
  if ($[32] !== classes.infiniteScrollMoreData || $[33] !== classes.tr || $[34] !== columns.length || $[35] !== height || $[36] !== isLoading) {
    t11 = isLoading && /* @__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" }) }) }) });
    $[32] = classes.infiniteScrollMoreData;
    $[33] = classes.tr;
    $[34] = columns.length;
    $[35] = height;
    $[36] = isLoading;
    $[37] = t11;
  } else {
    t11 = $[37];
  }
  let t12;
  if ($[38] !== classes.error || $[39] !== classes.tr || $[40] !== columns.length || $[41] !== error || $[42] !== height || $[43] !== (rowData == null ? void 0 : rowData.length) || $[44] !== search || $[45] !== t) {
    t12 = (rowData == null ? void 0 : rowData.length) === 0 && search && /* @__PURE__ */ jsxRuntimeExports.jsx("tr", { className: classes.tr, style: {
      height
    }, children: /* @__PURE__ */ jsxRuntimeExports.jsx("td", { colSpan: columns.length, children: error ? /* @__PURE__ */ jsxRuntimeExports.jsx(Box, { className: classes.error, children: Object.entries(error).map(_temp$1) }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fw: 500, ta: "center", c: "gray.6", children: t("noData") }) }) });
    $[38] = classes.error;
    $[39] = classes.tr;
    $[40] = columns.length;
    $[41] = error;
    $[42] = height;
    $[43] = rowData == null ? void 0 : rowData.length;
    $[44] = search;
    $[45] = t;
    $[46] = t12;
  } else {
    t12 = $[46];
  }
  const t13 = (rowData == null ? void 0 : rowData.length) > 0 && !isLoading && rows;
  let t14;
  if ($[47] !== t11 || $[48] !== t12 || $[49] !== t13) {
    t14 = /* @__PURE__ */ jsxRuntimeExports.jsxs("tbody", { children: [
      t11,
      t12,
      t13
    ] });
    $[47] = t11;
    $[48] = t12;
    $[49] = t13;
    $[50] = t14;
  } else {
    t14 = $[50];
  }
  let t15;
  if ($[51] !== t10 || $[52] !== t14 || $[53] !== t7) {
    t15 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Table, { horizontalSpacing: "md", verticalSpacing: "xs", sx: t7, children: [
      t10,
      t14
    ] });
    $[51] = t10;
    $[52] = t14;
    $[53] = t7;
    $[54] = t15;
  } else {
    t15 = $[54];
  }
  let t16;
  if ($[55] === Symbol.for("react.memo_cache_sentinel")) {
    t16 = /* @__PURE__ */ jsxRuntimeExports.jsx(Box, {});
    $[55] = t16;
  } else {
    t16 = $[55];
  }
  let t17;
  if ($[56] !== classes.wrapper || $[57] !== t15 || $[58] !== t4) {
    t17 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Box, { sx: t4, className: t5, children: [
      t15,
      t16
    ] });
    $[56] = classes.wrapper;
    $[57] = t15;
    $[58] = t4;
    $[59] = t17;
  } else {
    t17 = $[59];
  }
  return t17;
};
function _temp$1(t0) {
  const [key, value] = t0;
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { children: [
    key,
    ": ",
    /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: `${value}` })
  ] }, key);
}
const useStyles = createStyles((theme, _, utils) => ({
  controlWrapper: {
    display: "flex",
    flexDirection: "column",
    [utils.largerThan("xs")]: {
      flexDirection: "row"
    },
    [utils.smallerThan("xs")]: {
      button: {
        // width: '210px',
        marginBottom: 20
      }
    }
  },
  rightSection: {
    input: {
      width: "85px"
    }
  },
  filterSection: {
    [utils.smallerThan("xs")]: {
      marginTop: "20px"
    }
  },
  countText: {
    [utils.smallerThan("xs")]: {
      fontSize: theme.fontSizes.xs,
      marginRight: 10
    }
  },
  selectItem: {
    backgroundColor: theme.white,
    cursor: "pointer",
    padding: "6px",
    ".mantine-Group-root": {
      gap: "12px"
    },
    ".mantine-Radio-radio": {
      width: theme.spacing.sm,
      height: theme.spacing.sm
    }
  }
}));
const TableHeader = (t0) => {
  const $ = compilerRuntimeExports.c(34);
  const {
    handleChangePageSize,
    pageSize,
    pageSizeOptions,
    isLoading,
    startOffset,
    endOffset,
    totalCount,
    showButton,
    buttonComponent,
    list,
    setColumnsData,
    setColumnVisibility
  } = t0;
  const {
    t
  } = useTranslation();
  const {
    classes
  } = useStyles();
  const renderSelectOption = _temp;
  let displayText;
  if (!isLoading) {
    let offsetsText = `${startOffset}`;
    if (endOffset !== startOffset) {
      offsetsText = offsetsText + `-${endOffset}`;
    }
    let t12;
    if ($[0] !== t || $[1] !== totalCount) {
      t12 = totalCount % 10 === 1 && totalCount % 100 !== 11 ? t("statistics.records") : t("statistics.records_");
      $[0] = t;
      $[1] = totalCount;
      $[2] = t12;
    } else {
      t12 = $[2];
    }
    const recordsText = t12;
    const t22 = offsetsText;
    let t32;
    if ($[3] !== t) {
      t32 = t("statistics.from");
      $[3] = t;
      $[4] = t32;
    } else {
      t32 = $[4];
    }
    displayText = `${t22} ${t32} ${totalCount} ${recordsText}`;
  }
  const t1 = showButton ? "space-between" : "flex-end";
  const t2 = showButton && buttonComponent;
  let t3;
  if ($[5] !== classes.countText || $[6] !== displayText || $[7] !== isLoading || $[8] !== totalCount) {
    t3 = isLoading || totalCount > 0 && /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { className: classes.countText, c: themeColors.brandGray[0], size: "sm", mr: "sm", children: displayText });
    $[5] = classes.countText;
    $[6] = displayText;
    $[7] = isLoading;
    $[8] = totalCount;
    $[9] = t3;
  } else {
    t3 = $[9];
  }
  let t4;
  if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
    t4 = {
      zIndex: 500
    };
    $[10] = t4;
  } else {
    t4 = $[10];
  }
  let t5;
  if ($[11] !== pageSize) {
    t5 = pageSize == null ? void 0 : pageSize.toString();
    $[11] = pageSize;
    $[12] = t5;
  } else {
    t5 = $[12];
  }
  let t6;
  if ($[13] !== handleChangePageSize) {
    t6 = (value) => handleChangePageSize(+value);
    $[13] = handleChangePageSize;
    $[14] = t6;
  } else {
    t6 = $[14];
  }
  let t7;
  if ($[15] !== pageSizeOptions || $[16] !== t5 || $[17] !== t6) {
    t7 = /* @__PURE__ */ jsxRuntimeExports.jsx(Select, { comboboxProps: t4, size: "sm", value: t5, onChange: t6, renderOption: renderSelectOption, data: pageSizeOptions });
    $[15] = pageSizeOptions;
    $[16] = t5;
    $[17] = t6;
    $[18] = t7;
  } else {
    t7 = $[18];
  }
  let t8;
  if ($[19] !== classes.filterSection || $[20] !== list || $[21] !== setColumnVisibility || $[22] !== setColumnsData) {
    t8 = list && /* @__PURE__ */ jsxRuntimeExports.jsx(Flex, { align: "center", ml: "xs", className: classes.filterSection, children: /* @__PURE__ */ jsxRuntimeExports.jsx(TableColumnsAction, { setColumnsData, list, setColumnVisibility }) });
    $[19] = classes.filterSection;
    $[20] = list;
    $[21] = setColumnVisibility;
    $[22] = setColumnsData;
    $[23] = t8;
  } else {
    t8 = $[23];
  }
  let t9;
  if ($[24] !== classes.rightSection || $[25] !== t3 || $[26] !== t7 || $[27] !== t8) {
    t9 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { align: "center", className: classes.rightSection, justify: "flex-end", children: [
      t3,
      t7,
      t8
    ] });
    $[24] = classes.rightSection;
    $[25] = t3;
    $[26] = t7;
    $[27] = t8;
    $[28] = t9;
  } else {
    t9 = $[28];
  }
  let t10;
  if ($[29] !== classes.controlWrapper || $[30] !== t1 || $[31] !== t2 || $[32] !== t9) {
    t10 = /* @__PURE__ */ jsxRuntimeExports.jsxs(Flex, { justify: t1, className: classes.controlWrapper, children: [
      t2,
      t9
    ] });
    $[29] = classes.controlWrapper;
    $[30] = t1;
    $[31] = t2;
    $[32] = t9;
    $[33] = t10;
  } else {
    t10 = $[33];
  }
  return t10;
};
function _temp(t0) {
  const {
    option,
    checked
  } = t0;
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Group, { wrap: "nowrap", gap: "xs", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(Radio, { readOnly: true, checked, size: "xs" }),
    /* @__PURE__ */ jsxRuntimeExports.jsx(Text, { fz: "sm", styles: {
      root: {
        flexShrink: 0
      }
    }, children: option.label })
  ] });
}
export {
  PaginatedTable as P,
  TableHeader as T
};
//# sourceMappingURL=index-DXVFB9sp.js.map
