/**
 * FoodOrd Shortcodes Admin JavaScript
 */
jQuery(document).ready(function($) {
	// Copy to clipboard functionality
	$('.copy-btn').on('click', function(e) {
		e.preventDefault();
		e.stopPropagation();
		const $btn = $(this);
		const code = $btn.data('code');
		
		// Create temporary input
		const $temp = $('<input class="temp-clipboard-input">');
		$('body').append($temp);
		$temp.val(code).select();
		
		// Copy to clipboard
		document.execCommand('copy');
		$temp.remove();
		
		// Visual feedback
		const originalIcon = $btn.html();
		$btn.addClass('copied');
		$btn.html('<span class="dashicons dashicons-yes"></span>');
		
		setTimeout(function() {
			$btn.removeClass('copied');
			$btn.html(originalIcon);
		}, 2000);
	});
	
	// Prevent details element from affecting other cards
	$('.shortcode-params summary').on('click', function(e) {
		e.stopPropagation();
	});

	// Auto hide only success notices after saving (after 5 seconds)
	const $successNotice = $('.notice.notice-success.is-dismissible');
	if ($successNotice.length > 0) {
		setTimeout(function() {
			$successNotice.fadeOut(500, function() {
				$(this).remove();
			});
		}, 5000);
	}
});
