import {
  Body
} from "./chunk-6SGHAVWG.js";
import {
  Table
} from "./chunk-ZVVEPCBU.js";
import {
  EnumFilter,
  getDefaultEnumFilterState,
  isEnumFilterState
} from "./chunk-EIKXY7AD.js";
import {
  IdFilter,
  getDefaultIdFilterState,
  isIdFilterState
} from "./chunk-3GTTFRUO.js";
import {
  StringFilter,
  getDefaultStringFilterState,
  isStringFilterState
} from "./chunk-5AB6NTYU.js";
import {
  BooleanFilter,
  getDefaultBooleanFilterState
} from "./chunk-GFAX5WLZ.js";
import {
  CurrencyFilter,
  getDefaultCurrencyFilterState
} from "./chunk-SEL2XGBO.js";
import {
  DateFilter,
  getDefaultDateFilterState
} from "./chunk-2AVXNAAL.js";
import {
  LabelModerate
} from "./chunk-25AAHDUW.js";
import {
  Label
} from "./chunk-IT6Y66F5.js";
import {
  Modal
} from "./chunk-CSY4CGNN.js";
import {
  Dropdown
} from "./chunk-C4X6HNCA.js";
import {
  TextIconAligner
} from "./chunk-TH42CNH3.js";
import {
  CardPageFullWidth
} from "./chunk-TXJQWZCR.js";
import {
  StyledButtonRow
} from "./chunk-VHHLWRJS.js";
import {
  Spacing
} from "./chunk-E5DUKMCU.js";
import {
  Button,
  StyledButton
} from "./chunk-SIPHI6JZ.js";
import {
  z
} from "./chunk-55OQPFLF.js";
import {
  Icon
} from "./chunk-DMPXNHDT.js";
import {
  standardBorderRadius,
  standardContentInset
} from "./chunk-HGZGGJQB.js";
import {
  getColor,
  themeOr,
  themeOrWithKey
} from "./chunk-VAH342U2.js";
import {
  bp,
  useBreakpoints
} from "./chunk-JSGRNWSB.js";
import {
  colors
} from "./chunk-MIIIUXV6.js";
import {
  __async,
  __spreadProps,
  __spreadValues
} from "./chunk-W7FAWX6T.js";

// src/components/DataManagerTable/DataManagerTable.tsx
import styled from "@emotion/styled";
import { Fragment, useEffect, useState } from "react";
import { Fragment as Fragment2, jsx, jsxs } from "@emotion/react/jsx-runtime";
function getDefaultFilterState(filter) {
  switch (filter.type) {
    case "date" /* DATE */:
      return getDefaultDateFilterState();
    case "enum" /* ENUM */:
      return getDefaultEnumFilterState();
    case "string" /* STRING */:
      return getDefaultStringFilterState();
    case "id" /* ID */:
      return getDefaultIdFilterState(filter.allowedEntities);
    case "boolean" /* BOOLEAN */:
      return getDefaultBooleanFilterState();
    case "currency" /* CURRENCY */:
      return getDefaultCurrencyFilterState();
    default:
      throw new Error("Invalid filter type");
  }
}
function initialFilterState(filters) {
  let state = {};
  filters.forEach((filter) => {
    state = __spreadProps(__spreadValues({}, state), {
      [filter.accessorKey]: getDefaultFilterState(filter)
    });
  });
  return state;
}
function DataManagerTable(props) {
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
  const isCardPageFullWidth = typeof props.cardPageFullWidth === "boolean" ? props.cardPageFullWidth : true;
  const cardPageMt = typeof props.cardPageMt === "undefined" ? 24 : props.cardPageMt;
  const showPaginationPreviousNext = typeof ((_a = props.paginationDisplayOptions) == null ? void 0 : _a.showPaginationPreviousNext) === "boolean" ? props.paginationDisplayOptions.showPaginationPreviousNext : true;
  const pageSizeString = typeof ((_b = props.paginationDisplayOptions) == null ? void 0 : _b.pageSizeStringTemplate) === "string" ? props.paginationDisplayOptions.pageSizeStringTemplate : "Show {pageSize} items";
  const breakPoint = useBreakpoints();
  const [pageSize, setPageSize] = useState(((_c = props.pageSizes) == null ? void 0 : _c[0]) || 20);
  const [pageCursorState, setPageCursorState] = useState({
    startResult: void 0,
    nextPageCursor: props.nextPageCursor,
    cursorCache: {}
  });
  const [isLoading, setIsLoading] = useState(props.loading || false);
  const [numFiltersApplied, setNumFiltersApplied] = useState(0);
  const [showFilterEditor, setShowFilterEditor] = useState(false);
  const [filterStates, setFilterStates] = useState(
    props.filterOptions ? initialFilterState(props.filterOptions.filters) : {}
  );
  const [fetchVariables, setFetchVariables] = useState(
    ((_d = props.filterOptions) == null ? void 0 : _d.initialQueryVariables) || {}
  );
  const isSm = breakPoint.isSm();
  useEffect(() => {
    setIsLoading(Boolean(props.loading));
  }, [props.loading]);
  useEffect(() => {
    if (!props.nextPageCursor) {
      return;
    }
    const cursorCacheResult = Object.entries(
      pageCursorState.cursorCache[pageSize] || {}
    ).find(([_, cursor]) => cursor === props.nextPageCursor);
    if (cursorCacheResult) {
      setPageCursorState((prevState) => __spreadProps(__spreadValues({}, prevState), {
        startResult: parseInt(cursorCacheResult[0]),
        nextPageCursor: cursorCacheResult[1]
      }));
    } else {
      setPageCursorState((prevState) => {
        if (prevState.nextPageCursor === props.nextPageCursor) return prevState;
        const startResult = prevState.startResult === void 0 ? 1 : prevState.startResult + pageSize;
        return __spreadProps(__spreadValues({}, prevState), {
          startResult,
          nextPageCursor: props.nextPageCursor,
          cursorCache: __spreadProps(__spreadValues({}, prevState.cursorCache), {
            [pageSize]: __spreadProps(__spreadValues({}, prevState.cursorCache[pageSize]), {
              [startResult]: props.nextPageCursor
            })
          })
        });
      });
    }
  }, [props.nextPageCursor, pageSize, pageCursorState.cursorCache]);
  function updateFilterState(filter) {
    return (state) => {
      setFilterStates((prevState) => __spreadProps(__spreadValues({}, prevState), {
        [filter.accessorKey]: state
      }));
    };
  }
  const handleApplyFilters = (filterStates2, filterOptions, pageSize2) => __async(this, null, function* () {
    var _a2, _b2, _c2, _d2;
    const { filters: filters2, refetch, getFilterQueryVariables } = filterOptions;
    const appliedFilterStates = __spreadValues({}, filterStates2);
    const filterStatesArray = Object.values(appliedFilterStates);
    let isValid = true;
    for (let i = 0; i < filterStatesArray.length; i++) {
      const filterState = filterStatesArray[i];
      if (filterState.isApplied && filterState.onValidate) {
        const filter = filters2[i];
        const validResult = filterState.onValidate(
          filterState,
          filter.isMulti
        );
        if (validResult) {
          appliedFilterStates[filter.accessorKey] = validResult;
          if (isIdFilterState(filterState)) {
            const appliedValues = validResult.appliedValues;
            const isApplied = !!(appliedValues == null ? void 0 : appliedValues.length);
            updateFilterState(filter)(__spreadProps(__spreadValues({}, filterStates2[filter.accessorKey]), {
              value: "",
              appliedValues: appliedValues ? [...appliedValues] : [],
              isApplied
            }));
            filterState.isApplied = isApplied;
          }
        } else {
          filterState.errorMessage = filter.errorMessage || "Error validating input";
          isValid = false;
        }
      }
    }
    if (!isValid) {
      setFilterStates((prevState) => __spreadValues({}, prevState));
      return;
    }
    for (let i = 0; i < filterStatesArray.length; i++) {
      const filterState = filterStatesArray[i];
      if (!filterState.isApplied) continue;
      const filter = filters2[i];
      if (isStringFilterState(filterState)) {
        if (filterState.value) {
          const value = filterState.value;
          let updatedAppliedValues = [];
          if (filter.isMulti) {
            updatedAppliedValues = ((_a2 = filterState.appliedValues) == null ? void 0 : _a2.filter(
              (appliedValue) => appliedValue !== value
            )) || [];
          }
          updatedAppliedValues.push(value);
          const newFilterState = __spreadProps(__spreadValues({}, filterStates2[filter.accessorKey]), {
            value: "",
            appliedValues: updatedAppliedValues,
            isApplied: !!updatedAppliedValues.length
          });
          appliedFilterStates[filter.accessorKey] = newFilterState;
          updateFilterState(filter)(newFilterState);
        } else if (((_b2 = filterState.appliedValues) == null ? void 0 : _b2.length) === 0) {
          updateFilterState(filter)(getDefaultStringFilterState());
          filterState.isApplied = false;
        }
      } else if (isEnumFilterState(filterState)) {
        if (filterState.value) {
          const newFilterState = __spreadProps(__spreadValues({}, filterStates2[filter.accessorKey]), {
            value: "",
            appliedValues: filterState.appliedValues,
            isApplied: !!((_c2 = filterState.appliedValues) == null ? void 0 : _c2.length)
          });
          appliedFilterStates[filter.accessorKey] = newFilterState;
          updateFilterState(filter)(newFilterState);
        } else if (((_d2 = filterState.appliedValues) == null ? void 0 : _d2.length) === 0) {
          updateFilterState(filter)(getDefaultEnumFilterState());
          filterState.isApplied = false;
        }
      }
    }
    const numFiltersApplied2 = filterStatesArray.reduce((acc, state) => {
      return state.isApplied ? acc + 1 : acc;
    }, 0);
    setNumFiltersApplied(numFiltersApplied2);
    setShowFilterEditor(false);
    setIsLoading(true);
    const newFetchVariables = getFilterQueryVariables(
      filters2,
      appliedFilterStates,
      pageSize2
    );
    setFetchVariables(newFetchVariables);
    setPageCursorState((prevState) => __spreadProps(__spreadValues({}, prevState), {
      startResult: void 0
    }));
    try {
      yield refetch(newFetchVariables);
    } catch (e) {
      setIsLoading(false);
      throw e;
    }
    setIsLoading(false);
  });
  const handleClearFilters = () => {
    if (props.filterOptions) {
      const { filters: filters2 } = props.filterOptions;
      const newFilterStates = initialFilterState(filters2);
      setFilterStates(newFilterStates);
      void handleApplyFilters(newFilterStates, props.filterOptions, pageSize);
    }
  };
  const handleNext = () => __async(this, null, function* () {
    if (!props.filterOptions) {
      return;
    }
    const { refetch } = props.filterOptions;
    setIsLoading(true);
    const newFetchVariables = __spreadProps(__spreadValues({}, fetchVariables), {
      after: pageCursorState === void 0 ? void 0 : pageCursorState.nextPageCursor
    });
    setFetchVariables(newFetchVariables);
    try {
      yield refetch(newFetchVariables);
    } catch (e) {
      setIsLoading(false);
      throw e;
    }
    setIsLoading(false);
  });
  const handlePrev = () => __async(this, null, function* () {
    if (!props.filterOptions) {
      return;
    }
    const { refetch } = props.filterOptions;
    setIsLoading(true);
    const newFetchVariables = __spreadProps(__spreadValues({}, fetchVariables), {
      after: pageCursorState.startResult ? pageCursorState.cursorCache[pageSize][pageCursorState.startResult - pageSize - pageSize] : void 0
    });
    setFetchVariables(newFetchVariables);
    try {
      yield refetch(newFetchVariables);
    } catch (e) {
      setIsLoading(false);
      throw e;
    }
    setIsLoading(false);
  });
  const currentPage = Math.floor((pageCursorState.startResult || 0) / pageSize) + 1;
  const handleChangePage = (page) => __async(this, null, function* () {
    const pageCursorIndex = (page - 1) * pageSize + 1 - pageSize;
    const cachedCursorState = pageCursorState.cursorCache[pageSize][pageCursorIndex];
    if (!props.filterOptions || pageCursorIndex > 0 && !cachedCursorState || page === currentPage) {
      return;
    }
    const { refetch } = props.filterOptions;
    setIsLoading(true);
    const newFetchVariables = __spreadProps(__spreadValues({}, fetchVariables), {
      after: cachedCursorState
    });
    setFetchVariables(newFetchVariables);
    try {
      yield refetch(newFetchVariables);
    } catch (e) {
      setIsLoading(false);
      throw e;
    }
    setIsLoading(false);
  });
  const handleChangePageSize = (size) => __async(this, null, function* () {
    setPageSize(size);
    if (props.showMoreOptions) {
      const { refetch, initialQueryVariables } = props.showMoreOptions;
      setIsLoading(true);
      let pageSizeQueryVariables;
      if (props.showMoreOptions.pageSizeVariables) {
        pageSizeQueryVariables = {};
        for (const variable of props.showMoreOptions.pageSizeVariables) {
          pageSizeQueryVariables[variable] = size;
        }
      } else {
        pageSizeQueryVariables = { first: size };
      }
      const newFetchVariables = __spreadValues(__spreadValues({}, initialQueryVariables), pageSizeQueryVariables);
      setFetchVariables(newFetchVariables);
      try {
        yield refetch(newFetchVariables);
      } catch (e) {
        setIsLoading(false);
        throw e;
      }
      setIsLoading(false);
    } else if (props.filterOptions) {
      void handleApplyFilters(filterStates, props.filterOptions, size);
    }
  });
  const filterSections = props.filterOptions ? props.filterOptions.filters.map((filter) => {
    switch (filter.type) {
      case "date" /* DATE */:
        return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
          DateFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => __spreadProps(__spreadValues({}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "enum" /* ENUM */:
        return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
          EnumFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => __spreadProps(__spreadValues({}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            options: filter.enumValues,
            label: filter.label,
            placeholder: filter.placeholder,
            state: filterStates[filter.accessorKey],
            isMulti: filter.isMulti
          }
        ) }, filter.label);
      case "string" /* STRING */:
        return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
          StringFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => __spreadProps(__spreadValues({}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            label: filter.label,
            placeholder: filter.placeholder,
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "id" /* ID */:
        return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
          IdFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => __spreadProps(__spreadValues({}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            label: filter.label,
            placeholder: filter.placeholder,
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "boolean" /* BOOLEAN */:
        return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
          BooleanFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => __spreadProps(__spreadValues({}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            label: filter.label,
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "currency" /* CURRENCY */:
        return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(
          CurrencyFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => __spreadProps(__spreadValues({}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            label: filter.label,
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      default:
        return null;
    }
  }) : [];
  let filters;
  const isFilterButtonSmall = isSm && props.header;
  function onApply() {
    void handleApplyFilters(filterStates, props.filterOptions, pageSize);
  }
  const filterContent = /* @__PURE__ */ jsxs(
    FilterContentInner,
    {
      onKeyDownCapture: (e) => {
        if (e.key === "Enter") {
          onApply();
        }
      },
      isSm,
      children: [
        filterSections,
        /* @__PURE__ */ jsxs(FilterContentFooter, { children: [
          /* @__PURE__ */ jsx(Button, { text: "Clear", onClick: handleClearFilters }),
          /* @__PURE__ */ jsxs(FilterContentFooterRight, { children: [
            /* @__PURE__ */ jsx(Button, { text: "Cancel", onClick: () => setShowFilterEditor(false) }),
            /* @__PURE__ */ jsx(Button, { text: "Apply", kind: "primary", onClick: onApply })
          ] })
        ] })
      ]
    }
  );
  const commonButtonProps = {
    kind: isFilterButtonSmall ? "roundIcon" : "secondary",
    size: "ExtraSmall",
    typography: { color: "c6Neutral" },
    icon: {
      name: "Sort"
    },
    text: !isFilterButtonSmall ? `Filter${numFiltersApplied > 0 ? ` | ${numFiltersApplied}` : ""}` : void 0
  };
  if (props.filterOptions) {
    const FilterContainerComponent = ((_e = props.customComponents) == null ? void 0 : _e.filterContainerComponent) || DataManagerTableFilterContainer;
    filters = /* @__PURE__ */ jsx(FilterContainerComponent, { children: isSm ? /* @__PURE__ */ jsxs(Fragment, { children: [
      /* @__PURE__ */ jsx(
        Button,
        __spreadProps(__spreadValues(__spreadValues({}, commonButtonProps), props.filterButtonProps), {
          onClick: () => setShowFilterEditor(!showFilterEditor)
        })
      ),
      /* @__PURE__ */ jsx(
        Modal,
        {
          visible: showFilterEditor,
          onClose: () => setShowFilterEditor(false),
          smKind: "fullscreen",
          children: filterContent
        }
      )
    ] }) : /* @__PURE__ */ jsx(
      Dropdown,
      {
        borderRadius: 12,
        maxDropdownItemsWidth: 400,
        dropdownContent: /* @__PURE__ */ jsx(FilterDropdownContent, { visible: showFilterEditor, children: filterContent }),
        isOpen: showFilterEditor,
        onOpen: () => {
          setShowFilterEditor(true);
        },
        onClose: () => {
          setShowFilterEditor(false);
        },
        button: __spreadValues(__spreadValues({}, commonButtonProps), props.filterButtonProps),
        align: props.filterDropdownAlign || "right"
      }
    ) });
  }
  let showMoreDropdown;
  if (((_f = props.pageSizes) == null ? void 0 : _f.length) > 1) {
    showMoreDropdown = /* @__PURE__ */ jsx(
      Dropdown,
      {
        align: "right",
        verticalPlacement: "top",
        getCSS: ({ isOpen }) => ({
          height: "fit-content",
          alignSelf: "center"
        }),
        button: {
          getCSS: ({ isOpen }) => ({
            display: "flex",
            alignItems: "center",
            height: "100%",
            width: "100%"
          }),
          getContent: ({ isOpen }) => /* @__PURE__ */ jsx(
            TextIconAligner,
            {
              content: pageSizeString.replace("{pageSize}", `${pageSize}`),
              typography: { size: "ExtraSmall" },
              rightIcon: {
                name: "Chevron",
                ml: 4,
                width: 14,
                color: isOpen ? "onPrimaryText" : "mcNeutral"
              }
            }
          )
        },
        dropdownItems: props.pageSizes.map((size) => ({
          label: `${size}`,
          onClick: () => {
            void handleChangePageSize(size);
          }
        }))
      }
    );
  }
  let footer;
  if (props.showMoreOptions) {
    footer = /* @__PURE__ */ jsxs(DataManagerTableFooter, { children: [
      /* @__PURE__ */ jsx(
        Button,
        {
          text: "Show more",
          paddingY: "short",
          onClick: () => {
            var _a2;
            return void handleChangePageSize(pageSize + (((_a2 = props.pageSizes) == null ? void 0 : _a2[0]) || 20));
          }
        }
      ),
      showMoreDropdown
    ] });
  } else if (props.resultCount) {
    const startResult = pageCursorState.startResult || 1;
    const endResult = Math.min(props.resultCount, startResult + pageSize - 1);
    const isFullCount = (_g = props.isFullCount) != null ? _g : true;
    const countString = isFullCount ? props.resultCount : props.resultCount + "+";
    const resultsString = ((_h = props.paginationDisplayOptions) == null ? void 0 : _h.showPageNumberButtons) ? /* @__PURE__ */ jsx("div", {}) : /* @__PURE__ */ jsxs("div", { children: [
      /* @__PURE__ */ jsx(Label, { children: "Viewing " }),
      /* @__PURE__ */ jsx(LabelModerate, { children: `${startResult}-${endResult}` }),
      /* @__PURE__ */ jsx(Label, { children: " of " }),
      /* @__PURE__ */ jsx(LabelModerate, { children: `${countString}` }),
      /* @__PURE__ */ jsx(Label, { children: " results" })
    ] });
    const hasNext = props.resultCount ? startResult + pageSize - 1 < props.resultCount : false;
    const hasPrev = startResult > 1;
    const pageNumbers = Array.from(
      { length: Math.ceil(props.resultCount / pageSize) },
      (_, i) => i
    );
    const pageNumberButtons = ((_i = props.paginationDisplayOptions) == null ? void 0 : _i.showPageNumberButtons) ? /* @__PURE__ */ jsxs(PageNumberPaginationButtonsContainer, { children: [
      /* @__PURE__ */ jsx(
        Button,
        {
          icon: {
            name: "CentralChevronLeftSmall",
            width: 24,
            color: "text"
          },
          kind: "ghost",
          paddingY: "short",
          onClick: () => void handlePrev(),
          disabled: !hasPrev
        }
      ),
      pageNumbers.slice(0, 2).map((pageNumber) => /* @__PURE__ */ jsx(
        PageNumberButton,
        {
          onClick: () => void handleChangePage(pageNumber + 1),
          isCurrentPage: currentPage === pageNumber + 1,
          children: /* @__PURE__ */ jsx(Body, { content: `${pageNumber + 1}` })
        },
        pageNumber
      )),
      pageNumbers.length > 4 && currentPage - 2 > 1 && /* @__PURE__ */ jsx(
        Icon,
        {
          name: "CentralDotGrid1x3Horizontal",
          width: 18,
          ml: 7,
          mr: 7,
          color: "text"
        }
      ),
      currentPage - 1 > 1 && currentPage < pageNumbers.length && /* @__PURE__ */ jsx(
        PageNumberButton,
        {
          isCurrentPage: true,
          onClick: () => void handleChangePage(currentPage),
          children: /* @__PURE__ */ jsx(Body, { content: `${currentPage}` })
        },
        currentPage
      ),
      pageNumbers.length > 4 && currentPage + 1 < pageNumbers.length && /* @__PURE__ */ jsx(
        Icon,
        {
          name: "CentralDotGrid1x3Horizontal",
          width: 18,
          ml: 7,
          mr: 7,
          color: "text"
        }
      ),
      pageNumbers.length > 4 && /* @__PURE__ */ jsx(
        PageNumberButton,
        {
          isCurrentPage: currentPage === pageNumbers.length,
          onClick: () => void handleChangePage(pageNumbers.length),
          children: /* @__PURE__ */ jsx(Body, { content: `${pageNumbers.length}` })
        },
        pageNumbers.length
      ),
      /* @__PURE__ */ jsx(
        Button,
        {
          icon: {
            name: "CentralChevronRightSmall",
            width: 24,
            color: "text"
          },
          kind: "ghost",
          paddingY: "short",
          onClick: () => void handleNext(),
          disabled: !hasNext
        }
      )
    ] }) : /* @__PURE__ */ jsx(Fragment2, {});
    footer = /* @__PURE__ */ jsxs(DataManagerTableFooter, { children: [
      resultsString,
      pageNumberButtons,
      /* @__PURE__ */ jsxs(PaginationContainer, { children: [
        showMoreDropdown,
        showPaginationPreviousNext && /* @__PURE__ */ jsxs(PaginationButtonsContainer, { children: [
          /* @__PURE__ */ jsx(
            Button,
            {
              text: "Previous",
              paddingY: "short",
              onClick: () => {
                void handlePrev();
              },
              disabled: !hasPrev
            }
          ),
          /* @__PURE__ */ jsx(
            Button,
            {
              text: "Next",
              paddingY: "short",
              onClick: () => {
                void handleNext();
              },
              disabled: !hasNext
            }
          )
        ] })
      ] })
    ] });
  }
  const DataManagerTableHeaderComponent = ((_j = props.customComponents) == null ? void 0 : _j.dataManagerTableHeaderComponent) || DataManagerTableHeader;
  const content = /* @__PURE__ */ jsxs(Fragment2, { children: [
    props.showHeader && /* @__PURE__ */ jsxs(DataManagerTableHeaderComponent, { children: [
      props.header,
      filters
    ] }),
    /* @__PURE__ */ jsx(Table, __spreadProps(__spreadValues({}, props), { loading: isLoading })),
    footer
  ] });
  return /* @__PURE__ */ jsx(StyledDataManagerTable, { children: isCardPageFullWidth ? /* @__PURE__ */ jsx(CardPageFullWidth, { css: { marginTop: `${cardPageMt}px` }, children: content }) : content });
}
var StyledDataManagerTable = styled.div`
  width: 100%;
`;
var commonPadding = `
  ${bp.lg(`
  padding-left: ${standardContentInset.lgPx}px;
  padding-right: ${standardContentInset.lgPx}px;
  `)}
  ${bp.sm(`
  padding-left: ${standardContentInset.smPx}px;
  padding-right: ${standardContentInset.smPx}px;
  `)}
  ${bp.minSmMaxLg(`
  padding-left: ${standardContentInset.minSmMaxLgPx}px;
  padding-right: ${standardContentInset.minSmMaxLgPx}px;
  `)}
`;
var DataManagerTableHeader = styled.div`
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: ${Spacing.px.xs} 0;
  position: relative;
`;
var DataManagerTableFooter = styled.div`
  border-top: 1px solid ${({ theme }) => theme.c1Neutral};
  width: 100%;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  ${commonPadding}
  padding-top: ${Spacing.px.md};
  padding-bottom: ${Spacing.px.md};

  ${StyledButton} {
    align-self: end;
  }
`;
var PaginationContainer = styled.div`
  display: flex;
  flex-direction: row;
`;
var PaginationButtonsContainer = styled.div`
  display: flex;
  flex-direction: row;
  margin-left: ${Spacing.px.md};
  gap: ${Spacing.px.xs};
`;
var PageNumberPaginationButtonsContainer = styled.div`
  display: flex;
  flex-direction: row;
  align-items: center;
`;
var PageNumberButton = styled.button`
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  ${standardBorderRadius(8)}
  border: none;
  background-color: transparent;
  &:hover {
    background-color: ${colors["black-04"]};
  }
  &:active {
    background-color: ${colors["black-10"]};
  }
  ${({ isCurrentPage }) => isCurrentPage ? `
      border: 0.5px solid ${colors["black-10"]};
    ` : ""}
`;
var DataManagerTableFilterContainer = styled.div`
  position: absolute;
  z-index: 3;
  right: 0;
  ${StyledButtonRow} + & {
    background: linear-gradient(
      to right,
      ${({ theme }) => themeOr("rgba(0, 0, 0, 0)", "rgba(0, 0, 0, 0)")({ theme })}
        0%,
      ${({ theme }) => getColor(theme, "bg")} 15%
    );
  }
  ${commonPadding}
`;
var FilterDropdownContent = styled.div`
  width: 400px;
  background: ${({ theme }) => theme.bg};
  border: 0.5px solid
    ${({ theme }) => themeOrWithKey("c1Neutral", "c4Neutral")({ theme })};
  ${standardBorderRadius(12)}
  box-shadow:
    0px 1px 4px 0px rgba(0, 0, 0, 0.1),
    0px 4px 8px 0px rgba(0, 0, 0, 0.08);
  ${({ visible }) => !visible && "display: none;"}
`;
var FilterContentInner = styled.div`
  display: flex;
  flex-direction: column;
  gap: ${Spacing.px.xl};
  padding: ${({ isSm }) => isSm ? "0px" : Spacing.px.lg};
  z-index: ${z.dropdown + 1};
  position: relative;
`;
var FilterContentFooter = styled.div`
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
`;
var FilterContentFooterRight = styled.div`
  display: flex;
  gap: ${Spacing.px.xs};
`;

export {
  DataManagerTable
};
