import * as arrow from './arrow'
import * as rectangle from './rectangle'
import * as circle from './circle'
import * as triangle from './triangle'
import * as polygon from './polygon'
import * as line from './line'
import * as text from './text'
import * as icon from './icon'
import * as image from './image'
import * as bgImage from './bg-image'

import { ArrowData } from './arrow'
import { RectangleData } from './rectangle'
import { CircleData } from './circle'
import { TriangleData } from './triangle'
import { PolygonData } from './polygon'
import { LineData } from './line'
import { TextData } from './text'
import { IconData } from './icon'
import { ImageData } from './image'
import { BGImageData } from './bg-image'
import { Pos } from '@/utils/math'

const _components = {
	arrow,
	rectangle,
	circle,
	triangle,
	polygon,
	line,
	text,
	icon,
	image,
	bgImage
}

export const components = _components as Components

export type Components = {
	[key in keyof typeof _components]: (typeof _components)[key] & {
		getSnapInfos?: (items: DrawItem<key>) => ComponentSnapInfo[]
	}
}
export type ComponentValue<T extends ShapeType, K extends keyof Components[T]> = Components[T][K]

export type DrawDataItem = {
	arrow: ArrowData,
	rectangle: RectangleData,
	circle: CircleData,
	triangle: TriangleData,
	polygon: PolygonData,
	line: LineData,
	text: TextData,
	icon: IconData,
	image: ImageData,
	bgImage: BGImageData
}
export type ShapeType = keyof DrawDataItem

export type DrawData = {
	[k in ShapeType]?: DrawDataItem[k][]
}

export type DrawItem<T extends ShapeType = ShapeType> = DrawDataItem[T]

export type SnapPoint = Pos & { view?: boolean }
export type ComponentSnapInfo = {
	point: SnapPoint,
	links: Pos[]
	linkDirections: Pos[],
	linkAngle: number[]
}