tribe.tickets=tribe.tickets||{},tribe.tickets.iac={},function(e,t){const a=e(document);t.selectors={ticketsPageMeta:".tribe-event-tickets-plus-meta",ticketsPageMetaEmail:".tribe-tickets-meta-email",ticketsPageMetaEmailReSend:".tribe-tickets__tickets-page-attendee-meta-resend-email",ticketsPageMetaEmailReSendTemplate:".tribe-tickets__tickets-page-attendee-meta-resend-email-template",formFieldName:".tribe-tickets__iac-field--name",formFieldEmail:".tribe-tickets__iac-field--email",formFieldNameUniqueErrorTemplate:".tribe-tickets__iac-unique-name-error-template",formFieldEmailUniqueErrorTemplate:".tribe-tickets__iac-unique-email-error-template"},t.ticketsPageIACMetaEmailSaved={},t.attendeeTicketData={},t.ticketsPageMetaEmailReSendCheckboxRemove=function(e){e.closest(t.selectors.ticketsPageMetaEmail).find(t.selectors.ticketsPageMetaEmailReSend).remove()},t.ticketsPageMetaEmailReSendCheckboxAdd=function(e,a){if(e.closest(t.selectors.ticketsPageMetaEmail).find(t.selectors.ticketsPageMetaEmailReSend).length)return;const i=window.wp.template(t.selectors.ticketsPageMetaEmailReSendTemplate.className()+"-"+a);e.after(i())},t.bindEmailChangeCheck=function(a){const i=e(a.target),s=i.closest(t.selectors.ticketsPageMeta).data("attendee-id");t.ticketsPageIACMetaEmailSaved[s]!==i.val().trim()?t.ticketsPageMetaEmailReSendCheckboxAdd(i,s):t.ticketsPageMetaEmailReSendCheckboxRemove(i)},t.bindAttendeeReSendEmail=function(a){a.data("attendee-resend-email")&&a.find(t.selectors.ticketsPageMeta).each((function(){const a=e(this),i=a.data("attendee-id"),s=a.find(t.selectors.ticketsPageMetaEmail).find("input");s.length&&""!==s.val()&&(t.ticketsPageIACMetaEmailSaved[i]=s.val().trim()),s.on("keyup",t.bindEmailChangeCheck)}))},t.bindTicketsPageActions=function(e,a){t.bindAttendeeReSendEmail(a)},t.getInputValuesFromMap=function(e,t){return t.value.trim()},t.getInputValuesToArray=function(e){return e.map(t.getInputValuesFromMap).get()},t.getInputValuesByField=function(e,a){return t.attendeeTicketData[e][a]},t.removeIacUniqueErrorMessage=function(e){e.siblings(tribe.tickets.meta.selectors.formFieldInputHelperError).remove()},t.addIacUniqueErrorMessage=function(e,a){if(e.siblings(tribe.tickets.meta.selectors.formFieldInputHelperError).length)return;let i;"name"===a?i=window.wp.template(t.selectors.formFieldNameUniqueErrorTemplate.className()):"email"===a&&(i=window.wp.template(t.selectors.formFieldEmailUniqueErrorTemplate.className())),e.after(i())},t.loadUniqueMetaValuesPerTicket=function(a,i){const s=e(i),n=s.data("ticket-id");Object.prototype.hasOwnProperty.call(t,n)||(t.attendeeTicketData[n]={});const r=s.find(t.selectors.formFieldEmail+" input"),l=t.getInputValuesToArray(r);t.attendeeTicketData[n].email=l;const c=s.find(t.selectors.formFieldName+" input"),o=t.getInputValuesToArray(c);t.attendeeTicketData[n].name=o},t.loadUniqueMetaValues=function(e,a){a.find(tribe.tickets.meta.selectors.formAttendeeTickets).each(t.loadUniqueMetaValuesPerTicket)},t.bindUniqueMetaValidation=function(e,a,i){if(!i)return;const s=a.val().trim().toLowerCase();if(""===s)return;const n=a.closest(tribe.tickets.meta.selectors.formField);if(!n.hasClass(tribe.tickets.meta.selectors.formFieldUnique.className()))return;let r;const l=a.closest(tribe.tickets.meta.selectors.formAttendeeTickets).data("ticket-id");n.hasClass(t.selectors.formFieldName.className())?r="name":n.hasClass(t.selectors.formFieldEmail.className())&&(r="email");const c=t.getInputValuesByField(l,r);2>c.length||((i=1===c.filter((function(e){return e.toLowerCase()===s})).length)?(a.removeClass(tribe.tickets.meta.selectors.formFieldInputError.className()),t.removeIacUniqueErrorMessage(a)):(a.addClass(tribe.tickets.meta.selectors.formFieldInputError.className()),t.addIacUniqueErrorMessage(a,r)),a.data("valid",i))},t.addListeners=function(){a.on("afterSetup.tribeTicketsPage",t.bindTicketsPageActions),a.on("beforeValidateForm.tribeTicketsMeta",t.loadUniqueMetaValues),a.on("afterValidateField.tribeTicketsMeta",t.bindUniqueMetaValidation)},t.ready=function(){},t.addListeners(),e(t.ready)}(jQuery,tribe.tickets.iac),window.ticketsPlus=window.ticketsPlus||{},window.ticketsPlus.v2=window.ticketsPlus.v2||{},window.ticketsPlus.v2.ticketsIac={};