"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/components/Progress/index.tsx
var Progress_exports = {};
__export(Progress_exports, {
  Progress: () => Progress
});
module.exports = __toCommonJS(Progress_exports);

// src/components/Progress/Progress.tsx
var import_dedupe2 = __toESM(require("classnames/dedupe"));
var import_react = require("react");

// src/components/Label/Label.tsx
var import_dedupe = __toESM(require("classnames/dedupe"));
var import_Label = require("@simplybusiness/mobius/src/components/Label/Label.css");
var import_jsx_runtime = require("react/jsx-runtime");
var Label = ({ ref, ...props }) => {
  const { elementType: Element = "label", children, ...otherProps } = props;
  const classes = (0, import_dedupe.default)("mobius", "mobius-label", props.className);
  otherProps.className = classes;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Element, { ref, ...otherProps, className: classes, children });
};
Label.displayName = "Label";

// src/components/VisuallyHidden/VisuallyHidden.tsx
var import_jsx_runtime2 = require("react/jsx-runtime");
function VisuallyHidden(props) {
  const {
    className,
    children,
    elementType: Component = "div",
    ...otherProps
  } = props;
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
    Component,
    {
      className,
      style: {
        border: 0,
        clip: "rect(0 0 0 0)",
        clipPath: "inset(50%)",
        height: "1px",
        margin: "-1px",
        overflow: "hidden",
        padding: 0,
        position: "absolute",
        width: "1px",
        whiteSpace: "nowrap"
      },
      ...otherProps,
      children
    }
  );
}

// src/components/Progress/Progress.tsx
var import_Progress = require("@simplybusiness/mobius/src/components/Progress/Progress.css");
var import_jsx_runtime3 = require("react/jsx-runtime");
function warnAboutInvalidValues(value, minValue, maxValue) {
  if (minValue > maxValue) {
    console.warn("minValue is greater than maxValue");
  }
  if (value < minValue) {
    console.warn("Progress value is less than minValue");
  }
  if (value > maxValue) {
    console.warn("Progress value is greater than maxValue");
  }
}
var sanitizedValue = (value, defaultValue) => {
  if (value === void 0 || Number.isNaN(value)) {
    return defaultValue;
  }
  return value;
};
var getLabelComponent = (label, progressLabelId, showLabel) => {
  if (showLabel) {
    return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
      Label,
      {
        id: progressLabelId,
        className: "mobius-progress__label",
        elementType: "span",
        children: label
      }
    );
  }
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(VisuallyHidden, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
    Label,
    {
      id: progressLabelId,
      className: "mobius-progress__label",
      elementType: "span",
      children: label
    }
  ) });
};
var DEFAULT_VALUE = 0;
var DEFAULT_MIN_VALUE = 0;
var DEFAULT_MAX_VALUE = 100;
var Progress = ({ ref, ...props }) => {
  const progressId = (0, import_react.useId)();
  const progressLabelId = (0, import_react.useId)();
  const {
    id,
    label,
    showLabel = true,
    showValueLabel = !!label,
    valueFormatter,
    variant = "primary",
    className
  } = props;
  let { value, minValue, maxValue } = props;
  value = sanitizedValue(value, DEFAULT_VALUE);
  minValue = sanitizedValue(minValue, DEFAULT_MIN_VALUE);
  maxValue = sanitizedValue(maxValue, DEFAULT_MAX_VALUE);
  if (value === void 0 || minValue === void 0 || maxValue === void 0) {
    return null;
  }
  warnAboutInvalidValues(value, minValue, maxValue);
  const clamp = (num, min, max) => Math.min(Math.max(num, min), max);
  const percentage = clamp(
    Math.round((value - minValue) / (maxValue - minValue) * 100),
    0,
    100
  );
  const barWidth = `${percentage}%`;
  const classes = (0, import_dedupe2.default)("mobius", "mobius-progress", className, {
    "--is-primary": variant === "primary",
    "--is-secondary": variant === "secondary"
  });
  const progressBarProps = {};
  progressBarProps["aria-valuemin"] = minValue.toString();
  progressBarProps["aria-valuemax"] = maxValue.toString();
  progressBarProps["aria-valuenow"] = value.toString();
  progressBarProps["aria-valuetext"] = valueFormatter instanceof Function ? valueFormatter(value, minValue, maxValue) : barWidth;
  const labelComponent = getLabelComponent(label, progressLabelId, showLabel);
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
    "div",
    {
      id: id || progressId,
      ...progressBarProps,
      ref,
      className: classes,
      role: "progressbar",
      "aria-labelledby": progressLabelId,
      children: [
        labelComponent,
        /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "mobius-progress__track", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "mobius-progress__bar", style: { width: barWidth } }) }),
        showValueLabel && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Label, { "data-testid": "value-label", elementType: "span", children: progressBarProps["aria-valuetext"] })
      ]
    }
  );
};
Progress.displayName = "Progress";
//# sourceMappingURL=index.js.map
