var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellTopology/TopologyOverviewHud.tsx
var TopologyOverviewHud_exports = {};
__export(TopologyOverviewHud_exports, {
  TopologyOverviewHud: () => TopologyOverviewHud
});
module.exports = __toCommonJS(TopologyOverviewHud_exports);
var import_react = __toESM(require("react"));
var import_topologyElementKinds = require("./topologyElementKinds");
var import_TopologyIcons = require("./icons/TopologyIcons");
var import_TopologyOverviewHud = require("./TopologyOverviewHud.less");
var PREFIX = "pisell-topology-overview-hud";
var KIND_META = {
  [import_topologyElementKinds.TOPOLOGY_ROUTER_KIND]: { label: "Router", Icon: import_TopologyIcons.TopologyRouterIcon },
  [import_topologyElementKinds.TOPOLOGY_SWITCH_KIND]: { label: "Switch", Icon: import_TopologyIcons.TopologySwitchIcon },
  [import_topologyElementKinds.TOPOLOGY_AP_KIND]: { label: "AP", Icon: import_TopologyIcons.TopologyApIcon },
  [import_topologyElementKinds.TOPOLOGY_GATE_KIND]: { label: "Gate", Icon: import_TopologyIcons.TopologyGateIcon },
  [import_topologyElementKinds.TOPOLOGY_CASHIER_KIND]: { label: "Cashier", Icon: import_TopologyIcons.TopologyCashierIcon },
  [import_topologyElementKinds.TOPOLOGY_KIOSK_KIND]: { label: "Kiosk", Icon: import_TopologyIcons.TopologyKioskIcon },
  [import_topologyElementKinds.TOPOLOGY_INTEGRATED_POS_KIND]: {
    label: "POS",
    Icon: import_TopologyIcons.TopologyIntegratedPosIcon
  },
  [import_topologyElementKinds.TOPOLOGY_PRINTER_KIND]: { label: "打印机", Icon: import_TopologyIcons.TopologyPrinterIcon },
  [import_topologyElementKinds.TOPOLOGY_AMUSEMENT_KIND]: {
    label: "Amusement",
    Icon: import_TopologyIcons.TopologyAmusementIcon
  }
};
function countPorts(edges) {
  if (!(edges == null ? void 0 : edges.length)) return 0;
  const labels = /* @__PURE__ */ new Set();
  for (const e of edges) {
    if (e.sourceLabel) labels.add(`${e.id}:s:${e.sourceLabel}`);
    if (e.targetLabel) labels.add(`${e.id}:t:${e.targetLabel}`);
  }
  return labels.size || edges.length * 2;
}
function TopologyOverviewHud(props) {
  const { items, dataSources, edges } = props;
  const chips = (0, import_react.useMemo)(() => {
    var _a;
    const deviceRows = (dataSources == null ? void 0 : dataSources.devices) ?? [];
    const statusByRecord = new Map(
      deviceRows.map((r) => [String(r.id), r.status ?? "online"])
    );
    const byKind = /* @__PURE__ */ new Map();
    for (const item of items) {
      const kind = item.elementKind;
      if (!kind || !KIND_META[kind]) continue;
      const cur = byKind.get(kind) ?? { total: 0, online: 0 };
      cur.total += 1;
      const binding = (_a = item._sceneElement) == null ? void 0 : _a.dataBinding;
      const st = (binding == null ? void 0 : binding.recordId) ? statusByRecord.get(String(binding.recordId)) : "online";
      if (st === "online") cur.online += 1;
      byKind.set(kind, cur);
    }
    return Object.entries(KIND_META).map(([kind, meta]) => {
      const c = byKind.get(kind);
      if (!c || c.total === 0) return null;
      return { kind, ...meta, ...c };
    }).filter(Boolean);
  }, [items, dataSources]);
  const portCount = countPorts(edges);
  return /* @__PURE__ */ import_react.default.createElement("div", { className: PREFIX }, /* @__PURE__ */ import_react.default.createElement("div", { className: `${PREFIX}__title` }, "Actual Topology"), /* @__PURE__ */ import_react.default.createElement("ul", { className: `${PREFIX}__chips` }, chips.map((chip) => /* @__PURE__ */ import_react.default.createElement("li", { key: chip.kind, className: `${PREFIX}__chip` }, /* @__PURE__ */ import_react.default.createElement(chip.Icon, null), /* @__PURE__ */ import_react.default.createElement("span", null, chip.online, "/", chip.total))), portCount > 0 ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("li", { className: `${PREFIX}__sep`, "aria-hidden": true }, "|"), /* @__PURE__ */ import_react.default.createElement("li", { className: `${PREFIX}__chip` }, /* @__PURE__ */ import_react.default.createElement("span", { className: `${PREFIX}__ports` }, "Ports ", portCount))) : null));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  TopologyOverviewHud
});
