"use client";

import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
import { useEffect, useMemo, useState } from "react";
export function useCircularProgress(_ref) {
  var _ref$value = _ref.value,
    value = _ref$value === void 0 ? 0 : _ref$value,
    _ref$min = _ref.min,
    min = _ref$min === void 0 ? 0 : _ref$min,
    _ref$max = _ref.max,
    max = _ref$max === void 0 ? 100 : _ref$max,
    _ref$variant = _ref.variant,
    variant = _ref$variant === void 0 ? "determinate" : _ref$variant;
  var normalizedValue = useMemo(function () {
    if (variant !== "determinate") return 0;
    return Math.min(Math.max(value, min), max);
  }, [value, min, max, variant]);
  var percentage = useMemo(function () {
    if (variant !== "determinate") return 0;
    return (normalizedValue - min) / (max - min) * 100;
  }, [normalizedValue, min, max, variant]);

  // SSR-safe animated number
  var _useState = useState(normalizedValue),
    _useState2 = _slicedToArray(_useState, 2),
    displayValue = _useState2[0],
    setDisplayValue = _useState2[1];
  useEffect(function () {
    setDisplayValue(normalizedValue);
  }, [normalizedValue]);
  return {
    percentage: percentage,
    displayValue: displayValue
  };
}