import { Link } from 'react-router-dom'

import styled from 'styled-components/macro'

import { devices } from 'config/devices'
import { customScrollbar, solidButtonStyles } from 'features/Common'
import {
  InputWrapper,
  InputStyled,
  Label,
  Column,
} from 'features/Common/Input/styled'

export const Wrapper = styled.div`
  position: relative;
`

export const LoaderWrapper = styled.div`
  position: absolute;
  top: 0;
  background-color: rgba(129, 129, 129, 0.5);
  width: 100%;
  height: 48px;
  box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.3);
  border-radius: 2px;
  display: flex;
  align-items: center;
  justify-content: center;

  @media ${devices.mobile} {
    top: 20px;
  }

  @media ${devices.tablet} {
    top: 26px;
    height: 28px;
  }
`

export const Form = styled.form<{isMatch: boolean}>`
  width: 288px;
  position: relative;
  ${InputWrapper} {
    margin: 0;
    padding-bottom: 13px;

    @media ${devices.desktop} {
      padding-left: 12px;
    }

    @media ${devices.tablet} {
      padding-left: 6px;
      height: 12px;
      margin-top: 25px;
      background-color: transparent;
    }

    @media ${devices.mobile} {
      margin-top: 20px;
    }
  }

  @media ${devices.desktop} {
    width: ${({ isMatch }) => (isMatch ? '244px' : '51px')};

    :focus-within {
      width: 348px;
      position: ${({ isMatch }) => (isMatch ? 'static' : 'absolute')};
      z-index: 4;
    }
  }

  @media ${devices.tablet} {
    width: 30px;
    :focus-within {
      width: 252px;
      top: -38px;
      left: -250px;
    }
  }

  @media ${devices.mobile} {
    :focus-within {
      top: -33px;
    }
  }

  ${InputStyled} {
    width: 100%;

    ::-webkit-search-decoration,
    ::-webkit-search-cancel-button,
    ::-webkit-search-results-button,
    ::-webkit-search-results-decoration {
      display: none;
    }

    @media ${devices.tablet} {
      font-size: 14px;
    }
  }

  ${Label} {

    @media ${devices.laptop} {
      display: block;
    }
    ::before {
      content: '';
      display: block;
      position: absolute;
      width: 25px;
      height: 25px;
      background-image: url(/images/search.svg);
      background-repeat: no-repeat;

      @media ${devices.desktop} {
        margin-right: 0;
      }
      @media ${devices.tablet} {
        margin-right: 0;
        background-image: url(/images/search-mob.svg);
      }
    }
  }

  :focus-within {
    ${InputWrapper} {
      padding-left: 0;

      @media ${devices.tablet} {
        background-color: #3F3F3F;
      }
    }

    ${Label} {
      ::before {
        display: none;
      }
    }
  }

  @media ${devices.mobile} {
    ${Column} {
      width: auto;
      max-width: 335px;
    }
  }
`

export const Results = styled.div`
  overflow-y: auto;
  max-height: 431px;

  ${customScrollbar}
`

export const ResultsWrapper = styled.div`
  position: absolute;
  top: 56px;
  width: 448px;
  z-index: 1;

  @media ${devices.tablet} {
    position: fixed;
    top: 40px;
    left: 40%;
    width: 50vw;
  }
  @media ${devices.mobile} {
    left: 0;
    width: 100vw;
  }
`

export const LinkWrapper = styled.div`
  background-color: #666;
  width: 440px;
  padding: 10px 0;
`

export const StyledLink = styled(Link)`
  ${solidButtonStyles}

  width: 217px;
  height: 30px;
  font-weight: 600;
  font-size: 11px;
  margin: 0 auto;
  padding: 0;
  display: flex;
  justify-content: center;
  align-items: center;
`
