tec.ticketsPlus=tec.ticketsPlus||{},tec.ticketsPlus.waitlistClassic=tec.ticketsPlus.waitlistClassic||{},((t,e)=>{const i=t(document);e.selectors={editScreen:".tec-tickets-plus-waitlist-metabox__create-container",mainScreen:".tec-tickets-plus-waitlist-metabox__overview",cancelEdit:".tec-tickets-plus-waitlist-metabox__save-cancel",addWaitlist:".tec-tickets-plus-waitlist-metabox__add-ticket",editWaitlist:".tec-tickets-plus-waitlist-metabox__edit",deleteWaitlist:".tec-tickets-plus-waitlist-metabox__delete",saveWaitlist:".tec-tickets-plus-waitlist-metabox__save-waitlist",waitlistIdInEditScreen:'input[name="waitlist_id"]',conditionalTicketInEditScreen:'input[name="ticket-conditional"]:checked',conditionalRSVPInEditScreen:'input[name="rsvp-conditional"]:checked',nonceInEditScreen:'input[name="nonce"]',deleteNonce:'input[name="tec-tickets-plus-waitlist-metabox-delete-nonce"]',parent:"#tec-tickets-plus-waitlist-metabox .inside"},e.i18n={confirmDelete:wp.i18n.__("Are you sure you want to delete this waitlist? This will also delete all the subscribers of this waitlist!","event-tickets-plus")},e.closeEditScreen=s=>{s.preventDefault(),t(s.target).closest(e.selectors.editScreen).hide(),i.find(e.selectors.mainScreen).show()},e.openEditScreen=s=>{s.preventDefault();const a=t(s.target),c=a.data("type")||a.closest(e.selectors.editWaitlist).data("type");a.closest(e.selectors.mainScreen).hide(),i.find(e.selectors.editScreen+'[data-type="'+c+'"]').show()},e.deleteWaitlist=async s=>{s.preventDefault();const a=t(s.target),c=a.data("waitlist-id")||a.closest(e.selectors.deleteWaitlist).data("waitlist-id"),l=i.find(e.selectors.deleteNonce).val();if(!c||!l)return;if(!confirm(e.i18n.confirmDelete))return;const n=new FormData;n.append("action","tec_tickets_plus_waitlist_delete"),n.append("nonce",l),n.append("waitlist_id",c),a.prop("disabled",!0);const o=await fetch(TribeTicketsPlus.ajaxurl,{method:"POST",body:n});if(a.prop("disabled",!1),!o.ok)throw new Error("Failed to submit waitlist form.");const d=await o.json();if(!d?.success)return console.error("Failed to submit waitlist form.",d),!1;i.find(e.selectors.parent).html(d.data.markup)},e.saveWaitlist=async s=>{s.preventDefault();const a=t(s.target),c=a.closest(e.selectors.editScreen);if(!c.length)return;const l=c.find(e.selectors.waitlistIdInEditScreen).val(),n=a.data("type"),o="ticket"===n?c.find(e.selectors.conditionalTicketInEditScreen).val():c.find(e.selectors.conditionalRSVPInEditScreen).val(),d=c.find(e.selectors.nonceInEditScreen).val();if(!o||!d)return;const r=new FormData;r.append("action","tec_tickets_plus_waitlist_save"),r.append("nonce",d),r.append("waitlist_id",l),r.append("conditional",o),r.append("post_id",t("#post_ID").val()),r.append("type","ticket"===n?0:1),a.prop("disabled",!0);const p=await fetch(TribeTicketsPlus.ajaxurl,{method:"POST",body:r});if(a.prop("disabled",!1),!p.ok)throw new Error("Failed to submit waitlist form.");const w=await p.json();if(!w?.success)return console.error("Failed to submit waitlist form.",w),!1;i.find(e.selectors.parent).html(w.data.markup)},e.ready=()=>{i.on("click",e.selectors.cancelEdit,e.closeEditScreen),i.on("click",e.selectors.addWaitlist,e.openEditScreen),i.on("click",e.selectors.editWaitlist,e.openEditScreen),i.on("click",e.selectors.deleteWaitlist,e.deleteWaitlist),i.on("click",e.selectors.saveWaitlist,e.saveWaitlist)},t(e.ready)})(jQuery,tec.ticketsPlus.waitlistClassic),window.ticketsPlus=window.ticketsPlus||{},window.ticketsPlus.waitlist=window.ticketsPlus.waitlist||{},window.ticketsPlus.waitlist.admin=window.ticketsPlus.waitlist.admin||{},window.ticketsPlus.waitlist.admin.metabox={};