import styled, { css } from 'styled-components/macro'

import { isMobileDevice } from 'config/userAgent'

import { ProfileLogo } from 'features/ProfileLogo'
import { NameStyled } from 'features/Name'

import { Tabs as TabsBase } from '../PlayersPlaylists/styled'

import {
  BlockTitle as BlockTitleBase,
  Button as ButtonBase,
} from '../../styled'

export const Wrapper = styled.div`
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
`

export const HalfList = styled.ul`
  width: 100%;
`

export const HalfEvents = styled.li``

export const List = styled.ul``

export const Event = styled.li`
  width: 100%;
  height: 48px;
  margin-bottom: 12px;

  :first-child {
    margin-top: 12px;
  }
`

export const TextEvent = styled.li`
  width: 100%;

  :not(:last-child) {
    margin-bottom: 12px;
  }

  :last-child {
    margin-bottom: 0px;
  }
`

type AvatarProps = {
  isHomeTeam: boolean,
  isPlayer: boolean,
}

export const Avatar = styled(ProfileLogo) <AvatarProps>`
  position: absolute;
  width: 35px;
  height: 43px;
  object-fit: cover;

  ${({ isHomeTeam }) => (
    isHomeTeam
      ? css`left: 5px;`
      : css`right: 5px;`
  )}

  ${({ isPlayer }) => (
    isPlayer
      ? css`bottom: 0;`
      : css`
        top: 50%;
        transform: translateY(-50%);
      `
  )}

  ${({ isHomeTeam }) => (
    isMobileDevice
      ? css`
          @media (max-width: 750px) and (orientation: portrait){
            ${isHomeTeam ? 'left: 20px;' : 'right: 20px;'}
          }
        `
      : ''
  )}
`

export const EventInfo = styled.div`
  display: flex;
  width: 100%;
  position: relative;
`

export const EventDesc = styled.div`
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
`

export const Title = styled.span`
  font-weight: 600;
  font-size: 14px;
  line-height: 15px;
  color: #ffffff;
  width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
`

export const SubTitle = styled(Title)`
  font-size: 10px;
  line-height: 16px;
  font-weight: normal;
  color: rgba(255, 255, 255, 0.7);
  margin-top: 2px;

  ${NameStyled} {
    font-weight: 700;
  }
`

export const EventLike = styled.img`
  position: absolute;
  left: -14px;
  top: 2px;
  width: 10px;
  height: 10px;
`

export const EventTime = styled(Title)`
  font-size: 14px;
  font-weight: normal;
  margin-right: 10px;
  width: auto;
  overflow: initial;
  min-width: 29px;
`

export const Tabs = styled(TabsBase)`
  margin-top: 0px;
  font-style: normal;
  font-weight: 400;
  font-size: 12px;
  letter-spacing: -0.32px;
  color: #ffff;
  flex: 1 1 auto;

  ${isMobileDevice ? 'padding-left: 33px;' : 'padding-left: 20px;'}
`

type TTab = {
  active?: boolean,
}

export const Tab = styled.span<TTab>`
  text-transform: none;
  border: none;
  cursor: pointer;
  width: 13px;
  height: 13px;
  display: inline-block;
  
  :nth-child(2) {
    margin-left: 3px;
  }

  ${({ active }) => (active
    ? css`
    background: url(/images/boldArrowWhite.svg) no-repeat;
    background-size: 13px 13px;

    :nth-child(3) {
     transform: rotate(180deg);
    }
    `
    : css`
    background: url(/images/boldArrowGray.svg) no-repeat;
    background-size: 13px 13px;

    :nth-child(2) {
      transform: rotate(180deg);
     }
    `
  )}
  
`

export const LikeToggle = styled.img`
  width: 12px;
  height: 12px;
  cursor: pointer;
`

export const BlockTitle = styled(BlockTitleBase)`
  text-align: center;
  width: 100%;
  display: inline-block;
`

type ButtonProps = {
  active: boolean,
  isHomeTeam: boolean,
  like?: boolean,
}

export const Button = styled(ButtonBase) <ButtonProps>`
  ${({ active, like }) => (
    like && !active ? css`
      background: url(/images/event-like-bg.png);
      background-size: cover;
    ` : ''
  )}

  ${({ isHomeTeam }) => (
    isHomeTeam
      ? css`padding-left: 60px;`
      : css`padding: 0 40px 0 60px;`
  )}

  ${({ isHomeTeam }) => (
    isMobileDevice
      ? css`
        @media (max-width: 750px) and (orientation: portrait){
          ${isHomeTeam ? 'padding-left: 90px;' : 'padding: 0 60px 0 90px;'}
        }
      `
      : ''
  )}
`

export const ButtonsBlock = styled.div`
  position: relative;
  display: flex;
  width: 100%;
  height: 20px;
  margin-bottom: 7px;
`

export const HoverTooltip = styled.span`
  display: flex;
  background: #fff;
  border-radius: 6px;
  left: 8px;
  top: 30px;
  transform: translate(-100%, -50%);
  font-size: 15px;
  text-align: center;
  flex-direction: column;
  position: absolute;
  justify-content: center;
  align-items: center;
  min-width: 160px;
  width: max-content;
  line-height: 21px;
  padding: 0 9px;
  text-decoration: none;
  color: #000;
  opacity: 0;
  transition: all 0.1s ease;
  pointer-events: none;
  z-index: 1000;
`

type TFilters = {
  active?: boolean,
}

export const Filters = styled.span<TFilters>`
  cursor: pointer;
  width: 12px;
  height: 12px;
  position: relative;
  margin-left: 15px;

  ${({ active }) => (active
    ? css`
    background: url('/images/filter-white.svg') no-repeat;
  `
    : css`
    background: url('/images/filter-gray.svg')no-repeat;
  `)}

  :hover ${HoverTooltip} {
    opacity: 1;
    z-index: 1;
  }
`

export const SelectedEpisodes = styled.div`
  display: flex;
  align-items: center;
  gap: 18px;
`

export const EpisodesCount = styled.div`
  font-weight: 600;
  font-size: 12px;
  line-height: 20px;
  text-align: right;
  letter-spacing: -0.32px;
  color: rgba(255, 255, 255, 0.5);
`

export const WatchButton = styled.span`
  font-weight: 600;
  font-size: 12px;
  height: 16px;
  padding-left: 12px;
  letter-spacing: -0.32px;
  color: #ffff;
  cursor: pointer;
  background: url('/images/player-play.svg') left 2px no-repeat;
  background-size: 9px 11px;

  :hover {
    box-shadow: 0 1px #ffff;
  }
`
