"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const util = require("../../../../../../zrender@5.4.4/node_modules/zrender/lib/core/util.js");
const SeriesData = require("../../data/SeriesData.js");
const Graph = require("../../data/Graph.js");
const linkSeriesData = require("../../data/helper/linkSeriesData.js");
const createDimensions = require("../../data/helper/createDimensions.js");
const CoordinateSystem = require("../../core/CoordinateSystem.js");
const createSeriesData = require("./createSeriesData.js");
const model = require("../../util/model.js");
function createGraphFromNodeEdge(nodes, edges, seriesModel, directed, beforeLink) {
  var graph = new Graph.default(directed);
  for (var i = 0; i < nodes.length; i++) {
    graph.addNode(util.retrieve(
      // Id, name, dataIndex
      nodes[i].id,
      nodes[i].name,
      i
    ), i);
  }
  var linkNameList = [];
  var validEdges = [];
  var linkCount = 0;
  for (var i = 0; i < edges.length; i++) {
    var link = edges[i];
    var source = link.source;
    var target = link.target;
    if (graph.addEdge(source, target, linkCount)) {
      validEdges.push(link);
      linkNameList.push(util.retrieve(model.convertOptionIdName(link.id, null), source + " > " + target));
      linkCount++;
    }
  }
  var coordSys = seriesModel.get("coordinateSystem");
  var nodeData;
  if (coordSys === "cartesian2d" || coordSys === "polar") {
    nodeData = createSeriesData.default(nodes, seriesModel);
  } else {
    var coordSysCtor = CoordinateSystem.default.get(coordSys);
    var coordDimensions = coordSysCtor ? coordSysCtor.dimensions || [] : [];
    if (util.indexOf(coordDimensions, "value") < 0) {
      coordDimensions.concat(["value"]);
    }
    var dimensions = createDimensions.default(nodes, {
      coordDimensions,
      encodeDefine: seriesModel.getEncode()
    }).dimensions;
    nodeData = new SeriesData.default(dimensions, seriesModel);
    nodeData.initData(nodes);
  }
  var edgeData = new SeriesData.default(["value"], seriesModel);
  edgeData.initData(validEdges, linkNameList);
  beforeLink && beforeLink(nodeData, edgeData);
  linkSeriesData.default({
    mainData: nodeData,
    struct: graph,
    structAttr: "graph",
    datas: {
      node: nodeData,
      edge: edgeData
    },
    datasAttr: {
      node: "data",
      edge: "edgeData"
    }
  });
  graph.update();
  return graph;
}
exports.default = createGraphFromNodeEdge;
