import { Controller } from '@hotwired/stimulus';

export default class extends Controller {

   copy(event) {
      const element = event.currentTarget as HTMLElement;

      if (element) {
         navigator.clipboard.writeText(event.params.copy).then(() => {
            element.textContent = event.params.text;
            element.classList.add("copied");

            setTimeout(() => {
               element.textContent = event.params.copy;
               element.classList.remove("copied");
            }, 2000);
         });
      }
   }
}
