import { n as l, C as h } from "../chunks/lib-cortex-element.CVMmyPMC.js";
import { c as y } from "../chunks/component.styles.CRO4Odto.js";
import { U as r, D as u, L as D, F as d, g as S, f as F, c as U, a as g, S as _ } from "../chunks/time.CfxDkxSY.js";
import { c as b } from "../chunks/custom-element.L4WJXn1j.js";
import { L as N } from "../chunks/i18n.BABe9hN4.js";
import { w as m } from "../chunks/watch.BCJD77bD.js";
import { i as L, x as f } from "../chunks/lit-element.jLBm65_O.js";
import { r as M } from "../chunks/state.CSDxrqLd.js";
const T = L`:host{display:contents}.format-time{color:var(--cx-format-time-color,inherit);font-size:var(--cx-format-time-font-size,inherit);font-weight:var(--cx-format-time-font-weight,inherit)}`;
var w = Object.defineProperty, P = Object.getOwnPropertyDescriptor, n = (t, e, s, a) => {
  for (var o = a > 1 ? void 0 : a ? P(e, s) : e, p = t.length - 1, c; p >= 0; p--)
    (c = t[p]) && (o = (a ? c(e, s, o) : c(o)) || o);
  return a && o && w(e, s, o), o;
};
function O(t) {
  if (t === null || t === "")
    return null;
  const e = Number(t);
  return Number.isFinite(e) ? e : null;
}
function A(t) {
  return t == null ? null : String(t);
}
const v = r.DayHourMinute, I = u.Long, x = /* @__PURE__ */ new Set([
  r.Day,
  r.DayHour,
  r.DayHourMinute,
  r.DayHourMinuteSecond,
  r.Hour,
  r.HourMinute,
  r.HourMinuteSecond,
  r.Minute,
  r.MinuteSecond,
  r.Second
]), E = /* @__PURE__ */ new Set([
  u.Long,
  u.Short,
  u.Narrow,
  u.Digital
]);
let i = class extends h {
  constructor() {
    super(...arguments), this.localize = new N(this), this.duration = null, this.placeholder = "", this.unitsFormat = r.DayHourMinute, this.locale = D.English, this.displayStyle = u.Long, this.inputUnit = d.Millisecond, this.formattedDuration = "0";
  }
  updateFormattedDuration() {
    const t = this.normalizeDurationToMilliseconds();
    if (t == null || t === 0 || !Number.isFinite(t)) {
      this.formattedDuration = "0";
      return;
    }
    const e = x.has(this.unitsFormat) ? this.unitsFormat : v, s = E.has(this.displayStyle) ? this.displayStyle : I, a = S(t, e);
    try {
      this.formattedDuration = F(a, s, this.locale) || "0";
    } catch {
      const o = U(a);
      this.formattedDuration = g(o, s);
    }
  }
  normalizeDurationToMilliseconds() {
    return this.duration === null || this.duration === void 0 ? null : Number.isFinite(this.duration) ? this.inputUnit === d.Second ? this.duration * _ : this.duration : Number.NaN;
  }
  render() {
    const t = this.placeholder || this.localize.term("ongoing");
    return this.duration == null || Number.isNaN(this.duration) ? f`<span part="base" class="format-time">${t}</span>` : f`<span part="base" class="format-time">${this.formattedDuration}</span>`;
  }
};
i.styles = [y, T];
i.dependencies = {};
n([
  l({
    converter: {
      fromAttribute: O,
      toAttribute: A
    },
    reflect: !0
  })
], i.prototype, "duration", 2);
n([
  l({ type: String })
], i.prototype, "placeholder", 2);
n([
  l({ attribute: "units-format", reflect: !0, type: String })
], i.prototype, "unitsFormat", 2);
n([
  l({ type: String })
], i.prototype, "locale", 2);
n([
  l({ attribute: "display-style", reflect: !0, type: String })
], i.prototype, "displayStyle", 2);
n([
  l({ attribute: "input-unit", type: String })
], i.prototype, "inputUnit", 2);
n([
  M()
], i.prototype, "formattedDuration", 2);
n([
  m("displayStyle", { waitUntilFirstUpdate: !0 }),
  m("unitsFormat", { waitUntilFirstUpdate: !0 }),
  m("inputUnit", { waitUntilFirstUpdate: !0 }),
  m("locale", { waitUntilFirstUpdate: !0 }),
  m("duration")
], i.prototype, "updateFormattedDuration", 1);
i = n([
  b("cx-format-time")
], i);
export {
  i as default,
  O as fromDurationAttribute,
  A as toDurationAttribute
};
