import { n as e, r as t } from "./component-AqiMonitor-BUy1MSaP.mjs";
import { ElLoadingDirective as n } from "element-plus/es";
import { Fragment as r, computed as i, createCommentVNode as a, createElementBlock as o, createElementVNode as s, defineComponent as c, getCurrentInstance as l, normalizeClass as u, normalizeStyle as d, onMounted as f, onUnmounted as ee, openBlock as p, ref as m, renderList as h, toDisplayString as g, vShow as _, watch as te, withDirectives as v, withModifiers as y } from "vue";
//#region src/components/RadarTime/RadarTime.vue?vue&type=script&setup=true&lang.ts
var b = { class: "RadarTime" }, ne = { class: "RadarTime__head" }, re = { class: "RadarTime__head-top" }, ie = { class: "RadarTime__body" }, ae = { class: "RadarTime__toolbar" }, oe = { class: "RadarTime__display" }, se = { class: "RadarTime__panel" }, ce = { class: "RadarTime__time-list" }, le = ["onClick"], ue = {
	key: 0,
	class: "RadarTime__time-node"
}, de = { class: "RadarTime__node-value" }, fe = { class: "RadarTime__legend" }, pe = { class: "RadarTime__legend-bar" }, x = { class: "RadarTime__legend-labels" }, me = {
	key: 0,
	class: "RadarTime__station-bar"
}, he = { class: "RadarTime__station-name" }, ge = { class: "RadarTime__station-panel" }, _e = ["onClick"], ve = { class: "RadarTime__main" }, ye = { class: "RadarTime__play-wrapper" }, be = {
	key: 0,
	xmlns: "http://www.w3.org/2000/svg",
	width: "22",
	height: "22",
	viewBox: "0 0 24 24",
	fill: "#fff"
}, xe = {
	key: 1,
	xmlns: "http://www.w3.org/2000/svg",
	width: "20",
	height: "20",
	viewBox: "0 0 24 24",
	fill: "#fff"
}, Se = { class: "RadarTime__track-bg" }, Ce = { class: "RadarTime__track-content" }, we = ["onClick"], S = /* @__PURE__ */ e(/* @__PURE__ */ c({
	__name: "RadarTime",
	props: {
		appKey: {
			type: String,
			default: ""
		},
		appSalt: {
			type: String,
			default: ""
		},
		showCloseBtn: {
			type: Boolean,
			default: !0
		},
		baseHttp: {
			type: String,
			default: ""
		},
		ids: {
			type: Object,
			default: () => ({})
		},
		title: {
			type: String,
			default: "雷达时间轴"
		},
		legendData: {
			type: Array,
			default: () => [
				{
					value: "0",
					color: "rgb(192, 192, 253)"
				},
				{
					value: "5",
					color: "rgb(122, 114, 238)"
				},
				{
					value: "10",
					color: "rgb(30, 38, 208)"
				},
				{
					value: "15",
					color: "rgb(166, 252, 168)"
				},
				{
					value: "20",
					color: "rgb(0, 235, 0)"
				},
				{
					value: "25",
					color: "rgb(16, 146, 26)"
				},
				{
					value: "30",
					color: "rgb(252, 244, 100)"
				},
				{
					value: "35",
					color: "rgb(200, 200, 2)"
				},
				{
					value: "40",
					color: "rgb(140, 140, 0)"
				},
				{
					value: "45",
					color: "rgb(254, 172, 172)"
				},
				{
					value: "50",
					color: "rgb(254, 100, 92)"
				},
				{
					value: "55",
					color: "rgb(238, 2, 48)"
				},
				{
					value: "60",
					color: "rgb(212, 142, 254)"
				},
				{
					value: "65",
					color: "rgb(170, 36, 250)"
				}
			]
		}
	},
	emits: [
		"close",
		"addImage",
		"clearImg",
		"addPolygon",
		"addMarker"
	],
	setup(e, { emit: c }) {
		let S = l()?.appContext.config.globalProperties.$bus, C = e, w = c, T = m(!1), E = m(!1), D = m([]), O = m([]), k = m([]), A = m(0), j = m([]), M = m(null), N = m(!1), P = m(null), F = m(!1), I = m(null), L = m(0), R = i(() => O.value.map((e) => ({
			time: e.radar_time,
			displayTime: e.radar_time?.substring(11, 16) || "",
			selectedTime: e.radar_time?.substring(0, 16) || ""
		}))), Te = i(() => R.value.length > 0 && L.value >= 0 && R.value[L.value]?.selectedTime || ""), z = m(!1);
		te(() => R.value, (e) => {
			e.length > 0 && !z.value && (z.value = !0, L.value = e.length - 1);
		}, { immediate: !0 });
		let B = () => {
			F.value = !F.value;
		}, V = () => {
			F.value = !1;
		}, H = (e) => {
			I.value && !I.value.contains(e.target) && V(), P.value && !P.value.contains(e.target) && (N.value = !1);
		}, Ee = () => {
			N.value = !N.value;
		}, De = async (e) => {
			M.value?.ldCode !== e.ld_code && (M.value = e, N.value = !1, E.value = !1, O.value = [], k.value = [], D.value = [], A.value = 0, L.value = 0, z.value = !1, await Q());
		}, Oe = async (e) => {
			L.value = e;
			let t = R.value[e]?.time;
			t && (T.value = !0, await $(t), Z(e), T.value = !1), V();
		}, U = i(() => {
			if (!D.value || D.value.length <= 1) return 50;
			let e = D.value.length, t = D.value.filter((e) => e.type === "live").length / e * 98;
			return Math.max(t, 4);
		}), ke = i(() => {
			if (!D.value || D.value.length <= 1) return 0;
			let e = A.value / (D.value.length - 1) * 98;
			return Math.max(0, Math.min(98, e));
		}), Ae = (e) => {
			if (!D.value || D.value.length <= 1) return 0;
			let t = e / (D.value.length - 1) * 98;
			return Math.max(0, Math.min(98, t));
		}, W = m(null), je = m(null), G = m(!1), Me = (e) => {
			e.button === 0 && (G.value = !0, q(e), e.preventDefault());
		}, Ne = (e) => {
			G.value && q(e);
		}, K = () => {
			G.value &&= !1;
		}, q = (e) => {
			if (!W.value || !D.value || D.value.length === 0) return;
			let t = W.value.getBoundingClientRect(), n = e.clientX - t.left;
			n = Math.max(0, Math.min(n, t.width));
			let r = n / t.width, i = Math.round(r * (D.value.length - 1));
			X(Math.max(0, Math.min(D.value.length - 1, i)));
		}, J = null, Pe = () => {
			E.value = !E.value, E.value ? Fe() : Y();
		}, Fe = () => {
			Y(), J = setInterval(() => {
				A.value < D.value.length - 1 ? X(A.value + 1) : X(0);
			}, 1e3);
		}, Y = () => {
			J &&= (clearInterval(J), null);
		}, X = (e) => {
			A.value = e;
			let t = D.value[e];
			console.log(t, "选择的时间点"), t && t.png_path && t.bounds && t.bounds.length === 2 && (console.log(t, "item11"), w("addImage", {
				removeImg: "radarLayer",
				data: { imgArr: [{
					imgUrl: t.png_path,
					lngStart: String(t.bounds[0][0]),
					latStart: String(t.bounds[0][1]),
					lngEnd: String(t.bounds[1][0]),
					latEnd: String(t.bounds[1][1]),
					opacity: .8,
					zIndex: 999,
					otherData: { imgId: "radarLayer" }
				}] }
			}));
		}, Z = (e) => {
			let t = [];
			if (O.value && O.value.length > 0) {
				let n = typeof e == "number" ? e : 0;
				O.value.slice(n).forEach((e, n) => {
					t.push({
						time: e.radar_time?.substring(11, 16) || "",
						fullTime: e.radar_time || "",
						type: "live",
						index: n,
						png_path: e.png_path || "",
						bounds: e.bounds || []
					});
				});
			}
			k.value && k.value.length > 0 && k.value.forEach((e, n) => {
				t.push({
					time: e.radar_time?.substring(11, 16) || "",
					fullTime: e.radar_time || "",
					type: "forecast",
					index: n,
					png_path: e.png_path || "",
					bounds: e.bounds || []
				});
			}), D.value = t, A.value = 0, setTimeout(() => {
				X(0);
			}, 0);
		}, Q = async () => {
			T.value = !0;
			let e = {
				appKey: C.appKey,
				appSalt: C.appSalt,
				id: C.ids.data.id2,
				variables: {
					dateTime: (() => {
						let e = /* @__PURE__ */ new Date();
						e.setHours(e.getHours());
						let t = (e) => String(e).padStart(2, "0");
						return `${e.getFullYear()}-${t(e.getMonth() + 1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}:${t(e.getSeconds())}`;
					})(),
					ldCode: M.value?.ld_code || ""
				},
				baseHttp: C.baseHttp,
				reqType: C.ids.data.reqType,
				isFormData: C.ids.data.isFormData
			};
			try {
				let n = (await t(e)).data?.result?.output || "", r = JSON.parse(n)?.data || [];
				console.log(r, "雷达实况数据（标准版）"), r && r.length > 0 && (r = r.reverse(), O.value = r.map((e) => {
					let t = "";
					if (e.imagePath) {
						let n = e.imagePath.replace(/\\/g, "/");
						t = n.startsWith("D:/usr/uploadPath/tq") ? "/image-proxy" + n.substring(20) : n;
					} else console.log("实况项 png_path 为空, imagePath:", e.imagePath);
					return {
						...e,
						png_path: t,
						date_time: e.observationTime,
						radar_time: e.observationTime,
						bounds: [[e.lon_min, e.lat_min], [e.lon_max, e.lat_max]]
					};
				}), await $(), Z(L.value));
			} catch (e) {
				console.error("获取雷达实况数据失败:", e);
			} finally {
				T.value = !1;
			}
		}, $ = async (e) => {
			let n = {
				appKey: C.appKey,
				appSalt: C.appSalt,
				id: C.ids.data.forecastId,
				variables: { dateTime: e || O.value[O.value.length - 1]?.date_time || "" },
				baseHttp: C.baseHttp,
				reqType: C.ids.data.reqType,
				isFormData: C.ids.data.isFormData
			};
			try {
				let e = await t(n);
				console.log(e, "雷达外推数据");
				let r = e.data?.result?.output || "", i = {};
				try {
					i = typeof r == "string" ? JSON.parse(r) : r;
				} catch (e) {
					console.error("解析外推数据失败:", e);
					return;
				}
				let a = i?.data || {}, o = a?.elements || [];
				Array.isArray(o) && o.length > 0 && Ie(o), a.riskJsonPath && await ze(a.riskJsonPath);
			} catch (e) {
				console.error("获取雷达外推数据失败:", e);
			}
		}, Ie = (e) => {
			if (!Array.isArray(e) || e.length === 0) return;
			let t = O.value.length > 0 && O.value[O.value.length - 1]?.radar_time || "";
			k.value = e.map((e) => {
				let n = e.forecast_time || "", r = Re(n, 0, 8), i = [[80.29, 41.17], [81.29, 42.17]], a = "";
				if (e.image_path) {
					let t = e.image_path.replace(/\\/g, "/");
					a = t.startsWith("D:/usr/uploadPath/tq") ? "/image-proxy" + t.substring(20) : t;
				} else console.log("外推项 png_path 为空, image_path:", e.image_path);
				return {
					...e,
					type: "forecast",
					base_time: t,
					radar_time: r,
					fullTime: n,
					png_path: a,
					bounds: i
				};
			}), console.log(k.value, "forecastList 外推数据");
		}, Le = async () => {
			try {
				let e = (await t({
					appKey: C.appKey,
					appSalt: C.appSalt,
					id: C.ids.data.radarListId,
					variables: {},
					baseHttp: C.ids.baseHttp2,
					reqType: C.ids.data.reqType,
					isFormData: C.ids.data.isFormData
				})).data?.result?.output || [];
				e && e.length > 0 && (j.value = e, M.value = e[0], console.log(e, "雷达列表数据"));
			} catch (e) {
				console.error("获取雷达列表失败:", e);
			}
		}, Re = (e, t, n = 0) => {
			if (!e) return "";
			try {
				let r, i = e.replace(/[-:T\s]/g, "");
				if (r = /^\d{14}$/.test(i) ? new Date(Number(i.substring(0, 4)), Number(i.substring(4, 6)) - 1, Number(i.substring(6, 8)), Number(i.substring(8, 10)), Number(i.substring(10, 12)), Number(i.substring(12, 14))) : new Date(e), isNaN(r.getTime())) return "";
				r.setHours(r.getHours() + n), r.setMinutes(r.getMinutes() + t);
				let a = (e) => String(e).padStart(2, "0");
				return `${r.getFullYear()}-${a(r.getMonth() + 1)}-${a(r.getDate())} ${a(r.getHours())}:${a(r.getMinutes())}:${a(r.getSeconds())}`;
			} catch {
				return "";
			}
		}, ze = async (e) => {
			try {
				let t;
				if (e) {
					let n = e.replace(/\\/g, "/"), r = "";
					r = n.startsWith("D:/usr/uploadPath/tq") ? "/image-proxy" + n.substring(20) : e, console.log(r, "风险数据 json 路径"), t = await (await fetch(r)).json();
				} else console.log("未获取到风险数据");
				console.log(t, "风险数据 json 内容");
				let n = (t?.risk_conclusion || {}).time_periods_summary || [];
				if (!Array.isArray(n) || n.length === 0) {
					console.log("无风险时间段数据");
					return;
				}
				let r = {
					low: {
						line: "#52c41a",
						fill: "#52c41a"
					},
					medium: {
						line: "#faad14",
						fill: "#faad14"
					},
					high: {
						line: "#ff4d4f",
						fill: "#ff4d4f"
					}
				}, i = [], a = [];
				n.forEach((e, t) => {
					Array.isArray(e.risks) && e.risks.forEach((n, o) => {
						if (!n.bbox) return;
						let { lon_min: s, lat_min: c, lon_max: l, lat_max: u } = n.bbox;
						if ([
							s,
							c,
							l,
							u
						].some((e) => e === void 0)) return;
						let d = r[n.risk_level || "low"] || r.low, f = `riskArea_p${t}_r${o}`;
						i.push({
							polygonJson: [
								{
									lng: s,
									lat: c
								},
								{
									lng: l,
									lat: c
								},
								{
									lng: l,
									lat: u
								},
								{
									lng: s,
									lat: u
								},
								{
									lng: s,
									lat: c
								}
							],
							lineColor: d.line,
							weight: 2,
							zIndex: 999,
							lineStyle: "solid",
							fillColor: d.fill,
							fillOpacity: .25,
							otherData: { polyId: f },
							bAni: !1,
							minZoom: null,
							maxZoom: null
						}), n.centroid?.lon && n.centroid?.lat && a.push({
							spotObject: [{
								offsetX: -12,
								offsetY: -30,
								bAni: !1,
								minZoom: null,
								maxZoom: null,
								spotArrone: [{
									lng: String(n.centroid.lon),
									lat: String(n.centroid.lat),
									htmlString: `<div style="display:flex;color:${d.line};padding:2px 8px;font-size:12px;white-space:nowrap;">
                                    <div>${e.period_label || ""}</div>
                                    <div>${n.risk_type_label || ""}</div>
                                    <div>${n.risk_level_label || ""}</div>
                                </div>`,
									otherData: { markId: `riskMark_${f}` }
								}]
							}],
							drawArrObj: [],
							clickOpen: !1,
							hoverOpen: !1
						});
					});
				}), i.length > 0 && (w("addPolygon", {
					removePolygon: "riskArea",
					polygonArr: i
				}), console.log(`绘制了 ${i.length} 个风险区域多边形`)), a.length > 0 && (a.forEach((e) => {
					w("addMarker", {
						removeMarker: "riskMark",
						mapMarker: e
					});
				}), console.log(`绘制了 ${a.length} 个风险标记点`));
			} catch (e) {
				console.error("处理风险数据失败:", e);
			}
		};
		f(() => {
			S?.on("toComponent", (e) => {
				e.componentName === "RadarTime" && Be();
			}), document.addEventListener("click", H);
		}), ee(() => {
			document.removeEventListener("click", H), Y();
		});
		let Be = async () => {
			await Le(), await Q();
		}, Ve = () => {
			Y(), w("clearImg", "radarLayer"), w("close", "RadarTime");
		};
		return (t, i) => {
			let c = n;
			return v((p(), o("div", b, [s("div", ne, [s("div", re, [e.showCloseBtn ? (p(), o("div", {
				key: 0,
				class: "closeBtn",
				onClick: Ve,
				title: "关闭"
			})) : a("", !0)]), i[0] ||= s("img", {
				class: "RadarTime__head-line",
				src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAbsAAAASBAMAAAAwI22/AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAwUExURQAAAAem/wem/wem/wem/wem/wem/wem/wem/wem/wem/wem/wem/wem/wem/wem/5bu5GYAAAAPdFJOUwAFwAwc2M8ULQYDn/hGXGnV2UoAAAGZSURBVEjH7ZM/S8NAGId/JYGmmeLspptThurk0CHWRXGo0Nk/S50y6CYSHMRF7Efo4uQXEIpbwUnM6OhnEIeChXjv5ZLLXdLtLCX68vDCe0eGJ7/3AJN1VcL+UImB/SruVJwYTqSAW5V3LLyaPR1c+IIdH12OPZiLcyTAjccZEdccZ0Nn4bXpC3KpCuFu5tkdziX3FJxBSBZZdFk9HempCduMk4xSitJTpOgJSSIPrx10YAUB0tYOwrQ1g12k7ZyODIYXZmQpppLV26rtbDFOXVhua2Fn7WTWwUEyAe5Zc2hiLWTTC3jjk8Hw+jrSM9/Z8raKOAtZVmyr9jbpee4lU9hvSUStw6YvOpqwiXlK9d8IL0Oq5tuqvc3KLMs7q9uyCC0y22aKvDVp4u2SjnJ1c+Wecg7h9gV4CFV8NHpEaw7yF2wVGcIa6OBx/Ax3PI6pRWx6Am98alBbpSODNVTxgAbQUpF3KeVv0s80xMUow8N//YVaqWEV9BJDdby2PBUZ1/te0uU0YzeLa623jjrrvaLOep/+str9ACyAtv25BhHcAAAAAElFTkSuQmCC",
				alt: ""
			}, null, -1)]), s("div", ie, [
				s("div", ae, [
					s("div", {
						class: "RadarTime__dropdown",
						ref_key: "dropdownRef",
						ref: I
					}, [s("div", {
						class: "RadarTime__trigger",
						onClick: B
					}, [s("span", oe, g(Te.value || "选择时间"), 1), s("span", { class: u(["RadarTime__arrow", { "is-open": F.value }]) }, "▼", 2)]), v(s("div", se, [s("div", ce, [i[1] ||= s("div", { class: "RadarTime__time-item" }, " 暂无数据 ", -1), (p(!0), o(r, null, h(R.value, (e, t) => (p(), o("div", {
						key: t,
						class: u(["RadarTime__time-item", { "is-selected": L.value === t }]),
						onClick: (e) => Oe(t)
					}, g(e.time), 11, le))), 128))])], 512), [[_, F.value]])], 512),
					D.value.length > 0 && A.value >= 0 ? (p(), o("div", ue, [i[2] ||= s("span", { class: "RadarTime__node-label" }, "当前：", -1), s("span", de, g(D.value[A.value]?.time || "--:--"), 1)])) : a("", !0),
					s("div", fe, [i[3] ||= s("span", { class: "RadarTime__legend-title" }, "图例", -1), s("div", pe, [(p(!0), o(r, null, h(e.legendData, (e, t) => (p(), o("div", {
						key: t,
						class: "RadarTime__legend-segment",
						style: d({ backgroundColor: e.color })
					}, null, 4))), 128)), s("div", x, [(p(!0), o(r, null, h(e.legendData, (e, t) => (p(), o("span", { key: t }, g(e.value), 1))), 128))])])])
				]),
				j.value.length > 0 ? (p(), o("div", me, [s("div", {
					class: "RadarTime__station-dropdown",
					ref_key: "stationDropdownRef",
					ref: P
				}, [
					i[4] ||= s("label", { style: {
						color: "#fff",
						"font-size": "12px"
					} }, "雷达：", -1),
					s("div", {
						class: "RadarTime__station-trigger",
						onClick: Ee
					}, [s("span", he, g(M.value?.ld_name || "选择雷达站"), 1), s("span", { class: u(["RadarTime__arrow", { "is-open": N.value }]) }, "▼", 2)]),
					v(s("div", ge, [(p(!0), o(r, null, h(j.value, (e, t) => (p(), o("div", {
						key: t,
						class: u(["RadarTime__station-item", { "is-selected": M.value?.ldCode === e.ld_code }]),
						onClick: (t) => De(e)
					}, g(e.ld_name), 11, _e))), 128))], 512), [[_, N.value]])
				], 512)])) : a("", !0),
				s("div", ve, [s("div", ye, [s("button", {
					class: u(["RadarTime__play-btn", { playing: E.value }]),
					onClick: Pe
				}, [E.value ? (p(), o("svg", xe, [...i[6] ||= [s("path", { d: "M6 4h4v16H6V4zm8 0h4v16h-4V4z" }, null, -1)]])) : (p(), o("svg", be, [...i[5] ||= [s("path", { d: "M8 5v14l11-7z" }, null, -1)]]))], 2)]), s("div", {
					class: "RadarTime__track-wrapper",
					ref_key: "trackWrapper",
					ref: W,
					onMousedown: Me,
					onMousemove: Ne,
					onMouseup: K,
					onMouseleave: K
				}, [
					s("div", Se, [s("div", {
						class: "RadarTime__track-section RadarTime__track-live",
						style: d({ width: U.value + "%" })
					}, [...i[7] ||= [s("span", { class: "RadarTime__section-label" }, "实况", -1)]], 4), s("div", {
						class: "RadarTime__track-section RadarTime__track-forecast",
						style: d({ width: 100 - U.value + "%" })
					}, [...i[8] ||= [s("span", {
						class: "RadarTime__section-label",
						style: { color: "#fff" }
					}, "外推", -1)]], 4)]),
					s("div", Ce, [(p(!0), o(r, null, h(D.value, (e, t) => (p(), o("div", {
						key: t,
						class: u(["RadarTime__tick", { active: A.value === t }]),
						style: d({ left: Ae(t) + "%" }),
						onClick: y((e) => X(t), ["stop"])
					}, [...i[9] ||= [s("div", { class: "RadarTime__tick-dot" }, null, -1)]], 14, we))), 128))]),
					s("div", {
						class: "RadarTime__indicator",
						style: d({ left: ke.value + "%" }),
						ref_key: "positionIndicator",
						ref: je
					}, null, 4)
				], 544)])
			])])), [[c, T.value]]);
		};
	}
}), [["__scopeId", "data-v-7f07a478"]]);
//#endregion
export { S as t };
