import { dynamic } from "@solidjs/web";
import { omit } from "solid-js";
import { mergeRootProps } from "../../internals/merge-root-props.jsx";
import { resolveClassStyle } from "../../internals/resolve-class-style.jsx";
import { valueToPercent } from "../../internals/value-to-percent.jsx";
import { useProgressRootContext } from "../progress-root-context.jsx";
/**
 * Visualizes the completion status of the task. Renders a `<div>` (or `as`
 * override).
 */
export function ProgressIndicator(props) {
  const context = useProgressRootContext();
  const style = () => {
    const v = context.value();
    if (v == null || !Number.isFinite(v)) return undefined;
    const pct = valueToPercent(v, context.min(), context.max());
    return {
      "inset-inline-start": 0,
      height: "inherit",
      width: `${pct}%`
    };
  };

  // Resolve `class`/`style` so function values (stateful styling) are invoked
  // with the progress state instead of being spread to the DOM raw. The
  // internal `style` (the indicator width) is merged first below, so a
  // user-supplied style composes with it rather than replacing the width.
  const userClassStyle = resolveClassStyle(props, () => ({
    status: context.status()
  }));
  const userProps = omit(props, "as", "class", "style", "attrs");
  const internalSlot = {
    get style() {
      return style();
    },
    get "data-indeterminate"() {
      return context.status() === "indeterminate" ? "" : undefined;
    },
    get "data-progressing"() {
      return context.status() === "progressing" ? "" : undefined;
    },
    get "data-complete"() {
      return context.status() === "complete" ? "" : undefined;
    }
  };
  let merged = mergeRootProps(internalSlot, userClassStyle);
  merged = mergeRootProps(merged, userProps);
  const Tag = dynamic(() => props.as ?? "div");
  return <Tag {...merged} />;
}
//# sourceMappingURL=progress-indicator.jsx.map
