import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
//#region src/plus/saasDevice/appPeripheral/utils.ts
const DEVICE_ICON_COLOR = {
	smart: "#1677ff",
	dumb: "#faad14",
	integrated: "#389e0d"
};
const CONNECTION_TYPE_OPTIONS = [
	{
		label: "USB",
		value: "usb"
	},
	{
		label: "Ethernet",
		value: "ethernet"
	},
	{
		label: "WiFi",
		value: "wifi"
	},
	{
		label: "Bluetooth",
		value: "bluetooth"
	},
	{
		label: "Serial",
		value: "serial"
	}
];
const getBrandOptionValue = (brand) => `${brand.id}__${brand.code}`;
const getBrandCodeFromOptionValue = (value) => value === null || value === void 0 ? void 0 : value.split("__").slice(1).join("__");
const getModelConnectionTypes = (model) => {
	var _model$data;
	const connections = (_model$data = model.data) === null || _model$data === void 0 ? void 0 : _model$data.connection_types;
	return Array.isArray(connections) ? connections.map((item) => String(item || "").trim()).filter(Boolean) : [];
};
const getConnectionTypeLabel = (value) => {
	var _CONNECTION_TYPE_OPTI;
	if (!value) return "-";
	const normalizedValue = value.toLowerCase().trim();
	return ((_CONNECTION_TYPE_OPTI = CONNECTION_TYPE_OPTIONS.find((option) => option.value === normalizedValue)) === null || _CONNECTION_TYPE_OPTI === void 0 ? void 0 : _CONNECTION_TYPE_OPTI.label) || value;
};
const 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);
};
const flattenDeviceModels = (types) => {
	const modelMap = /* @__PURE__ */ new Map();
	types.forEach((type) => {
		(type.active_models || []).forEach((model) => {
			if (!modelMap.has(model.code)) modelMap.set(model.code, _objectSpread2(_objectSpread2({}, model), {}, { type: model.type || type }));
		});
	});
	return Array.from(modelMap.values());
};
const createDeviceRow = (item, translation) => {
	var _item$type, _item$model, _item$profile;
	const name = translation(item.name);
	const typeName = translation((_item$type = item.type) === null || _item$type === void 0 ? void 0 : _item$type.name) || item.type_code;
	const modelName = translation((_item$model = item.model) === null || _item$model === void 0 ? void 0 : _item$model.name) || item.model_code;
	const link = item.link || "unlinked";
	const 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,
		typeName,
		modelName,
		profileName,
		link,
		status: link === "linked" ? item.status || "offline" : "unknown",
		typeCode: item.type_code,
		modelCode: item.model_code,
		_raw: item
	};
};
//#endregion
export { CONNECTION_TYPE_OPTIONS, DEVICE_ICON_COLOR, createDeviceRow, flattenDeviceModels, getBrandCodeFromOptionValue, getBrandOptionValue, getConnectionTypeLabel, getModelConnectionTypes, isProfileRequired };
