import type { TableRow } from '@/tools/types' /** * Transforms a table from the store format to a key-value object. */ export const transformTable = ( table: TableRow[] | Record | string | null ): Record => { if (!table) return {} if (typeof table === 'string') { try { const parsed = JSON.parse(table) as TableRow[] | Record return transformTable(parsed) } catch { return {} } } if (Array.isArray(table)) { return table.reduce( (acc, row) => { if (row.cells?.Key && row.cells?.Value !== undefined) { const value = row.cells.Value acc[row.cells.Key] = value } return acc }, {} as Record ) } if (typeof table === 'object') { return table } return {} }