(()=>{"use strict";const t=window.wp.hooks,e=tec.tickets.seating.currency,n=tec.tickets.seating.frontend.ticketsBlock,r=window.tec.tickets.seating.frontend.arModal,o=window.tec.tickets.seating.frontend.ticketsBlockData,i=tec.tickets.seating.frontend.session,{arModalObjectName:c,arModalContentSelector:s,seatSelectionModalObjectName:a}=r;function l(t){return document.getElementById(`tribe-modal-tickets-item-${t}`)||null}function d(t){const r=window[c],o=document.querySelector(s),d=window[a];if(!(r&&o&&d))return console.error("The modal is not currently being used to collect Attendee Registration information."),!1;if(!t.has("tribe_tickets_ar_data"))return console.error("The checkout data does not contain the required data."),!1;const u=JSON.parse(t.get("tribe_tickets_ar_data"));if(!(u instanceof Object&&u.hasOwnProperty("tribe_tickets_tickets")&&u.hasOwnProperty("tribe_tickets_post_id")))return console.error("The checkout data does not contain the required data."),!1;const{tribe_tickets_tickets:k}=u;r.render();const m=r.node;if(!m instanceof HTMLElement)return console.error("The AR modal did not create a valid HTML element."),!1;k.map((t=>function(t){const n=l(t.ticket_id);n?(n.setAttribute("data-seat-labels",t.seat_labels.join(",")),function(t,n,r){const o=t.querySelector(".tribe-tickets__tickets-item-quantity-number-input"),i=function(t){return Number(l(t)?.dataset?.ticketPrice)||0}(n);if(!o||void 0===i)return;o.value=r,o.setAttribute("readonly","readonly"),0===r?t.style.display="none":t.style.removeProperty("display");const c=r*Number(i),s=t.querySelector(".tribe-tickets__tickets-item-total .tribe-amount");s?s.innerText=(0,e.formatValue)(c):console.error("Could not find the amount element for the ticket")}(n,Number(t.ticket_id),t.quantity),function(t){t.querySelectorAll(".tribe-tickets__tickets-item-remove-wrap").forEach((t=>t.remove())),t.querySelectorAll(".tribe-tickets__tickets-item-quantity-remove").forEach((t=>t.remove())),t.querySelectorAll(".tribe-tickets__tickets-item-quantity-add").forEach((t=>t.remove())),t.querySelectorAll(".tribe-tickets__tickets-item-content-title-container").forEach((t=>t.style.gridColumn="1"))}(n)):console.error(`Could not find the ticket element for the ticket with id ${t.ticket_id}`)}(t))),d.hide();const _=()=>{(0,i.setIsInterruptable)(!0),(0,n.cancelReservations)()};return r.on("hide",_),r.on("destroy",_),r._show(),function(t){t.querySelectorAll(".tribe-tickets__attendee-tickets-item-remove").forEach((t=>t.remove()))}(m),function(t){t.querySelector(".tribe-dialog__wrapper")||console.error("Could not find the AR modal wrapper element.")}(m),(0,i.setIsInterruptable)(!1),!0}const{arPageUrl:u}=r;async function k(t){const e=await fetch(u,{method:"POST",body:t});return!!e.redirected&&((0,i.setIsInterruptable)(!1),window.location.href=e.url,!1)}const{ajaxUrl:m,ajaxNonce:_,ACTION_WOO_CART_UPDATE:f}=o;async function w(t){t.append("tribe_tickets_ar","1"),t.append("tribe_tickets_provider","woo");const e=new URL(m);e.searchParams.set("_ajax_nonce",_),e.searchParams.set("action",f);const n=await fetch(e.toString(),{method:"POST",body:t});if(!n.ok)return!1;const r=await n.json();return!(!r||!r?.data?.url||((0,i.setIsInterruptable)(!1),window.location.href=r.data.url,0))}const{isUsingModal:b}=r;(0,t.addFilter)("tec.tickets.seating.checkoutHandler","tec-tickets-plus-seating",(function(t,e){switch(e){case"TECTicketsCommerceModule":case"TEC\\Tickets\\Commerce\\Module":return b?d:k;case"Tribe__Tickets_Plus__Commerce__WooCommerce__Main":return b?d:w;default:return null}})),window.ticketsPlus=window.ticketsPlus||{},window.ticketsPlus.seating=window.ticketsPlus.seating||{},window.ticketsPlus.seating.frontend=window.ticketsPlus.seating.frontend||{},window.ticketsPlus.seating.frontend.ticketsBlock={}})();