 MinimapIndicator = require './minimap-indicator'
 MinimapOpenQuickSettingsView = require './minimap-open-quick-settings-view'
 
+# Public: A `MinimapView` instance is created for every `Editor` opened in Atom.
+# It provides delegation to many `Editor` and {MinimapRenderView} methods so
+# that in most case you can just substitute a {MinimapView} instance
+# instead of an `Editor`.
+#
+# The following methods are delegated to the {MinimapRenderView} instance:
+#
+# - [getLineHeight]{MinimapRenderView::getLineHeight}
+# - [getCharHeight]{MinimapRenderView::getCharHeight}
+# - [getCharWidth]{MinimapRenderView::getCharWidth}
+# - [getLinesCount]{MinimapRenderView::getLinesCount}
+# - [getMinimapHeight]{MinimapRenderView::getMinimapHeight}
+# - [getMinimapScreenHeight]{MinimapRenderView::getMinimapScreenHeight}
+# - [getMinimapHeightInLines]{MinimapRenderView::getMinimapHeightInLines}
+# - [getFirstVisibleScreenRow]{MinimapRenderView::getFirstVisibleScreenRow}
+# - [getLastVisibleScreenRow]{MinimapRenderView::getLastVisibleScreenRow}
+# - [pixelPositionForScreenPosition]{MinimapRenderView::pixelPositionForScreenPosition}
+# - [decorateMarker]{DecorationManagement::decorateMarker}
+# - [removeDecoration]{DecorationManagement::removeDecoration}
+# - [decorationsForScreenRowRange]{DecorationManagement::decorationsForScreenRowRange}
+# - [removeAllDecorationsForMarker]{DecorationManagement::removeAllDecorationsForMarker}
+#
+# The following methods are delegated to the `Editor` instance:
+#
+# - getSelection
+# - getSelections
+# - getLastSelection
+# - bufferRangeForBufferRow
+# - getTextInBufferRange
+# - getEofBufferPosition
+# - scanInBufferRange
+# - markBufferRange
 module.exports =
 class MinimapView extends View
   Debug('minimap').includeInto(this)
   Delegato.includeInto(this)
-
 
   @delegatesMethods 'getLineHeight', 'getCharHeight', 'getCharWidth', 'getLinesCount', 'getMinimapHeight', 'getMinimapScreenHeight', 'getMinimapHeightInLines', 'getFirstVisibleScreenRow', 'getLastVisibleScreenRow', 'pixelPositionForScreenPosition', 'decorateMarker', 'removeDecoration', 'decorationsForScreenRowRange', 'removeAllDecorationsForMarker', toProperty: 'renderView'
 

    @renderView.destroy()
    @remove()

  # MINIMAP DISPLAY MANAGEMENT

  attachToPaneView: ->
    @paneView.append(this)
    @adjustTopPosition()

  detachFromPaneView: ->
    @detach()

  minimapIsAttached: -> @paneView.find('.minimap').length is 1

  # EDITOR VIEW MANAGEMENT

  unsubscribeFromEditor: ->
    @unsubscribe @editor, '.minimap' if @editor?
    @unsubscribe @scrollView, '.minimap' if @scrollView?

  subscribeToEditor: ->
    @subscribe @editor, 'scroll-top-changed.minimap', @updateScrollY
    # Hacked scroll-left
    @subscribe @scrollView, 'scroll.minimap', @updateScrollX

  getEditorViewClientRect: -> @scrollView[0].getBoundingClientRect()

  getScrollViewClientRect: -> @scrollViewLines[0].getBoundingClientRect()

  getMinimapClientRect: -> @[0].getBoundingClientRect()

  # UPDATE METHODS

  updateMinimapRenderView: => @renderView.update()

  updateMinimapSize: =>
    return unless @indicator?

    {width, height} = @getMinimapClientRect()
    editorViewRect = @getEditorViewClientRect()
    miniScrollViewRect = @renderView.getClientRect()

    evw = editorViewRect.width
    evh = editorViewRect.height

    minimapVisibilityRatio = miniScrollViewRect.height / height

    @miniScroller.height(evh / minimapVisibilityRatio)
    @miniScroller.toggleClass 'visible', minimapVisibilityRatio > 1 and @miniScrollVisible

    @miniWrapper.css {width}

    # VisibleArea's size
    @indicator.height = evh * @scaleY
    @indicator.width = width / @scaleX

    @miniVisibleArea.css
      width : width / @scaleX
      height: evh * @scaleY

    msvw = miniScrollViewRect.width || 0
    msvh = miniScrollViewRect.height || 0

    # Minimap's size
    @indicator.setWrapperSize width, Math.min(height, msvh)

    # Minimap ScrollView's size
    @indicator.setScrollerSize msvw, msvh

    # Compute boundary
    @indicator.updateBoundary()


  updateMinimapView: =>
    return unless @editorView
    return unless @indicator


  isClicked: false

  ### Public ###

  #    #### ##    ## #### ########
  #     ##  ###   ##  ##     ##
  #     ##  ####  ##  ##     ##
  #     ##  ## ## ##  ##     ##
  #     ##  ##  ####  ##     ##
  #     ##  ##   ###  ##     ##
  #    #### ##    ## ####    ##

  # Creates a new {MinimapView}.
  #
  # editorView - The `EditorView` for which displaying a minimap.
  constructor: (@editorView) ->
    @editor = @editorView.getEditor()
    @paneView = @editorView.getPaneView()
