import { getSupabaseServerClient } from '@kit/supabase/server-client';
import { createSiteBuilderApi } from '@kit/site-builder/api';
import { SiteSettingsForm } from '@kit/site-builder/components';
import { CmsPageShell } from '~/components/cms-page-shell';

interface Props { params: Promise<{ account: string }> }

export default async function SiteSettingsPage({ params }: Props) {
  const { account } = await params;
  const client = getSupabaseServerClient();
  const { data: acct } = await client.from('accounts').select('id').eq('slug', account).single();
  if (!acct) return <div>Konto nicht gefunden</div>;

  const api = createSiteBuilderApi(client);
  const settings = await api.getSiteSettings(acct.id);

  return (
    <CmsPageShell account={account} title="Website-Einstellungen" description="Design und Kontaktdaten">
      <SiteSettingsForm accountId={acct.id} account={account} settings={settings} />
    </CmsPageShell>
  );
}
