'use client'; import React, { useState, useMemo, useRef, useEffect, useCallback } from 'react'; import Link from 'next/link'; import { Search, ArrowRight, Wand2, Scissors, Smile, Palette, Sparkles, X, Layers, ShieldCheck, Zap, Smartphone, SlidersHorizontal, ChevronRight, RotateCcw, } from 'lucide-react'; import { ToolItem, CategoryItem, AppItem, resolveLocalised } from '@/types'; import { KineticText } from '@/components/magicui/kinetic-text'; import { AnimatedShinyText } from '@/components/magicui/animated-shiny-text'; import { BorderBeam } from '@/components/magicui/border-beam'; import { RainbowButton } from '@/components/magicui/rainbow-button'; interface ToolGridSectionProps { title?: any; subtitle?: any; tools?: ToolItem[]; categories?: CategoryItem[]; apps?: AppItem[]; showSearch?: boolean; showCategoryFilter?: boolean; limit?: number; columns?: number; locale?: string; } type ToolMediaConfig = | { type: 'comparison'; before: string; after: string } | { type: 'video'; videoUrl: string; poster?: string; badge: string } | { type: 'single'; image: string; badge: string }; // Comprehensive media resolver for all tools function getToolMedia(tool: ToolItem): ToolMediaConfig { const example = tool.content?.examples?.[0]; const localDefaults: Record = { 'blemish-remover': { type: 'comparison', before: '/management/pages/home/sections/our-tools/blemish-remover/before.jpg', after: '/management/pages/home/sections/our-tools/blemish-remover/after.jpg', }, 'teeth-whitener': { type: 'comparison', before: '/management/pages/home/sections/our-tools/teeth-whitener/before.jpg', after: '/management/pages/home/sections/our-tools/teeth-whitener/after.jpg', }, 'eye-redness-remover': { type: 'comparison', before: '/management/pages/home/sections/our-tools/eye-redness-remover/before.jpg', after: '/management/pages/home/sections/our-tools/eye-redness-remover/after.jpg', }, 'eye-bag-remover': { type: 'comparison', before: '/management/pages/home/sections/our-tools/eye-bag-remover/before.jpg', after: '/management/pages/home/sections/our-tools/eye-bag-remover/after.jpg', }, 'portrait-glow': { type: 'comparison', before: '/management/pages/home/sections/our-tools/portrait-glow/before.jpg', after: '/management/pages/home/sections/our-tools/portrait-glow/after.jpg', }, 'photo-enhancer': { type: 'comparison', 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': { type: 'comparison', 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': { type: 'comparison', before: '/management/pages/home/sections/our-tools/colorization/before.jpg', after: '/management/pages/home/sections/our-tools/colorization/after.jpg', }, 'cartoon-avatar': { type: 'comparison', before: '/management/pages/home/sections/our-tools/cartoon-avatar/before.jpg', after: '/management/pages/home/sections/our-tools/cartoon-avatar/after.jpg', }, 'object-eraser': { type: 'comparison', before: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=800&auto=format&fit=crop&q=80', after: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=800&auto=format&fit=crop&q=80', }, 'background-remover': { type: 'single', image: '/management/pages/home/sections/our-tools/background-remover/poster.jpg', badge: 'Alpha Matting', }, 'polaroid-maker': { type: 'single', image: '/management/pages/home/sections/our-tools/polaroid-maker/image.jpg', badge: 'Vintage Polaroid', }, }; const matched = localDefaults[tool.slug]; if (matched) return matched; 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', }; } // Model specification tags for pro-grade UI const TOOL_MODEL_SPECS: Record = { 'blemish-remover': 'Sub-pore Retouch GAN', 'teeth-whitener': 'Enamel Luminance Refiner', 'eye-redness-remover': 'Sclera Chromatic Balancer', 'eye-bag-remover': 'Periorbital Volume Fill', 'portrait-glow': 'Three-Point Studio Relight', 'photo-enhancer': 'Real-ESRGAN 4K Super-Res', 'old-photo-restorer': 'Archival Scratches & Deblur', 'colorization': 'Historical Spectral Chroma', 'cartoon-avatar': 'CartoonGAN Anime Synthesis', 'object-eraser': 'Edge-Guided Inpainting', 'background-remover': 'P3M Deep Alpha Matting', 'polaroid-maker': 'Emulsion Color Matrix', }; // Category visual themes aligned to Porcelain Light theme const CATEGORY_THEMES: Record< string, { icon: React.ReactNode; color: string; badgeBg: string; description: string; } > = { 'portrait-retouch': { icon: , color: 'text-rose-600', badgeBg: 'bg-rose-500/10 text-rose-700 border-rose-500/20', description: 'Sub-pore blemish removal, enamel whitening, redness clearing, and radiant studio lighting.', }, 'restoration': { icon: , color: 'text-indigo-600', badgeBg: 'bg-indigo-500/10 text-indigo-700 border-indigo-500/20', description: 'Super-resolution 4K deblurring, vintage scratch removal, and authentic archival colorization.', }, 'background-cutout': { icon: , color: 'text-emerald-600', badgeBg: 'bg-emerald-500/10 text-emerald-700 border-emerald-500/20', description: 'P3M deep learning alpha matting separating hair strands, semi-transparent glass, and edges.', }, 'creative-art': { icon: , color: 'text-amber-600', badgeBg: 'bg-amber-500/10 text-amber-700 border-amber-500/20', description: 'Cel-shaded anime synthesis, vintage Polaroid emulsion borders, and object generative fill.', }, }; // Interactive Before/After Card Image Component with Pointer and Touch scrubbing function ToolCardImage({ tool, toolName }: { tool: ToolItem; toolName: string }) { const [splitPos, setSplitPos] = useState(50); const containerRef = useRef(null); const isDraggingRef = useRef(false); const videoRef = useRef(null); const media = getToolMedia(tool); // Video autoplay gating with IntersectionObserver useEffect(() => { if (media.type !== 'video') return; const video = videoRef.current; if (!video) return; let isIntersecting = false; const updatePlayState = () => { if (isIntersecting && !document.hidden) { video.play().catch(() => {}); } else { video.pause(); } }; const observer = new IntersectionObserver( ([entry]) => { isIntersecting = entry.isIntersecting; updatePlayState(); }, { threshold: 0.1 } ); observer.observe(video); return () => { observer.disconnect(); video.pause(); }; }, [media.type]); const updatePosition = useCallback((clientX: number) => { if (!containerRef.current) return; const rect = containerRef.current.getBoundingClientRect(); if (rect.width <= 0) return; const x = Math.max(0, Math.min(clientX - rect.left, rect.width)); const pct = Math.max(4, Math.min(96, (x / rect.width) * 100)); setSplitPos(pct); }, []); const handlePointerDown = (e: React.PointerEvent) => { if (media.type !== 'comparison') return; isDraggingRef.current = true; try { e.currentTarget.setPointerCapture(e.pointerId); } catch {} updatePosition(e.clientX); }; const handlePointerMove = (e: React.PointerEvent) => { if (media.type !== 'comparison') return; if (isDraggingRef.current || e.pointerType === 'mouse') { updatePosition(e.clientX); } }; const handlePointerUp = (e: React.PointerEvent) => { isDraggingRef.current = false; try { e.currentTarget.releasePointerCapture(e.pointerId); } catch {} }; const handlePointerLeave = (e: React.PointerEvent) => { if (e.pointerType === 'mouse' && !isDraggingRef.current) { setSplitPos(50); } }; // 1. VIDEO TOOL (Background Remover) if (media.type === 'video') { return (
); } // 2. SINGLE IMAGE (Polaroid, etc.) if (media.type === 'single') { return (
{/* eslint-disable-next-line @next/next/no-img-element */} {toolName}
); } // 3. COMPARISON (Interactive Split Slider) 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 Line */}
{/* Sleek handle pill */}
); } // Spacious Single Tool Card Component function ToolCard({ tool, locale, categoryName, }: { tool: ToolItem; locale: string; categoryName?: string; }) { const toolName = resolveLocalised(tool.name, locale); const toolSummary = resolveLocalised(tool.summary, locale); return (
{/* Image Dominant Preview Frame */} {/* Info Area: Title, Subtitle, and Direct Action Button */}
{/* Tool Title */}

{toolName}

{/* Tool Description */}

{toolSummary}

{/* Action Button Row */}
Try tool in browser
); } export function ToolGridSection({ title, subtitle, tools = [], categories = [], showSearch = true, showCategoryFilter = true, locale = 'en', }: ToolGridSectionProps) { const [selectedCategory, setSelectedCategory] = useState('all'); const [searchQuery, setSearchQuery] = useState(''); // Group all tools by category const categorizedTools = useMemo(() => { const orderedCategoryIds = [ 'portrait-retouch', 'restoration', 'background-cutout', 'creative-art', ]; 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]); // Synchronize with URL Hash (e.g. #category-portrait-retouch or #portrait-retouch) useEffect(() => { const syncFromHash = () => { if (typeof window === 'undefined') return; const hash = window.location.hash.replace('#', ''); if (!hash) return; const rawId = hash.startsWith('category-') ? hash.replace('category-', '') : hash; const exists = categorizedTools.some((g) => g.id === rawId); if (exists) { setSelectedCategory(rawId); setSearchQuery(''); } }; syncFromHash(); window.addEventListener('hashchange', syncFromHash); return () => window.removeEventListener('hashchange', syncFromHash); }, [categorizedTools]); // Handle Category Selection with URL Hash reflection const handleSelectCategory = (catId: string) => { setSelectedCategory(catId); if (searchQuery) setSearchQuery(''); if (typeof window !== 'undefined') { const newHash = catId === 'all' ? '' : `#category-${catId}`; window.history.replaceState(null, '', newHash || window.location.pathname); } }; // 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]); // Active Category details const activeCategoryItem = useMemo(() => { if (selectedCategory === 'all') return null; return categorizedTools.find((g) => g.id === selectedCategory); }, [categorizedTools, selectedCategory]); // Categories to display const displayedCategories = useMemo(() => { if (selectedCategory === 'all') { return categorizedTools; } return categorizedTools.filter((group) => group.id === selectedCategory); }, [categorizedTools, selectedCategory]); // If this is a simple embedded grid (e.g., inside an App detail page), render standard container if (!showCategoryFilter) { return (
{title && (

{resolveLocalised(title, locale)}

)}
{tools.map((tool) => ( ))}
); } // ========================================================================= // FULL EDGE-TO-EDGE STUDIO WORKSPACE ARCHITECTURE (/tools) // Left Sidebar is docked directly to the left screen edge. // Right Main Studio area fills the remaining screen width with spacious cards. // ========================================================================= return (
{/* Studio Lighting Ambient Glow */}