/**
 * BoostBot Widget View Scripts
 *
 * JavaScript for interactive widget templates (e.g. coupon copy).
 * Enqueued via wp_enqueue_script in class-boostbot.php.
 *
 * @package BoostBot
 * @since 2.2.17
 */

/* global navigator */

/**
 * Copy a coupon code to clipboard and show visual feedback.
 *
 * @param {string} id   The coupon card element ID.
 * @param {string} code The coupon code to copy.
 */
function boostbotCopyCoupon(id, code) { // eslint-disable-line no-unused-vars
    navigator.clipboard.writeText(code).then(function () {
        var btn = document.querySelector('#' + id + ' .bb-coupon-copy');
        if (!btn) return;
        btn.classList.add('copied');
        setTimeout(function () {
            btn.classList.remove('copied');
        }, 2000);
    });
}
