(function($){
'use strict';
$(document).on('click', '.wcp-copy-btn-inline', function(){
var code=$(this).data('code');
if(code){
navigator.clipboard.writeText(code).then(function(){
var btn=$(this);
var originalText=btn.text();
btn.text('Copied!');
setTimeout(function(){
btn.text(originalText);
}, 2000);
}.bind(this));
}});
$(document).on('click', '.wcp-copy-all-btn', function(){
var codes=$(this).data('codes');
var postId=$(this).data('post-id');
var btnStyle=$(this).data('btn-style');
if(codes){
navigator.clipboard.writeText(codes).then(function(){
if(typeof wcp_ajax!=='undefined'){
$.post(wcp_ajax.ajax_url, {
action: 'wcp_track_button_click',
post_id: postId,
button_style: btnStyle,
nonce: wcp_ajax.nonce
});
}});
}});
$(document).on('click', '.wcp-filter-btn', function(){
var filter=$(this).data('filter');
$('.wcp-filter-btn').removeClass('active');
$(this).addClass('active');
if(filter==='all'){
$('.wcp-card').show();
}else{
$('.wcp-card').hide();
$('.wcp-card[data-type="' + filter + '"]').show();
}});
$(document).on('click', '.wcp-terms-btn', function(){
var terms=$(this).data('terms');
$('#wcp-modal-terms-text').text(terms);
$('#wcp-terms-modal').fadeIn();
});
$(document).on('click', '.wcp-modal-close, .wcp-modal', function(e){
if(e.target===this){
$('#wcp-modal').fadeOut();
}});
})(jQuery);