"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Legend = void 0;
var _react = _interopRequireDefault(require("react"));
var _t = require("../../../../shared/i18n/t");
require("./legend.scss");
var _labels = require("../../../labels");
var _use_metric_percentages = require("../../hooks/use_metric_percentages.hook");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

const Legend = ({
  metrics,
  health,
  trianglePosition = 'left'
}) => {
  const legendClassName = `celHealthDonutLegend ${trianglePosition === 'right' ? 'celTriangleRight' : 'celTriangleLeft'}`;
  const {
    faults5xxPercent,
    errors4xxPercent,
    ok2xxPercent
  } = (0, _use_metric_percentages.useMetricPercentages)(metrics !== null && metrics !== void 0 ? metrics : {
    requests: 0,
    faults5xx: 0,
    errors4xx: 0
  });
  const {
    breached,
    recovered
  } = health !== null && health !== void 0 ? health : {
    breached: 0,
    recovered: 0
  };
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: legendClassName,
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
      className: "celHealthDonutLegendContent",
      children: [!!faults5xxPercent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_labels.FaultsLabel, {
        text: (0, _t.t)('healthDonut.legend.faults', {
          value: Math.round(faults5xxPercent)
        })
      }), !!errors4xxPercent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_labels.ErrorsLabel, {
        text: (0, _t.t)('healthDonut.legend.errors', {
          value: Math.round(errors4xxPercent)
        })
      }), !!ok2xxPercent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_labels.OkLabel, {
        text: (0, _t.t)('healthDonut.legend.ok', {
          value: Math.round(ok2xxPercent)
        })
      }), !!breached && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "osd:-ml-0.5 osd:-mt-0.5",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_labels.BreachedLabel, {
          text: (0, _t.t)(`healthDonut.legend.sliBreach`, {
            value: breached
          })
        })
      }), !!recovered && !breached && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: "osd:-ml-0.5 osd:-mt-0.5",
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_labels.RecoveredLabel, {
          text: (0, _t.t)(`healthDonut.legend.sliRecovered`, {
            value: recovered
          })
        })
      }), !breached && !recovered && !faults5xxPercent && !errors4xxPercent && !ok2xxPercent && /*#__PURE__*/(0, _jsxRuntime.jsx)(_labels.Label, {
        text: (0, _t.t)(`healthDonut.legend.noIssue`)
      })]
    })
  });
};
exports.Legend = Legend;