import { Cell, CellType, Direction } from "./cell.ts";
export type RowType< T extends CellType | undefined = CellType | undefined,> = | Array<T> | Row<T>;
export type DataRow = Record<string, string | number>;
interface RowOptions { indent?: number; border?: boolean; align?: Direction;}
export class Row< T extends CellType | undefined = CellType | undefined,> extends Array<T> { protected options: RowOptions = {};
public static from<T extends CellType | undefined>( cells: RowType<T>, ): Row<T> { const row = new this(...cells); if (cells instanceof Row) { row.options = { ...(cells as Row).options }; } return row; }
public clone(): Row { const row = new Row( ...this.map((cell: T) => cell instanceof Cell ? cell.clone() : cell), ); row.options = { ...this.options }; return row; }
public border(enable = true, override = true): this { if (override || typeof this.options.border === "undefined") { this.options.border = enable; } return this; }
public align(direction: Direction, override = true): this { if (override || typeof this.options.align === "undefined") { this.options.align = direction; } return this; }
public getBorder(): boolean { return this.options.border === true; }
public hasBorder(): boolean { return this.getBorder() || this.some((cell) => cell instanceof Cell && cell.getBorder()); }
public getAlign(): Direction { return this.options.align ?? "left"; }}
export type IRow = RowType;
export type IDataRow = DataRow;