import type { ReactElement } from 'react'

import styled from 'styled-components/macro'

import { VolumeBar } from 'features/StreamPlayer/components/VolumeBar'
import {
  Controls,
  Fullscreen,
  PlayStop,
} from 'features/StreamPlayer/styled'

import { ProgressBar } from '.'

const Story = {
  component: ProgressBar,
  title: 'ProgressBar',
}

export default Story

const Wrapper = styled.div`
  position: relative;
  width: 95vw;
  height: 50vh;
  left: 50%;
  transform: translateX(-50%);
  background-color: #000;
`

const callback = () => {}

const renderInControls = (progressBarElement: ReactElement) => (
  <Wrapper>
    <Controls visible>
      <PlayStop onClick={callback} playing={false} />
      <VolumeBar
        value={50}
        muted={false}
        onChange={callback}
        onClick={callback}
      />
      {progressBarElement}
      <Fullscreen onClick={callback} isFullscreen={false} />
    </Controls>
  </Wrapper>
)

const duration = 70000

export const Empty = () => renderInControls(
  <ProgressBar
    duration={duration}
    onPlayedProgressChange={callback}
    playedProgress={0}
    loadedProgress={0}
  />,
)

export const HalfLoaded = () => renderInControls(
  <ProgressBar
    duration={duration}
    onPlayedProgressChange={callback}
    playedProgress={0}
    loadedProgress={30000}
  />,
)

export const HalfPlayed = () => renderInControls(
  <ProgressBar
    duration={duration}
    onPlayedProgressChange={callback}
    playedProgress={30000}
    loadedProgress={0}
  />,
)

export const Loaded40AndPlayed20 = () => renderInControls(
  <ProgressBar
    duration={duration}
    onPlayedProgressChange={callback}
    playedProgress={20000}
    loadedProgress={40000}
  />,
)
