/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
/******/ (() => { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ "./src/js/fundraising-campaign.js"
/*!****************************************!*\
  !*** ./src/js/fundraising-campaign.js ***!
  \****************************************/
() {

eval("{;\n(function ($) {\n  // Function to initialize the slider\n  function bpFundraisingCampaignSlider() {\n    // Check if the necessary elements exist\n    if ($('.better-payment .img-wrapper img').length && $('#bp-bgimage').length) {\n      const galleryImages = $('.better-payment .img-wrapper img');\n      const bgImage = $('#bp-bgimage');\n      const imageWrappers = $('.better-payment .img-wrapper');\n      const overlays = $('.better-payment .image_overlay');\n      const imageUrls = galleryImages.map(function () {\n        return $(this).data('bg');\n      }).get();\n\n      // Only proceed if we have image URLs\n      if (imageUrls.length > 0) {\n        let currentIndex = 0;\n        let sliderInterval;\n        const updateBackground = index => {\n          if (!imageUrls[index]) return;\n\n          // Set background image\n          bgImage.css('background-image', `url('${imageUrls[index]}')`);\n\n          // Update overlays and borders\n          imageWrappers.each(function (i) {\n            const $wrapper = $(this);\n            const $overlay = $wrapper.find('.image_overlay');\n            if (i === index) {\n              $overlay.hide();\n              $wrapper.css('border', '2px solid #FBBF24');\n            } else {\n              $overlay.show();\n              $wrapper.css('border', 'none');\n            }\n          });\n\n          // Toggle active class\n          galleryImages.removeClass('active').eq(index).addClass('active');\n        };\n        const startSlider = () => {\n          clearInterval(sliderInterval); // Clear any existing interval\n          sliderInterval = setInterval(() => {\n            currentIndex = (currentIndex + 1) % imageUrls.length;\n            updateBackground(currentIndex);\n          }, 5000);\n        };\n\n        // Manual click handler\n        overlays.each(function (index) {\n          $(this).off('click').on('click', function () {\n            clearInterval(sliderInterval);\n            currentIndex = index;\n            updateBackground(index);\n            startSlider();\n          });\n        });\n        updateBackground(currentIndex);\n        startSlider();\n        return true;\n      }\n    }\n    return false;\n  }\n\n  // Initialize on document ready (for frontend)\n  $(document).ready(function () {\n    $(document).on('click', '.better-payment .bp-tab_button', function () {\n      // Remove active class from all buttons\n      $('.bp-tab_button').removeClass('bp-active');\n\n      // Add active class to the clicked button\n      $(this).addClass('bp-active');\n\n      // Get the tab to show\n      var tabToShow = $(this).data('tab');\n\n      // Hide all tab panes\n      $('.bp-tab_pane').hide();\n\n      // Show the selected tab pane\n      $('#' + tabToShow).show();\n    });\n    function showMoreShowLess() {\n      const $announcementText = $('.bp-announcement');\n      const $learnMoreButtonText = $('.more-btn_text');\n      if ($announcementText.hasClass('active')) {\n        $announcementText.removeClass('active');\n        $learnMoreButtonText.text('Learn More');\n      } else {\n        $announcementText.addClass('active');\n        $learnMoreButtonText.text('Show Less');\n      }\n    }\n    $(document).on('click', '.better-payment .bp-learn_more-btn', function (e) {\n      e.preventDefault(); // Optional: prevents default button behavior\n      showMoreShowLess();\n    });\n    $(document).on('click', '.better-payment .bp-payment_item .bp-option-amount', function () {\n      resetDonateButtonHref();\n      var selectedValue = $(this).val();\n\n      // Set the value in the input field\n      $('.other_amount').val(selectedValue);\n\n      // Manage active_border class\n      $('label[for^=\"amount_\"]').removeClass('active_border'); // remove from all\n      $('label[for=\"' + $(this).attr('id') + '\"]').addClass('active_border'); // add to selected\n    });\n    $(document).on('focus', '.better-payment .bp-payment_form .other_amount', function () {\n      resetDonateButtonHref();\n      $('.bp-option-amount').prop('checked', false);\n      $('label[for^=\"amount_\"]').removeClass('active_border');\n    });\n\n    // Reset donate button href when user selects radio or types custom amount\n    function resetDonateButtonHref() {\n      var $button = $('.bp-donate_btn');\n      var baseHref = $button.attr('href')?.split('?')[0];\n      $button.attr('href', baseHref);\n      $button.data('clicked', false); // allow query string to be added again on next clickensure base is saved for future\n    }\n    $(document).on('change', '.better-payment .bp-donate_amounts .bp-option-amount', function () {\n      resetDonateButtonHref();\n\n      // Remove active class from all labels\n      $('.bp-donate_amounts .bp-radio_label').removeClass('bp-radio_active');\n\n      // Add active class to the label associated with the selected radio\n      $(this).closest('.bp-radio_label').addClass('bp-radio_active');\n\n      // Set the value in the number input field\n      var amount = $(this).data('value');\n      $('.campaign-custom-amount').val(amount);\n    });\n    $(document).on('focus', '.better-payment .campaign-custom-amount', function () {\n      resetDonateButtonHref();\n\n      // Uncheck all radio buttons\n      $('.bp-option-amount').prop('checked', false);\n\n      // Remove active class from all labels\n      $('.bp-radio_label').removeClass('bp-radio_active');\n    });\n\n    // Campaign builder: sync preset amount selection into custom input field\n    $(document).on('change', '.bp-campaign .bp-donate_amounts .bp-option-amount', function () {\n      var amount = $(this).val();\n      $(this).closest('.bp-campaign-donate').find('.campaign-custom-amount').val(amount);\n    });\n\n    // Campaign builder: clear radio selection when user types a custom amount\n    $(document).on('focus', '.bp-campaign .campaign-custom-amount', function () {\n      $(this).closest('.bp-campaign-donate').find('.bp-option-amount').prop('checked', false);\n    });\n\n    // Campaign builder: validate minimum donation amount before navigating\n    $(document).on('click', '.bp-campaign .bp-donate_btn', function (e) {\n      var $campaign = $(this).closest('.bp-campaign');\n      var $notice = $campaign.find('.bp-min-donation-notice');\n      if (!$notice.length) return;\n      var minAmount = parseFloat($notice.data('min')) || 0;\n      if (minAmount <= 0) return;\n      var customVal = parseFloat($campaign.find('.campaign-custom-amount').val());\n      var radioVal = parseFloat($campaign.find('.bp-option-amount:checked').val());\n      var enteredAmount = !isNaN(customVal) && customVal > 0 ? customVal : !isNaN(radioVal) && radioVal > 0 ? radioVal : 0;\n      if (enteredAmount < minAmount) {\n        e.preventDefault();\n        $notice.addClass('is-error');\n      } else {\n        $notice.removeClass('is-error');\n      }\n    });\n\n    // Clear error state when user changes amount selection\n    $(document).on('change', '.bp-campaign .bp-option-amount, input.bp-campaign .campaign-custom-amount', function () {\n      $(this).closest('.bp-campaign').find('.bp-min-donation-notice').removeClass('is-error');\n    });\n    $(document).on('input', '.bp-campaign .campaign-custom-amount', function () {\n      $(this).closest('.bp-campaign').find('.bp-min-donation-notice').removeClass('is-error');\n    });\n    $(document).on('click', '.better-payment .bp-donate_btn', function (e) {\n      var $button = $(this);\n      var selectedRadio = $('.better-payment .bp-option-amount:checked').val();\n      var customAmount = $('.better-payment .campaign-custom-amount').val();\n      var amount = '';\n      var bp_campaign_id = $('.better_payment_campaign_id').val() || '';\n      var bp_campaign_currency = $('.better_payment_campaign_currency').val() || '';\n\n      // Use custom input if provided, else fallback to radio\n      if (customAmount) {\n        amount = customAmount;\n      } else if (selectedRadio) {\n        amount = selectedRadio;\n      }\n\n      // Append or update query parameter\n      if (amount || bp_campaign_id || bp_campaign_currency) {\n        var originalUrl = new URL($button.attr('href'), window.location.origin);\n        if (bp_campaign_currency) {\n          originalUrl.searchParams.set('campaign_currency', bp_campaign_currency);\n        }\n        if (amount) {\n          originalUrl.searchParams.set('payment_amount', amount);\n        }\n        if (bp_campaign_id) {\n          originalUrl.searchParams.set('campaign_id', bp_campaign_id);\n        }\n        $button.attr('href', originalUrl.toString());\n      }\n    });\n\n    // Try to initialize slider\n    if (!bpFundraisingCampaignSlider()) {\n      bpFundraisingCampaignSlider();\n    }\n  });\n\n  // Initialize for Elementor editor\n  $(window).on('elementor/frontend/init', function () {\n    elementorFrontend.hooks.addAction('frontend/element_ready/fundraising-campaign.default', function ($scope) {\n      // Try to initialize slider with a delay to ensure elements are rendered\n      bpFundraisingCampaignSlider();\n    });\n  });\n})(jQuery);\n\n//# sourceURL=webpack://better-payment/./src/js/fundraising-campaign.js?\n}");

/***/ }

/******/ 	});
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module can't be inlined because the eval devtool is used.
/******/ 	var __webpack_exports__ = {};
/******/ 	__webpack_modules__["./src/js/fundraising-campaign.js"]();
/******/ 	
/******/ })()
;