import { ApiError } from '$lib/api/client';
import { listMyCollections } from '$lib/api/collections';
import type { PageLoad } from './$types';

export const ssr = false;

export const load: PageLoad = async () => {
    try {
        const page = await listMyCollections({ limit: 200 });
        return { collections: page.items, authenticated: true, error: null };
    } catch (e) {
        if (e instanceof ApiError && e.status === 401) {
            return { collections: [], authenticated: false, error: null };
        }
        if (e instanceof ApiError) {
            return { collections: [], authenticated: true, error: e.message };
        }
        throw e;
    }
};
