'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ButtonImageWithText = undefined;

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _radium = require('radium');

var _radium2 = _interopRequireDefault(_radium);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _buttonImage = require('kitten/components/buttons/button-image');

var _text = require('kitten/components/typography/text');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

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 ButtonImage = (0, _radium2.default)(_buttonImage.ButtonImage);
var Text = (0, _radium2.default)(_text.Text);

var ButtonImageWithTextComponent = function (_Component) {
  _inherits(ButtonImageWithTextComponent, _Component);

  function ButtonImageWithTextComponent() {
    _classCallCheck(this, ButtonImageWithTextComponent);

    return _possibleConstructorReturn(this, (ButtonImageWithTextComponent.__proto__ || Object.getPrototypeOf(ButtonImageWithTextComponent)).apply(this, arguments));
  }

  _createClass(ButtonImageWithTextComponent, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        { style: styles },
        this.renderButtonImage(),
        this.renderDescription()
      );
    }
  }, {
    key: 'renderButtonImage',
    value: function renderButtonImage() {
      return _react2.default.createElement(ButtonImage, {
        tag: 'span',
        img: this.props.avatarProps,
        withoutPointerEvents: true
      });
    }
  }, {
    key: 'renderDescription',
    value: function renderDescription() {
      var _props = this.props,
          title = _props.title,
          description = _props.description,
          micro = _props.micro,
          tag = _props.tag,
          titleRegular = _props.titleRegular,
          textRegular = _props.textRegular,
          largeGutter = _props.largeGutter;


      var size = micro ? 'micro' : 'tiny';

      var Tag = tag;

      var titleWeight = titleRegular ? 'regular' : 'light';

      var textWeight = textRegular ? 'regular' : 'light';

      var styleTag = [styles, tag == 'p' && styles.paragraph];

      var styleText = [styles.text, largeGutter && styles.text.largeGutter];

      return _react2.default.createElement(
        'div',
        { style: styleText },
        _react2.default.createElement(
          Text,
          { tag: Tag, size: size, weight: titleWeight, style: styleTag },
          title
        ),
        _react2.default.createElement(
          Text,
          { tag: Tag, size: size, weight: textWeight, style: styleTag },
          description
        )
      );
    }
  }]);

  return ButtonImageWithTextComponent;
}(_react.Component);

ButtonImageWithTextComponent.propTypes = {
  title: _propTypes2.default.string.isRequired,
  description: _propTypes2.default.string.isRequired,
  micro: _propTypes2.default.bool,
  tag: _propTypes2.default.string,
  largeGutter: _propTypes2.default.bool,
  titleRegular: _propTypes2.default.bool,
  textRegular: _propTypes2.default.bool,
  avatarProps: _propTypes2.default.func
};
ButtonImageWithTextComponent.defaultProps = {
  avatarProps: {
    src: 'https://placehold.it/100x100/caf4fe/caf4fe',
    alt: ''
  },
  micro: false,
  tag: 'p',
  largeGutter: false,
  titleRegular: false,
  textRegular: false
};


var styles = {
  display: 'flex',
  alignItems: 'center',
  flex: '1',

  text: {
    marginLeft: '10px',
    lineHeight: '1.2',

    largeGutter: {
      marginLeft: '15px'
    }
  },

  paragraph: {
    margin: 0
  }
};

var ButtonImageWithText = exports.ButtonImageWithText = (0, _radium2.default)(ButtonImageWithTextComponent);