"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.Progress = exports.ProgressBase = 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 utils_1 = require("../utils");
exports.ProgressBase = core_1.styled.divBox `
  display: flex;
  width: 100%;
`;
const minPercentageDisplay = 3;
const maxValue = 100;
/** Indicates a process progress. */
exports.Progress = (0, core_1.vui)((props, ref) => {
    const { className, value = 0, showPercentage } = props, rest = __rest(props, ["className", "value", "showPercentage"]);
    const [width, setWidth] = (0, react_1.useState)(0);
    const styles = (0, core_1.useStyleConfig)('Progress', props);
    (0, react_1.useEffect)(() => {
        const w = !value ? 0 : Math.ceil(value);
        setWidth(w > maxValue ? maxValue : w);
    }, [value]);
    const bg = rest.bg || styles.bg;
    const color = rest.color || styles.color;
    return ((0, jsx_runtime_1.jsx)(exports.ProgressBase, Object.assign({ className: (0, utils_1.cs)('vui-progress', className), ref: ref }, styles.container, rest, { bg: bg, borderRadius: "sm", h: 1, children: (0, jsx_runtime_1.jsx)(box_1.Box, { bg: color, borderRadius: "sm", position: "relative", textAlign: "right", transition: "width 0.4s ease-in-out;", w: `${width}%`, children: showPercentage && value >= minPercentageDisplay && ((0, jsx_runtime_1.jsx)(box_1.Box, Object.assign({}, styles.percentage, { position: "absolute", right: "0", children: `${width}%` }))) }) })));
});
exports.Progress.displayName = 'Progress';
exports.default = exports.Progress;
//# sourceMappingURL=progress.js.map