function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

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 _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

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

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */

/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
// ### React
import React from 'react';
import PropTypes from 'prop-types'; // ### classNames

import classNames from 'classnames'; // ### find

import find from 'lodash.find'; // ## Children

import Checkbox from '../../checkbox';
import Radio from '../../radio'; // ## Constants

import { DATA_TABLE_ROW, DATA_TABLE_ROW_ACTIONS, DATA_TABLE_CELL } from '../../../utilities/constants';
/**
 * Used internally, provides row rendering to the DataTable.
 */

var DataTableRow = /*#__PURE__*/function (_React$Component) {
  _inherits(DataTableRow, _React$Component);

  var _super = _createSuper(DataTableRow);

  function DataTableRow() {
    var _this;

    _classCallCheck(this, DataTableRow);

    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), "isSelected", function () {
      return !!find(_this.props.selection, _this.props.item);
    });

    _defineProperty(_assertThisInitialized(_this), "handleToggle", function (e, _ref) {
      var checked = _ref.checked;
      return _this.props.onToggle(_this.props.item, checked, e);
    });

    return _this;
  }

  _createClass(DataTableRow, [{
    key: "render",
    // ### Render
    value: function render() {
      var _this2 = this;

      var ariaProps = {};
      var isSelected = this.isSelected();

      if (this.props.canSelectRows) {
        ariaProps['aria-selected'] = isSelected ? 'true' : 'false';
      } // i18n


      return /*#__PURE__*/React.createElement("tr", _extends({}, ariaProps, {
        className: classNames(this.props.className, {
          'slds-hint-parent': this.props.rowActions,
          'slds-is-selected': this.props.canSelectRows && isSelected
        })
      }), this.props.canSelectRows ? /*#__PURE__*/React.createElement("td", {
        role: this.props.fixedLayout ? 'gridcell' : null,
        className: "slds-text-align_right",
        "data-label": this.props.stacked ? 'Select Row' : undefined,
        style: {
          width: '3.25rem'
        }
      }, this.props.canSelectRows === 'radio' ? /*#__PURE__*/React.createElement(Radio, {
        assistiveText: {
          label: "".concat(this.props.assistiveText.selectRow, " ").concat(Number(this.props.index) + 1)
        },
        "aria-labelledby": "".concat(this.props.id, "-SelectRow-label ").concat(this.props.tableId, "-SLDSDataTableHead-column-group-header-row-select"),
        checked: isSelected,
        className: "slds-m-right_x-small",
        id: "".concat(this.props.id, "-SelectRow"),
        labelId: "".concat(this.props.id, "-SelectRow-label"),
        name: "".concat(this.props.tableId, "-SelectRow"),
        onChange: this.handleToggle
      }) : /*#__PURE__*/React.createElement(Checkbox, {
        assistiveText: {
          label: "".concat(this.props.assistiveText.selectRow, " ").concat(Number(this.props.index) + 1)
        },
        "aria-labelledby": "".concat(this.props.id, "-SelectRow-label ").concat(this.props.tableId, "-SLDSDataTableHead-column-group-header-row-select"),
        checked: isSelected,
        id: "".concat(this.props.id, "-SelectRow"),
        labelId: "".concat(this.props.id, "-SelectRow-label"),
        name: "SelectRow".concat(this.props.index + 1),
        onChange: this.handleToggle
      })) : null, this.props.columns.map(function (column) {
        var Cell = column.Cell;
        var cellId = "".concat(_this2.props.id, "-").concat(DATA_TABLE_CELL, "-").concat(column.props.property);
        return /*#__PURE__*/React.createElement(Cell, _extends({}, column.props, {
          className: column.props.truncate ? 'slds-truncate' : null,
          fixedLayout: _this2.props.fixedLayout,
          rowHeader: column.props.primaryColumn,
          id: cellId,
          item: _this2.props.item,
          key: cellId,
          width: column.props.width
        }), _this2.props.item[column.props.property]);
      }), this.props.rowActions ? /*#__PURE__*/React.cloneElement(this.props.rowActions, {
        id: "".concat(this.props.id, "-").concat(DATA_TABLE_ROW_ACTIONS),
        item: this.props.item
      }) : null);
    }
  }]);

  return DataTableRow;
}(React.Component);

_defineProperty(DataTableRow, "displayName", DATA_TABLE_ROW);

_defineProperty(DataTableRow, "propTypes", {
  assistiveText: PropTypes.shape({
    actionsHeader: PropTypes.string,
    columnSort: PropTypes.string,
    columnSortedAscending: PropTypes.string,
    columnSortedDescending: PropTypes.string,
    selectAllRows: PropTypes.string,
    selectRow: PropTypes.string
  }),
  canSelectRows: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['checkbox', 'radio'])]),
  className: PropTypes.string,
  columns: PropTypes.arrayOf(PropTypes.shape({
    Cell: PropTypes.func,
    props: PropTypes.object
  })),

  /**
   * Use this if you are creating an advanced table (selectable, sortable, or resizable rows)
   */
  fixedLayout: PropTypes.bool,
  id: PropTypes.string.isRequired,
  item: PropTypes.object.isRequired,
  onToggle: PropTypes.func,
  rowActions: PropTypes.element,
  selection: PropTypes.array,
  tableId: PropTypes.string
});

export default DataTableRow;
//# sourceMappingURL=row.js.map