"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _checkbox = require("../../checkbox");
var _flex = _interopRequireDefault(require("../../templates/flex"));
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; }
var width = 32;
var _default = exports["default"] = function _default(enabled, _ref) {
  var testPrefix = _ref.testPrefix,
    tableMeta = _ref.tableMeta;
  return (0, _react.useMemo)(function () {
    return enabled ? {
      id: "checkbox",
      enableHiding: false,
      enableResizing: false,
      header: function header(_ref2) {
        var table = _ref2.table;
        return /*#__PURE__*/_react["default"].createElement(_flex["default"], {
          width: 4
        }, /*#__PURE__*/_react["default"].createElement(_checkbox.Checkbox, {
          "data-testid": "netdata-table-header-checkbox" + testPrefix,
          checked: table.getIsAllRowsSelected(),
          indeterminate: table.getIsSomeRowsSelected(),
          onChange: function onChange(checked) {
            table.getToggleAllRowsSelectedHandler()({
              target: {
                checked: checked
              }
            });
          }
        }));
      },
      cell: function cell(_ref3) {
        var _row$original, _row$original2, _row$original3;
        var row = _ref3.row;
        return ((_row$original = row.original) == null ? void 0 : _row$original.disabled) !== "hidden" && /*#__PURE__*/_react["default"].createElement(_checkbox.Checkbox, {
          "data-testid": "netdata-table-cell-checkbox" + testPrefix,
          checked: !((_row$original2 = row.original) != null && _row$original2.disabled) && row.getIsSelected(),
          indeterminate: row.getIsSomeSelected(),
          onChange: function onChange(checked, e) {
            e == null || e.stopPropagation == null || e.stopPropagation();
            row.getToggleSelectedHandler()({
              target: {
                checked: checked
              }
            });
          },
          disabled: ((_row$original3 = row.original) == null ? void 0 : _row$original3.disabled) || false
        });
      },
      enableColumnFilter: false,
      enableSorting: false,
      size: width,
      maxSize: width,
      minSize: width,
      notFlex: true,
      tableMeta: tableMeta
    } : null;
  }, [enabled]);
};