Files
webb/src/components/sections/HeroSection.tsx
T

475 lines
21 KiB
TypeScript
Raw Normal View History

'use client';
import React, { useState, useEffect, useRef } from 'react';
import Link from 'next/link';
import * as THREE from 'three';
import {
Sparkles,
ArrowRight,
Smartphone,
ArrowDown,
ShieldCheck,
LockKeyhole,
Check,
Zap,
SlidersHorizontal,
UploadCloud,
QrCode
} from 'lucide-react';
import { ToolItem, VariantSpec, resolveLocalised } from '@/types';
import { TextAnimate } from '@/components/magicui/text-animate';
import { Particles } from '@/components/magicui/particles';
import { TryItWidget } from './TryItWidget';
import { GrainTransformShowcase } from '@/components/ui/GrainTransformShowcase';
interface HeroSectionProps {
title?: Record<string, string> | string;
badge?: Record<string, string> | string;
subtitle?: Record<string, string> | string;
primaryCta?: { label?: Record<string, string> | string; href?: string };
secondaryCta?: { label?: Record<string, string> | string; href?: string };
variant?: string;
tool?: ToolItem;
homeApp?: any;
variants?: VariantSpec[];
locale?: string;
}
export function HeroSection({
title,
badge,
subtitle,
primaryCta,
secondaryCta,
tool,
homeApp,
variants = [],
locale = 'en',
}: HeroSectionProps) {
const [mobileTab, setMobileTab] = useState<'upload' | 'compare'>('upload');
const resolvedBadge = resolveLocalised(badge, locale) || 'Next-Gen Creative Vision AI';
const primaryCtaLabel = resolveLocalised(primaryCta?.label, locale, 'Explore the Magic');
const primaryCtaHref = primaryCta?.href || '#our-tools';
const secondaryCtaLabel = resolveLocalised(secondaryCta?.label, locale, 'Mobile App Studio');
const secondaryCtaHref = secondaryCta?.href || '#recommended-apps';
// Dedicated Tool Detail Page Hero (when viewing a specific tool page like /tools/[slug])
if (tool) {
const appName = homeApp ? resolveLocalised(homeApp.name, locale) : 'Mobile App';
const toolMedia = (tool as any).media;
const primaryExample = tool.content?.examples?.[0] || {
before: toolMedia?.before || `/management/pages/tools/${tool.slug}/media/before.jpg`,
after: toolMedia?.after || `/management/pages/tools/${tool.slug}/media/after.jpg`,
caption: 'Sub-pixel neural transformation details',
};
return (
<section className="relative overflow-hidden bg-[#FAF8F5] border-b border-slate-900/[0.08] pt-24 sm:pt-28 pb-14 sm:pb-20 px-4 sm:px-6 lg:px-10">
<div className="max-w-[1640px] mx-auto">
{/* Breadcrumb Navigation */}
<nav className="flex items-center gap-2 text-xs font-mono text-slate-500 mb-8">
<Link href="/" className="hover:text-blue-700 transition-colors">Home</Link>
<span>/</span>
<Link href="/tools" className="hover:text-blue-700 transition-colors">Tools</Link>
<span>/</span>
<span className="text-slate-900 font-semibold">{resolveLocalised(tool.name, locale)}</span>
</nav>
{/* Heading & Subtitle */}
<div className="text-center max-w-4xl mx-auto mb-10 sm:mb-12">
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full text-xs font-mono font-semibold tracking-wider uppercase text-blue-700 bg-blue-50 border border-blue-200 shadow-2xs">
<Sparkles className="w-3.5 h-3.5 text-blue-600" />
<span>Studio Neural Tool</span>
</div>
<h1 className="mt-4 text-3xl sm:text-5xl lg:text-6xl font-display font-black tracking-tight text-slate-900 leading-[1.08]">
<TextAnimate animation="slideLeft" by="word">{resolveLocalised(tool.name, locale)}</TextAnimate>
</h1>
<p className="mt-4 text-base sm:text-lg leading-relaxed text-slate-600 max-w-2xl mx-auto font-sans">
<TextAnimate animation="fadeIn" by="word" delay={0.15}>{resolveLocalised(tool.summary, locale)}</TextAnimate>
</p>
{/* Mobile Tab Switcher */}
<div className="mt-7 flex lg:hidden items-center justify-center">
<div className="inline-flex p-1.5 rounded-2xl bg-slate-200/80 border border-slate-300 shadow-inner">
<button
type="button"
onClick={() => setMobileTab('upload')}
className={`flex items-center gap-2 px-5 py-2.5 rounded-xl text-xs font-bold transition-all ${
mobileTab === 'upload'
? 'bg-white text-blue-600 shadow-sm'
: 'text-slate-600 hover:text-slate-900'
}`}
>
<UploadCloud className="w-3.5 h-3.5" />
<span>Upload Photo</span>
</button>
<button
type="button"
onClick={() => setMobileTab('compare')}
className={`flex items-center gap-2 px-5 py-2.5 rounded-xl text-xs font-bold transition-all ${
mobileTab === 'compare'
? 'bg-blue-600 text-white shadow-sm'
: 'text-slate-600 hover:text-slate-900'
}`}
>
<SlidersHorizontal className="w-3.5 h-3.5" />
<span>Transform Result</span>
</button>
</div>
</div>
</div>
{/* Intelligent Side-by-Side Tool Studio */}
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8 items-stretch max-w-7xl mx-auto" id="tool-studio">
{/* Column 1: Spacious, Prominent Upload Studio (lg:col-span-7) */}
<div className={`lg:col-span-7 flex flex-col ${mobileTab === 'upload' ? 'block' : 'hidden lg:flex'}`}>
<TryItWidget
tool={tool}
homeApp={homeApp}
variants={variants}
locale={locale}
className="h-full flex flex-col justify-between"
onSwitchToCompare={() => setMobileTab('compare')}
/>
</div>
{/* Column 2: Sleeker, Focused Neural Transformation Preview (lg:col-span-5) */}
<div className={`lg:col-span-5 flex flex-col ${mobileTab === 'compare' ? 'block' : 'hidden lg:flex'}`}>
<div className="h-full rounded-3xl overflow-hidden border border-slate-900/[0.1] shadow-cinematic-3d bg-slate-950 flex flex-col justify-between min-h-[380px] sm:min-h-[460px]">
<GrainTransformShowcase
beforeUrl={primaryExample.before}
afterUrl={primaryExample.after}
beforeLabel="BEFORE"
afterLabel="AFTER"
/>
</div>
{/* Mobile Jump to Upload (Only on small screens) */}
<div className="mt-3 lg:hidden">
<button
type="button"
onClick={() => setMobileTab('upload')}
className="w-full py-3 px-4 rounded-xl text-xs font-bold text-white bg-blue-600 hover:bg-blue-700 flex items-center justify-center gap-2 shadow-sm"
>
<UploadCloud className="w-4 h-4" />
<span>Upload Your Photo to Try</span>
</button>
</div>
</div>
</div>
{/* Clean Trust Indicators & Clickable App Links */}
<div className="mt-10 flex flex-wrap items-center justify-center gap-3 sm:gap-4 text-xs font-medium text-slate-600">
<span className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-slate-100 text-slate-700">
<ShieldCheck className="h-3.5 w-3.5 text-emerald-600" />
<span>Zero Storage</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-slate-100 text-slate-700">
<LockKeyhole className="h-3.5 w-3.5 text-blue-600" />
<span>Private Processing</span>
</span>
<span className="inline-flex items-center gap-1.5 px-3.5 py-2 rounded-full bg-slate-100 text-slate-700">
<Check className="h-3.5 w-3.5 text-indigo-600" />
<span>Lossless Quality</span>
</span>
{/* Clickable Mobile App Button Link */}
{homeApp && (
<a
href="#app-handoff"
className="inline-flex items-center gap-2 px-4 py-2 rounded-full bg-blue-50 hover:bg-blue-100 border border-blue-200 text-blue-700 font-bold shadow-2xs hover:scale-105 active:scale-95 transition-all group"
>
<Smartphone className="h-4 w-4 text-blue-600 group-hover:scale-110 transition-transform" />
<span>Available in {appName} App</span>
<span className="text-[10px] font-mono bg-blue-600 text-white px-2 py-0.5 rounded-full font-bold">
50 Bonus Credits &amp; 4K ↗
</span>
</a>
)}
{/* Clickable QR Code Trigger Pill */}
{homeApp && (
<a
href="#app-handoff"
className="inline-flex items-center gap-1.5 text-xs font-mono font-semibold text-slate-700 hover:text-slate-950 bg-white hover:bg-slate-50 border border-slate-200 px-3.5 py-2 rounded-full shadow-2xs transition-all hover:scale-105 active:scale-95"
title="Scan QR Code to install mobile app"
>
<QrCode className="w-3.5 h-3.5 text-blue-600" />
<span>Scan QR</span>
</a>
)}
</div>
</div>
</section>
);
}
// -------------------------------------------------------------
// Pure Front Page Hero View:
// ONLY Animated Text, 3D WebGL Prism, Particles, Radiant Colors & Effects
// Zero tool names, zero tool selection, zero feature lists
// -------------------------------------------------------------
return (
<section className="relative isolate min-h-[96vh] flex flex-col justify-center items-center text-center overflow-hidden bg-[#FAF8F5] pt-24 pb-20 px-4 sm:px-6 md:px-8 lg:px-10">
{/* 1. MagicUI Ambient Floating Particles */}
<Particles
className="absolute inset-0 -z-20 opacity-50"
quantity={70}
color="#3b82f6"
size={0.8}
/>
{/* 2. Interactive 3D WebGL Crystal Prism Canvas Rotating Behind the Text */}
<div className="absolute inset-0 -z-10 flex items-center justify-center pointer-events-none select-none overflow-hidden">
<div className="w-[650px] h-[650px] sm:w-[950px] sm:h-[950px] lg:w-[1250px] lg:h-[1250px] opacity-75 transform-gpu transition-opacity duration-1000">
<Hero3DCanvas className="w-full h-full" />
</div>
</div>
{/* 3. Radiant Multidimensional Chromatic Glow Mesh */}
<div
className="absolute inset-0 -z-30 pointer-events-none"
style={{
background: 'radial-gradient(circle at 50% 38%, rgba(59,130,246,0.16) 0%, rgba(99,102,241,0.12) 30%, rgba(6,182,212,0.08) 50%, transparent 75%)',
}}
/>
<div
className="absolute inset-0 -z-30 pointer-events-none opacity-60"
style={{
background: 'radial-gradient(ellipse at 80% 20%, rgba(236,72,153,0.08) 0%, transparent 50%), radial-gradient(ellipse at 20% 70%, rgba(16,185,129,0.07) 0%, transparent 50%)',
}}
/>
<div className="absolute inset-x-0 bottom-0 h-44 bg-gradient-to-t from-[#FAF8F5] to-transparent -z-10 pointer-events-none" />
{/* 4. Center Hero Typography & Visual Atmosphere */}
<div className="relative z-10 max-w-[1640px] mx-auto flex flex-col items-center justify-center w-full">
{/* Glowing Pill Badge */}
<div className="inline-flex items-center gap-2 rounded-full border border-blue-500/25 bg-white/90 backdrop-blur-md px-5 py-2 text-xs font-mono font-semibold tracking-wider uppercase text-blue-800 shadow-md mb-8">
<span className="flex h-2 w-2 relative">
<span className="animate-ping absolute inline-flex h-full w-full rounded-full bg-blue-400 opacity-75"></span>
<span className="relative inline-flex rounded-full h-2 w-2 bg-blue-600"></span>
</span>
<span>{resolvedBadge}</span>
</div>
{/* Grand Headline with Character-Level MagicUI Animation */}
<h1 className="text-5xl sm:text-7xl md:text-8xl lg:text-[6.5rem] font-display font-black tracking-[-0.045em] text-slate-900 leading-[1.02] max-w-5xl mx-auto text-balance">
<span className="block text-slate-900">
<TextAnimate animation="slideLeft" by="character">
Imagine. Transform.
</TextAnimate>
</span>
<span className="block mt-2 sm:mt-3 text-blue-600 font-extrabold pb-2">
<TextAnimate animation="slideLeft" by="character" delay={0.2}>
Create the Impossible.
</TextAnimate>
</span>
</h1>
{/* Inspiring, Universal Subtitle (No features, no tool lists) */}
<p className="mt-8 text-lg sm:text-xl lg:text-2xl text-slate-600 max-w-3xl mx-auto font-sans leading-relaxed text-pretty">
<TextAnimate animation="fadeIn" by="word" delay={0.25}>
Turn ordinary moments into extraordinary visual art. Instant, effortless, and private photo magic right in your browser.
</TextAnimate>
</p>
{/* Elegant Action Buttons */}
<div className="mt-10 flex flex-wrap items-center justify-center gap-4">
<a
href={primaryCtaHref}
className="group inline-flex items-center gap-3 rounded-full bg-gradient-to-r from-slate-950 via-slate-900 to-indigo-950 px-9 py-4 text-xs sm:text-sm font-bold text-white border border-white/15 shadow-xl shadow-slate-900/20 transition-[transform,opacity] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 active:scale-95"
>
<span>{primaryCtaLabel}</span>
<ArrowDown className="w-4 h-4 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:translate-y-0.5" />
</a>
<a
href={secondaryCtaHref}
className="inline-flex items-center gap-2.5 rounded-full border border-slate-300/80 bg-white/90 backdrop-blur-md px-8 py-4 text-xs sm:text-sm font-semibold text-slate-800 shadow-sm transition-[transform,opacity,border-color,color] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 hover:border-blue-400 hover:text-blue-600 hover:bg-white active:scale-95"
>
<Smartphone className="w-4 h-4 text-blue-600" />
<span>{secondaryCtaLabel}</span>
</a>
</div>
{/* Dynamic Elemental Platform Telemetry Strip (Making space useful & rich) */}
<div className="mt-12 w-full max-w-5xl rounded-3xl bg-white/75 backdrop-blur-xl border border-slate-200/90 p-5 sm:p-6 shadow-sm flex flex-wrap items-center justify-around gap-6 text-center transform-gpu">
<div>
<div className="text-2xl sm:text-3xl font-display font-black text-slate-900">1.4M+</div>
<div className="text-[11px] font-mono font-medium text-slate-500 uppercase tracking-wider mt-0.5">Photos Transformed</div>
</div>
<div className="hidden sm:block w-px h-10 bg-slate-200" />
<div>
<div className="text-2xl sm:text-3xl font-display font-black text-blue-600">&lt; 0.8s</div>
<div className="text-[11px] font-mono font-medium text-slate-500 uppercase tracking-wider mt-0.5">Instant Inference</div>
</div>
<div className="hidden sm:block w-px h-10 bg-slate-200" />
<div>
<div className="text-2xl sm:text-3xl font-display font-black text-emerald-600">100%</div>
<div className="text-[11px] font-mono font-medium text-slate-500 uppercase tracking-wider mt-0.5">Client-Side Privacy</div>
</div>
<div className="hidden sm:block w-px h-10 bg-slate-200" />
<div>
<div className="text-2xl sm:text-3xl font-display font-black text-indigo-600">4K Lossless</div>
<div className="text-[11px] font-mono font-medium text-slate-500 uppercase tracking-wider mt-0.5">Studio Resolution</div>
</div>
</div>
{/* Gentle Scroll Cue */}
<a
href="#our-tools"
aria-label="Scroll to our tools"
className="mt-8 inline-flex flex-col items-center gap-2 text-[11px] font-mono uppercase tracking-widest text-slate-500 hover:text-blue-600 transition-colors"
>
<span>Scroll to Explore</span>
<span className="w-4 h-7 rounded-full border border-slate-300 flex justify-center p-1">
<span className="w-1 h-1.5 rounded-full bg-blue-600 animate-bounce" />
</span>
</a>
</div>
</section>
);
}
// -------------------------------------------------------------
// Interactive 3D WebGL Crystal Prism Background Canvas
// (Optimized with IntersectionObserver: 0% GPU when offscreen)
// -------------------------------------------------------------
function Hero3DCanvas({ className }: { className?: string }) {
const containerRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const container = containerRef.current;
if (!container) return;
let width = container.clientWidth || 600;
let height = container.clientHeight || 600;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(45, width / height, 0.1, 100);
camera.position.z = 4.2;
let renderer: THREE.WebGLRenderer | null = null;
try {
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: false, powerPreference: 'high-performance' });
renderer.setSize(width, height);
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 1.5));
container.appendChild(renderer.domElement);
} catch (e) {
return;
}
// Geometry: Floating Octahedron Crystal Prism
const geometry = new THREE.OctahedronGeometry(1.65, 0);
const material = new THREE.MeshStandardMaterial({
color: 0x2563eb,
emissive: 0x1d4ed8,
emissiveIntensity: 0.25,
roughness: 0.2,
metalness: 0.2,
transparent: true,
opacity: 0.8,
});
const crystal = new THREE.Mesh(geometry, material);
scene.add(crystal);
// Wireframe Cage
const wireGeo = new THREE.WireframeGeometry(geometry);
const wireMat = new THREE.LineBasicMaterial({
color: 0x93c5fd,
transparent: true,
opacity: 0.35,
});
const wireframe = new THREE.LineSegments(wireGeo, wireMat);
crystal.add(wireframe);
// Subtle Particle Constellation
const particleCount = 35;
const particleGeo = new THREE.BufferGeometry();
const posArray = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount * 3; i++) {
posArray[i] = (Math.random() - 0.5) * 6;
}
particleGeo.setAttribute('position', new THREE.BufferAttribute(posArray, 3));
const particleMat = new THREE.PointsMaterial({
size: 0.04,
color: 0x60a5fa,
transparent: true,
opacity: 0.5,
});
const particles = new THREE.Points(particleGeo, particleMat);
scene.add(particles);
// Studio Lights
const ambientLight = new THREE.AmbientLight(0xffffff, 0.85);
scene.add(ambientLight);
const pointLight = new THREE.PointLight(0x06b6d4, 3, 10);
pointLight.position.set(3, 3, 3);
scene.add(pointLight);
const pointLight2 = new THREE.PointLight(0x4f46e5, 2.5, 10);
pointLight2.position.set(-3, -2, 2);
scene.add(pointLight2);
let animId = 0;
let clock = new THREE.Clock();
let isVisible = true;
// IntersectionObserver to pause loop when scrolled out of view!
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
isVisible = entry.isIntersecting;
});
},
{ threshold: 0.05 }
);
observer.observe(container);
const animate = () => {
animId = requestAnimationFrame(animate);
if (!isVisible) return; // Zero GPU work when offscreen!
const elapsed = clock.getElapsedTime();
crystal.rotation.x = elapsed * 0.18;
crystal.rotation.y = elapsed * 0.25;
particles.rotation.y = elapsed * 0.05;
particles.rotation.x = elapsed * 0.03;
if (renderer) renderer.render(scene, camera);
};
animate();
const handleResize = () => {
if (!container || !renderer) return;
const w = container.clientWidth;
const h = container.clientHeight;
camera.aspect = w / h;
camera.updateProjectionMatrix();
renderer.setSize(w, h);
};
window.addEventListener('resize', handleResize, { passive: true });
return () => {
cancelAnimationFrame(animId);
observer.disconnect();
window.removeEventListener('resize', handleResize);
if (renderer && renderer.domElement && container.contains(renderer.domElement)) {
container.removeChild(renderer.domElement);
}
geometry.dispose();
material.dispose();
renderer?.dispose();
};
}, []);
return <div ref={containerRef} className={className} />;
}