window.i18nReady.then(() => {
    document.querySelectorAll('[data-copy-target]').forEach(button => {
        button.addEventListener('click', function () {
            const targetId = this.getAttribute('data-copy-target');
            const target = document.getElementById(targetId);

            if (target) {
                const copyData = target.getAttribute('data-copy-data');
                if (copyData) {
                    navigator.clipboard.writeText(copyData).then(() => {
                        Swal.fire({
                            background: background,
                            color: color,
                            title: __('copied'),
                            text: __("copy_text_success"),
                            icon: 'success',
                            confirmButtonText: __("ok")
                        });
                    }).catch(err => {
                        console.error('Clipboard error:', err);
                        Swal.fire({
                            background: background,
                            color: color,
                            title: 'Error!',
                            text: 'Failed to copy the content.',
                            icon: 'error',
                            confirmButtonText: 'OK'
                        });
                    });
                }
            }
        });
    });
});