var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/pisellTopology/useTopologyDeviceDetail.ts
var useTopologyDeviceDetail_exports = {};
__export(useTopologyDeviceDetail_exports, {
  useTopologyDeviceDetail: () => useTopologyDeviceDetail
});
module.exports = __toCommonJS(useTopologyDeviceDetail_exports);
var import_react = require("react");
var import_model = require("../saasDevice/devicePlanning/model");
function buildInitialDeviceRow(recordId, raw, translation) {
  const _raw = {
    id: Number(recordId),
    type_kind: (raw == null ? void 0 : raw.type_kind) ?? "smart",
    type_code: (raw == null ? void 0 : raw.type_code) ?? "unknown",
    model_code: (raw == null ? void 0 : raw.model_code) ?? "",
    // ghost 节点（recordId 有但设备列表无匹配）raw 缺失时，用 #id 兜底，避免详情 404 回退后头部空白
    name: (raw == null ? void 0 : raw.name) ?? { original: `#${recordId}` },
    number: (raw == null ? void 0 : raw.number) ?? void 0,
    status: raw == null ? void 0 : raw.status,
    link: raw == null ? void 0 : raw.link,
    data: (raw == null ? void 0 : raw.data) ?? null,
    type: raw == null ? void 0 : raw.type,
    model: raw == null ? void 0 : raw.model
  };
  return (0, import_model.createDeviceRow)(_raw, translation);
}
function useTopologyDeviceDetail({
  rawDevices,
  translation
}) {
  const [open, setOpen] = (0, import_react.useState)(false);
  const [record, setRecord] = (0, import_react.useState)();
  const rawDevicesById = (0, import_react.useMemo)(
    () => new Map(rawDevices.map((d) => [String(d.id), d])),
    [rawDevices]
  );
  const openByItem = (0, import_react.useCallback)(
    (item) => {
      var _a, _b;
      const recordId = (_b = (_a = item._sceneElement) == null ? void 0 : _a.dataBinding) == null ? void 0 : _b.recordId;
      if (recordId == null) return;
      if (!Number.isFinite(Number(recordId))) return;
      const raw = rawDevicesById.get(String(recordId));
      setRecord(buildInitialDeviceRow(String(recordId), raw, translation));
      setOpen(true);
    },
    [rawDevicesById, translation]
  );
  const close = (0, import_react.useCallback)(() => setOpen(false), []);
  return { open, record, openByItem, close };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useTopologyDeviceDetail
});
