"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _typeof = require("@babel/runtime/helpers/typeof");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

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

var _Icon = _interopRequireDefault(require("../../components/Icon"));

var _Button = _interopRequireDefault(require("../../components/Button"));

var _TextArea = _interopRequireDefault(require("../../components/TextArea"));

var _Module = require("../../components/Module");

var _ReduxFormWrapper = _interopRequireDefault(require("../../components/ReduxFormWrapper"));

var _reactFinalForm = require("react-final-form");

var _Blockquote = _interopRequireDefault(require("../../components/Blockquote"));

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(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; } }

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

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

var FaviconGenerator = /*#__PURE__*/function (_Component) {
  (0, _inherits2.default)(FaviconGenerator, _Component);

  var _super = _createSuper(FaviconGenerator);

  function FaviconGenerator(props) {
    var _this;

    (0, _classCallCheck2.default)(this, FaviconGenerator);
    _this = _super.call(this, props);
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onSubmit", /*#__PURE__*/function () {
      var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(values) {
        var result, formatted;
        return _regenerator.default.wrap(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                result = getJSON(values.svg);
                formatted = formatJS(result, {
                  json: false
                });

                _this.setState({
                  json: formatted
                });

              case 3:
              case "end":
                return _context.stop();
            }
          }
        }, _callee);
      }));

      return function (_x) {
        return _ref.apply(this, arguments);
      };
    }());
    _this.state = {
      dataurl: {}
    };
    return _this;
  }

  (0, _createClass2.default)(FaviconGenerator, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      return /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_reactFinalForm.Form, {
        onSubmit: this.onSubmit,
        initialValues: {
          svg: "<svg id=\"Layer_1\" data-name=\"Layer 1\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 16 14\">\n  <title>favorite--outline</title>\n  <path d=\"M1.49,7.72A4.41,4.41,0,1,1,8,1.84a4.42,4.42,0,1,1,6.44,6L8,13.87Z\"/>\n</svg>\n            "
        },
        render: function render(_ref2) {
          var handleSubmit = _ref2.handleSubmit,
              form = _ref2.form,
              submitting = _ref2.submitting,
              pristine = _ref2.pristine,
              values = _ref2.values;
          return /*#__PURE__*/_react.default.createElement("form", {
            onSubmit: handleSubmit,
            className: "wfp--form-long"
          }, /*#__PURE__*/_react.default.createElement(_Module.Module, {
            light: true,
            className: "some-class",
            style: {
              padding: '1em 0'
            }
          }, /*#__PURE__*/_react.default.createElement(_Module.ModuleHeader, null, "Convert svg to icon"), /*#__PURE__*/_react.default.createElement(_Module.ModuleBody, null, /*#__PURE__*/_react.default.createElement(_reactFinalForm.Field, {
            name: "svg",
            component: _ReduxFormWrapper.default,
            inputComponent: _TextArea.default,
            type: "text",
            labelText: "SVG code",
            placeholder: "Your svg code"
          }), /*#__PURE__*/_react.default.createElement(_Button.default, {
            type: "submit",
            style: {
              marginTop: '1em'
            }
          }, "Generate Icon"), _this2.state.json && /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement("label", {
            className: "wfp--label"
          }, "Preview"), /*#__PURE__*/_react.default.createElement("br", null), /*#__PURE__*/_react.default.createElement(_Module.Module, {
            light: true,
            className: "some-class",
            style: {
              padding: '1em 0'
            }
          }, /*#__PURE__*/_react.default.createElement(_Module.ModuleBody, null, /*#__PURE__*/_react.default.createElement(_Icon.default, {
            name: "your icon",
            icon: _this2.state.json
          }), /*#__PURE__*/_react.default.createElement(_Icon.default, {
            name: "your icon",
            width: "50",
            height: "50",
            icon: _this2.state.json
          }), /*#__PURE__*/_react.default.createElement(_Icon.default, {
            fill: "#0b77c2",
            name: "your icon",
            width: "100",
            height: "100",
            icon: _this2.state.json
          }))), /*#__PURE__*/_react.default.createElement(_Blockquote.default, {
            title: "Icon json",
            code: true
          }, /*#__PURE__*/_react.default.createElement("code", {
            component: "pre",
            className: "language-json"
          }, JSON.stringify(_this2.state.json, null, 2))), /*#__PURE__*/_react.default.createElement(_Blockquote.default, {
            title: "Component code",
            code: true
          }, /*#__PURE__*/_react.default.createElement("code", {
            component: "pre",
            className: "language-json"
          }, "<Icon \n  icon={".concat(JSON.stringify(_this2.state.json, null, 2), "}\n/>\n")))))));
        }
      }));
    }
  }]);
  return FaviconGenerator;
}(_react.Component);

exports.default = FaviconGenerator;