import { getText } from "../../../locales/index.js";
import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
//#region src/components/PisellTabbar2/utils/index.ts
/**
* 默认的特殊项配置
*/
const defaultItems = {
	all: {
		id: 0,
		shop_id: 9,
		parent_id: 0,
		name: "pisell-tabbar-all",
		slug: "All",
		icon: ""
	},
	search: {
		id: -1,
		shop_id: 9,
		parent_id: 0,
		name: "pisell-tabbar-search",
		slug: "Search",
		key: "search",
		icon: "",
		customClick: true
	},
	expand: {
		id: -2,
		shop_id: 9,
		parent_id: 0,
		key: "expand",
		icon: "pisell2-expand-01",
		name: "pisell-tabbar-expand",
		slug: "expand",
		customClick: true
	}
};
/**
* 向数据源添加特殊项（如 all、search、expand 按钮）
* 
* @param dataSource - 原始数据源
* @param keys - 要添加的特殊项 key 数组
* @returns 添加了特殊项的新数据源
* 
* @example
* ```tsx
* const newData = addDataSourceItemsByKey(categoryData, ['expand', 'all']);
* // 返回: [expandItem, allItem, ...categoryData]
* ```
*/
const addDataSourceItemsByKey = (dataSource, keys) => {
	return [...keys.map((key) => _objectSpread2(_objectSpread2({}, defaultItems[key]), {}, { name: getText(defaultItems[key].name) })), ...dataSource];
};
/**
* 获取默认激活的 key 数组
* 
* @param dataSource - 数据源
* @param rowKey - 用作唯一标识的字段名
* @returns 默认激活的 key 数组（多层级）
* 
* @description
* 默认选中第一项，如果第一项有子级，同时选中第一个子级
* 
* @example
* ```tsx
* const defaultKeys = getDefaultActiveKey(categoryData, 'id');
* // 返回: [1, 0] (第一层级的第一项ID，第二层级的第一项ID)
* ```
*/
const getDefaultActiveKey = (dataSource, rowKey) => {
	const _activeKey = [];
	if (dataSource.length) {
		var _level1Item$children;
		const level1Item = dataSource[0];
		_activeKey.push(String(level1Item[rowKey]));
		if ((_level1Item$children = level1Item.children) === null || _level1Item$children === void 0 ? void 0 : _level1Item$children.length) if (level1Item.childrenMaxLevel !== void 0 && level1Item.childrenMaxLevel < 2) _activeKey.push(String(0));
		else {
			var _level2Item$children;
			const level2Item = level1Item.children[0];
			_activeKey.push(String(level2Item[rowKey]));
			if ((_level2Item$children = level2Item.children) === null || _level2Item$children === void 0 ? void 0 : _level2Item$children.length) _activeKey.push(String(0));
		}
	}
	return _activeKey;
};
//#endregion
export { addDataSourceItemsByKey, getDefaultActiveKey };
