/* 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 { Button, Input, Radio, RadioGroup, Tag } from '@douyinfe/semi-ui'; import { Image, Palette, Sparkles, Type, Wand2 } from 'lucide-react'; import { CARTOON_AVATAR_PRESETS, USER_AVATAR_TYPES, getCartoonAvatarDataUrl, getInitialAvatarDataUrl, } from '../../../../helpers'; const AVATAR_TYPE_OPTIONS = [ { value: USER_AVATAR_TYPES.PRESET, label: '卡通形象', desc: '从系统内置卡通头像中选择,适合默认展示', icon: Palette, }, { value: USER_AVATAR_TYPES.INITIAL, label: '姓名首字', desc: '根据用户名自动生成简洁文字头像', icon: Type, }, { value: USER_AVATAR_TYPES.CUSTOM, label: '图片链接', desc: '填写公网图片 URL,使用自己的头像', icon: Image, }, ]; 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('选择你在平台内展示的头像样式')}

{t('头像预览')}
{username}
{t('该头像会同步展示在右上角用户入口和体验中心文本对话中。')}
{t('实时预览')}
handleAvatarSettingChange('avatarType', e.target.value) } className='!flex !flex-wrap !gap-2' > {AVATAR_TYPE_OPTIONS.map((option) => { const Icon = option.icon; return ( {t(option.label)} ); })}

{t( AVATAR_TYPE_OPTIONS.find( (item) => item.value === avatarSettings.avatarType, )?.desc || '', )}

{avatarSettings.avatarType === USER_AVATAR_TYPES.PRESET && (
{CARTOON_AVATAR_PRESETS.map((preset) => { const selected = avatarSettings.avatarPreset === preset.id; return ( ); })}
)} {avatarSettings.avatarType === USER_AVATAR_TYPES.CUSTOM && (
handleAvatarSettingChange('customAvatarUrl', value) } placeholder={t( '请输入图片 URL,例如 https://example.com/avatar.png', )} prefix={} showClear />

{t('支持公网图片链接。若图片加载失败,会回退到默认卡通头像。')}

)}
); }; export default AvatarSection;