import { useRef, useLayoutEffect } from 'react';
import classnames from 'classnames';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { isNotPresent } from '@bigbinary/neeto-cist';
import { omit, not } from 'ramda';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
import Column from '@bigbinary/neeto-icons/Column';
import { C as Columns$1 } from './Columns-Bs-Y6jgW.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@tanstack/react-query';
import '@bigbinary/neeto-commons-frontend/react-utils/useMutationWithInvalidation';
import 'axios';
import { jsx, jsxs } from 'react/jsx-runtime';
import Download from '@bigbinary/neeto-icons/Download';
import Button from '@bigbinary/neetoui/Button';
import NeetoFilters from '@bigbinary/neeto-filters-frontend/Filters';
import Filter from '@bigbinary/neeto-icons/Filter';
import { n } from './inject-css-C2dztUxs.js';
import '@babel/runtime/helpers/slicedToArray';
import '@dnd-kit/core';
import '@dnd-kit/sortable';
import 'i18next';
import '@bigbinary/neeto-icons/Search';
import '@bigbinary/neetoui/Checkbox';
import '@bigbinary/neetoui/Dropdown';
import '@bigbinary/neetoui/Input';
import '@bigbinary/neetoui/Label';
import 'react-i18next';
import '@bigbinary/neeto-icons/Reorder';

var _excluded$1 = ["t", "buttonProps", "columnData", "onMutationSuccess", "allowConfigurationResetOnUpdate", "tableKey"];
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 unUsedI18nProps = ["tReady", "i18n"];
var Columns = withT(function (_ref) {
  var t = _ref.t,
    _ref$buttonProps = _ref.buttonProps,
    buttonProps = _ref$buttonProps === void 0 ? {} : _ref$buttonProps,
    columnData = _ref.columnData,
    onMutationSuccess = _ref.onMutationSuccess,
    allowConfigurationResetOnUpdate = _ref.allowConfigurationResetOnUpdate,
    tableKey = _ref.tableKey,
    props = _objectWithoutProperties(_ref, _excluded$1);
  return /*#__PURE__*/jsx("div", {
    className: "neeto-molecules-subheader__columns",
    children: /*#__PURE__*/jsx(Columns$1, _objectSpread$3({
      isSearchable: true,
      className: "neeto-ui-dropdown--manage-columns",
      buttonProps: _objectSpread$3({
        icon: Column,
        label: null,
        tooltipProps: {
          content: t("neetoMolecules.columns.columns"),
          position: "bottom",
          touch: ["hold", 500]
        },
        "data-testid": "columns-button",
        "data-cy": "columns-dropdown-button"
      }, buttonProps)
    }, _objectSpread$3({
      allowConfigurationResetOnUpdate: allowConfigurationResetOnUpdate,
      columnData: columnData,
      onMutationSuccess: onMutationSuccess,
      tableKey: tableKey
    }, omit(unUsedI18nProps, props))))
  });
});
Columns.displayName = "Columns";

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 DownloadButton = withT(function (_ref) {
  var t = _ref.t,
    count = _ref.count,
    onClick = _ref.onClick,
    _ref$dataCy = _ref["data-cy"],
    dataCy = _ref$dataCy === void 0 ? "download-button" : _ref$dataCy,
    tooltipProps = _ref.tooltipProps;
  return /*#__PURE__*/jsxs("div", {
    className: "neeto-molecules-subheader__download",
    children: [/*#__PURE__*/jsx(Button, {
      onClick: onClick,
      "data-cy": dataCy,
      "data-testid": "download-button",
      icon: Download,
      style: "text",
      tooltipProps: _objectSpread$2({
        content: t("neetoMolecules.common.download"),
        position: "bottom",
        touch: ["hold", 500]
      }, tooltipProps)
    }), count && /*#__PURE__*/jsx("span", {
      className: "neeto-molecules-subheader__download-count",
      children: count
    })]
  });
});

var _excluded = ["t", "buttonProps"];
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 FilterButton = withT(function (_ref) {
  var t = _ref.t,
    buttonProps = _ref.buttonProps,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/jsx("div", {
    className: "neeto-molecules-subheader__filter",
    children: /*#__PURE__*/jsx(NeetoFilters, _objectSpread$1({
      buttonProps: _objectSpread$1({
        "data-testid": "filter-button",
        icon: Filter,
        style: "text",
        tooltipProps: {
          content: t("neetoMolecules.common.filter"),
          position: "bottom",
          touch: ["hold", 500]
        },
        label: null
      }, buttonProps)
    }, props))
  });
});

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 RightBlock = function RightBlock(_ref) {
  var downloadButtonProps = _ref.downloadButtonProps,
    columnsButtonProps = _ref.columnsButtonProps,
    filterProps = _ref.filterProps,
    dataProps = _ref.dataProps;
  var showIcons = isNotPresent(dataProps === null || dataProps === void 0 ? void 0 : dataProps.totalCount) ? true : (dataProps === null || dataProps === void 0 ? void 0 : dataProps.totalCount) > 0;
  return /*#__PURE__*/jsxs("div", {
    "data-testid": "subheader-rightblock-buttons-container",
    className: classnames("neeto-molecules-subheader__right-actions", {
      hidden: not(showIcons)
    }),
    children: [downloadButtonProps && /*#__PURE__*/jsx(DownloadButton, _objectSpread({}, downloadButtonProps)), columnsButtonProps && /*#__PURE__*/jsx(Columns, _objectSpread({}, columnsButtonProps)), filterProps && /*#__PURE__*/jsx(FilterButton, _objectSpread({}, filterProps))]
  });
};

var css = ":root{--neeto-molecules-sub-header-height:2.3125rem;--neeto-molecules-sub-header-bottom-margin:1.25rem;--neeto-molecules-effective-subheader-height:0px}.neeto-molecules-subheader{align-items:center;background-color:rgb(var(--neeto-ui-white));display:flex;flex-direction:row;flex-shrink:0;gap:1rem;justify-content:space-between;margin-bottom:1.25rem;margin-bottom:var(--neeto-molecules-sub-header-bottom-margin);width:100%}@media screen and (max-width:768px){.neeto-molecules-subheader{flex-wrap:wrap}}.neeto-molecules-subheader .neeto-molecules-subheader__left-wrapper{display:flex;flex-grow:1}.neeto-molecules-subheader .neeto-molecules-subheader__left-wrapper .neeto-molecules-subheader__left{align-items:center;display:flex;flex-direction:row;justify-content:flex-start}.neeto-molecules-subheader .neeto-molecules-subheader__left-wrapper .neeto-molecules-subheader__left .neeto-molecules-input__prefix{color:rgb(var(--neeto-ui-gray-400))}@media screen and (max-width:360px){.neeto-molecules-subheader .neeto-molecules-subheader__left-wrapper .neeto-molecules-subheader__left h4{font-size:.875rem}}.neeto-molecules-subheader .neeto-molecules-subheader__left-wrapper .neeto-ui-btn{flex-shrink:0}.neeto-molecules-subheader .neeto-molecules-subheader__right{align-items:center;display:flex;flex-direction:row;gap:.75rem;justify-content:flex-end}@media screen and (max-width:768px){.neeto-molecules-subheader .neeto-molecules-subheader__right{margin-left:auto}}.neeto-molecules-subheader .neeto-molecules-subheader__right-actions{align-items:center;display:flex;flex-direction:row;gap:.5rem;justify-content:flex-end}.neeto-molecules-subheader .neeto-molecules-subheader__right-actions>:not([hidden])~:not([hidden]){border-left:thin solid rgb(var(--neeto-ui-gray-200));padding-left:.5rem}.neeto-molecules-subheader__download{position:relative}.neeto-molecules-subheader__download-count{align-items:center;background-color:rgb(var(--neeto-ui-accent-500));border-radius:var(--neeto-ui-rounded-full);color:rgb(var(--neeto-ui-white));display:inline-flex;font-size:.625rem;justify-content:center;min-height:1rem;min-width:1rem;position:absolute;right:-2px;text-align:center;top:-2px;z-index:1}.neeto-molecules-subheader__columns .neeto-ui-dropdown__popup{max-height:calc(100vh - var(--neeto-molecules-effective-header-height) - 3.5625rem);max-height:calc(100vh - var(--neeto-molecules-effective-header-height) - var(--neeto-molecules-sub-header-height) - var(--neeto-molecules-sub-header-bottom-margin));min-width:20rem}";
n(css,{});

var SubHeader = function SubHeader(_ref) {
  var _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    leftActionBlock = _ref.leftActionBlock,
    rightActionBlock = _ref.rightActionBlock,
    _ref$dataCy = _ref["data-cy"],
    dataCy = _ref$dataCy === void 0 ? "subheader" : _ref$dataCy;
  var subheaderRef = useRef(null);
  useLayoutEffect(function () {
    var updateHeaderHeight = function updateHeaderHeight() {
      if (!subheaderRef.current) return;
      var height = subheaderRef.current.offsetHeight;
      document.body.style.setProperty("--neeto-molecules-effective-subheader-height", "".concat(height, "px"));
    };
    updateHeaderHeight();
    window.addEventListener("resize", updateHeaderHeight);
    return function () {
      return window.removeEventListener("resize", updateHeaderHeight);
    };
  }, []);
  return /*#__PURE__*/jsxs("div", {
    className: classnames(["neeto-molecules-subheader", className]),
    "data-cy": dataCy,
    "data-testid": "subheader",
    ref: subheaderRef,
    children: [/*#__PURE__*/jsx("div", {
      className: "neeto-molecules-subheader__left-wrapper",
      "data-cy": "subheader-left-wrapper",
      children: leftActionBlock && /*#__PURE__*/jsx("div", {
        className: "neeto-molecules-subheader__left",
        "data-cy": "subheader-left",
        children: leftActionBlock
      })
    }), rightActionBlock && /*#__PURE__*/jsx("div", {
      className: "neeto-molecules-subheader__right",
      "data-cy": "subheader-right",
      children: rightActionBlock
    })]
  });
};
SubHeader.RightBlock = RightBlock;

export { SubHeader as default };
//# sourceMappingURL=SubHeader.js.map
