'use client' import React, { useState, useEffect, Suspense } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import Link from 'next/link' import { useSDK } from '@/lib/sdk' import type { AdvisoryForm } from './_types' import { industryToDomain } from './_data' import { StepIndicator } from './_components/StepIndicator' import { Step1Basics } from './_components/Step1Basics' import { Step2DataCategories } from './_components/Step2DataCategories' import { Step3Purposes } from './_components/Step3Purposes' import { Step4Automation } from './_components/Step4Automation' import { Step5Hosting } from './_components/Step5Hosting' import { Step6Transfer } from './_components/Step6Transfer' import { Step7Retention } from './_components/Step7Retention' import { Step8Contracts } from './_components/Step8Contracts' import { NavigationButtons } from './_components/NavigationButtons' import { ResultView } from './_components/ResultView' // ============================================================================= // MAIN COMPONENT // ============================================================================= function AdvisoryBoardPageInner() { const router = useRouter() const searchParams = useSearchParams() const { state: sdkState } = useSDK() const editId = searchParams.get('edit') const isEditMode = !!editId const [currentStep, setCurrentStep] = useState(1) const [isSubmitting, setIsSubmitting] = useState(false) const [editLoading, setEditLoading] = useState(false) const [result, setResult] = useState(null) const [error, setError] = useState(null) // Derive domain from company profile industry const profileIndustry = sdkState.companyProfile?.industry const derivedDomain = industryToDomain( Array.isArray(profileIndustry) ? profileIndustry : profileIndustry ? [profileIndustry] : [] ) // Form state — tile-based multi-select via arrays const [form, setForm] = useState({ title: '', use_case_text: '', domain: 'general', category: '', data_categories: [], custom_data_types: [], purposes: [], automation: '', hosting_provider: '', hosting_region: '', model_usage: [], transfer_targets: [], transfer_countries: [], transfer_mechanism: '', retention_period: '', retention_purpose: '', contracts: [], subprocessors: '', }) const updateForm = (updates: Partial) => { setForm(prev => ({ ...prev, ...updates })) } // Auto-set domain from profile useEffect(() => { if (!isEditMode && derivedDomain !== 'general') { updateForm({ domain: derivedDomain }) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [derivedDomain]) // Pre-fill form when in edit mode useEffect(() => { if (!editId) return setEditLoading(true) fetch(`/api/sdk/v1/ucca/assessments/${editId}`) .then(r => r.json()) .then(data => { const intake = data.intake || {} setForm({ title: data.title || '', use_case_text: intake.use_case_text || '', domain: data.domain || 'general', category: data.category || intake.category || '', data_categories: intake.data_categories || [], custom_data_types: intake.data_types?.custom_data_types || intake.custom_data_types || [], purposes: intake.purposes || [], automation: intake.automation || '', hosting_provider: intake.hosting?.provider || '', hosting_region: intake.hosting?.region || '', model_usage: intake.model_usage_list || [], transfer_targets: intake.transfer_targets || [], transfer_countries: intake.international_transfer?.countries || intake.transfer_countries || [], transfer_mechanism: intake.transfer_mechanism || intake.international_transfer?.mechanism || '', retention_period: intake.retention_period || '', retention_purpose: intake.retention?.purpose || intake.retention_purpose || '', contracts: intake.contracts_list || [], subprocessors: intake.contracts?.subprocessors || intake.subprocessors || '', }) }) .catch(() => {}) .finally(() => setEditLoading(false)) }, [editId]) const handleSubmit = async () => { setIsSubmitting(true) setError(null) try { const intake = { title: form.title, use_case_text: form.use_case_text, domain: form.domain, category: form.category, data_categories: form.data_categories, custom_data_types: form.custom_data_types.filter(s => s.trim()), purposes: form.purposes, automation: form.automation, hosting: { provider: form.hosting_provider, region: form.hosting_region, }, model_usage_list: form.model_usage, transfer_targets: form.transfer_targets, transfer_countries: form.transfer_countries, transfer_mechanism: form.transfer_mechanism, retention_period: form.retention_period, retention_purpose: form.retention_purpose, contracts_list: form.contracts, subprocessors: form.subprocessors, store_raw_text: true, } const url = isEditMode ? `/api/sdk/v1/ucca/assessments/${editId}` : '/api/sdk/v1/ucca/assess' const method = isEditMode ? 'PUT' : 'POST' const response = await fetch(url, { method, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(intake), }) if (!response.ok) { const errData = await response.json().catch(() => null) throw new Error(errData?.error || `HTTP ${response.status}`) } if (isEditMode) { router.push(`/sdk/use-cases/${editId}`) return } const data = await response.json() setResult(data) } catch (err) { setError(err instanceof Error ? err.message : 'Fehler bei der Bewertung') } finally { setIsSubmitting(false) } } // If we have a result, show it if (result) { return ( router.push(`/sdk/use-cases/${id}`)} onGoToOverview={() => router.push('/sdk/use-cases')} /> ) } return (
{/* Header */}

{isEditMode ? 'Assessment bearbeiten' : 'Use Case Workshop'}

{isEditMode ? 'Angaben anpassen und Assessment neu bewerten' : 'Erfassen Sie Ihren KI-Anwendungsfall Schritt fuer Schritt'}

UCCA-Dokumentation
{/* Edit loading indicator */} {editLoading && (
Lade Assessment-Daten...
)} {/* Error */} {error && (
{error}
)} {/* Step Content */}
{currentStep === 1 && ( )} {currentStep === 2 && } {currentStep === 3 && } {currentStep === 4 && } {currentStep === 5 && } {currentStep === 6 && } {currentStep === 7 && } {currentStep === 8 && }
currentStep > 1 ? setCurrentStep(currentStep - 1) : router.push('/sdk/use-cases')} onNext={() => setCurrentStep(currentStep + 1)} onSubmit={handleSubmit} />
) } export default function AdvisoryBoardPage() { return ( Lade...}> ) }