{"ast":null,"code":"import { jsxs as _jsxs } from \"react/jsx-runtime\";\nimport { jsx as _jsx } from \"react/jsx-runtime\";\nimport cn from 'classnames';\nimport { useRef, useState } from 'react';\nimport styles from './VideoLoop.module.scss';\n\nconst VideoLoop = ({\n  className,\n  videos\n}) => {\n  const {\n    0: index,\n    1: setIndex\n  } = useState(0);\n  const preloadingRef = useRef();\n  const playingRef = useRef(); // console.log('VideoLoop.js::12 videos', videos)\n\n  if (videos.length == 0) return null;\n\n  if (videos.length == 1) {\n    return /*#__PURE__*/_jsx(\"div\", {\n      className: cn(styles.container, className),\n      children: /*#__PURE__*/_jsx(\"video\", {\n        className: cn(styles.video),\n        autoPlay: true,\n        muted: true,\n        loop: true,\n        ref: playingRef,\n        children: /*#__PURE__*/_jsx(\"source\", {\n          src: videos[0],\n          type: \"video/mp4\"\n        })\n      })\n    });\n  }\n\n  const onEnded = () => {\n    preloadingRef && preloadingRef.current && preloadingRef.current.play();\n    playingRef && playingRef.current && playingRef.current.pause();\n    setIndex(i => i + 1 == videos.length ? 0 : i + 1);\n  };\n\n  const previousVideo = videos.length > 1 && videos[index - 1 >= 0 ? index - 1 : videos.length - 1];\n  const currentVideo = videos[index];\n  const nextVideo = videos.length > 1 && videos[index + 1 == videos.length ? 0 : index + 1];\n  return /*#__PURE__*/_jsxs(\"div\", {\n    className: cn(styles.container, className),\n    children: [nextVideo && /*#__PURE__*/_jsx(\"video\", {\n      className: cn(styles.nextVideo),\n      ref: preloadingRef,\n      muted: true,\n      children: /*#__PURE__*/_jsx(\"source\", {\n        src: nextVideo,\n        type: \"video/mp4\"\n      })\n    }, nextVideo + '-preload'), previousVideo && /*#__PURE__*/_jsx(\"video\", {\n      className: cn(styles.previousVideo),\n      muted: true,\n      children: /*#__PURE__*/_jsx(\"source\", {\n        src: nextVideo,\n        type: \"video/mp4\"\n      })\n    }, previousVideo), /*#__PURE__*/_jsx(\"video\", {\n      className: cn(styles.video),\n      autoPlay: true,\n      muted: true,\n      onEnded: nextVideo && onEnded,\n      loop: nextVideo ? false : true,\n      ref: playingRef,\n      children: /*#__PURE__*/_jsx(\"source\", {\n        src: currentVideo,\n        type: \"video/mp4\"\n      })\n    }, currentVideo)]\n  });\n};\n\nexport default VideoLoop;","map":null,"metadata":{},"sourceType":"module"}