import { api } from './client.js' const q = (params) => { const s = new URLSearchParams() Object.entries(params || {}).forEach(([k, v]) => { if (v !== undefined && v !== null && v !== '') s.set(k, v) }) const str = s.toString() return str ? '?' + str : '' } // 打卡 / 日历 export const checkinApi = { habits: (date) => api('/checkin/habits' + q({ date })), day: (date) => api('/checkin/day' + q({ date })), calendar: (month) => api('/checkin/calendar' + q({ month })), createHabit: (body) => api('/checkin/habits', { method: 'POST', body }), updateHabit: (id, body) => api(`/checkin/habits/${id}`, { method: 'PUT', body }), reorderHabits: (ids) => api('/checkin/habits/reorder', { method: 'POST', body: { ids } }), deleteHabit: (id, hard) => api(`/checkin/habits/${id}${hard ? '?hard=1' : ''}`, { method: 'DELETE' }), check: (id, date, note) => api(`/checkin/habits/${id}/check`, { method: 'POST', body: { date, note } }), uncheck: (id, date) => api(`/checkin/habits/${id}/check` + q({ date }), { method: 'DELETE' }), } // 检查清单 export const checklistApi = { lists: (archived) => api('/checklists' + q({ archived: archived ? 1 : 0 })), list: (id) => api(`/checklists/${id}`), create: (body) => api('/checklists', { method: 'POST', body }), update: (id, body) => api(`/checklists/${id}`, { method: 'PUT', body }), remove: (id) => api(`/checklists/${id}`, { method: 'DELETE' }), duplicate: (id) => api(`/checklists/${id}/duplicate`, { method: 'POST', body: {} }), addItem: (id, body) => api(`/checklists/${id}/items`, { method: 'POST', body }), updateItem: (itemId, body) => api(`/checklists/items/${itemId}`, { method: 'PUT', body }), removeItem: (itemId) => api(`/checklists/items/${itemId}`, { method: 'DELETE' }), checkAll: (id, done) => api(`/checklists/${id}/check-all`, { method: 'POST', body: { done } }), templates: () => api('/checklists/templates'), template: (id) => api(`/checklists/templates/${id}`), createTemplate: (body) => api('/checklists/templates', { method: 'POST', body }), updateTemplate: (id, body) => api(`/checklists/templates/${id}`, { method: 'PUT', body }), removeTemplate: (id) => api(`/checklists/templates/${id}`, { method: 'DELETE' }), }