'use client'
import { useRef, useState } from 'react'
import { cn, getAssetUrl } from '@/lib/utils'
import { Lightbox } from './lightbox'
interface ActionImageProps {
src: string
alt: string
enableLightbox?: boolean
}
interface ActionVideoProps {
src: string
alt: string
enableLightbox?: boolean
}
export function ActionImage({ src, alt, enableLightbox = true }: ActionImageProps) {
const [isLightboxOpen, setIsLightboxOpen] = useState(false)
const openLightbox = () => setIsLightboxOpen(true)
const image = (
)
return (
<>
{enableLightbox ? (
) : (
image
)}
{enableLightbox && (
setIsLightboxOpen(false)}
src={src}
alt={alt}
type='image'
/>
)}
>
)
}
export function ActionVideo({ src, alt, enableLightbox = true }: ActionVideoProps) {
const videoRef = useRef(null)
const startTimeRef = useRef(0)
const [isLightboxOpen, setIsLightboxOpen] = useState(false)
const resolvedSrc = getAssetUrl(src)
const openLightbox = () => {
startTimeRef.current = videoRef.current?.currentTime ?? 0
setIsLightboxOpen(true)
}
const video = (
)
return (
<>
{enableLightbox ? (
) : (
video
)}
{enableLightbox && (
setIsLightboxOpen(false)}
src={src}
alt={alt}
type='video'
startTime={startTimeRef.current}
/>
)}
>
)
}