import React, { useState } from 'react'; import { View, Text, ScrollView, KeyboardAvoidingView, Platform, Switch, Alert, } from 'react-native'; import { router, Stack } from 'expo-router'; import { Icon } from '~/components/ui/Icon'; import { useDeckStore } from '../../store/deckStore'; import { Button } from '../../components/ui/Button'; import { Input } from '../../components/ui/Input'; import { Card } from '../../components/ui/Card'; import { useThemeColors } from '~/utils/themeUtils'; import { spacing } from '~/utils/spacing'; export default function CreateDeckScreen() { const colors = useThemeColors(); const [title, setTitle] = useState(''); const [description, setDescription] = useState(''); const [isPublic, setIsPublic] = useState(false); const [tags, setTags] = useState(''); const [errors, setErrors] = useState<{ title?: string }>({}); const { createDeck, isLoading } = useDeckStore(); const validateForm = () => { const newErrors: { title?: string } = {}; if (!title.trim()) { newErrors.title = 'Titel ist erforderlich'; } else if (title.length < 3) { newErrors.title = 'Titel muss mindestens 3 Zeichen lang sein'; } setErrors(newErrors); return Object.keys(newErrors).length === 0; }; const handleCreate = async () => { if (!validateForm()) return; try { const deck = await createDeck({ title: title.trim(), description: description.trim() || undefined, is_public: isPublic, tags: tags .split(',') .map((tag) => tag.trim()) .filter((tag) => tag.length > 0), }); Alert.alert('Deck erstellt!', 'Dein Deck wurde erfolgreich erstellt.', [ { text: 'OK', onPress: () => router.replace(`/deck/${deck.id}`), }, ]); } catch (error: any) { Alert.alert('Fehler', error.message || 'Deck konnte nicht erstellt werden'); } }; return ( <> ( router.back()} style={{ marginLeft: 10 }} library="Ionicons" /> ), }} /> Öffentliches Deck Andere Nutzer können dein Deck sehen und lernen ); }