(function() {
  "use strict";
  function createDataFrame(opts) {
    const fields = opts.fields.map((f) => ({
      name: f.name,
      type: f.type ?? inferType(f.values),
      config: f.config ?? {},
      values: f.values,
      labels: f.labels
    }));
    const length = fields.reduce((max, f) => Math.max(max, f.values.length), 0);
    return {
      refId: opts.refId,
      name: opts.name,
      fields,
      length,
      meta: opts.meta
    };
  }
  function inferType(values) {
    const sample = values.find((v) => v != null);
    if (typeof sample === "number") return "number";
    if (typeof sample === "boolean") return "boolean";
    if (sample instanceof Date) return "time";
    if (typeof sample === "string" && !Number.isNaN(Date.parse(sample)) && /\d{4}-\d{2}-\d{2}/.test(sample)) {
      return "time";
    }
    return typeof sample === "string" ? "string" : "other";
  }
  function toFixed(value, decimals) {
    if (decimals == null) {
      if (!Number.isFinite(value)) return String(value);
      if (Number.isInteger(value) || Math.abs(value - Math.round(value)) < 1e-9) {
        return String(Math.round(value));
      }
      const abs = Math.abs(value);
      const d = abs >= 100 ? 0 : abs >= 1 ? 1 : abs >= 0.01 ? 2 : 3;
      return String(Number(value.toFixed(d)));
    }
    return value.toFixed(Math.max(0, Math.min(10, Math.floor(decimals))));
  }
  function toFixedUnit(unit = "") {
    return (value, decimals) => ({
      text: toFixed(value, decimals),
      suffix: unit ? ` ${unit}` : void 0
    });
  }
  function scaledUnits(factor, extArray, offset = 0) {
    return (value, decimals) => {
      if (value === null || value === void 0 || Number.isNaN(value)) {
        return { text: "" };
      }
      let si = offset;
      let v = Math.abs(value);
      while (v >= factor && si < extArray.length - 1) {
        v /= factor;
        si += 1;
      }
      const sign = value < 0 ? "-" : "";
      return {
        // When decimals is null/undefined, toFixed uses auto precision (Grafana axis ticks).
        text: `${sign}${toFixed(v, decimals)}`,
        suffix: extArray[si] ? ` ${extArray[si]}` : void 0
      };
    };
  }
  function booleanValueFormatter(t = "True", f = "False") {
    return (value) => ({ text: value ? t : f });
  }
  function locale(value, decimals) {
    try {
      return {
        text: value.toLocaleString(void 0, {
          maximumFractionDigits: decimals ?? 2,
          minimumFractionDigits: decimals ?? void 0
        })
      };
    } catch {
      return { text: toFixed(value, decimals) };
    }
  }
  function stringFormatter(value) {
    return { text: value == null ? "" : String(value) };
  }
  function dtdhms(value) {
    if (!Number.isFinite(value)) return { text: String(value) };
    const sign = value < 0 ? "-" : "";
    let s = Math.floor(Math.abs(value));
    const d = Math.floor(s / 86400);
    s -= d * 86400;
    const h = Math.floor(s / 3600);
    s -= h * 3600;
    const m = Math.floor(s / 60);
    s -= m * 60;
    const parts = [];
    if (d) parts.push(`${d}d`);
    if (h || parts.length) parts.push(`${h}h`);
    if (m || parts.length) parts.push(`${m}m`);
    parts.push(`${s}s`);
    return { text: `${sign}${parts.join(" ")}` };
  }
  function dateTimeAsIso(value) {
    try {
      return { text: new Date(value).toISOString() };
    } catch {
      return { text: String(value) };
    }
  }
  function dateTimeAsSystem(value, _decimals, _scaled, timeZone) {
    try {
      const d = new Date(value);
      if (Number.isNaN(d.getTime())) return { text: String(value) };
      const pad = (n) => String(n).padStart(2, "0");
      const tz = String(timeZone || "browser").toLowerCase();
      const useUtc = tz === "utc" || tz === "gmt" || tz === "etc/utc";
      const Y = useUtc ? d.getUTCFullYear() : d.getFullYear();
      const M = useUtc ? d.getUTCMonth() + 1 : d.getMonth() + 1;
      const D = useUtc ? d.getUTCDate() : d.getDate();
      const h = useUtc ? d.getUTCHours() : d.getHours();
      const m = useUtc ? d.getUTCMinutes() : d.getMinutes();
      const s = useUtc ? d.getUTCSeconds() : d.getSeconds();
      const text = `${Y}-${pad(M)}-${pad(D)} ${pad(h)}:${pad(m)}:${pad(s)}`;
      return { text };
    } catch {
      return { text: String(value) };
    }
  }
  const index = /* @__PURE__ */ new Map();
  function register(id, fn) {
    index.set(id, fn);
  }
  function build() {
    if (index.size) return;
    register("none", (v, d) => {
      if (d != null) return { text: Number(v).toFixed(d) };
      if (!Number.isFinite(v)) return { text: String(v) };
      if (Number.isInteger(v) || Math.abs(v - Math.round(v)) < 1e-9)
        return { text: String(Math.round(v)) };
      const abs = Math.abs(v);
      if (abs >= 100 && Math.abs(v - Math.round(v)) < 0.5)
        return { text: String(Math.round(v)) };
      const decimals = abs >= 1e3 ? 0 : abs >= 1 ? 1 : abs >= 0.01 ? 2 : 3;
      return { text: String(Number(v.toFixed(decimals))) };
    });
    register("short", scaledUnits(1e3, ["", "K", "Mil", "Bil", "Tri"]));
    register("percent", (v, d) => ({
      text: d == null ? String(v) : v.toFixed(d),
      suffix: "%"
    }));
    register("percentunit", (v, d) => {
      const p = v * 100;
      return {
        text: d == null ? String(Number(p.toPrecision(12))) : p.toFixed(d),
        suffix: "%"
      };
    });
    register("locale", (v, d) => locale(v, d));
    register("string", (_v) => stringFormatter(_v));
    register("bool", booleanValueFormatter());
    register("boolean", booleanValueFormatter());
    for (const u of ["ns", "µs", "ms", "s", "m", "h", "d"]) {
      register(u, toFixedUnit(u));
    }
    register(
      "bytes",
      scaledUnits(1024, ["B", "KiB", "MiB", "GiB", "TiB", "PiB"])
    );
    register("decbytes", scaledUnits(1e3, ["B", "kB", "MB", "GB", "TB", "PB"]));
    register("bits", scaledUnits(1e3, ["b", "Kbit", "Mbit", "Gbit", "Tbit"]));
    register("decbits", scaledUnits(1e3, ["b", "Kbit", "Mbit", "Gbit", "Tbit"]));
    register("kbytes", scaledUnits(1024, ["KiB", "MiB", "GiB", "TiB"]));
    register("mbytes", scaledUnits(1024, ["MiB", "GiB", "TiB"]));
    for (const u of [
      "cps",
      "ops",
      "reqps",
      "rps",
      "wps",
      "iops",
      "binBps",
      "Bps",
      "pps"
    ]) {
      register(u, toFixedUnit(u));
    }
    register("dateTimeAsIso", (v) => dateTimeAsIso(v));
    register("dateTimeAsSystem", (v) => dateTimeAsSystem(v));
    register("sci", (v, d) => ({ text: v.toExponential(d ?? 2) }));
    register("humidity", toFixedUnit("%H"));
    register("dB", toFixedUnit("dB"));
    register("dBm", toFixedUnit("dBm"));
    register("celsius", toFixedUnit("°C"));
    register("fahrenheit", toFixedUnit("°F"));
    register("farenheit", toFixedUnit("°F"));
    register("lengthm", toFixedUnit("m"));
    register("lengthmm", toFixedUnit("mm"));
    register("velocityms", toFixedUnit("m/s"));
    register("bps", scaledUnits(1e3, ["b/s", "Kb/s", "Mb/s", "Gb/s", "Tb/s"]));
    register("dtdhms", (v) => dtdhms(v));
    register("qps", toFixedUnit("qps"));
    register("hertz", scaledUnits(1e3, ["Hz", "kHz", "MHz", "GHz", "THz"]));
    register("volt", scaledUnits(1e3, ["V", "kV", "MV", "GV"]));
    register("rotrpm", toFixedUnit("rpm"));
  }
  function listValueFormatIds() {
    build();
    return [...index.keys()].sort();
  }
  const ZABBIX_UNIT_MAP = {
    "%": "percent",
    b: "decbits",
    // bits(SI)
    bps: "bps",
    // bits/sec(SI)
    B: "bytes",
    // bytes(IEC)
    Bps: "binBps",
    // bytes/sec(IEC)
    // 'unixtime': 'dateTimeAsSystem', // matches React: left commented out upstream
    uptime: "dtdhms",
    qps: "qps",
    // requests/sec (rps)
    iops: "iops",
    // I/O ops/sec (iops)
    Hz: "hertz",
    // Hertz (1/s)
    V: "volt",
    // Volt (V)
    C: "celsius",
    // Celsius (°C)
    RPM: "rotrpm",
    // Revolutions per minute (rpm)
    dBm: "dBm"
    // Decibel-milliwatt (dBm)
  };
  let knownUnitIds = null;
  function getKnownGrafanaUnitIds() {
    if (!knownUnitIds) knownUnitIds = new Set(listValueFormatIds());
    return knownUnitIds;
  }
  function convertZabbixUnit(zabbixUnit) {
    if (!zabbixUnit) return void 0;
    const mapped = ZABBIX_UNIT_MAP[zabbixUnit];
    if (mapped) return mapped;
    if (getKnownGrafanaUnitIds().has(zabbixUnit)) return zabbixUnit;
    return void 0;
  }
  function itemLabel(item) {
    const host = item.hosts?.[0]?.name || item.hosts?.[0]?.host || "";
    return host ? `${host}: ${item.name}` : item.name || item.key_;
  }
  function seriesToDataFrame(series, refId, datasourceUid, valueMaps) {
    const times = series.points.map((p) => p.time);
    const values = series.points.map((p) => p.value);
    const display = series.name || itemLabel(series.item);
    const host = series.item.hosts?.[0];
    const tagValues = /* @__PURE__ */ new Map();
    for (const tag of series.item.tags || []) {
      const key = tag.tag.replace(/[^A-Za-z0-9_]/g, "_");
      if (!key) continue;
      tagValues.set(key, [
        ...tagValues.get(key) || [],
        String(tag.value ?? "")
      ]);
    }
    const scopedVars = {
      __zbx_item: { value: series.item.name },
      __zbx_item_name: { value: series.item.name },
      __zbx_item_key: { value: series.item.key_ },
      __zbx_item_interval: { value: String(series.item.delay || "") }
    };
    if (host) {
      scopedVars.__zbx_host = { value: host.name || host.host || "" };
      scopedVars.__zbx_host_id = { value: host.hostid };
      scopedVars.__zbx_host_name = { value: host.name || host.host || "" };
    }
    for (const [key, entries] of tagValues) {
      scopedVars[`__zbx_item_tag_${key}`] = { value: entries.sort().join(", ") };
    }
    const unit = convertZabbixUnit(series.item.units);
    const mappings = void 0;
    const fields = [
      {
        name: "Time",
        type: "time",
        values: times,
        config: { custom: { itemInterval: series.item.delay } }
      },
      {
        name: "Value",
        type: "number",
        values: values.map((v) => v == null || v === "" ? null : Number(v)),
        labels: {
          ...host ? { host: host.name || host.host || "" } : {},
          item: series.item.name,
          item_key: series.item.key_
        },
        config: {
          displayNameFromDS: display,
          custom: { scopedVars, itemInterval: series.item.delay },
          ...unit ? { unit } : {},
          ...unit === "percent" ? { min: 0, max: 100 } : {},
          ...Array.isArray(mappings) && mappings.length ? {
            mappings: mappings.map((mapping) => ({
              type: "value",
              options: {
                [String(mapping.value)]: { text: mapping.newvalue }
              }
            }))
          } : {}
        }
      }
    ];
    const frame = createDataFrame({
      refId,
      name: display,
      fields
    });
    frame.meta = {
      source: "live",
      datasourceUid,
      ...series.points.some((point) => point.valueRaw != null) ? {
        custom: {
          valueRaw: series.points.map(
            (point) => point.valueRaw == null ? null : String(point.valueRaw)
          )
        }
      } : {}
    };
    return frame;
  }
  function seriesListToFrames(series, refId, datasourceUid, valueMaps) {
    return series.map(
      (s) => seriesToDataFrame(s, refId, datasourceUid)
    );
  }
  const ctx = self;
  ctx.onmessage = (e) => {
    const { id, series, refId, datasourceUid } = e.data || {};
    try {
      const frames = seriesListToFrames(series || [], refId || "A", datasourceUid || "");
      ctx.postMessage({ id, ok: true, frames });
    } catch (err) {
      ctx.postMessage({
        id,
        ok: false,
        error: err instanceof Error ? err.message : String(err)
      });
    }
  };
})();
//# sourceMappingURL=frameWorker-D950i8VL.js.map
