import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inherits from "@babel/runtime/helpers/inherits";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _defineProperty from "@babel/runtime/helpers/defineProperty";

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 from 'react';
import { storiesOf } from '@storybook/react';
import Modal from '.';

var ModalWithControls = /*#__PURE__*/function (_React$Component) {
  _inherits(ModalWithControls, _React$Component);

  var _super = _createSuper(ModalWithControls);

  function ModalWithControls() {
    var _this;

    _classCallCheck(this, ModalWithControls);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _super.call.apply(_super, [this].concat(args));

    _defineProperty(_assertThisInitialized(_this), "state", {
      open: false
    });

    _defineProperty(_assertThisInitialized(_this), "toggleModal", function () {
      _this.setState(function (state) {
        return {
          open: !state.open
        };
      });
    });

    _defineProperty(_assertThisInitialized(_this), "submitAndClose", function () {
      alert('Submit now and close the modal');

      _this.setState(function (state) {
        return {
          open: false
        };
      });
    });

    return _this;
  }

  _createClass(ModalWithControls, [{
    key: "render",
    value: function render() {
      var open = this.state.open;
      return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("button", {
        onClick: this.toggleModal
      }, "Open Modal"), /*#__PURE__*/React.createElement(Modal, {
        open: open,
        primaryButtonText: "Submit",
        onRequestSubmit: this.submitAndClose,
        secondaryButtonText: "Cancel Modal",
        onSecondarySubmit: this.toggleModal,
        onRequestClose: this.toggleModal
      }, /*#__PURE__*/React.createElement("p", {
        className: "wfp--modal-content__text"
      }, "Nothing to see here")));
    }
  }]);

  return ModalWithControls;
}(React.Component);

storiesOf('Components|Modal', module).add('with Controls', function () {
  return /*#__PURE__*/React.createElement(ModalWithControls, null);
});