!function(){"use strict";const t="data-action",n="https://app.buttons.dev",o=()=>window.actions.apiRoot;function e(t){return"function"==typeof t.onclick}function i(t,n){return window&&window.actions&&window.actions.connectedElements&&window.actions.connectedElements.includes(t)}function s(t,n=!1){if(!t||!t.dataset)return{};const o=t.dataset;if("object"!=typeof o)return{};const{action:e,...i}=o,s=Object.keys(i).reduce(((t,n)=>{let o=i[n];if("string"==typeof o&&["true","false"].includes(o.toLowerCase())&&(o="true"===o.toLowerCase()),"string"==typeof o&&/^[0-9]+$/g.test(o)&&!isNaN(o)&&(o=Number(o)),"string"==typeof o&&o.startsWith("{")&&o.endsWith("}"))try{o=JSON.parse(o)}catch(t){console.error(`Failed to parse param ${n} with value ${o}`)}if("string"==typeof o&&o.startsWith("[")&&o.endsWith("]"))try{o=JSON.parse(o)}catch(t){console.error(`Failed to parse param ${n} with value ${o}`)}return{...t,[n]:o}}),{});if("FORM"===t.tagName.toUpperCase()){const n=new FormData(t);for(let[t,o]of n.entries())s[t]=o}return n?{action:e,...s}:s}function c(t,n,o){console.log("Action error: "+o),"function"==typeof window?.actions?.onError?window.actions.onError(t,n,responseData):"undefined"!=typeof Notyf&&(window.notyf=window.notyf||new Notyf,window.notyf.error("Error!\nPlease try again..."))}function r(t,n){console.log("[Actions] Action clicked: "+t+"("+JSON.stringify(n)+")");const e=`${o()}/api/actions/progressive-execute?`;var i;console.log("Fetching: "+e),fetch(e+(i={action:t,input:JSON.stringify(n),page:window.location.pathname,apiKey:window?.actions?.apiKey||void 0,pid:window?.actions?.projectId,url:window.location.href},Object.keys(i).filter((t=>void 0!==i[t]&&null!==i[t])).map((t=>`${t}=${encodeURIComponent(i[t])}`)).join("&")),{method:"GET",redirect:"manual"}).then((t=>{if("opaqueredirect"===t.type||t.status>=300&&t.status<400){console.log("Received opaque redirect response");const n=t.headers.has("Location")?t.headers.get("Location"):t.url;return console.log("Redirecting to: "+n),window.location.href=n,null}return t.json()})).then((o=>{o&&(o.success?function(t,n,o){console.log("Action executed OK!",o),"function"==typeof window?.actions?.onSuccess?window.actions.onSuccess(t,n,o):"undefined"!=typeof Notyf&&(window.notyf=window.notyf||new Notyf,window.notyf.success("Success!"))}(t,n,o):c(t,n,o))})).catch((o=>{console.error("Fetch error:",o),c(t,n,o.toString())}))}function a(t,n){const o=function(t,n){return`${t}-${JSON.stringify(Object.keys(n).sort())}`}(t,n);return!!window?.knownActions?.[o]}function d(n){let o=n.getAttribute(t);const e=s(n);if("string"!=typeof o||0===o.length){if(o=n.getAttribute("href"),"string"!=typeof o||0===o.trim().length)return null;o=o.trim(),o=o.startsWith("action:")?decodeURIComponent(o.split("action:")[1].trim()):o.startsWith("https://btns.dev/")?decodeURIComponent(o.split("https://btns.dev/")[1].trim()):o.startsWith("https://")||o.startsWith("http://")||o.startsWith("//")||o.startsWith("#")?o.startsWith("#")||!decodeURIComponent(o).includes(" ")||/\.[a-z]{2,}/g.test(decodeURIComponent(o).split(" ")[0])?null:decodeURIComponent(o.split("//").slice(1).join("//")).trim():decodeURIComponent(o).includes(" ")?decodeURIComponent(o):null}return"string"!=typeof o?null:{action:o,params:e}}function l(t){const n=t.target;if(!n)return;const o=d(n);!o||!o.action||"string"!=typeof o.action||o.action.length<=0||(t.preventDefault(),r(o.action,o.params||{}))}function u(){document.querySelectorAll("["+t+"]").forEach((n=>{const o=n.getAttribute(t),c=s(n);if("string"!=typeof o)return;console.log("Element found: ",o);const r=e(n),d=i(n);if(r||d)return void console.log("Element found has click listeners: ",o);a(o,c)||console.log("Element found is not known: ",o);const u="FORM"===n.tagName.toUpperCase()?"submit":"click";n.addEventListener(u,l),window.actions=window.actions||{},window.actions.connectedElements=window.actions.connectedElements||[],window.actions.connectedElements.push(n)})),document.querySelectorAll("[href]").forEach((n=>{const{action:o}=d(n)||{};if("string"!=typeof o)return;console.log("Element found: ",o);const s=e(n),c=i(n);if(s||c)return void console.log("Element found has click listeners: ",o);n.removeAttribute("href"),n.setAttribute(t,o),n.style.cursor="pointer";const r="FORM"===n.tagName.toUpperCase()?"submit":"click";n.addEventListener(r,l),window.actions=window.actions||{},window.actions.connectedElements=window.actions.connectedElements||[],window.actions.connectedElements.push(n)}))}function f(t){console.log("Initializing actions with params: ",t),window.actions=t||{},window.actions.apiRoot=t&&"string"==typeof t.apiRoot?t.apiRoot:n,window.actions.projectId=t&&"string"==typeof t.projectId?t.projectId:void 0,window.actions.showNotifications=!0,window.actions.exec=r,window.actions.clickHandler=l;const o=Array.from(document.querySelectorAll('script[src*=".buttons.dev"]')).filter((t=>t.src.includes("cdn")))[0]||null;if(o){const t=o.src;if(t.includes("pid=")){const t=o.src.split("pid=")[1].split("&")[0];if(!window.actions.projectId&&t&&t.length>0){const n="project_";window.actions.projectId=t.startsWith(n)?t:n+t}}(t.toLowerCase().includes("shownotifications=false")||t.toLowerCase().includes("shownotifications=0"))&&(window.actions.showNotifications=!1)}!function(){if(window?.actions?.showNotifications){const t=document.head||document.getElementsByTagName("head")[0],n=document.createElement("link");n.rel="stylesheet",n.href="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.css",t.appendChild(n);const o=document.createElement("script");o.src="https://cdn.jsdelivr.net/npm/notyf@3/notyf.min.js",t.appendChild(o)}}(),u(),function(t){const n=document;new MutationObserver((function(n,o){for(let o of n)"childList"===o.type&&o.addedNodes.length>0&&t(o.addedNodes)})).observe(n,{childList:!0,subtree:!0})}(u)}var w;"loading"===document.readyState?document.addEventListener("DOMContentLoaded",(function(){f(w)})):f(w)}();