"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
Object.defineProperty(exports, "ReactFormGenerator", {
  enumerable: true,
  get: function () {
    return _form.default;
  }
});
Object.defineProperty(exports, "ElementStore", {
  enumerable: true,
  get: function () {
    return _store.default;
  }
});
Object.defineProperty(exports, "Registry", {
  enumerable: true,
  get: function () {
    return _registry.default;
  }
});
exports.ReactFormBuilder = exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactDnd = require("react-dnd");

var _reactDndHtml5Backend = require("react-dnd-html5-backend");

var _preview = _interopRequireDefault(require("./preview"));

var _toolbar = _interopRequireDefault(require("./toolbar"));

var _form = _interopRequireDefault(require("./form"));

var _store = _interopRequireDefault(require("./stores/store"));

var _registry = _interopRequireDefault(require("./stores/registry"));

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

function _extends() { _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; }; return _extends.apply(this, arguments); }

class ReactFormBuilder extends _react.default.Component {
  constructor(props) {
    super(props);
    this.state = {
      editMode: false,
      editElement: null
    };
    this.editModeOn = this.editModeOn.bind(this);
  }

  editModeOn(data, e) {
    e.preventDefault();
    e.stopPropagation();

    if (this.state.editMode) {
      this.setState({
        editMode: !this.state.editMode,
        editElement: null
      });
    } else {
      this.setState({
        editMode: !this.state.editMode,
        editElement: data
      });
    }
  }

  manualEditModeOff() {
    if (this.state.editMode) {
      this.setState({
        editMode: false,
        editElement: null
      });
    }
  }

  render() {
    const toolbarProps = {
      showDescription: this.props.show_description
    };

    if (this.props.toolbarItems) {
      toolbarProps.items = this.props.toolbarItems;
    }

    return /*#__PURE__*/_react.default.createElement(_reactDnd.DndProvider, {
      backend: _reactDndHtml5Backend.HTML5Backend
    }, /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("div", {
      className: "react-form-builder clearfix"
    }, /*#__PURE__*/_react.default.createElement(_preview.default, {
      files: this.props.files,
      manualEditModeOff: this.manualEditModeOff.bind(this),
      showCorrectColumn: this.props.showCorrectColumn,
      parent: this,
      data: this.props.data,
      url: this.props.url,
      saveUrl: this.props.saveUrl,
      onLoad: this.props.onLoad,
      onPost: this.props.onPost,
      editModeOn: this.editModeOn,
      editMode: this.state.editMode,
      variables: this.props.variables,
      registry: _registry.default,
      editElement: this.state.editElement
    }), /*#__PURE__*/_react.default.createElement(_toolbar.default, _extends({}, toolbarProps, {
      customItems: this.props.customToolbarItems
    })))));
  }

}

exports.ReactFormBuilder = ReactFormBuilder;
const FormBuilders = {};
FormBuilders.ReactFormBuilder = ReactFormBuilder;
FormBuilders.ReactFormGenerator = _form.default;
FormBuilders.ElementStore = _store.default;
FormBuilders.Registry = _registry.default;
var _default = FormBuilders;
exports.default = _default;