"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/bordered.ts
/**
* @file Bordered table renderer using Unicode box-drawing characters (`┌`, `─`,
*   `│`, `┴`, …). The right choice when the output context renders box-drawing
*   reliably (modern terminals, GitHub markdown, most CI runners). Shares
*   column-width calculation, alignment, and padding with the simple renderer
*   via `./padding`.
*/
/**
* Format data as an ASCII table with borders.
*
* @example
*   import { formatTable } from '@socketsecurity/lib/tables/bordered'
*   import colors from 'yoctocolors-cjs'
*
*   const data = [
*     { name: 'lodash', version: '4.17.21', issues: 0 },
*     { name: 'react', version: '18.2.0', issues: 2 },
*   ]
*   const columns = [
*     { key: 'name', header: 'Package' },
*     { key: 'version', header: 'Version', align: 'center' },
*     {
*       key: 'issues',
*       header: 'Issues',
*       align: 'right',
*       color: v => (v === '0' ? colors.green(v) : colors.red(v)),
*     },
*   ]
*   console.log(formatTable(data, columns))
*   // Output:
*   // ┌─────────┬─────────┬────────┐
*   // │ Package │ Version │ Issues │
*   // ├─────────┼─────────┼────────┤
*   // │ lodash  │ 4.17.21 │      0 │
*   // │ react   │ 18.2.0  │      2 │
*   // └─────────┴─────────┴────────┘
*
* @param data - Array of data objects.
* @param columns - Column configuration.
*
* @returns Formatted table string
*/
function formatTable(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 = [];
	const topBorder = `┌─${widths.map((w) => "─".repeat(w)).join("─┬─")}─┐`;
	require_primordials_array.ArrayPrototypePush(lines, src_external_yoctocolors_cjs.default.dim(topBorder));
	const headerCells = columns.map((col, i) => {
		return require_tables_padding.padText(src_external_yoctocolors_cjs.default.bold(col.header), widths[i], col.align);
	});
	require_primordials_array.ArrayPrototypePush(lines, src_external_yoctocolors_cjs.default.dim("│ ") + headerCells.join(src_external_yoctocolors_cjs.default.dim(" │ ")) + src_external_yoctocolors_cjs.default.dim(" │"));
	const headerSep = `├─${widths.map((w) => "─".repeat(w)).join("─┼─")}─┤`;
	require_primordials_array.ArrayPrototypePush(lines, src_external_yoctocolors_cjs.default.dim(headerSep));
	for (const row of data) {
		const cells = 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);
		});
		require_primordials_array.ArrayPrototypePush(lines, src_external_yoctocolors_cjs.default.dim("│ ") + cells.join(src_external_yoctocolors_cjs.default.dim(" │ ")) + src_external_yoctocolors_cjs.default.dim(" │"));
	}
	const bottomBorder = `└─${widths.map((w) => "─".repeat(w)).join("─┴─")}─┘`;
	require_primordials_array.ArrayPrototypePush(lines, src_external_yoctocolors_cjs.default.dim(bottomBorder));
	return lines.join("\n");
}

//#endregion
exports.formatTable = formatTable;