'use strict';

var React = require('react');
var classnames = require('classnames');

var styles = {"indicator":"-TBRV1VUsfc-","smaller":"MStgN8AhV3s-","small":"iAlYWHjs6JQ-","base":"WWEzA1-OjSM-","continuous":"r9ShSj58V6w-","fill":"Hsuq8zT-KzY-","stepped":"FB1e9bL90tI-","segment":"bpLIiDGlsCs-","filled":"_0FxmImvY-04-","spinning":"_2aJghEPvl14-"};

/**
 * `ProgressIndicator` communicates **determinate** progress — a known fraction
 * of a task that has been completed. Use it when you can express progress as
 * `value / max`, such as a multi-step setup wizard or a file upload with a
 * known total size.
 *
 * For indeterminate activity (loading time or fraction unknown), use
 * `ActivityIndicator` instead.
 *
 * For now, the legacy `ProgressBar` component also remains available; new code
 * should prefer `ProgressIndicator`.
 */
function ProgressIndicator({ value, max = 100, variation = "continuous", size = "base", ariaLabel, className, style, }) {
    const clampedValue = Math.min(value, max);
    const resolvedAriaLabel = ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : defaultAriaLabel(clampedValue, max);
    return (React.createElement("div", { role: "progressbar", "aria-valuenow": clampedValue, "aria-valuemin": 0, "aria-valuemax": max, "aria-label": resolvedAriaLabel, className: classnames(styles.indicator, styles[size], variation === "stepped" ? styles.stepped : styles.continuous, className), style: style }, variation === "stepped"
        ? SteppedSegments({ value: clampedValue, max })
        : ContinuousFill({ value: clampedValue, max })));
}
function ContinuousFill({ value, max, }) {
    const percentage = max === 0 ? 0 : (value / max) * 100;
    return (React.createElement("div", { className: styles.fill, style: { "--progress-indicator--fill-amount": percentage } }));
}
function SteppedSegments({ value, max, }) {
    return (React.createElement(React.Fragment, null, Array.from({ length: max }).map((_, index) => {
        const step = index + 1;
        return (React.createElement("div", { key: step, className: classnames(styles.segment, step <= value && styles.filled) }));
    })));
}
function defaultAriaLabel(value, max) {
    if (max === 100)
        return `${value}%`;
    return `${value} / ${max}`;
}

exports.ProgressIndicator = ProgressIndicator;
