/*
 * 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 } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
export const Legend = _ref => {
  let {
    metrics,
    health,
    trianglePosition = 'left'
  } = _ref;
  const legendClassName = "celHealthDonutLegend ".concat(trianglePosition === 'right' ? 'celTriangleRight' : 'celTriangleLeft');
  const {
    faults5xxPercent,
    errors4xxPercent,
    ok2xxPercent
  } = 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__*/_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")
      })]
    })
  });
};