diff --git a/src/components/sections/ToolGridSection.tsx b/src/components/sections/ToolGridSection.tsx index 5321876..3f2716f 100644 --- a/src/components/sections/ToolGridSection.tsx +++ b/src/components/sections/ToolGridSection.tsx @@ -1,8 +1,19 @@ 'use client'; -import React, { useState, useMemo } from 'react'; +import React, { useState, useMemo, useRef, useEffect } from 'react'; import Link from 'next/link'; -import { Search, ArrowRight, Wand2, Scissors, Smile, Palette, RefreshCcw } from 'lucide-react'; +import { + Search, + ArrowRight, + Wand2, + Scissors, + Smile, + Palette, + Sparkles, + ChevronLeft, + ChevronRight, + X, +} from 'lucide-react'; import { ToolItem, CategoryItem, AppItem, resolveLocalised } from '@/types'; interface ToolGridSectionProps { @@ -18,62 +29,359 @@ interface ToolGridSectionProps { locale?: string; } +type ToolMediaConfig = + | { type: 'comparison'; before: string; after: string } + | { type: 'single'; image: string; badge: string }; + +// Media resolver for tool cards +function getToolMedia(tool: ToolItem): ToolMediaConfig { + const example = tool.content?.examples?.[0]; + + // Specific bespoke high-res local media + if (tool.slug === 'background-remover') { + return { + type: 'single', + image: '/management/pages/home/sections/our-tools/background-remover/poster.jpg', + badge: 'Alpha Matting', + }; + } + + if (tool.slug === 'polaroid-maker') { + return { + type: 'single', + image: '/management/pages/home/sections/our-tools/polaroid-maker/image.jpg', + badge: 'Vintage Polaroid', + }; + } + + const localDefaults: Record = { + 'blemish-remover': { + before: '/management/pages/home/sections/our-tools/blemish-remover/before.jpg', + after: '/management/pages/home/sections/our-tools/blemish-remover/after.jpg', + }, + 'teeth-whitener': { + before: '/management/pages/home/sections/our-tools/teeth-whitener/before.jpg', + after: '/management/pages/home/sections/our-tools/teeth-whitener/after.jpg', + }, + 'photo-enhancer': { + before: '/management/pages/home/sections/our-tools/photo-enhancer/before.jpg', + after: '/management/pages/home/sections/our-tools/photo-enhancer/after.jpg', + }, + 'old-photo-restorer': { + before: '/management/pages/home/sections/our-tools/old-photo-restorer/before.jpg', + after: '/management/pages/home/sections/our-tools/old-photo-restorer/after.jpg', + }, + 'colorization': { + before: '/management/pages/home/sections/our-tools/colorization/before.jpg', + after: '/management/pages/home/sections/our-tools/colorization/after.jpg', + }, + 'cartoon-avatar': { + before: '/management/pages/home/sections/our-tools/cartoon-avatar/before.jpg', + after: '/management/pages/home/sections/our-tools/cartoon-avatar/after.jpg', + }, + }; + + const matched = localDefaults[tool.slug]; + if (matched) { + return { + type: 'comparison', + before: matched.before, + after: matched.after, + }; + } + + if (example && example.before && example.after) { + return { + type: 'comparison', + before: example.before, + after: example.after, + }; + } + + return { + type: 'single', + image: example?.after || '/management/pages/home/sections/our-tools/blemish-remover/after.jpg', + badge: 'AI Studio', + }; +} + +// Category design themes +const CATEGORY_THEMES: Record< + string, + { + icon: React.ReactNode; + color: string; + badgeBg: string; + border: string; + } +> = { + 'portrait-retouch': { + icon: , + color: 'text-rose-600', + badgeBg: 'bg-rose-50 text-rose-700 border-rose-200', + border: 'border-rose-100', + }, + 'restoration': { + icon: , + color: 'text-indigo-600', + badgeBg: 'bg-indigo-50 text-indigo-700 border-indigo-200', + border: 'border-indigo-100', + }, + 'background-cutout': { + icon: , + color: 'text-emerald-600', + badgeBg: 'bg-emerald-50 text-emerald-700 border-emerald-200', + border: 'border-emerald-100', + }, + 'creative-art': { + icon: , + color: 'text-amber-600', + badgeBg: 'bg-amber-50 text-amber-700 border-amber-200', + border: 'border-amber-100', + }, +}; + +// Interactive Before/After Card Image Component +function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string }) { + const [splitPos, setSplitPos] = useState(50); + const media = getToolMedia(tool); + + const handleMouseMove = (e: React.MouseEvent) => { + const rect = e.currentTarget.getBoundingClientRect(); + const x = e.clientX - rect.left; + const pct = Math.max(5, Math.min(95, (x / rect.width) * 100)); + setSplitPos(pct); + }; + + const handleMouseLeave = () => { + setSplitPos(50); + }; + + if (media.type === 'single') { + return ( +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {toolName} + {/* Floating badge */} + + {media.badge} + + + Try Tool ↗ + +
+ ); + } + + return ( +
+ {/* Enhanced / After Image (Underneath) */} + {/* eslint-disable-next-line @next/next/no-img-element */} + {`${toolName} + + {/* Original / Before Image (Clipped overlay) */} +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {`${toolName} +
+ + {/* Vertical Slider Divider */} +
+ {/* Sleek handle pill */} +
+
+
+
+
+
+
+ + {/* Floating badges */} + + Before + + + CRE AI + + + Try Tool ↗ + +
+ ); +} + +// Single Image-Dominant Tool Card Component (~75% Image, Minimal Text) +function ToolCard({ tool, locale }: { tool: ToolItem; locale: string }) { + const toolName = resolveLocalised(tool.name, locale); + const toolSummary = resolveLocalised(tool.summary, locale); + + return ( + + {/* Image Dominant Preview (~75% of visual area) */} + + + {/* Minimalist Info Area: Only Title & Subtitle */} +
+
+

+ {toolName} +

+
+ +
+
+ +

+ {toolSummary} +

+
+ + ); +} + export function ToolGridSection({ title, subtitle, tools = [], categories = [], - apps = [], - showSearch = false, - showCategoryFilter = false, - limit, + showSearch = true, + showCategoryFilter = true, locale = 'en', }: ToolGridSectionProps) { const [selectedCategory, setSelectedCategory] = useState('all'); const [searchQuery, setSearchQuery] = useState(''); + const railRef = useRef(null); - const appMap = useMemo(() => new Map(apps.map((a) => [a.id, a])), [apps]); + // Group tools by category + const categorizedTools = useMemo(() => { + const orderedCategoryIds = [ + 'portrait-retouch', + 'restoration', + 'background-cutout', + 'creative-art', + ]; - const filteredTools = useMemo(() => { - let list = tools; - if (selectedCategory !== 'all') { - list = list.filter((t) => t.category === selectedCategory); - } - if (searchQuery.trim()) { - const q = searchQuery.toLowerCase(); - list = list.filter((t) => { - const name = resolveLocalised(t.name, locale).toLowerCase(); - const summary = resolveLocalised(t.summary, locale).toLowerCase(); - return name.includes(q) || summary.includes(q); + const catMap = new Map(); + categories.forEach((cat) => catMap.set(cat.id, cat)); + + return orderedCategoryIds + .map((catId) => { + const cat = catMap.get(catId); + const catTools = tools.filter((t) => t.category === catId); + return { + id: catId, + category: cat, + tools: catTools, + }; + }) + .filter((group) => group.tools.length > 0); + }, [categories, tools]); + + // Filter tools when search query is active + const searchResults = useMemo(() => { + if (!searchQuery.trim()) return null; + const q = searchQuery.toLowerCase(); + return tools.filter((t) => { + const name = resolveLocalised(t.name, locale).toLowerCase(); + const summary = resolveLocalised(t.summary, locale).toLowerCase(); + return name.includes(q) || summary.includes(q); + }); + }, [tools, searchQuery, locale]); + + // Smooth scroll rail for categories + const scrollRail = (direction: 'left' | 'right') => { + if (railRef.current) { + railRef.current.scrollBy({ + left: direction === 'left' ? -220 : 220, + behavior: 'smooth', }); } - if (limit && limit > 0) { - list = list.slice(0, limit); - } - return list; - }, [tools, selectedCategory, searchQuery, limit, locale]); - - const getCategoryIcon = (catId: string) => { - switch (catId) { - case 'portrait-retouch': - return ; - case 'restoration': - return ; - case 'background-cutout': - return ; - case 'creative-art': - return ; - default: - return ; - } }; + // Scroll to category section + const handleCategoryClick = (catId: string) => { + setSelectedCategory(catId); + if (searchQuery) setSearchQuery(''); + + if (catId === 'all') { + const el = document.getElementById('tools-catalog'); + if (el) { + el.scrollIntoView({ behavior: 'smooth', block: 'start' }); + } + } else { + const el = document.getElementById(`category-${catId}`); + if (el) { + el.scrollIntoView({ behavior: 'smooth', block: 'start' }); + } + } + }; + + // Active category observer as user scrolls + useEffect(() => { + if (searchQuery) return; + + const observer = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting) { + const id = entry.target.id.replace('category-', ''); + setSelectedCategory(id); + } + }); + }, + { + rootMargin: '-30% 0px -60% 0px', + threshold: 0, + } + ); + + categorizedTools.forEach((group) => { + const el = document.getElementById(`category-${group.id}`); + if (el) observer.observe(el); + }); + + return () => observer.disconnect(); + }, [categorizedTools, searchQuery]); + return ( -
+
{/* Section Heading */} {(title || subtitle) && ( -
+
{title && (

{resolveLocalised(title, locale)} @@ -87,143 +395,223 @@ export function ToolGridSection({

)} - {/* Search & Filters */} - {(showSearch || showCategoryFilter) && ( -
- {showCategoryFilter && categories.length > 0 && ( -
- - {categories.map((cat) => ( + {/* Sticky Horizontal Scrolling Category Bar & Search */} + {(showCategoryFilter || showSearch) && ( +
+
+ {/* Category Rail with Smooth Scrolling */} + {showCategoryFilter && ( +
+ {/* Left Scroll Arrow */} - ))} -
- )} - {showSearch && ( -
- - setSearchQuery(e.target.value)} - className="w-full pl-10 pr-4 py-2.5 rounded-full text-xs sm:text-sm border border-slate-300 bg-white text-slate-900 placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 shadow-sm" - /> -
- )} + {/* Horizontal Scrollable Categories Container */} +
+ {/* All Categories Pill */} + + + {/* Individual Category Pills */} + {categorizedTools.map((group) => { + const isSelected = + selectedCategory === group.id && !searchQuery; + const catName = group.category + ? resolveLocalised(group.category.name, locale) + : group.id; + const theme = CATEGORY_THEMES[group.id]; + + return ( + + ); + })} +
+ + {/* Right Scroll Arrow */} + +
+ )} + + {/* Integrated Search Input */} + {showSearch && ( +
+ + setSearchQuery(e.target.value)} + className="w-full pl-10 pr-9 py-2 rounded-full text-xs sm:text-sm border border-slate-200 bg-white text-slate-900 placeholder-slate-400 focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 shadow-sm" + /> + {searchQuery && ( + + )} +
+ )} +
)} - {/* Tools Cards Grid with Visual Image Previews */} -
- {filteredTools.map((tool) => { - const homeApp = appMap.get(tool.homeApp); - const example = tool.content?.examples?.[0]; - - return ( -
+
+

+ Found {searchResults.length}{' '} + {searchResults.length === 1 ? 'tool' : 'tools'} matching " + {searchQuery}" +

+ +
- {/* Category Tag & Icon */} -
- - {tool.category} - -
- {getCategoryIcon(tool.category)} + {searchResults.length > 0 ? ( +
+ {searchResults.map((tool) => ( + + ))} +
+ ) : ( +
+

+ No photo tools found matching "{searchQuery}" +

+

+ Try searching for "blemish", "restoration", + "background", or "avatar". +

+ +
+ )} +
+ ) : ( + /* Categorized Tools Sections */ +
+ {categorizedTools.map((group) => { + const theme = CATEGORY_THEMES[group.id]; + const catName = group.category + ? resolveLocalised(group.category.name, locale) + : group.id; + const catDesc = group.category + ? resolveLocalised(group.category.description, locale) + : ''; + + return ( +
+ {/* Category Header */} +
+
+
+ {theme?.icon || } +
+
+
+

+ {catName} +

+ + {group.tools.length}{' '} + {group.tools.length === 1 ? 'tool' : 'tools'} + +
+ {catDesc && ( +

+ {catDesc} +

+ )} +
-

- {resolveLocalised(tool.name, locale)} -

- -

- {resolveLocalised(tool.summary, locale)} -

+ {/* Category Tools Grid with Image-Dominant Cards */} +
+ {group.tools.map((tool) => ( + + ))} +
- -
- {homeApp && ( -
- Home App: - - {resolveLocalised(homeApp.name, locale)} - -
- )} - - - Try Free Online - - -
-
- ); - })} -
- - {filteredTools.length === 0 && ( -
-

No photo tools found matching "{searchQuery}"

-

Try searching for "blemish", "background", "photo", or clear filters.

+ ); + })}
)}