<commit_before>import {RowDetails} from './row.details';
import {RowDetailsStatus} from './row.details.status';
import {AppError} from '../infrastructure';
import {columnFactory} from '../column/column.factory';

export function flatView(table) {
	const result = [];
	const model = table.model;
	const createColumn = columnFactory(model);
	const colspan = table.data.columns().length;
	const rows = model.view().rows;
	const status = model.row().status;

	rows.forEach(row => {
		if (!(row instanceof RowDetails)) {
			const state = status.get(row);
			result.push(row);
			if (state && state instanceof RowDetailsStatus) {
				if (state.expand) {
					const column = createColumn('row-details');
					result.push(new RowDetails(row, column));
					column.colspan = colspan;
				}
			}
		}
	});

	return result;
}

export function toggleStatus(rows, status, mode = 'single') {
	switch (mode) {
		case 'single':
			status = new Map(Array.from(status.entries()).filter(entry => {
				const row = entry[0];
				const status = entry[1];
				return rows.indexOf(row) >= 0 || !(status instanceof RowDetailsStatus);
			}));
			break;
		case 'multiple':
			status = new Map(status.entries());
			break;
		default:
			throw AppError('row.details.service', `Invalid mode ${mode}`);
	}

	rows.forEach(row => {
		const state = status.get(row);
		if (!state) {
			status.set(row, new RowDetailsStatus(true));
		} else {
			state.expand = !state.expand;
		}
	});
<commit_msg>add new<commit_after>import {RowDetails} from './row.details';
import {RowDetailsStatus} from './row.details.status';
import {AppError} from '../infrastructure';
import {columnFactory} from '../column/column.factory';

export function flatView(table) {
	const result = [];
	const model = table.model;
	const createColumn = columnFactory(model);
	const colspan = table.data.columns().length;
	const rows = model.view().rows;
	const status = model.row().status;

	rows.forEach(row => {
		if (!(row instanceof RowDetails)) {
			const state = status.get(row);
			result.push(row);
			if (state && state instanceof RowDetailsStatus) {
				if (state.expand) {
					const column = createColumn('row-details');
					result.push(new RowDetails(row, column));
					column.colspan = colspan;
				}
			}
		}
	});

	return result;
}

export function toggleStatus(rows, status, mode = 'single') {
	switch (mode) {
		case 'single':
			status = new Map(Array.from(status.entries()).filter(entry => {
				const row = entry[0];
				const status = entry[1];
				return rows.indexOf(row) >= 0 || !(status instanceof RowDetailsStatus);
			}));
			break;
		case 'multiple':
			status = new Map(status.entries());
			break;
		default:
			throw new AppError('row.details.service', `Invalid mode ${mode}`);
	}

	rows.forEach(row => {
		const state = status.get(row);
		if (!state) {
			status.set(row, new RowDetailsStatus(true));
		} else {
			state.expand = !state.expand;
		}
	});

{'fraction_non_alphanumeric': 0.16027397260273973, 'fraction_numerical': 0.002054794520547945, 'mean_word_length': 3.7650897226753672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2129647', 'n_tokens_mistral': 1037, 'n_tokens_neox': 908, 'n_words': 226}