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

import isUndefined from 'lodash/isUndefined'

import { client } from 'config/clients'
import { isMobileDevice } from 'config/userAgent'

import { Logo } from 'features/Logo'

export const DEFAULT_HEADER_COLOR = 'rgba(53, 96, 225, 0.56)'

export const defaultHeaderStyles = (color: string = DEFAULT_HEADER_COLOR) => {
  if (color.includes('linear-gradient')) {
    return css`
      background: ${color};
      z-index: 10;
`
  }
  return client.name === 'facr' ? client.styles.homePageHeader : css`
  background: linear-gradient(
    187deg,
    ${color} -4.49%,
    #000000 68.29%),
    #000000;
  z-index: 10;
`
}

type HeaderProps = {
  color?: string,
  headerImage?: string | null,
  height?: number,
}

export const HeaderStyled = styled.header<HeaderProps>`
  position: relative;
  display: flex;
  justify-content: center;
  height: ${({ height = 8.5 }) => height}rem;

  @media (max-width: 450px){
    height: 124px;
  }

  ${({ color }) => defaultHeaderStyles(color)}

  ${isMobileDevice
    ? css`
      height: auto;
      padding: 8px;
    `
    : ''}
`

type Props = {
  height?: number,
  marginTop?: number,
}

export const HeaderGroup = styled.div<Props>`
  display: flex;

  ${({ height }) => (height ? `height: ${height}rem` : '')};
  ${({ marginTop }) => (marginTop ? `margin-top: ${marginTop}rem` : '')};

  ${isMobileDevice
    ? css`
      position: relative;
      justify-content: flex-end;
    `
    : ''};
`

export const HeaderLogo = styled(Logo)`
  ${({ isMatchPage }) => (isMatchPage ? css`
    width: ${client.styles.matchLogoWidth}rem;
    height: ${client.styles.matchLogoHeight}rem;
  ` : '')}

  ${isMobileDevice
    ? css`
        width: 85px;
        height: 20px;

        @media (max-width: 450px){
        left: 48vw;
        top: 5px;
        transform: translateX(-50%);
        position: absolute;
      }
    `
    : ''}
`

type PositionProps = {
  isMatchPage?: boolean,
  left?: number,
  right?: number,
  top?: number,
}

export const Position = styled.div<PositionProps>`
  position: absolute;

  top: ${({ isMatchPage, top = 1.14 }) => (
    isMatchPage
      ? client.styles.matchLogoTopMargin ?? top
      : top
  )}rem;

  ${({ left }) => (isUndefined(left) ? '' : `left: ${left}rem`)};
  ${({ right }) => (isUndefined(right) ? '' : `right: ${right}rem`)};
`
