import { useState } from 'react'; function Settings({ profiles, activeProfileId, onSaveProfiles, onChangeActiveProfile, onCloseSettings, onSaveSummarizationProfile, summarizationProfile }) { const [localProfiles, setLocalProfiles] = useState(profiles); const [localSummarizationProfile, setLocalSummarizationProfile] = useState(summarizationProfile || { id: 'default-summarization-profile', apiEndpoint: '', apiKey: '', model: 'DeepSeek-R1' }); const [editingProfileId, setEditingProfileId] = useState(activeProfileId); const [isHintExpanded, setIsHintExpanded] = useState(false); const editingProfile = localProfiles.find(p => p.id === editingProfileId) || localProfiles[0]; const editingSummarizationProfile = localSummarizationProfile; const handleProfileChange = (updatedProfile) => { setLocalProfiles(localProfiles.map(p => p.id === updatedProfile.id ? updatedProfile : p )); }; const handleSummarizationProfileChange = (updatedProfile) => { setLocalSummarizationProfile(updatedProfile); }; const handleAddProfile = () => { const newId = `profile-${Date.now()}`; const newProfile = { id: newId, name: `New Profile ${localProfiles.length + 1}`, apiEndpoint: '', apiKey: '', model: 'DeepSeek-R1' }; const updatedProfiles = [...localProfiles, newProfile]; setLocalProfiles(updatedProfiles); setEditingProfileId(newId); }; const handleDeleteProfile = (profileId) => { if (localProfiles.length <= 1) { alert("Cannot delete the last profile"); return; } const updatedProfiles = localProfiles.filter(p => p.id !== profileId); setLocalProfiles(updatedProfiles); if (editingProfileId === profileId) { setEditingProfileId(updatedProfiles[0].id); } }; const handleSubmit = (e) => { e.preventDefault(); onSaveProfiles(localProfiles); onSaveSummarizationProfile(localSummarizationProfile); onChangeActiveProfile(editingProfileId); onCloseSettings(); }; return (