import { getModels } from "$lib/services";

const LIMIT = 24;

export async function load({ fetch, url }) {
  const search = url.searchParams.get("search") || undefined;
  const sort = url.searchParams.get("sort") || "name";
  const page = Math.max(1, parseInt(url.searchParams.get("page") || "1", 10));
  const offset = (page - 1) * LIMIT;

  const result = await getModels({ search, sortBy: sort, offset, limit: LIMIT }, fetch);
  return { ...result, search, sort, page, limit: LIMIT };
}
