'use strict';

var _extends = require('@babel/runtime/helpers/extends');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var classnames = require('classnames');
var PropTypes = require('prop-types');
var React = require('react');
var react = require('@carbon/react');
var Button = require('../../../Button/Button.js');
var Settings = require('../../../../constants/Settings.js');
var iconsReact = require('@carbon/icons-react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _extends__default = /*#__PURE__*/_interopDefault(_extends);
var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);
var PropTypes__default = /*#__PURE__*/_interopDefault(PropTypes);
var React__default = /*#__PURE__*/_interopDefault(React);

var _excluded = ["ariaLabel", "className", "children", "isExpanded", "onExpand", "expandIconDescription", "isSelected", "expandHeaderId", "rowId", "langDir"];
var prefix = Settings.settings.prefix,
  iotPrefix = Settings.settings.iotPrefix;
var propTypes = {
  /**
   * Specify the string read by a voice reader when the expand trigger is
   * focused
   */
  ariaLabel: PropTypes__default.default.string.isRequired,
  children: PropTypes__default.default.node,
  className: PropTypes__default.default.string,
  /**
   * The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43
   */
  expandHeaderId: PropTypes__default.default.string,
  /**
   * The description of the chevron right icon, to be put in its SVG `<title>` element.
   */
  expandIconDescription: PropTypes__default.default.string,
  /**
   * Specify whether this row is expanded or not. This helps coordinate data
   * attributes so that `TableExpandRow` and `TableExpandedRow` work together
   */
  isExpanded: PropTypes__default.default.bool.isRequired,
  /**
   * Specify if the row is selected
   */
  isSelected: PropTypes__default.default.bool,
  /**
   * Hook for when a listener initiates a request to expand the given row
   */
  onExpand: PropTypes__default.default.func.isRequired,
  /**
   * Unique row id
   */
  rowId: PropTypes__default.default.string.isRequired,
  /**
   * direction of document
   */
  langDir: PropTypes__default.default.oneOf(['ltr', 'rtl'])
};
var defaultProps = {
  children: [],
  className: '',
  expandHeaderId: 'expand',
  expandIconDescription: 'Click to expand content',
  isSelected: false,
  langDir: 'ltr'
};
var TableExpandRow = function TableExpandRow(_ref) {
  var ariaLabel = _ref.ariaLabel,
    rowClassName = _ref.className,
    children = _ref.children,
    isExpanded = _ref.isExpanded,
    onExpand = _ref.onExpand,
    expandIconDescription = _ref.expandIconDescription,
    isSelected = _ref.isSelected,
    expandHeaderId = _ref.expandHeaderId,
    rowId = _ref.rowId,
    langDir = _ref.langDir,
    rest = _objectWithoutProperties__default.default(_ref, _excluded);
  var className = classnames__default.default(_defineProperty__default.default(_defineProperty__default.default(_defineProperty__default.default({}, "".concat(prefix, "--parent-row"), true), "".concat(prefix, "--expandable-row"), isExpanded), "".concat(prefix, "--data-table--selected"), isSelected), rowClassName);
  var previousValue = isExpanded ? 'collapsed' : undefined;
  return /*#__PURE__*/React__default.default.createElement("tr", _extends__default.default({}, rest, {
    className: className,
    "data-parent-row": true,
    "data-testid": "expand-row-".concat(rowId)
  }), /*#__PURE__*/React__default.default.createElement(react.TableCell, {
    className: "".concat(prefix, "--table-expand"),
    "data-previous-value": previousValue,
    headers: expandHeaderId
  }, /*#__PURE__*/React__default.default.createElement(Button, {
    "aria-label": ariaLabel,
    testId: "expand-icon-button-".concat(rowId),
    className: classnames__default.default("".concat(prefix, "--table-expand__button"), "".concat(iotPrefix, "--table-expand__button"), "".concat(iotPrefix, "--tooltip-svg-wrapper"), _defineProperty__default.default({}, "".concat(iotPrefix, "--table-expand__button--close"), isExpanded)),
    onClick: onExpand,
    iconDescription: expandIconDescription,
    renderIcon: iconsReact.ChevronRight,
    size: "sm",
    tooltipAlignment: langDir === 'ltr' ? 'start' : 'end',
    tooltipPosition: "top",
    kind: "icon-selection"
  })), children);
};
TableExpandRow.propTypes = propTypes;
TableExpandRow.defaultProps = defaultProps;
TableExpandRow.__docgenInfo = {
  "description": "",
  "methods": [],
  "displayName": "TableExpandRow",
  "props": {
    "children": {
      "defaultValue": {
        "value": "[]",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "node"
      },
      "required": false
    },
    "className": {
      "defaultValue": {
        "value": "''",
        "computed": false
      },
      "description": "",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "expandHeaderId": {
      "defaultValue": {
        "value": "'expand'",
        "computed": false
      },
      "description": "The id of the matching th node in the table head. Addresses a11y concerns outlined here: https://www.ibm.com/able/guidelines/ci162/info_and_relationships.html and https://www.w3.org/TR/WCAG20-TECHS/H43",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "expandIconDescription": {
      "defaultValue": {
        "value": "'Click to expand content'",
        "computed": false
      },
      "description": "The description of the chevron right icon, to be put in its SVG `<title>` element.",
      "type": {
        "name": "string"
      },
      "required": false
    },
    "isSelected": {
      "defaultValue": {
        "value": "false",
        "computed": false
      },
      "description": "Specify if the row is selected",
      "type": {
        "name": "bool"
      },
      "required": false
    },
    "langDir": {
      "defaultValue": {
        "value": "'ltr'",
        "computed": false
      },
      "description": "direction of document",
      "type": {
        "name": "enum",
        "value": [{
          "value": "'ltr'",
          "computed": false
        }, {
          "value": "'rtl'",
          "computed": false
        }]
      },
      "required": false
    },
    "ariaLabel": {
      "description": "Specify the string read by a voice reader when the expand trigger is\nfocused",
      "type": {
        "name": "string"
      },
      "required": true
    },
    "isExpanded": {
      "description": "Specify whether this row is expanded or not. This helps coordinate data\nattributes so that `TableExpandRow` and `TableExpandedRow` work together",
      "type": {
        "name": "bool"
      },
      "required": true
    },
    "onExpand": {
      "description": "Hook for when a listener initiates a request to expand the given row",
      "type": {
        "name": "func"
      },
      "required": true
    },
    "rowId": {
      "description": "Unique row id",
      "type": {
        "name": "string"
      },
      "required": true
    }
  }
};
var TableExpandRow$1 = TableExpandRow;

module.exports = TableExpandRow$1;
