import map from 'lodash/map'

import {
  LoadedProgress,
  PlayedProgress,
} from 'features/StreamPlayer/components/ProgressBar/styled'

import type { Chapter } from '../../types'
import {
  ChapterList,
  ChapterContainer,
} from './styled'

type ChapterWithStyles = Chapter & {
  loaded: number,
  played: number,
  width: number,
}

type Props = {
  chapters: Array<ChapterWithStyles>,
}

export const Chapters = ({ chapters }: Props) => (
  <ChapterList>
    {
      map(
        chapters,
        ({
          loaded,
          played,
          width,
        }, index) => (
          <ChapterContainer key={index} style={{ width: `${width}%` }}>
            <LoadedProgress style={{ width: `${loaded}%` }} />
            <PlayedProgress style={{ width: `${played}%` }} />
          </ChapterContainer>
        ),
      )
    }
  </ChapterList>
)
