Spaces:
Build error
Build error
File size: 7,055 Bytes
1e3f08b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | import { useState, useEffect } from 'react';
import Link from 'next/link';
export default function Header({ cartCount, setIsCartOpen }) {
const [searchTerm, setSearchTerm] = useState('');
const [isMenuOpen, setIsMenuOpen] = useState(false);
const handleSearch = (e) => {
e.preventDefault();
if (searchTerm.trim()) {
window.location.href = `/?search=${encodeURIComponent(searchTerm)}`;
}
};
return (
<header className="sticky top-0 z-50">
{/* Top Banner */}
<div className="bg-amazon-dark text-white py-1 px-4 text-xs text-center">
<span>
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" rel="noopener noreferrer" className="text-amazon-yellow hover:underline">
Built with anycoder
</a>
{' '} - The best AI-powered coding assistant
</span>
</div>
{/* Main Header */}
<div className="bg-amazon-light text-white">
<div className="max-w-7xl mx-auto px-4">
<div className="flex items-center justify-between h-16">
{/* Logo */}
<Link href="/" className="flex items-center space-x-2">
<div className="bg-white text-amazon-light px-3 py-1 rounded font-bold text-xl tracking-wider">
amazon
</div>
<span className="text-sm hidden sm:inline">.clone</span>
</Link>
{/* Search Bar */}
<form onSubmit={handleSearch} className="flex-1 max-w-2xl mx-4 hidden md:flex">
<div className="flex w-full rounded overflow-hidden">
<select className="bg-gray-100 text-gray-800 px-3 py-2 text-sm border-r border-gray-300 outline-none">
<option>All</option>
<option>Electronics</option>
<option>Books</option>
<option>Fashion</option>
<option>Home</option>
</select>
<input
type="text"
placeholder="Search Amazon"
className="flex-1 px-4 py-2 text-gray-800 outline-none"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
<button
type="submit"
className="bg-amazon-orange px-6 py-2 hover:bg-orange-600 transition-colors"
>
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
</div>
</form>
{/* Right Section */}
<div className="flex items-center space-x-6">
{/* Language */}
<button className="hidden sm:flex items-center space-x-1 text-sm">
<span>🇺🇸</span>
<span>EN</span>
</button>
{/* Account & Lists */}
<div className="hidden sm:block cursor-pointer">
<div className="text-xs text-gray-300">Hello, Sign in</div>
<div className="text-sm font-bold">Account & Lists</div>
</div>
{/* Returns */}
<div className="hidden sm:block cursor-pointer">
<div className="text-xs text-gray-300">Returns</div>
<div className="text-sm font-bold">& Orders</div>
</div>
{/* Cart */}
<button
onClick={() => setIsCartOpen(true)}
className="flex items-center space-x-1 relative"
>
<svg className="w-8 h-8" fill="currentColor" viewBox="0 0 24 24">
<path d="M7 18c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm10 0c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zM7.2 14.6l.1-.1 1.1-2h7.4c.8 0 1.4-.4 1.7-1l3.9-7-1.7-1-3.9 7H8.5L4.3 2H1v2h2l3.6 7.6-1.4 2.5c-.1.2-.2.5-.2.9 0 1.1.9 2 2 2h12v-2H7.4c-.1 0-.2-.1-.2-.2z"/>
</svg>
<span className="absolute -top-1 -right-1 bg-amazon-orange text-white text-xs font-bold rounded-full w-5 h-5 flex items-center justify-center">
{cartCount}
</span>
<span className="text-sm font-bold hidden sm:inline">Cart</span>
</button>
{/* Mobile Menu Button */}
<button
className="md:hidden"
onClick={() => setIsMenuOpen(!isMenuOpen)}
>
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16M4 18h16" />
</svg>
</button>
</div>
</div>
</div>
</div>
{/* Secondary Header */}
<div className="bg-gray-800 text-white">
<div className="max-w-7xl mx-auto px-4">
<div className="flex items-center space-x-6 h-10 overflow-x-auto">
<button className="flex items-center space-x-1 text-sm hover:text-gray-300">
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
<path d="M3 18h18v-2H3v2zm0-5h18v-2H3v2zm0-7v2h18V6H3z"/>
</svg>
<span className="font-bold">All</span>
</button>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Today's Deals</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Customer Service</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Registry</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Gift Cards</a>
<a href="#" className="text-sm whitespace-nowrap hover:text-gray-300">Sell</a>
</div>
</div>
</div>
{/* Mobile Search */}
<form onSubmit={handleSearch} className="md:hidden bg-amazon-light p-2">
<div className="flex">
<select className="bg-gray-100 text-gray-800 px-3 py-2 text-sm border-r border-gray-300 outline-none rounded-l">
<option>All</option>
</select>
<input
type="text"
placeholder="Search Amazon"
className="flex-1 px-4 py-2 text-gray-800 outline-none"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
/>
<button
type="submit"
className="bg-amazon-orange px-4 py-2 rounded-r"
>
<svg className="w-5 h-5 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z" />
</svg>
</button>
</div>
</form>
</header>
);
} |