'use client'; import React from 'react'; import { Icons } from '@/components/ui/Icon'; import { usePlayerSettings } from '../hooks/usePlayerSettings'; import { createPortal } from 'react-dom'; interface DesktopMoreMenuProps { showMoreMenu: boolean; isProxied?: boolean; onToggleMoreMenu: () => void; onMouseEnter: () => void; onMouseLeave: () => void; onCopyLink: (type?: 'original' | 'proxy') => void; containerRef: React.RefObject; } export function DesktopMoreMenu({ showMoreMenu, isProxied = false, onToggleMoreMenu, onMouseEnter, onMouseLeave, onCopyLink, containerRef }: DesktopMoreMenuProps) { const { autoNextEpisode, autoSkipIntro, skipIntroSeconds, autoSkipOutro, skipOutroSeconds, showModeIndicator, setAutoNextEpisode, setAutoSkipIntro, setSkipIntroSeconds, setAutoSkipOutro, setSkipOutroSeconds, setShowModeIndicator, } = usePlayerSettings(); const buttonRef = React.useRef(null); const [menuPosition, setMenuPosition] = React.useState({ top: 0, left: 0 }); React.useEffect(() => { if (showMoreMenu && buttonRef.current && containerRef.current) { const buttonRect = buttonRef.current.getBoundingClientRect(); const containerRect = containerRef.current.getBoundingClientRect(); setMenuPosition({ top: buttonRect.bottom - containerRect.top + 10, left: buttonRect.left - containerRect.left }); } }, [showMoreMenu, containerRef]); const handleToggle = () => { if (!showMoreMenu && buttonRef.current && containerRef.current) { const buttonRect = buttonRef.current.getBoundingClientRect(); const containerRect = containerRef.current.getBoundingClientRect(); setMenuPosition({ top: buttonRect.bottom - containerRect.top + 10, left: buttonRect.left - containerRect.left }); } onToggleMoreMenu(); }; const MenuContent = (
e.stopPropagation()} > {/* Copy Link Options */} {isProxied ? ( <> ) : ( )} {/* Divider */}
{/* Show Mode Indicator Switch */}
显示模式指示器
{/* Auto Next Episode Switch */}
自动下一集
{/* Skip Intro Switch */}
跳过片头
{/* Expandable Input */} {autoSkipIntro && (
时长: setSkipIntroSeconds(parseInt(e.target.value) || 0)} className="w-16 px-2 py-1 text-sm text-center bg-[var(--glass-bg)] border border-[var(--glass-border)] rounded-[var(--radius-2xl)] text-[var(--text-color)] focus:outline-none focus:border-[var(--accent-color)] no-spinner" onClick={(e) => e.stopPropagation()} />
)}
{/* Skip Outro Switch */}
跳过片尾
{/* Expandable Input */} {autoSkipOutro && (
剩余: setSkipOutroSeconds(parseInt(e.target.value) || 0)} className="w-16 px-2 py-1 text-sm text-center bg-[var(--glass-bg)] border border-[var(--glass-border)] rounded-[var(--radius-2xl)] text-[var(--text-color)] focus:outline-none focus:border-[var(--accent-color)] no-spinner" onClick={(e) => e.stopPropagation()} />
)}
); return (
{/* More Menu Dropdown (Portal) */} {showMoreMenu && typeof document !== 'undefined' && createPortal(MenuContent, containerRef.current || document.body)}
); }