!function(t,e){"use strict";e.state={submitActive:!0},e.tribe_rsvp_toggle_actions=function(t){const e=t.hasClass("tribe-block__rsvp__status-button--going")?".tribe-block__rsvp__status-button--not-going":".tribe-block__rsvp__status-button--going",i=t.closest(".tribe-block__rsvp__status").find(e);t.addClass("tribe-active"),t.removeClass("tribe-inactive"),t.attr("disabled","disabled"),i.addClass("tribe-inactive"),i.removeClass("tribe-active"),i.removeAttr("disabled")},e.events.handle_rsvp_response=function(){const i=t(this),s=i.closest(".tribe-block__rsvp"),n=s.find(".tribe-block__rsvp__ticket"),_=n.data("rsvp-id"),r=i.hasClass("tribe-block__rsvp__status-button--going");e.tribe_rsvp_toggle_actions(i);const a={action:"rsvp-form",ticket_id:_,going:r?"yes":"no"};e.tribe_rsvp_loader_start(),t.post(TribeRsvp.ajaxurl,a,(function(t){s.find(".tribe-block__rsvp__message__success").remove();const i=n.find(".tribe-block__rsvp__form");if(i.html(t.data.html),window.tribe_event_tickets_plus){const t=i.find("input.tribe-tickets-quantity");window.tribe_event_tickets_plus.meta.block_set_quantity(t,r)}e.validate_submission(i)||(i.find(".tribe-block__rsvp__submit-button").prop("disabled",!0),e.state.submitActive=!1),e.tribe_rsvp_loader_end()}))},e.events.handle_quantity_change=function(e){e.preventDefault();const i=t(this).parent().find('input[type="number"]'),s=t(this).hasClass("tribe-block__rsvp__number-input-button--plus"),n=i[0].step?Number(i[0].step):1,_=Number(i[0].value);if(s){const t=i[0].max?Number(i[0].max):-1;if("function"==typeof i[0].stepUp)try{if(t<_+n)return;i[0].stepUp()}catch(e){i[0].value=-1===t||t>=_+n?_+n:t}else i[0].value=-1===t||t>=_+n?_+n:t}else{const t=i[0].min?Number(i[0].min):0;if("function"==typeof i[0].stepDown)try{i[0].stepDown()}catch(e){i[0].value=t<=_-n?_-n:t}else i[0].value=t<=_-n?_-n:t}_!==i[0].value&&i.trigger("change")},e.events.handle_quantity_change_value=function(e){e.preventDefault();const i=t(e.target),s=i.attr("max");let n=parseInt(i.val(),10);n=isNaN(n)?0:n,s<n&&(n=s,i.val(s)),e.preventDefault()},e.events.handle_input_focus=function(i){e.state.submitActive||(t(i.target).siblings(".tribe-block__rsvp__submit-button").attr("disabled",!1),e.state.submitActive=!0)},e.tribe_rsvp_loader_start=function(e){t(".tribe-block__rsvp").find(".tribe-block__rsvp__loading").removeClass("tribe-common-a11y-hidden")},e.tribe_rsvp_loader_end=function(e){t(".tribe-block__rsvp").find(".tribe-block__rsvp__loading").addClass("tribe-common-a11y-hidden")},e.validate_submission=function(t){const e=t.find("input.tribe-tickets-quantity"),i=t.find("input.tribe-tickets-full-name"),s=t.find("input.tribe-tickets-email");return i.val().trim().length&&s.val().trim().length&&parseInt(e.val(),10)>0},e.events.handle_submission=function(i){i.preventDefault();const s=t(this).closest(".tribe-block__rsvp__ticket"),n=s.data("rsvp-id"),_=s.find("form"),r=e.validate_submission(_);let a=!0;const o=!!window.tribe_event_tickets_plus;if(o&&(a=window.tribe_event_tickets_plus.meta.validate_meta(_)),r&&a){const i=_.serializeArray();i.push({name:"action",value:"rsvp-process"}),i.push({name:"ticket_id",value:n}),e.tribe_rsvp_loader_start(),t.post(TribeRsvp.ajaxurl,i,(function(t){const i=t.data.remaining;s.find(".tribe-block__rsvp__details .tribe-block__rsvp__availability").replaceWith(t.data.remaining_html),s.find(".tribe-block__rsvp__form").empty(),s.closest(".tribe-block__rsvp").append(t.data.html),0===i&&s.find(".tribe-block__rsvp__status").replaceWith(t.data.status_html),e.tribe_rsvp_loader_end()}))}else r?_.find(".tribe-block__rsvp__message__error").hide():_.find(".tribe-block__rsvp__message__error").show(),o&&a?_.find(".tribe-event-tickets-meta-required-message").hide():_.find(".tribe-event-tickets-meta-required-message").show(),t("html, body").animate({scrollTop:_.offset().top-100},300)},e.bind_events=function(){t(".tribe-block__rsvp__ticket").on("click",".tribe-block__rsvp__status-button--going, .tribe-block__rsvp__status-button--not-going",e.events.handle_rsvp_response).on("click",'button[type="submit"]',e.events.handle_submission).on("click",".tribe-block__rsvp__number-input-button--minus, .tribe-block__rsvp__number-input-button--plus",e.events.handle_quantity_change).on("change keyup",".tribe-tickets-quantity",e.events.handle_quantity_change_value).on("focus",".tribe-tickets-full-name, .tribe-tickets-email",e.events.handle_input_focus)},e.init=function(){t(".tribe-block__rsvp").length&&e.bind_events()},e.init()}(jQuery,{events:{}}),window.tec=window.tec||{},window.tec.tickets=window.tec.tickets||{},window.tec.tickets.rsvpBlock={};