'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactCodemirror = require('@skidding/react-codemirror');

var _reactCodemirror2 = _interopRequireDefault(_reactCodemirror);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _lodash = require('lodash');

var _lodash2 = _interopRequireDefault(_lodash);

var _helpers = require('./codeMirror/helpers');

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

require('codemirror/mode/javascript/javascript'); /* eslint-disable import/no-extraneous-dependencies */

require('codemirror/lib/codemirror.css');
require('./Editor.css'); // Order Important
require('codemirror/mode/xml/xml');
require('codemirror/mode/markdown/markdown');
require('codemirror/addon/lint/lint.js');
require('./codeMirror/addon/lint/eslint/eslint-lint.js');
require('codemirror/addon/comment/comment.js');
require('codemirror/addon/comment/continuecomment.js');
require('codemirror/addon/edit/closebrackets.js');
require('codemirror/keymap/sublime.js');

var Editor = function Editor(_ref) {
  var showLints = _ref.showLints,
      onValidCode = _ref.onValidCode,
      onAnyCode = _ref.onAnyCode,
      code = _ref.code;

  if (showLints) {
    require('codemirror/addon/lint/lint.css');
  }

  var handleValidCode = function handleValidCode(annotationsNotSorted, annotations, cmInstance) {
    var cleanCode = cmInstance.getValue();
    onValidCode(cleanCode);
  };

  var options = (0, _helpers.getOptions)({}, _lodash2.default.debounce(handleValidCode, 300));

  return _react2.default.createElement(_reactCodemirror2.default, {
    value: code,
    onChange: onAnyCode,
    options: options
  });
};

Editor.propTypes = {
  code: _propTypes2.default.string,
  onValidCode: _propTypes2.default.func,
  onAnyCode: _propTypes2.default.func,
  showLints: _propTypes2.default.bool
};

Editor.defaultProps = {
  code: '// Your code here:',
  showLints: true,
  onValidCode: function onValidCode(lintedCode) {},
  onAnyCode: function onAnyCode(code) {}
};

exports.default = Editor;