'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 _getClassName2 = require('babel-plugin-react-css-modules/dist/browser/getClassName');

var _getClassName3 = _interopRequireDefault(_getClassName2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _Icon = require('../Icon');

var _Icon2 = _interopRequireDefault(_Icon);

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

var _styleModuleImportMap = {
  './title.scss': {
    'base': 'flive_title_base',
    'primary': 'flive_title_primary',
    'purple': 'flive_title_purple',
    'white': 'flive_title_white',
    'strong': 'flive_title_strong',
    'withoutMargeTop': 'flive_title_withoutMargeTop',
    'withoutMargeBottom': 'flive_title_withoutMargeBottom',
    'withoutMarge': 'flive_title_withoutMarge',
    'dash-lagoon': 'flive_title_dash-lagoon',
    'level-1': 'flive_title_level-1',
    'level-2': 'flive_title_level-2',
    'level-3': 'flive_title_level-3',
    'level-4': 'flive_title_level-4',
    'level-5': 'flive_title_level-5',
    'center': 'flive_title_center',
    'icon': 'flive_title_icon'
  }
};

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

var propTypes = {
  level: _propTypes2.default.oneOf([1, 2, 3, 4, 5]),
  variant: _propTypes2.default.oneOf(['primary', 'dash-lagoon', 'purple', 'white']),
  strong: _propTypes2.default.bool,
  withoutMargeTop: _propTypes2.default.bool,
  withoutMargeBottom: _propTypes2.default.bool,
  withoutMarge: _propTypes2.default.bool,
  center: _propTypes2.default.bool,
  /** A component, h1, h2, h3, a, react router Link, etc... */
  component: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.object, _propTypes2.default.func]),
  children: _propTypes2.default.any,
  icon: _propTypes2.default.string,
  className: _propTypes2.default.string
};

var defaultProps = {
  level: 3,
  variant: 'primary',
  strong: false,
  withoutMargeTop: false,
  withoutMargeBottom: false,
  withoutMarge: false,
  center: false,
  component: null,
  children: null,
  icon: null,
  className: undefined
};

var Title = function Title(_ref) {
  var icon = _ref.icon,
      component = _ref.component,
      level = _ref.level,
      variant = _ref.variant,
      strong = _ref.strong,
      withoutMarge = _ref.withoutMarge,
      withoutMargeTop = _ref.withoutMargeTop,
      withoutMargeBottom = _ref.withoutMargeBottom,
      center = _ref.center,
      children = _ref.children,
      className = _ref.className,
      props = _objectWithoutProperties(_ref, ['icon', 'component', 'level', 'variant', 'strong', 'withoutMarge', 'withoutMargeTop', 'withoutMargeBottom', 'center', 'children', 'className']);

  var resultLevel = Math.min(level, 5) || 5;
  var MyComponent = component || 'h' + resultLevel;
  return _react2.default.createElement(
    'div',
    null,
    _react2.default.createElement(
      MyComponent,
      _extends({}, props, {
        className: (className ? className + ' ' : '') + (0, _getClassName3.default)((0, _classnames2.default)('base', 'level-' + resultLevel, variant, {
          strong: strong,
          withoutMargeTop: withoutMargeTop,
          withoutMargeBottom: withoutMargeBottom,
          withoutMarge: withoutMarge,
          center: center
        }), _styleModuleImportMap)
      }),
      icon ? _react2.default.createElement(_Icon2.default, { size: 'md', name: icon, className: 'flive_title_icon' }) : null,
      children
    )
  );
};

Title.propTypes = propTypes;
Title.defaultProps = defaultProps;

exports.default = Title;
module.exports = exports['default'];