import { useState } from 'react' import { Plus, Check } from 'lucide-react' import { useProfile } from '../context/ProfileContext' import { api } from '../utils/api' const COLORS = ['#1D9E75','#378ADD','#D85A30','#EF9F27','#7F77DD','#D4537E','#639922','#888780'] const AVATARS = ['👤','👦','👧','👨','👩','🧔','👴','👵','🧒','🧑'] function Avatar({ profile, size=48, onClick, selected }) { const initials = profile.name.split(' ').map(n=>n[0]).join('').toUpperCase().slice(0,2) return (
{initials}
) } export { Avatar } export default function ProfileSelect() { const { profiles, setActiveProfile, refreshProfiles } = useProfile() const [creating, setCreating] = useState(false) const [newName, setNewName] = useState('') const [newColor, setNewColor] = useState(COLORS[0]) const [saving, setSaving] = useState(false) const handleCreate = async () => { if (!newName.trim()) return setSaving(true) try { const p = await api.createProfile({ name: newName.trim(), avatar_color: newColor }) // Refresh profile list first, then set active await refreshProfiles() setActiveProfile(p) setCreating(false) setNewName('') } catch(e) { console.error('Create profile error:', e) } finally { setSaving(false) } } return (
BodyTrack
Wer bist du?
{profiles.map(p => (
setActiveProfile(p)} style={{display:'flex',alignItems:'center',gap:14,padding:'14px 16px', background:'var(--surface)',borderRadius:14,marginBottom:10,cursor:'pointer', border:'1.5px solid var(--border)',transition:'all 0.15s'}} onMouseEnter={e=>e.currentTarget.style.borderColor='var(--accent)'} onMouseLeave={e=>e.currentTarget.style.borderColor='var(--border)'}>
{p.name}
{p.sex==='m'?'Männlich':'Weiblich'}{p.height?` · ${p.height} cm`:''} {p.goal_weight?` · Ziel: ${p.goal_weight} kg`:''}
→
))} {!creating ? ( ) : (
Neues Profil
setNewName(e.target.value)} onKeyDown={e=>e.key==='Enter'&&handleCreate()} style={{width:'100%',padding:'10px 12px',borderRadius:8,fontSize:15,fontWeight:500, border:'1.5px solid var(--border2)',background:'var(--surface2)', color:'var(--text1)',fontFamily:'var(--font)',boxSizing:'border-box',marginBottom:12}} autoFocus/>
Farbe wählen
{COLORS.map(c=>(
setNewColor(c)} style={{width:32,height:32,borderRadius:'50%',background:c,cursor:'pointer', border:`3px solid ${newColor===c?'white':'transparent'}`, boxShadow:newColor===c?`0 0 0 2px ${c}`:'none',transition:'all 0.1s'}}/> ))}
)}
) }