import type {
	ProductTableTemplateKey,
	ProductTableTemplateSettings,
} from './types';

export type ProductTableTemplateSpec = {
	headerHeightPx: number;
	rowHeightPx: number;
	cellPaddingPx: number;
	fontSizePx: number;
	lineHeight: number;
	borderColor: string;
	borderWidthPx: number;
	headerBg: string;
	headerFontWeight: number;
	thumbnailSizePx: number;
	/** Borderless zebra layout with rounded header / band rows (editor + PDF). */
	modernZebra?: boolean;
	/** Header cell text color when modernZebra. */
	headerTextColor?: string;
	/** Default body text color when modernZebra. */
	bodyMutedColor?: string;
	/** Alternating row background (even rows, 1-based: rows 2,4,6…) when modernZebra. */
	zebraEvenBg?: string;
	rowBorderRadiusPx?: number;
	/** Vertical gap between body rows (border-spacing) when modernZebra. */
	rowGapPx?: number;
};

const MINIMAL: ProductTableTemplateSpec = {
	headerHeightPx: 30,
	rowHeightPx: 26,
	cellPaddingPx: 6,
	fontSizePx: 12,
	lineHeight: 1.25,
	borderColor: '#e5e7eb',
	borderWidthPx: 1,
	headerBg: 'transparent',
	headerFontWeight: 600,
	thumbnailSizePx: 32,
};

const CLASSIC: ProductTableTemplateSpec = {
	headerHeightPx: 34,
	rowHeightPx: 28,
	cellPaddingPx: 7,
	fontSizePx: 12.5,
	lineHeight: 1.25,
	borderColor: '#cbd5e1',
	borderWidthPx: 1,
	headerBg: '#f8fafc',
	headerFontWeight: 700,
	thumbnailSizePx: 36,
};

const COMPACT: ProductTableTemplateSpec = {
	headerHeightPx: 28,
	rowHeightPx: 22,
	cellPaddingPx: 4,
	fontSizePx: 11.5,
	lineHeight: 1.2,
	borderColor: '#e5e7eb',
	borderWidthPx: 1,
	headerBg: 'transparent',
	headerFontWeight: 600,
	thumbnailSizePx: 28,
};

const INVOICE_BOLD: ProductTableTemplateSpec = {
	headerHeightPx: 36,
	rowHeightPx: 29,
	cellPaddingPx: 7,
	fontSizePx: 12.5,
	lineHeight: 1.25,
	borderColor: '#0f172a',
	borderWidthPx: 1,
	headerBg: '#ffffff',
	headerFontWeight: 800,
	thumbnailSizePx: 40,
};

/** Rounded dark header, no grid lines, gray “pill” bands on even rows (matches reference layout). */
const MODERN_ZEBRA: ProductTableTemplateSpec = {
	headerHeightPx: 48,
	rowHeightPx: 44,
	cellPaddingPx: 16,
	fontSizePx: 13,
	lineHeight: 1.45,
	borderColor: 'transparent',
	borderWidthPx: 0,
	headerBg: '#000000',
	headerFontWeight: 700,
	thumbnailSizePx: 40,
	modernZebra: true,
	headerTextColor: '#ffffff',
	bodyMutedColor: '#6b7280',
	zebraEvenBg: '#f5f5f5',
	rowBorderRadiusPx: 8,
	rowGapPx: 8,
};

export const PRODUCT_TABLE_TEMPLATES: Record<
	ProductTableTemplateKey,
	ProductTableTemplateSpec
> = {
	minimal: MINIMAL,
	classic: CLASSIC,
	compact: COMPACT,
	invoice_bold: INVOICE_BOLD,
	modern_zebra: MODERN_ZEBRA,
};

export function getTemplateSpec(settings: ProductTableTemplateSettings): ProductTableTemplateSpec {
	return PRODUCT_TABLE_TEMPLATES[settings.template] ?? MINIMAL;
}

