'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.CodeWrapper = 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 _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _reactSyntaxHighlighter = require('react-syntax-highlighter');

var _reactSyntaxHighlighter2 = _interopRequireDefault(_reactSyntaxHighlighter);

var _tomorrowNight = require('react-syntax-highlighter/dist/styles/tomorrow-night');

var _tomorrowNight2 = _interopRequireDefault(_tomorrowNight);

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 CodeWrapper = exports.CodeWrapper = _styledComponents2.default.pre.withConfig({
  displayName: 'Code__CodeWrapper'
})(['word-wrap: break-word;white-space: pre-wrap;text-rendering: optimizeLegibility;-webkit-font-smoothing: antialiased;font-family: ', ';font-size: ', ';background: ', ';color: ', ';padding: ', ';margin: 0;& pre, & code {background: transparent !important;word-wrap: inherit;white-space: inherit;}'], function (_ref) {
  var theme = _ref.theme;
  return theme.code.fontFamily;
}, function (_ref2) {
  var theme = _ref2.theme;
  return theme.code.fontSize;
}, function (_ref3) {
  var theme = _ref3.theme;
  return theme.code.bg;
}, function (_ref4) {
  var theme = _ref4.theme;
  return theme.code.fg;
}, function (_ref5) {
  var theme = _ref5.theme;
  return theme.code.padding;
});

var Code = function (_React$Component) {
  _inherits(Code, _React$Component);

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

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

  _createClass(Code, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        CodeWrapper,
        null,
        _react2.default.createElement(
          _reactSyntaxHighlighter2.default,
          { language: this.props.language, style: _tomorrowNight2.default },
          '' + this.props.children
        )
      );
    }
  }]);

  return Code;
}(_react2.default.Component);

Code.propTypes = {
  children: _propTypes2.default.node.isRequired,
  language: _propTypes2.default.string
};
Code.defaultProps = {
  language: 'javascript'
};


Code.usage = '\n# Code\n\nApplies styling to render code on the page. Supports multiline only (use InlineCode for single line).\n\n```\n<Code>\nSome complex\nCode here\n</Code>\n```\n';

exports.default = Code;