import { useQuery } from '@tanstack/react-query'; import type { PackageCardData } from '../data/content'; // Relative path so it resolves against whichever domain served the app // (test.slpsoftware.nl / slpsoftware.nl) — see aidlc-docs/features/react-frontend/ // construction/react-frontend-app/functional-design/packages-api-handoff.md // for the API contract this endpoint must implement. // VITE_API_BASE_URL is only set locally (.env.local, e.g. https://localhost:7223) to // point at a locally running backend; on test/production it's unset, so the path stays // relative to whichever origin served the app. Read inside the function (not as a // module-level constant) so tests can stub it per-case. function offeringsEndpoint() { return `${import.meta.env.VITE_API_BASE_URL ?? ''}/api/v1/offerings`; } async function fetchPackages(): Promise { const response = await fetch(offeringsEndpoint()); if (!response.ok) { throw new Error(`Failed to fetch packages: ${response.status} ${response.statusText}`); } return response.json(); } export function usePackagesQuery() { return useQuery({ queryKey: ['packages'], queryFn: fetchPackages, }); }