import { useMemo } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import getColor from "../../../../utils/colors/getColor.js";
import useBoundaryProps from '../../hooks/useBoundaryProps';
import useZoomTransform from '../../hooks/useZoomTransform';
import TooltipTrigger from '../../OptionalTooltip';
import getCircleTransform from './_utils/getCircleTransform';
const defaultDotProps = {
  fill: 'white',
  stroke: getColor('warmgray-100')
};
const DistrictDots = function DistrictDots(props) {
  const {
    districts: districtShapes,
    tooltip,
    customClasses,
    getBoundaryProps
  } = props;
  const {
    k: zoomScale,
    zoomLevel
  } = useZoomTransform();
  const dotSize = 2 * (5 + 8 * zoomLevel);
  const districts = useMemo(() => districtShapes.filter(({
    properties
  }) => !properties.noDot), [districtShapes]);
  const {
    districtDotClass,
    districtDotClassesByCode = {}
  } = customClasses;
  const boundaryProps = useBoundaryProps({
    getProps: getBoundaryProps,
    defaults: defaultDotProps
  });
  return <g>
      {districts.map(({
      properties
    }) => <TooltipTrigger key={properties.code} as="g" tooltip={tooltip} props={properties}>
          <circle className={classnames(districtDotClass, districtDotClassesByCode[properties.code])} transform={getCircleTransform(properties, zoomScale)} r={dotSize} {...boundaryProps(properties)} />
        </TooltipTrigger>)}
    </g>;
};
DistrictDots.defaultProps = {
  districtColorByCode: new Map(),
  tooltip: undefined,
  customClasses: {},
  getBoundaryProps: undefined
};
DistrictDots.propTypes = {
  districts: PropTypes.arrayOf(PropTypes.shape({
    properties: PropTypes.shape({
      code: PropTypes.string,
      d: PropTypes.string
    })
  })).isRequired,
  districtColorByCode: PropTypes.instanceOf(Map),
  tooltip: PropTypes.shape({}),
  customClasses: PropTypes.shape({
    districtDotClass: PropTypes.string,
    districtDotClassesByCode: PropTypes.shape({})
  }),
  getBoundaryProps: PropTypes.func
};
export default DistrictDots;