import React, { useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; import { UserMeResponse } from '../types/api'; import LanguageSwitch from './LanguageSwitch'; import { NAV } from './navItems'; interface SettingsPanelProps { variant: 'sidebar' | 'bottom'; onClose: () => void; onNavigate: (id: string) => void; activeItem: string; userInfo?: UserMeResponse | null; credits?: number | null; isGuest: boolean; isLoggingOut?: boolean; onLogout?: () => void; onLoginClick: () => void; /** 팝업을 여는 설정 버튼 영역. 외부 클릭 닫기에서 제외해 재클릭 시 토글이 정상 동작하게 한다 */ anchorRef?: React.RefObject; } const SettingsPanel: React.FC = ({ variant, onClose, onNavigate, activeItem, userInfo, credits, isGuest, isLoggingOut, onLogout, onLoginClick, anchorRef, }) => { const { t } = useTranslation(); const panelRef = useRef(null); useEffect(() => { const handleClickOutside = (e: MouseEvent) => { const target = e.target as Node; if (anchorRef?.current?.contains(target)) return; if (panelRef.current && !panelRef.current.contains(target)) { onClose(); } }; const handleEscape = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('mousedown', handleClickOutside); document.addEventListener('keydown', handleEscape); return () => { document.removeEventListener('mousedown', handleClickOutside); document.removeEventListener('keydown', handleEscape); }; }, [onClose, anchorRef]); return (
{/* 1) 프로필 — 패널 헤더 역할 */} {!isGuest && ( <>
{userInfo?.profile_image_url || userInfo?.thumbnail_image_url ? ( Profile ) : (
)}

{userInfo?.nickname || t('sidebar.defaultUser')}

{credits !== null && credits !== undefined && (

{t('sidebar.credits', { count: credits })}

)}
)} {/* 2) 메뉴 그룹 — 대시보드 */}
{/* 3) 하단 그룹 — 언어 전환 / 로그아웃(로그인) / 고객의견 */}
{isGuest ? ( ) : ( )} {t('sidebar.inquiry')}
); }; export default SettingsPanel;