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

import { devices } from 'config/devices'
import { isMobileDevice } from 'config/userAgent'

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

type CardProps = {
  isMatchPage?: boolean,
}

export const CardWrapperOuter = styled.li.attrs({
  tabIndex: 0,
}) <CardProps>`
  padding-top: ${({ isMatchPage }) => (isMatchPage ? 0 : '100%')};
  position: relative;

  ${isMobileDevice
    ? css`
      width: 100%;
      padding-top: 0;
      height: 90px;
      margin-bottom: 10px;

      @media screen and (orientation: landscape){
        width: 49%;
        :nth-child(odd){
        margin-right: 10px;
      }
      }
    `
    : ''};
`

export const CardWrapper = styled.div<CardProps>`
  position: ${({ isMatchPage }) => (isMatchPage ? 'relative' : 'absolute')};
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
  padding: ${({ isMatchPage }) => (isMatchPage ? '0.5rem 0.625rem 1.8rem' : '0 0 0.75rem')};
  border-radius: 3px;
  background-color: #3F3F3F;
  box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.4);
  cursor: pointer;

  ${isMobileDevice
    ? css`
      width: 100%;
      height: 90px;
      padding-bottom: 0;
    `
    : ''};
`

export const HoverFrame = styled.div`
  position: absolute;
  top: 0;
  left: 0;
  min-width: 100%;
  min-height: 100%;
  border-radius: 2px;
  border: 2px solid transparent;
  transition: border 0.5s ease-out;
  z-index: 2;

  &:hover {
    border: 2px solid #fff
  }
`

type TPreviewWrapper = {
  color?: string,
  isGradientPreview?: boolean,
  isMatchPage?: boolean,
}

export const PreviewWrapper = styled.div<TPreviewWrapper>`
  position: relative;
  display: flex;
  width: 100%;
  height: 60%;
  ${({ color, isGradientPreview }) => isGradientPreview
    && css`
    background: ${color};`}
  
  ${({ isMatchPage }) => (
    isMatchPage
      ? css`
        position: absolute;
        inset: 0;
        height: 100%;
      `
      : ''
  )}

  ${isMobileDevice
    ? css`
      width: 50%;
      height: 100%;
    `
    : ''};
`

export const Preview = styled.img<CardProps>`
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.2;
`

export const MatchTimeInfo = styled.div<CardProps>`
  width: 100%;
  position: absolute;
  top: 0.519rem;
  padding: 0 0.519rem;
  display: flex;
  flex-direction: row;

  ${({ isMatchPage }) => (
    isMatchPage
      ? css`
        top: auto;
        bottom: 0.519rem;
        flex-direction: row-reverse;
        justify-content: flex-end;
      `
      : ''
  )}
`

type MatchDateProps = {
  isHomePage?: boolean,
  isMatchPage?: boolean,
}

export const MatchDate = styled.div<MatchDateProps>`
  width: fit-content;
  height: 0.9rem;
  border-radius: 2px;
  padding: ${({ isHomePage }) => (!isHomePage ? '0 0.27rem' : '')};
  font-weight: bold;
  font-size: 0.472rem;
  line-height: 0.567rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  display: flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  color: white;
  background-color: #6D6D6D;

  @media ${devices.tablet} {
    padding: ${({ isHomePage }) => (!isHomePage ? '0.27rem 0.36rem' : '')};
  }
  ${isMobileDevice
    ? css`
      height: 15px;
      font-size: 8px;
    `
    : ''};
`

export const LiveSign = styled(MatchDate)`
  background-color: #CC0000;
  margin-left: auto;

  ${({ isMatchPage }) => (
    isMatchPage
      ? css`
        margin-right: 10px;
        margin-left: 0;
      `
      : ''
  )}
`

export const Time = styled.span`
  margin: 0 0.2rem;
`

export const Info = styled.div<CardProps>`
  position: relative;
  display: flex;
  flex-direction: column;
  padding: ${({ isMatchPage }) => (isMatchPage ? '0 5px 5px 0' : '0.85rem 0.472rem 0 0.519rem')};
  color: #fff;
  z-index: 1;

  ${isMobileDevice
    ? css`
      position: absolute;
      top: 0;
      left: 50%;
      width: 50%;
      height: 100%;
      padding: 13px 12px 13px 10px;
    `
    : ''};
`

type FavoriteSignProps = {
  marginLeft?: number,
}

export const FavoriteSign = styled.span<FavoriteSignProps>`
  display: inline-block;
  width: 0.472rem;
  height: 0.472rem;
  margin-top: 0.08rem;
  margin-left: ${({ marginLeft = 9 }) => marginLeft}px;
  background: url('/images/sportFavStar.png') no-repeat center / 100% 100%;

  ${isMobileDevice
    ? css`
      width: 10px;
      height: 10px;
    `
    : ''};
`

const nameStyles = css`
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
`

export const Teams = styled.div<CardProps>`
  margin-bottom: ${({ isMatchPage }) => (isMatchPage ? '0' : '0.567rem')};

  ${isMobileDevice
    ? css`
      margin-bottom: 15px;
    `
    : ''};
`

export const Team = styled.span<CardProps>`
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.14rem;
  color: #fff;

  ${({ isMatchPage }) => (
    isMatchPage
      ? css`
        font-size: 18px;
        line-height: 28px;
      `
      : ''
  )}

  ${isMobileDevice
    ? css`
      font-size: 14px;
      line-height: 20px;
    `
    : ''};
`

export const NameSignWrapper = styled.div`
  display: flex;
  max-width: 90%;
  align-items: center;
`

export const TeamName = styled(Name)`
  ${nameStyles}
`

export const Score = styled.div``

export const TeamLogos = styled.div<CardProps>`
  display: ${({ isMatchPage }) => (isMatchPage ? 'none' : 'flex')};
  align-items: center;
  justify-content: center;
  margin: ${({ isMatchPage }) => (isMatchPage ? '0' : '0.71rem auto 0 auto')};
  z-index: 1;
`

export const TeamLogo = styled(ProfileLogo)<CardProps>`
  width: 33%;
  max-height: 100%;

  :last-child {
    margin-left: 0.8rem;
  }
  
  ${isMobileDevice
    ? css`
      width: 30%;
    `
    : ''};

  ${({ isMatchPage }) => (isMatchPage
    ? css`
        width: 18px;
        margin-right: 5px;
   `
    : '')
}
`

export const BuyMatchBadge = styled.span<CardProps>`
  position: absolute;
  left: 0.472rem;
  bottom: 0.519rem;
  width: 1.18rem;
  height: 1.18rem;
  cursor: pointer;
  background-image: url(/images/dollar-sign.svg);
  background-position: center;
  background-repeat: no-repeat;
  background-size: 0.472rem 0.71rem;
  background-color: #fff;
  border-radius: 50%;
  border: 0.5px solid rgba(0, 0, 0, 0.2);
  box-shadow: 0px 0.08rem 0.283rem rgba(0, 0, 0, 0.5);
  display: ${({ isMatchPage }) => (isMatchPage ? 'none' : 'block')};

  ${isMobileDevice
    ? css`
      width: 19px;
      height: 17px;
      background-size: 40%;
    `
    : ''};
`

export const BuyMatchBadgeCustom = styled(BuyMatchBadge)`
  background-color: rgba(255, 255, 255, 0.19);
  background-image: url(/images/dollar-sign-grey.svg);
  background-size: auto;
  min-width: 18px;
  min-height: 18px;
  position: initial;
  box-shadow: none;
  margin-left: auto;
`
