import api from '../api'; export interface TableListViewRow { id: string; userId?: string; mandateId?: string | null; contextKey: string; viewKey: string; displayName: string; config: TableViewConfig; updatedAt?: number; } export interface TableViewConfig { schemaVersion?: number; filters?: Record; sort?: Array<{ field: string; direction: 'asc' | 'desc' }>; groupByLevels?: Array<{ field: string; nullLabel?: string }>; /** Section mode (`tableGroupLayoutMode="sections"`): stable keys (`sk`) of collapsed sections. */ collapsedSectionKeys?: string[]; /** Inline `groupLayout` bands: keys are `band.path.join('///')`. */ collapsedGroupKeys?: string[]; } export async function listTableViews(contextKey: string): Promise { const { data } = await api.get('/api/table-views', { params: { contextKey }, }); return Array.isArray(data) ? data : []; } export async function getTableView(contextKey: string, viewKey: string): Promise { const { data } = await api.get(`/api/table-views/${encodeURIComponent(viewKey)}`, { params: { contextKey }, }); return data; } export async function createTableView(payload: { contextKey: string; viewKey: string; displayName: string; config: TableViewConfig; }): Promise { const { data } = await api.post('/api/table-views', payload); return data; } export async function updateTableView( viewId: string, updates: { displayName?: string; viewKey?: string; config?: TableViewConfig }, ): Promise { const { data } = await api.put(`/api/table-views/${encodeURIComponent(viewId)}`, updates); return data; } export async function deleteTableView(viewId: string): Promise { await api.delete(`/api/table-views/${encodeURIComponent(viewId)}`); }