"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 _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
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-testid": "netdata-table-header-container",
    "data-noprint": true,
    width: "100%",
    zIndex: 10,
    background: "panelBg",
    gap: 1,
    alignItems: "center",
    padding: [2, 3],
    round: {
      side: "top",
      size: 1
    },
    flexWrap: true
  }, 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);