/*
 * 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/).
 */
/******/ (function() { // webpackBootstrap
/******/ 	var __webpack_modules__ = ({

/***/ "./admin/assets/js/components/pixelio_cart_abandon_recovery_more_admin_header.js":
/*!***************************************************************************************!*\
  !*** ./admin/assets/js/components/pixelio_cart_abandon_recovery_more_admin_header.js ***!
  \***************************************************************************************/
/***/ (function() {

eval("jQuery(document).ready(function ($) {\n  $.ajax({\n    url: pixelio_vars.api_is_available,\n    method: 'GET',\n    headers: {\n      'Content-Type': 'application/json',\n      'x-api-key': pixelio_vars.api_key\n    },\n    success: function (data) {\n      if (data.available) {\n        $('#pixelio-cart-abandon-recovery-more-beta-signup-container').show();\n      } else {\n        $('#pixelio-cart-abandon-recovery-more-beta-signup-container').hide();\n      }\n    }\n  });\n\n  /* ------------------------------\r\n     2. FAQ Toggle\r\n  --------------------------------*/\n  $('#pixelio-cart-abandon-recovery-more-beta-faq-toggle').on('click', function (e) {\n    e.preventDefault();\n    $('.pixelio-cart-abandon-recovery-more-beta-faq').toggle();\n  });\n\n  /* ------------------------------\r\n     3. Checkbox Join Beta\r\n  --------------------------------*/\n  $('#pixelio-cart-abandon-recovery-more-join-beta').on('change', function () {\n    $('.pixelio-cart-abandon-recovery-more-beta-preference').toggle(this.checked).trigger('change');\n    if (this.checked) {\n      $('input[name=\"comm_method\"]').prop('checked', false);\n    }\n    $('.pixelio-cart-abandon-recovery-more-beta-extra-fields').hide();\n    $('input[name=\"email_username\"]').hide();\n  });\n\n  /* ------------------------------\r\n     4. Radio Communication Method\r\n  --------------------------------*/\n  $('input[name=\"comm_method\"]').on('change', function () {\n    $('.pixelio-cart-abandon-recovery-more-beta-extra-fields').show();\n    if ($(this).val() === 'email') {\n      $('input[name=\"email_username\"]').show();\n    } else {\n      $('input[name=\"email_username\"]').hide();\n    }\n  });\n\n  /* ------------------------------\r\n     5. Bouton Signup\r\n  --------------------------------*/\n  $('#pixelio-cart-abandon-recovery-more-beta-signup-btn').on('click', function () {\n    const joinBeta = $('#pixelio-cart-abandon-recovery-more-join-beta');\n    if (!joinBeta.is(':checked')) {\n      alert(pixelio_vars.msg_join_beta);\n      return;\n    }\n    const commMethod = $('input[name=\"comm_method\"]:checked');\n    if (!commMethod.length) {\n      alert(pixelio_vars.msg_select_comm);\n      return;\n    }\n    let payload = {\n      preferred_communication: commMethod.val()\n    };\n    if (joinBeta.is(':checked')) {\n      payload.consent_definition = joinBeta.parent().text().trim();\n    }\n    if (commMethod.val() === 'email') {\n      const email = $('input[name=\"email_username\"]').val().trim();\n      if (!email) {\n        alert(pixelio_vars.msg_email_required);\n        return;\n      }\n      payload.email = email;\n    }\n    payload.language = pixelio_vars.language;\n    const btn = $('#pixelio-cart-abandon-recovery-more-beta-signup-btn');\n    btn.prop('disabled', true).text(pixelio_vars.msg_signing_up);\n    $.ajax({\n      url: pixelio_vars.api_signup,\n      method: 'POST',\n      headers: {\n        'Content-Type': 'application/json',\n        'x-api-key': pixelio_vars.api_key\n      },\n      data: JSON.stringify(payload),\n      success: function (data) {\n        if (data.success) {\n          let successMsg = $('<p>').text(pixelio_vars.msg_success).css({\n            fontWeight: 600,\n            color: '#0D367A'\n          });\n          $('.pixelio-cart-abandon-recovery-more-beta-signup-wrapper').append(successMsg);\n          setTimeout(() => {\n            $('.pixelio-cart-abandon-recovery-more-beta-signup-wrapper').hide();\n          }, 5000);\n        } else {\n          let errorMsg = $('<p>').text(pixelio_vars.msg_error).css({\n            color: 'red'\n          });\n          $('.pixelio-cart-abandon-recovery-more-beta-signup-wrapper').append(errorMsg);\n        }\n      },\n      error: function () {\n        alert(pixelio_vars.msg_server_error);\n      },\n      complete: function () {\n        btn.prop('disabled', false).text('Sign Up');\n      }\n    });\n  });\n\n  /* ------------------------------\r\n     6. Récupération des quotas\r\n  --------------------------------*/\n  $.ajax({\n    url: pixelio_vars.api_quota,\n    method: 'GET',\n    headers: {\n      'Content-Type': 'application/json',\n      'x-api-key': pixelio_vars.api_key\n    },\n    success: function (quotas) {\n      const revenusMaxTexte = quotas.revenusMax === -1 ? '∞' : quotas.revenusMax + '€';\n      const emailsMaxTexte = quotas.emailsMax === -1 ? '∞' : quotas.emailsMax;\n      const emailPercent = quotas.emailsMax === -1 ? 100 : Math.min(quotas.emailsSents / quotas.emailsMax * 100, 100);\n      const revenusPercent = quotas.revenusMax === -1 ? 100 : Math.min(quotas.revenus / quotas.revenusMax * 100, 100);\n      $(\"#pixelio-cart-abandon-recovery-more-emails-bar\").css(\"width\", emailPercent + \"%\").closest(\".pixelio-cart-abandon-recovery-more-quota-horizontal\").find(\".pixelio-cart-abandon-recovery-more-quota-label strong\").text(quotas.emailsSents + \" / \" + emailsMaxTexte);\n      $(\"#pixelio-cart-abandon-recovery-more-revenus-bar\").css(\"width\", revenusPercent + \"%\").closest(\".pixelio-cart-abandon-recovery-more-quota-horizontal\").find(\".pixelio-cart-abandon-recovery-more-quota-label strong\").text(quotas.revenus + \"€ / \" + revenusMaxTexte);\n      if (parseFloat(quotas.emailsMax) > -1 && parseInt(quotas.emailsSents) > parseInt(quotas.emailsMax) || parseFloat(quotas.revenusMax) > -1 && parseFloat(quotas.revenus) > parseFloat(quotas.revenusMax)) {\n        $(\".pixelio-cart-abandon-recovery-more-quota-footer\").show();\n      } else {\n        $(\".pixelio-cart-abandon-recovery-more-quota-footer\").hide();\n      }\n    },\n    error: function () {}\n  });\n  function resetOrDisconnect(disconnect) {\n    $.ajax({\n      url: ajaxurl,\n      method: 'POST',\n      data: {\n        action: 'pixelio_reset_first_config',\n        'pixelio_disconnect': disconnect,\n        _ajax_nonce: pixelio_vars.nonce\n      },\n      success: function (response) {\n        if (response.success) {\n          window.location.href = 'admin.php?page=rivio-first-config';\n        } else {\n          alert(pixelio_vars.ajaxError);\n        }\n      },\n      error: function () {\n        alert(pixelio_vars.strings.ajaxError + ' ' + error);\n      }\n    });\n  }\n\n  /* ------------------------------\r\n  \t   7. Reset first config\r\n  \t--------------------------------*/\n  $('#pixelio-cart-abandon-recovery-more-reset-first-config').on('click', function (e) {\n    e.preventDefault();\n    resetOrDisconnect(false);\n  });\n  $('#pixelio-cart-abandon-recovery-more-disconnect-first-config').on('click', function (e) {\n    e.preventDefault();\n    resetOrDisconnect(true);\n  });\n\n  /* ------------------------------\r\n     8. Menu toggle\r\n  --------------------------------*/\n  $('#pixelio-cart-abandon-recovery-more-settings-btn').on('click', function () {\n    $('#pixelio-cart-abandon-recovery-more-submenu').toggle();\n  });\n});\n\n//# sourceURL=webpack://pixelio-cart-abandon-recovery-more/./admin/assets/js/components/pixelio_cart_abandon_recovery_more_admin_header.js?");

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	
/******/ 	// 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__["./admin/assets/js/components/pixelio_cart_abandon_recovery_more_admin_header.js"]();
/******/ 	
/******/ })()
;