import type { ProductTableGroup, ProductTableRow } from '@/types/product'; export function groupProductRows(rows: ProductTableRow[]): ProductTableGroup[] { const groups: ProductTableGroup[] = []; const indexByProductId = new Map(); for (const row of rows) { const existingIndex = indexByProductId.get(row.product_id); if (existingIndex === undefined) { indexByProductId.set(row.product_id, groups.length); groups.push({ product_id: row.product_id, product_row_number: row.product_row_number, product_name: row.product_name, categories: row.categories, is_active: row.is_active, variants: [row], }); continue; } groups[existingIndex].variants.push(row); } return groups; }