text: 'use strict';
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  
  var _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; };
  
  var _createClass = 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); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  
  var _simpleAssign = require('simple-assign');
  
  var _simpleAssign2 = _interopRequireDefault(_simpleAssign);
  
  var _react = require('react');
  
  var _react2 = _interopRequireDefault(_react);
  
  var _Paper = require('../Paper');
  
  var _Paper2 = _interopRequireDefault(_Paper);
  
  var _CardExpandable = require('./CardExpandable');
  
  var _CardExpandable2 = _interopRequireDefault(_CardExpandable);
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  
  function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
  
  var Card = function (_Component) {
    _inherits(Card, _Component);
  
    function Card() {
      var _Object$getPrototypeO;
  
      var _temp, _this, _ret;
  
      _classCallCheck(this, Card);
  
      for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }
  
      return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_Object$getPrototypeO = Object.getPrototypeOf(Card)).call.apply(_Object$getPrototypeO, [this].concat(args))), _this), _this.state = { expanded: null }, _this.handleExpanding = function (event) {
        event.preventDefault();
        var newExpandedState = !_this.state.expanded;
        // no automatic state update when the component is controlled
        if (_this.props.expanded === null) {
          _this.setState({ expanded: newExpandedState });
        }
        if (_this.props.onExpandChange) _this.props.onExpandChange(newExpandedState);
      }, _temp), _possibleConstructorReturn(_this, _ret);
    }
  
    _createClass(Card, [{
      key: 'componentWillMount',
      value: function componentWillMount() {
        this.setState({
          expanded: this.props.expanded === null ? this.props.initiallyExpanded === true : this.props.expanded
        });
      }
    }, {
      key: 'componentWillReceiveProps',
      value: function componentWillReceiveProps(nextProps) {
        // update the state when the component is controlled.
        if (nextProps.expanded !== null) this.setState({ expanded: nextProps.expanded });
      }
    }, {
      key: 'render',
      value: function render() {
        var _this2 = this;
  
        var lastElement = void 0;
        var expanded = this.state.expanded;
        var newChildren = _react2.default.Children.map(this.props.children, function (currentChild) {
          var doClone = false;
          var newChild = undefined;
          var newProps = {};
          var element = currentChild;
          if (!currentChild || !currentChild.props) {
            return null;
          }
          if (expanded === false && currentChild.props.expandable === true) return;
          if (currentChild.props.actAsExpander === true) {
            doClone = true;
            newProps.onTouchTap = _this2.handleExpanding;
            newProps.style = (0, _simpleAssign2.default)({ cursor: 'pointer' }, currentChild.props.style);
          }
          if (currentChild.props.showExpandableButton === true) {
            doClone = true;
            newChild = _react2.default.createElement(_CardExpandable2.default, { expanded: expanded, onExpanding: _this2.handleExpanding });
          }
          if (doClone) {
            element = _react2.default.cloneElement(currentChild, newProps, currentChild.props.children, newChild);
          }
          return element;
        }, this);
  
        // If the last element is text or a title we should add
        // 8px padding to the bottom of the card
        var addBottomPadding = lastElement && (lastElement.type.muiName === 'CardText' || lastElement.type.muiName === 'CardTitle');
        var _props = this.props;
        var style = _props.style;
        var containerStyle = _props.containerStyle;
  
        var other = _objectWithoutProperties(_props, ['style', 'containerStyle']);
  
        var mergedStyles = (0, _simpleAssign2.default)({
          zIndex: 1
        }, style);
        var containerMergedStyles = (0, _simpleAssign2.default)({
          paddingBottom: addBottomPadding ? 8 : 0
        }, containerStyle);
  
        return _react2.default.createElement(
          _Paper2.default,
          _extends({}, other, { style: mergedStyles }),
          _react2.default.createElement(
            'div',
            { style: containerMergedStyles },
            newChildren
          )
        );
      }
    }]);
  
    return Card;
  }(_react.Component);
  
  Card.propTypes = {
    /**
     * If true, a click on this card component expands the card. Can be set on any child of the `Card` component.
     */
    actAsExpander: _react.PropTypes.bool,
    /**
     * Can be used to render elements inside the Card.
     */
    children: _react.PropTypes.node,
    /**
     * Override the inline-styles of the container element.
     */
    containerStyle: _react.PropTypes.object,
    /**
     * If true, this card component is expandable. Can be set on any child of the `Card` component.
     */
    expandable: _react.PropTypes.bool,
    /**
     * Whether this card is expanded.
     * If `true` or `false` the component is controlled.
     * if `null` the component is uncontrolled.
     */
    expanded: _react.PropTypes.bool,
    /**
     * Whether this card is initially expanded.
     */
    initiallyExpanded: _react.PropTypes.bool,
    /**
     * Callback function fired when the `expandable` state of the card has changed.
     *
     * @param {boolean} newExpandedState Represents the new `expanded` state of the card.
     */
    onExpandChange: _react.PropTypes.func,
    /**
     * If true, this card component will include a button to expand the card. `CardTitle`,
     * `CardHeader` and `CardActions` implement `showExpandableButton`. Any child component
     * of `Card` can implements `showExpandableButton` or forwards the property to a child
     * component supporting it.
     */
    showExpandableButton: _react.PropTypes.bool,
    /**
     * Override the inline-styles of the root element.
     */
    style: _react.PropTypes.object
  };
  Card.defaultProps = {
    expanded: null,
    expandable: false,
    initiallyExpanded: false,
    actAsExpander: false
  };
  exports.default = Card;