import React from 'react'
import Lightbox from 'yet-another-react-lightbox'
import {
  Download,
  Fullscreen,
  Counter,
  Zoom,
} from 'yet-another-react-lightbox/plugins'
import 'yet-another-react-lightbox/styles.css'
import 'yet-another-react-lightbox/plugins/counter.css'

interface LigtboxProps {
  isOpen: boolean
  index: number
  setIsOpen: (isOpen: boolean) => void
  slides: Array<{ src: string }>
  setIndex: (index: number) => void
}

const Index: React.FC<LigtboxProps> = (props) => {
  return (
    <Lightbox
      open={props.isOpen}
      index={props.index}
      close={() => props.setIsOpen(false)}
      plugins={[Download, Fullscreen, Counter, Zoom]}
      counter={{ container: { style: { top: 0, bottom: 'unset' } } }}
      styles={{ container: { backgroundColor: 'rgba(0, 0, 0, .9)' } }}
      slides={props.slides}
      on={{
        view: ({ index: currentIndex }) => {
          props.setIndex(currentIndex)
        },
      }}
      controller={{
        closeOnBackdropClick: true,
        closeOnPullDown: true,
        closeOnPullUp: true,
      }}
    />
  )
}

export default Index
