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

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

import { devices, PAGES } from 'config'
import { isMobileDevice } from 'config/userAgent'
import { client } from 'config/clients'

import { Logo } from 'features/Logo'

const HeaderStyled = styled.header`
  display: flex;
  align-items: center;
  margin-bottom: 65px;
  width: 100%;
  height: ${client.styles.logoHeight}rem;
  justify-content: space-between;

  @media ${devices.tablet} {
    margin-bottom: 0;
  }

  ${isMobileDevice
    ? css`
      @media (max-width: 650px){
        margin-bottom: 20px;
      }
      @media (orientation: landscape){
        margin-bottom: 20px;
      }
    `
    : ''};
`

const HomeIcon = styled.div`
  display: block;
  width: 30px;
  height: 30px;
  background-size: contain;
  background-repeat: no-repeat;
  background-image: url(/images/home.png);
`

export const HeaderLogo = styled(Logo)`
  position: absolute;
  top: ${client.styles.logoTop}rem;
  left: ${client.styles.logoLeft}rem;

  ${isMobileDevice
    ? css`
      left: 50%;
      transform: translateX(-50%);
    `
    : ''}
`

export const Header = () => (
  <HeaderStyled>
    <Link to={PAGES.home}>
      <HeaderLogo />
    </Link>
    <Link to={PAGES.home}>
      <HomeIcon />
    </Link>
  </HeaderStyled>
)
