"use client"; import React, { useState, useEffect } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Checkbox } from "@/components/ui/checkbox"; import { AlertCircle, CheckCircle, ChevronRight, ChevronLeft } from "lucide-react"; const BUNDESLANDS = [ "BERLIN", "BREMEN", "HAMBURG", "HESSE", "LOWER_SAXONY", "MECKLENBURG_VORPOMMERN", "NORTH_RHINE_WESTPHALIA", "RHINELAND_PALATINATE", "SAARLAND", "SAXONY", "SAXONY_ANHALT", "SCHLESWIG_HOLSTEIN", "THURINGIA", "BADEN_WUERTTEMBERG", "BAVARIA", "BRANDENBURG", ]; const MODULES = [ { id: "AI_TUTOR", label: "AI Tutor", requiresDpia: true }, { id: "EXAM_MODE", label: "Exam Mode", requiresDpia: true }, { id: "WELLNESS_CHECKS", label: "Wellness Checks", requiresDpia: false }, { id: "SIGNAGE_EMERGENCY", label: "Signage & Emergency", requiresDpia: false }, { id: "MESSAGING", label: "Messaging", requiresDpia: false }, { id: "LEARNING_ANALYTICS", label: "Learning Analytics", requiresDpia: false }, ]; interface WizardState { step: number; schoolName?: string; dpoName?: string; dpoEmail?: string; schultragerName?: string; schultragerEmail?: string; bundesland?: string; consultationTypes: string[]; dpiaModules: Record; moduleConsultations: Record< string, { elternbeirat: boolean; personalrat: boolean; schulkonferenz: boolean; } >; } interface ComplianceWizardProps { schoolId: string; onComplete?: (data: WizardState) => void; } export function ComplianceWizard({ schoolId, onComplete }: ComplianceWizardProps) { const [state, setState] = useState({ step: 1, consultationTypes: [], dpiaModules: MODULES.reduce( (acc, mod) => ({ ...acc, [mod.id]: { completed: false }, }), {} ), moduleConsultations: MODULES.reduce( (acc, mod) => ({ ...acc, [mod.id]: { elternbeirat: false, personalrat: mod.requiresDpia, schulkonferenz: false, }, }), {} ), }); const [loading, setLoading] = useState(false); const [error, setError] = useState(""); const isStep1Valid = state.schoolName && state.dpoName && state.dpoEmail && state.schultragerName && state.schultragerEmail && state.bundesland; const isStep2Valid = true; // Retention policies auto-seeded const isStep3Valid = Object.keys(state.moduleConsultations).length > 0; const isStep4Valid = MODULES.filter((m) => m.requiresDpia).every( (m) => state.dpiaModules[m.id]?.completed ); const handleStep1Submit = async () => { if (!isStep1Valid) { setError("Please fill in all fields"); return; } try { setLoading(true); const response = await fetch("/api/v1/compliance/onboarding/step1", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ schoolId, dpoName: state.dpoName, dpoEmail: state.dpoEmail, schultragerName: state.schultragerName, schultragerEmail: state.schultragerEmail, bundesland: state.bundesland, }), }); if (!response.ok) throw new Error("Failed to save step 1"); setState((prev) => ({ ...prev, step: 2 })); } catch (err) { setError(err instanceof Error ? err.message : "Unknown error"); } finally { setLoading(false); } }; const handleStep4Submit = async () => { if (!isStep4Valid) { setError("Please complete all required DPIAs"); return; } try { setLoading(true); const response = await fetch("/api/v1/compliance/onboarding/complete", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ schoolId, state, }), }); if (!response.ok) throw new Error("Failed to complete onboarding"); onComplete?.(state); } catch (err) { setError(err instanceof Error ? err.message : "Unknown error"); } finally { setLoading(false); } }; return (
{/* Progress Indicator */}
{[1, 2, 3, 4, 5].map((step) => (
= step ? "bg-emerald-600 text-white" : "bg-slate-200 text-slate-600" }`} > {state.step > step ? ( ) : ( step )}
{step < 5 && (
step ? "bg-emerald-600" : "bg-slate-200" }`} /> )}
))}
{error && (

{error}

)} {/* Step 1: School & Contact Info */} {state.step === 1 && ( School & Contact Information Provide your school's basic information and designated contacts
setState((prev) => ({ ...prev, schoolName: e.target.value, })) } placeholder="e.g., Gymnasium Berlin" />
setState((prev) => ({ ...prev, dpoName: e.target.value })) } placeholder="Full name" />
setState((prev) => ({ ...prev, dpoEmail: e.target.value })) } placeholder="dpo@school.de" />
setState((prev) => ({ ...prev, schultragerName: e.target.value, })) } placeholder="e.g., City of Berlin" />
setState((prev) => ({ ...prev, schultragerEmail: e.target.value, })) } placeholder="admin@schultraeger.de" />
)} {/* Step 2: Retention Periods (coming in next iteration) */} {state.step === 2 && ( Data Retention Periods Configure retention periods for each data category (state-specific defaults provided)

Retention periods have been pre-seeded based on your state's regulations. Your DPO should review and confirm these settings.

)} {/* Step 3: Consultations */} {state.step === 3 && ( Consultation Checklist Log consultations with staff and parent bodies per module
{MODULES.map((module) => (

{module.label}

{!module.requiresDpia && ( )} {module.requiresDpia && ( )}
))}
)} {/* Step 4: DPIA Gating */} {state.step === 4 && ( DPIA (Data Protection Impact Assessment) Upload completed DPIAs for high-risk modules before enabling them {MODULES.filter((m) => m.requiresDpia).map((module) => (

{module.label} DPIA

Upload your completed DPIA document (PDF)

{ if (e.target.files?.[0]) { setState((prev) => ({ ...prev, dpiaModules: { ...prev.dpiaModules, [module.id]: { completed: true, documentUrl: e.target.files![0].name, }, }, })); } }} className="block w-full text-sm text-slate-500 file:mr-4 file:py-2 file:px-4 file:rounded file:border-0 file:text-sm file:font-semibold file:bg-emerald-50 file:text-emerald-700 hover:file:bg-emerald-100" /> {state.dpiaModules[module.id]?.documentUrl && (

{state.dpiaModules[module.id].documentUrl}

)}
))}
)} {/* Step 5: Summary & Complete */} {state.step === 5 && ( Compliance Setup Complete Review your configuration before finalizing

All compliance requirements have been configured. Your school is now ready for production use.

DPO: {state.dpoName} ({state.dpoEmail})

State: {state.bundesland}

Modules: {MODULES.length} configured

)}
); }