text: class DocumentRequests {
      static getDraftRequest() {
  
          let editDocumentForm = document.querySelector('#edit-document-form')
  
          let draftContent = {
              content: ''
          }
  
          $.ajax({
              type: 'GET',
              url: editDocumentForm.dataset.getDraft,
              processData: false,
              contentType: false,
              async: false
          }).done(function (response) {
              if (response.document.content) {
                  draftContent = response.document
              }
          }).fail(function (response) {
              console.log('Error with getting draft')
          })
  
          return draftContent
      }
  
      static publishGitDocument(commit) {
  
          let access_token = document.querySelector('meta[name="csrf-token"]').getAttribute("content")
  
          $.ajax({
              type: 'POST',
              url: window.location.href + '/publish-git-document',
              async: true,
              data: {
                  _token: access_token,
                  commit: !!(commit),
              }
          }).done(function (response) {
              console.log(response.data.status)
          }).fail(function (response) {
              console.log(response.data.status)
          })
      }
  
      static commitDocument () {
  
          let access_token = document.querySelector('meta[name="csrf-token"]').getAttribute("content")
  
          $.ajax({
              type: 'POST',
              url: window.location.href + '/commit-document',
              async: true,
              data: {
                  _token: access_token,
              }
          }).done(function (response) {
              console.log(response.data.status)
          }).fail(function (response) {
              console.log(response.data.status)
          })
      }
  
  
      static sendUpdateContentRequest(access_token, isDraftOnly = false) {
          let documentContent = ''
          let editDocumentForm = document.querySelector('#edit-document-form:not(.untitled-document)')
          if (editDocumentForm) {
              let defaultCKEditorContent = document.querySelector('#default-document-ckeditor')
              let collaborationCKEditorContent = document.querySelector('#collaboration-document-ckeditor')
              let draftContent = document.querySelector('.document-content-draft .srm-description__content-inner')
  
              let url = isDraftOnly ? editDocumentForm.dataset.updateDraft : editDocumentForm.action
  
              if (defaultCKEditorContent && window.defaultDocumentCKEditor) {
                  documentContent = window.defaultDocumentCKEditor.getData()
              }
  
              if (collaborationCKEditorContent && window.collaborationDocumentCKEditor) {
                  documentContent = collaborationDocumentCKEditor.getData()
              }
  
              if (!defaultDocumentCKEditor && !collaborationDocumentCKEditor) {
                  if (draftContent) {
                      documentContent = draftContent.innerHTML
                  }
              }
  
              if (documentContent.trim().length) {
                  let formData = new FormData()
  
                  formData.append('_token', access_token)
                  formData.append('_method', 'PUT')
  
                  formData.append('document', documentContent)
  
  
                  if (window.commentsRepository) {
                      window.commentThreadsData = window.commentsRepository.getCommentThreads({
                          skipNotAttached: true,
                          skipEmpty: true,
                          toJSON: true
                      });
  
                      if (window.commentThreadsData && window.commentThreadsData.length) {
                          formData.append('document_comments', JSON.stringify(window.commentThreadsData))
                      } else {
                          formData.append('document_comments', '')
                      }
                  }
  
                  if (window.collaborationDocumentCKEditor) {
                      formData.append('collaborative', 'true')
                  }
  
  
                  $.ajax({
                      type: 'POST',
                      url: url,
                      data: formData,
                      processData: false,
                      contentType: false,
                      async: false
                  }).done((response) => {
                      console.log(response.data.status)
  
                      if (!isDraftOnly) {
                          this.publishGitDocument(response.data.document.status)
                      } else {
                          if (response.data.document.status === true) {
                              this.commitDocument()
                          }
                      }
  
                      if (!isDraftOnly) {
  
                          let isHrInContent = $('.document-content .srm-description__content_public .srm-description__content-inner hr').length
                          let isHrInNewContent = response.data.document.content.includes('<hr>')
  
                          $('.document-content .srm-description__content_public .srm-description__content-inner').html(response.data.document.content)
  
                          if (!!isHrInContent && !isHrInNewContent) {
                              $('.srm-description__content_public .projects-see-more-btn-public').remove()
                          }
  
  
                          if (!isHrInContent && isHrInNewContent) {
  
                              let btnText = $('.document-content').hasClass('document-opened-public') ? 'See less' : 'See more'
  
                              let seeMoreBtn = `<div class="projects-see-more projects-see-more-btn-public">
              <span class="projects-see-more-text">${btnText}</span>
              <svg class="comments-triangle">
                <use xlink:href="#triangle-icon"></use>
              </svg>
              <div class="projects-see-line"></div>
            </div>`
  
  
                              $(seeMoreBtn).insertAfter(".document-content .srm-description__content_public .srm-description__content-inner");
  
                              let documentWrapper = $('.document-content')
                              let seeMoreText = $('.document-content .document-content-public .projects-see-more-text')
  
                              $('.document-content .document-content-public .projects-see-more-btn-public').click(() => {
                                  documentWrapper.toggleClass('document-opened-public')
                                  if (seeMoreText.text() == 'See more') {
                                      seeMoreText.text('See less')
                                  } else {
                                      seeMoreText.text('See more')
                                  }
                              })
                          }
                      }
  
  
                      $('.document-content').removeClass('document-opened-public')
  
                      clearTimeout(window.contentTimer)
                      window.contentTimer = null
  
                  }).fail(function (response) {
                      console.log(response.data.status)
                  })
              }
          }
      }
  
      static sendUpdateIconRequest(access_token) {
  
          let editDocumentForm = document.querySelector('#edit-document-form')
          let icon = editDocumentForm.querySelector('#edit-document-icon')
  
          let formData = new FormData()
  
          formData.append('_token', access_token)
          formData.append('_method', 'PUT')
  
          formData.append('icon', icon.value)
  
  
          $.ajax({
              type: 'POST',
              url: editDocumentForm.dataset.updateIcon,
              data: formData,
              processData: false,
              contentType: false
          }).done(function (response) {
              console.log(response.data.status)
  
              if (response.data.document.icon) {
                  $('#change-icon-btn').html(response.data.document.icon)
                  $('#change-icon-btn').removeClass('empty-icon')
              } else {
  
                  let imageName = 'default-document-icon.svg'
                  let documentContent = document.querySelector('.document-content')
  
                  if (documentContent.classList.contains('document-challenge')) {
                      imageName = 'default-challenge-icon.svg'
                  } else if (documentContent.classList.contains('document-wiki')) {
                      imageName = 'default-wiki-icon.svg'
                  } else if (documentContent.classList.contains('document-idea')) {
                      imageName = 'default-idea-icon.svg'
                  } else if (documentContent.classList.contains('document-project')) {
                      imageName = 'default-project-icon.svg'
                  }
  
  
                  $('#change-icon-btn').html(`<img src="${window.location.protocol + "//" + window.location.host + "/img/" + imageName}" alt="">`)
                  $('#change-icon-btn').addClass('empty-icon')
              }
  
  
          }).fail(function (response) {
              console.log(response.data.status)
          })
      }
  
      static sendUpdateTitleRequest(access_token) {
  
          let editDocumentForm = document.querySelector('#edit-document-form:not(.untitled-document)')
          if(editDocumentForm) {
              let title = document.querySelector('.document-content #title')
  
              if (title.textContent.trim().length) {
                  let formData = new FormData()
  
                  formData.append('_token', access_token)
                  formData.append('_method', 'PUT')
                  formData.append('title', title.textContent)
  
                  $.ajax({
                      type: 'POST',
                      url: editDocumentForm.dataset.updateTitle,
                      data: formData,
                      processData: false,
                      contentType: false
                  }).done(function (response) {
                      console.log(response.data.status)
                  }).fail(function (response) {
                      console.log(response.data.status)
                  })
              }
          }
      }
  
      static sendUpdateParentRequest(parentId, access_token) {
  
          let editDocumentForm = document.querySelector('#edit-document-form')
  
          let formData = new FormData()
  
          formData.append('_token', access_token)
          formData.append('_method', 'PUT')
  
          formData.append('parent_id', parentId)
  
          $.ajax({
              type: 'POST',
              url: editDocumentForm.dataset.updateParent,
              data: formData,
              processData: false,
              contentType: false
          }).done(function (response) {
              console.log(response.data.status)
          }).fail(function (response) {
              console.log(response.data.status)
          })
      }
  
      static getEmojiBlock(route, blockClasses, isDocument=false){
  
          let emojiBlock = null
          let data = null
  
          if (isDocument){
              data = {
                  isDocument: true
              }
          }
  
          $.ajax({
              url: route,
              data: data,
              type: "get",
              async: false
          }).done(function (response) {
              emojiBlock = document.createElement('div')
              emojiBlock.className = blockClasses
              emojiBlock.insertAdjacentHTML("beforeEnd", response)
          }).fail(function (response) {
              console.log(response)
          });
  
          return emojiBlock
      }
  }
  
  module.exports = DocumentRequests
  