"use strict";

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

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

var _CardContainer = _interopRequireDefault(require("./CardContainer"));

var _BlockContainer = _interopRequireDefault(require("./BlockContainer"));

var _reactGridSystem = require("react-grid-system");

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

var _GridProvider = _interopRequireDefault(require("./GridProvider"));

var _reactDndMultiBackend = _interopRequireDefault(require("react-dnd-multi-backend"));

var _HTML5toTouch = _interopRequireDefault(require("react-dnd-multi-backend/dist/esm/HTML5toTouch"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

// or any other pipeline
var CodeCardEditor = (0, _react.forwardRef)(function (_ref, ref) {
  var _ref$codeCards = _ref.codeCards,
      codeCards = _ref$codeCards === void 0 ? [] : _ref$codeCards,
      _ref$style = _ref.style,
      style = _ref$style === void 0 ? {} : _ref$style,
      _ref$extra = _ref.extra,
      extra = _ref$extra === void 0 ? [] : _ref$extra;

  var _style$editorTitle = style.editorTitle,
      editorTitle = _style$editorTitle === void 0 ? {
    padding: 10,
    backgroundColor: 'black',
    borderTopLeftRadius: 10,
    borderTopRightRadius: 10,
    color: 'white'
  } : _style$editorTitle,
      _style$codeCardContai = style.codeCardContainerStyle,
      codeCardContainerStyle = _style$codeCardContai === void 0 ? {
    backgroundColor: 'rgba(0,0,0,0.8)',
    borderBottomLeftRadius: 10,
    border: '1px solid rgba(200,200,200,1)',
    padding: 10
  } : _style$codeCardContai,
      _style$blockContainer = style.blockContainerStyle,
      blockContainerStyle = _style$blockContainer === void 0 ? {
    backgroundColor: 'rgba(0,0,0,0.5)',
    borderTopRightRadius: 10,
    borderBottomRightRadius: 10,
    border: '1px solid rgba(200,200,200,1)',
    borderLeft: 'none',
    padding: 10
  } : _style$blockContainer,
      restStyle = _objectWithoutProperties(style, ["editorTitle", "codeCardContainerStyle", "blockContainerStyle"]);

  var _useState = (0, _react.useState)(''),
      _useState2 = _slicedToArray(_useState, 2),
      code = _useState2[0],
      setcode = _useState2[1];

  var blockContainerRef = (0, _react.useRef)();

  var handleDragEnd = function handleDragEnd(items) {
    console.log(items);
    var codes = items.map(function (item) {
      return item.code ? item.code() : '';
    });
    var code = codes.join("\r\n");
    console.log(code);
    setcode(code);
  };

  (0, _react.useImperativeHandle)(ref, function () {
    return {
      getCode: function getCode() {
        return code;
      },
      clear: function clear() {
        return blockContainerRef.current.clear();
      }
    };
  });
  return _react["default"].createElement(_reactDnd.DndProvider, {
    backend: _reactDndMultiBackend["default"],
    options: _HTML5toTouch["default"]
  }, _react["default"].createElement(_reactGridSystem.Container, null, _react["default"].createElement(_reactGridSystem.Row, {
    gutterWidth: 5
  }, _react["default"].createElement(_reactGridSystem.Col, {
    style: editorTitle,
    xs: 6
  }, "Edit: Path")), _react["default"].createElement(_reactGridSystem.Row, {
    gutterWidth: 5
  }, _react["default"].createElement(_reactGridSystem.Col, {
    width: 120,
    style: codeCardContainerStyle
  }, _react["default"].createElement("div", {
    style: {
      flexDirection: 'column',
      display: 'flex',
      height: '100%',
      justifyContent: 'space-between'
    }
  }, _react["default"].createElement(_CardContainer["default"], {
    codeCards: codeCards
  }), extra)), _react["default"].createElement(_reactGridSystem.Col, {
    style: blockContainerStyle
  }, _react["default"].createElement(_GridProvider["default"], null, _react["default"].createElement(_BlockContainer["default"], {
    height: 300,
    onDragEnd: handleDragEnd,
    ref: blockContainerRef
  }))))));
});
var _default = CodeCardEditor;
exports["default"] = _default;