'use strict';

var React = require('react');
var classnames = require('classnames');
var neetoCist = require('@bigbinary/neeto-cist');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var ramda = require('ramda');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var neetoAtoms = require('@bigbinary/neeto-atoms');
var reactI18next = require('react-i18next');
var Columns$1 = require('../Columns-CKKEXExE.js');
require('@babel/runtime/helpers/toConsumableArray');
require('@tanstack/react-query');
require('@bigbinary/neeto-commons-frontend/react-utils/useMutationWithInvalidation');
require('axios');
var jsxRuntime = require('react/jsx-runtime');
var createLucideIcon = require('../createLucideIcon-DBDhE7kE.js');
var reactUtils = require('@bigbinary/neeto-commons-frontend/react-utils');
var v2 = require('@bigbinary/neeto-filters-frontend/v2');
require('@babel/runtime/helpers/slicedToArray');
require('@bigbinary/neeto-atoms/primitives');
require('@dnd-kit/core');
require('@dnd-kit/sortable');
require('i18next');
require('../utilities.esm-jwIHISzF.js');
require('../search-BBuFYdmG.js');

/**
 * @license lucide-react v1.7.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */


const __iconNode$2 = [
  ["rect", { width: "18", height: "18", x: "3", y: "3", rx: "2", key: "afitv7" }],
  ["path", { d: "M9 3v18", key: "fh3hqa" }],
  ["path", { d: "M15 3v18", key: "14nvp0" }]
];
const Columns3 = createLucideIcon.createLucideIcon("columns-3", __iconNode$2);

/**
 * @license lucide-react v1.7.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */


const __iconNode$1 = [
  ["path", { d: "M12 15V3", key: "m9g1x1" }],
  ["path", { d: "M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4", key: "ih7n3h" }],
  ["path", { d: "m7 10 5 5 5-5", key: "brsn70" }]
];
const Download = createLucideIcon.createLucideIcon("download", __iconNode$1);

/**
 * @license lucide-react v1.7.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */


const __iconNode = [
  [
    "path",
    {
      d: "M10 20a1 1 0 0 0 .553.895l2 1A1 1 0 0 0 14 21v-7a2 2 0 0 1 .517-1.341L21.74 4.67A1 1 0 0 0 21 3H3a1 1 0 0 0-.742 1.67l7.225 7.989A2 2 0 0 1 10 14z",
      key: "sc7q7i"
    }
  ]
];
const Funnel = createLucideIcon.createLucideIcon("funnel", __iconNode);

var _excluded$2 = ["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 Columns = function Columns(_ref) {
  var _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$2);
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var tooltipContent = t("neetoMolecules.columns.columns");
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    children: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Tooltip, {
      content: tooltipContent,
      position: "bottom",
      children: /*#__PURE__*/jsxRuntime.jsx("div", {
        className: "inline-flex",
        children: /*#__PURE__*/jsxRuntime.jsx(Columns$1.Columns, _objectSpread$3({
          isSearchable: true,
          buttonProps: _objectSpread$3({
            icon: Columns3,
            "data-testid": "columns-dropdown-button"
          }, buttonProps)
        }, _objectSpread$3({
          allowConfigurationResetOnUpdate: allowConfigurationResetOnUpdate,
          columnData: columnData,
          onMutationSuccess: onMutationSuccess,
          tableKey: tableKey
        }, props)))
      })
    })
  });
};
Columns.displayName = "Columns";

var _excluded$1 = ["content"];
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 = function DownloadButton(_ref) {
  var count = _ref.count,
    onClick = _ref.onClick,
    _ref$dataTestid = _ref["data-testid"],
    dataTestid = _ref$dataTestid === void 0 ? "download-button" : _ref$dataTestid,
    _ref$tooltipProps = _ref.tooltipProps,
    tooltipProps = _ref$tooltipProps === void 0 ? {} : _ref$tooltipProps;
  var _useTranslation = reactI18next.useTranslation(),
    t = _useTranslation.t;
  var tooltipContent = tooltipProps.content,
    restTooltipProps = _objectWithoutProperties(tooltipProps, _excluded$1);
  var resolvedTooltipContent = tooltipContent !== null && tooltipContent !== void 0 ? tooltipContent : t("neetoMolecules.common.download");
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    className: "relative",
    children: [/*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Tooltip, _objectSpread$2(_objectSpread$2({
      content: resolvedTooltipContent,
      position: "bottom"
    }, restTooltipProps), {}, {
      children: /*#__PURE__*/jsxRuntime.jsx(neetoAtoms.Button, {
        onClick: onClick,
        "data-testid": neetoCist.isPresent(dataTestid) ? dataTestid : "download-button",
        icon: Download,
        size: "icon",
        variant: "ghost"
      })
    })), count && /*#__PURE__*/jsxRuntime.jsx("span", {
      className: "bg-primary text-primary-foreground absolute -end-0.5 -top-0.5 z-[1] inline-flex min-h-4 min-w-4 items-center justify-center rounded-full text-[0.625rem]",
      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 = reactUtils.withT(function (_ref) {
  var t = _ref.t,
    buttonProps = _ref.buttonProps,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/jsxRuntime.jsx("div", {
    children: /*#__PURE__*/jsxRuntime.jsx(v2.Filters, _objectSpread$1({
      buttonProps: _objectSpread$1({
        "data-testid": "filter-button",
        icon: Funnel,
        variant: "ghost",
        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 = neetoCist.isNotPresent(dataProps === null || dataProps === void 0 ? void 0 : dataProps.totalCount) ? true : (dataProps === null || dataProps === void 0 ? void 0 : dataProps.totalCount) > 0;
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    "data-testid": "subheader-rightblock-buttons-container",
    className: classnames("flex flex-row items-center justify-end gap-2", "[&>:not([hidden])~:not([hidden])]:border-border [&>:not([hidden])~:not([hidden])]:border-s [&>:not([hidden])~:not([hidden])]:ps-2", {
      hidden: ramda.not(showIcons)
    }),
    children: [downloadButtonProps && /*#__PURE__*/jsxRuntime.jsx(DownloadButton, _objectSpread({}, downloadButtonProps)), columnsButtonProps && /*#__PURE__*/jsxRuntime.jsx(Columns, _objectSpread({}, columnsButtonProps)), filterProps && /*#__PURE__*/jsxRuntime.jsx(FilterButton, _objectSpread({}, filterProps))]
  });
};

var SubHeader = function SubHeader(_ref) {
  var _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    leftActionBlock = _ref.leftActionBlock,
    rightActionBlock = _ref.rightActionBlock,
    _ref$dataTestid = _ref["data-testid"],
    dataTestid = _ref$dataTestid === void 0 ? "subheader" : _ref$dataTestid;
  var subheaderRef = React.useRef(null);
  React.useLayoutEffect(function () {
    var updateHeaderHeight = function updateHeaderHeight() {
      if (!subheaderRef.current) return;
      var height = subheaderRef.current.offsetHeight;
      document.body.style.setProperty("--nv-subheader-height", "".concat(height, "px"));
    };
    updateHeaderHeight();
    window.addEventListener("resize", updateHeaderHeight);
    return function () {
      window.removeEventListener("resize", updateHeaderHeight);
      document.body.style.removeProperty("--nv-subheader-height");
    };
  }, []);
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
    "data-testid": neetoCist.isPresent(dataTestid) ? dataTestid : "subheader",
    ref: subheaderRef,
    className: classnames("mb-5 flex w-full shrink-0 flex-row flex-wrap items-center justify-between gap-4 md:flex-nowrap", className),
    children: [/*#__PURE__*/jsxRuntime.jsx("div", {
      className: "flex grow",
      "data-testid": "subheader-left-wrapper",
      children: leftActionBlock && /*#__PURE__*/jsxRuntime.jsx("div", {
        className: "flex flex-row items-center justify-start",
        "data-testid": "subheader-left",
        children: leftActionBlock
      })
    }), rightActionBlock && /*#__PURE__*/jsxRuntime.jsx("div", {
      className: "ms-auto flex flex-row items-center justify-end gap-3 md:ms-0",
      "data-testid": "subheader-right",
      children: rightActionBlock
    })]
  });
};
SubHeader.RightBlock = RightBlock;

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