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

import {
  isIOS,
  isMobileDevice,
  devices,
} from 'config'

import { ButtonOutline, customScrollbar } from 'features/Common'
import { T9n } from 'features/T9n'

type WrapperProps = {
  highlighted?: boolean,
  isHidden?: boolean,
  isTourOpen?: boolean,
}

export const Wrapper = styled.div<WrapperProps>`
  padding-right: 14px;

  ${({ highlighted }) => (highlighted
    ? css`
        border: 1px solid #0057FF;
        border-radius: 5px;
        box-shadow: 0px 0px 66px 16px rgba(0, 87, 255, 0.8);
      `
    : '')}

  ${isMobileDevice
    ? css`
      overflow-y: auto;
      width: 100%;
      padding: 10px 10px 0;

      ::-webkit-scrollbar {
        display: none;
      }
    `
    : ''};
  
  ${({ isHidden }) => (isHidden && isMobileDevice
    ? css`
      padding-top: 50px;`
    : '')}
  
  ${({ isTourOpen }) => (isTourOpen
    ? css`
         overflow-y: initial;
         z-index: 9999;
      `
    : '')}
`

export const TabsWrapper = styled.div``

export const TabsGroup = styled.div.attrs({ role: 'tablist' })`
  display: flex;
  justify-content: center;
  gap: ${isMobileDevice ? 30 : 20}px;
  padding-top: 10px;
`

export const TabTitle = styled(T9n)`
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  color: ${({ theme }) => theme.colors.white};
`

export const TabButton = styled.button`
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  padding-left: 0;
  padding-right: 0;
  opacity: 0.4;
  cursor: pointer;
  border: none;
  background: none;
`

export const Tab = styled.div.attrs({ role: 'tab' })`
  position: relative;

  &[aria-pressed="true"], :hover {
    ${TabButton} {
      opacity: 1;

      ${TabTitle} {
        font-weight: 600;
      }
    }
  }

  :only-child {
    cursor: unset;
  }
`

type TabIconProps = {
  icon: 'watch' | 'plays' | 'players' | 'stats',
}

export const TabIcon = styled.div<TabIconProps>`
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  margin-bottom: 5px;
  background-image: url(/images/matchTabs/${({ icon }) => `${icon}.svg`});
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;

  ${({ icon }) => (icon === 'players'
    ? css`
         background-size: 25px;
      `
    : '')}
`

type TContainer = {
  forWatchTab?: boolean,
  hasScroll: boolean,
  highlighted?: boolean,
}

export const Container = styled.div<TContainer>`
  width: 320px;
  margin-top: 14px;
  max-height: calc(100vh - 130px);
  overflow-y: auto;
  padding-right: ${({ forWatchTab }) => (forWatchTab ? '0' : '')};
  padding-left: 14px;
  padding-right: ${({ hasScroll }) => (hasScroll ? '10px' : '')};

  ${customScrollbar}

  @media ${devices.tablet} {
    margin-top: 15px;
  }

  ${isMobileDevice
    ? css`
      padding: 0 5px;
      padding-bottom: ${isIOS ? 60 : 78}px;
      overflow-y: hidden;
      max-height: initial;

      @media (max-width: 750px){
        width: 100%;
      }

      @media (orientation: landscape){
        width: 100%;
      }
    `
    : ''};

  ${({ highlighted }) => (highlighted
    ? css`
         overflow-y: initial;
      `
    : '')}
`

type ButtonProps = {
  active?: boolean,
}

export const Button = styled.button<ButtonProps>`
  border: none;
  outline: none;
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  background: ${({ theme }) => theme.colors.playerActionBtnBackground};
  box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.3);
  border-radius: 2px;

  ${({ disabled }) => (
    disabled
      ? css`
          pointer-events: none;
          opacity: 0.5;
        `
      : css`
          cursor: pointer;
        `
  )}

  :hover {
    background-color: #555555;
  }

  span {
    pointer-events: none;
  }

  @media ${devices.mobile} {
    justify-content: center;
    border-radius: 1.8px;
  }

  ${({ active, theme }) => {
    const bgColor = theme.colors.button
    const bgHoverColor = theme.colors.buttonHover

    return active ? css`
      background-color: ${bgColor};

      &:hover {
        background-color: ${bgHoverColor};
      }
    ` : ''
  }}
`

export const DownloadButton = styled(ButtonOutline)`
  width: 100%;
  height: 2.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1rem;

  :hover {
    background-color:  ${({ theme }) => theme.colors.buttonHover};
  }
`

export const Title = styled.span`
  font-weight: 600;
  font-size: 14px;
  max-width: 55%;
  line-height: 16px;
  color: #ffffff;
  overflow: hidden;
  white-space: nowrap;
  text-overflow:ellipsis;
`

export const BlockTitle = styled.span`
  font-weight: 600;
  font-size: 12px;
  line-height: 18px;
  text-align: start;
  color: rgba(255, 255, 255, 0.5);
  text-transform: uppercase;
`

export const EventsAdsWrapper = styled.div<TContainer>`
  width: ${({ hasScroll }) => (hasScroll ? '288px' : '306px')};
  margin-bottom: 0.6rem;

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