import { jsxs, jsx } from 'react/jsx-runtime';
import { forwardRef, useId, isValidElement } from 'react';
import { c as cx } from './index-De1g9FRV.js';
import { S as SvgCheckCircle } from './check_circle-CM0ukqXv.js';
import { S as SvgError } from './error-DR_wWdYY.js';
import { F as FieldLabel } from './FieldLabel-DZWu5dMp.js';
import { F as Flex } from './Flex-DOUtHiPi.js';
import { w as warnDeprecatedErrorUsage } from './utils-CM48ODEJ.js';
import { I as Icon } from './Icon-BMMbp40n.js';
import { u as useLayoutPropsUtil } from './useLayoutPropsUtil-CB_zHDbW.js';
import { H as Helper } from './Helper-DtDeaYTn.js';

import './ProgressBar.css';const indeterminate = "_indeterminate_r8r5u_1";
const bar = "_bar_r8r5u_21";
const success = "_success_r8r5u_65";
const error = "_error_r8r5u_61";
const styles = {
	indeterminate: indeterminate,
	"progress-bar": "_progress-bar_r8r5u_1",
	"bar-container": "_bar-container_r8r5u_21",
	bar: bar,
	"check-icon": "_check-icon_r8r5u_57",
	"error-icon": "_error-icon_r8r5u_61",
	success: success,
	error: error
};

const ProgressBar = forwardRef(
  (props, ref) => {
    const { layoutStyles, componentProps } = useLayoutPropsUtil(props);
    const {
      className,
      style,
      value,
      children,
      indeterminate,
      errorAriaLive,
      description,
      warning,
      error = false,
      max = 100,
      ...mainProps
    } = componentProps;
    const styleCombined = {
      ...style,
      ...layoutStyles
    };
    warnDeprecatedErrorUsage("ProgressBar", error);
    const errorMessages = typeof error === "boolean" || error === void 0 ? void 0 : error;
    const labelUid = useId();
    const isSuccess = typeof value !== "undefined" && +value >= +max;
    if ("label" in props && !!props.label) {
      const { label, labelProps, ...rest } = mainProps;
      const ProgressBarClassNames2 = cx(
        [styles["progress-bar"]],
        className,
        {
          [styles[`error`]]: error,
          [styles[`success`]]: isSuccess
        }
      );
      return /* @__PURE__ */ jsxs(
        "div",
        {
          className: ProgressBarClassNames2,
          "data-anv": "progress-bar",
          style: styleCombined,
          ref,
          children: [
            /* @__PURE__ */ jsxs(Flex, { justifyContent: "space-between", alignItems: "center", children: [
              /* @__PURE__ */ jsx(FieldLabel, { id: labelUid, ...labelProps, children: label }),
              isSuccess && !error ? /* @__PURE__ */ jsx(Icon, { className: styles["check-icon"], svg: SvgCheckCircle }) : null,
              error ? /* @__PURE__ */ jsx(Icon, { className: styles["error-icon"], svg: SvgError }) : null
            ] }),
            /* @__PURE__ */ jsx("div", { className: styles["bar-container"], children: /* @__PURE__ */ jsx(
              "progress",
              {
                "aria-labelledby": labelUid,
                className: styles["bar"],
                value,
                max,
                ...rest
              }
            ) }),
            errorMessages || warning || description ? /* @__PURE__ */ jsx(
              Helper,
              {
                error: typeof errorMessages === "string" || Array.isArray(errorMessages) ? errorMessages : void 0,
                warning,
                errorMessage: isValidElement(errorMessages) ? errorMessages : void 0,
                description
              }
            ) : null
          ]
        }
      );
    }
    const ProgressBarClassNames = cx([styles["progress-bar"]], className, {
      [styles[`error`]]: error,
      [styles[`success`]]: isSuccess
    });
    return /* @__PURE__ */ jsxs(
      "div",
      {
        className: ProgressBarClassNames,
        "data-anv": "progress-bar",
        style: styleCombined,
        ref,
        children: [
          /* @__PURE__ */ jsx("div", { className: styles["bar-container"], children: /* @__PURE__ */ jsx(
            "progress",
            {
              className: styles["bar"],
              max,
              value,
              ...mainProps
            }
          ) }),
          errorMessages || warning || description ? /* @__PURE__ */ jsx(
            Helper,
            {
              error: typeof errorMessages === "string" || Array.isArray(errorMessages) ? errorMessages : void 0,
              warning,
              errorMessage: isValidElement(errorMessages) ? errorMessages : void 0,
              description
            }
          ) : null
        ]
      }
    );
  }
);
ProgressBar.displayName = "ProgressBar";

export { ProgressBar as P };
//# sourceMappingURL=ProgressBar-DSrjgLTx.js.map
