'use strict';

exports.__esModule = true;
exports.default = TutorialResponse;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _debounce = require('lodash/debounce');

var _debounce2 = _interopRequireDefault(_debounce);

var _CodeEditor = require('../../../CodeEditor');

var _CodeEditor2 = _interopRequireDefault(_CodeEditor);

var _ = require('../..');

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

// Components
function TutorialResponse(_ref) {
  var response = _ref.response,
      updateTutorial = _ref.updateTutorial;

  var handleChange = function handleChange(value, _ref2, readOnly) {
    var origin = _ref2.origin;

    if (['+input', 'paste', '+delete'].includes(origin) && !readOnly) {
      updateTutorial({ response: value });
    }
  };

  var _onChange = process.env.NODE_ENV === 'test' ? handleChange : (0, _debounce2.default)(handleChange, 300);

  return _react2.default.createElement(
    _.PermissionContext.Consumer,
    null,
    function (readOnly) {
      return _react2.default.createElement(_CodeEditor2.default, {
        code: response,
        lang: 'json',
        onChange: function onChange(editor, data, value) {
          _onChange(value, data, readOnly);
        },
        options: { readOnly: readOnly ? 'nocursor' : false }
      });
    }
  );
}

// Permissions
// 3rd-Party Libraries


TutorialResponse.propTypes = process.env.NODE_ENV !== "production" ? {
  response: _propTypes2.default.string,
  updateTutorial: _propTypes2.default.func
} : {};

TutorialResponse.defaultProps = {
  response: ''
};
module.exports = exports['default'];