import React from 'react';
import styled from 'styled-components';
import PropTypes from 'prop-types';

import { withTheme } from '../../styles';

const MARKER_SIZE = 0.8;
const MARKER_PADDING = 0.3;
const POINT_MARKER_SIZE = 0.188;
const POINT_MARKER_PADDING = 0.188;

const StyledMarkerComponent = styled(({ isOnlyMarker, ...rest }) => (
  <div {...rest} />
))`
  height: ${(props) =>
    props.isOnlyMarker ? POINT_MARKER_SIZE : MARKER_SIZE}rem;
  min-width: ${(props) =>
    props.isOnlyMarker ? POINT_MARKER_SIZE : MARKER_SIZE}rem;
  width: auto;
  border-radius: 1rem;
  position: absolute;
  //calc the correct position for the marker.
  //see: https://github.com/istarkov/google-map-react/blob/master/API.md#positioning-a-marker
  left: ${(props) =>
    -(props.isOnlyMarker ? POINT_MARKER_SIZE : MARKER_SIZE) / 2}rem;
  top: ${(props) =>
    -(props.isOnlyMarker ? POINT_MARKER_SIZE : MARKER_SIZE) / 2}rem;
  background: ${(props) => props.theme.colors.primary.base};
  padding: ${(props) =>
    props.isOnlyMarker ? POINT_MARKER_PADDING : MARKER_PADDING}rem;
  white-space: nowrap;
  color: white;
  font-size: 1.2em;
  line-height: 1;
  text-align: center;
  z-index: ${(props) => (props.isOnlyMarker ? 0 : 1)};
  border: ${(props) => (props.isOnlyMarker ? '2px solid white' : 0)};
`;

StyledMarkerComponent.propTypes = { isOnlyMarker: PropTypes.bool };

const StyledMarker = withTheme(StyledMarkerComponent);

const StyledLabelComponent = styled(({ isOnlyMarker, ...rest }) => (
  <div {...rest} />
))`
  color: ${(props) => props.theme.colors.primary.base};
  font-size: 0.8rem;
  text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white;
  font-weight: 700;
  line-height: 1;
  position: absolute;
  left: ${(props) => (props.isOnlyMarker ? 150 : 110)}%;
  bottom: ${(props) => (props.isOnlyMarker ? -5 : 5)}px;
`;

const StyledLabel = withTheme(StyledLabelComponent);

export { StyledMarker, StyledLabel };
