"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var _chunkIDJPIJSNcjs = require('./chunk-IDJPIJSN.cjs');


var _chunkSPJXDMZKcjs = require('./chunk-SPJXDMZK.cjs');




var _chunk4YJ2NQRPcjs = require('./chunk-4YJ2NQRP.cjs');




var _chunkEL4BFAUNcjs = require('./chunk-EL4BFAUN.cjs');




var _chunkXI3DEXNNcjs = require('./chunk-XI3DEXNN.cjs');



var _chunkBGUYF4L2cjs = require('./chunk-BGUYF4L2.cjs');



var _chunkWXIJ3B4Wcjs = require('./chunk-WXIJ3B4W.cjs');



var _chunkWMAEVB25cjs = require('./chunk-WMAEVB25.cjs');


var _chunkRKH2QFA7cjs = require('./chunk-RKH2QFA7.cjs');


var _chunk6EBTM3SIcjs = require('./chunk-6EBTM3SI.cjs');


var _chunkONOZU4XXcjs = require('./chunk-ONOZU4XX.cjs');


var _chunkZUAUG74Vcjs = require('./chunk-ZUAUG74V.cjs');


var _chunkSJ67AQ6Icjs = require('./chunk-SJ67AQ6I.cjs');


var _chunkSGTENCGPcjs = require('./chunk-SGTENCGP.cjs');


var _chunkTXDLUYVGcjs = require('./chunk-TXDLUYVG.cjs');


var _chunkZUAO4DW3cjs = require('./chunk-ZUAO4DW3.cjs');



var _chunkKKOBB4X5cjs = require('./chunk-KKOBB4X5.cjs');


var _chunkZU72XWNEcjs = require('./chunk-ZU72XWNE.cjs');


var _chunkWF7Z2VITcjs = require('./chunk-WF7Z2VIT.cjs');



var _chunkRSHN4K6Ncjs = require('./chunk-RSHN4K6N.cjs');




var _chunkOBHJBBPCcjs = require('./chunk-OBHJBBPC.cjs');



var _chunkKW3JYLRIcjs = require('./chunk-KW3JYLRI.cjs');


var _chunkQQDRBCBYcjs = require('./chunk-QQDRBCBY.cjs');




var _chunkZ6EUSUADcjs = require('./chunk-Z6EUSUAD.cjs');

// src/components/DataManagerTable/DataManagerTable.tsx
var _styled = require('@emotion/styled'); var _styled2 = _interopRequireDefault(_styled);
var _react = require('react');
var _jsxruntime = require('@emotion/react/jsx-runtime');
function getDefaultFilterState(filter) {
  switch (filter.type) {
    case "date" /* DATE */:
      return _chunkWMAEVB25cjs.getDefaultDateFilterState.call(void 0, );
    case "enum" /* ENUM */:
      return _chunk4YJ2NQRPcjs.getDefaultEnumFilterState.call(void 0, );
    case "string" /* STRING */:
      return _chunkXI3DEXNNcjs.getDefaultStringFilterState.call(void 0, );
    case "id" /* ID */:
      return _chunkEL4BFAUNcjs.getDefaultIdFilterState.call(void 0, filter.allowedEntities);
    case "boolean" /* BOOLEAN */:
      return _chunkBGUYF4L2cjs.getDefaultBooleanFilterState.call(void 0, );
    case "currency" /* CURRENCY */:
      return _chunkWXIJ3B4Wcjs.getDefaultCurrencyFilterState.call(void 0, );
    default:
      throw new Error("Invalid filter type");
  }
}
function initialFilterState(filters) {
  let state = {};
  filters.forEach((filter) => {
    state = _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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 = _chunkKW3JYLRIcjs.useBreakpoints.call(void 0, );
  const [pageSize, setPageSize] = _react.useState.call(void 0, ((_c = props.pageSizes) == null ? void 0 : _c[0]) || 20);
  const [pageCursorState, setPageCursorState] = _react.useState.call(void 0, {
    startResult: void 0,
    nextPageCursor: props.nextPageCursor,
    cursorCache: {}
  });
  const [isLoading, setIsLoading] = _react.useState.call(void 0, props.loading || false);
  const [numFiltersApplied, setNumFiltersApplied] = _react.useState.call(void 0, 0);
  const [showFilterEditor, setShowFilterEditor] = _react.useState.call(void 0, false);
  const [filterStates, setFilterStates] = _react.useState.call(void 0, 
    props.filterOptions ? initialFilterState(props.filterOptions.filters) : {}
  );
  const [fetchVariables, setFetchVariables] = _react.useState.call(void 0, 
    ((_d = props.filterOptions) == null ? void 0 : _d.initialQueryVariables) || {}
  );
  const isSm = breakPoint.isSm();
  _react.useEffect.call(void 0, () => {
    setIsLoading(Boolean(props.loading));
  }, [props.loading]);
  _react.useEffect.call(void 0, () => {
    if (!props.nextPageCursor) {
      return;
    }
    const cursorCacheResult = Object.entries(
      pageCursorState.cursorCache[pageSize] || {}
    ).find(([_, cursor]) => cursor === props.nextPageCursor);
    if (cursorCacheResult) {
      setPageCursorState((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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 _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState), {
          startResult,
          nextPageCursor: props.nextPageCursor,
          cursorCache: _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState.cursorCache), {
            [pageSize]: _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState.cursorCache[pageSize]), {
              [startResult]: props.nextPageCursor
            })
          })
        });
      });
    }
  }, [props.nextPageCursor, pageSize, pageCursorState.cursorCache]);
  function updateFilterState(filter) {
    return (state) => {
      setFilterStates((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState), {
        [filter.accessorKey]: state
      }));
    };
  }
  const handleApplyFilters = (filterStates2, filterOptions, pageSize2) => _chunkZ6EUSUADcjs.__async.call(void 0, this, null, function* () {
    var _a2, _b2, _c2, _d2;
    const { filters: filters2, refetch, getFilterQueryVariables } = filterOptions;
    const appliedFilterStates = _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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 (_chunkEL4BFAUNcjs.isIdFilterState.call(void 0, filterState)) {
            const appliedValues = validResult.appliedValues;
            const isApplied = !!(appliedValues == null ? void 0 : appliedValues.length);
            updateFilterState(filter)(_chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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) => _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState));
      return;
    }
    for (let i = 0; i < filterStatesArray.length; i++) {
      const filterState = filterStatesArray[i];
      if (!filterState.isApplied) continue;
      const filter = filters2[i];
      if (_chunkXI3DEXNNcjs.isStringFilterState.call(void 0, 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 = _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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)(_chunkXI3DEXNNcjs.getDefaultStringFilterState.call(void 0, ));
          filterState.isApplied = false;
        }
      } else if (_chunk4YJ2NQRPcjs.isEnumFilterState.call(void 0, filterState)) {
        if (filterState.value) {
          const newFilterState = _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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)(_chunk4YJ2NQRPcjs.getDefaultEnumFilterState.call(void 0, ));
          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) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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 = () => _chunkZ6EUSUADcjs.__async.call(void 0, this, null, function* () {
    if (!props.filterOptions) {
      return;
    }
    const { refetch } = props.filterOptions;
    setIsLoading(true);
    const newFetchVariables = _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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 = () => _chunkZ6EUSUADcjs.__async.call(void 0, this, null, function* () {
    if (!props.filterOptions) {
      return;
    }
    const { refetch } = props.filterOptions;
    setIsLoading(true);
    const newFetchVariables = _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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) => _chunkZ6EUSUADcjs.__async.call(void 0, 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 = _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, fetchVariables), {
      after: cachedCursorState
    });
    setFetchVariables(newFetchVariables);
    try {
      yield refetch(newFetchVariables);
    } catch (e) {
      setIsLoading(false);
      throw e;
    }
    setIsLoading(false);
  });
  const handleChangePageSize = (size) => _chunkZ6EUSUADcjs.__async.call(void 0, 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 = _chunkZ6EUSUADcjs.__spreadValues.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
          _chunkWMAEVB25cjs.DateFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "enum" /* ENUM */:
        return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
          _chunk4YJ2NQRPcjs.EnumFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
          _chunkXI3DEXNNcjs.StringFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            label: filter.label,
            placeholder: filter.placeholder,
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "id" /* ID */:
        return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
          _chunkEL4BFAUNcjs.IdFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            label: filter.label,
            placeholder: filter.placeholder,
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "boolean" /* BOOLEAN */:
        return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
          _chunkBGUYF4L2cjs.BooleanFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, prevState), {
                [filter.accessorKey]: state
              }));
            },
            label: filter.label,
            state: filterStates[filter.accessorKey]
          }
        ) }, filter.label);
      case "currency" /* CURRENCY */:
        return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
          _chunkWXIJ3B4Wcjs.CurrencyFilter,
          {
            updateFilterState: (state) => {
              setFilterStates((prevState) => _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, 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__ */ _jsxruntime.jsxs.call(void 0, 
    FilterContentInner,
    {
      onKeyDownCapture: (e) => {
        if (e.key === "Enter") {
          onApply();
        }
      },
      isSm,
      children: [
        filterSections,
        /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, FilterContentFooter, { children: [
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKKOBB4X5cjs.Button, { text: "Clear", onClick: handleClearFilters }),
          /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, FilterContentFooterRight, { children: [
            /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKKOBB4X5cjs.Button, { text: "Cancel", onClick: () => setShowFilterEditor(false) }),
            /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKKOBB4X5cjs.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__ */ _jsxruntime.jsx.call(void 0, FilterContainerComponent, { children: isSm ? /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _react.Fragment, { children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkKKOBB4X5cjs.Button,
        _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, commonButtonProps), props.filterButtonProps), {
          onClick: () => setShowFilterEditor(!showFilterEditor)
        })
      ),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkONOZU4XXcjs.Modal,
        {
          visible: showFilterEditor,
          onClose: () => setShowFilterEditor(false),
          smKind: "fullscreen",
          children: filterContent
        }
      )
    ] }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      _chunkZUAUG74Vcjs.Dropdown,
      {
        borderRadius: 12,
        maxDropdownItemsWidth: 400,
        dropdownContent: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, FilterDropdownContent, { visible: showFilterEditor, children: filterContent }),
        isOpen: showFilterEditor,
        onOpen: () => {
          setShowFilterEditor(true);
        },
        onClose: () => {
          setShowFilterEditor(false);
        },
        button: _chunkZ6EUSUADcjs.__spreadValues.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, commonButtonProps), props.filterButtonProps),
        align: props.filterDropdownAlign || "right"
      }
    ) });
  }
  let showMoreDropdown;
  if (((_f = props.pageSizes) == null ? void 0 : _f.length) > 1) {
    showMoreDropdown = /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
      _chunkZUAUG74Vcjs.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__ */ _jsxruntime.jsx.call(void 0, 
            _chunkSJ67AQ6Icjs.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__ */ _jsxruntime.jsxs.call(void 0, DataManagerTableFooter, { children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkKKOBB4X5cjs.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__ */ _jsxruntime.jsx.call(void 0, "div", {}) : /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk6EBTM3SIcjs.Label, { children: "Viewing " }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRKH2QFA7cjs.LabelModerate, { children: `${startResult}-${endResult}` }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk6EBTM3SIcjs.Label, { children: " of " }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkRKH2QFA7cjs.LabelModerate, { children: `${countString}` }),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk6EBTM3SIcjs.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__ */ _jsxruntime.jsxs.call(void 0, PageNumberPaginationButtonsContainer, { children: [
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkKKOBB4X5cjs.Button,
        {
          icon: {
            name: "CentralChevronLeftSmall",
            width: 24,
            color: "text"
          },
          kind: "ghost",
          paddingY: "short",
          onClick: () => void handlePrev(),
          disabled: !hasPrev
        }
      ),
      pageNumbers.slice(0, 2).map((pageNumber) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        PageNumberButton,
        {
          onClick: () => void handleChangePage(pageNumber + 1),
          isCurrentPage: currentPage === pageNumber + 1,
          children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkIDJPIJSNcjs.Body, { content: `${pageNumber + 1}` })
        },
        pageNumber
      )),
      pageNumbers.length > 4 && currentPage - 2 > 1 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkWF7Z2VITcjs.Icon,
        {
          name: "CentralDotGrid1x3Horizontal",
          width: 18,
          ml: 7,
          mr: 7,
          color: "text"
        }
      ),
      currentPage - 1 > 1 && currentPage < pageNumbers.length && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        PageNumberButton,
        {
          isCurrentPage: true,
          onClick: () => void handleChangePage(currentPage),
          children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkIDJPIJSNcjs.Body, { content: `${currentPage}` })
        },
        currentPage
      ),
      pageNumbers.length > 4 && currentPage + 1 < pageNumbers.length && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkWF7Z2VITcjs.Icon,
        {
          name: "CentralDotGrid1x3Horizontal",
          width: 18,
          ml: 7,
          mr: 7,
          color: "text"
        }
      ),
      pageNumbers.length > 4 && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        PageNumberButton,
        {
          isCurrentPage: currentPage === pageNumbers.length,
          onClick: () => void handleChangePage(pageNumbers.length),
          children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkIDJPIJSNcjs.Body, { content: `${pageNumbers.length}` })
        },
        pageNumbers.length
      ),
      /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
        _chunkKKOBB4X5cjs.Button,
        {
          icon: {
            name: "CentralChevronRightSmall",
            width: 24,
            color: "text"
          },
          kind: "ghost",
          paddingY: "short",
          onClick: () => void handleNext(),
          disabled: !hasNext
        }
      )
    ] }) : /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _jsxruntime.Fragment, {});
    footer = /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, DataManagerTableFooter, { children: [
      resultsString,
      pageNumberButtons,
      /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, PaginationContainer, { children: [
        showMoreDropdown,
        showPaginationPreviousNext && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, PaginationButtonsContainer, { children: [
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
            _chunkKKOBB4X5cjs.Button,
            {
              text: "Previous",
              paddingY: "short",
              onClick: () => {
                void handlePrev();
              },
              disabled: !hasPrev
            }
          ),
          /* @__PURE__ */ _jsxruntime.jsx.call(void 0, 
            _chunkKKOBB4X5cjs.Button,
            {
              text: "Next",
              paddingY: "short",
              onClick: () => {
                void handleNext();
              },
              disabled: !hasNext
            }
          )
        ] })
      ] })
    ] });
  }
  const DataManagerTableHeaderComponent = ((_j = props.customComponents) == null ? void 0 : _j.dataManagerTableHeaderComponent) || DataManagerTableHeader;
  const content = /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, _jsxruntime.Fragment, { children: [
    props.showHeader && /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, DataManagerTableHeaderComponent, { children: [
      props.header,
      filters
    ] }),
    /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkSPJXDMZKcjs.Table, _chunkZ6EUSUADcjs.__spreadProps.call(void 0, _chunkZ6EUSUADcjs.__spreadValues.call(void 0, {}, props), { loading: isLoading })),
    footer
  ] });
  return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, StyledDataManagerTable, { children: isCardPageFullWidth ? /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkSGTENCGPcjs.CardPageFullWidth, { css: { marginTop: `${cardPageMt}px` }, children: content }) : content });
}
var StyledDataManagerTable = _styled2.default.div`
  width: 100%;
`;
var commonPadding = `
  ${_chunkKW3JYLRIcjs.bp.lg(`
  padding-left: ${_chunkRSHN4K6Ncjs.standardContentInset.lgPx}px;
  padding-right: ${_chunkRSHN4K6Ncjs.standardContentInset.lgPx}px;
  `)}
  ${_chunkKW3JYLRIcjs.bp.sm(`
  padding-left: ${_chunkRSHN4K6Ncjs.standardContentInset.smPx}px;
  padding-right: ${_chunkRSHN4K6Ncjs.standardContentInset.smPx}px;
  `)}
  ${_chunkKW3JYLRIcjs.bp.minSmMaxLg(`
  padding-left: ${_chunkRSHN4K6Ncjs.standardContentInset.minSmMaxLgPx}px;
  padding-right: ${_chunkRSHN4K6Ncjs.standardContentInset.minSmMaxLgPx}px;
  `)}
`;
var DataManagerTableHeader = _styled2.default.div`
  display: flex;
  flex-direction: row;
  align-items: center;
  padding: ${_chunkZUAO4DW3cjs.Spacing.px.xs} 0;
  position: relative;
`;
var DataManagerTableFooter = _styled2.default.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: ${_chunkZUAO4DW3cjs.Spacing.px.md};
  padding-bottom: ${_chunkZUAO4DW3cjs.Spacing.px.md};

  ${_chunkKKOBB4X5cjs.StyledButton} {
    align-self: end;
  }
`;
var PaginationContainer = _styled2.default.div`
  display: flex;
  flex-direction: row;
`;
var PaginationButtonsContainer = _styled2.default.div`
  display: flex;
  flex-direction: row;
  margin-left: ${_chunkZUAO4DW3cjs.Spacing.px.md};
  gap: ${_chunkZUAO4DW3cjs.Spacing.px.xs};
`;
var PageNumberPaginationButtonsContainer = _styled2.default.div`
  display: flex;
  flex-direction: row;
  align-items: center;
`;
var PageNumberButton = _styled2.default.button`
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  cursor: pointer;
  ${_chunkRSHN4K6Ncjs.standardBorderRadius.call(void 0, 8)}
  border: none;
  background-color: transparent;
  &:hover {
    background-color: ${_chunkQQDRBCBYcjs.colors["black-04"]};
  }
  &:active {
    background-color: ${_chunkQQDRBCBYcjs.colors["black-10"]};
  }
  ${({ isCurrentPage }) => isCurrentPage ? `
      border: 0.5px solid ${_chunkQQDRBCBYcjs.colors["black-10"]};
    ` : ""}
`;
var DataManagerTableFilterContainer = _styled2.default.div`
  position: absolute;
  z-index: 3;
  right: 0;
  ${_chunkTXDLUYVGcjs.StyledButtonRow} + & {
    background: linear-gradient(
      to right,
      ${({ theme }) => _chunkOBHJBBPCcjs.themeOr.call(void 0, "rgba(0, 0, 0, 0)", "rgba(0, 0, 0, 0)")({ theme })}
        0%,
      ${({ theme }) => _chunkOBHJBBPCcjs.getColor.call(void 0, theme, "bg")} 15%
    );
  }
  ${commonPadding}
`;
var FilterDropdownContent = _styled2.default.div`
  width: 400px;
  background: ${({ theme }) => theme.bg};
  border: 0.5px solid
    ${({ theme }) => _chunkOBHJBBPCcjs.themeOrWithKey.call(void 0, "c1Neutral", "c4Neutral")({ theme })};
  ${_chunkRSHN4K6Ncjs.standardBorderRadius.call(void 0, 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 = _styled2.default.div`
  display: flex;
  flex-direction: column;
  gap: ${_chunkZUAO4DW3cjs.Spacing.px.xl};
  padding: ${({ isSm }) => isSm ? "0px" : _chunkZUAO4DW3cjs.Spacing.px.lg};
  z-index: ${_chunkZU72XWNEcjs.z.dropdown + 1};
  position: relative;
`;
var FilterContentFooter = _styled2.default.div`
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
`;
var FilterContentFooterRight = _styled2.default.div`
  display: flex;
  gap: ${_chunkZUAO4DW3cjs.Spacing.px.xs};
`;



exports.DataManagerTable = DataManagerTable;
