import { useState, useRef } from 'react' import { useTranslation } from 'react-i18next' import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query' import { brandingApi, setCachedBranding } from '../../api/branding' import { setCachedAnimationEnabled } from '../AnimatedBackground' import { setCachedFullscreenEnabled } from '../../hooks/useTelegramWebApp' import { UploadIcon, TrashIcon, PencilIcon, CheckIcon, CloseIcon } from './icons' import { Toggle } from './Toggle' interface BrandingTabProps { accentColor?: string } export function BrandingTab({ accentColor = '#3b82f6' }: BrandingTabProps) { const { t } = useTranslation() const queryClient = useQueryClient() const fileInputRef = useRef(null) const [editingName, setEditingName] = useState(false) const [newName, setNewName] = useState('') // Queries const { data: branding } = useQuery({ queryKey: ['branding'], queryFn: brandingApi.getBranding, }) const { data: animationSettings } = useQuery({ queryKey: ['animation-enabled'], queryFn: brandingApi.getAnimationEnabled, }) const { data: fullscreenSettings } = useQuery({ queryKey: ['fullscreen-enabled'], queryFn: brandingApi.getFullscreenEnabled, }) const { data: emailAuthSettings } = useQuery({ queryKey: ['email-auth-enabled'], queryFn: brandingApi.getEmailAuthEnabled, }) // Mutations const updateBrandingMutation = useMutation({ mutationFn: brandingApi.updateName, onSuccess: (data) => { setCachedBranding(data) queryClient.invalidateQueries({ queryKey: ['branding'] }) setEditingName(false) }, }) const uploadLogoMutation = useMutation({ mutationFn: brandingApi.uploadLogo, onSuccess: (data) => { setCachedBranding(data) queryClient.invalidateQueries({ queryKey: ['branding'] }) }, }) const deleteLogoMutation = useMutation({ mutationFn: brandingApi.deleteLogo, onSuccess: (data) => { setCachedBranding(data) queryClient.invalidateQueries({ queryKey: ['branding'] }) }, }) const updateAnimationMutation = useMutation({ mutationFn: (enabled: boolean) => brandingApi.updateAnimationEnabled(enabled), onSuccess: (data) => { setCachedAnimationEnabled(data.enabled) queryClient.invalidateQueries({ queryKey: ['animation-enabled'] }) }, }) const updateFullscreenMutation = useMutation({ mutationFn: (enabled: boolean) => brandingApi.updateFullscreenEnabled(enabled), onSuccess: (data) => { setCachedFullscreenEnabled(data.enabled) queryClient.invalidateQueries({ queryKey: ['fullscreen-enabled'] }) }, }) const updateEmailAuthMutation = useMutation({ mutationFn: (enabled: boolean) => brandingApi.updateEmailAuthEnabled(enabled), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['email-auth-enabled'] }) }, }) const handleLogoUpload = (e: React.ChangeEvent) => { const file = e.target.files?.[0] if (file) { uploadLogoMutation.mutate(file) } } return (
{/* Logo & Name */}

{t('admin.settings.logoAndName')}

{/* Logo */}
{branding?.has_custom_logo ? ( Logo ) : ( branding?.logo_letter || 'V' )}
{branding?.has_custom_logo && ( )}
{/* Name */}
{editingName ? (
setNewName(e.target.value)} className="flex-1 px-4 py-2 rounded-xl bg-dark-700 border border-dark-600 text-dark-100 focus:outline-none focus:border-accent-500" maxLength={50} />
) : (
{branding?.name || t('admin.settings.notSpecified')}
)}
{/* Animation & Fullscreen toggles */}

{t('admin.settings.interfaceOptions')}

{t('admin.settings.animatedBackground')}

{t('admin.settings.animatedBackgroundDesc')}

updateAnimationMutation.mutate(!(animationSettings?.enabled ?? true))} disabled={updateAnimationMutation.isPending} />
{t('admin.settings.autoFullscreen')}

{t('admin.settings.autoFullscreenDesc')}

updateFullscreenMutation.mutate(!(fullscreenSettings?.enabled ?? false))} disabled={updateFullscreenMutation.isPending} />
{t('admin.settings.emailAuth')}

{t('admin.settings.emailAuthDesc')}

updateEmailAuthMutation.mutate(!(emailAuthSettings?.enabled ?? true))} disabled={updateEmailAuthMutation.isPending} />
) }