"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _react = _interopRequireDefault(require("react"));
var _RichTextInputAreaForm = _interopRequireDefault(require("./RichTextInputAreaForm"));
var _RichTextInputAreaContext = require("../RichTextInputAreaContext");
var _Box = _interopRequireDefault(require("../../Box"));
var _Input = _interopRequireDefault(require("../../Input"));
var _jsxFileName = "/home/builduser/work/57e038ea7326c1ec/packages/wix-design-system/dist/cjs/RichTextInputArea/Form/RichTextInputAreaLinkForm.jsx";
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
var RichTextInputAreaLinkForm = /*#__PURE__*/function (_React$Component) {
  function RichTextInputAreaLinkForm(props) {
    var _this;
    (0, _classCallCheck2["default"])(this, RichTextInputAreaLinkForm);
    _this = _callSuper(this, RichTextInputAreaLinkForm, [props]);
    _this.state = {
      text: '',
      url: ''
    };
    _this._onSubmit = function (event) {
      // Prevents form submission, but still enables submission when clicking `Enter`
      event.preventDefault();
      var onSubmit = _this.props.onSubmit;
      var _this$state = _this.state,
        text = _this$state.text,
        url = _this$state.url;
      onSubmit && onSubmit(event, {
        text: text,
        url: url
      });
    };
    var _props$data = props.data,
      _props$data$text = _props$data.text,
      _text = _props$data$text === void 0 ? '' : _props$data$text,
      _props$data$url = _props$data.url,
      _url = _props$data$url === void 0 ? '' : _props$data$url;
    _this.state = {
      text: _text,
      url: _url
    };
    return _this;
  }
  (0, _inherits2["default"])(RichTextInputAreaLinkForm, _React$Component);
  return (0, _createClass2["default"])(RichTextInputAreaLinkForm, [{
    key: "render",
    value: function render() {
      var _this2 = this;
      var _this$props = this.props,
        dataHook = _this$props.dataHook,
        onCancel = _this$props.onCancel;
      return /*#__PURE__*/_react["default"].createElement(_RichTextInputAreaContext.RichTextInputAreaContext.Consumer, {
        __self: this,
        __source: {
          fileName: _jsxFileName,
          lineNumber: 29,
          columnNumber: 7
        }
      }, function (_ref) {
        var texts = _ref.texts;
        return /*#__PURE__*/_react["default"].createElement(_RichTextInputAreaForm["default"], {
          dataHook: dataHook,
          onSubmit: _this2._onSubmit,
          onCancel: onCancel,
          isDisabled: _this2.state.url.length === 0,
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 31,
            columnNumber: 11
          }
        }, /*#__PURE__*/_react["default"].createElement(_Box["default"], {
          marginBottom: 2,
          direction: "vertical",
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 37,
            columnNumber: 13
          }
        }, /*#__PURE__*/_react["default"].createElement(_Input["default"], {
          dataHook: "richtextarea-form-link-text",
          placeholder: texts.insertionForm.link.textInputPlaceholder,
          size: "small",
          value: _this2.state.text,
          onChange: function onChange(event) {
            return _this2._setInputValue(event, 'text');
          },
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 38,
            columnNumber: 15
          }
        })), /*#__PURE__*/_react["default"].createElement(_Input["default"], {
          dataHook: "richtextarea-form-link-url",
          placeholder: texts.insertionForm.link.urlInputPlaceholder,
          size: "small",
          value: _this2.state.url,
          onChange: function onChange(event) {
            return _this2._setInputValue(event, 'url');
          },
          __self: _this2,
          __source: {
            fileName: _jsxFileName,
            lineNumber: 46,
            columnNumber: 13
          }
        }));
      });
    }
  }, {
    key: "_setInputValue",
    value: function _setInputValue(event, key) {
      var value = event.target.value;
      this.setState((0, _defineProperty2["default"])({}, key, value));
    }
  }]);
}(_react["default"].Component);
var _default = exports["default"] = RichTextInputAreaLinkForm;