'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var core = require('@dnd-kit/core');
var sortable = require('@dnd-kit/sortable');
var i18next = require('i18next');
var neetoCist = require('@bigbinary/neeto-cist');
var Search = require('@bigbinary/neeto-icons/Search');
var Checkbox = require('@bigbinary/neetoui/Checkbox');
var Dropdown = require('@bigbinary/neetoui/Dropdown');
var Input = require('@bigbinary/neetoui/Input');
var Label = require('@bigbinary/neetoui/Label');
var Button = require('@bigbinary/neetoui/Button');
var ramda = require('ramda');
var reactI18next = require('react-i18next');
var injectCss = require('./inject-css-B6qYtOJe.js');
var classnames = require('classnames');
var Reorder = require('@bigbinary/neeto-icons/Reorder');
var jsxRuntime = require('react/jsx-runtime');
var reactQuery = require('@tanstack/react-query');
var useMutationWithInvalidation = require('@bigbinary/neeto-commons-frontend/react-utils/useMutationWithInvalidation');
var axios = require('axios');

var css = ":root{--neeto-molecules-columns-menu-max-width:31.25rem}.neeto-molecules-columns__container{max-width:31.25rem;max-width:var(--neeto-molecules-columns-menu-max-width)}.neeto-molecules-columns__sortable-item .neeto-ui-cursor-grab{cursor:grab}.neeto-molecules-columns__sortable-item .neeto-ui-cursor-grab:active{cursor:grabbing}.neeto-molecules-columns__sortable-item:hover .neeto-ui-text-gray-400{color:#6b7280}.neeto-ui-dropdown--manage-columns .neeto-ui-dropdown__popup{max-height:calc(100dvh - 200px)!important}";
injectCss.n(css,{});

const CSS = /*#__PURE__*/Object.freeze({
  Translate: {
    toString(transform) {
      if (!transform) {
        return;
      }

      const {
        x,
        y
      } = transform;
      return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
    }

  },
  Scale: {
    toString(transform) {
      if (!transform) {
        return;
      }

      const {
        scaleX,
        scaleY
      } = transform;
      return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
    }

  },
  Transform: {
    toString(transform) {
      if (!transform) {
        return;
      }

      return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(' ');
    }

  },
  Transition: {
    toString(_ref) {
      let {
        property,
        duration,
        easing
      } = _ref;
      return property + " " + duration + "ms " + easing;
    }

  }
});

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(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 Item = function Item(_ref) {
  var _active$data, _over$data;
  var column = _ref.column,
    hiddenColumns = _ref.hiddenColumns,
    checkboxProps = _ref.checkboxProps,
    onToggle = _ref.onToggle,
    isTableConfigurationFetching = _ref.isTableConfigurationFetching;
  var key = column.key,
    title = column.title;
  var _useSortable = sortable.useSortable({
      id: key
    }),
    attributes = _useSortable.attributes,
    listeners = _useSortable.listeners,
    setNodeRef = _useSortable.setNodeRef,
    transform = _useSortable.transform,
    transition = _useSortable.transition,
    isDragging = _useSortable.isDragging,
    isOver = _useSortable.isOver,
    over = _useSortable.over,
    active = _useSortable.active;
  var dragStyle = {
    transform: isDragging ? CSS.Transform.toString(transform) : undefined,
    transition: transition,
    opacity: isDragging ? 0.5 : 1
  };
  var isIndicatorVisible = !isDragging && isOver;
  var draggedIndex = active === null || active === void 0 || (_active$data = active.data) === null || _active$data === void 0 || (_active$data = _active$data.current) === null || _active$data === void 0 || (_active$data = _active$data.sortable) === null || _active$data === void 0 ? void 0 : _active$data.index;
  var targetIndex = over === null || over === void 0 || (_over$data = over.data) === null || _over$data === void 0 || (_over$data = _over$data.current) === null || _over$data === void 0 || (_over$data = _over$data.sortable) === null || _over$data === void 0 ? void 0 : _over$data.index;
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    children: [/*#__PURE__*/jsxRuntime.jsx("div", {
      className: classnames({
        "neeto-ui-bg-gray-200 h-1 w-full": isIndicatorVisible && targetIndex < draggedIndex
      })
    }), /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "neeto-molecules-columns__sortable-item",
      "data-cy": "column-sortable-item",
      ref: setNodeRef,
      style: dragStyle,
      children: /*#__PURE__*/jsxRuntime.jsxs(Label, {
        className: "neeto-ui-flex neeto-ui-w-full hover:neeto-ui-bg-gray-200 neeto-ui-cursor-pointer neeto-ui-items-center px-4 py-2",
        htmlFor: key,
        children: [/*#__PURE__*/jsxRuntime.jsx("div", _objectSpread$3(_objectSpread$3(_objectSpread$3({}, attributes), listeners), {}, {
          className: "neeto-ui-mr-2 neeto-ui-cursor-grab neeto-ui-flex neeto-ui-items-center",
          "data-cy": "column-drag-handle",
          children: /*#__PURE__*/jsxRuntime.jsx(Reorder, {
            className: "neeto-ui-text-gray-800",
            size: 18
          })
        })), /*#__PURE__*/jsxRuntime.jsx(Checkbox, _objectSpread$3({
          checked: !hiddenColumns.includes(key),
          "data-cy": "neeto-ui-columns-checkbox",
          disabled: isTableConfigurationFetching,
          id: key,
          label: title,
          name: key,
          onChange: onToggle
        }, checkboxProps))]
      })
    }), /*#__PURE__*/jsxRuntime.jsx("div", {
      className: classnames({
        "neeto-ui-bg-gray-200 h-1 w-full": isIndicatorVisible && targetIndex > draggedIndex
      })
    })]
  });
};

var baseUrl = "api/v1/table_configurations";
var fetch = function fetch(tableKey) {
  return axios.get("".concat(baseUrl, "/").concat(tableKey));
};
var create = function create(payload) {
  return axios.post(baseUrl, {
    tableConfiguration: payload
  });
};
var update = function update(_ref) {
  var tableKey = _ref.tableKey,
    payload = _ref.payload;
  return axios.patch("".concat(baseUrl, "/").concat(tableKey), {
    tableConfiguration: payload
  });
};
var destroy = function destroy(tableKey) {
  return axios["delete"]("".concat(baseUrl, "/").concat(tableKey));
};
var tableConfigurationApi = {
  fetch: fetch,
  create: create,
  update: update,
  destroy: destroy
};

var HIDDEN_COLUMNS_STORAGE_KEY = "neeto-molecules-hidden-columns";
var COLUMNS_ORDER_STORAGE_KEY = "neeto-molecules-columns-order";
var TABLE_CONFIGURATION_QUERY_KEY = "table-configuration";

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(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 useFetchTableConfiguration = function useFetchTableConfiguration(_ref) {
  var tableKey = _ref.tableKey,
    _ref$options = _ref.options,
    options = _ref$options === void 0 ? {} : _ref$options;
  return reactQuery.useQuery(_objectSpread$2({
    queryKey: [TABLE_CONFIGURATION_QUERY_KEY, tableKey],
    enabled: !!tableKey,
    queryFn: function queryFn() {
      return tableConfigurationApi.fetch(tableKey);
    }
  }, options));
};
var useUpdateTableConfiguration = function useUpdateTableConfiguration(tableKey) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  return useMutationWithInvalidation(tableConfigurationApi.update, _objectSpread$2({
    keysToInvalidate: [[TABLE_CONFIGURATION_QUERY_KEY, tableKey]]
  }, options));
};
var useDestroyTableConfiguration = function useDestroyTableConfiguration(tableKey) {
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  return useMutationWithInvalidation(tableConfigurationApi.destroy, _objectSpread$2({
    keysToInvalidate: [[TABLE_CONFIGURATION_QUERY_KEY, tableKey]]
  }, options));
};

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(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 useTableConfigurations = function useTableConfigurations(tableKey, columnData) {
  var onMutationSuccess = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : neetoCist.noop;
  var allowConfigurationResetOnUpdate = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
  var defaultHiddenColumns = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
  var _useFetchTableConfigu = useFetchTableConfiguration({
      tableKey: tableKey
    }),
    tableConfiguration = _useFetchTableConfigu.data,
    isLoading = _useFetchTableConfigu.isLoading,
    isFetching = _useFetchTableConfigu.isFetching;
  var _useUpdateTableConfig = useUpdateTableConfiguration(tableKey, {
      onSuccess: onMutationSuccess
    }),
    updateConfiguration = _useUpdateTableConfig.mutate;
  var _useDestroyTableConfi = useDestroyTableConfiguration(tableKey, {
      onSuccess: onMutationSuccess
    }),
    destroyConfiguration = _useDestroyTableConfi.mutate;
  var processColumnsWithConfiguration = React.useCallback(function () {
    var originalColumns = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    var existingColumnConfiguration = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
    if (ramda.isEmpty(existingColumnConfiguration)) {
      return originalColumns;
    }
    var originalColumnsByKey = new Map(originalColumns === null || originalColumns === void 0 ? void 0 : originalColumns.filter(ramda.prop("key")).map(function (column) {
      return [column.key, column];
    }));
    var configurationByKey = new Map(existingColumnConfiguration.map(function (config) {
      return [config.key, config];
    }));
    var orderedConfiguredColumns = existingColumnConfiguration.map(function (config) {
      return originalColumnsByKey.get(config.key);
    }).filter(Boolean);
    var unconfiguredOriginalColumns = originalColumns.filter(function (column) {
      return column.key && !configurationByKey.has(column.key);
    });
    return [].concat(_toConsumableArray(orderedConfiguredColumns), _toConsumableArray(unconfiguredOriginalColumns));
  }, []);
  var hasAdditionalColumns = React.useMemo(function () {
    if (!(tableConfiguration !== null && tableConfiguration !== void 0 && tableConfiguration.columns) || !columnData) {
      return false;
    }
    var configurationKeys = ramda.pluck("key", tableConfiguration.columns).sort();
    var dataKeys = ramda.pluck("key", columnData).sort();
    return neetoCist.isNotEqualDeep(configurationKeys, dataKeys);
  }, [tableConfiguration, columnData]);
  var shouldApplyTableConfiguration = React.useMemo(function () {
    return !isLoading && (tableConfiguration === null || tableConfiguration === void 0 ? void 0 : tableConfiguration.columns) && neetoCist.isNotEmpty(tableConfiguration === null || tableConfiguration === void 0 ? void 0 : tableConfiguration.columns) && !hasAdditionalColumns;
  }, [tableConfiguration, isLoading, hasAdditionalColumns]);
  React.useEffect(function () {
    if (hasAdditionalColumns && tableConfiguration && allowConfigurationResetOnUpdate) {
      destroyConfiguration(tableKey);
    }
  }, [hasAdditionalColumns, tableKey, allowConfigurationResetOnUpdate]);
  var allProcessedColumns = React.useMemo(function () {
    if (!isLoading && neetoCist.isNotEmpty(tableConfiguration === null || tableConfiguration === void 0 ? void 0 : tableConfiguration.columns) && !hasAdditionalColumns) {
      return processColumnsWithConfiguration(columnData, tableConfiguration === null || tableConfiguration === void 0 ? void 0 : tableConfiguration.columns);
    }
    return columnData || [];
  }, [isLoading, tableConfiguration === null || tableConfiguration === void 0 ? void 0 : tableConfiguration.columns, hasAdditionalColumns, columnData, processColumnsWithConfiguration]);
  var existingColumnConfiguration = React.useMemo(function () {
    if (shouldApplyTableConfiguration) {
      return tableConfiguration.columns;
    }
    if (!columnData || ramda.isEmpty(columnData)) {
      return [];
    }
    return columnData.map(function (column) {
      return {
        key: column.key,
        isShown: !defaultHiddenColumns.includes(column.key)
      };
    });
  }, [shouldApplyTableConfiguration, columnData, tableConfiguration === null || tableConfiguration === void 0 ? void 0 : tableConfiguration.columns, defaultHiddenColumns]);
  var customizedColumns = React.useMemo(function () {
    var visibleColumnsConfig = existingColumnConfiguration.filter(ramda.prop("isShown"));
    var visibleColumnKeys = ramda.pluck("key", visibleColumnsConfig);
    return allProcessedColumns.filter(function (column) {
      return visibleColumnKeys.includes(column.key);
    });
  }, [allProcessedColumns, existingColumnConfiguration]);
  var updateColumns = function updateColumns(updatedColumns) {
    updateConfiguration({
      tableKey: tableKey,
      payload: {
        table_key: tableKey,
        columns: updatedColumns
      }
    });
  };
  var hideColumn = function hideColumn(columnKey) {
    updateColumns(existingColumnConfiguration.map(function (column) {
      return column.key === columnKey ? _objectSpread$1(_objectSpread$1({}, column), {}, {
        isShown: false
      }) : column;
    }));
  };
  var showColumn = function showColumn(columnKey) {
    updateColumns(existingColumnConfiguration.map(function (column) {
      return column.key === columnKey ? _objectSpread$1(_objectSpread$1({}, column), {}, {
        isShown: true
      }) : column;
    }));
  };
  return {
    customizedColumns: customizedColumns,
    // Only visible columns (for displaying the columns in the table)
    allProcessedColumns: allProcessedColumns,
    // All columns (for displaying the columns in the Subheader)
    isTableConfigurationLoading: isLoading,
    isTableConfigurationFetching: isFetching,
    existingColumnConfiguration: existingColumnConfiguration,
    hideColumn: hideColumn,
    showColumn: showColumn,
    updateColumns: updateColumns,
    destroyConfiguration: destroyConfiguration
  };
};

var getHidableColumns = function getHidableColumns(columnData) {
  return neetoCist.removeBy({
    isHidable: false
  }, columnData);
};
var filterBySearchTerm = function filterBySearchTerm(searchTerm, columns) {
  return ramda.filter(function (_ref) {
    var title = _ref.title;
    return ramda.includes(ramda.trim(ramda.toLower(searchTerm)), ramda.trim(ramda.toLower(title)));
  }, columns);
};

var _excluded = ["actionBlock", "checkboxProps", "columnData", "isSearchable", "tableKey", "noColumnMessage", "searchProps", "allowConfigurationResetOnUpdate", "onMutationSuccess", "defaultHiddenColumns"];
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(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 Columns = function Columns(_ref) {
  var actionBlock = _ref.actionBlock,
    _ref$checkboxProps = _ref.checkboxProps,
    checkboxProps = _ref$checkboxProps === void 0 ? {} : _ref$checkboxProps,
    _ref$columnData = _ref.columnData,
    columnData = _ref$columnData === void 0 ? [] : _ref$columnData,
    _ref$isSearchable = _ref.isSearchable,
    isSearchable = _ref$isSearchable === void 0 ? false : _ref$isSearchable,
    _ref$tableKey = _ref.tableKey,
    tableKey = _ref$tableKey === void 0 ? "" : _ref$tableKey,
    _ref$noColumnMessage = _ref.noColumnMessage,
    noColumnMessage = _ref$noColumnMessage === void 0 ? i18next.t("neetoMolecules.columns.noColumns") : _ref$noColumnMessage,
    _ref$searchProps = _ref.searchProps,
    searchProps = _ref$searchProps === void 0 ? {} : _ref$searchProps,
    _ref$allowConfigurati = _ref.allowConfigurationResetOnUpdate,
    allowConfigurationResetOnUpdate = _ref$allowConfigurati === void 0 ? true : _ref$allowConfigurati,
    _ref$onMutationSucces = _ref.onMutationSuccess,
    onMutationSuccess = _ref$onMutationSucces === void 0 ? neetoCist.noop : _ref$onMutationSucces,
    _ref$defaultHiddenCol = _ref.defaultHiddenColumns,
    defaultHiddenColumns = _ref$defaultHiddenCol === void 0 ? [] : _ref$defaultHiddenCol,
    dropdownProps = _objectWithoutProperties(_ref, _excluded);
  var Divider = Dropdown.Divider,
    Menu = Dropdown.Menu,
    MenuItem = Dropdown.MenuItem;
  var _useState = React.useState(""),
    _useState2 = _slicedToArray(_useState, 2),
    searchTerm = _useState2[0],
    setSearchTerm = _useState2[1];
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var _useTableConfiguratio = useTableConfigurations(tableKey, columnData, onMutationSuccess, allowConfigurationResetOnUpdate, defaultHiddenColumns),
    allProcessedColumns = _useTableConfiguratio.allProcessedColumns,
    existingColumnConfiguration = _useTableConfiguratio.existingColumnConfiguration,
    hideColumn = _useTableConfiguratio.hideColumn,
    showColumn = _useTableConfiguratio.showColumn,
    updateColumns = _useTableConfiguratio.updateColumns,
    destroyConfiguration = _useTableConfiguratio.destroyConfiguration,
    isTableConfigurationFetching = _useTableConfiguratio.isTableConfigurationFetching;
  var hiddenColumns = ramda.pluck("key", existingColumnConfiguration.filter(function (column) {
    return !column.isShown;
  }));
  var handleDragEnd = function handleDragEnd(event) {
    var active = event.active,
      over = event.over;
    if (!over || active.id === over.id) return;
    var oldIndex = neetoCist.findIndexBy({
      key: active.id
    }, existingColumnConfiguration);
    var newIndex = neetoCist.findIndexBy({
      key: over.id
    }, existingColumnConfiguration);
    if (oldIndex === -1 || newIndex === -1) return;
    var newOrder = _toConsumableArray(existingColumnConfiguration);
    var _newOrder$splice = newOrder.splice(oldIndex, 1),
      _newOrder$splice2 = _slicedToArray(_newOrder$splice, 1),
      movedItem = _newOrder$splice2[0];
    newOrder.splice(newIndex, 0, movedItem);
    updateColumns(newOrder);
  };
  var columns = getHidableColumns(allProcessedColumns);
  var filteredColumns = filterBySearchTerm(searchTerm, columns);
  var handleHideAllColumns = function handleHideAllColumns() {
    var columnsToHideKeys = ramda.pluck("key", columns);
    updateColumns(existingColumnConfiguration.map(function (column) {
      return ramda.includes(column.key, columnsToHideKeys) ? ramda.assoc("isShown", false, column) : column;
    }));
  };
  var handleChange = function handleChange(_ref2) {
    var _ref2$target = _ref2.target,
      dataIndex = _ref2$target.name,
      checked = _ref2$target.checked;
    if (checked) showColumn(dataIndex);else hideColumn(dataIndex);
  };
  var handleSearch = function handleSearch(_ref3) {
    var value = _ref3.target.value;
    return setSearchTerm(value);
  };
  return /*#__PURE__*/jsxRuntime.jsx(Dropdown, _objectSpread(_objectSpread({
    appendTo: document.body,
    buttonSize: "medium",
    buttonStyle: "text",
    closeOnSelect: false,
    position: "bottom-end",
    onClose: function onClose() {
      return setSearchTerm("");
    }
  }, dropdownProps), {}, {
    children: /*#__PURE__*/jsxRuntime.jsx(Menu, {
      children: /*#__PURE__*/jsxRuntime.jsxs("div", {
        className: "neeto-molecules-columns__container",
        "data-cy": "customize-columns-dropdown-container",
        children: [isSearchable && /*#__PURE__*/jsxRuntime.jsx(Input, _objectSpread({
          className: "px-4 py-2",
          "data-cy": "neeto-ui-columns-search",
          "data-testid": "neeto-ui-columns-search",
          placeholder: t("neetoMolecules.columns.search"),
          prefix: /*#__PURE__*/jsxRuntime.jsx(Search, {}),
          type: "search",
          value: searchTerm,
          onChange: handleSearch
        }, searchProps)), ramda.isEmpty(filteredColumns) && /*#__PURE__*/jsxRuntime.jsx("span", {
          className: "neeto-ui-flex neeto-ui-flex-col neeto-ui-items-center neeto-ui-p-2",
          children: noColumnMessage
        }), neetoCist.isNotEmpty(filteredColumns) && !searchTerm && /*#__PURE__*/jsxRuntime.jsx(core.DndContext, {
          collisionDetection: core.closestCenter,
          onDragEnd: handleDragEnd,
          children: /*#__PURE__*/jsxRuntime.jsx(sortable.SortableContext, {
            items: ramda.pluck("key", filteredColumns),
            strategy: sortable.verticalListSortingStrategy,
            children: filteredColumns.map(function (column) {
              return /*#__PURE__*/React.createElement(Item, {
                checkboxProps: checkboxProps,
                column: column,
                hiddenColumns: hiddenColumns,
                isTableConfigurationFetching: isTableConfigurationFetching,
                key: column.key,
                onToggle: handleChange
              });
            })
          })
        }), neetoCist.isNotEmpty(filteredColumns) && searchTerm && filteredColumns.map(function (_ref4) {
          var key = _ref4.key,
            title = _ref4.title;
          return /*#__PURE__*/jsxRuntime.jsx(MenuItem, {
            children: /*#__PURE__*/jsxRuntime.jsx(Label, {
              className: "neeto-ui-flex neeto-ui-w-full hover:neeto-ui-bg-gray-200 neeto-ui-cursor-pointer px-4 py-2",
              htmlFor: key,
              children: /*#__PURE__*/jsxRuntime.jsx(Checkbox, _objectSpread({
                checked: !hiddenColumns.includes(key),
                "data-cy": "neeto-ui-columns-checkbox",
                id: key,
                label: title,
                name: key,
                onChange: handleChange
              }, checkboxProps))
            })
          }, key);
        }), /*#__PURE__*/jsxRuntime.jsx(Divider, {}), !!actionBlock && /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
          children: [actionBlock, /*#__PURE__*/jsxRuntime.jsx(Divider, {})]
        }), /*#__PURE__*/jsxRuntime.jsxs("div", {
          className: "flex justify-end gap-2 p-1 pr-3",
          children: [/*#__PURE__*/jsxRuntime.jsx(Button, {
            "data-cy": "column-visibility-hide-all-button",
            label: t("neetoMolecules.columns.hideAll"),
            style: "tertiary",
            onClick: handleHideAllColumns
          }), /*#__PURE__*/jsxRuntime.jsx(Button, {
            "data-cy": "column-visibility-reset-button",
            label: t("neetoMolecules.columns.reset"),
            style: "secondary",
            onClick: function onClick() {
              return destroyConfiguration(tableKey);
            }
          })]
        })]
      })
    })
  }));
};
Columns.displayName = "Columns";

exports.COLUMNS_ORDER_STORAGE_KEY = COLUMNS_ORDER_STORAGE_KEY;
exports.Columns = Columns;
exports.HIDDEN_COLUMNS_STORAGE_KEY = HIDDEN_COLUMNS_STORAGE_KEY;
exports.TABLE_CONFIGURATION_QUERY_KEY = TABLE_CONFIGURATION_QUERY_KEY;
exports.useTableConfigurations = useTableConfigurations;
//# sourceMappingURL=Columns-DvL5p9SR.js.map
