import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
  static targets = ["source", "trigger"]

  copy (event) {
    event.preventDefault();
    navigator.clipboard.writeText(this.sourceTarget.value);
    this.triggerTarget.querySelector('.content-initial').classList.add('hidden');
    this.triggerTarget.querySelector('.content-active').classList.remove('hidden');
    setTimeout(() => {
      this.triggerTarget.querySelector('.content-initial').classList.remove('hidden');
      this.triggerTarget.querySelector('.content-active').classList.add('hidden');
    }, 2000)
  }
}
