!function(i){window.llms=window.llms||{},window.llms.checkout=new function(){var m=[],s=[];return this.$checkout_form=i("#llms-product-purchase-form"),this.$confirm_form=i("#llms-product-purchase-confirm-form"),this.$form_sections=!1,this.form_action=!1,this.init=function(){var e=this;i(".llms-checkout-wrapper").length&&this.bind_login(),this.$checkout_form.length?(this.form_action="checkout",this.$form_sections=this.$checkout_form.find(".llms-checkout-section"),this.$checkout_form.on("submit",this,this.submit),i(".llms-password-strength-meter").length&&this.add_before_submit_event({data:LLMS.PasswordStrength,handler:LLMS.PasswordStrength.checkout}),this.bind_coupon(),this.bind_gateways()):this.$confirm_form.length&&(this.form_action="confirm",this.$form_sections=this.$confirm_form.find(".llms-checkout-section"),this.$confirm_form.on("submit",function(){e.processing("start")}))},this.add_before_submit_event=function(e){e.handler&&"function"==typeof e.handler&&(e.data||(e.data=null),m.push(e))},this.add_error=function(e,t){var s="llms-checkout-errors";$err=i("#"+s),$err.length||($err=i('<ul class="llms-notice llms-error" id="'+s+'" />'),i(".llms-checkout-wrapper").prepend($err)),$err.append("<li>"+e+"</li>"),t&&console.error(t)},this.add_gateway=function(e){s.push(e)},this.bind_coupon=function(){var t=this;i('a[href="#llms-coupon-toggle"]').on("click",function(e){e.preventDefault(),i(".llms-coupon-entry").slideToggle(400)}),i("#llms-apply-coupon").on("click",function(e){e.preventDefault(),t.coupon_apply(i(this))}),i("#llms-remove-coupon").on("click",function(e){e.preventDefault(),t.coupon_remove(i(this))})},this.bind_gateways=function(){this.load_gateways(),i('input[name="llms_payment_gateway"]').length||i("#llms_create_pending_order").removeAttr("disabled"),i('input[name="llms_payment_gateway"]').on("change",function(){i('input[name="llms_payment_gateway"]').each(function(){var e=i(this),t=e.closest(".llms-payment-gateway"),s=t.find(".llms-gateway-fields").find("input, textarea, select"),o=e.is(":checked");t[o?"addClass":"removeClass"]("is-selected"),o?(s.removeAttr("disabled"),i(".llms-payment-gateways").trigger("llms-gateway-selected",{id:e.val(),$selector:t})):s.attr("disabled","disabled")})}),i(".llms-payment-gateways").on("llms-gateway-selected",function(e,t){var s=i("#llms_create_pending_order");t.$selector&&t.$selector.find(".llms-gateway-fields .invalid").length?s.attr("disabled","disabled"):s.removeAttr("disabled")})},this.bind_login=function(){i('a[href="#llms-show-login"]').on("click",function(e){e.preventDefault(),i(this).closest(".llms-info,.llms-notice").slideUp(400),i("form.llms-login").slideDown(400)})},this.clear_errors=function(){i("#llms-checkout-errors").remove()},this.coupon_apply=function(e){var s=this,t=i("#llms_coupon_code").val(),o=i(".llms-coupon-messages"),n=o.find(".llms-error"),l=i("form.llms-checkout");LLMS.Spinner.start(l),window.LLMS.Ajax.call({data:{action:"validate_coupon_code",code:t,plan_id:i("#llms-plan-id").val()},beforeSend:function(){n.hide()},success:function(e){if(LLMS.Spinner.stop(l),"error"===e.code){var t=i("<li>"+e.message+"</li>");n.length?n.empty():(n=i('<ul class="llms-notice llms-error" />'),o.append(n)),t.appendTo(n),n.show()}else e.success&&(i(".llms-coupon-wrapper").replaceWith(e.data.coupon_html),s.bind_coupon(),i(".llms-payment-gateways").replaceWith(e.data.gateways_html),s.bind_gateways(),i(".llms-order-summary").replaceWith(e.data.summary_html))}})},this.coupon_remove=function(e){var t=this,s=i("form.llms-checkout");LLMS.Spinner.start(s),window.LLMS.Ajax.call({data:{action:"remove_coupon_code",plan_id:i("#llms-plan-id").val()},success:function(e){LLMS.Spinner.stop(s),e.success&&(i(".llms-coupon-wrapper").replaceWith(e.data.coupon_html),t.bind_coupon(),i(".llms-order-summary").replaceWith(e.data.summary_html),i(".llms-payment-gateways").replaceWith(e.data.gateways_html),t.bind_gateways())}})},this.focus_errors=function(){i("html, body").animate({scrollTop:i("#llms-checkout-errors").offset().top-50},200)},this.load_gateways=function(){for(var e=0;e<=s.length;e++){var t=s[e];"object"==typeof t&&null!==t&&void 0!==t.bind&&"function"==typeof t.bind&&t.bind()}},this.processing=function(e){var t,s;switch(e){case"stop":t="removeClass";break;case"start":default:t="addClass"}"checkout"===this.form_action?s=this.$checkout_form:"confirm"===this.form_action&&(s=this.$confirm_form),s[t]("llms-is-processing"),LLMS.Spinner[e](this.$form_sections)},this.submit=function(e){var o,n=e.data,l=m.length,i=0,r=[],a=0,c=0;e.preventDefault(),n.processing("start"),n.clear_errors();for(var t=0;t<m.length;t++){var s=m[t];s.handler(s.data,function(e){a++,!0===e?c++:"string"==typeof e&&r.push(e)})}o=setInterval(function(){var e=!1,t=!1;if(6e4<=i)t=e=!0;else if(l===a)if(l===c)e=!0,n.$checkout_form.off("submit",n.submit),n.$checkout_form.trigger("submit");else if(r.length){t=e=!0;for(var s=0;s<r.length;s++)n.add_error(r[s]);n.focus_errors()}e&&clearInterval(o),t&&n.processing("stop"),i++},100)},this.init(),this}}(jQuery);
//# sourceMappingURL=../maps/js/llms-form-checkout.min.js.map