diff --git a/src/components/layout/Navbar.tsx b/src/components/layout/Navbar.tsx index 87368b3..25308b5 100644 --- a/src/components/layout/Navbar.tsx +++ b/src/components/layout/Navbar.tsx @@ -1,23 +1,21 @@ -import React, { useState, useEffect } from 'react'; -import { Link, useLocation } from 'react-router-dom'; +import React, { useState, useEffect, useRef } from 'react'; +import { Link, useLocation, useNavigate } from 'react-router-dom'; import { - Sparkles, + Search, Menu, X, - Layers, - Cpu, - CreditCard, - Building2, - GraduationCap, BookOpen, - Users, - Phone, - Download, - LogIn, - Bot, - MessageSquare + Cpu, + Layers, + Building2, + CreditCard, + Sparkles, + ArrowLeft, + GraduationCap } from 'lucide-react'; -import siteInfo from '../../data/siteInfo.json'; +import postsData from '../../data/posts.json'; +import toolsData from '../../data/tools.json'; +import modelsData from '../../data/models.json'; interface NavbarProps { onOpenAuth: () => void; @@ -25,12 +23,16 @@ interface NavbarProps { export const Navbar: React.FC = ({ onOpenAuth }) => { const [isOpen, setIsOpen] = useState(false); + const [isSearchOpen, setIsSearchOpen] = useState(false); + const [searchQuery, setSearchQuery] = useState(''); const [scrolled, setScrolled] = useState(false); const location = useLocation(); + const navigate = useNavigate(); + const searchInputRef = useRef(null); useEffect(() => { const handleScroll = () => { - if (window.scrollY > 20) { + if (window.scrollY > 15) { setScrolled(true); } else { setScrolled(false); @@ -40,174 +42,353 @@ export const Navbar: React.FC = ({ onOpenAuth }) => { return () => window.removeEventListener('scroll', handleScroll); }, []); - // Close mobile menu on route change + // Close menus on route change useEffect(() => { setIsOpen(false); + setIsSearchOpen(false); }, [location.pathname]); + // Focus search input when modal opens + useEffect(() => { + if (isSearchOpen) { + setTimeout(() => { + searchInputRef.current?.focus(); + }, 100); + } + }, [isSearchOpen]); + + // Handle escape key to close search modal + useEffect(() => { + const handleKeyDown = (e: KeyboardEvent) => { + if (e.key === 'Escape') { + setIsSearchOpen(false); + } + }; + window.addEventListener('keydown', handleKeyDown); + return () => window.removeEventListener('keydown', handleKeyDown); + }, []); + const navLinks = [ - { name: 'صفحه اصلی', path: '/' }, - { name: 'ابزارها', path: '/tools', icon: Layers }, - { name: 'مدل‌های زبانی', path: '/models', icon: Cpu }, - { name: 'تعرفه‌ها', path: '/pricing', icon: CreditCard }, - { name: 'راهکارهای سازمانی', path: '/enterprise', icon: Building2 }, - { name: 'آموزش هوش مصنوعی', path: '/academy', icon: GraduationCap }, - { name: 'رسانه و مقالات', path: '/blog', icon: BookOpen }, - { name: 'دستیار چت', path: '/chat', icon: MessageSquare, highlight: true }, - { name: 'درباره ما', path: '/about', icon: Users }, - { name: 'تماس با ما', path: '/contact', icon: Phone }, + { name: 'خانه', path: '/' }, + { name: 'رسانه', path: '/blog' }, + { name: 'مدل‌های زبانی', path: '/models' }, + { name: 'ابزارها', path: '/tools' }, + { name: 'راهکارهای سازمانی', path: '/enterprise' }, + { name: 'تعرفه', path: '/pricing' }, + { name: '+ هوشان', path: '/academy' }, ]; + // Quick search filter + const filteredPosts = searchQuery.trim() + ? postsData.filter(p => p.title.toLowerCase().includes(searchQuery.toLowerCase())).slice(0, 4) + : []; + + const filteredTools = searchQuery.trim() + ? toolsData.filter(t => t.title.toLowerCase().includes(searchQuery.toLowerCase()) || t.description.toLowerCase().includes(searchQuery.toLowerCase())).slice(0, 3) + : []; + + const filteredModels = searchQuery.trim() + ? modelsData.filter(m => m.name.toLowerCase().includes(searchQuery.toLowerCase()) || m.provider.toLowerCase().includes(searchQuery.toLowerCase())).slice(0, 3) + : []; + + const hasSearchResults = filteredPosts.length > 0 || filteredTools.length > 0 || filteredModels.length > 0; + return ( -
-
-
- - {/* Right: Logo & Brand */} - -
-
+ <> +
+
+
+ + {/* Right Side: Logo & Navigation Links */} +
+ {/* Authentic Houshan Owl Logo */} + Houshan AI Logo -
- - - - + + + {/* Desktop Navigation Links separated by | */} +
- -
-
- - {siteInfo.name} - - - AI - -
- - دستیار هوش مصنوعی مدیران - + + {/* Left Side: Search Button & Login/Register Button */} +
+ + {/* Search Icon Button */} + + + {/* Login / Register Button */} + + + {/* Mobile Menu Toggle Button */} + +
- - {/* Center: Desktop Navigation Links */} - - - {/* Left: Actions & Auth Button */} -
- - - دانلود اپلیکیشن - - -
- - {/* Mobile Menu Toggle Button */} -
- - -
-
-
- {/* Mobile Drawer Navigation */} - {isOpen && ( -
-
- {navLinks.map((link) => { - const Icon = link.icon; - const isActive = location.pathname === link.path; - return ( - - {Icon && } - {link.name} - - ); - })} + {/* Mobile Navigation Drawer */} + {isOpen && ( +
+
+ {navLinks.map((link) => { + const isActive = location.pathname === link.path; + return ( + setIsOpen(false)} + className={`flex items-center justify-between p-2.5 rounded-xl text-sm font-bold transition-colors ${ + isActive + ? 'bg-sky-50 text-sky-600 border border-sky-200' + : 'text-[#38b6ff] hover:bg-gray-50 hover:text-sky-600' + }`} + > + {link.name} + + ); + })} +
+ +
+ + + +
+ )} +
-
- - - دانلود مستقیم اپلیکیشن هوشان - - + {/* Global Interactive Search Modal */} + {isSearchOpen && ( +
+
e.stopPropagation()} + > + {/* Search Input Bar */} +
+ + setSearchQuery(e.target.value)} + placeholder="جستجو در مقالات، ابزارها، مدل‌ها و دوره‌ها..." + className="w-full bg-transparent text-slate-800 placeholder-gray-400 text-sm sm:text-base focus:outline-none" + /> + {searchQuery && ( + + )} + +
+ + {/* Live Search Results */} +
+ {!searchQuery.trim() ? ( +
+

عبارت مورد نظر خود را برای جستجو وارد کنید

+
+ پیشنهادها: + {['هوش مصنوعی', 'چت‌بات', 'Claude 3.5', 'ChatGPT', 'تولید تصویر', 'سئو'].map((tag) => ( + + ))} +
+
+ ) : !hasSearchResults ? ( +
+

نتیجه‌ای برای «{searchQuery}» یافت نشد.

+
+ ) : ( +
+ {/* Blog Articles */} + {filteredPosts.length > 0 && ( +
+

+ + مقالات و آموزش‌ها +

+
+ {filteredPosts.map((post) => ( + setIsSearchOpen(false)} + className="flex items-center justify-between p-2.5 rounded-xl hover:bg-gray-50 border border-transparent hover:border-gray-200 transition-all text-right group" + > + + {post.title} + + + + ))} +
+
+ )} + + {/* AI Tools */} + {filteredTools.length > 0 && ( +
+

+ + ابزارهای هوش مصنوعی +

+
+ {filteredTools.map((tool) => ( + setIsSearchOpen(false)} + className="flex items-center justify-between p-2.5 rounded-xl hover:bg-gray-50 border border-transparent hover:border-gray-200 transition-all text-right group" + > +
+ + {tool.title} + + + {tool.description} + +
+ + + ))} +
+
+ )} + + {/* AI Models */} + {filteredModels.length > 0 && ( +
+

+ + مدل‌های زبانی +

+
+ {filteredModels.map((model) => ( + setIsSearchOpen(false)} + className="flex items-center justify-between p-2.5 rounded-xl hover:bg-gray-50 border border-transparent hover:border-gray-200 transition-all text-right group" + > +
+ + {model.name} + + + ارائه دهنده: {model.provider} + +
+ + + ))} +
+
+ )} +
+ )} +
+ + {/* Modal Footer */} +
+ هوشان • پلتفرم جامع هوش مصنوعی +
+ ESC + جهت بستن +
+
)} -
+ ); };