<commit_before>DocumentationView = require './atom-ternjs-documentation-view'

module.exports =
class Reference

  documentation: null
  disposables: []
  client: null

  constructor: (client, state = {}) ->
    state.attached ?= true

    @client = client

    @documentation = new DocumentationView()
    @documentation.initialize(state)
    @documentationPanel = atom.workspace.addBottomPanel(item: @documentation, priority: 0)
    @documentationPanel.hide()

    atom.views.getView(@documentationPanel).classList.add("atom-ternjs-documentation-panel", "panel-bottom")

  set: (data) ->
    @documentation.setTitle(data.word, data.label)
    @documentation.setContent(data.docs)
    @show()

  hide: ->
    @documentationPanel?.hide()

  show: ->
    @documentationPanel?.show()

  destroy: ->
    @documentation?.destroy()
    @documentation = null

    @documentationPanel?.destroy()
    @documentationPanel = null<commit_msg>use modalPanel (for now) if there is not enough space at the bottom<commit_after>DocumentationView = require './atom-ternjs-documentation-view'

module.exports =
class Reference

  documentation: null
  disposables: []
  client: null
  orientation: null

  constructor: (client, state = {}) ->
    state.attached ?= true

    @client = client

    @documentation = new DocumentationView()
    @documentation.initialize(state)

    @addBottom()
    @documentationPanel.hide()

    atom.views.getView(@documentationPanel).classList.add("atom-ternjs-documentation-panel", "panel-bottom")

  addBottom: ->
    @orientation = 'bottom'
    @documentationPanel = atom.workspace.addBottomPanel(item: @documentation, priority: 0)

  addTop: ->
    @orientation = 'right'
    @documentationPanel = atom.workspace.addModalPanel(item: @documentation, priority: 0)

  destroyPanel: ->
    @documentationPanel?.destroy()
    @documentationPanel = null

  setPosition: ->
    editor = atom.workspace.getActiveTextEditor()
    cursor = editor.getLastCursor()
    cursorTop = cursor.getPixelRect().top
    editorHeight = editor.getHeight()

    if editorHeight - cursorTop <= 200 and @orientation is 'bottom'
      @destroyPanel()
      @addTop()
      return

    if editorHeight - cursorTop > 200 and @orientation is 'right'
      @destroyPanel()
      @addBottom()

  set: (data) ->
    @setPosition()
    @documentation.setTitle(data.word, data.label)
    @documentation.setContent(data.docs)
    @show()

  hide: ->
    @documentationPanel?.hide()

  show: ->
    @documentationPanel?.show()

  destroy: ->
    @documentation?.destroy()
    @documentation = null
{'fraction_non_alphanumeric': 0.12785741960480435, 'fraction_numerical': 0.003487020534676482, 'mean_word_length': 3.6945454545454544, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7642388', 'n_tokens_mistral': 787, 'n_tokens_neox': 719, 'n_words': 151}