import React, { useState, useRef } from 'react'; import { ChevronRightIcon } from '../../assets/icons/ChevronRightIcon'; import SeoConsentModal from '../SeoConsent/SeoConsentModal'; import { IS_WORDPRESS } from '../../constants'; interface QuickLink { label: string; href: string; external?: boolean; action?: () => void; } const baseLinks: QuickLink[] = [ { label: 'Privacy', href: 'https://wpassistant.ai/privacy/', external: true }, { label: 'Terms', href: 'https://wpassistant.ai/terms/', external: true }, { label: 'Sitemap', href: 'https://wpassistant.ai/html-sitemap/', external: true }, ]; const WORDPRESS_HELP_LINK: QuickLink = { label: 'Human WordPress Help', href: 'https://wpassistant.ai/human-wordpress-help/', external: true, }; const QuickLinks: React.FC = () => { const [isOpen, setIsOpen] = useState(false); const [isModalOpen, setIsModalOpen] = useState(false); const timeoutRef = useRef(); // Optionally, detect if it's a mobile device const isMobile = window.matchMedia('(pointer: coarse)').matches; const handleMouseEnter = () => { // Show dropdown only if it's not a mobile device if (!isMobile) { if (timeoutRef.current) { clearTimeout(timeoutRef.current); } setIsOpen(true); } }; const handleMouseLeave = () => { if (!isMobile) { timeoutRef.current = setTimeout(() => { setIsOpen(false); }, 75); } }; const handleClick = () => { // If it is mobile, toggle on click if (isMobile) { setIsOpen(!isOpen); } }; const openModal = () => { setIsOpen(false); setIsModalOpen(true); }; // Add privacy preferences link const links = IS_WORDPRESS ? baseLinks.filter(link => link.label !== 'Sitemap') : baseLinks; const allLinks = IS_WORDPRESS ? [...links, WORDPRESS_HELP_LINK] : [ ...links, { label: 'Content Use', href: '#', action: openModal } ]; return (
{/* Desktop menu */} {isOpen && !isMobile && (
{allLinks.map((link, index) => ( { if (link.action) { e.preventDefault(); link.action(); } }} className="block px-3 py-2 text-sm dark:text-gray-400 text-gray-500 hover:text-foreground hover:bg-secondary/10 dark:hover:bg-secondary/40 transition-colors duration-0 rounded-lg" > {link.label} ))}
)} {/* Mobile menu */} {isOpen && isMobile && (
{allLinks.map((link, index) => ( { if (link.action) { e.preventDefault(); link.action(); } }} className="block px-3 py-2 text-sm dark:text-gray-400 text-gray-500 hover:text-foreground hover:bg-secondary/10 dark:hover:bg-secondary/40 transition-colors duration-0 rounded-lg" > {link.label} ))}
)} {isModalOpen && ( setIsModalOpen(false)} /> )}
); }; export default React.memo(QuickLinks);