import { n as e, r as t } from "./component-AqiMonitor-BUy1MSaP.mjs";
import { n } from "./component-GeologyLiveAlarm-DVTs1YA3.mjs";
import { ElIcon as r, ElLoadingDirective as i, ElRadio as a, ElRadioGroup as o } from "element-plus/es";
import { Fragment as s, computed as c, createCommentVNode as l, createElementBlock as u, createElementVNode as d, createTextVNode as f, createVNode as p, defineComponent as m, nextTick as h, normalizeClass as g, normalizeStyle as ee, onBeforeUnmount as te, onMounted as ne, openBlock as _, ref as v, renderList as y, toDisplayString as b, unref as x, vShow as S, withCtx as C, withDirectives as w } from "vue";
import { ArrowRight as T } from "@element-plus/icons-vue";
import * as re from "echarts";
import "element-plus/es/components/loading/style/css";
import "element-plus/es/components/radio/style/css";
import "element-plus/es/components/radio-group/style/css";
//#region src/assets/img/icons/水库.png
var ie = "data:image/png;base64, ", ae = {
	class: "ReservoirLiveAlarm",
	"element-loading-background": "rgba(0, 0, 0, 0.4)"
}, oe = {
	key: 0,
	class: "voice-permission-mask"
}, se = { class: "ReservoirLiveAlarm-head" }, ce = { class: "ReservoirLiveAlarm-head-top" }, le = { class: "head-actions" }, ue = { class: "view-switch" }, de = { class: "ReservoirLiveAlarm-chart" }, fe = { class: "ReservoirLiveAlarm-setting-panel" }, pe = { class: "display-setting" }, me = { class: "setting-row" }, he = { class: "ReservoirLiveAlarm-table" }, ge = { class: "table-body" }, _e = ["onClick"], ve = { class: "name" }, ye = ["onClick"], be = {
	key: 0,
	style: { color: "red" }
}, xe = { class: "station-panel" }, Se = { class: "station-head" }, Ce = { class: "metric-head" }, we = { class: "label" }, Te = {
	key: 0,
	class: "warn-count"
}, Ee = { class: "metric-head" }, De = { class: "label" }, Oe = {
	key: 0,
	class: "warn-count"
}, ke = {
	key: 0,
	class: "station-body"
}, Ae = ["onClick"], je = { class: "metric-value" }, Me = { class: "metric-value" }, Ne = {
	key: 1,
	class: "station-empty"
}, Pe = {
	key: 0,
	class: "detail-popup-dialog"
}, Fe = { class: "detail-popup-head" }, Ie = { class: "detail-popup-title" }, Le = { class: "detail-popup-row" }, Re = { class: "detail-popup-row" }, ze = { class: "detail-popup-row" }, Be = { class: "detail-popup-row" }, Ve = { class: "detail-popup-row" }, He = { class: "detail-popup-row" }, Ue = { key: 0 }, We = {
	key: 0,
	style: { "margin-right": "10px" }
}, Ge = { key: 1 }, Ke = { key: 1 }, E = "当前暂无报警", D = /* @__PURE__ */ e(/* @__PURE__ */ m({
	__name: "ReservoirLiveAlarm",
	props: {
		appKey: {
			type: String,
			default: ""
		},
		appSalt: {
			type: String,
			default: ""
		},
		baseHttp: {
			type: String,
			default: ""
		},
		ids: {
			type: Object,
			default: () => ({})
		}
	},
	emits: [
		"addMarker",
		"close",
		"removeMarker",
		"addDataTitle",
		"removeDataTitle",
		"toMapView"
	],
	setup(e, { emit: m }) {
		let D = e, O = m, qe = v([]), k = v(""), A = v(!1), j = v(null), M = v(null), N = v("table"), P = v("1h降水"), F = v(!1), I = v(!1), L = v({}), R = v("水库点观测时间：--"), z = v([]), B = v({}), V = v({}), H = null, Je = c(() => k.value === E ? "#52c41a" : "#ff4d4f"), U = (e) => (e || []).filter((e) => X(e)).length, W = () => H || (H = new Audio(n), H.preload = "auto", H), Ye = () => new Promise((e) => {
			let t = W();
			t.volume = 0, t.currentTime = 0;
			let n = t.play();
			if (!n) {
				F.value = !0, e();
				return;
			}
			n.then(() => {
				t.pause(), t.volume = 1, e();
			}).catch(() => {
				F.value = !0, e();
			});
		}), G = () => {
			let e = W();
			e.volume = 1, e.currentTime = 0, e.play().catch(() => {});
		}, Xe = () => {
			let e = W();
			e.volume = 0, e.currentTime = 0;
			let t = e.play();
			if (!t) {
				F.value = !1;
				return;
			}
			t.then(() => {
				e.pause(), F.value = !1, k.value !== E && G();
			}).catch(() => {});
		}, Ze = c(() => Q(z.value, (e) => Z(e.tags)));
		ne(() => {
			K(), j.value = setInterval(() => {
				K();
			}, 1e3 * 60 * 10);
		}), te(() => {
			j.value && clearInterval(j.value), H && (H.pause(), H.currentTime = 0), M.value?.dispose(), M.value = null;
		});
		let K = async () => {
			A.value = !0;
			let e = await t({
				appKey: D.appKey,
				appSalt: D.appSalt,
				id: D.ids.data.id,
				variables: {},
				baseHttp: D.baseHttp,
				reqType: D.ids.data.reqType,
				isFormData: D.ids.data.isFormData
			});
			A.value = !1;
			let n = e.data.result.ds;
			console.log("得到数据", JSON.parse(JSON.stringify(n))), qe.value = n;
			let r = R.value, i = $e(n);
			R.value = i, O("removeDataTitle", r), setTimeout(() => {
				O("addDataTitle", i);
			}, 1e3);
			let a = [], o = [], s = 0, c = 0, l = 0, u = 0;
			n.forEach((e) => {
				let t = tt(e), n = Q(e.skzhds || [], (e) => X(e));
				s += n.length, n.forEach((e) => {
					X(e) && c++, e?.iswarnpre === 1 && l++, e?.iswarnpre_6 === 1 && u++;
				}), o.push({
					name: e.name,
					stations: n,
					warnCount: rt(n),
					tags: nt(t)
				});
			});
			let d = s - c;
			a.push({
				value: d,
				name: "正常",
				itemStyle: { color: "#52c41a" },
				label: { color: "#52c41a" }
			}, {
				value: c,
				name: "报警",
				itemStyle: { color: "#ff4d4f" },
				label: { color: "#ff4d4f" }
			}), z.value = o, o.length > 0 && (B.value[o[0].name] = !0), o.forEach((e) => {
				V.value[e.name] = !0;
			}), $(), k.value = it(o), await Ye(), c > 0 && G(), at(a);
		}, Qe = (e) => {
			I.value = !1, O("toMapView", {
				lng: e.longitude,
				lat: e.latitude,
				zoom: 12
			});
		}, q = (e) => {
			let t = Number(e);
			return t < 999999 && t > -999999;
		}, J = (e, t, n = 1) => {
			let r = Number(e);
			return q(r) ? `${r.toFixed(n)}${t}` : "";
		}, Y = (e, t = 1) => {
			let n = Number(e);
			return q(n) ? n.toFixed(t) : "--";
		}, X = (e) => e?.iswarnpre === 1 || e?.iswarnpre_6 === 1, Z = (e) => e.some((e) => e.warn), Q = (e, t) => [...e].sort((e, n) => Number(t(n)) - Number(t(e))), $e = (e) => {
			let t = (e || []).find((e) => (e?.skzhds || []).length)?.skzhds?.[0]?.observation_time;
			return t ? `水库点观测时间：${String(t).replace("T", " ").slice(0, 13)}时` : "水库点观测时间：--";
		}, et = (e, t, n) => e.find((e) => e?.[t] === 1 && q(e?.[n])) || e.find((e) => e?.[t] === 1), tt = (e) => {
			let t = e.skzhds || [], n = et(t, "iswarnpre", "rainfall_1h"), r = et(t, "iswarnpre_6", "rainfall_6h");
			return {
				iswarnrainfall_1h: n ? 1 : 0,
				iswarnrainfall_6h: r ? 1 : 0,
				rainfallWarnStation: n,
				rainfall6hWarnStation: r
			};
		}, nt = (e) => [{
			label: "1h降水",
			warn: e.iswarnrainfall_1h === 1,
			value: e.iswarnrainfall_1h ? J(e.rainfallWarnStation?.rainfall_1h, "mm", 1) : ""
		}, {
			label: "6h降水",
			warn: e.iswarnrainfall_6h === 1,
			value: e.iswarnrainfall_6h ? J(e.rainfall6hWarnStation?.rainfall_6h, "mm", 1) : ""
		}], rt = (e) => ({
			rainfall_1h: e.filter((e) => e?.iswarnpre === 1).length,
			rainfall_6h: e.filter((e) => e?.iswarnpre_6 === 1).length
		}), it = (e) => {
			let t = e.filter((e) => e.warnCount.rainfall_1h > 0 || e.warnCount.rainfall_6h > 0);
			return t.length ? t.map((e) => {
				let t = [];
				return e.warnCount.rainfall_1h > 0 && t.push("1h降水报警"), e.warnCount.rainfall_6h > 0 && t.push("6h降水报警"), `${e.name}：${t.join("、")}`;
			}).join("；") : E;
		}, at = (e) => {
			let t = document.querySelector(".ReservoirLiveAlarm-chart");
			if (!t) return;
			M.value ||= re.init(t);
			let n = {
				tooltip: {
					trigger: "item",
					formatter: (e) => `${e?.name ?? ""}: ${e?.value ?? 0}个`
				},
				color: "#52c41a",
				grid: {
					top: "0",
					right: "0",
					bottom: "0",
					left: "0"
				},
				series: [{
					type: "pie",
					radius: "40%",
					label: {
						show: !0,
						position: "outside",
						fontSize: 12,
						color: "#fff"
					},
					data: e
				}]
			};
			M.value.setOption(n);
		}, ot = async (e) => {
			N.value = e, e === "chart" && (await h(), M.value?.resize());
		}, $ = () => {
			let e = {
				clickOpen: !1,
				spotObject: [{
					offsetX: -20,
					offsetY: -15,
					spotArrone: []
				}],
				drawArrObj: [],
				onlyLayerID: "geo"
			}, t = [];
			z.value.flatMap((e) => e.stations || []).forEach((n, r) => {
				t.push({
					id: `marker_${r}`,
					data: n
				});
				let i = `
      <div id="marker_${r}" style="display:flex;align-items:center;justify-content:center;flex-direction:column;cursor:pointer;" title="${n.reservoir_name}">
        <div style="color:#fff;font-size:12px;text-align:center;line-height:1.4;text-shadow:1px 0 #000,-1px 0 #000,0 1px #000,0 -1px #000,1px 1px #000,-1px -1px #000,1px -1px #000,-1px 1px #000">
          ${Y(P.value === "1h降水" ? n.rainfall_1h : n.rainfall_6h)}mm
        </div>
        <img src="${ie}" alt="地质灾害" style="width: 24px; height: 24px;">
      </div>
    `, a = {
					lng: n.longitude,
					lat: n.latitude,
					htmlString: i,
					otherData: { markId: "geo" }
				};
				e.spotObject[0].spotArrone.push(a);
			}), O("addMarker", {
				mapMarker: e,
				removeMarker: "geo"
			}), setTimeout(() => {
				t.forEach((e) => {
					document.getElementById(e.id)?.addEventListener("click", () => {
						I.value = !0, L.value = e.data;
					});
				});
			}, 1e3);
		}, st = (e) => {
			B.value[e] = !B.value[e];
		}, ct = (e) => {
			V.value[e] = !V.value[e];
		}, lt = () => {
			O("close", "ReservoirLiveAlarm");
		}, ut = () => {
			I.value = !1;
		};
		return (e, t) => {
			let n = a, c = o, m = r, h = i;
			return _(), u(s, null, [w((_(), u("div", ae, [
				F.value ? (_(), u("div", oe, [d("div", { class: "voice-permission-dialog" }, [
					t[3] ||= d("div", { class: "voice-permission-title" }, "播报报警需要授权", -1),
					t[4] ||= d("div", { class: "voice-permission-desc" }, "请点击下方按钮开启播报报警", -1),
					d("button", {
						class: "voice-permission-btn",
						onClick: Xe
					}, "开启")
				])])) : l("", !0),
				d("div", se, [d("div", ce, [t[5] ||= d("div", null, "水库灾害实况报警", -1), d("div", le, [d("div", ue, [d("button", {
					class: g(["switch-btn", { active: N.value === "chart" }]),
					onClick: t[0] ||= (e) => ot("chart")
				}, " 图表 ", 2), d("button", {
					class: g(["switch-btn", { active: N.value === "table" }]),
					onClick: t[1] ||= (e) => ot("table")
				}, " 表格 ", 2)]), d("div", {
					class: "closeBtn",
					onClick: lt,
					title: "关闭"
				})])]), t[6] ||= d("img", {
					class: "ReservoirLiveAlarm-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)]),
				w(d("div", {
					class: "ReservoirLiveAlarm-summary",
					style: ee({ color: Je.value })
				}, b(k.value), 5), [[S, N.value === "chart"]]),
				w(d("div", de, null, 512), [[S, N.value === "chart"]]),
				w(d("div", fe, [d("div", pe, [d("div", me, [t[9] ||= d("span", { class: "setting-label" }, "地图要素：", -1), p(c, {
					modelValue: P.value,
					"onUpdate:modelValue": t[2] ||= (e) => P.value = e,
					class: "setting-radios",
					onChange: $
				}, {
					default: C(() => [p(n, { value: "1h降水" }, {
						default: C(() => [...t[7] ||= [f("1h降水", -1)]]),
						_: 1
					}), p(n, { value: "6h降水" }, {
						default: C(() => [...t[8] ||= [f("6h降水", -1)]]),
						_: 1
					})]),
					_: 1
				}, 8, ["modelValue"])])])], 512), [[S, N.value === "table"]]),
				w(d("div", he, [t[16] ||= d("div", { class: "table-head" }, [
					d("span", null, "水库类别"),
					d("span", null, "状态要素"),
					d("span", { class: "head-arrow" })
				], -1), d("div", ge, [(_(!0), u(s, null, y(Ze.value, (e) => (_(), u("div", {
					class: "table-row",
					key: e.name
				}, [
					d("div", {
						class: "table-row-main",
						onClick: (t) => st(e.name)
					}, [
						d("span", ve, b(e.name), 1),
						d("div", { class: g(["status-tags", { "has-warn": Z(e.tags) }]) }, [(_(!0), u(s, null, y(e.tags, (t) => (_(), u("span", {
							class: g(["status-tag", { warn: t.warn }]),
							key: `${e.name}-${t.label}`
						}, [d("span", null, b(t.label), 1)], 2))), 128))], 2),
						d("span", {
							class: g(["expand-arrow", { expanded: B.value[e.name] }]),
							"aria-hidden": "true"
						}, [p(m, null, {
							default: C(() => [p(x(T))]),
							_: 1
						})], 2)
					], 8, _e),
					w(d("div", {
						class: "station-title",
						onClick: (t) => ct(e.name)
					}, [d("span", null, [t[10] ||= f(" 水库点数据 ", -1), U(e.stations) > 0 ? (_(), u("span", be, " （报警数量：" + b(U(e.stations)) + "个） ", 1)) : l("", !0)]), d("span", { class: g(["panel-arrow", { expanded: V.value[e.name] }]) }, [p(m, null, {
						default: C(() => [p(x(T))]),
						_: 1
					})], 2)], 8, ye), [[S, B.value[e.name]]]),
					w(d("div", xe, [d("div", Se, [
						t[15] ||= d("span", null, "水库点", -1),
						d("span", Ce, [d("span", we, [t[11] ||= f(" 1h降水 ", -1), e.warnCount.rainfall_1h > 0 ? (_(), u("span", Te, b(e.warnCount.rainfall_1h) + "条 ", 1)) : l("", !0)]), t[12] ||= d("span", { class: "unit" }, "(mm)", -1)]),
						d("span", Ee, [d("span", De, [t[13] ||= f(" 6h降水 ", -1), e.warnCount.rainfall_6h > 0 ? (_(), u("span", Oe, b(e.warnCount.rainfall_6h) + "条 ", 1)) : l("", !0)]), t[14] ||= d("span", { class: "unit" }, "(mm)", -1)])
					]), e.stations.length ? (_(), u("div", ke, [(_(!0), u(s, null, y(e.stations, (t) => (_(), u("div", {
						class: g(["station-row", { "is-warn": X(t) }]),
						key: `${e.name}-${t.reservoir_name}`,
						onClick: (e) => Qe(t)
					}, [
						d("span", null, b(t.reservoir_name || "--"), 1),
						d("span", je, b(Y(t.rainfall_1h)), 1),
						d("span", Me, b(Y(t.rainfall_6h)), 1)
					], 10, Ae))), 128))])) : (_(), u("div", Ne, "暂无站点数据"))], 512), [[S, B.value[e.name] && V.value[e.name]]])
				]))), 128))])], 512), [[S, N.value === "table"]])
			])), [[h, A.value]]), I.value ? (_(), u("div", Pe, [
				d("div", Fe, [d("span", Ie, b(L.value.name), 1), d("span", {
					class: "detail-popup-close",
					onClick: ut,
					title: "关闭"
				})]),
				d("div", Le, [t[17] ||= d("div", null, "水库点", -1), d("div", null, b(L.value.reservoir_name), 1)]),
				d("div", Re, [t[18] ||= d("div", null, "观测时间", -1), d("div", null, b(L.value.observation_time), 1)]),
				d("div", ze, [t[19] ||= d("div", null, "关联自动站", -1), d("div", null, b(L.value.station_name) + "（" + b(L.value.station_number) + "）", 1)]),
				d("div", Be, [t[20] ||= d("div", null, "经度", -1), d("div", null, b(L.value.longitude), 1)]),
				d("div", Ve, [t[21] ||= d("div", null, "纬度", -1), d("div", null, b(L.value.latitude), 1)]),
				d("div", He, [t[22] ||= d("div", null, "是否报警", -1), L.value.iswarnpre || L.value.iswarnpre_6 ? (_(), u("div", Ue, [L.value.iswarnpre ? (_(), u("span", We, "1h降水")) : l("", !0), L.value.iswarnpre_6 ? (_(), u("span", Ge, "6h降水")) : l("", !0)])) : (_(), u("div", Ke, "无"))])
			])) : l("", !0)], 64);
		};
	}
}), [["__scopeId", "data-v-4f49313f"]]);
//#endregion
export { D as t };
