/* Copyright (C) 2025 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import React from 'react'; import { Segmented } from 'antd'; import { Button, Input } from '@/components/ui'; import { Check } from 'lucide-react'; import { CARTOON_AVATAR_PRESETS, USER_AVATAR_TYPES, getCartoonAvatarDataUrl, getInitialAvatarDataUrl, } from '../../../../helpers'; import SectionHeader from '../components/SectionHeader'; const AVATAR_TYPE_OPTIONS = [ { value: USER_AVATAR_TYPES.PRESET, label: '卡通形象' }, { value: USER_AVATAR_TYPES.INITIAL, label: '姓名首字' }, { value: USER_AVATAR_TYPES.CUSTOM, label: '图片链接' }, ]; const AvatarSection = ({ t, userState, avatarSettings, handleAvatarSettingChange, saveAvatarSettings, savingAvatarSettings, }) => { const username = userState?.user?.display_name || userState?.user?.username || 'User'; const previewUrl = avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM && avatarSettings.customAvatarUrl ? avatarSettings.customAvatarUrl : avatarSettings.avatarType === USER_AVATAR_TYPES.INITIAL ? getInitialAvatarDataUrl(username, 128) : getCartoonAvatarDataUrl(avatarSettings.avatarPreset, 128); const customAvatarInvalid = avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM && !avatarSettings.customAvatarUrl?.trim(); return (
{t('保存头像')} } />
{t('头像预览')} {username} {t('实时预览')}

{t('头像将同步显示在用户入口和体验中心对话中')}

{t('头像类型')}
handleAvatarSettingChange('avatarType', value)} options={AVATAR_TYPE_OPTIONS.map((option) => ({ value: option.value, label: t(option.label), }))} /> {avatarSettings.avatarType === USER_AVATAR_TYPES.PRESET && (
{t('选择卡通形象')}
{CARTOON_AVATAR_PRESETS.map((preset) => { const selected = avatarSettings.avatarPreset === preset.id; return ( ); })}
)} {avatarSettings.avatarType === USER_AVATAR_TYPES.INITIAL && (

{t('根据用户名自动生成简洁文字头像')}

)} {avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM && (
{t('图片链接')}
handleAvatarSettingChange('customAvatarUrl', value) } placeholder='https://example.com/avatar.png' showClear />
)}
); }; export default AvatarSection;