import {
  DrawPolygonMode,
  DrawRectangleMode,
  DrawCircleFromCenterMode,
  DrawPolygonByDraggingMode,
  GeoJsonEditMode,
} from '@deck.gl-community/editable-layers'
import type { LassoToolsMode, LassoToolsModes } from '../../types'
import { CustomCompositeEditMode } from './modes/custom-edit-mode.class'
import type { DefaultLassoToolsProps } from './types'
import { DataFilterExtension } from '@deck.gl/extensions'

export const MAP_LASSO_TOOLS_LAYER_ID = 'lassoLayer'
export const MAP_MASK_LAYER_ID = 'maskLayer'

export const DEFAULT_LASSO_TOOLS_LAYER_PROPS = {
  id: MAP_LASSO_TOOLS_LAYER_ID,
  billboard: false,
  editHandlePointRadiusUnits: 'pixels',
  editHandlePointRadiusMinPixels: 1,
  editHandlePointRadiusMaxPixels: 12,
  editHandlePointStrokeWidth: 3,
  getEditHandlePointRadius: 3,
  stroked: true,
  filled: true,
  lineWidthUnits: 'pixels',
  getLineWidth: 2,
  lineWidthMinPixels: 2,
} as const

export const DEFAULT_LASSO_TOOLS_COLORS: DefaultLassoToolsProps['styles']['colors'] =
  {
    editing: {
      border: [3, 111, 226, 255],
      fill: [3, 111, 226, 20.4],
      point: [255, 255, 255, 255],
    },
    finished: {
      border: [71, 219, 153, 255],
      fill: [71, 219, 153, 0],
    },
  } as const

export const DEFAULT_LASSO_TOOLS_PROPS: DefaultLassoToolsProps = {
  styles: {
    colors: {
      editing: DEFAULT_LASSO_TOOLS_COLORS.editing,
      finished: DEFAULT_LASSO_TOOLS_COLORS.finished,
    },
  },
  labels: {
    mask: 'Mask',
    draw: 'Drawing',
    selfIntersectionRepaired: 'Self-intersection automatically repaired',
  },
} as const

const EXTENSION_FILTER = [new DataFilterExtension({ filterSize: 1 })]

export const DEFAULT_MASK_LAYER_PROPS = {
  id: MAP_MASK_LAYER_ID,
  operation: 'mask',
  pickable: false,
  visible: true,
  extensions: EXTENSION_FILTER,
  filterRange: [1, 1],
}

export const DEFAULT_LASSO_TOOLS_MODES: LassoToolsModes<
  LassoToolsMode,
  GeoJsonEditMode
> = {
  polygon: {
    value: 'polygon',
    mode: DrawPolygonMode,
  },
  rectangle: {
    value: 'rectangle',
    mode: DrawRectangleMode,
  },
  circle: {
    value: 'circle',
    mode: DrawCircleFromCenterMode,
  },
  lasso: {
    value: 'lasso',
    mode: DrawPolygonByDraggingMode,
  },
  edit: {
    value: 'edit',
    mode: CustomCompositeEditMode,
  },
} as const
