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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
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); }
export var DEVICE_ICON_COLOR = {
  smart: '#1677ff',
  dumb: '#faad14',
  integrated: '#389e0d'
};
export var CONNECTION_TYPE_OPTIONS = [{
  label: 'USB',
  value: 'usb'
}, {
  label: 'Ethernet',
  value: 'ethernet'
}, {
  label: 'WiFi',
  value: 'wifi'
}, {
  label: 'Bluetooth',
  value: 'bluetooth'
}, {
  label: 'Serial',
  value: 'serial'
}];
export var BRAND_OPTION_SEPARATOR = '__';
export var getBrandOptionValue = function getBrandOptionValue(brand) {
  return "".concat(brand.id).concat(BRAND_OPTION_SEPARATOR).concat(brand.code);
};
export var getBrandCodeFromOptionValue = function getBrandCodeFromOptionValue(value) {
  return value === null || value === void 0 ? void 0 : value.split(BRAND_OPTION_SEPARATOR).slice(1).join(BRAND_OPTION_SEPARATOR);
};
export var getModelConnectionTypes = function getModelConnectionTypes(model) {
  var _model$data;
  var connections = (_model$data = model.data) === null || _model$data === void 0 ? void 0 : _model$data.connection_types;
  return Array.isArray(connections) ? connections.map(function (item) {
    return String(item || '').trim();
  }).filter(Boolean) : [];
};
export var getConnectionTypeLabel = function getConnectionTypeLabel(value) {
  var _CONNECTION_TYPE_OPTI;
  if (!value) return '-';
  var normalizedValue = value.toLowerCase().trim();
  return ((_CONNECTION_TYPE_OPTI = CONNECTION_TYPE_OPTIONS.find(function (option) {
    return option.value === normalizedValue;
  })) === null || _CONNECTION_TYPE_OPTI === void 0 ? void 0 : _CONNECTION_TYPE_OPTI.label) || value;
};
export var isProfileRequired = function isProfileRequired(model) {
  var _model$data2;
  return Boolean(model === null || model === void 0 || (_model$data2 = model.data) === null || _model$data2 === void 0 || (_model$data2 = _model$data2.profile_structure) === null || _model$data2 === void 0 ? void 0 : _model$data2.required);
};
export var flattenDeviceModels = function flattenDeviceModels(types) {
  var modelMap = new Map();
  types.forEach(function (type) {
    (type.active_models || []).forEach(function (model) {
      if (!modelMap.has(model.code)) {
        modelMap.set(model.code, _objectSpread(_objectSpread({}, model), {}, {
          type: model.type || type
        }));
      }
    });
  });
  return Array.from(modelMap.values());
};
export var createDeviceRow = function createDeviceRow(item, translation) {
  var _item$type, _item$model, _item$profile;
  var name = translation(item.name);
  var typeName = translation((_item$type = item.type) === null || _item$type === void 0 ? void 0 : _item$type.name) || item.type_code;
  var modelName = translation((_item$model = item.model) === null || _item$model === void 0 ? void 0 : _item$model.name) || item.model_code;
  var link = item.link || 'unlinked';
  var profileName = translation((_item$profile = item.profile) === null || _item$profile === void 0 ? void 0 : _item$profile.name) || (item.profile_id ? String(item.profile_id) : '-');
  return {
    id: item.id,
    name: name,
    typeName: typeName,
    modelName: modelName,
    profileName: profileName,
    link: link,
    status: link === 'linked' ? item.status || 'offline' : 'unknown',
    typeCode: item.type_code,
    modelCode: item.model_code,
    _raw: item
  };
};