<commit_before>// @flow
import React from 'react'
import {connect} from 'react-redux'
import {withHandlers, compose} from 'recompose'
import FaIconCircle from 'react-icons/lib/fa/circle-o'
import classnames from 'classnames'

import {ENTITY_CLOSE_ZOOM} from '../../../../constants'
import {openAddressDetail, zoomToLocation, setDrawer, setEntitySearchOpen, deselectLocation} from '../../../../actions/publicActions'
import {
  zoomSelector,
  openedAddressDetailSelector,
  selectedLocationSelector,
} from '../../../../selectors'
import Marker from '../Marker/Marker'
import './ClusterMarker.css'

import type {Center} from '../../../../state'
import type {MapCluster} from '../../../../selectors'
import type {Thunk} from '../../../../types/reduxTypes'

type ClusterMarkerProps = {
  zoom: number,
  selectedLocation: Center,
  zoomToLocation: ({lat: number, lng: number}) => Thunk,
  cluster: MapCluster,
  onClick: () => void,
  openedAddressIds: Array<number>,
}
const clusterIsOnSelectedLocation = (selectedLocation, point) => (
  (selectedLocation !== null)
    && (point.lat === selectedLocation.lat)
    && (point.lng === selectedLocation.lng)
)
const ClusterMarker = ({
  cluster,
  zoom,
  selectedLocation,
  zoomToLocation,
  onClick,
  openedAddressIds,
}: ClusterMarkerProps) => {
  let className
  const selected = cluster.numPoints === 1 &&
  ((openedAddressIds.includes(cluster.points[0].address_id)
    || clusterIsOnSelectedLocation(selectedLocation, {lat: cluster.points[0].lat, lng: cluster.points[0].lng})))
  className = classnames({
    'simple-marker': cluster.isLabel,
    'company-marker': cluster.numPoints === 1,
    'cluster-marker': cluster.numPoints > 1,
    'government': !cluster.isLabel && cluster.points[0].tradewithgovernment,
  })
  const children = cluster.numPoints === 1
    ? <FaIconCircle size="18" />
    : !cluster.isLabel ? <span className="marker__text">{cluster.numPoints}</span> : <div />
  className = classnames(className, {selected})
  return (
    <Marker className={className} onClick={onClick}>
      {children}
    </Marker>
  )
}

export default compose(
  connect(
    (state) => ({
      openedAddressIds: openedAddressDetailSelector(state),
      zoom: zoomSelector(state),
      selectedLocation: selectedLocationSelector(state),<commit_msg>verejne frontend: update name of trafe_with_government flag<commit_after>// @flow
import React from 'react'
import {connect} from 'react-redux'
import {withHandlers, compose} from 'recompose'
import FaIconCircle from 'react-icons/lib/fa/circle-o'
import classnames from 'classnames'

import {ENTITY_CLOSE_ZOOM} from '../../../../constants'
import {openAddressDetail, zoomToLocation, setDrawer, setEntitySearchOpen, deselectLocation} from '../../../../actions/publicActions'
import {
  zoomSelector,
  openedAddressDetailSelector,
  selectedLocationSelector,
} from '../../../../selectors'
import Marker from '../Marker/Marker'
import './ClusterMarker.css'

import type {Center} from '../../../../state'
import type {MapCluster} from '../../../../selectors'
import type {Thunk} from '../../../../types/reduxTypes'

type ClusterMarkerProps = {
  zoom: number,
  selectedLocation: Center,
  zoomToLocation: ({lat: number, lng: number}) => Thunk,
  cluster: MapCluster,
  onClick: () => void,
  openedAddressIds: Array<number>,
}
const clusterIsOnSelectedLocation = (selectedLocation, point) => (
  (selectedLocation !== null)
    && (point.lat === selectedLocation.lat)
    && (point.lng === selectedLocation.lng)
)
const ClusterMarker = ({
  cluster,
  zoom,
  selectedLocation,
  zoomToLocation,
  onClick,
  openedAddressIds,
}: ClusterMarkerProps) => {
  let className
  const selected = cluster.numPoints === 1 &&
  ((openedAddressIds.includes(cluster.points[0].address_id)
    || clusterIsOnSelectedLocation(selectedLocation, {lat: cluster.points[0].lat, lng: cluster.points[0].lng})))
  className = classnames({
    'simple-marker': cluster.isLabel,
    'company-marker': cluster.numPoints === 1,
    'cluster-marker': cluster.numPoints > 1,
    'government': !cluster.isLabel && cluster.points[0].trade_with_government,
  })
  const children = cluster.numPoints === 1
    ? <FaIconCircle size="18" />
    : !cluster.isLabel ? <span className="marker__text">{cluster.numPoints}</span> : <div />
  className = classnames(className, {selected})
  return (
    <Marker className={className} onClick={onClick}>
      {children}
    </Marker>
  )
}

export default compose(
  connect(
    (state) => ({
      openedAddressIds: openedAddressDetailSelector(state),
      zoom: zoomSelector(state),
      selectedLocation: selectedLocationSelector(state),
{'fraction_non_alphanumeric': 0.1579286635152557, 'fraction_numerical': 0.004297378599054577, 'mean_word_length': 4.212765957446808, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '677431', 'n_tokens_mistral': 1383, 'n_tokens_neox': 1367, 'n_words': 313}