import { v4 as uuidv4 } from 'uuid';

export default class BaseAnnotation {
  constructor ({
    container,
    annotation,
    viewport,
    page,
    eventBus,
    layer,
  }) {
    if (!annotation.name) {
      annotation.name = uuidv4()
    }
    this.layer = layer
    this.container = container
    this.annotation = annotation
    this.viewport = viewport
    this.scale = viewport.scale
    this.isEdit = false
    this.eventBus = eventBus
    this.scrollTop = 0
    this.scrollLeft = 0

    this.deleteSvgStr = `<rect width="30" height="30" rx="2" fill="#DDE9FF"/>
      <path fill-rule="evenodd" clip-rule="evenodd" d="M19 6.5V9.5H24V10.5H21.5V23.5H8.5V10.5H6V9.5H11V6.5H19ZM9.5 10.5V22.5H20.5V10.5H9.5ZM18 7.5V9.5H12V7.5H18ZM13.5 13V20H12.5V13H13.5ZM17.5 20V13H16.5V20H17.5Z" fill="#333333"/>
    `
    this.replySvgStr = `<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path d="M16 12.3333C16 12.7017 15.8537 13.055 15.5932 13.3154C15.3327 13.5759 14.9795 13.7222 14.6111 13.7222H6.27778L3.5 16.5V5.38889C3.5 5.02053 3.64633 4.66726 3.9068 4.4068C4.16726 4.14633 4.52053 4 4.88889 4H14.6111C14.9795 4 15.3327 4.14633 15.5932 4.4068C15.8537 4.66726 16 5.02053 16 5.38889V12.3333Z" stroke="#43474D" stroke-linecap="round" stroke-linejoin="round"/>
    </svg>`

    this.page = page
  }

  getMouseLocation(e) {
    const documentViewer = this.layer.documentViewer
    const scrollElement = documentViewer.getScrollViewElement();
    const scrollLeft = scrollElement.scrollLeft || 0
    const scrollTop = scrollElement.scrollTop || 0
  
    return {
      x: e.pageX + scrollLeft,
      y: e.pageY + scrollTop
    }
  }
}
