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, params, url }) => {
	const brandId = params.id;

	// console.log(backendParams);

	try {
		const brands = await fetch(`${VITE_BACKEND_URL}${endpoints.category.brand(brandId)}`, {
			headers: {
				Accept: 'application/json',
				'Content-Type': 'application/json'
			}
		});

		// const response = await productCategory.text();

		// console.log(response);

		return {
			status: 'success',
			brands: brands.json()
		};
	} catch (err) {
		return {
			status: 'error',
			message: 'Unable to fetch products',
			error: err instanceof Error ? err?.message : 'Unknown Error'
		};
	}
};
