"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _flex = _interopRequireDefault(require("../../templates/flex"));
var _search = _interopRequireDefault(require("../../search"));
var _icon = require("../../icon");
var _typography = require("../../typography");
var _groupBy = _interopRequireDefault(require("./groupBy"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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); }
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 = (0, _react.useMemo)(function () {
    return typeof tableMeta === "function" ? tableMeta({}, {}, null) : tableMeta;
  }, []);
  if (!title && !groupByColumns && !hasSearch && !bulkActions && !enableColumnVisibility) return null;
  return /*#__PURE__*/_react["default"].createElement(_flex["default"], _extends({
    "data-noprint": true,
    width: "100%",
    zIndex: 10,
    background: "mainBackground",
    gap: 1,
    alignItems: "center",
    padding: [1]
  }, tableMeta.bulkActionsStyles), typeof title === "string" ? /*#__PURE__*/_react["default"].createElement(_typography.TextBig, {
    strong: true
  }, title) : title, hasSearch && /*#__PURE__*/_react["default"].createElement(_flex["default"], _extends({
    flex: "grow"
  }, tableMeta.searchContainerStyles), /*#__PURE__*/_react["default"].createElement(_search["default"], _extends({
    "data-testid": "table-global-search-filter",
    "data-ga": dataGa + "::search-words::table-filter",
    value: q,
    iconLeft: /*#__PURE__*/_react["default"].createElement(_icon.Icon, {
      color: "textLite",
      name: "magnify",
      height: "18px",
      width: "18px"
    }),
    onChange: onSearch,
    placeholder: searchPlaceholder,
    controlled: enableCustomSearch
  }, tableMeta.searchStyles))), /*#__PURE__*/_react["default"].createElement(_groupBy["default"], {
    groupByColumns: groupByColumns,
    tableMeta: tableMeta,
    dataColumns: dataColumns,
    grouping: grouping,
    onGroupBy: onGroupBy,
    dataGa: dataGa
  }), children);
};
var _default = exports["default"] = /*#__PURE__*/(0, _react.memo)(Header);