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 { useStyletron } from '../styles';
import { getOverrides } from '../helpers/overrides';
import { PINHEAD_TYPES, NEEDLE_SIZES, PINHEAD_SIZES_SHAPES, LABEL_ENHANCER_POSITIONS, KIND, dragShadowHeight, dragShadowMarginTop } from './constants';
import PinHead from './pin-head';
import Needle from './needle';
import DragShadow from './drag-shadow';
import { StyledFixedMarkerDragContainer, StyledFixedMarkerRoot } from './styled-components';

function getColors(kind, theme) {
  if (kind === KIND.accent) {
    return {
      color: theme.colors.contentInversePrimary,
      backgroundColor: theme.colors.backgroundAccent
    };
  }

  if (kind === KIND.negative) {
    return {
      color: theme.colors.contentInversePrimary,
      backgroundColor: theme.colors.backgroundNegative
    };
  }

  return {
    color: theme.colors.contentInversePrimary,
    backgroundColor: theme.colors.backgroundInversePrimary
  };
}

const FixedMarker = ({
  size = PINHEAD_SIZES_SHAPES.medium,
  needle = NEEDLE_SIZES.medium,
  label,
  startEnhancer,
  endEnhancer,
  kind = KIND.default,
  dragging = false,
  overrides = {},
  labelEnhancerContent = null,
  labelEnhancerPosition = LABEL_ENHANCER_POSITIONS.bottom,
  badgeEnhancerSize = null,
  badgeEnhancerContent = null,
  ...restProps
}) => {
  const [, theme] = useStyletron();
  const {
    color,
    backgroundColor
  } = getColors(kind, theme);
  const doesPinHeadTransformOnDrag = needle !== NEEDLE_SIZES.none && size !== PINHEAD_SIZES_SHAPES.xxSmallCircle && size !== PINHEAD_SIZES_SHAPES.xxSmallSquare;
  const [Root, rootProps] = getOverrides(overrides.Root, StyledFixedMarkerRoot);
  const [FixedMarkerDragContainer, fixedMarkerDragContainerProps] = getOverrides(overrides.DragContainer, StyledFixedMarkerDragContainer);
  const renderNeedle = needle !== NEEDLE_SIZES.none && ![PINHEAD_SIZES_SHAPES.xxSmallCircle, PINHEAD_SIZES_SHAPES.xxSmallSquare].includes(size);

  if (process.env.NODE_ENV !== "production") {
    if (needle !== NEEDLE_SIZES.none && [PINHEAD_SIZES_SHAPES.xxSmallCircle, PINHEAD_SIZES_SHAPES.xxSmallSquare].includes(size)) {
      console.warn(`Needles cannot be rendered with ${PINHEAD_SIZES_SHAPES.xxSmallCircle} or ${PINHEAD_SIZES_SHAPES.xxSmallSquare} pin heads`);
    }
  }

  const enhancers = {};

  if (startEnhancer) {
    enhancers.startEnhancer = startEnhancer;
  }

  if (endEnhancer) {
    enhancers.endEnhancer = endEnhancer;
  }

  return /*#__PURE__*/React.createElement(Root, _extends({
    "data-baseweb": "fixed-map-marker"
  }, rootProps), /*#__PURE__*/React.createElement(FixedMarkerDragContainer, _extends({
    $translateAmount: dragShadowMarginTop + dragShadowHeight,
    $performTranslate: doesPinHeadTransformOnDrag && !dragging
  }, fixedMarkerDragContainerProps), /*#__PURE__*/React.createElement(PinHead, _extends({
    size: size,
    label: label
  }, enhancers, {
    color: color,
    background: backgroundColor,
    type: PINHEAD_TYPES.fixed,
    overrides: overrides,
    badgeEnhancerSize: badgeEnhancerSize,
    badgeEnhancerContent: badgeEnhancerContent,
    labelEnhancerContent: labelEnhancerContent,
    labelEnhancerPosition: labelEnhancerPosition,
    needle: needle
  })), renderNeedle && /*#__PURE__*/React.createElement(Needle, {
    size: needle,
    background: backgroundColor,
    overrides: overrides
  })), doesPinHeadTransformOnDrag && /*#__PURE__*/React.createElement(DragShadow, {
    background: backgroundColor,
    dragging: dragging,
    height: dragShadowMarginTop + dragShadowHeight,
    overrides: overrides
  }));
};

export default FixedMarker;