const _excluded = ["segments", "diameter", "strokeWidth"];
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
/*
 * Copyright OpenSearch Contributors
 * SPDX-License-Identifier: Apache-2.0
 */

import React from 'react';
import { jsx as _jsx } from "react/jsx-runtime";
/**
 * SVG arc segments rendered around a circle.
 * Each segment's arc length is proportional to its value / total.
 */
export const HealthArc = _ref => {
  var _rest$ariaLabel;
  let {
      segments,
      diameter,
      strokeWidth = 6
    } = _ref,
    rest = _objectWithoutProperties(_ref, _excluded);
  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__*/_jsx("svg", {
      width: diameter,
      height: diameter,
      role: "img",
      "aria-label": ariaLabel,
      children: /*#__PURE__*/_jsx("circle", {
        cx: center,
        cy: center,
        r: radius,
        fill: "none",
        stroke: "var(--osd-color-cl-gray-350)",
        strokeWidth: strokeWidth
      })
    });
  }
  let cumulativeOffset = 0;
  return /*#__PURE__*/_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__*/_jsx("circle", {
        cx: center,
        cy: center,
        r: radius,
        fill: "none",
        stroke: segment.color,
        strokeWidth: strokeWidth,
        strokeDasharray: "".concat(segmentLength, " ").concat(gap),
        strokeDashoffset: offset,
        strokeLinecap: "butt",
        style: {
          transition: 'stroke-dasharray 0.3s ease'
        }
      }, i);
    })
  });
};