import { error } from '@sveltejs/kit';
import type { PageLoad } from './$types';
import type { User } from '$lib/api/types';

export const ssr = false;
export const load = (async ({ fetch, params }) => {
  // check if user exists
  const userId = params.user;
  const response = await fetch(`/api/users/${userId}`);
  if (!response.ok) throw error(response.status, response.statusText);

  const user = await response.json() as User;
  return {
    user: user
  };

}) satisfies PageLoad;

export interface UserProfilePage {
  user: User
}
