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/saasDevice/appPeripheral/utils/peripheralCardModel.ts
var peripheralCardModel_exports = {};
__export(peripheralCardModel_exports, {
  createPeripheralConnectionCardModel: () => createPeripheralConnectionCardModel
});
module.exports = __toCommonJS(peripheralCardModel_exports);
var import_utils = require("../utils");
var import_peripheralRuntime = require("./peripheralRuntime");
var createPeripheralConnectionCardModel = ({
  row,
  runtimeOverlay,
  getText,
  translation
}) => {
  var _a, _b, _c, _d, _e, _f;
  const { connection } = row;
  const peripheral = row.peripheral || void 0;
  const physicalDevice = (runtimeOverlay == null ? void 0 : runtimeOverlay.physicalDevice) || row.physical;
  const status = (() => {
    if ((runtimeOverlay == null ? void 0 : runtimeOverlay.status) === "select") return "connecting";
    if (runtimeOverlay == null ? void 0 : runtimeOverlay.status) return runtimeOverlay.status;
    if (physicalDevice) {
      return physicalDevice.is_connect ? "connected" : "disconnected";
    }
    return "connecting";
  })();
  const isSelectAction = (runtimeOverlay == null ? void 0 : runtimeOverlay.status) === "select";
  const isUsageAction = status === "connected" && (peripheral == null ? void 0 : peripheral.type_code) === "label_printer" && !row.usage;
  const connectionDetail = (0, import_peripheralRuntime.getPhysicalDeviceDisplay)(physicalDevice) || (((_a = connection.config) == null ? void 0 : _a.connection_ip) ? String(connection.config.connection_ip) : "");
  const typeName = peripheral ? translation((_b = peripheral.type) == null ? void 0 : _b.name) || peripheral.type_code : "-";
  const workAreaName = translation((_c = peripheral == null ? void 0 : peripheral.workarea) == null ? void 0 : _c.name);
  const profileIdSet = new Set((connection.profile_ids || []).map(Number));
  const selectedProfiles = (connection.profiles || []).filter(
    (profile) => profileIdSet.has(Number(profile.id))
  );
  return {
    connection,
    peripheral,
    physicalDevice,
    status,
    title: peripheral ? translation(peripheral.name) || String(peripheral.id) : "-",
    subtitle: peripheral && workAreaName ? `${typeName} @ ${workAreaName}` : typeName,
    modelName: translation((_d = peripheral == null ? void 0 : peripheral.model) == null ? void 0 : _d.name) || (peripheral == null ? void 0 : peripheral.model_code) || "-",
    connectionTypeLabel: (0, import_utils.getConnectionTypeLabel)((_e = connection.config) == null ? void 0 : _e.connection_type),
    connectionDetail,
    profileLabels: selectedProfiles.length ? selectedProfiles.map((profile) => translation(profile.name) || profile.id) : [],
    icon: ((_f = peripheral == null ? void 0 : peripheral.type) == null ? void 0 : _f.icon) || "PrinterOutlined",
    canTest: status === "connected" && !isUsageAction && import_peripheralRuntime.TESTABLE_PRINTER_TYPES.includes((peripheral == null ? void 0 : peripheral.type_code) || ""),
    canConnect: status !== "connected" || isUsageAction,
    isSelectAction,
    isUsageAction,
    actionText: isSelectAction ? getText("pisell2.saas.app-peripheral.select") : isUsageAction ? getText("pisell2.saas.app-peripheral.print-usage-title") : status === "connecting" ? getText("pisell2.saas.app-peripheral.connecting") : getText("pisell2.saas.app-peripheral.connect"),
    actionDisabled: status === "connecting" && !isSelectAction,
    canDisconnect: status === "connected"
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  createPeripheralConnectionCardModel
});
