/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

import React from 'react';
import { t } from '../../../../shared/i18n/t';
import './legend.scss';
import { BreachedLabel, ErrorsLabel, FaultsLabel, Label, RecoveredLabel, OkLabel } from '../../../labels';
import { useMetricPercentages } from '../../hooks/use_metric_percentages.hook';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
export const Legend = _ref => {
  let metrics = _ref.metrics,
    health = _ref.health,
    _ref$trianglePosition = _ref.trianglePosition,
    trianglePosition = _ref$trianglePosition === void 0 ? 'left' : _ref$trianglePosition;
  const legendClassName = "celHealthDonutLegend ".concat(trianglePosition === 'right' ? 'celTriangleRight' : 'celTriangleLeft');
  const _useMetricPercentages = useMetricPercentages(metrics !== null && metrics !== void 0 ? metrics : {
      requests: 0,
      faults5xx: 0,
      errors4xx: 0
    }),
    faults5xxPercent = _useMetricPercentages.faults5xxPercent,
    errors4xxPercent = _useMetricPercentages.errors4xxPercent,
    ok2xxPercent = _useMetricPercentages.ok2xxPercent;
  const _ref2 = health !== null && health !== void 0 ? health : {
      breached: 0,
      recovered: 0
    },
    breached = _ref2.breached,
    recovered = _ref2.recovered;
  return /*#__PURE__*/_jsx("div", {
    className: legendClassName,
    children: /*#__PURE__*/_jsxs("div", {
      className: "celHealthDonutLegendContent",
      children: [!!faults5xxPercent && /*#__PURE__*/_jsx(FaultsLabel, {
        text: t('healthDonut.legend.faults', {
          value: Math.round(faults5xxPercent)
        })
      }), !!errors4xxPercent && /*#__PURE__*/_jsx(ErrorsLabel, {
        text: t('healthDonut.legend.errors', {
          value: Math.round(errors4xxPercent)
        })
      }), !!ok2xxPercent && /*#__PURE__*/_jsx(OkLabel, {
        text: t('healthDonut.legend.ok', {
          value: Math.round(ok2xxPercent)
        })
      }), !!breached && /*#__PURE__*/_jsx("div", {
        className: "osd:-ml-0.5 osd:-mt-0.5",
        children: /*#__PURE__*/_jsx(BreachedLabel, {
          text: t("healthDonut.legend.sliBreach", {
            value: breached
          })
        })
      }), !!recovered && !breached && /*#__PURE__*/_jsx("div", {
        className: "osd:-ml-0.5 osd:-mt-0.5",
        children: /*#__PURE__*/_jsx(RecoveredLabel, {
          text: t("healthDonut.legend.sliRecovered", {
            value: recovered
          })
        })
      }), !breached && !recovered && !faults5xxPercent && !errors4xxPercent && !ok2xxPercent && /*#__PURE__*/_jsx(Label, {
        text: t("healthDonut.legend.noIssue")
      })]
    })
  });
};