import { VITE_BACKEND_URL } from '$env/static/private';
import { endpoints } from '$lib/utils/api';
import type { PageServerLoad } from './$types';

export const load: PageServerLoad = async ({ fetch }) => {
	try {
		const brand = await fetch(`${VITE_BACKEND_URL}${endpoints.category.brands}`, {
			headers: {
				Accept: 'application/json'
			}
		});
		if (!brand.ok) {
			return {
				status: 'error',
				message: 'Unable to fetch brand'
			};
		}

		return {
			status: 'success',
			brand: brand.json()
		};
	} catch (err) {
		return {
			status: 'error',
			error: err instanceof Error ? err?.message : 'Unknown error'
		};
	}
};
