'use client' import { useState, useEffect, useRef } from 'react' interface InlineInputProps { value: string onSave: (val: string) => Promise className?: string type?: 'text' | 'number' } export function InlineInput({ value, onSave, className, type = 'text' }: InlineInputProps) { const [isEditing, setIsEditing] = useState(false) const [currentValue, setCurrentValue] = useState(value) const inputRef = useRef(null) useEffect(() => { setCurrentValue(value) }, [value]) useEffect(() => { if (isEditing && inputRef.current) { inputRef.current.focus() } }, [isEditing]) const handleBlur = async () => { setIsEditing(false) if (currentValue !== value) { await onSave(currentValue) } } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter') { handleBlur() } } if (isEditing) { return ( setCurrentValue(e.target.value)} onBlur={handleBlur} onKeyDown={handleKeyDown} className={`bg-white/10 text-white border border-primary px-1 rounded outline-none w-full ${className}`} /> ) } return ( setIsEditing(true)} className={`cursor-pointer hover:bg-white/5 rounded px-1 transition ${className}`} > {value || Klicken zum Bearbeiten} ) }