"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: !0
}), exports.getEleNode = exports.commonAddNodeAndConn = exports.commonAddNode = exports.addTrigerEleAndConn = exports.addTrigerAndAction = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")), _amosJsplumb = require("amos-jsplumb"), _stageConf = require("./modelConf/stageConf");

function ownKeys(e, o) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var r = Object.getOwnPropertySymbols(e);
    o && (r = r.filter((function(o) {
      return Object.getOwnPropertyDescriptor(e, o).enumerable;
    }))), t.push.apply(t, r);
  }
  return t;
}

function _objectSpread(e) {
  for (var o = 1; o < arguments.length; o++) {
    var t = null != arguments[o] ? arguments[o] : {};
    o % 2 ? ownKeys(Object(t), !0).forEach((function(o) {
      (0, _defineProperty2.default)(e, o, t[o]);
    })) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach((function(o) {
      Object.defineProperty(e, o, Object.getOwnPropertyDescriptor(t, o));
    }));
  }
  return e;
}

var commonAddNode = function(e) {
  var o = e.eleType, t = e.labelValue, r = e.position, n = e.ruleNodeId;
  return {
    config: {
      label: t,
      nodeType: o,
      type: (0, _stageConf.typeValue)(o),
      ruleNodeId: n,
      style: _objectSpread({}, r)
    },
    id: _amosJsplumb.tools.uuid()
  };
};

exports.commonAddNode = commonAddNode;

var commonAddNodeAndConn = function(e) {
  var o = e.eleType, t = e.labelValue, r = e.position, n = e.sourceId, d = _amosJsplumb.tools.uuid();
  return {
    node: {
      config: {
        label: t,
        nodeType: o,
        type: (0, _stageConf.typeValue)(o),
        style: _objectSpread({}, r)
      },
      id: d
    },
    conn: {
      sourceId: n,
      targetId: d
    }
  };
};

exports.commonAddNodeAndConn = commonAddNodeAndConn;

var addTrigerEleAndConn = function(e) {
  var o = e.labelValue, t = e.position, r = e.statusId, n = _amosJsplumb.tools.uuid();
  return {
    node: {
      config: {
        label: o,
        type: "trigger",
        nodeType: "trigger",
        style: _objectSpread({}, t)
      },
      id: n
    },
    conn: {
      sourceId: r,
      targetId: n
    }
  };
};

exports.addTrigerEleAndConn = addTrigerEleAndConn;

var addTrigerAndAction = function(e) {
  var o = e.labelValue, t = e.position, r = e.statusId, n = _amosJsplumb.tools.uuid(), d = _amosJsplumb.tools.uuid(), i = {
    left: t.left + _stageConf.stagePosition.spaceX * _stageConf.stagePosition.ratio_3,
    top: t.top
  };
  return {
    node: [ {
      id: n,
      config: {
        label: o,
        nodeType: "trigger",
        type: "both",
        style: _objectSpread({}, t)
      }
    }, {
      id: d,
      config: {
        label: "动作",
        nodeType: "flowAction",
        type: "both",
        style: _objectSpread({}, i)
      }
    } ],
    conn: [ {
      sourceId: r,
      targetId: n
    }, {
      sourceId: n,
      targetId: d
    } ]
  };
};

exports.addTrigerAndAction = addTrigerAndAction;

var getEleNode = function e(o) {
  if (o) return (o.className || "").indexOf("ele") > -1 ? o : e(o.parentNode);
};

exports.getEleNode = getEleNode;