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

import { Checkbox as BaseCheckbox } from 'features/Common/Checkbox'
import { Label } from 'features/Common/Checkbox/styled'
import { CheckboxSvg } from 'features/Common/Checkbox/Icon'
import { customScrollbar } from 'features/Common'
import { NameStyled } from 'features/Name'
import { isMobileDevice } from 'config/userAgent'
import { BaseButton } from 'features/PopupComponents'

type CheckboxProps = {
  checked: boolean,
  isMainCheckbox?: boolean,
}

type PlayerNumberProps = {
  checked: boolean,
}

export const PopupContainer = styled.div`
  background: #333333;
  box-shadow: 0px 2px 40px rgba(0, 0, 0, 0.6);
  border-radius: 2px;
  display: flex;
  flex-direction: column;
  position: absolute;
  z-index: 1000;
  height: 100%;
  right: 0;
  top: 0;

  ${isMobileDevice
    ? css`
      position: fixed;
      height: calc(100vh - 40px);
      width: 100%;
      padding-bottom: 70px;
      top: 40px;`
    : css`
      width: 651px;`}
`

export const PopupInner = styled.div`
  max-height: 100%;
  height: 100%;
  overflow-y: auto;
  padding-bottom: ${(isMobileDevice ? '20%' : '')};
  
  ${customScrollbar}
`

export const PopupHeader = styled.div`
  flex: 0 0 auto;
  ${isMobileDevice
    ? css`
      height: auto;
      padding: 12px 0px 0px 0px;
      margin-bottom: 14px;`
    : css`
      height: 50px;
      padding: 17px 22px 0px 22px;`}
`

export const CloseButtonContainer = styled.div`
  position: absolute;
  top: 14px;
  right: 12px;
  
  ${BaseButton} {
    top: -4px;
    right:0 ;
  }
`

export const HeaderText = styled.div`
  font-family: 'Montserrat';
  font-style: normal;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;

  ${isMobileDevice
    ? css`
    font-size: 12px;
    line-height: 15px;
    text-align: center;`
    : css`
    font-size: 18px;
    line-height: 22px;
    margin-bottom: 21px;`}
`

export const PartBlock = styled.div`
  flex: 1 0 auto;
  padding: 17px 22px 17px 22px;

  ${isMobileDevice
    ? css`
      border-bottom: 1px solid #505050;`
    : css`  
      :not(:last-child) {
        border-bottom: 1px solid #505050;
      }
    `};
`

export const ItemsContainer = styled.ul`
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
`

export const MainCheckboxContainer = styled.div`
  margin-bottom: ${(isMobileDevice ? '10px' : '15px')};
  display: flex;
`

export const ItemBlock = styled.div`
  flex: 0 0 33.33%;
  margin-bottom: 4px;

  ${isMobileDevice
    ? css`
    flex: 0 0 50%;`
    : css`
    flex: 0 0 33.33%;`}
`

export const Checkbox = styled(BaseCheckbox)<CheckboxProps>`
  height: 28px;
  display: block;

  ${Label} {
    height: 100%;
    font-style: normal;
    
    ${isMobileDevice
    ? css`
      font-size: 12px;
      line-height: 18px;`
    : css`
      font-size: 14px;
      line-height: 16px;`}
    
    ${({ checked, isMainCheckbox }) => (isMainCheckbox
    ? css`
      font-weight: 500;`
    : css`
      color: ${checked ? 'rgba(255, 255, 255, 0.6)' : 'rgba(255, 255, 255, 0.3)'};
      font-weight: 400;`
  )}
  }

  ${CheckboxSvg} {
    ${({ checked, isMainCheckbox }) => (isMainCheckbox
    ? css`
      width: ${(isMobileDevice ? '23px' : '20px')};
      height: ${(isMobileDevice ? '23px' : '20px')};`
    : css`
      fill:  ${checked ? 'rgba(255, 255, 255, 0.6)' : 'rgba(255, 255, 255, 0.3)'};
      width: ${(isMobileDevice ? '18px' : '14px')};
      height: ${(isMobileDevice ? '18px' : '14px')};
      margin-left: ${(isMobileDevice ? '2px' : '3px')};`
  )}
    margin-right: 8px;
  }
`

export const ItemText = styled.div`
  display: flex;
  height: 100%;
  align-items: center;

  ${NameStyled} {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 130px;
  }
  
  ${isMobileDevice
    ? css`
    width: 110px;`
    : css`
    width: 130px;`}
`

export const ButtonConatiner = styled.div`
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 66px;

  ${isMobileDevice
    ? css`
    position: fixed;
    bottom: 14px;
    left: 50%;
    transform: translate(-50%, 0);`
    : css`
    border-top: 1px solid #505050;`}
`

export const Button = styled.button`
  height: 41px;
  background: #294FC4;
  box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.3);
  border-radius: 5px;
  border: none;
  cursor: pointer;
  font-size: 15px;
  line-height: 50px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffff;
 
  ${isMobileDevice
    ? css`
    width: 190px;`
    : css`
    width: 167px;`}
`
export const PlayerNumber = styled.span<PlayerNumberProps>`
  color: ${({ checked }) => (checked ? '#fff' : 'rgba(255, 255, 255,  0.3)')};
  margin-right: 5px;
  min-width: 14px;
  font-size: 11px;
  line-height: 16px;
  font-weight: 600;
`
