'use client' import React, { useState } from 'react' import { motion } from 'framer-motion' import type { Page, Media } from '../../payload-types' import Link from 'next/link' import Image from 'next/image' type Props = Extract[0], { blockType: 'hero' }> const customEase = [0.22, 1, 0.36, 1] as const const containerVariants = { hidden: {}, visible: { transition: { staggerChildren: 0.14, }, }, } const itemVariants = { hidden: { opacity: 0, y: 22 }, visible: { opacity: 1, y: 0, transition: { duration: 0.5, ease: customEase, }, }, } const collageVariants = { hidden: { opacity: 0, scale: 0.96, y: 24 }, visible: { opacity: 1, scale: 1, y: 0, transition: { duration: 0.6, ease: customEase, delay: 0.25, }, }, } function useParallax3D(maxAngle = 4.5) { const [rotation, setRotation] = useState({ rotateX: 0, rotateY: 0 }) const [isHovered, setIsHovered] = useState(false) const handlePointerMove = (e: React.PointerEvent) => { const rect = e.currentTarget.getBoundingClientRect() const x = e.clientX - rect.left const y = e.clientY - rect.top const centerX = rect.width / 2 const centerY = rect.height / 2 const rotateX = -((y - centerY) / centerY) * maxAngle const rotateY = ((x - centerX) / centerX) * maxAngle setRotation({ rotateX, rotateY }) } const handlePointerLeave = () => { setIsHovered(false) setRotation({ rotateX: 0, rotateY: 0 }) } const handlePointerEnter = () => { setIsHovered(true) } return { bind: { onPointerMove: handlePointerMove, onPointerEnter: handlePointerEnter, onPointerLeave: handlePointerLeave, }, style: { transform: `perspective(1000px) rotateX(${rotation.rotateX.toFixed(2)}deg) rotateY(${rotation.rotateY.toFixed(2)}deg)`, transition: isHovered ? 'transform 0.12s ease-out' : 'transform 0.55s ease-out', }, } } export const HeroBlock: React.FC = ({ title, titleAccent, subtitle, primaryCta, secondaryCta, image, imageSecondary, floatingStat, }) => { const heroMedia = typeof image === 'object' && image !== null ? (image as Media) : null const imageUrl = heroMedia?.url || 'https://images.unsplash.com/photo-1554224155-8d04cb21cd6c?auto=format&fit=crop&w=1200&q=80' const imageAlt = heroMedia?.alt || 'Doradztwo podatkowe - biuro' const secondaryMedia = typeof imageSecondary === 'object' && imageSecondary !== null ? (imageSecondary as Media) : null const secondaryUrl = secondaryMedia?.url const secondaryAlt = secondaryMedia?.alt || 'Profesjonalne rozliczenia podatkowe' const { bind: parallaxBind, style: parallaxStyle } = useParallax3D(4.5) const statValue = floatingStat?.value || '20+' const statLabel = floatingStat?.label || 'Lat doświadczenia' return (
{/* Kolumna tekstowa z animacjami wejścia */}
{title} {titleAccent && {titleAccent}} {subtitle} {primaryCta} {secondaryCta?.text && secondaryCta?.url && ( secondaryCta.url.startsWith('#') ? ( {secondaryCta.text} ) : ( {secondaryCta.text} ) )}
{/* Prawa kolumna: Kolaż zdjęć z 3D paralaksą i pływającą kartą */}
{/* Pływająca karta (floating card) */} {statValue} {statLabel} {secondaryUrl ? ( /* Układ kolażu dwóch nachodzących na siebie zdjęć */
{/* Zdjęcie 1 (mniejsze, przesunięte w lewo-górę) */}
{imageAlt}
{/* Zdjęcie 2 (większe, przesunięte w prawo-dół, nachodzące na pierwsze o ok. 18%) */}
{secondaryAlt}
) : ( /* Pojedyncze zdjęcie jeśli imageSecondary jest puste */
{imageAlt}
)}
) }