import D from "moment";
import { ElMessage as j } from "element-plus";
import S from "./constant.mjs";
const V = (n, o, e, c, u) => {
  if (n) {
    const g = [];
    if (e.forEach((l) => {
      var x;
      l.lng = l.value[0], l.lat = l.value[1], l.count = (x = l == null ? void 0 : l.value) == null ? void 0 : x[2], l.typeCode = (l == null ? void 0 : l.typeCode) || "A01";
      const h = l.resourceName || l.name, b = [l.lng, l.lat];
      l.image;
      const m = "url(http://zgdev.fxo2opt.com/document/shi/zv-hj-scene-amap2d/green.png)", i = document.createElement("div"), s = document.createElement("div");
      s.style.backgroundImage = m, s.style.backgroundPosition = "100% 100%", s.style.backgroundSize = "cover", s.style.backgroundPosition = "center center", s.style.display = "flex", s.style.alignItems = "flex-start", s.style.justifyContent = "center", s.style.width = "110px", s.style.height = "142px", s.style.position = "relative", s.style.top = "-106px", s.style.cursor = "pointer";
      const w = S.iconfont[l.typeCode], p = "#ffffff";
      l.homeImage || (i.className = "iconfont " + w, i.style.width = i.style.height = "32px", i.style.fontSize = "20px", i.style.color = p, i.style.position = "relative", i.style.top = "8px", i.style.display = "flex", i.style.alignItems = "center", i.style.justifyContent = "center"), s.appendChild(i);
      const t = {
        extData: l,
        position: b,
        autoMove: !0,
        content: s,
        anchor: "bottom-center",
        // 将锚点设置为标记的底部中心点
        offset: new n.Pixel(0, 142)
        // 偏移量
      }, y = new n.Marker(t);
      y.setLabel({
        direction: "top",
        offset: new n.Pixel(0, -120),
        // 设置文本标注偏移量
        content: `<div class='hj__map-marker-label'>${h}</div>`
        // 设置文本标注内容
      }), g.push(y), y.on("click", () => {
        typeof u.clickCallback == "function" && u.clickCallback(l);
      }), y.on("mouseover", () => {
        typeof u.mouseoverCallback == "function" && u.mouseoverCallback(l);
      });
    }), g.length > 0)
      return o.add(g), g;
  }
}, H = (n, o) => {
  if (n.value) {
    const e = o.lng, c = o.lat;
    e && c ? n.value.setCenter([e, c]) : n.value.getAllOverlays("marker").forEach((u) => {
      u.getExtData().resourceId === o.resourceId && n.value.setCenter(u.getPosition());
    });
  }
}, N = (n, o, e) => {
  o.value && e.setMap(o.value);
}, R = (n, o, e) => {
  o.value && e.hide();
}, A = (n, o, e) => {
  o.value && (o.value.add(e), o.value.setFitView());
}, F = (n, o, e) => {
  o.value && e.hide();
}, K = (n, o, e) => {
  o.value && e.hide();
}, L = (n, o, e) => {
  o.value && e.hide();
}, U = (n, o) => {
  n.value && o.value.length > 0 && o.value.forEach((e) => {
    (e == null ? void 0 : e.type) === "locaPointLayer" && n.value.remove(e.value);
  });
}, _ = (n, o) => {
  n.value && o.value.length > 0 && o.value.forEach((e) => {
    (e == null ? void 0 : e.type) === "breathRed" && n.value.remove(e.value);
  });
}, q = (n, o) => {
  n.value && o.value.length > 0 && o.value.forEach((e) => {
    (e == null ? void 0 : e.type) === "labelsLayer" && n.value.remove(e.value);
  });
}, G = (n, o) => {
  n.value && o.value.length > 0 && o.value.forEach((e) => {
    (e == null ? void 0 : e.type) === "markerLayer" && n.value.remove(e.value);
  });
}, J = (n, o, e) => {
  n.value && o.value.length > 0 && o.value.forEach((c) => {
    c.type === "labelsLayer" && c.value.setStyle({
      // 其他样式
      text: {
        style: {
          visible: !!e.value,
          opacity: e.value ? 1 : 0
        }
      }
    });
  });
}, Q = (n, o, e, c, u, g) => {
  if (!(!e || !(e != null && e.length)) && n) {
    o.clearMap();
    const l = [], h = [], b = 226;
    for (let p = 0; p < e.length; p++) {
      const t = e[p];
      if (t.lng = (t == null ? void 0 : t.lng) || (t == null ? void 0 : t.longitude) || (t == null ? void 0 : t[0]) || t.value[0], t.lat = (t == null ? void 0 : t.lat) || (t == null ? void 0 : t.latitude) || (t == null ? void 0 : t[1]) || t.value[1], !t.lng || !t.lat)
        continue;
      const y = t.resourceName || t.name, x = [t.lng, t.lat];
      h.push(x);
      const M = `url(${c.track.unselected.bg})`, r = document.createElement("div");
      r.id = t.indexCode, r.style.backgroundImage = M, r.style.backgroundPosition = "100% 100%", r.style.backgroundSize = "cover", r.style.display = "flex", r.style.alignItems = "flex-start", r.style.justifyContent = "center", r.style.width = "131px", r.style.height = b + "px", r.style.position = "absolute", r.style.top = "-205px", r.style.left = "-65px", r.style.cursor = "pointer", r.style.color = c.track.unselected.color;
      const d = document.createElement("div");
      d.style.position = "absolute", d.style.top = "37px", d.style.width = "20px", d.style.display = "flex", d.style.justifyContent = "center", d.style.alignItems = "center", d.style.textAlign = "center", d.style.textOverflow = "ellipsis", d.style.overflow = "hidden", d.style.maxHeight = "130px", d.style.fontSize = "14px", d.style.fontWeight = "400", d.innerHTML = y, r.appendChild(d);
      const v = `
            <div style="width: 320px; height: 252px; padding:16px; background-image: url(${c.track.infoWindow.bg}); background-position: 100% 100%; background-size: cover;">
              <div style="color: rgba(255, 255, 255, 1);font-size: 14px;font-weight: 600;width: 100%; display: flex; align-items: center; justify-content: flex-start;">${y}</div>
              <div style="color: rgba(255, 255, 255, 0.6);font-size: 12px;font-weight: 400;width: 100%; display: flex; align-items: center; justify-content: flex-start;margin: 3px 0 0 0;">${t.captureTime}</div>
              <div style="margin: 10px 0 0 0;width: 100%; height: 166px; display: flex; align-items: center; justify-content: center;">
              <iframe id="iframe-${t.indexCode}" style="width: 100%" src="${c.track.videoPlayUrl}/hjly/config/html/videoSurveillance/demo.html#type=2" frameborder="0"></iframe>
              </div>
            </div>`;
      t.content1 = v;
      const E = {
        extData: t,
        position: x,
        autoMove: !0,
        content: r,
        anchor: "bottom-center",
        // 将锚点设置为标记的底部中心点
        offset: new n.Pixel(0, 0)
        // 偏移量
      }, T = new n.Marker(E);
      l.push(T);
      const I = new n.InfoWindow({
        offset: new n.Pixel(200, -45),
        closeWhenClickMap: !0,
        content: t.content1,
        isCustom: !0
      });
      I.on("close", (P) => {
        const k = document.getElementById("iframe-" + t.indexCode);
        k && k.contentWindow.postMessage(
          {
            type: "close"
          },
          "*"
        );
        const f = document.getElementById(t.indexCode);
        f && (f.style.backgroundImage = `url(${c.track.unselected.bg})`, f.style.color = c.track.unselected.color);
      }), T.on("click", (P) => {
        e.forEach((f) => {
          const a = document.getElementById(f.indexCode);
          a && (a.style.backgroundImage = `url(${c.track.unselected.bg})`, a.style.color = c.track.unselected.color);
        });
        const k = document.getElementById(t.indexCode);
        k && (k.style.backgroundImage = `url(${c.track.selected.bg})`, k.style.color = c.track.selected.color), u && u.clickCallback(t), I.setContent(t.content1), I.open(o, P.target.getPosition()), setTimeout(() => {
          g.getDeviceByIndexCode({ indexCode: t.indexCode }).then((f) => {
            var C;
            const a = (C = f == null ? void 0 : f.data) == null ? void 0 : C.deviceId;
            if (!a)
              return j({
                message: f == null ? void 0 : f.msg,
                type: "error"
              });
            t.deviceId = a, t.resourceId = a, W(g, t);
          });
        }, 200);
      });
    }
    const m = document.createElement("canvas"), i = 24;
    m.width = i, m.height = i;
    const s = m.getContext("2d");
    s.strokeStyle = "red", s.lineJoin = "round", s.lineWidth = 8, s.moveTo(-4, i - 4), s.lineTo(i / 2, 6), s.lineTo(i + 4, i - 4), s.stroke();
    const w = new n.Polyline({
      path: h,
      isOutline: !0,
      outlineColor: c.track.line.color,
      borderWeight: 0,
      strokeColor: c.track.line.color,
      strokeOpacity: 1,
      strokeWeight: 6,
      // 折线样式还支持 'dashed'
      strokeStyle: "solid",
      // strokeStyle是dashed时有效
      strokeDasharray: [10, 5],
      lineJoin: "round",
      lineCap: "round",
      zIndex: 9999999,
      showDir: !0,
      dirImg: m
    });
    return o.add(w), o.add(l), o.setFitView(), l;
  }
}, W = (n, o) => {
  const e = o.deviceId || "1162";
  n.getVideoDeviceParams({ deviceId: e }).then((c) => {
    var r, d;
    const u = c.data, g = u.filter((v) => v.paramKey === "recordLocation"), l = g[0] && g[0].paramValue || 1, h = window.location.protocol === "https:" ? "wss" : "ws", b = u[0].protocolId, m = u.filter((v) => v.paramKey === "rtspHost"), i = u.filter(
      (v) => v.paramKey === "outerWsPlayBackHost"
    ), s = h + "://" + ((r = m[0]) == null ? void 0 : r.paramValue) + ":" + (((d = i[0]) == null ? void 0 : d.paramValue) || 9422), w = o.captureTime.substr(0, 19).replace("T", " "), p = D(w).subtract(15, "s").format("yyyy-MM-DD HH:mm:ss"), t = D(w).add(15, "s").format("yyyy-MM-DD HH:mm:ss"), y = 1, x = {
      deviceId: e,
      beginTime: p,
      endTime: t,
      protocol: h,
      location: l,
      streamType: y
    };
    let M = [];
    n.getRecordFileList(x).then((v) => {
      var I;
      const E = ((I = v == null ? void 0 : v.data) == null ? void 0 : I.data) || [];
      M = E && !Array.isArray(E) ? JSON.parse(E) : [];
      const T = {
        deviceId: e,
        beginTime: p.split(" ")[0],
        endTime: t.split(" ")[0],
        protocol: h,
        streamType: y,
        recordLocation: l
      };
      n.getPlaybackConfig(T).then((P) => {
        const a = { uri: P.data, ...{} };
        a.index = 0, a.streamType = y, a.startTime = p.split(" ").join("T"), a.endTime = t.split(" ").join("T"), a.row = 1, a.captureTag = !0, a.channelId = b || "", a.wsUrl = s || "", a.fileList = M;
        const C = document.getElementById("iframe-" + o.indexCode);
        C && C.contentWindow && setTimeout(() => {
          C.contentWindow.postMessage(
            {
              type: "playback",
              data: a
            },
            "*"
          );
        }, 2e3);
      });
    });
  });
};
export {
  q as clearLabelsLayer,
  U as clearLoadLocaDotLayers,
  G as clearMarkerLayer,
  _ as clearRipplesScatter,
  F as hideLineMap,
  R as hideRoadMap,
  L as hideSmallMap,
  V as loadDotMap,
  A as loadLineMap,
  H as navigatorDot,
  J as showAndHideDotLabelMap,
  N as showRoadMap,
  K as showSmallMap,
  Q as trackPlay
};
