function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import React from 'react';
import classNames from 'classnames';
import { locales } from '@pisell/utils';
import { TOPOLOGY_KIND_ICONS, TopologyRouterIcon } from "./icons/TopologyIcons";
import "./TopologyDeviceCard.less";
var PREFIX = 'pisell-topology-device-card';
var I18N_STATUS = 'pisell-topology.device-status';
function statusLabel(status) {
  var key = "".concat(I18N_STATUS, ".").concat(status);
  var text = locales.getText(key);
  return text !== key ? text : status;
}

/** 拓扑图元卡片：左上状态、中部图标、底部名称 + IP */
export function TopologyDeviceCard(props) {
  var _item$elementKind, _TOPOLOGY_KIND_ICONS$, _item$_sceneElement, _item$name, _device$name, _device$model, _device$status, _device$ip;
  var item = props.item,
    device = props.device;
  var kind = (_item$elementKind = item.elementKind) !== null && _item$elementKind !== void 0 ? _item$elementKind : '';
  var Icon = (_TOPOLOGY_KIND_ICONS$ = TOPOLOGY_KIND_ICONS[kind]) !== null && _TOPOLOGY_KIND_ICONS$ !== void 0 ? _TOPOLOGY_KIND_ICONS$ : TopologyRouterIcon;

  /**
   * Ghost：sceneElement 是已保存的，但当前 device 接口里没匹配到这个 recordId。
   * 这里走两条线：
   * - 卡片整体加 `--ghost` 类，渲染灰色虚框 + 低透明
   * - 状态徽标改用「已下线 / removed」文案
   */
  var 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) : undefined;
  var isGhost = recordId != null && device == null;
  var 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);
  var status = isGhost ? 'unknown' : (_device$status = device === null || device === void 0 ? void 0 : device.status) !== null && _device$status !== void 0 ? _device$status : 'online';
  var ip = device === null || device === void 0 || (_device$ip = device.ip) === null || _device$ip === void 0 ? void 0 : _device$ip.trim();
  var statusText = isGhost ? locales.getText('pisell-topology.device-status.removed') : statusLabel(status);
  return /*#__PURE__*/React.createElement("div", {
    className: classNames(PREFIX, _defineProperty({}, "".concat(PREFIX, "--ghost"), isGhost))
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__main")
  }, /*#__PURE__*/React.createElement("span", {
    className: classNames("".concat(PREFIX, "__status"), isGhost ? "".concat(PREFIX, "__status--removed") : "".concat(PREFIX, "__status--").concat(status))
  }, statusText), /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__icon")
  }, /*#__PURE__*/React.createElement(Icon, null))), /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__footer")
  }, /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__name"),
    title: title
  }, title), ip ? /*#__PURE__*/React.createElement("div", {
    className: "".concat(PREFIX, "__ip"),
    title: ip
  }, ip) : null));
}