{"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\nvar VideoLoop = function VideoLoop(_ref) {\n  var className = _ref.className,\n      videos = _ref.videos;\n\n  var _useState = useState(0),\n      index = _useState[0],\n      setIndex = _useState[1];\n\n  var preloadingRef = useRef();\n  var 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  var onEnded = function onEnded() {\n    preloadingRef && preloadingRef.current && preloadingRef.current.play();\n    playingRef && playingRef.current && playingRef.current.pause();\n    setIndex(function (i) {\n      return i + 1 == videos.length ? 0 : i + 1;\n    });\n  };\n\n  var previousVideo = videos.length > 1 && videos[index - 1 >= 0 ? index - 1 : videos.length - 1];\n  var currentVideo = videos[index];\n  var 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"}