"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.HealthDonut = exports.HEALTH_DONUT_TEST_ID = void 0;
var _react = _interopRequireDefault(require("react"));
var _use_element_hover = require("../../shared/hooks/use_element_hover.hook");
var _use_donut_segments = require("./hooks/use_donut_segments.hook");
var _use_icon_sizing = require("./hooks/use_icon_sizing.hook");
var _sli_status_icon = require("../sli_status_icon/sli_status_icon");
require("./styles.scss");
var _use_health_status_colors = require("./hooks/use_health_status_colors.hook");
var _absolute_position = require("./components/absolute_position");
var _donut = require("../donut");
var _constants = require("./constants");
var _legend = require("./components/legend");
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 HEALTH_DONUT_TEST_ID = exports.HEALTH_DONUT_TEST_ID = 'health-donut';
const HealthDonut = ({
  metrics,
  health,
  size,
  icon,
  status,
  isLegendEnabled,
  children
}) => {
  const {
    isHovered: isVisible,
    ...rest
  } = (0, _use_element_hover.useElementHover)();
  const iconSizes = (0, _use_icon_sizing.useIconSizing)(size);
  const segments = (0, _use_donut_segments.useDonutSegments)(metrics);
  const colors = (0, _use_health_status_colors.useHealthStatusColors)(status);
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
    "data-test-subj": HEALTH_DONUT_TEST_ID,
    className: "celHealthDonut",
    style: {
      width: size,
      height: size
    },
    ...(isLegendEnabled ? rest : {}),
    children: [((health === null || health === void 0 ? void 0 : health.status) === 'breached' || (health === null || health === void 0 ? void 0 : health.status) === 'recovered') && /*#__PURE__*/(0, _jsxRuntime.jsx)(_absolute_position.AbsolutePosition, {
      left: "-8%",
      top: "-8%",
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_sli_status_icon.SliStatusIcon, {
        status: health.status,
        size: iconSizes.sliStatusIconSize,
        isPulsing: true
      })
    }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_donut.Donut, {
      diameter: size,
      iconSize: iconSizes.centerIconSize,
      segments: segments,
      isInverted: status !== undefined && status !== _constants.HEALTH_DONUT_STATUS.OK,
      fill: colors.fill,
      stroke: colors.stroke,
      children: icon
    }), isLegendEnabled && isVisible && /*#__PURE__*/(0, _jsxRuntime.jsx)(_legend.Legend, {
      metrics: metrics,
      health: health
    }), children]
  });
};
exports.HealthDonut = HealthDonut;