"use strict";

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

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

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 _index = require("@material-ui/core/styles/index");

var _index2 = _interopRequireDefault(require("@material-ui/core/Collapse/index"));

var _mathRendering = require("../../math-rendering");

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 { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

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

  var _super = _createSuper(Collapsible);

  function Collapsible() {
    var _this;

    (0, _classCallCheck2["default"])(this, Collapsible);

    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));
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "state", {
      expanded: false
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "toggleExpanded", function () {
      _this.setState(function (state) {
        return {
          expanded: !state.expanded
        };
      });
    });
    return _this;
  }

  (0, _createClass2["default"])(Collapsible, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      (0, _mathRendering.renderMath)(this.root);
    }
  }, {
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      (0, _mathRendering.renderMath)(this.root);
    }
  }, {
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          classes = _this$props.classes,
          labels = _this$props.labels,
          children = _this$props.children,
          className = _this$props.className;
      var title = this.state.expanded ? labels.visible || 'Hide' : labels.hidden || 'Show';
      return /*#__PURE__*/_react["default"].createElement("div", {
        className: className,
        ref: function ref(r) {
          return _this2.root = r;
        }
      }, /*#__PURE__*/_react["default"].createElement("div", {
        onClick: this.toggleExpanded
      }, /*#__PURE__*/_react["default"].createElement("span", {
        className: classes.title
      }, title)), /*#__PURE__*/_react["default"].createElement(_index2["default"], {
        "in": this.state.expanded,
        timeout: "auto",
        unmountOnExit: true,
        className: classes.collapsible
      }, children));
    }
  }]);
  return Collapsible;
}(_react["default"].Component);

exports.Collapsible = Collapsible;
(0, _defineProperty2["default"])(Collapsible, "propTypes", {
  classes: _propTypes["default"].object.isRequired,
  className: _propTypes["default"].string,
  children: _propTypes["default"].object,
  labels: _propTypes["default"].shape({
    visible: _propTypes["default"].string,
    hidden: _propTypes["default"].string
  })
});
(0, _defineProperty2["default"])(Collapsible, "defaultProps", {
  labels: {}
});

var _default = (0, _index.withStyles)(function (theme) {
  return {
    title: {
      color: theme.palette.primary.light,
      borderBottom: "1px dotted ".concat(theme.palette.primary.light),
      cursor: 'pointer'
    },
    collapsible: {
      paddingTop: theme.spacing.unit * 2
    }
  };
})(Collapsible);

exports["default"] = _default;
//# sourceMappingURL=index.js.map