const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
//#region src/plus/saasDevice/devicePlanning/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"
	}
];
/** 把品牌 id 和 code 编码成 Select value，避免 code 中特殊字符与 id 冲突。 */
const getBrandOptionValue = (brand) => `${brand.id}__${brand.code}`;
/** 从品牌 Select value 中还原 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) : [];
};
/** 把连接方式 code 转成 UI 展示文案。 */
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;
};
/** 判断当前型号是否必须选择 profile。 */
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 hasI18nValue = (value) => {
	if (!value) return false;
	return Object.values(value).some((item) => String(item || "").trim());
};
/** 将后端按类型返回的 active_models 展平成去重后的型号列表。 */
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, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, model), {}, { type: model.type || type }));
		});
	});
	return Array.from(modelMap.values());
};
/** 把后端设备实体转换成列表和详情抽屉共用的展示模型。 */
const createDeviceRow = (item, translation, profileNameMap) => {
	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 ? profileNameMap === null || profileNameMap === void 0 ? void 0 : profileNameMap.get(item.profile_id) : "") || (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
	};
};
/** 兼容工作区详情接口可能返回 data 数组或单对象的两种结构。 */
const resolveWorkAreaDetail = (response) => {
	const data = response === null || response === void 0 ? void 0 : response.data;
	if (Array.isArray(data)) return data[0];
	return data || response;
};
/** 从工作区详情响应中提取三类设备数量，用于删除前阻断判断。 */
const getDeleteWorkAreaCounts = (response) => {
	const workArea = resolveWorkAreaDetail(response);
	return {
		smart: (workArea === null || workArea === void 0 ? void 0 : workArea.smart_devices_count) || 0,
		dumb: (workArea === null || workArea === void 0 ? void 0 : workArea.dumb_devices_count) || 0,
		integrated: (workArea === null || workArea === void 0 ? void 0 : workArea.integrated_devices_count) || 0
	};
};
//#endregion
exports.CONNECTION_TYPE_OPTIONS = CONNECTION_TYPE_OPTIONS;
exports.DEVICE_ICON_COLOR = DEVICE_ICON_COLOR;
exports.createDeviceRow = createDeviceRow;
exports.flattenDeviceModels = flattenDeviceModels;
exports.getBrandCodeFromOptionValue = getBrandCodeFromOptionValue;
exports.getBrandOptionValue = getBrandOptionValue;
exports.getConnectionTypeLabel = getConnectionTypeLabel;
exports.getDeleteWorkAreaCounts = getDeleteWorkAreaCounts;
exports.getModelConnectionTypes = getModelConnectionTypes;
exports.hasI18nValue = hasI18nValue;
exports.isProfileRequired = isProfileRequired;
