'use strict';

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

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _require = require('humps'),
    pascalize = _require.pascalize;

var UnregisteredItem = exports.UnregisteredItem = function (_Component) {
  (0, _inherits3.default)(UnregisteredItem, _Component);

  function UnregisteredItem() {
    (0, _classCallCheck3.default)(this, UnregisteredItem);
    return (0, _possibleConstructorReturn3.default)(this, (UnregisteredItem.__proto__ || Object.getPrototypeOf(UnregisteredItem)).apply(this, arguments));
  }

  (0, _createClass3.default)(UnregisteredItem, [{
    key: 'render',
    value: function render() {
      return _react2.default.createElement(
        'div',
        null,
        'UnregisteredItem'
      );
    }
  }]);
  UnregisteredItem.displayName = 'UnregisteredItem'
  ;
  return UnregisteredItem;
}(_react.Component);

// TODO: when webpack 2 upgrade finished, change this to use System.import


var componentForItem = function componentForItem(intTypeSlug, usage) {
  // MC and MA interactionTypes are the only two that don't have slugs that match
  // the naming conventions on quiz_interactions, we we change them to match
  var componentKey = intTypeSlug && intTypeSlug.replace('-', '_');
  if (componentKey === 'multi_answer') {
    componentKey = 'multiple_answer';
  }

  if (componentKey === 'choice') {
    componentKey = 'multiple_choice';
  }

  // TODO: change quiz interactions
  // to include the underscore
  if (componentKey === 'hot_spot') {
    componentKey = 'hotspot';
  }

  // Try to find the module in the quiz_interactions library with
  // the key that matches the pattern of the slug and use
  try {
    return require('quiz-interactions/lib/components/' + componentKey + '/' + pascalize(usage.toLowerCase()) + '/index.js').default;
  } catch (ex) {
    return UnregisteredItem;
  }
};

exports.default = componentForItem;