export const DOCS_GRAPHIC_CROP_START_EVENT = "ultidocs:graphic-crop-start"
export const DOCS_GRAPHIC_CROP_APPLY_EVENT = "ultidocs:graphic-crop-apply"
export const DOCS_GRAPHIC_CROP_CHANGED_EVENT = "ultidocs:graphic-crop-changed"

export function startDocsGraphicCrop() {
  window.dispatchEvent(new CustomEvent(DOCS_GRAPHIC_CROP_START_EVENT))
}

export function applyDocsGraphicCrop() {
  window.dispatchEvent(new CustomEvent(DOCS_GRAPHIC_CROP_APPLY_EVENT))
}

export function notifyDocsGraphicCropChanged(active: boolean) {
  window.dispatchEvent(
    new CustomEvent(DOCS_GRAPHIC_CROP_CHANGED_EVENT, { detail: { active } })
  )
}

export function readDocsGraphicCropActive(): boolean {
  return Boolean(document.querySelector(".docs-graphic--cropping"))
}
