import { writable } from 'svelte/store'; import type { Holiday, PTO, Revenue, TeamCapacity } from '$lib/types/capacity'; import { getHolidays, getPTOs, getPossibleRevenue, getTeamCapacity } from '$lib/api/capacity'; export const teamCapacityStore = writable(null); export const revenueStore = writable(null); export const holidaysStore = writable([]); export const ptosStore = writable([]); export async function loadTeamCapacity(month: string): Promise { try { const payload = await getTeamCapacity(month); teamCapacityStore.set(payload); } catch (error) { console.error('Failed to load team capacity', error); teamCapacityStore.set(null); } } export async function loadRevenue(month: string): Promise { try { const payload = await getPossibleRevenue(month); revenueStore.set(payload); } catch (error) { console.error('Failed to load revenue', error); revenueStore.set(null); } } export async function loadHolidays(month: string): Promise { try { const payload = await getHolidays(month); holidaysStore.set(payload); } catch (error) { console.error('Failed to load holidays', error); holidaysStore.set([]); } } export async function loadPTOs(month: string, teamMemberId?: string): Promise { if (!teamMemberId) { ptosStore.set([]); return; } try { const payload = await getPTOs({ team_member_id: teamMemberId, month }); ptosStore.set(payload); } catch (error) { console.error('Failed to load PTOs', error); ptosStore.set([]); } }