import { useState, useCallback } from 'react' import type { Project } from '../types/kanban' import { useI18n } from '../i18n' interface ProjectSelectorProps { projects: Project[] activeId: string onSelect: (id: string) => void onCreate: (id: string) => void onDelete?: (id: string) => void } export function ProjectSelector({ projects, activeId, onSelect, onCreate, onDelete }: ProjectSelectorProps) { const { t } = useI18n() const [creating, setCreating] = useState(false) const [newName, setNewName] = useState('') const [confirmDelete, setConfirmDelete] = useState(null) const handleCreate = useCallback(() => { const id = newName.trim().toLowerCase().replace(/[^a-z0-9_-]+/g, '-').replace(/^-|-$/g, '') if (!id) return onCreate(id) setNewName('') setCreating(false) }, [newName, onCreate]) const handleDelete = useCallback(() => { if (!confirmDelete || !onDelete) return onDelete(confirmDelete) setConfirmDelete(null) }, [confirmDelete, onDelete]) return (
{creating ? (
{ e.preventDefault(); handleCreate() }} style={{ display: 'flex', gap: 4 }} > setNewName(e.target.value)} onKeyDown={e => { if (e.key === 'Escape') setCreating(false) }} style={{ width: 120 }} />
) : ( )} {onDelete && activeId !== 'default' && !confirmDelete && ( )} {confirmDelete && (

{t('project.confirmTitle', { name: confirmDelete })}

{t('project.confirmBody')}

)}
) }