function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

/*
Copyright (c) Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
import * as React from 'react';
import { getOverrides } from '../helpers/overrides';
import { StyledInnerXXSmallAnchor, StyledOuterXXSmallAnchor, StyledInnerXSmallAnchor, StyledOuterXSmallAnchor, StyledPinHead, RelativeContainer, StyledContentItem } from './styled-components';
import { PINHEAD_DIMENSIONS, PINHEAD_TYPES, PINHEAD_SIZES_SHAPES, NEEDLE_HEIGHTS, NEEDLE_SIZES } from './constants';
import BadgeEnhancer from './badge-enhancer';
import LabelEnhancer from './label-enhancer';

const PinHead = ({
  size = PINHEAD_SIZES_SHAPES.medium,
  label = '',
  startEnhancer: StartEnhancer,
  endEnhancer: EndEnhancer,
  color,
  background,
  type = PINHEAD_TYPES.fixed,
  anchorType,
  needle = NEEDLE_SIZES.none,
  labelEnhancerContent,
  labelEnhancerPosition,
  badgeEnhancerSize,
  badgeEnhancerContent,
  overrides = {}
}) => {
  const activeElements = [label, StartEnhancer, EndEnhancer].filter(x => x);
  const gridTemplateColumns = activeElements.map(() => 'auto').join(' ');
  const forceCircle = activeElements.length === 1 && !label;
  const {
    height,
    icon
  } = PINHEAD_DIMENSIONS[size];
  const [PinHead, pinHeadProps] = getOverrides(overrides.PinHead, StyledPinHead);
  const [ContentItem, contentItemProps] = getOverrides(overrides.PinHeadContent, StyledContentItem);
  const [InnerXXSmallAnchor, innerXXSmallAnchorProps] = getOverrides(overrides.InnerAnchor, StyledInnerXXSmallAnchor);
  const [OuterXXSmallAnchor, outerXXSmallAnchorProps] = getOverrides(overrides.OuterAnchor, StyledOuterXXSmallAnchor);
  const [InnerXSmallAnchor, innerXSmallAnchorProps] = getOverrides(overrides.InnerAnchor, StyledInnerXSmallAnchor);
  const [OuterXSmallAnchor, outerXSmallAnchorProps] = getOverrides(overrides.OuterAnchor, StyledOuterXSmallAnchor);
  const badge = /*#__PURE__*/React.createElement(BadgeEnhancer, {
    markerType: type,
    pinHeadSize: size,
    badgeEnhancerSize: badgeEnhancerSize,
    badgeEnhancerContent: badgeEnhancerContent,
    overrides: overrides
  });

  if (type === PINHEAD_TYPES.fixed && (size === PINHEAD_SIZES_SHAPES.xxSmallCircle || size === PINHEAD_SIZES_SHAPES.xxSmallSquare)) {
    const round = size === PINHEAD_SIZES_SHAPES.xxSmallCircle;
    return /*#__PURE__*/React.createElement(OuterXXSmallAnchor, _extends({
      $round: round,
      $background: background,
      $size: height
    }, outerXXSmallAnchorProps), /*#__PURE__*/React.createElement(InnerXXSmallAnchor, _extends({
      $color: color,
      $round: round,
      $size: icon
    }, innerXXSmallAnchorProps)));
  }

  if (type === PINHEAD_TYPES.fixed && (size === PINHEAD_SIZES_SHAPES.xSmallSquare || size === PINHEAD_SIZES_SHAPES.xSmallCircle)) {
    const round = size === PINHEAD_SIZES_SHAPES.xSmallCircle;
    return /*#__PURE__*/React.createElement(RelativeContainer, null, badge, /*#__PURE__*/React.createElement(OuterXSmallAnchor, _extends({
      $round: round,
      $background: background,
      $size: height
    }, outerXSmallAnchorProps), /*#__PURE__*/React.createElement(InnerXSmallAnchor, _extends({
      $color: color,
      $round: round,
      $size: icon
    }, innerXSmallAnchorProps))));
  }

  return /*#__PURE__*/React.createElement(RelativeContainer, null, /*#__PURE__*/React.createElement(LabelEnhancer, {
    labelEnhancerContent: labelEnhancerContent,
    labelEnhancerPosition: labelEnhancerPosition,
    needleHeight: NEEDLE_HEIGHTS[needle],
    size: size,
    overrides: overrides
  }), badge, /*#__PURE__*/React.createElement(PinHead, _extends({
    $background: background,
    $height: height,
    $gridTemplateColumns: gridTemplateColumns,
    $forceCircle: forceCircle,
    $type: type
  }, pinHeadProps), StartEnhancer && /*#__PURE__*/React.createElement(ContentItem, _extends({
    $height: height,
    $color: color,
    $size: size
  }, contentItemProps), /*#__PURE__*/React.createElement(StartEnhancer, {
    size: icon
  })), label && /*#__PURE__*/React.createElement(ContentItem, _extends({
    $height: height,
    $color: color,
    $size: size
  }, contentItemProps), label), EndEnhancer && /*#__PURE__*/React.createElement(ContentItem, _extends({
    $height: height,
    $color: color,
    $size: size
  }, contentItemProps), /*#__PURE__*/React.createElement(EndEnhancer, {
    size: icon
  }))));
};

export default PinHead;