"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.useCelestialNodes = void 0;
var _react = require("@xyflow/react");
var _react2 = require("react");
var _celestial_node = require("../transformers/celestial_node.transformer");
var _topology_node = require("../models/topology_node.model");
var _celestial_node2 = require("../utils/celestial_node.utils");
/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

const useCelestialNodes = data => (0, _react2.useMemo)(() => {
  var _data$Edges2;
  const nodes = data.Nodes.map((node, idx) => {
    var _data$Edges;
    const position = (0, _celestial_node2.calculatePosition)(idx, _celestial_node2.DEFAULT_GRID_CONFIG);
    const enhancedNode = {
      ...node,
      DependencyTypes: (0, _celestial_node2.computeDependencyTypes)(node, (_data$Edges = data.Edges) !== null && _data$Edges !== void 0 ? _data$Edges : [], data.Nodes)
    };
    const model = new _topology_node.TopologyNodeModel(enhancedNode);
    return {
      id: node.NodeId,
      type: 'celestialNode',
      position,
      data: new _celestial_node.TopologyNodeTransformer(model).toCelestialCard(),
      selectable: true,
      deletable: false
    };
  });
  const edges = ((_data$Edges2 = data.Edges) !== null && _data$Edges2 !== void 0 ? _data$Edges2 : []).map(edge => ({
    id: edge.EdgeId,
    source: edge.SourceNodeId,
    target: edge.DestinationNodeId,
    sourceHandle: 'source-right',
    targetHandle: 'target-left',
    markerEnd: {
      type: _react.MarkerType.ArrowClosed
    },
    style: {
      strokeWidth: 2
    },
    type: 'bezier',
    data: {
      relationship: 'Invoke',
      statistics: edge.StatisticReferences
    }
  })) || [];
  return {
    nodes,
    edges
  };
}, [data]);
exports.useCelestialNodes = useCelestialNodes;