(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 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);
    let values = series.points.map((p) => p.value);
    const asString = values.some((v) => typeof v === "string");
    const display = series.name || itemLabel(series.item);
    const fields = [
      { name: "Time", type: "time", values: times },
      {
        name: "Value",
        type: asString ? "string" : "number",
        values: asString ? values.map((v) => v == null ? null : String(v)) : values.map((v) => v == null || v === "" ? null : Number(v)),
        labels: {
          itemid: series.item.itemid,
          item: series.item.name,
          host: series.item.hosts?.[0]?.name || ""
        },
        config: {
          displayNameFromDS: display,
          ...series.item.units ? { unit: series.item.units } : {}
        }
      }
    ];
    if (series.points.some((p) => p.valueRaw != null && p.valueRaw !== "")) {
      fields.push({
        name: "ValueRaw",
        type: "string",
        values: series.points.map(
          (p) => p.valueRaw == null ? null : String(p.valueRaw)
        )
      });
    }
    if (series.meta?.source === "trend") {
      fields.push(
        {
          name: "TrendMin",
          type: "number",
          values: series.points.map(
            (p) => p.value_min == null ? null : Number(p.value_min)
          )
        },
        {
          name: "TrendAvg",
          type: "number",
          values: series.points.map(
            (p) => p.value_avg == null ? null : Number(p.value_avg)
          )
        },
        {
          name: "TrendMax",
          type: "number",
          values: series.points.map(
            (p) => p.value_max == null ? null : Number(p.value_max)
          )
        },
        {
          name: "TrendNum",
          type: "number",
          values: series.points.map(
            (p) => p.num == null ? null : Number(p.num)
          )
        }
      );
    }
    if (series.points.some(
      (p) => p.logeventid != null || p.source != null || p.severity != null
    )) {
      fields.push(
        {
          name: "timestamp",
          type: "string",
          values: series.points.map((p) => p.timestamp ?? null)
        },
        {
          name: "source",
          type: "string",
          values: series.points.map((p) => p.source ?? null)
        },
        {
          name: "severity",
          type: "string",
          values: series.points.map((p) => p.severity ?? null)
        },
        {
          name: "logeventid",
          type: "string",
          values: series.points.map((p) => p.logeventid ?? null)
        },
        {
          name: "ns",
          type: "string",
          values: series.points.map((p) => p.ns ?? null)
        }
      );
    }
    const frame = createDataFrame({
      refId,
      name: display,
      fields
    });
    frame.meta = {
      ...frame.meta,
      source: "live",
      datasourceUid,
      custom: {
        source: "zabbix",
        itemid: series.item.itemid,
        datasourceUid
      },
      notices: (series.notices || []).map((text) => ({
        severity: "warning",
        text
      }))
    };
    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-C6D9tEGY.js.map
