(function () {
  'use strict';

  document.addEventListener('click', function (e) {
    var btn = e.target.closest('.env-copy-btn');
    if (!btn) return;

    var targetSelector = btn.getAttribute('data-clipboard-target');
    var target = document.querySelector(targetSelector);
    if (!target) return;

    var text = target.textContent.trim();
    navigator.clipboard.writeText(text).then(function () {
      var origHTML = btn.innerHTML;
      btn.innerHTML = '<span class="env-copy-btn__icon">&#x2713;</span> Copied';
      btn.classList.add('env-copy-btn--copied');
      setTimeout(function () {
        btn.innerHTML = origHTML;
        btn.classList.remove('env-copy-btn--copied');
      }, 2000);
    });
  });
})();
