import { Suspense } from 'react';
import SpritzClient from './components/SpritzClient';
import type { SysParams } from './components/SpritzClient';
import pkg from '../package.json';

interface SearchParams {
  test?: string;
  doinit?: string;
  einheit?: string;
}

export default async function Page({
  searchParams,
}: {
  searchParams: Promise<SearchParams>;
}) {
  const params = await searchParams;
  const sysParams: SysParams = {
    testing: params.test === 'true',
    doinit: params.doinit === 'true',
    einheit: parseInt(params.einheit ?? '0') || 0,
    version: pkg.version,
    date: (pkg as typeof pkg & { date?: string }).date ?? '',
  };
  return (
    <Suspense fallback={<div style={{ padding: '30px' }}>Lade…</div>}>
      <SpritzClient sysParams={sysParams} />
    </Suspense>
  );
}
