import { Controller } from "@hotwired/stimulus"
import { useIntersection } from "stimulus-use"
import { get } from "@rails/request.js"

export default class extends Controller {

  static values = {    
    url: String
  }

  connect() {
    this.fetchingData = false
    useIntersection(this)
  }

  async appear () {
    
    if (this.fetchingData) return
    

    this.fetchingData = true   
    await get(this.urlValue, { responseKind: "turbo-stream" } )
    this.fetchingData = false
  }


}
