import { computed as s, unref as r, ref as P } from "vue";
import { autoPtgSizes as N } from "./sizeUtil.mjs";
function i(t) {
  return typeof t == "string" && t.endsWith("%");
}
function a(t) {
  return Number(t.slice(0, -1)) / 100;
}
const M = (t, c) => {
  const d = s(() => r(t).map((e) => e.size)), l = s(() => r(t).length), u = s(() => r(c) || 0), x = (e) => e * r(u), p = P(
    r(t).map(
      (e) => e.defaultSize || e["default-size"]
    )
  ), z = s(() => {
    const e = [];
    for (let n = 0; n < l.value; n += 1)
      e[n] = d.value[n] ?? p.value[n];
    return e;
  }), f = s(
    () => r(t).map((e) => i(e.min) ? a(e.min) : (e.min || 0) / u.value)
  ), m = s(
    () => r(t).map((e) => i(e.max) ? a(e.max) : (e.max || u.value) / u.value)
  ), v = s(() => {
    const e = [];
    for (let n = 0; n < l.value; n += 1) {
      const o = z.value[n];
      if (i(o))
        e[n] = a(o);
      else if (o || o === 0) {
        const g = Number(o);
        Number.isNaN(g) || (e[n] = g / u.value);
      } else
        e[n] = void 0;
    }
    return N(
      e,
      f.value,
      m.value
    );
  }), S = s(() => r(v).map(x));
  return [
    s(() => c?.value ? r(S) : r(z)),
    S,
    v,
    f,
    m,
    (e) => {
      p.value = e;
    }
  ];
};
export {
  a as getPtg,
  M as useSizes
};
