import { useState, useRef, useLayoutEffect } from 'react';
import classnames from 'classnames';
import { isPresent, isNotPresent } from '@bigbinary/neeto-cist';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { not } from 'ramda';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import { TooltipProvider, Tooltip, TooltipTrigger, TooltipContent } from '@bigbinary/neeto-atoms/primitives';
import { useTranslation } from 'react-i18next';
import { a as Columns$1 } from '../Columns-gR00LMKF.js';
import '@babel/runtime/helpers/toConsumableArray';
import '@tanstack/react-query';
import '@bigbinary/neeto-commons-frontend/v2/react-utils/useMutationWithInvalidation';
import 'axios';
import { jsx, jsxs } from 'react/jsx-runtime';
import { c as createLucideIcon } from '../createLucideIcon-mNMhCCpf.js';
import { Tooltip as Tooltip$1, Button } from '@bigbinary/neeto-atoms';
import { withT } from '@bigbinary/neeto-commons-frontend/v2/react-utils';
import NeetoFilters from '@bigbinary/neeto-filters-frontend/v2/Filters';
import '@dnd-kit/core';
import '@dnd-kit/modifiers';
import '@dnd-kit/sortable';
import 'i18next';
import '../utilities.esm-CS21Daln.js';
import '../search-DCgpNjip.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("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("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("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 = useTranslation(),
    t = _useTranslation.t;
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    isOpen = _useState2[0],
    setIsOpen = _useState2[1];
  var _useState3 = useState(false),
    _useState4 = _slicedToArray(_useState3, 2),
    isTooltipOpen = _useState4[0],
    setIsTooltipOpen = _useState4[1];
  return /*#__PURE__*/jsx(TooltipProvider, {
    children: /*#__PURE__*/jsxs(Tooltip, {
      open: isOpen ? false : isTooltipOpen,
      onOpenChange: setIsTooltipOpen,
      children: [/*#__PURE__*/jsx(TooltipTrigger, {
        asChild: true,
        children: /*#__PURE__*/jsx("span", {
          className: "inline-flex",
          children: /*#__PURE__*/jsx(Columns$1, _objectSpread$3({
            isSearchable: true,
            buttonProps: _objectSpread$3({
              icon: Columns3,
              "data-testid": "columns-dropdown-button"
            }, buttonProps),
            onOpenChange: setIsOpen
          }, _objectSpread$3({
            allowConfigurationResetOnUpdate: allowConfigurationResetOnUpdate,
            columnData: columnData,
            onMutationSuccess: onMutationSuccess,
            tableKey: tableKey
          }, props)))
        })
      }), /*#__PURE__*/jsx(TooltipContent, {
        side: "bottom",
        children: t("neetoMolecules.columns.columns")
      })]
    })
  });
};
Columns.displayName = "Columns";

var _excluded$1 = ["content", "position"];
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 = useTranslation(),
    t = _useTranslation.t;
  var content = tooltipProps.content,
    position = tooltipProps.position,
    restTooltipProps = _objectWithoutProperties(tooltipProps, _excluded$1);
  return /*#__PURE__*/jsxs("div", {
    className: "relative",
    children: [/*#__PURE__*/jsx(Tooltip$1, _objectSpread$2(_objectSpread$2({
      content: content !== null && content !== void 0 ? content : t("neetoMolecules.common.download"),
      position: position !== null && position !== void 0 ? position : "bottom"
    }, restTooltipProps), {}, {
      children: /*#__PURE__*/jsx(Button, {
        onClick: onClick,
        "data-testid": isPresent(dataTestid) ? dataTestid : "download-button",
        icon: Download,
        size: "icon",
        variant: "ghost"
      })
    })), count && /*#__PURE__*/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 = withT(function (_ref) {
  var t = _ref.t,
    buttonProps = _ref.buttonProps,
    props = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/jsx(NeetoFilters, _objectSpread$1({
    buttonProps: _objectSpread$1({
      "data-testid": "filter-button",
      icon: Funnel,
      variant: "ghost",
      tooltipProps: {
        content: t("neetoMolecules.common.filter"),
        position: "bottom"
      },
      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("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: not(showIcons)
    }),
    children: [downloadButtonProps && /*#__PURE__*/jsx(DownloadButton, _objectSpread({}, downloadButtonProps)), columnsButtonProps && /*#__PURE__*/jsx(Columns, _objectSpread({}, columnsButtonProps)), filterProps && /*#__PURE__*/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 = useRef(null);
  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__*/jsxs("div", {
    "data-testid": 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__*/jsx("div", {
      className: "flex grow",
      "data-testid": "subheader-left-wrapper",
      children: leftActionBlock && /*#__PURE__*/jsx("div", {
        className: "flex flex-row items-center justify-start",
        "data-testid": "subheader-left",
        children: leftActionBlock
      })
    }), rightActionBlock && /*#__PURE__*/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;

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