"use strict";
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ProgressCircular = exports.ProgressCircularBase = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = require("react");
const box_1 = require("../box");
const core_1 = require("../core");
const t_1 = require("../t");
const utils_1 = require("../utils");
const consts_1 = require("./consts");
exports.ProgressCircularBase = core_1.styled.divBox `
  display: flex;
  position: relative;
  width: 100%;
`;
const MainCircle = core_1.styled.circle `
  fill: transparent;
`;
const ProgressCircle = (0, core_1.styled)(MainCircle) `
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.5s ease-out;
`;
/** Indicates a process progress. */
exports.ProgressCircular = (0, core_1.vui)((props, ref) => {
    const { children, className, label, value = 0, showPercentage } = props, rest = __rest(props, ["children", "className", "label", "value", "showPercentage"]);
    const styles = (0, core_1.useStyleConfig)('ProgressCircular', props);
    const [progress, setProgress] = (0, react_1.useState)(value);
    (0, react_1.useEffect)(() => {
        setProgress(value ? Math.ceil(value) : 0);
    }, [value]);
    (0, react_1.useEffect)(() => {
        const w = !value ? 0 : Math.ceil(value);
        setProgress(w > consts_1.maxValue ? consts_1.maxValue : w);
    }, [value]);
    const radius = consts_1.maxValue / 2 - styles.strokeWidth * 2;
    const angle = radius * 2 * Math.PI;
    const offset = angle - (progress / consts_1.maxValue) * angle;
    return ((0, jsx_runtime_1.jsxs)(exports.ProgressCircularBase, Object.assign({ className: (0, utils_1.cs)('vui-progress-circular', className), ref: ref, w: styles.width }, rest, { children: [(0, jsx_runtime_1.jsxs)("svg", { "aria-valuemax": consts_1.maxValue, "aria-valuemin": 0, "aria-valuenow": progress, height: styles.width, role: "meter", version: "1.1", viewBox: "0 0 100 100", width: styles.width, xmlns: "http://www.w3.org/2000/svg", children: [(0, jsx_runtime_1.jsx)(MainCircle, { cx: "50", cy: "50", r: radius, stroke: styles.stroke.main, strokeWidth: styles.strokeWidth }), (0, jsx_runtime_1.jsx)(ProgressCircle, { cx: "50", cy: "50", r: radius, stroke: styles.stroke.progress, strokeDasharray: `${angle} ${angle}`, strokeDashoffset: offset, strokeWidth: styles.strokeWidth })] }), (0, jsx_runtime_1.jsx)(box_1.Box, Object.assign({}, consts_1.absCenterStyles, { top: styles.top, children: children ? (children) : showPercentage ? ((0, jsx_runtime_1.jsxs)(t_1.T, { color: styles.color, fontSize: styles.fontSize, children: [progress, "%"] })) : null })), !!label && ((0, jsx_runtime_1.jsx)(box_1.Box, Object.assign({}, consts_1.absCenterStyles, { bottom: consts_1.labelBottom, children: (0, jsx_runtime_1.jsx)(t_1.T, { color: styles.color, fontSize: styles.fontSize, children: label }) })))] })));
});
exports.ProgressCircular.displayName = 'ProgressCircular';
exports.default = exports.ProgressCircular;
//# sourceMappingURL=progressCircular.js.map