import { unsafeCSS, LitElement, svg, html } from "lit";
import { property } from "lit/decorators.js";
import componentStyle from "./circular-progress.css.js";
import { customElement } from "../../decorator.js";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result) __defProp(target, key, result);
  return result;
};
var CircularProgressMode = /* @__PURE__ */ ((CircularProgressMode2) => {
  CircularProgressMode2["determinate"] = "determinate";
  CircularProgressMode2["indeterminate"] = "indeterminate";
  CircularProgressMode2["progressiveIndeterminate"] = "progressive-indeterminate";
  return CircularProgressMode2;
})(CircularProgressMode || {});
let ObcCircularProgress = class extends LitElement {
  constructor() {
    super(...arguments);
    this.mode = "indeterminate";
    this.value = 0;
    this.strokeWidth = 4;
    this.viewBoxSize = 42;
    this.padding = 0;
  }
  render() {
    const size = this.viewBoxSize;
    const sw = this.strokeWidth;
    const center = size / 2;
    const radius = Math.max(0, (size - sw) / 2 - this.padding);
    const circumference = 2 * Math.PI * radius;
    const rawValue = Number.isFinite(this.value) ? this.value : 0;
    const clampedValue = Math.max(0, Math.min(100, rawValue));
    let progressElement;
    if (this.mode === "progressive-indeterminate") {
      const minArc = circumference * 0.02;
      const progressiveArcLength = clampedValue >= 100 ? circumference : Math.max(minArc, clampedValue / 100 * circumference * 0.97);
      const progressiveGapLength = circumference - progressiveArcLength;
      progressElement = svg`
        <circle
          class="circular-progress progressive-indeterminate"
          cx="${center}"
          cy="${center}"
          r="${radius}"
          stroke-width="${sw}"
          fill="none"
          stroke-dasharray="${progressiveArcLength} ${progressiveGapLength}"
          transform-origin="${center} ${center}"
        />
      `;
    } else if (this.mode === "determinate") {
      const adjustedValue = clampedValue >= 100 ? 100 : clampedValue * 0.97;
      const strokeDashoffset = circumference - adjustedValue / 100 * circumference;
      progressElement = svg`
        <circle
          class="circular-progress determinate"
          cx="${center}"
          cy="${center}"
          r="${radius}"
          stroke-width="${sw}"
          fill="none"
          stroke-dasharray="${circumference}"
          stroke-dashoffset="${strokeDashoffset}"
          transform="rotate(-90 ${center} ${center})"
        />
      `;
    } else {
      progressElement = svg`
        <circle
          class="circular-progress indeterminate"
          cx="${center}"
          cy="${center}"
          r="${radius}"
          stroke-width="${sw}"
          fill="none"
          stroke-dasharray="${circumference * 0.25} ${circumference * 0.75}"
          transform-origin="${center} ${center}"
        />
      `;
    }
    return html`
      <div class="circular-progress-container">
        <svg
          class="circular-progress-svg"
          viewBox="0 0 ${size} ${size}"
          preserveAspectRatio="xMidYMid meet"
        >
          <circle
            class="circular-background"
            cx="${center}"
            cy="${center}"
            r="${radius}"
            stroke-width="${sw}"
            fill="none"
          />
          ${progressElement}
        </svg>
      </div>
    `;
  }
};
ObcCircularProgress.styles = unsafeCSS(componentStyle);
__decorateClass([
  property({ type: String })
], ObcCircularProgress.prototype, "mode", 2);
__decorateClass([
  property({ type: Number })
], ObcCircularProgress.prototype, "value", 2);
__decorateClass([
  property({ type: Number })
], ObcCircularProgress.prototype, "strokeWidth", 2);
__decorateClass([
  property({ type: Number })
], ObcCircularProgress.prototype, "viewBoxSize", 2);
__decorateClass([
  property({ type: Number })
], ObcCircularProgress.prototype, "padding", 2);
ObcCircularProgress = __decorateClass([
  customElement("obc-circular-progress")
], ObcCircularProgress);
export {
  CircularProgressMode,
  ObcCircularProgress
};
//# sourceMappingURL=circular-progress.js.map
