function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
import React, { memo, useMemo } from "react";
import Flex from "../../templates/flex";
import SearchInput from "../../search";
import { Icon } from "../../icon";
import { TextBig } from "../../typography";
import GroupBy from "./groupBy";
var Header = function Header(_ref) {
  var q = _ref.q,
    hasSearch = _ref.hasSearch,
    onSearch = _ref.onSearch,
    groupByColumns = _ref.groupByColumns,
    grouping = _ref.grouping,
    onGroupBy = _ref.onGroupBy,
    tableMeta = _ref.tableMeta,
    title = _ref.title,
    dataGa = _ref.dataGa,
    _ref$searchPlaceholde = _ref.searchPlaceholder,
    searchPlaceholder = _ref$searchPlaceholde === void 0 ? "Search" : _ref$searchPlaceholde,
    dataColumns = _ref.dataColumns,
    children = _ref.children,
    bulkActions = _ref.bulkActions,
    enableColumnVisibility = _ref.enableColumnVisibility,
    enableCustomSearch = _ref.enableCustomSearch;
  tableMeta = useMemo(function () {
    return typeof tableMeta === "function" ? tableMeta({}, {}, null) : tableMeta;
  }, []);
  if (!title && !groupByColumns && !hasSearch && !bulkActions && !enableColumnVisibility) return null;
  return /*#__PURE__*/React.createElement(Flex, _extends({
    width: "100%",
    zIndex: 10,
    background: "mainBackground",
    gap: 1,
    alignItems: "center",
    padding: [1]
  }, tableMeta.bulkActionsStyles), typeof title === "string" ? /*#__PURE__*/React.createElement(TextBig, {
    strong: true
  }, title) : title, hasSearch && /*#__PURE__*/React.createElement(Flex, _extends({
    flex: "grow"
  }, tableMeta.searchContainerStyles), /*#__PURE__*/React.createElement(SearchInput, _extends({
    "data-testid": "table-global-search-filter",
    "data-ga": dataGa + "::search-words::table-filter",
    value: q,
    iconLeft: /*#__PURE__*/React.createElement(Icon, {
      color: "textLite",
      name: "magnify",
      height: "18px",
      width: "18px"
    }),
    onChange: onSearch,
    placeholder: searchPlaceholder,
    controlled: enableCustomSearch
  }, tableMeta.searchStyles))), /*#__PURE__*/React.createElement(GroupBy, {
    groupByColumns: groupByColumns,
    tableMeta: tableMeta,
    dataColumns: dataColumns,
    grouping: grouping,
    onGroupBy: onGroupBy,
    dataGa: dataGa
  }), children);
};
export default /*#__PURE__*/memo(Header);