window.tec=window.tec||{},window.tec.tickets=window.tec.tickets||{},window.tec.tickets.commerce=window.tec.tickets.commerce||{},window.tec.tickets.commerce.square=window.tec.tickets.commerce.square||{},((e,t)=>{"use strict";const{__}=wp.i18n,n={connect:__("Connect with Square","event-tickets"),connecting:__("Connecting...","event-tickets"),reconnect:__("Reconnect Account","event-tickets"),connectError:__("There was an error connecting to Square. Please try again.","event-tickets"),disconnectConfirm:__("Are you sure you want to disconnect from Square?","event-tickets"),disconnectError:__("There was an error disconnecting from Square. Please try again.","event-tickets"),disconnecting:__("Disconnecting...","event-tickets"),disconnect:__("Disconnect from Square","event-tickets")},c="#tec-tickets__admin-settings-tickets-commerce-gateway-disconnect-square",o="#tec-tickets__admin-settings-tickets-commerce-gateway-disconnect-square-dialog",i=()=>{const t=e.querySelector("#tec-tickets__admin-settings-tickets-commerce-gateway-square-container");return t?{connect:t.dataset.connect||n.connect,connecting:t.dataset.connecting||n.connecting,disconnecting:t.dataset.disconnecting||n.disconnecting,reconnect:t.dataset.reconnect||n.reconnect,connectError:t.dataset.connectError||n.connectError,disconnectConfirm:t.dataset.disconnectConfirm||n.disconnectConfirm,disconnectError:t.dataset.disconnectError||n.disconnectError,connectNonce:t.dataset.connectNonce||""}:{...n,connectNonce:""}},r=e=>{e.preventDefault();const n=e.currentTarget,c=i();n.classList.add("loading"),n.innerText=c.connecting,fetch(ajaxurl,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"tec_tickets_commerce_square_connect",_wpnonce:t.localized.connectNonce})}).then((e=>e.json())).then((e=>{e.success&&e.data.url?window.location.href=e.data.url:(alert(c.connectError),n.classList.remove("loading"),n.innerText=c.connect)})).catch((()=>{alert(c.connectError),n.classList.remove("loading"),n.innerText=c.connect}))},s=e=>{e.preventDefault();const t=e.currentTarget,n=i();t.classList.add("loading"),t.innerText=n.connecting;const c=t.dataset.requiredScopes||"";fetch(ajaxurl,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"tec_tickets_commerce_square_connect",_wpnonce:n.connectNonce,scopes:c})}).then((e=>e.json())).then((e=>{e.success&&e.data.url?window.location.href=e.data.url:(alert(n.connectError),t.classList.remove("loading"),t.innerText=n.reconnect)})).catch((()=>{alert(n.connectError),t.classList.remove("loading"),t.innerText=n.reconnect}))},a=t=>{t.preventDefault();const n=e.querySelector(o);n&&(n.style.display="flex")},d=()=>{const t=i(),n=e.querySelector(c),r=e.querySelector(o);r&&(r.style.display="none"),n.classList.add("loading"),n.innerText=t.disconnecting,n.disabled=!0,fetch(ajaxurl,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({action:"tec_tickets_commerce_square_disconnect",_wpnonce:n.dataset.nonce})}).then((e=>e.json())).then((e=>{e.success?window.location.reload():(alert(t.disconnectError),n.classList.remove("loading"),n.innerText=t.disconnect,n.disabled=!1)})).catch((()=>{alert(t.disconnectError),n.classList.remove("loading"),n.innerText=t.disconnect,n.disabled=!1}))},l=t=>{t.preventDefault();const n=e.querySelector(o);n&&(n.style.display="none")},w=()=>{(()=>{const t=e.querySelector("#tec-tickets__admin-settings-tickets-commerce-gateway-connect-square");t&&t.addEventListener("click",r);const n=e.querySelector(c);n&&n.addEventListener("click",a);const i=e.querySelector("#tec-tickets__admin-settings-tickets-commerce-gateway-reconnect-square");i&&i.addEventListener("click",s);const w=e.querySelector(".tec-tickets__admin-settings-tickets-commerce-gateway-disconnect-cancel");w&&w.addEventListener("click",l);const m=e.querySelector(".tec-tickets__admin-settings-tickets-commerce-gateway-disconnect-confirm");m&&m.addEventListener("click",d);const u=e.querySelector(o);u&&u.addEventListener("click",(e=>{e.target===u&&l(e)}))})()};"loading"!==e.readyState?w():e.addEventListener("DOMContentLoaded",w)})(document,window.tec.tickets.commerce.square),window.tec=window.tec||{},window.tec.tickets=window.tec.tickets||{},window.tec.tickets.admin=window.tec.tickets.admin||{},window.tec.tickets.admin.gateway=window.tec.tickets.admin.gateway||{},window.tec.tickets.admin.gateway.square=window.tec.tickets.admin.gateway.square||{},window.tec.tickets.admin.gateway.square.settings={};