import Slider from '@react-native-community/slider'; import * as Haptics from 'expo-haptics'; import { Stack, useRouter } from 'expo-router'; import React, { useState } from 'react'; import { ScrollView, View, Text, TextInput, Pressable, Alert, Modal } from 'react-native'; import { SafeAreaView } from 'react-native-safe-area-context'; import { Icon } from '@/components/Icon'; import { useResponsive } from '@/hooks/useResponsive'; import type { MoodSequenceItem } from '@/store/store'; import { useStore } from '@/store/store'; import { getThemeColors } from '@/utils/theme'; const TRANSITION_OPTIONS = [ { label: '2s', value: 2 }, { label: '5s', value: 5 }, { label: '10s', value: 10 }, ]; export default function CreateSequence() { const router = useRouter(); const moods = useStore((state) => state.moods); const settings = useStore((state) => state.settings); const addSequence = useStore((state) => state.addSequence); const [name, setName] = useState(''); const [transitionDuration, setTransitionDuration] = useState(5); const [items, setItems] = useState([]); const [showMoodPicker, setShowMoodPicker] = useState(false); const theme = getThemeColors(); const responsive = useResponsive(); const handleHaptic = () => { if (settings.hapticFeedback) { Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); } }; const addMoodToSequence = (moodId: string) => { handleHaptic(); setItems([...items, { moodId, duration: 300 }]); // 5 Minuten default setShowMoodPicker(false); }; const formatDuration = (seconds: number) => { const mins = Math.floor(seconds / 60); const secs = seconds % 60; if (mins === 0) { return `${secs} Sek`; } else if (secs === 0) { return `${mins} Min`; } else { return `${mins} Min ${secs} Sek`; } }; const removeMoodFromSequence = (index: number) => { handleHaptic(); setItems(items.filter((_, i) => i !== index)); }; const updateMoodDuration = (index: number, duration: number) => { handleHaptic(); const newItems = [...items]; newItems[index].duration = duration; setItems(newItems); }; const handleCreate = () => { if (!name.trim()) { Alert.alert('Fehler', 'Bitte gib einen Namen ein'); return; } if (items.length === 0) { Alert.alert('Fehler', 'Bitte füge mindestens einen Mood hinzu'); return; } handleHaptic(); addSequence({ name: name.trim(), items, transitionDuration, isCustom: true, }); Alert.alert('Erfolg', 'Sequenz wurde erstellt!', [ { text: 'OK', onPress: () => router.back(), }, ]); }; const getMoodById = (id: string) => moods.find((m) => m.id === id); return ( {/* Name Input */} Name {/* Transition Duration */} Übergangsdauer {TRANSITION_OPTIONS.map((option) => ( { handleHaptic(); setTransitionDuration(option.value); }} className={`rounded-full px-4 py-2 ${ transitionDuration === option.value ? 'bg-blue-500' : 'bg-gray-200' }`} > {option.label} ))} {/* Moods in Sequenz */} Moods ({items.length}) {items.map((item, index) => { const mood = getMoodById(item.moodId); if (!mood) return null; return ( {/* Mood Name & Delete */} {index + 1}. {mood.name} removeMoodFromSequence(index)} className="ml-2"> {/* Duration Slider */} Dauer: {formatDuration(item.duration)} updateMoodDuration(index, Math.round(value))} minimumTrackTintColor="#3B82F6" maximumTrackTintColor="#4B5563" thumbTintColor="#3B82F6" /> 1 Sek 60 Min ); })} {/* Add Mood Button */} { handleHaptic(); setShowMoodPicker(true); }} className="mt-2 items-center rounded-xl bg-gray-700 p-3" > + Mood hinzufügen {/* Create Button */} Sequenz speichern {/* Mood Picker Modal */} setShowMoodPicker(false)} > Mood auswählen { handleHaptic(); setShowMoodPicker(false); }} > {moods.map((mood) => ( addMoodToSequence(mood.id)} className="mb-2 rounded-xl bg-gray-800 p-4" > {mood.name} ))} ); }