"use strict";

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

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

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

var _Chip = require("../Chip");

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

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

function getChipsFromSummary(component, summary) {
  if (!summary) {
    return [];
  }

  var chips = [];

  if (summary.healthy > 0) {
    chips.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.Link, {
      to: "/topology/".concat(component.id, "?status=healthy"),
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.Chip, {
        text: summary.healthy,
        label: "Healthy",
        color: "green"
      }, "healthy")
    }, "".concat(component.id, "-healthy")));
  }

  if (summary.unhealthy > 0) {
    chips.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.Link, {
      to: "/topology/".concat(component.id, "?status=unhealthy"),
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.Chip, {
        text: summary.unhealthy,
        label: "Unhealthy",
        color: "red"
      }, "unhealthy")
    }, "".concat(component.id, "-unhealthy")));
  }

  if (summary.warning > 0) {
    chips.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.Link, {
      to: "/topology/".concat(component.id, "?status=warning"),
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.Chip, {
        text: summary.warning,
        label: "Warning",
        color: "orange"
      }, "warning")
    }, "".concat(component.id, "-warning")));
  }

  if (summary.unknown > 0) {
    chips.push( /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactRouterDom.Link, {
      to: "/topology?/".concat(component.id, "?status=unknown"),
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Chip.Chip, {
        text: summary.unknown,
        label: "Unknown",
        color: "gray"
      }, "unknown")
    }, "".concat(component.id, "-unknown")));
  }

  return chips;
}

var HealthSummary = function HealthSummary(_ref) {
  var component = _ref.component,
      iconSize = _ref.iconSize;
  var name = component.name,
      icon = component.icon,
      summary = component.summary;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "flex mb-1.5",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
        name: icon,
        className: "mr-1",
        size: iconSize
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("h5", {
        className: "text-xs linear-1.21rel mr-1",
        children: name
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "flex gap-2 ",
        children: getChipsFromSummary(component, summary)
      })]
    })
  });
};

exports.HealthSummary = HealthSummary;
HealthSummary.propTypes = {
  iconSize: _propTypes.default.string,
  component: _propTypes.default.shape({}).isRequired
};
HealthSummary.defaultProps = {
  iconSize: "sm"
};