"use strict";

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

var _reactRouterDom = require("react-router-dom");

var _react = require("react");

var _lodash = require("lodash");

var _topology2 = require("../../api/services/topology");

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

var _Loading = require("../Loading");

var _jsxRuntime = require("react/jsx-runtime");

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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 isTopologyEmpty(topology) {
  return topology == null || (0, _lodash.isEmpty)(topology.id) && topology.components.length === 0;
}

function TopologyBreadcrumbs(_ref) {
  var topology = _ref.topology,
      topologyId = _ref.topologyId;

  var _useState = (0, _react.useState)(topology),
      _useState2 = _slicedToArray(_useState, 2),
      _topology = _useState2[0],
      setTopology = _useState2[1];

  (0, _react.useEffect)(function () {
    if ((0, _lodash.isEmpty)(topologyId) && isTopologyEmpty(_topology)) {
      return;
    }

    if (topologyId != null && _topology == null) {
      (0, _topology2.getTopology)({
        id: topologyId
      }).then(function (results) {
        setTopology(results.data[0]);
      });
    }
  }, [_topology, topologyId]);

  if (_topology == null && (0, _lodash.isEmpty)(topologyId)) {
    return "";
  }

  if (_topology == null) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Loading.Loading, {
      text: ".."
    });
  }

  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
    children: ["\xA0/\xA0", /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactRouterDom.Link, {
      to: "/topology/".concat(_topology.id),
      className: "flex flex-nowrap hover:text-gray-500 my-auto ",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
        name: _topology.icon,
        size: "xl",
        className: "mr-1"
      }), _topology.name || _topology.title]
    })]
  });
}