import api from './client' import type { SheetMeta, Deliverable } from '../types' export const listSheets = () => api.get<{ sheets: SheetMeta[] }>('/sheets').then(r => r.data.sheets) export const createSheet = (name: string, data: Deliverable[] = []) => api.post<{ sheet: SheetMeta }>('/sheets', { name, data }).then(r => r.data.sheet) export const loadSheet = (id: string) => api.get<{ data: Deliverable[] }>(`/sheets/${id}`).then(r => r.data.data) export const updateSheet = (id: string, data: Deliverable[]) => api.put(`/sheets/${id}`, { data }) export const deleteSheet = (id: string) => api.delete(`/sheets/${id}`) export const renameSheet = (id: string, name: string) => api.patch(`/sheets/${id}`, { name }) export const duplicateSheet = (id: string) => api.post<{ sheet: SheetMeta }>(`/sheets/${id}/duplicate`).then(r => r.data.sheet) export const importDeliverables = (sheetId: string, deliverables: Deliverable[], mode: 'append' | 'replace' = 'append') => api.post(`/sheets/${sheetId}/import`, { deliverables, mode }).then(r => r.data) export const exportSheet = (id: string) => { const token = sessionStorage.getItem('ac_access_token') const query = token ? `?_token=${token}` : '' window.open(`${import.meta.env.BASE_URL}api/sheets/${id}/export${query}`, '_blank') }