'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});
exports.TRANSFORMS = exports.SVG_TRANSFORMS = exports.FA_TRANSFORMS = 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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _invariant = require('invariant');

var _invariant2 = _interopRequireDefault(_invariant);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

var _Icon2 = _interopRequireDefault(_Icon);

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

var FA_TRANSFORMS = exports.FA_TRANSFORMS = {
	spin: 'fa-spin',
	'rotate-90': 'fa-rotate-90',
	'rotate-180': 'fa-rotate-180',
	'rotate-270': 'fa-rotate-270',
	'flip-horizontal': 'fa-flip-horizontal',
	'flip-vertical': 'fa-flip-vertical'
};

var SVG_TRANSFORMS = exports.SVG_TRANSFORMS = {
	spin: _Icon2.default.spin,
	'rotate-45': _Icon2.default['rotate-45'],
	'rotate-90': _Icon2.default['rotate-90'],
	'rotate-135': _Icon2.default['rotate-135'],
	'rotate-180': _Icon2.default['rotate-180'],
	'rotate-225': _Icon2.default['rotate-225'],
	'rotate-270': _Icon2.default['rotate-270'],
	'rotate-315': _Icon2.default['rotate-315'],
	'flip-horizontal': _Icon2.default['flip-horizontal'],
	'flip-vertical': _Icon2.default['flip-vertical']
};

var TRANSFORMS = exports.TRANSFORMS = Object.keys(FA_TRANSFORMS);

/**
 * SVG implementation is inspired by
 * http://svgicons.sparkk.fr/
 * @param {object} props react props
 * @example
<Icon name="fa-bars"></Icon>
 */
function Icon(_ref) {
	var className = _ref.className,
	    name = _ref.name,
	    title = _ref.title,
	    transform = _ref.transform;

	var accessibility = {
		focusable: 'false', // IE11
		'aria-hidden': 'true',
		title: title || null
	};
	if (name.startsWith('fa-')) {
		var classes = (0, _classnames2.default)('fa', name, className, transform && FA_TRANSFORMS[transform]);
		return _react2.default.createElement('i', _extends({ className: classes }, accessibility));
	}
	if (name.startsWith('fa fa-') || name.startsWith('icon-')) {
		var _classes = (0, _classnames2.default)(name, className, transform && FA_TRANSFORMS[transform]);
		return _react2.default.createElement('i', _extends({ className: _classes }, accessibility));
	}
	if (name) {
		var classname = (0, _classnames2.default)(_Icon2.default['svg-icon'], 'tc-svg-icon', className, SVG_TRANSFORMS[transform]);
		return _react2.default.createElement(
			'svg',
			_extends({ className: classname }, accessibility),
			_react2.default.createElement('use', { xlinkHref: '#' + name })
		);
	}
	(0, _invariant2.default)(true, 'no name provided');
}

Icon.propTypes = {
	className: _react.PropTypes.string,
	name: _react.PropTypes.string.isRequired,
	title: _react.PropTypes.string,
	transform: _react.PropTypes.oneOf(TRANSFORMS)
};

exports.default = Icon;