"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(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 { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

// Style

/* istanbul ignore next */
if (typeof window !== 'undefined') {}

var ShowMore = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(ShowMore, _React$Component);

  var _super = _createSuper(ShowMore);

  function ShowMore(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, ShowMore);
    _this = _super.call(this, props);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function () {
      return _this.setState({
        open: !_this.state.open
      });
    });
    _this.state = {
      open: props.open || false
    };
    return _this;
  }

  (0, _createClass2["default"])(ShowMore, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          children = _this$props.children,
          fade = _this$props.fade,
          height = _this$props.height,
          label = _this$props.label,
          labelClose = _this$props.labelClose,
          open = _this$props.open,
          props = (0, _objectWithoutProperties2["default"])(_this$props, ["children", "fade", "height", "label", "labelClose", "open"]);
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: "ShowMore ".concat(!fade || 'ShowMore_fade', " ").concat(props.className),
        open: this.state.open,
        style: {
          maxHeight: this.state.open ? '' : height
        }
      }, children, /*#__PURE__*/_react["default"].createElement("div", {
        className: "ShowMore-toggle",
        onClick: this.handleClick,
        onKeyDown: this.handleClick,
        role: "button",
        tabIndex: 0
      }, this.state.open ? labelClose : label));
    }
  }]);
  return ShowMore;
}(_react["default"].Component);

(0, _defineProperty2["default"])(ShowMore, "propTypes", {
  children: _propTypes["default"].array,
  className: _propTypes["default"].array,
  fade: _propTypes["default"].bool,
  height: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
  label: _propTypes["default"].string,
  labelClose: _propTypes["default"].string,
  open: _propTypes["default"].bool
});
(0, _defineProperty2["default"])(ShowMore, "defaultProps", {
  fade: true,
  height: '',
  label: 'Show More',
  labelClose: 'Show Less',
  open: false
});
var _default = ShowMore;
exports["default"] = _default;