(function(){"use strict";const k="premium",w="is-active",b="data-calc-init",p={root:'[data-calc="root"]',output:"[data-calc-output]",input:"[data-calc-input]",slider:"[data-calc-slider]",tier:"[data-calc-tier]",rateLabel:"[data-calc-rate-label]"},q={style:"currency",currency:"USD",minimumFractionDigits:0,maximumFractionDigits:0};function W(t,e,a,o,r){const i=Math.min(1,Math.max(0,a/o));return t+(e-t)*r(i)}function j(t){const{from:e,to:a,duration:o,ease:r,onFrame:i,onDone:n,reducedMotion:c}=t;if(c||o<=0)return i(a),n==null||n(),()=>{};let s=0,l=0,d=!1;const f=E=>{if(d)return;l===0&&(l=E);const h=E-l;if(h>=o){i(a),n==null||n();return}i(W(e,a,h,o,r)),s=requestAnimationFrame(f)};return s=requestAnimationFrame(f),()=>{d=!0,s&&cancelAnimationFrame(s)}}const T="[calc]",g={debug:(...t)=>{},info:(...t)=>{},warn:(...t)=>console.warn(T,...t),error:(...t)=>console.error(T,...t)},H=Object.freeze({standard:{rate:.06,cap:null,aboveRate:.06},premium:{rate:.09,cap:5e4,aboveRate:.06},private:{rate:.12,cap:2e5,aboveRate:.06}}),X=["standard","premium","private"];function z(t){return X.includes(t)}function V(t,e){return t[e]}function G(t){const e=t.querySelector(p.output);if(!e)return g.warn("missing element",p.output,"— skipping root"),null;const a=t.querySelector(p.input);if(!(a instanceof HTMLInputElement))return g.warn("missing text input",p.input,"— skipping root"),null;const o=t.querySelector(p.slider);if(!(o instanceof HTMLInputElement))return g.warn("missing range slider",p.slider,"— skipping root"),null;const r=new Map;for(const n of t.querySelectorAll(p.tier)){const c=n.getAttribute("data-calc-tier");c&&z(c)&&r.set(c,n)}if(r.size===0)return g.warn("no tier buttons",p.tier,"— skipping root"),null;const i=Array.from(t.querySelectorAll(p.rateLabel));return{root:t,output:e,input:a,slider:o,tierButtons:r,rateLabels:i}}function Q(t){for(const[e,a]of t.tierButtons)if(a.classList.contains(w))return e;return k}function M(t,e){for(const[a,o]of t.tierButtons){const r=a===e;o.classList.toggle(w,r),o.setAttribute("aria-pressed",String(r))}}function Y(t){t.min="0",t.max=String(1e3),t.step="1"}const K=t=>1-(1-t)**3,J=new Intl.NumberFormat("en-US",q);function N(t){const e=Number.isFinite(t)?t:0;return J.format(e)}function y(t){const e=t.replace(/[$,\s]/g,"");if(e==="")return null;const a=Number(e);return Number.isFinite(a)?a:null}function A(t){if(!Number.isFinite(t))return 2;const e=Math.floor(t);return Math.min(5e5,Math.max(2,e))}const Z=Math.log(5e5/2);function tt(t){if(t<=0)return 2;if(t>=1e3)return 5e5;const e=t/1e3,a=2*(5e5/2)**e;return A(a)}function et(t){const e=A(t),a=Math.log(e/2)/Z;return Math.round(a*1e3)}function nt(t,e,a=H){if(!Number.isFinite(t)||t<=0)return 0;const{rate:o,cap:r,aboveRate:i}=V(a,e);if(r===null)return t*o;const n=Math.min(t,r)*o,c=Math.max(0,t-r)*i;return n+c}function rt(t){return{tier:t,balance:1e4}}function _(t,e){return{...t,balance:e}}function ot(t,e){return{...t,tier:e}}function C(t){return nt(t.balance,t.tier)}const at="(prefers-reduced-motion: reduce)";function st(t){const e=G(t);if(!e)return null;const{output:a,input:o,slider:r,tierButtons:i}=e;Y(r);let n=rt(Q(e)),c=0,s=null;const l=window.matchMedia(at);let d=l.matches;const f=u=>{c=u,a.textContent=N(u)},E=()=>{s==null||s(),s=null,f(C(n))},h=()=>{s==null||s();const u=C(n);s=j({from:c,to:u,duration:700,ease:K,reducedMotion:d,onFrame:f,onDone:()=>{f(u),s=null}})},L=()=>{o.value=N(n.balance)},S=()=>{r.value=String(et(n.balance))},B=()=>{for(const u of e.rateLabels)u.textContent=n.tier},At=u=>()=>{u!==n.tier&&(n=ot(n,u),M(e,u),B(),h())},x=()=>{const u=tt(Number(r.value));n=_(n,u),L(),E()},P=()=>{h()},O=()=>{const u=y(o.value);u!==null&&(n=_(n,A(u)),S(),E())},v=()=>{const u=y(o.value);if(u===null){L();return}n=_(n,A(u)),L(),S(),h()},D=u=>{u.key==="Enter"&&(u.preventDefault(),v())},F=()=>{d=l.matches},m=[];for(const[u,U]of i){const $=At(u);U.addEventListener("click",$),m.push(()=>U.removeEventListener("click",$))}return r.addEventListener("input",x),m.push(()=>r.removeEventListener("input",x)),r.addEventListener("change",P),m.push(()=>r.removeEventListener("change",P)),o.addEventListener("input",O),m.push(()=>o.removeEventListener("input",O)),o.addEventListener("change",v),m.push(()=>o.removeEventListener("change",v)),o.addEventListener("keydown",D),m.push(()=>o.removeEventListener("keydown",D)),l.addEventListener("change",F),m.push(()=>l.removeEventListener("change",F)),M(e,n.tier),B(),L(),S(),f(0),h(),g.debug("ready",{tier:n.tier,balance:n.balance}),()=>{s==null||s();for(const u of m)u()}}function I(){const t=document.querySelectorAll(p.root);if(t.length===0)return()=>{};const e=[];for(const a of t){if(a.hasAttribute(b))continue;const o=st(a);o&&(a.setAttribute(b,""),e.push(()=>{o(),a.removeAttribute(b)}))}return()=>{for(const a of e)a()}}const it=Object.freeze(Object.defineProperty({__proto__:null,default:()=>{document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>I(),{once:!0}):I()}},Symbol.toStringTag,{value:"Module"})),ct=new Set(["/src/_global.ts","/src/_global.tsx"]),ut=Object.assign({"/src/reserve.ts":it});function lt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function ft(t){const e=[],o=t.split("/").filter(Boolean).map(n=>n.startsWith(":")?(e.push(n.slice(1)),"([^/]+)"):lt(n)),r=o.length===0?"":`/${o.join("/")}`;return{regex:new RegExp(`^${r||"/"}/?$`),paramNames:e}}function dt(t){let e=t.replace(/^\/src/,"").replace(/\.tsx?$/,"");return e.endsWith("/index")&&(e=e.slice(0,-6)),(e===""||e==="/index")&&(e="/"),e.replace(/\[(\w+)\]/g,":$1")}function pt(){const t=[];let e=null,a=null;const o=new Map;for(const[r,i]of Object.entries(ut)){if(ct.has(r)){if(typeof i.default=="function"){if(e&&a)throw new Error(`[viteflow] Duplicate global handlers: ${a} and ${r}`);e=i.default,a=r}continue}if(r.split("/").filter(Boolean).some(f=>f.startsWith("_")))continue;if(typeof i.default!="function"){console.warn(`[viteflow] ${r} has no default export — skipped`);continue}const c=dt(r);if(o.has(c))throw new Error(`[viteflow] Duplicate route "${c}": ${o.get(c)} and ${r}`);o.set(c,r);const{regex:s,paramNames:l}=ft(c),d=c.split("/").filter(Boolean);t.push({pattern:c,regex:s,paramNames:l,handler:i.default,filePath:r,segments:d})}return t.sort((r,i)=>{const n=Math.max(r.segments.length,i.segments.length);for(let c=0;c1&&t.endsWith("/")?t.slice(0,-1):t}function gt(t){const e=new URL(t,"http://localhost"),a=ht(e.pathname),o=e.hash,r=o.startsWith("#")?o.slice(1):o;let i;try{i=decodeURIComponent(r)}catch{i=r}return{path:a,searchParams:e.searchParams,hash:o,id:i}}async function Et(t){const{path:e,searchParams:a,hash:o,id:r}=gt(t),i={params:{},path:e,searchParams:a,hash:o,id:r};if(R)try{await R(i)}catch(n){console.error("[viteflow] global handler error",n)}for(const n of mt){const c=n.regex.exec(e);if(!c)continue;const s={};n.paramNames.forEach((l,d)=>{const f=c[d+1]??"";try{s[l]=decodeURIComponent(f)}catch{s[l]=f}});try{await n.handler({params:s,path:e,searchParams:a,hash:o,id:r})}catch(l){console.error(`[viteflow] handler error in ${n.filePath} (${n.pattern})`,l)}return}console.warn("[viteflow] no route matched for",e)}Et(window.location.pathname+window.location.search+window.location.hash)})(); //# sourceMappingURL=main.js.map