import { PDFPage } from "pdf-lib";
import { Margin, Padding } from "./Layout.js";
export type Size = number | "auto";

export abstract class PDFElement {
	protected _height: Size = 0;
	protected _width: Size = 0;
	public margin: Margin = { top: 0, bottom: 0, left: 0, right: 0 };
	public padding: Padding = { top: 0, bottom: 0, left: 0, right: 0 };

	get width(): number {
		return this.innerWidth + this.padding.left + this.padding.right;
	}

	set width(value: Size) {
		this._width = value;
	}

	get innerWidth() {
		return this._width === "auto" ? 0 : this._width;
	}

	get height(): number {
		return this.innerHeight + this.padding.top + this.padding.bottom;
	}

	set height(value: Size) {
		this._height = value;
	}

	get innerHeight() {
		return this._height === "auto" ? 0 : this._height;
	}

	abstract draw(page: PDFPage, x: number, y: number): void;

	abstract addChild(...children: PDFElement[]): void;
}
