import $ from "jquery"
/**
 * Class Credit
 */
export default class Credit {
  /**
   * Run when the document is ready.
   *
   * @return {void}
   */

  constructor() {
    this.cache()
    const verified = 0
    const wpbakeryEditorMode = 0
  }

  cache() {
    this.parentContainer = $(".ac-container")
  }

  setVerifiedStatus() {
    this.verified = BafFrontendData.verified !== undefined && BafFrontendData.verified == 1 ? 1 : 0
  }

  docReady() {
    if (this.parentContainer.length === 0) return ""

    this.setVerifiedStatus()

    if (this.verified == 0) {
      this.attachCreditNote()
    }
  }

  getTheCreditNote() {
    return `<div class="plugin-credit-note"><strong>Powered by:</strong> <a href="${BafFrontendData.url}" target="_blank">${BafFrontendData.title}</a><div>`
  }

  attachCreditNote() {
    this.parentContainer.each((index, element) => {
      // Checking if accordion has content.
      if ($(element).find(".ac-container").length) {
        $(element).remove(".plugin-credit-note")
      } else {
        $(element).after(this.getTheCreditNote())
      }
    })
  }
}
