'use strict';

var _ConfigProvider = require('antd/lib/config-provider');
var _Table = require('antd/lib/table');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var neetoCist = require('@bigbinary/neeto-cist');
var Left = require('@bigbinary/neeto-icons/Left');
var Right = require('@bigbinary/neeto-icons/Right');
var MenuHorizontal = require('@bigbinary/neeto-icons/MenuHorizontal');
var ramda = require('ramda');
var ReactDragListView = require('react-drag-listview');
var reactI18next = require('react-i18next');
var reactRouterDom = require('react-router-dom');
var constants = require('./constants.js');
require('@bigbinary/neeto-hotkeys');
require('./overlayManager.js');
var index = require('./index-CNZKW5X0.js');
var useQueryParams = require('./useQueryParams-BT5EJ1-8.js');
var Button = require('./Button.js');
var Callout = require('./Callout.js');
var Typography = require('./Typography.js');
var jsxRuntime = require('react/jsx-runtime');
var DatePicker = require('./index-BIFpyYcO.js');
var reactResizable = require('react-resizable');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('qs');
require('./index-BgzkP01c.js');
require('i18next');
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var DownArrow = require('@bigbinary/neeto-icons/DownArrow');
var UpArrow = require('@bigbinary/neeto-icons/UpArrow');
var InfoRound = require('@bigbinary/neeto-icons/InfoRound');
var Popover = require('./Popover.js');
var Spinner = require('./Spinner.js');
require('antd/locale/de_DE');
require('antd/locale/en_US');
require('antd/locale/es_ES');
require('antd/locale/fr_FR');
require('antd/locale/nl_NL');
require('antd/locale/pl_PL');
require('antd/locale/pt_PT');
require('./en-B1i-pQJm.js');
require('./Tooltip.js');
require('@tippyjs/react');
require('tippy.js');
require('./usePrefersReducedMotion-D2Ck84HM.js');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');
require('@bigbinary/neeto-icons/Clock');
require('./Accordion.js');
require('framer-motion');
require('./ActionDropdown.js');
require('./Dropdown.js');
require('@bigbinary/neeto-icons/Down');
require('./useId-DXHUzdxd.js');
require('./Textarea-DxdJutA8.js');
require('./Label.js');
require('@bigbinary/neeto-icons/Help');
require('./Modal.js');
require('@bigbinary/neeto-icons/Close');
require('./Portal-nCvANFeL.js');
require('@babel/runtime/helpers/esm/extends');
require('@babel/runtime/helpers/esm/objectWithoutPropertiesLoose');
require('@babel/runtime/helpers/esm/inheritsLoose');
require('react-dom');
require('avvvatars-react');
require('./Checkbox.js');
require('@babel/runtime/helpers/asyncToGenerator');
require('@babel/runtime/regenerator');
require('@bigbinary/neeto-icons/ColorPicker');
require('react-colorful');
require('./useRecentlyUsedColors-P_o42kpC.js');
require('antd/lib/date-picker');
require('@bigbinary/neeto-icons/Calendar');
require('./Input.js');
require('./MultiEmailInput.js');
require('./react-select-creatable.esm-CYabSQvs.js');
require('@babel/runtime/helpers/esm/objectSpread2');
require('@babel/runtime/helpers/esm/classCallCheck');
require('@babel/runtime/helpers/esm/createClass');
require('@babel/runtime/helpers/esm/inherits');
require('@babel/runtime/helpers/esm/createSuper');
require('@babel/runtime/helpers/esm/toConsumableArray');
require('@babel/runtime/helpers/extends');
require('@babel/runtime/helpers/esm/taggedTemplateLiteral');
require('@babel/runtime/helpers/esm/objectWithoutProperties');
require('@babel/runtime/helpers/esm/slicedToArray');
require('@babel/runtime/helpers/esm/typeof');
require('@babel/runtime/helpers/esm/defineProperty');
require('@babel/runtime/helpers/objectSpread2');
require('@babel/runtime/helpers/inherits');
require('@babel/runtime/helpers/createSuper');
require('@babel/runtime/helpers/taggedTemplateLiteral');
require('@babel/runtime/helpers/typeof');
require('@babel/runtime/helpers/toArray');
require('./Tag.js');
require('./Pane.js');
require('./Radio.js');
require('antd/lib/slider');
require('./Switch.js');
require('@bigbinary/neeto-icons/Check');
require('./Tab.js');
require('@bigbinary/neeto-icons/Ascending');
require('@bigbinary/neeto-icons/Descending');
require('@bigbinary/neeto-icons/Pin');
require('@bigbinary/neeto-icons/ColumnToLeft');
require('@bigbinary/neeto-icons/ColumnToRight');
require('@bigbinary/neeto-icons/Hide');
require('zustand');
require('./Toastr.js');
require('@bigbinary/neeto-icons/CheckCircle');
require('@bigbinary/neeto-icons/Warning');
require('@bigbinary/neeto-icons/Info');
require('react-toastify');
require('linkify-react');
require('antd/lib/tree');
require('./TreeSelect.js');
require('antd/lib/tree-select');
require('./Select.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _ConfigProvider__default = /*#__PURE__*/_interopDefault(_ConfigProvider);
var _Table__default = /*#__PURE__*/_interopDefault(_Table);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__default = /*#__PURE__*/_interopDefault(React);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var Left__default = /*#__PURE__*/_interopDefault(Left);
var Right__default = /*#__PURE__*/_interopDefault(Right);
var MenuHorizontal__default = /*#__PURE__*/_interopDefault(MenuHorizontal);
var ReactDragListView__default = /*#__PURE__*/_interopDefault(ReactDragListView);
var _toConsumableArray__default = /*#__PURE__*/_interopDefault(_toConsumableArray);
var DownArrow__default = /*#__PURE__*/_interopDefault(DownArrow);
var UpArrow__default = /*#__PURE__*/_interopDefault(UpArrow);
var InfoRound__default = /*#__PURE__*/_interopDefault(InfoRound);

var useTimeout = function useTimeout(callback, delay) {
  var savedCallback = React.useRef(callback);
  React.useEffect(function () {
    savedCallback.current = callback;
  }, [callback]);
  React.useEffect(function () {
    var id = setTimeout(function () {
      return savedCallback.current();
    }, delay);
    return function () {
      return clearTimeout(id);
    };
  }, [delay]);
};

function ownKeys$9(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var AllRowsSelectedCallout = function AllRowsSelectedCallout(_ref) {
  var calloutProps = _ref.calloutProps,
    onClearSelection = _ref.onClearSelection,
    allRowsSelectedMessage = _ref.allRowsSelectedMessage,
    clearSelectionButtonLabel = _ref.clearSelectionButtonLabel;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t,
    i18n = _useTranslation.i18n;
  return /*#__PURE__*/jsxRuntime.jsx(Callout, _objectSpread$9(_objectSpread$9({
    className: "my-2"
  }, calloutProps), {}, {
    "data-testid": "clear-selections-callout",
    children: /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-ui-flex neeto-ui-gap-3",
      children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
        style: "body2",
        children: allRowsSelectedMessage || index.getLocale(i18n, t, "neetoui.table.allRowsSelected")
      }), /*#__PURE__*/jsxRuntime.jsx(Button, {
        "data-testid": "clear-selections-button",
        style: "link",
        label: clearSelectionButtonLabel || index.getLocale(i18n, t, "neetoui.table.clearSelection"),
        onClick: onClearSelection
      })]
    })
  }));
};

function ownKeys$8(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$8(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$8(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$8(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var SelectAllRowsCallout = function SelectAllRowsCallout(_ref) {
  var calloutProps = _ref.calloutProps,
    onBulkSelectAllRows = _ref.onBulkSelectAllRows,
    selectAllRowButtonLabel = _ref.selectAllRowButtonLabel,
    selectAllRowMessage = _ref.selectAllRowMessage;
  return /*#__PURE__*/jsxRuntime.jsx(Callout, _objectSpread$8(_objectSpread$8({
    className: "my-2"
  }, calloutProps), {}, {
    "data-testid": "select-all-rows-callout",
    children: /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-ui-flex neeto-ui-gap-3",
      children: [/*#__PURE__*/jsxRuntime.jsx(Typography, {
        style: "body2",
        children: selectAllRowMessage
      }), /*#__PURE__*/jsxRuntime.jsx(Button, {
        "data-testid": "select-all-rows-button",
        label: selectAllRowButtonLabel,
        style: "link",
        onClick: onBulkSelectAllRows
      })]
    })
  }));
};

var useLocalStorage = function useLocalStorage(key, defaultValue) {
  var _useState = React.useState(function () {
      return index.getFromLocalStorage(key, defaultValue);
    }),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    storedValue = _useState2[0],
    setStoredValue = _useState2[1];
  var setValue = function setValue(value) {
    return setStoredValue(function (prevStoredValue) {
      var newValue = typeof value === "function" ? value(prevStoredValue) : value;
      if (ramda.isNil(newValue)) {
        index.removeFromLocalStorage(key);
      } else {
        index.setToLocalStorage(key, newValue);
      }
      return newValue;
    });
  };
  return [storedValue, setValue];
};

var _excluded$6 = ["children", "isSortable", "isAddEnabled", "sortedInfo", "onSort", "isHidable", "isDeletable", "isFixedColumn", "isColumnFreezeEnabled", "isMoveToLeftEnabled", "isMoveToRightEnabled", "onColumnHide", "onColumnUpdate", "onAddColumn", "onColumnDelete", "onColumnFreeze", "onMoreActionClick", "column", "moreActions"];
function ownKeys$7(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$7(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$7(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$7(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var CellContent$1 = function CellContent(_ref) {
  var children = _ref.children,
    isSortable = _ref.isSortable,
    isAddEnabled = _ref.isAddEnabled,
    sortedInfo = _ref.sortedInfo,
    onSort = _ref.onSort,
    _ref$isHidable = _ref.isHidable,
    isHidable = _ref$isHidable === void 0 ? true : _ref$isHidable,
    _ref$isDeletable = _ref.isDeletable,
    isDeletable = _ref$isDeletable === void 0 ? false : _ref$isDeletable,
    isFixedColumn = _ref.isFixedColumn,
    isColumnFreezeEnabled = _ref.isColumnFreezeEnabled,
    isMoveToLeftEnabled = _ref.isMoveToLeftEnabled,
    isMoveToRightEnabled = _ref.isMoveToRightEnabled,
    onColumnHide = _ref.onColumnHide,
    onColumnUpdate = _ref.onColumnUpdate,
    onAddColumn = _ref.onAddColumn,
    onColumnDelete = _ref.onColumnDelete,
    onColumnFreeze = _ref.onColumnFreeze,
    onMoreActionClick = _ref.onMoreActionClick,
    column = _ref.column,
    _ref$moreActions = _ref.moreActions,
    moreActions = _ref$moreActions === void 0 ? [] : _ref$moreActions,
    headerProps = _objectWithoutProperties__default.default(_ref, _excluded$6);
  var isColumnHidable = isHidable && neetoCist.isPresent(onColumnHide);
  var isColumnDeletable = isDeletable && neetoCist.isPresent(onColumnDelete);
  var hasMoreActions = !ramda.isEmpty(moreActions) && neetoCist.isPresent(onMoreActionClick);
  var hasMoreMenu = isSortable || isColumnHidable || isAddEnabled || hasMoreActions || neetoCist.isPresent(column) && isColumnFreezeEnabled;
  return /*#__PURE__*/jsxRuntime.jsx("th", _objectSpread$7(_objectSpread$7({}, headerProps), {}, {
    title: "",
    onClick: isSortable ? neetoCist.noop : headerProps.onClick,
    children: /*#__PURE__*/jsxRuntime.jsxs("div", {
      className: "neeto-ui-flex neeto-ui-items-center neeto-ui-justify-between",
      "data-testid": "".concat(index.hyphenize(headerProps.title), "-header-title"),
      children: [/*#__PURE__*/jsxRuntime.jsx("div", {
        className: "neeto-ui-min-w-0 neeto-ui-flex-grow neeto-ui-truncate neeto-ui-table__column-title-content",
        children: children
      }), hasMoreMenu && /*#__PURE__*/jsxRuntime.jsx(DatePicker.HeaderCellMenu, {
        column: column,
        hasMoreActions: hasMoreActions,
        isAddEnabled: isAddEnabled,
        isColumnDeletable: isColumnDeletable,
        isColumnFreezeEnabled: isColumnFreezeEnabled,
        isFixedColumn: isFixedColumn,
        isMoveToLeftEnabled: isMoveToLeftEnabled,
        isMoveToRightEnabled: isMoveToRightEnabled,
        isSortable: isSortable,
        moreActions: moreActions,
        onAddColumn: onAddColumn,
        onColumnDelete: onColumnDelete,
        onColumnFreeze: onColumnFreeze,
        onColumnHide: onColumnHide,
        onColumnUpdate: onColumnUpdate,
        onMoreActionClick: onMoreActionClick,
        onSort: onSort,
        sortedInfo: sortedInfo,
        isHidable: isColumnHidable
      })]
    })
  }));
};
var CellContent = /*#__PURE__*/React__default.default.memo(CellContent$1);

var _excluded$5 = ["resizeHandles"];
function ownKeys$6(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$6(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$6(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$6(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var rtlResizeHandles = ["w"];
var Resizable = function Resizable(_ref) {
  var resizeHandles = _ref.resizeHandles,
    rest = _objectWithoutProperties__default.default(_ref, _excluded$5);
  return /*#__PURE__*/jsxRuntime.jsx(reactResizable.Resizable, _objectSpread$6(_objectSpread$6({}, rest), {}, {
    resizeHandles: index.getContentDir() === "rtl" ? rtlResizeHandles : resizeHandles
  }));
};

var _excluded$4 = ["onResize", "width", "onResizeStop", "className"];
function ownKeys$5(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$5(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$5(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$5(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var HeaderCell$1 = function HeaderCell(props) {
  var onResize = props.onResize,
    width = props.width,
    onResizeStop = props.onResizeStop,
    className = props.className,
    restProps = _objectWithoutProperties__default.default(props, _excluded$4);
  if (!width) {
    return /*#__PURE__*/jsxRuntime.jsx(CellContent, _objectSpread$5(_objectSpread$5({}, restProps), {}, {
      className: classnames__default.default(className, "drag-handler")
    }));
  }
  return /*#__PURE__*/jsxRuntime.jsx(Resizable, {
    onResize: onResize,
    onResizeStop: onResizeStop,
    width: width,
    draggableOpts: {
      enableUserSelectHack: false
    },
    height: 0,
    handle: /*#__PURE__*/jsxRuntime.jsx("span", {
      className: "react-resizable-handle",
      onClick: function onClick(e) {
        return e.stopPropagation();
      }
    }),
    onResizeStart: function onResizeStart(e) {
      e.preventDefault();
    },
    children: /*#__PURE__*/jsxRuntime.jsx(CellContent, _objectSpread$5(_objectSpread$5({}, restProps), {}, {
      className: classnames__default.default(className, "drag-handler")
    }))
  });
};
var HeaderCell = /*#__PURE__*/React__default.default.memo(HeaderCell$1);

var _excluded$3 = ["onResize", "width", "onResizeStop", "onResizeStart"];
function ownKeys$4(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$4(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$4(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$4(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var ResizableHeaderCell$1 = function ResizableHeaderCell(props) {
  var onResize = props.onResize,
    width = props.width,
    _onResizeStop = props.onResizeStop,
    _onResizeStart = props.onResizeStart,
    restProps = _objectWithoutProperties__default.default(props, _excluded$3);
  var _useState = React.useState(false),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    isResizing = _useState2[0],
    setIsResizing = _useState2[1];
  if (!width) {
    return /*#__PURE__*/jsxRuntime.jsx(CellContent, _objectSpread$4({}, restProps));
  }
  return /*#__PURE__*/jsxRuntime.jsx(Resizable, _defineProperty__default.default(_defineProperty__default.default({
    onResize: onResize,
    onResizeStop: _onResizeStop,
    width: width,
    draggableOpts: {
      enableUserSelectHack: false
    },
    height: 0,
    handle: /*#__PURE__*/jsxRuntime.jsx("span", {
      className: classnames__default.default("react-resizable-handle", {
        "react-resizable-handle--resizing": isResizing
      }),
      onClick: function onClick(e) {
        return e.stopPropagation();
      },
      children: /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "neeto-ui-table-react-resizable-handle__inner"
      })
    }),
    onResizeStart: function onResizeStart(e, data) {
      e.preventDefault();
      setIsResizing(true);
      _onResizeStart === null || _onResizeStart === void 0 ? void 0 : _onResizeStart(e, data);
    }
  }, "onResizeStop", function onResizeStop(e, data) {
    setIsResizing(false);
    _onResizeStop === null || _onResizeStop === void 0 ? void 0 : _onResizeStop(e, data);
  }), "children", /*#__PURE__*/jsxRuntime.jsx(CellContent, _objectSpread$4({}, restProps))));
};
var ResizableHeaderCell = /*#__PURE__*/React__default.default.memo(ResizableHeaderCell$1);

var _excluded$2 = ["className"];
function ownKeys$3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$3(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$3(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$3(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var ReorderableHeaderCell = function ReorderableHeaderCell(_ref) {
  var className = _ref.className,
    props = _objectWithoutProperties__default.default(_ref, _excluded$2);
  return /*#__PURE__*/jsxRuntime.jsx(CellContent, _objectSpread$3(_objectSpread$3({}, props), {}, {
    className: classnames__default.default(className, "drag-handler")
  }));
};

var convertLocationPathnameToId = function convertLocationPathnameToId() {
  var pathname = decodeURIComponent(window.location.pathname).replace(/^\//, "");
  var hash = 0;
  for (var i = 0; i < pathname.length; i++) {
    var _char = pathname.charCodeAt(i);
    hash = (hash << 5) - hash + _char;
    hash = hash & hash; // Convert to 32-bit integer
  }
  return Math.abs(hash).toString(16).toUpperCase();
};
var getHeaderCell = function getHeaderCell(_ref) {
  var enableColumnResize = _ref.enableColumnResize,
    enableColumnReorder = _ref.enableColumnReorder;
  if (enableColumnReorder && enableColumnResize) return {
    cell: HeaderCell
  };
  if (enableColumnResize) return {
    cell: ResizableHeaderCell
  };
  if (enableColumnReorder) return {
    cell: ReorderableHeaderCell
  };
  return {
    cell: CellContent
  };
};
var isIncludedIn = function isIncludedIn(array1, array2) {
  return ramda.all(ramda.includes(ramda.__, array1), array2);
};
var getSelectAllRowsCalloutHeight = function getSelectAllRowsCalloutHeight() {
  return window.innerWidth < 768 ? DatePicker.SELECT_ALL_ROWS_CALLOUT_MOBILE_HEIGHT : DatePicker.SELECT_ALL_ROWS_CALLOUT_DESKTOP_HEIGHT;
};
var sortFrozenColumns = function sortFrozenColumns(columnData) {
  var originalIndices = new Map(columnData.map(function (col, index) {
    return [col.dataIndex, index];
  }));
  return function (a, b) {
    var aFixed = neetoCist.isPresent(a.fixed);
    var bFixed = neetoCist.isPresent(b.fixed);
    var aIndex = originalIndices.get(a.dataIndex);
    var bIndex = originalIndices.get(b.dataIndex);
    if (aFixed !== bFixed) return aFixed ? -1 : 1;
    return aIndex - bIndex;
  };
};
var getFixedColumns = function getFixedColumns(columnData) {
  return ramda.pipe(ramda.filter(function (_ref2) {
    var fixed = _ref2.fixed;
    return neetoCist.isPresent(fixed);
  }), ramda.pluck("dataIndex"))(columnData);
};
var getColumnSortOrder = function getColumnSortOrder(col, sortedInfo) {
  return ramda.equals(sortedInfo.field, col.dataIndex) || ramda.equals(sortedInfo.field, col.key) ? sortedInfo.order : null;
};
var getColumFixedValue = function getColumFixedValue(col, frozenColumns) {
  return (frozenColumns === null || frozenColumns === void 0 ? void 0 : frozenColumns.indexOf(col.dataIndex)) !== -1 ? DatePicker.COLUMN_FIXED_VALUES.LEFT : null;
};
var getFrozenColumnsLocalStorageKey = function getFrozenColumnsLocalStorageKey(localStorageKeyPrefix) {
  var prefix = neetoCist.isPresent(localStorageKeyPrefix) ? localStorageKeyPrefix : convertLocationPathnameToId();
  return "NEETOUI-".concat(prefix, "-FIXED_COLUMNS");
};
var getSortInfoFromQueryParams = function getSortInfoFromQueryParams(queryParams) {
  var sortedInfo = {};
  if (neetoCist.isPresent(queryParams.sort_by) && neetoCist.isPresent(queryParams.order_by) && neetoCist.isPresent(DatePicker.TABLE_SORT_ORDERS[queryParams.order_by])) {
    sortedInfo.field = queryParams.sort_by.includes("+") ? queryParams.sort_by.split("+").map(neetoCist.snakeToCamelCase) : neetoCist.snakeToCamelCase(queryParams.sort_by);
    sortedInfo.order = DatePicker.TABLE_SORT_ORDERS[queryParams.order_by];
  }
  return sortedInfo;
};
var getSortField = function getSortField(field) {
  if (Array.isArray(field)) {
    return field.map(neetoCist.camelToSnakeCase).join("+");
  }
  return neetoCist.camelToSnakeCase(field);
};
var calculateRowsPerPage = function calculateRowsPerPage() {
  var viewportHeight = window.innerHeight;
  var rowsPerPage = Math.floor((viewportHeight - DatePicker.TABLE_PAGINATION_HEIGHT) / DatePicker.TABLE_ROW_HEIGHT * 3);
  return Math.ceil(rowsPerPage / 10) * 10;
};
var filterVisibleColumns = function filterVisibleColumns(columns) {
  return columns.filter(function (col) {
    return col.hidden !== true && col.isShown !== false;
  });
};

var useReorderColumns = function useReorderColumns(_ref) {
  var isEnabled = _ref.isEnabled,
    columns = _ref.columns,
    setColumns = _ref.setColumns,
    onColumnUpdateWithChanges = _ref.onColumnUpdateWithChanges,
    rowSelection = _ref.rowSelection;
  if (!isEnabled) return {
    dragProps: {},
    columns: columns
  };
  var isColumnFixed = function isColumnFixed(column) {
    return !!column.fixed;
  };
  var dragProps = {
    onDragEnd: function onDragEnd(fromIndex, toIndex) {
      if (rowSelection) {
        fromIndex--;
        toIndex--;
      }
      if (fromIndex < 0 || toIndex < 0 || fromIndex === toIndex) return;
      var visibleColumns = filterVisibleColumns(columns);
      var fromColumn = visibleColumns[fromIndex];
      var toColumn = visibleColumns[toIndex];
      if (!fromColumn || !toColumn) return;else if (isColumnFixed(fromColumn) || isColumnFixed(toColumn)) return;
      var fromColumnActualIndex = columns.indexOf(fromColumn);
      var toColumnActualIndex = columns.indexOf(toColumn);
      if (fromColumnActualIndex < 0 || toColumnActualIndex < 0) return;
      var newColumns = ramda.move(fromColumnActualIndex, toColumnActualIndex, columns);
      setColumns(newColumns);
      onColumnUpdateWithChanges(newColumns);
    },
    nodeSelector: "th:not(.ant-table-cell-fix-left):not(.ant-table-cell-scrollbar)",
    handleSelector: ".drag-handler",
    ignoreSelector: ".react-resizable-handle"
  };
  return {
    dragProps: dragProps,
    columns: columns
  };
};

var SortIcon = function SortIcon(_ref) {
  var sortOrder = _ref.sortOrder;
  if (sortOrder === DatePicker.TABLE_SORT_ORDERS.asc || sortOrder === DatePicker.URL_SORT_ORDERS.ascend) {
    return /*#__PURE__*/jsxRuntime.jsx(UpArrow__default.default, {
      size: 14
    });
  }
  if (sortOrder === DatePicker.TABLE_SORT_ORDERS.desc || sortOrder === DatePicker.URL_SORT_ORDERS.descend) {
    return /*#__PURE__*/jsxRuntime.jsx(DownArrow__default.default, {
      size: 14
    });
  }
  return null;
};

var _excluded$1 = ["title", "description"];
var TitleWithInfoIcon$1 = function TitleWithInfoIcon(_ref) {
  var title = _ref.title,
    description = _ref.description,
    rest = _objectWithoutProperties__default.default(_ref, _excluded$1);
  var popoverRef = React.useRef();
  return /*#__PURE__*/jsxRuntime.jsxs("span", {
    className: "neeto-ui-pr-5 neeto-ui-inline-flex relative",
    children: [typeof title === "function" ? title(rest) : title, description && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
      children: [/*#__PURE__*/jsxRuntime.jsx("span", {
        className: "neeto-ui-table__column-title-info-icon",
        "data-testid": "column-info-icon",
        ref: popoverRef,
        children: /*#__PURE__*/jsxRuntime.jsx(InfoRound__default.default, {
          color: "currentColor",
          size: 14
        })
      }), /*#__PURE__*/jsxRuntime.jsx(Popover, {
        appendTo: function appendTo() {
          return document.body;
        },
        className: "max-h-64 overflow-y-auto",
        position: "bottom",
        reference: popoverRef,
        children: /*#__PURE__*/jsxRuntime.jsx(Typography, {
          lineHeight: "normal",
          style: "body2",
          children: description
        })
      })]
    })]
  });
};
var TitleWithInfoIcon = /*#__PURE__*/React__default.default.memo(TitleWithInfoIcon$1);

function ownKeys$2(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$2(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$2(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var useResizableColumns = function useResizableColumns(_ref) {
  var columns = _ref.columns,
    columnData = _ref.columnData,
    frozenColumns = _ref.frozenColumns,
    setColumns = _ref.setColumns,
    isEnabled = _ref.isEnabled,
    isAddEnabled = _ref.isAddEnabled,
    isColumnFreezeEnabled = _ref.isColumnFreezeEnabled,
    onColumnAdd = _ref.onColumnAdd,
    onColumnUpdate = _ref.onColumnUpdate,
    onColumnUpdateWithChanges = _ref.onColumnUpdateWithChanges,
    onColumnDelete = _ref.onColumnDelete,
    handleSort = _ref.handleSort,
    sortedInfo = _ref.sortedInfo,
    onColumnHide = _ref.onColumnHide,
    onColumnFreeze = _ref.onColumnFreeze,
    onMoreActionClick = _ref.onMoreActionClick,
    tableOnChangeProps = _ref.tableOnChangeProps;
  var handleResize = function handleResize(index) {
    return function (_, _ref2) {
      var size = _ref2.size;
      var nextColumns = _toConsumableArray__default.default(columns);
      nextColumns[index] = _objectSpread$2(_objectSpread$2({}, nextColumns[index]), {}, {
        width: size.width
      });
      setColumns(nextColumns);
    };
  };
  var computedColumnsData = React.useMemo(function () {
    return columns.map(function (col, index) {
      var fixed = getColumFixedValue(col, frozenColumns);
      var lastColProps = {}; // This configuration allows more flexibility in resizing of other columns.
      if (index >= columns.length - 1) {
        lastColProps.width = undefined;
        lastColProps.onCell = function () {
          return {
            style: {
              minWidth: col.width
            }
          };
        };
      }
      var modifiedColumn = _objectSpread$2(_objectSpread$2(_objectSpread$2({}, col), lastColProps), {}, {
        onHeaderCell: function onHeaderCell(column) {
          return {
            width: col.width,
            onColumnUpdate: onColumnUpdate,
            onResize: isEnabled ? handleResize(index) : neetoCist.noop,
            onResizeStop: function onResizeStop() {
              return isEnabled ? onColumnUpdateWithChanges(columns) : neetoCist.noop;
            },
            isSortable: neetoCist.isPresent(col.sorter),
            onSort: handleSort,
            sortedInfo: sortedInfo,
            onColumnHide: onColumnHide,
            onColumnFreeze: onColumnFreeze,
            onMoreActionClick: onMoreActionClick,
            isMoveToLeftEnabled: index > 0,
            isMoveToRightEnabled: index < columns.length - 1,
            isColumnFreezeEnabled: isColumnFreezeEnabled,
            isAddEnabled: isAddEnabled && !fixed,
            onAddColumn: function onAddColumn(positionOffset) {
              return onColumnAdd(index + positionOffset);
            },
            isFixedColumn: !!fixed,
            onColumnDelete: onColumnDelete,
            isHidable: col.isHidable,
            isDeletable: col.isDeletable,
            moreActions: col.moreActions,
            column: col,
            "data-text-align": column.align
          };
        },
        sortIcon: SortIcon,
        sortOrder: getColumnSortOrder(col, sortedInfo),
        fixed: fixed,
        title: col.description ? function (props) {
          return /*#__PURE__*/jsxRuntime.jsx(TitleWithInfoIcon, _objectSpread$2(_objectSpread$2({}, props), {}, {
            description: col.description,
            title: col.title
          }));
        } : col.title
      });
      if (!ramda.has("ellipsis", col)) modifiedColumn.ellipsis = true;
      return modifiedColumn;
    }).sort(sortFrozenColumns(columnData));
  }, [columns, sortedInfo, tableOnChangeProps, onColumnFreeze, frozenColumns, columnData]);
  return {
    columns: computedColumnsData
  };
};

function ownKeys$1(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$1(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$1(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var useColumns = function useColumns(_ref) {
  var columns = _ref.columns,
    columnData = _ref.columnData,
    setColumns = _ref.setColumns,
    isResizeEnabled = _ref.isResizeEnabled,
    isReorderEnabled = _ref.isReorderEnabled,
    isAddEnabled = _ref.isAddEnabled,
    isColumnFreezeEnabled = _ref.isColumnFreezeEnabled,
    onColumnAdd = _ref.onColumnAdd,
    onColumnUpdate = _ref.onColumnUpdate,
    onColumnUpdateWithChanges = _ref.onColumnUpdateWithChanges,
    onColumnDelete = _ref.onColumnDelete,
    rowSelection = _ref.rowSelection,
    sortedInfo = _ref.sortedInfo,
    setSortedInfo = _ref.setSortedInfo,
    onColumnHide = _ref.onColumnHide,
    onMoreActionClick = _ref.onMoreActionClick,
    onTableChange = _ref.onTableChange,
    tableOnChangeProps = _ref.tableOnChangeProps,
    handleTableSortChange = _ref.handleTableSortChange,
    isDefaultPageChangeHandler = _ref.isDefaultPageChangeHandler,
    localStorageKeyPrefix = _ref.localStorageKeyPrefix;
  var _useLocalStorage = useLocalStorage(getFrozenColumnsLocalStorageKey(localStorageKeyPrefix)),
    _useLocalStorage2 = _slicedToArray__default.default(_useLocalStorage, 2),
    frozenColumns = _useLocalStorage2[0],
    setFrozenColumns = _useLocalStorage2[1];
  var onColumnFreeze = React.useCallback(function (isFixedColumn, _ref2) {
    var dataIndex = _ref2.dataIndex;
    var updatedColumns = isFixedColumn ? ramda.without([dataIndex], frozenColumns) : ramda.append(dataIndex, frozenColumns);
    setFrozenColumns(updatedColumns);
  }, [frozenColumns, setFrozenColumns]);
  React.useEffect(function () {
    if (ramda.isEmpty(columnData) || frozenColumns) return;
    var fixedCols = getFixedColumns(columnData);
    setFrozenColumns(fixedCols);
  }, [columnData, setFrozenColumns]);
  var _useReorderColumns = useReorderColumns({
      isEnabled: isReorderEnabled,
      columns: columns,
      setColumns: setColumns,
      onColumnUpdateWithChanges: onColumnUpdateWithChanges,
      rowSelection: rowSelection
    }),
    dragProps = _useReorderColumns.dragProps;
  var handleSort = function handleSort(sorter) {
    var _tableOnChangeProps$c, _tableOnChangeProps$c2, _tableOnChangeProps$c3;
    var newSortedInfo = _objectSpread$1({}, sorter);
    if (ramda.equals(ramda.props(["field", "order"], newSortedInfo), ramda.props(["field", "order"], sortedInfo))) {
      newSortedInfo = {
        field: null,
        order: null,
        column: null,
        columnKey: null
      };
    }
    setSortedInfo(newSortedInfo);
    onTableChange === null || onTableChange === void 0 ? void 0 : onTableChange(((_tableOnChangeProps$c = tableOnChangeProps.current) === null || _tableOnChangeProps$c === void 0 ? void 0 : _tableOnChangeProps$c.pagination) || {}, ((_tableOnChangeProps$c2 = tableOnChangeProps.current) === null || _tableOnChangeProps$c2 === void 0 ? void 0 : _tableOnChangeProps$c2.filters) || {}, _objectSpread$1({}, newSortedInfo));
    isDefaultPageChangeHandler && handleTableSortChange(((_tableOnChangeProps$c3 = tableOnChangeProps.current) === null || _tableOnChangeProps$c3 === void 0 ? void 0 : _tableOnChangeProps$c3.pagination) || {}, newSortedInfo);
  };
  var _useResizableColumns = useResizableColumns({
      columns: columns,
      columnData: columnData,
      frozenColumns: frozenColumns,
      setColumns: setColumns,
      isEnabled: isResizeEnabled,
      isAddEnabled: isAddEnabled,
      isColumnFreezeEnabled: isColumnFreezeEnabled,
      onColumnAdd: onColumnAdd,
      onColumnUpdate: onColumnUpdate,
      onColumnUpdateWithChanges: onColumnUpdateWithChanges,
      onColumnDelete: onColumnDelete,
      handleSort: handleSort,
      sortedInfo: sortedInfo,
      onColumnHide: onColumnHide,
      onMoreActionClick: onMoreActionClick,
      tableOnChangeProps: tableOnChangeProps,
      onColumnFreeze: onColumnFreeze
    }),
    computedColumnsData = _useResizableColumns.columns;
  return {
    dragProps: dragProps,
    columns: computedColumnsData
  };
};

var useScroll = function useScroll(_ref) {
  var fixedHeight = _ref.fixedHeight,
    enableColumnReorder = _ref.enableColumnReorder,
    loading = _ref.loading,
    otherProps = _ref.otherProps,
    rowData = _ref.rowData,
    pageSize = _ref.pageSize,
    shouldShowSelectAllRowsCallout = _ref.shouldShowSelectAllRowsCallout,
    shouldShowAllRowsSelectedCallout = _ref.shouldShowAllRowsSelectedCallout,
    headerHeight = _ref.headerHeight;
  var _useState = React.useState(0),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    containerHeight = _useState2[0],
    setContainerHeight = _useState2[1];
  var resizeObserver = React.useRef(new ResizeObserver(function (_ref2) {
    var _ref3 = _slicedToArray__default.default(_ref2, 1),
      entry = _ref3[0];
    return setContainerHeight(entry.contentRect.height);
  }));
  var scrollRef = React.useRef(null);
  var tableRef = React.useCallback(function (table) {
    scrollRef.current = table;
    if (!fixedHeight) return;
    var observer = resizeObserver.current;
    if (table !== null) {
      var _table$parentNode;
      var targetNode = enableColumnReorder ? table === null || table === void 0 ? void 0 : (_table$parentNode = table.parentNode) === null || _table$parentNode === void 0 ? void 0 : _table$parentNode.parentNode : table === null || table === void 0 ? void 0 : table.parentNode;
      observer.observe(targetNode);
    } else if (observer) {
      observer.disconnect();
    }
  }, [resizeObserver.current, fixedHeight, enableColumnReorder]);
  var _useRestoreScrollPosi = DatePicker.useRestoreScrollPosition({
      tableRef: tableRef,
      scrollRef: scrollRef,
      loading: loading
    }),
    handleScroll = _useRestoreScrollPosi.handleScroll;
  var calculateTableContainerHeight = function calculateTableContainerHeight() {
    var isPaginationVisible = otherProps.pagination !== false && rowData.length > pageSize;
    var selectAllRowsCalloutHeight = 0;
    if (shouldShowSelectAllRowsCallout || shouldShowAllRowsSelectedCallout) {
      selectAllRowsCalloutHeight = getSelectAllRowsCalloutHeight();
    }
    return containerHeight - headerHeight - (isPaginationVisible ? DatePicker.TABLE_PAGINATION_HEIGHT : 0) - selectAllRowsCalloutHeight;
  };
  return {
    tableRef: tableRef,
    tableContainerRef: null,
    handleScroll: handleScroll,
    calculatedScroll: {
      x: "max-content",
      y: calculateTableContainerHeight()
    }
  };
};

var useTableSort = function useTableSort() {
  var queryParams = useQueryParams.useQueryParams();
  var _useState = React.useState(function () {
      return getSortInfoFromQueryParams(queryParams);
    }),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    sortedInfo = _useState2[0],
    setSortedInfo = _useState2[1];
  React.useEffect(function () {
    setSortedInfo(getSortInfoFromQueryParams(queryParams));
  }, [queryParams === null || queryParams === void 0 ? void 0 : queryParams.sort_by, queryParams === null || queryParams === void 0 ? void 0 : queryParams.order_by]);
  var history = reactRouterDom.useHistory();
  var handleTableChange = function handleTableChange(pagination, sorter) {
    var params = {
      sort_by: sorter.order ? getSortField(sorter.field) : undefined,
      order_by: DatePicker.URL_SORT_ORDERS[sorter.order],
      page: pagination.current
    };
    var pathname = window.location.pathname;
    history.push(index.buildUrl(pathname, ramda.mergeLeft(params, queryParams)));
  };
  return {
    handleTableChange: handleTableChange,
    sortedInfo: sortedInfo,
    setSortedInfo: setSortedInfo
  };
};

var useVirtualScroll = function useVirtualScroll(_ref) {
  var otherProps = _ref.otherProps,
    rowData = _ref.rowData,
    pageSize = _ref.pageSize,
    shouldShowSelectAllRowsCallout = _ref.shouldShowSelectAllRowsCallout,
    shouldShowAllRowsSelectedCallout = _ref.shouldShowAllRowsSelectedCallout,
    headerHeight = _ref.headerHeight;
  var _useState = React.useState({
      top: 0,
      left: 0
    }),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    containerRect = _useState2[0],
    setContainerRect = _useState2[1];
  var tableContainerRef = React.useRef(null);
  React.useEffect(function () {
    var updateContainerRect = function updateContainerRect() {
      if (!tableContainerRef.current) return;
      var rect = tableContainerRef.current.getBoundingClientRect();
      setContainerRect(rect);
    };
    updateContainerRect();
    window.addEventListener("scroll", updateContainerRect);
    window.addEventListener("resize", updateContainerRect);
    return function () {
      window.removeEventListener("scroll", updateContainerRect);
      window.removeEventListener("resize", updateContainerRect);
    };
  }, []);
  var calculateTableContainerHeight = function calculateTableContainerHeight() {
    var isPaginationVisible = otherProps.pagination !== false && rowData.length > pageSize;
    var selectAllRowsCalloutHeight = 0;
    if (shouldShowSelectAllRowsCallout || shouldShowAllRowsSelectedCallout) {
      selectAllRowsCalloutHeight = getSelectAllRowsCalloutHeight();
    }
    var containerHeight = window.innerHeight - containerRect.top;
    return containerHeight - headerHeight - (isPaginationVisible ? DatePicker.TABLE_PAGINATION_HEIGHT : 0) - selectAllRowsCalloutHeight;
  };
  return {
    tableRef: null,
    tableContainerRef: tableContainerRef,
    handleScroll: neetoCist.noop,
    calculatedScroll: {
      x: window.innerWidth - (containerRect === null || containerRect === void 0 ? void 0 : containerRect.left),
      y: calculateTableContainerHeight()
    }
  };
};

var _excluded = ["allowRowClick", "enableColumnResize", "enableColumnReorder", "enableColumnFreeze", "enableAddColumn", "className", "columnData", "currentPageNumber", "defaultPageSize", "handlePageChange", "loading", "onRowClick", "onRowSelect", "rowData", "totalCount", "selectedRowKeys", "fixedHeight", "paginationProps", "rowKey", "scroll", "rowSelection", "shouldDynamicallyRenderRowSize", "bordered", "onColumnUpdate", "components", "onColumnHide", "onColumnAdd", "onColumnDelete", "onChange", "onMoreActionClick", "bulkSelectAllRowsProps", "localStorageKeyPrefix", "virtual"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var Table = function Table(_ref) {
  var _ref$allowRowClick = _ref.allowRowClick,
    allowRowClick = _ref$allowRowClick === void 0 ? true : _ref$allowRowClick,
    _ref$enableColumnResi = _ref.enableColumnResize,
    enableColumnResize = _ref$enableColumnResi === void 0 ? true : _ref$enableColumnResi,
    _ref$enableColumnReor = _ref.enableColumnReorder,
    enableColumnReorder = _ref$enableColumnReor === void 0 ? false : _ref$enableColumnReor,
    _ref$enableColumnFree = _ref.enableColumnFreeze,
    enableColumnFreeze = _ref$enableColumnFree === void 0 ? true : _ref$enableColumnFree,
    _ref$enableAddColumn = _ref.enableAddColumn,
    enableAddColumn = _ref$enableAddColumn === void 0 ? false : _ref$enableAddColumn,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$columnData = _ref.columnData,
    columnData = _ref$columnData === void 0 ? [] : _ref$columnData,
    _ref$currentPageNumbe = _ref.currentPageNumber,
    currentPageNumber = _ref$currentPageNumbe === void 0 ? 1 : _ref$currentPageNumbe,
    _ref$defaultPageSize = _ref.defaultPageSize,
    defaultPageSize = _ref$defaultPageSize === void 0 ? 30 : _ref$defaultPageSize,
    _ref$handlePageChange = _ref.handlePageChange,
    handlePageChange = _ref$handlePageChange === void 0 ? index.noop : _ref$handlePageChange,
    _ref$loading = _ref.loading,
    loading = _ref$loading === void 0 ? false : _ref$loading,
    onRowClick = _ref.onRowClick,
    onRowSelect = _ref.onRowSelect,
    _ref$rowData = _ref.rowData,
    rowData = _ref$rowData === void 0 ? [] : _ref$rowData,
    _ref$totalCount = _ref.totalCount,
    totalCount = _ref$totalCount === void 0 ? 0 : _ref$totalCount,
    _ref$selectedRowKeys = _ref.selectedRowKeys,
    initialSelectedRowKeys = _ref$selectedRowKeys === void 0 ? [] : _ref$selectedRowKeys,
    _ref$fixedHeight = _ref.fixedHeight,
    fixedHeight = _ref$fixedHeight === void 0 ? false : _ref$fixedHeight,
    _ref$paginationProps = _ref.paginationProps,
    paginationProps = _ref$paginationProps === void 0 ? {} : _ref$paginationProps,
    _ref$rowKey = _ref.rowKey,
    rowKey = _ref$rowKey === void 0 ? "id" : _ref$rowKey,
    scroll = _ref.scroll,
    rowSelection = _ref.rowSelection,
    _ref$shouldDynamicall = _ref.shouldDynamicallyRenderRowSize,
    shouldDynamicallyRenderRowSize = _ref$shouldDynamicall === void 0 ? false : _ref$shouldDynamicall,
    _ref$bordered = _ref.bordered,
    bordered = _ref$bordered === void 0 ? true : _ref$bordered,
    onColumnUpdate = _ref.onColumnUpdate,
    _ref$components = _ref.components,
    components = _ref$components === void 0 ? {} : _ref$components,
    onColumnHide = _ref.onColumnHide,
    _ref$onColumnAdd = _ref.onColumnAdd,
    onColumnAdd = _ref$onColumnAdd === void 0 ? index.noop : _ref$onColumnAdd,
    onColumnDelete = _ref.onColumnDelete,
    onChange = _ref.onChange,
    onMoreActionClick = _ref.onMoreActionClick,
    bulkSelectAllRowsProps = _ref.bulkSelectAllRowsProps,
    localStorageKeyPrefix = _ref.localStorageKeyPrefix,
    _ref$virtual = _ref.virtual,
    virtual = _ref$virtual === void 0 ? false : _ref$virtual,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded);
  var _useTranslation = reactI18next.useTranslation(),
    i18n = _useTranslation.i18n;
  var _useState = React.useState(DatePicker.TABLE_DEFAULT_HEADER_HEIGHT),
    _useState2 = _slicedToArray__default.default(_useState, 2),
    headerHeight = _useState2[0],
    setHeaderHeight = _useState2[1];
  var _useState3 = React.useState(columnData),
    _useState4 = _slicedToArray__default.default(_useState3, 2),
    columns = _useState4[0],
    setColumns = _useState4[1];
  var _useState5 = React.useState(false),
    _useState6 = _slicedToArray__default.default(_useState5, 2),
    bulkSelectedAllRows = _useState6[0],
    setBulkSelectedAllRows = _useState6[1];
  var _useState7 = React.useState({}),
    _useState8 = _slicedToArray__default.default(_useState7, 2),
    columnChanges = _useState8[0],
    setColumnChanges = _useState8[1];
  var _useTableSort = useTableSort(),
    handleTableSortChange = _useTableSort.handleTableChange,
    sortedInfo = _useTableSort.sortedInfo,
    setSortedInfo = _useTableSort.setSortedInfo;
  var _ref2 = bulkSelectAllRowsProps !== null && bulkSelectAllRowsProps !== void 0 ? bulkSelectAllRowsProps : {},
    handleSetBulkSelectedAllRows = _ref2.setBulkSelectedAllRows;
  var isDefaultPageChangeHandler = handlePageChange === index.noop;
  var history = reactRouterDom.useHistory();
  var headerRef = React.useRef();
  var tableOnChangeProps = React.useRef({});
  useTimeout(function () {
    var headerHeight = headerRef.current ? headerRef.current.offsetHeight : DatePicker.TABLE_DEFAULT_HEADER_HEIGHT;
    setHeaderHeight(headerHeight);
  }, 10);
  var onColumnUpdateWithChanges = function onColumnUpdateWithChanges(updatedColumns) {
    var newChanges = {};
    updatedColumns.forEach(function (col) {
      var originalCol = columnData.find(function (c) {
        return c.dataIndex === col.dataIndex;
      });
      var changes = {};
      if (col.width && col.width !== (originalCol === null || originalCol === void 0 ? void 0 : originalCol.width)) {
        changes.width = col.width;
      }
      if (Object.keys(changes).length > 0) {
        newChanges[col.dataIndex] = changes;
      }
    });
    setColumnChanges(function (prev) {
      return _objectSpread(_objectSpread({}, prev), newChanges);
    });
    onColumnUpdate === null || onColumnUpdate === void 0 ? void 0 : onColumnUpdate(updatedColumns);
  };
  var _useColumns = useColumns({
      isReorderEnabled: enableColumnReorder,
      isResizeEnabled: enableColumnResize,
      isAddEnabled: enableAddColumn,
      isColumnFreezeEnabled: enableColumnFreeze,
      onTableChange: onChange,
      columns: columns,
      columnData: columnData,
      setColumns: setColumns,
      onColumnUpdate: onColumnUpdate,
      onColumnUpdateWithChanges: onColumnUpdateWithChanges,
      rowSelection: rowSelection,
      sortedInfo: sortedInfo,
      setSortedInfo: setSortedInfo,
      onColumnHide: onColumnHide,
      onMoreActionClick: onMoreActionClick,
      onColumnAdd: onColumnAdd,
      onColumnDelete: onColumnDelete,
      tableOnChangeProps: tableOnChangeProps,
      handleTableSortChange: handleTableSortChange,
      isDefaultPageChangeHandler: isDefaultPageChangeHandler,
      localStorageKeyPrefix: localStorageKeyPrefix
    }),
    dragProps = _useColumns.dragProps,
    curatedColumnsData = _useColumns.columns;
  var queryParams = useQueryParams.useQueryParams();
  var setSortFromURL = function setSortFromURL(columnData) {
    var _queryParams$sort_by;
    return neetoCist.modifyBy({
      dataIndex: neetoCist.snakeToCamelCase((_queryParams$sort_by = queryParams.sort_by) !== null && _queryParams$sort_by !== void 0 ? _queryParams$sort_by : "")
    }, ramda.assoc("sortOrder", DatePicker.TABLE_SORT_ORDERS[queryParams.order_by]), columnData);
  };
  var sortedColumns = isDefaultPageChangeHandler ? setSortFromURL(curatedColumnsData) : curatedColumnsData;
  var locale = {
    emptyText: /*#__PURE__*/jsxRuntime.jsx(Typography, {
      style: "body2",
      children: "No Data"
    })
  };
  var selectedRowKeys = bulkSelectedAllRows ? ramda.pluck(rowKey, rowData) : initialSelectedRowKeys;
  var showBulkSelectionCallout = React.useMemo(function () {
    return isIncludedIn(selectedRowKeys, ramda.pluck(rowKey, rowData)) && selectedRowKeys.length !== totalCount && !bulkSelectedAllRows;
  }, [selectedRowKeys, rowKey, rowData, totalCount, bulkSelectedAllRows]);
  var shouldShowSelectAllRowsCallout = bulkSelectAllRowsProps && showBulkSelectionCallout;
  var shouldShowAllRowsSelectedCallout = bulkSelectAllRowsProps && bulkSelectedAllRows;
  var pageSize = shouldDynamicallyRenderRowSize ? calculateRowsPerPage() : paginationProps.pageSize || defaultPageSize;
  var _ref3 = (virtual ? useVirtualScroll : useScroll)({
      fixedHeight: fixedHeight,
      enableColumnReorder: enableColumnReorder,
      loading: loading,
      otherProps: otherProps,
      rowData: rowData,
      pageSize: pageSize,
      shouldShowSelectAllRowsCallout: shouldShowSelectAllRowsCallout,
      shouldShowAllRowsSelectedCallout: shouldShowAllRowsSelectedCallout,
      headerHeight: headerHeight
    }),
    tableRef = _ref3.tableRef,
    tableContainerRef = _ref3.tableContainerRef,
    handleScroll = _ref3.handleScroll,
    calculatedScroll = _ref3.calculatedScroll;
  var handleRowChange = function handleRowChange(selectedRowKeys, selectedRows) {
    var tableWrapper = document.querySelector('[data-testid="table-wrapper"]');
    if (selectedRowKeys.length !== defaultPageSize) {
      setBulkSelectedAllRows(false);
      handleSetBulkSelectedAllRows === null || handleSetBulkSelectedAllRows === void 0 ? void 0 : handleSetBulkSelectedAllRows(false);
      tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.remove("neeto-ui-overflow-hidden");
    } else {
      tableWrapper === null || tableWrapper === void 0 ? void 0 : tableWrapper.classList.add("neeto-ui-overflow-hidden");
    }
    onRowSelect === null || onRowSelect === void 0 ? void 0 : onRowSelect(selectedRowKeys, selectedRows);
  };
  var rowSelectionProps = rowSelection ? _objectSpread(_objectSpread({
    type: "checkbox",
    preserveSelectedRowKeys: true,
    columnWidth: 48
  }, rowSelection), {}, {
    onChange: handleRowChange,
    selectedRowKeys: selectedRowKeys
  }) : false;

  // eslint-disable-next-line @bigbinary/neeto/no-excess-function-arguments
  var handleTableChange = function handleTableChange(pagination, filters, sorter, extras) {
    setSortedInfo(sorter);
    isDefaultPageChangeHandler && handleTableSortChange(pagination, sorter);
    onChange === null || onChange === void 0 ? void 0 : onChange(pagination, filters, sorter, extras);
    tableOnChangeProps.current = {
      pagination: pagination,
      filters: filters
    };
  };
  var handleRow = function handleRow(record, rowIndex) {
    var rowKeyValue = record[rowKey];
    var isSelected = rowSelection && Array.isArray(selectedRowKeys) ? selectedRowKeys.includes(rowKeyValue) : false;
    return _objectSpread({
      onClick: function onClick(event) {
        return allowRowClick && onRowClick && onRowClick(event, record, rowIndex);
      }
    }, rowSelection && {
      "aria-selected": isSelected
    });
  };
  var componentOverrides = _objectSpread(_objectSpread({}, components), {}, {
    header: getHeaderCell({
      enableColumnResize: enableColumnResize,
      enableColumnReorder: enableColumnReorder
    })
  });
  var calculatePageSizeOptions = function calculatePageSizeOptions() {
    return neetoCist.dynamicArray(5, function (index) {
      return (index + 1) * pageSize;
    });
  };
  var itemRender = function itemRender(_, type, originalElement) {
    var commonProps = {
      size: "small",
      style: "text"
    };
    if (type === "prev") return /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread({
      icon: Left__default.default
    }, commonProps));
    if (type === "next") return /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread({
      icon: Right__default.default
    }, commonProps));
    if (type === "jump-prev" || type === "jump-next") {
      return /*#__PURE__*/jsxRuntime.jsx(Button, _objectSpread({
        icon: MenuHorizontal__default.default
      }, commonProps));
    }
    return originalElement;
  };
  React.useEffect(function () {
    if (neetoCist.isNotEmpty(initialSelectedRowKeys)) return;
    setBulkSelectedAllRows(false);
    handleSetBulkSelectedAllRows === null || handleSetBulkSelectedAllRows === void 0 ? void 0 : handleSetBulkSelectedAllRows(false);
  }, [handleSetBulkSelectedAllRows, initialSelectedRowKeys]);
  React.useEffect(function () {
    var shouldNavigateToLastPage = ramda.isEmpty(rowData) && !loading && currentPageNumber !== 1;
    if (!shouldNavigateToLastPage) return;
    var lastPage = Math.ceil(totalCount / pageSize);
    var page = Math.max(1, lastPage);
    var pathname = window.location.pathname;
    isDefaultPageChangeHandler ? history.push(index.buildUrl(pathname, ramda.mergeLeft({
      page: page
    }, queryParams))) : handlePageChange(page, pageSize);
  }, [rowData]);
  React.useEffect(function () {
    var mergedColumns = columnData.map(function (col) {
      return _objectSpread(_objectSpread({}, col), columnChanges[col.dataIndex]);
    });
    setColumns(mergedColumns);
  }, [columnData, columnChanges]);
  var neetoUIFontBold = parseInt(getComputedStyle(document.documentElement).getPropertyValue("--neeto-ui-font-bold"), 10);
  var renderTable = function renderTable() {
    return /*#__PURE__*/jsxRuntime.jsxs(_ConfigProvider__default.default, {
      direction: index.getContentDir(),
      locale: constants.ANTD_LOCALE[i18n.language || "en"],
      theme: {
        token: _objectSpread({}, index.ANT_DESIGN_GLOBAL_TOKEN_OVERRIDES),
        components: {
          Pagination: {
            itemActiveBg: "rgb(var(--neeto-ui-primary-500))",
            itemActiveBgDisabled: "rgb(var(--neeto-ui-gray-50))",
            itemActiveColorDisabled: "rgb(var(--neeto-ui-gray-300))",
            itemBg: "rgb(var(--neeto-ui-white))",
            itemInputBg: "rgb(var(--neeto-ui-white))",
            itemLinkBg: "rgb(var(--neeto-ui-white))",
            // Global overrides
            colorBgContainer: "rgb(var(--neeto-ui-primary-500))",
            colorPrimary: "rgb(var(--neeto-ui-white))",
            colorPrimaryHover: "rgb(var(--neeto-ui-white))",
            colorBgTextHover: "rgb(var(--neeto-ui-gray-200))",
            borderRadius: 6
          },
          Table: {
            headerBorderRadius: 0,
            bodySortBg: "rgb(var(--neeto-ui-gray-50))",
            borderColor: "rgb(var(--neeto-ui-gray-200))",
            expandIconBg: "rgb(var(--neeto-ui-white))",
            filterDropdownBg: "rgb(var(--neeto-ui-white))",
            filterDropdownMenuBg: "rgb(var(--neeto-ui-white))",
            fixedHeaderSortActiveBg: "rgb(var(--neeto-ui-gray-200))",
            footerBg: "rgb(var(--neeto-ui-gray-100))",
            footerColor: "rgb(var(--neeto-ui-black))",
            headerBg: "rgb(var(--neeto-ui-gray-100))",
            headerColor: "rgb(var(--neeto-ui-black))",
            headerFilterHoverBg: "rgb(var(--neeto-ui-gray-100))",
            headerSortActiveBg: "rgb(var(--neeto-ui-gray-200))",
            headerSortHoverBg: "rgb(var(--neeto-ui-gray-200))",
            headerSplitColor: "rgb(var(--neeto-ui-gray-100))",
            rowExpandedBg: "rgb(var(--neeto-ui-gray-100))",
            rowHoverBg: "rgb(var(--neeto-ui-gray-50))",
            rowSelectedBg: "rgb(var(--neeto-ui-accent-50))",
            rowSelectedHoverBg: "rgb(var(--neeto-ui-accent-50))",
            stickyScrollBarBg: "rgb(var(--neeto-ui-gray-300))",
            cellPaddingBlock: 11,
            // Global overrides
            colorPrimary: "rgb(var(--neeto-ui-primary-500))",
            fontSize: 14,
            fontWeightStrong: neetoUIFontBold,
            paddingContentVerticalLG: 11
          }
        }
      },
      children: [shouldShowSelectAllRowsCallout && /*#__PURE__*/jsxRuntime.jsx(SelectAllRowsCallout, _objectSpread(_objectSpread({}, bulkSelectAllRowsProps), {}, {
        onBulkSelectAllRows: function onBulkSelectAllRows() {
          setBulkSelectedAllRows(true);
          handleSetBulkSelectedAllRows === null || handleSetBulkSelectedAllRows === void 0 ? void 0 : handleSetBulkSelectedAllRows(true);
        }
      })), shouldShowAllRowsSelectedCallout && /*#__PURE__*/jsxRuntime.jsx(AllRowsSelectedCallout, _objectSpread(_objectSpread({}, bulkSelectAllRowsProps), {}, {
        onClearSelection: function onClearSelection() {
          setBulkSelectedAllRows(false);
          handleSetBulkSelectedAllRows === null || handleSetBulkSelectedAllRows === void 0 ? void 0 : handleSetBulkSelectedAllRows(false);
          handleRowChange([], []);
        }
      })), /*#__PURE__*/jsxRuntime.jsx(_Table__default.default, _objectSpread({
        bordered: bordered,
        locale: locale,
        rowKey: rowKey,
        virtual: virtual,
        columns: sortedColumns,
        components: componentOverrides,
        dataSource: rowData,
        loading: {
          spinning: loading,
          indicator: /*#__PURE__*/jsxRuntime.jsx(Spinner, {})
        },
        ref: tableRef,
        rowSelection: rowSelectionProps,
        scroll: _objectSpread(_objectSpread({}, calculatedScroll), scroll),
        showSorterTooltip: false,
        pagination: _objectSpread(_objectSpread({
          hideOnSinglePage: true
        }, paginationProps), {}, {
          showSizeChanger: false,
          total: totalCount !== null && totalCount !== void 0 ? totalCount : 0,
          current: currentPageNumber,
          defaultPageSize: pageSize,
          pageSizeOptions: calculatePageSizeOptions(),
          onChange: handlePageChange,
          itemRender: itemRender
        }),
        rowClassName: classnames__default.default("neeto-ui-table--row", {
          "neeto-ui-table--row_hover": allowRowClick
        }, [className]),
        onChange: handleTableChange,
        onRow: handleRow,
        onScroll: handleScroll,
        onHeaderRow: function onHeaderRow() {
          return {
            ref: headerRef,
            className: classnames__default.default("neeto-ui-table__header", {
              "neeto-ui-table-reorderable": enableColumnReorder
            }),
            id: "neeto-ui-table__header"
          };
        }
      }, otherProps)), /*#__PURE__*/jsxRuntime.jsx(DatePicker.TableInfoPane, {
        onColumnUpdate: onColumnUpdate
      })]
    });
  };
  var renderTableVirtual = function renderTableVirtual() {
    return virtual ? /*#__PURE__*/jsxRuntime.jsx("div", {
      ref: tableContainerRef,
      children: renderTable()
    }) : renderTable();
  };
  return enableColumnReorder ? /*#__PURE__*/jsxRuntime.jsx(ReactDragListView__default.default.DragColumn, _objectSpread(_objectSpread({}, dragProps), {}, {
    children: renderTableVirtual()
  })) : renderTableVirtual();
};

module.exports = Table;
//# sourceMappingURL=Table.js.map
