'use strict';

exports.__esModule = true;
exports.default = undefined;

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 _class, _temp2;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

require('./style.scss');

var _reactChartjs = require('react-chartjs-2');

var charts = _interopRequireWildcard(_reactChartjs);

var _Title = require('../Title');

var _Title2 = _interopRequireDefault(_Title);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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; }

/**
 * Display some `data` as a numeric metric or a chart.
 */
var Metric = (_temp2 = _class = function (_React$Component) {
  _inherits(Metric, _React$Component);

  function Metric() {
    var _temp, _this, _ret;

    _classCallCheck(this, Metric);

    for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.chart = function () {
      var chartType = _this.props.chart.charAt(0).toUpperCase() + _this.props.chart.substring(1);
      return new charts[chartType]();
    }, _temp), _possibleConstructorReturn(_this, _ret);
  }

  Metric.prototype.render = function render() {
    return _react2.default.createElement(
      'div',
      {
        className: ['Metric', this.props.className, this.props.chart ? 'Metric_chart' : ''].join(' '),
        style: this.props.style
      },
      _react2.default.createElement(
        'div',
        { className: 'Metric-value' },
        this.props.chart ? _react2.default.createElement(this.chart, { data: this.props.data, options: _extends({ maintainAspectRatio: false }, this.props.data.options) }) : _react2.default.createElement(
          _Title2.default,
          { className: 'Metric-label', level: 1 },
          this.props.data
        )
      ),
      this.props.children || _react2.default.createElement(
        _Title2.default,
        { level: 5 },
        _react2.default.createElement(
          'b',
          null,
          this.props.label
        )
      )
    );
  };

  return Metric;
}(_react2.default.Component), _class.defaultProps = {
  label: ''
}, _temp2);
exports.default = Metric;
Metric.propTypes = process.env.NODE_ENV !== "production" ? {
  chart: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.bool]),
  data: _propTypes2.default.oneOfType([_propTypes2.default.object, _propTypes2.default.number, _propTypes2.default.string]).isRequired,
  label: _propTypes2.default.string
} : {};
module.exports = exports['default'];