"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../_virtual/_rolldown/runtime.js');
const require_primordials_math = require('../primordials/math.js');
const require_primordials_array = require('../primordials/array.js');
const require_tables_padding = require('./padding.js');
let src_external_yoctocolors_cjs = require("../external/yoctocolors-cjs");
src_external_yoctocolors_cjs = require_runtime.__toESM(src_external_yoctocolors_cjs);

//#region src/tables/simple.ts
/**
* @file Borderless table renderer — columns separated by two spaces, header
*   underlined with `─`. Lighter weight than `formatTable` (no box-drawing
*   characters); the right choice when the surface is rendering to a context
*   that doesn't reliably support box-drawing glyphs.
*/
/**
* Format data as a simple table without borders. Lighter weight alternative to
* formatTable().
*
* @example
*   import { formatSimpleTable } from '@socketsecurity/lib/tables/simple'
*   import colors from 'yoctocolors-cjs'
*
*   const data = [
*     { name: 'lodash', version: '4.17.21' },
*     { name: 'react', version: '18.2.0' },
*   ]
*   const columns = [
*     { key: 'name', header: 'Package' },
*     { key: 'version', header: 'Version' },
*   ]
*   console.log(formatSimpleTable(data, columns))
*   // Output:
*   // Package  Version
*   // ───────  ───────
*   // lodash   4.17.21
*   // react    18.2.0
*
* @param data - Array of data objects.
* @param columns - Column configuration.
*
* @returns Formatted table string
*/
function formatSimpleTable(data, columns) {
	if (data.length === 0) return "(no data)";
	const widths = columns.map((col) => {
		const headerWidth = require_tables_padding.displayWidth(col.header);
		const maxDataWidth = require_primordials_math.MathMax(...data.map((row) => require_tables_padding.displayWidth(String(row[col.key] ?? ""))));
		return col.width ?? require_primordials_math.MathMax(headerWidth, maxDataWidth);
	});
	const lines = [];
	require_primordials_array.ArrayPrototypePush(lines, columns.map((col, i) => require_tables_padding.padText(src_external_yoctocolors_cjs.default.bold(col.header), widths[i], col.align)).join("  "));
	require_primordials_array.ArrayPrototypePush(lines, widths.map((w) => src_external_yoctocolors_cjs.default.dim("─".repeat(w))).join("  "));
	for (const row of data) require_primordials_array.ArrayPrototypePush(lines, columns.map((col, i) => {
		let value = String(row[col.key] ?? "");
		if (col.color) value = col.color(value);
		return require_tables_padding.padText(value, widths[i], col.align);
	}).join("  "));
	return lines.join("\n");
}

//#endregion
exports.formatSimpleTable = formatSimpleTable;