"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.HealthArc = void 0;
var _react = _interopRequireDefault(require("react"));
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
 */

/**
 * SVG arc segments rendered around a circle.
 * Each segment's arc length is proportional to its value / total.
 */
const HealthArc = ({
  segments,
  diameter,
  strokeWidth = 6,
  ...rest
}) => {
  var _rest$ariaLabel;
  const ariaLabel = (_rest$ariaLabel = rest['aria-label']) !== null && _rest$ariaLabel !== void 0 ? _rest$ariaLabel : 'Health arc';
  const radius = (diameter - strokeWidth) / 2;
  const circumference = 2 * Math.PI * radius;
  const total = segments.reduce((sum, s) => sum + s.value, 0);
  const center = diameter / 2;
  if (total === 0) {
    return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
      width: diameter,
      height: diameter,
      role: "img",
      "aria-label": ariaLabel,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", {
        cx: center,
        cy: center,
        r: radius,
        fill: "none",
        stroke: "var(--osd-color-cl-gray-350)",
        strokeWidth: strokeWidth
      })
    });
  }
  let cumulativeOffset = 0;
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("svg", {
    width: diameter,
    height: diameter,
    role: "img",
    "aria-label": ariaLabel,
    children: segments.map((segment, i) => {
      if (segment.value <= 0) return null;
      const segmentLength = segment.value / total * circumference;
      const gap = circumference - segmentLength;
      const offset = -cumulativeOffset + circumference / 4;
      cumulativeOffset += segmentLength;
      return /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", {
        cx: center,
        cy: center,
        r: radius,
        fill: "none",
        stroke: segment.color,
        strokeWidth: strokeWidth,
        strokeDasharray: `${segmentLength} ${gap}`,
        strokeDashoffset: offset,
        strokeLinecap: "butt",
        style: {
          transition: 'stroke-dasharray 0.3s ease'
        }
      }, i);
    })
  });
};
exports.HealthArc = HealthArc;