"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const lodashEs = require("lodash-es");
const index_esm = require("../../../node_modules/.pnpm/mantine-react-table@2.0.0-beta.7_@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@_6pmziqsvipqgt5gv2plqw5hct4/node_modules/mantine-react-table/dist/index.esm.cjs");
const index = require("../../../icons/index.cjs");
;/* empty css                                                                                                                                                                                           */
;/* empty css                                                                                                                                                                                            */
;/* empty css                                                                                                                                                                                                    */
;/* empty css                                                                                                                                                                                               */
;/* empty css                                                                                                                                                                                               */
require("clsx");
const styles = require("../../../utils/styles.cjs");
const MantineThemeProvider = require("../../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/MantineProvider/MantineThemeProvider/MantineThemeProvider.cjs");
function mergeMProps(preProps, mProps) {
  if (lodashEs.isFunction(preProps) || lodashEs.isFunction(mProps)) {
    const fn = (...args) => {
      const prePropsResult = lodashEs.isFunction(preProps) ? preProps(...args) : preProps;
      const mPropsResult = lodashEs.isFunction(mProps) ? mProps(...args) : mProps;
      return {
        ...prePropsResult,
        ...mPropsResult,
        sx: styles.mergeSxList([prePropsResult == null ? void 0 : prePropsResult.sx, mPropsResult == null ? void 0 : mPropsResult.sx])
      };
    };
    return fn;
  }
  return {
    ...preProps,
    ...mProps || {},
    sx: styles.mergeSxList([preProps.sx, mProps == null ? void 0 : mProps.sx])
  };
}
function mergeProTableProps(props) {
  const {
    mantineTableProps = {},
    mantinePaperProps = {},
    mantineTableContainerProps = {},
    mantineSkeletonProps = {},
    mantineTableBodyProps,
    mantineTableHeadCellProps = {},
    mantineTableBodyCellProps = {},
    mantineTableBodyRowProps = {},
    mantineBottomToolbarProps = {},
    mantineTableFooterCellProps = {},
    mantineTableFooterRowProps = {},
    mantineTableFooterProps = {},
    mantineLoadingOverlayProps = {},
    enablePagination = false,
    enableBottomToolbar,
    layoutMode,
    withBorder = true,
    loading = false,
    enableExpanding = false,
    enableRowVirtualization = false,
    pagination,
    enableStickyHeader,
    enableStickyFooter,
    emptyMessage,
    errorMessage,
    data,
    localization,
    state,
    rowCount,
    ...rest
  } = props;
  const theme = MantineThemeProvider.useMantineTheme();
  const mPaperProps = mergeMProps(
    {
      shadow: "none",
      withBorder,
      sx: (theme2) => ({
        backgroundColor: "transparent",
        borderRadius: withBorder ? theme2.defaultRadius : 0,
        borderColor: withBorder ? theme2.colors.carbon[4] : "transparent",
        overflow: "hidden",
        transition: "none",
        // see https://v2.mantine-react-table.com/docs/guides/customize-component-styles#how-to-set-mrt-css-variables
        "--mrt-row-hover-background-color": theme2.colors.carbon[3]
      })
    },
    mantinePaperProps
  );
  const mTableProps = mergeMProps(
    {
      highlightOnHover: true,
      withColumnBorders: false,
      horizontalSpacing: 8,
      verticalSpacing: 8,
      sx: {
        color: "inherit",
        thead: {
          tr: {
            boxShadow: "none",
            th: {
              color: theme.colors.carbon[7],
              backgroundColor: theme.colors.carbon[2],
              fontWeight: 500,
              "&[data-column-pinned]": {
                backgroundColor: theme.colors.carbon[2]
              }
            }
          }
        },
        tbody: {
          tr: {
            transition: "none",
            backgroundColor: theme.colors.carbon[0],
            color: theme.colors.carbon[8],
            td: {
              borderColor: theme.colors.carbon[3]
            },
            ":last-of-type": {
              td: {
                borderBottom: "none"
              }
            }
          }
        }
      }
    },
    mantineTableProps
  );
  const mTableContainerProps = mergeMProps(
    {
      sx: {
        backgroundColor: "transparent"
      }
    },
    mantineTableContainerProps
  );
  const mTableBodyProps = mergeMProps((args) => {
    var _a, _b, _c;
    if (!(data == null ? void 0 : data.length)) {
      return {
        sx: {
          "tr td div": {
            maxWidth: `min(100vw, ${((_c = (_b = (_a = args == null ? void 0 : args.table) == null ? void 0 : _a.refs.tablePaperRef) == null ? void 0 : _b.current) == null ? void 0 : _c.clientWidth) ?? "100%"})`
          }
        }
      };
    }
    return {};
  }, mantineTableBodyProps);
  const mTableHeaderCellProps = mergeMProps(() => {
    return {
      sx: {
        ".mrt-table-head-sort-button": {
          height: "auto",
          width: "auto",
          backgroundColor: "transparent",
          borderColor: "transparent",
          minWidth: 20,
          minHeight: 20
        },
        ".mrt-table-head-cell-resize-handle": {
          marginRight: -7
        }
      }
    };
  }, mantineTableHeadCellProps);
  const mTableBodyCellProps = mergeMProps(() => {
    return {
      h: 48
    };
  }, mantineTableBodyCellProps);
  const mTableBodyRowProps = mergeMProps(() => {
    return {
      sx: {
        "&:where([data-with-row-border]):not(:last-of-type)": {
          td: {
            borderBottom: enableRowVirtualization || layoutMode && layoutMode !== "semantic" ? "none !important" : void 0
          }
        },
        "&:not([data-striped], [data-striped='false'])": {
          backgroundColor: theme.colors.carbon[0]
        },
        "&:not([data-selected], [data-row-pinned]) td[data-column-pinned]::before": {
          backgroundColor: "transparent"
        }
      }
    };
  }, mantineTableBodyRowProps);
  const mBottomToolbarProps = mergeMProps(
    {
      sx: (theme2) => ({
        backgroundColor: "inherit",
        transition: "none",
        borderBottomLeftRadius: withBorder ? theme2.defaultRadius : void 0,
        borderBottomRightRadius: withBorder ? theme2.defaultRadius : void 0
      })
    },
    mantineBottomToolbarProps
  );
  const mLoadingOverlayProps = mergeMProps(
    () => ({
      visible: false
    }),
    mantineLoadingOverlayProps
  );
  const mTabelSkeletonProps = mergeMProps(
    {
      sx: (theme2) => ({
        "&::after": {
          backgroundImage: `linear-gradient(90deg, ${theme2.colors.gray[4]},  ${theme2.colors.gray[3]},  ${theme2.colors.gray[3]}, ${theme2.colors.gray[4]})`
        }
      })
    },
    mantineSkeletonProps
  );
  const mTableFooterCellProps = mergeMProps(
    {
      p: 8
    },
    mantineTableFooterCellProps
  );
  const mTableFooterRowProps = mergeMProps(
    {
      sx: { borderBottom: "none", outline: enableStickyFooter ? "none" : void 0 }
    },
    mantineTableFooterRowProps
  );
  const mTableFooterProps = mergeMProps(
    {
      sx: { outline: enableStickyFooter ? "none !important" : void 0 }
    },
    mantineTableFooterProps
  );
  const withPagination = (!!pagination || enablePagination) && ((rowCount ?? 0) || ((pagination == null ? void 0 : pagination.total) ?? 0)) > 0;
  return {
    enableColumnActions: false,
    enableColumnFilters: false,
    enableTopToolbar: false,
    enableSorting: false,
    rowCount,
    enablePagination: withPagination,
    enableBottomToolbar: withPagination || enableBottomToolbar,
    renderBottomToolbar: () => {
      return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
    },
    enableExpanding,
    enableStickyHeader,
    enableStickyFooter,
    enableRowVirtualization,
    mantinePaperProps: mPaperProps,
    mantineTableProps: mTableProps,
    mantineTableHeadCellProps: mTableHeaderCellProps,
    mantineSkeletonProps: mTabelSkeletonProps,
    mantineLoadingOverlayProps: mLoadingOverlayProps,
    mantineTableBodyProps: mTableBodyProps,
    mantineTableContainerProps: mTableContainerProps,
    mantineBottomToolbarProps: mBottomToolbarProps,
    mantineTableBodyRowProps: mTableBodyRowProps,
    mantineTableBodyCellProps: mTableBodyCellProps,
    mantineTableFooterCellProps: mTableFooterCellProps,
    mantineTableFooterRowProps: mTableFooterRowProps,
    mantineTableFooterProps: mTableFooterProps,
    layoutMode,
    data,
    icons: {
      IconChevronLeft: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconChevronLeft, { ...props2 }),
      IconChevronRight: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconChevronRight, { ...props2 }),
      IconChevronDown: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconChevronDown, { ...props2 }),
      IconChevronLeftPipe: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconChevronLeftDouble, { ...props2 }),
      IconChevronRightPipe: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconChevronRightDouble, { ...props2 }),
      IconArrowsSort: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconSwitchVertical02, { ...props2 }),
      IconSortAscending: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconArrowUp, { ...props2 }),
      IconSortDescending: (props2) => /* @__PURE__ */ jsxRuntime.jsx(index.IconArrowDown, { ...props2 })
    },
    localization: {
      noRecordsToDisplay: errorMessage ? errorMessage : emptyMessage ? emptyMessage : void 0,
      ...localization
    },
    state: {
      isLoading: loading,
      ...state,
      columnVisibility: { ...enableExpanding ? { "mrt-row-expand": false } : void 0, ...state == null ? void 0 : state.columnVisibility }
    },
    pagination,
    ...rest
  };
}
function useProTable(options) {
  const props = mergeProTableProps(options);
  return { ...props, ...index_esm.useMantineReactTable(props) };
}
exports.mergeMProps = mergeMProps;
exports.mergeProTableProps = mergeProTableProps;
exports.useProTable = useProTable;
