import { MarkType } from '../../types/drawing'
import { MARK_TYPE_CONFIG, MarkRenderProps } from './MarkStrategy'

interface MarkRenderComponentProps extends MarkRenderProps {
  markType: MarkType
}

export const MarkRender = ({ markType, ...rest }: MarkRenderComponentProps) => {
  const { render: RenderComponent } = MARK_TYPE_CONFIG[markType] || {}

  if (typeof RenderComponent !== 'undefined') {
    return <RenderComponent {...rest} />
  }

  return <DefaultRenderComponent {...rest} />
}

const DefaultRenderComponent = ({ value }: MarkRenderProps) => (
  <span>{value}</span>
)
