'use client';
import PropTypes from 'prop-types';
import { useEffect, useRef, useState } from 'react';
// @mui
import { useTheme } from '@mui/material/styles';
import Button from '@mui/material/Button';
import Chip from '@mui/material/Chip';
import Stack from '@mui/material/Stack';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
// @third-party
import { motion, useScroll, useTransform } from 'motion/react';
// @project
import ButtonAnimationWrapper from '@/components/ButtonAnimationWrapper';
import { GraphicsCard } from '@/components/cards';
import ContainerWrapper from '@/components/ContainerWrapper';
import GraphicsImage from '@/components/GraphicsImage';
import SvgIcon from '@/components/SvgIcon';
import { SECTION_COMMON_PY } from '@/utils/constant';
import { getBackgroundDots } from '@/utils/getBackgroundDots';
import { withAlpha } from '@/utils/colorUtils';
// @assets
import Wave from '@/images/graphics/Wave';
// threshold - adjust threshold as needed
const options = { root: null, rootMargin: '0px', threshold: 0.6 };
/*************************** HERO - 17 ***************************/
/**
*
* Demos:
* - [Hero17](https://www.saasable.io/blocks/hero/hero17)
*
* API:
* - [Hero17 API](https://phoenixcoded.gitbook.io/saasable/ui-kit/development/components/hero/hero17#props-details)
*/
export default function Hero17({ chip, headLine, captionLine, primaryBtn, videoSrc, videoThumbnail, listData }) {
const theme = useTheme();
const boxRadius = { xs: 24, sm: 32, md: 40 };
const containerRef = useRef(null);
const { scrollYProgress } = useScroll({
target: containerRef,
offset: ['start start', 'end start']
});
const scale = useTransform(scrollYProgress, [0, 0.1, 0.2, 0.4, 0.6], [0.9, 0.92, 0.94, 0.96, 1]);
const videoRef = useRef(null);
const [isPlaying, setIsPlaying] = useState(false);
// Handle video play/pause based on intersection with the viewport
useEffect(() => {
const handleIntersection = (entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
if (videoRef.current && !isPlaying) {
videoRef.current
.play()
.then(() => {
setIsPlaying(true);
})
.catch((error) => {
console.error('Autoplay was prevented:', error);
});
}
} else {
if (videoRef.current && isPlaying) {
videoRef.current.pause();
setIsPlaying(false);
}
}
});
};
const observer = new IntersectionObserver(handleIntersection, options);
const videoElement = videoRef.current;
if (videoElement) {
observer.observe(videoElement);
}
return () => {
if (videoElement) {
observer.unobserve(videoElement);
}
};
}, [isPlaying]);
return (
<>
{headLine}
{captionLine}
}
{...primaryBtn}
/>
{listData.map((item, index) => (
}
slotProps={{ label: { sx: { py: 0.75, px: 1, typography: 'caption2' } } }}
sx={{ height: 32, px: 1, bgcolor: 'grey.100' }}
/>
))}
>
);
}
Hero17.propTypes = {
chip: PropTypes.object,
headLine: PropTypes.string,
captionLine: PropTypes.string,
primaryBtn: PropTypes.any,
videoSrc: PropTypes.string,
videoThumbnail: PropTypes.string,
listData: PropTypes.array
};