import { Cell, Direction, ICell } from "./cell.ts";
export type IRow<T extends ICell | undefined = ICell | undefined> = | T[] | Row<T>;export type IDataRow = Record<string, string | number>;
export interface IRowOptions { indent?: number; border?: boolean; align?: Direction;}
export class Row<T extends ICell | undefined = ICell | undefined> extends Array<T> { protected options: IRowOptions = {};
public static from<T extends ICell | undefined>( cells: IRow<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: boolean, 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"; }}