
/** Convert QC definitions tree into a flat list.
 */
function flattenQCDefinitions(items, keywords=[], labels=[], disabled=false) {
	const result = [];

	if (items) {
		for (const item of items) {
			if (!item.children) {
				result.push({
					...item,
					iterate: (item.iterate ?? "shots"),
					labels: labels.concat(item.labels??[]),
					disabled: (item.disabled ?? disabled)
				});
			} else {
				const k = [...keywords, item.name];
				const l = [...labels, ...(item.labels??[])];
				const d = item.disabled ?? disabled
				result.push(...flattenQCDefinitions(item.children, k, l, d))
			}
		}
	}
	return result;
}

module.exports = flattenQCDefinitions;
