import _extends from "@babel/runtime/helpers/extends";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

import React, { Component } from 'react';
import { reduxForm } from 'redux-form';
import { connect } from 'react-redux';
import { load as loadAccount } from './loadDefaultData';

var FormEl = /*#__PURE__*/function (_Component) {
  _inherits(FormEl, _Component);

  var _super = _createSuper(FormEl);

  function FormEl() {
    _classCallCheck(this, FormEl);

    return _super.apply(this, arguments);
  }

  _createClass(FormEl, [{
    key: "render",
    value: function render() {
      var handleSubmit = this.props.handleSubmit;
      return /*#__PURE__*/React.createElement("form", {
        onSubmit: handleSubmit,
        className: "wfp-form--stacked"
      }, this.props.children);
    }
  }]);

  return FormEl;
}(Component);

var Form = reduxForm({
  form: 'SimpleForm',
  //Form name is same
  enableReinitialize: true
})(FormEl); // You have to connect() to any reducers that you wish to connect to yourself

Form = connect(function (state) {
  return {
    initialValues: state.account.data // pull initial values from account reducer

  };
}, {
  load: loadAccount
} // bind account loading action creator
)(Form);

var RfFormWrapper = /*#__PURE__*/function (_Component2) {
  _inherits(RfFormWrapper, _Component2);

  var _super2 = _createSuper(RfFormWrapper);

  function RfFormWrapper() {
    _classCallCheck(this, RfFormWrapper);

    return _super2.apply(this, arguments);
  }

  _createClass(RfFormWrapper, [{
    key: "onSubmit",
    value: function onSubmit(submit) {
      alert('Submitted: ' + JSON.stringify(submit));
    }
  }, {
    key: "render",
    value: function render() {
      return /*#__PURE__*/React.createElement(Form, _extends({
        onSubmit: this.onSubmit
      }, this.props), this.props.children);
    }
  }]);

  return RfFormWrapper;
}(Component);

export default RfFormWrapper;