import useEngineContext from "../../hooks/useEngineContext.js";
import { getTopologyText, resolveTopologyDisplayLocale } from "./topologyLocale.js";
import { TOPOLOGY_KIND_ICONS, TopologyRouterIcon } from "./icons/TopologyIcons.js";
import React from "react";
import classNames from "classnames";
import "./TopologyDeviceCard.less";
//#region src/plus/pisellTopology/TopologyDeviceCard.tsx
const PREFIX = "pisell-topology-device-card";
const I18N_STATUS = "pisell-topology.device-status";
function statusLabel(status, displayLocale) {
	var _getTopologyText;
	return (_getTopologyText = getTopologyText(`${I18N_STATUS}.${status}`, displayLocale)) !== null && _getTopologyText !== void 0 ? _getTopologyText : status;
}
/** 拓扑图元卡片：左上状态、中部图标、底部名称 + IP */
function TopologyDeviceCard(props) {
	var _item$elementKind, _TOPOLOGY_KIND_ICONS$, _item$_sceneElement, _item$name, _device$name, _device$model, _device$status, _device$ip;
	const { item, device } = props;
	const kind = (_item$elementKind = item.elementKind) !== null && _item$elementKind !== void 0 ? _item$elementKind : "";
	const Icon = (_TOPOLOGY_KIND_ICONS$ = TOPOLOGY_KIND_ICONS[kind]) !== null && _TOPOLOGY_KIND_ICONS$ !== void 0 ? _TOPOLOGY_KIND_ICONS$ : TopologyRouterIcon;
	const displayLocale = resolveTopologyDisplayLocale(useEngineContext());
	/**
	* Ghost：sceneElement 是已保存的，但当前 device 接口里没匹配到这个 recordId。
	* 这里走两条线：
	* - 卡片整体加 `--ghost` 类，渲染灰色虚框 + 低透明
	* - 状态徽标改用「已下线 / removed」文案
	*/
	const recordId = ((_item$_sceneElement = item._sceneElement) === null || _item$_sceneElement === void 0 || (_item$_sceneElement = _item$_sceneElement.dataBinding) === null || _item$_sceneElement === void 0 ? void 0 : _item$_sceneElement.recordId) != null ? String(item._sceneElement.dataBinding.recordId) : void 0;
	const isGhost = recordId != null && device == null;
	const title = ((_item$name = item.name) === null || _item$name === void 0 ? void 0 : _item$name.trim()) || (device === null || device === void 0 || (_device$name = device.name) === null || _device$name === void 0 ? void 0 : _device$name.trim()) || (device === null || device === void 0 || (_device$model = device.model) === null || _device$model === void 0 ? void 0 : _device$model.trim()) || (isGhost ? recordId : kind);
	const status = isGhost ? "unknown" : (_device$status = device === null || device === void 0 ? void 0 : device.status) !== null && _device$status !== void 0 ? _device$status : "online";
	const ip = device === null || device === void 0 || (_device$ip = device.ip) === null || _device$ip === void 0 ? void 0 : _device$ip.trim();
	const statusText = isGhost ? statusLabel("removed", displayLocale) : statusLabel(status, displayLocale);
	return /* @__PURE__ */ React.createElement("div", { className: classNames(PREFIX, { [`${PREFIX}--ghost`]: isGhost }) }, /* @__PURE__ */ React.createElement("div", { className: `${PREFIX}__main` }, /* @__PURE__ */ React.createElement("span", { className: classNames(`${PREFIX}__status`, isGhost ? `${PREFIX}__status--removed` : `${PREFIX}__status--${status}`) }, statusText), /* @__PURE__ */ React.createElement("div", { className: `${PREFIX}__icon` }, /* @__PURE__ */ React.createElement(Icon, null))), /* @__PURE__ */ React.createElement("div", { className: `${PREFIX}__footer` }, /* @__PURE__ */ React.createElement("div", {
		className: `${PREFIX}__name`,
		title
	}, title), ip ? /* @__PURE__ */ React.createElement("div", {
		className: `${PREFIX}__ip`,
		title: ip
	}, ip) : null));
}
//#endregion
export { TopologyDeviceCard };
