import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _excluded = ["className", "children", "forwardedRef", "hovered", "sliceFrom", "sliceTo", "onClick", "onSelectionChange", "selected", "selectable"];

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

import React, { forwardRef, PureComponent } from 'react';
import PropTypes from 'prop-types';
import Cell from './Cell';
import Checkbox from '../checkbox';
import Row from './Row';
import cx from 'classnames';
import theme from './theme.css';

var BodyRow = /*#__PURE__*/function (_PureComponent) {
  _inherits(BodyRow, _PureComponent);

  var _super = _createSuper(BodyRow);

  function BodyRow() {
    var _this;

    _classCallCheck(this, BodyRow);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "handleClick", function (event) {
      var onClick = _this.props.onClick;
      onClick && onClick(event);
    });

    return _this;
  }

  _createClass(BodyRow, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          className = _this$props.className,
          children = _this$props.children,
          forwardedRef = _this$props.forwardedRef,
          hovered = _this$props.hovered,
          sliceFrom = _this$props.sliceFrom,
          sliceTo = _this$props.sliceTo,
          onClick = _this$props.onClick,
          onSelectionChange = _this$props.onSelectionChange,
          selected = _this$props.selected,
          selectable = _this$props.selectable,
          others = _objectWithoutProperties(_this$props, _excluded);

      var childrenArray = Array.isArray(children) ? children : [children];
      var childrenSliced = childrenArray.slice(sliceFrom, sliceTo);
      var classNames = cx(theme['body-row'], _defineProperty({}, theme['has-pointer-cursor'], onClick), className);
      return /*#__PURE__*/React.createElement(Row, _extends({
        backgroundColor: hovered ? 'neutral' : 'white',
        className: classNames,
        "data-teamleader-ui": "datagrid-body-row",
        onClick: this.handleClick,
        ref: forwardedRef
      }, others), selectable && /*#__PURE__*/React.createElement(Cell, {
        flex: "checkbox-width",
        onClick: function onClick(event) {
          return event.stopPropagation();
        },
        preventOverflow: false
      }, /*#__PURE__*/React.createElement(Checkbox, {
        checked: selected,
        onChange: onSelectionChange,
        size: "small"
      })), childrenSliced);
    }
  }]);

  return BodyRow;
}(PureComponent);

/** @type {any} */
var ForwardedBodyRow = /*#__PURE__*/forwardRef(function (props, ref) {
  return /*#__PURE__*/React.createElement(BodyRow, _extends({}, props, {
    forwardedRef: ref
  }));
});
ForwardedBodyRow.displayName = 'BodyRow';
export default ForwardedBodyRow;