import React, { useMemo } from "react";
import { Checkbox } from "../../checkbox";
import Flex from "../../templates/flex";
var width = 32;
export default (function (enabled, _ref) {
  var testPrefix = _ref.testPrefix,
    tableMeta = _ref.tableMeta;
  return useMemo(function () {
    return enabled ? {
      id: "checkbox",
      enableHiding: false,
      enableResizing: false,
      header: function header(_ref2) {
        var table = _ref2.table;
        return /*#__PURE__*/React.createElement(Flex, {
          width: 4
        }, /*#__PURE__*/React.createElement(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.createElement(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]);
});