(function ($) {
	'use strict';

	$(document).ready(function () {
		// Radio tier selection on frontend
		$(document).on('click', '.drbu-pack', function (e) {
			var $pack = $(this);
			var $container = $pack.closest('.drbu-buy');
			var tierIndex = $pack.data('tier');

			$container.find('.drbu-pack').removeClass('active-tile');
			$pack.addClass('active-tile');
			$pack.find('.drbu-radio').prop('checked', true);

			// Update prices/views if data-v attributes exist
			$container.find('.drbu-price-v, .drbu-ship-v, .drbu-cta-v').each(function () {
				if ($(this).attr('data-v') == tierIndex) {
					$(this).css('display', 'flex').show();
				} else {
					$(this).hide();
				}
			});
		});
	});
})(jQuery);
