@aifeatures/react 0.5.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +22 -4
- package/dist/index.d.ts +22 -4
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var ct=Object.defineProperty;var ln=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var dn=Object.prototype.hasOwnProperty;var pn=(e,t)=>{for(var r in t)ct(e,r,{get:t[r],enumerable:!0})},fn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of cn(t))!dn.call(e,o)&&o!==r&&ct(e,o,{get:()=>t[o],enumerable:!(n=ln(t,o))||n.enumerable});return e};var mn=e=>fn(ct({},"__esModule",{value:!0}),e);var pr={};pn(pr,{AccountLogin:()=>Be,AccountOrders:()=>ut,AccountPage:()=>un,AddToCartButton:()=>Ht,AifeaturesCaptcha:()=>Rt,BuyButton:()=>Wt,CartCheckoutButton:()=>Zt,MARKET_COUNTRIES:()=>st,MAX_CART_LINES:()=>St,OrderConfirmation:()=>Qt,PlanPicker:()=>Xt,ProductPrice:()=>Ft,SubscriptionList:()=>ze,VariantPicker:()=>jt,ZERO_DECIMAL_CURRENCIES:()=>pt,applySelectionToUrl:()=>Ze,formatPrice:()=>z,getOptions:()=>we,getVariants:()=>be,isMultiVariant:()=>Re,isValueAvailable:()=>Ye,isValueInCatalog:()=>We,planRecurringAmount:()=>Ct,reanchorSelection:()=>He,resolveVariant:()=>ke,searchFromSelection:()=>Me,selectedImages:()=>Ae,selectedValues:()=>ft,selectionFromSearch:()=>Ge,useCart:()=>ye,useCartCheckout:()=>ot,useCartItems:()=>it,useCartSummary:()=>qt,useCheckout:()=>nt,useMarket:()=>Bt,useProduct:()=>ve,useSession:()=>Ie,valueSlug:()=>pe,variantPriceRange:()=>Je});module.exports=mn(pr);var Ne=require("react"),xt=require("@marsidev/react-turnstile"),dt=require("react/jsx-runtime");function Rt({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=(0,Ne.useState)(null),[f,y]=(0,Ne.useState)(!0);return(0,Ne.useEffect)(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(u=>u.json()).then(u=>{l(u.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),f||!i?null:(0,dt.jsx)("div",{className:o,children:(0,dt.jsx)(xt.Turnstile,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}var ce=require("react"),je=[1e3,3e3];function ve(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=(0,ce.useState)(null),[l,f]=(0,ce.useState)(!0),[y,u]=(0,ce.useState)(null),[v,c]=(0,ce.useState)(0),x=(0,ce.useRef)(e);(0,ce.useEffect)(()=>{let p=!1,A;f(!0),u(null),x.current!==e&&(x.current=e,i(null));let w=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let P=await a.json().catch(()=>null);if(!p)if(!a.ok||!P){if(a.status>=500&&b<je.length){A=setTimeout(()=>w(b+1),je[b]);return}u(P?.error??`Request failed (${a.status})`),i(null),f(!1)}else i(P),f(!1)}).catch(a=>{if(!p){if(b<je.length){A=setTimeout(()=>w(b+1),je[b]);return}u(a instanceof Error?a.message:"Failed to load product"),f(!1)}})};return w(0),()=>{p=!0,A&&clearTimeout(A)}},[e,r,n,v]);let k=(0,ce.useCallback)(()=>c(p=>p+1),[]);return{product:o,loading:l,error:y,refresh:k}}var pt=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function z(e,t,r){let n=pt.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function be(e){return e.variants??[]}function we(e){return e.options??[]}function Re(e){return we(e).length>0}function Ke(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ke(e,t){let r=Object.keys(t);return e.find(n=>{let o=n.option_values;return o.length!==r.length?!1:o.every(i=>t[i.option_id]===i.value_id)})??null}function Ye(e,t,r,n){return e.some(o=>{let i=Ke(o);if(i[r]!==n)return!1;for(let[l,f]of Object.entries(t))if(l!==r&&i[l]!==f)return!1;return!0})}function We(e,t,r){return e.some(n=>Ke(n)[t]===r)}function He(e,t,r,n){let o={[r]:n};for(let[l,f]of Object.entries(t)){if(l===r)continue;e.some(u=>{let v=Ke(u);return v[r]===n&&v[l]===f})&&(o[l]=f)}return e.some(l=>{let f=Ke(l);return Object.entries(o).every(([y,u])=>f[y]===u)})?o:{[r]:n}}function Je(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function ft(e,t){let r={};for(let n of we(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i&&(r[n.title]=i.value)}return r}function pe(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ge(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((i,l)=>{n.has(pe(l))||n.set(pe(l),i)});let o={};for(let i of we(e)){let l=pe(i.title);if(l.length===0)continue;let f=n.get(l);if(f===void 0)continue;let y=pe(f);if(y.length===0)continue;let u=i.values.find(v=>pe(v.value)===y);u&&(o[i.id]=u.id)}return o}function Me(e,t){let r={};for(let[n,o]of Object.entries(ft(e,t))){let i=pe(n),l=pe(o);i.length===0||l.length===0||(r[i]=l)}return r}function Ae(e,t){let r=[];for(let n of we(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i?.images?.length&&r.push(...i.images)}return r.length>0?r:e.images??[]}function Ze(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of we(e)){let o=pe(n.title);o.length!==0&&r.searchParams.delete(o)}for(let[n,o]of Object.entries(Me(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}var oe=require("react");var gt="aifeatures_cart",yt="aifeatures_market",At="aifeatures_cart_cleared";var mt="aifeatures:cart-storage",Ve=new Map;function qe(e){if(Ve.has(e))return Ve.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Oe(e,t){if(typeof window>"u"){Ve.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Ve.delete(e)}catch{Ve.set(e,t)}gn(e)}function gn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(mt,{detail:{key:e}}))}catch{}}function Qe(e,t){if(typeof window>"u")return()=>{};let r=o=>{(o.key===e||o.key===null)&&t()},n=o=>{o.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(mt,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(mt,n)}}function yn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[l,f]of Object.entries(t.selection))typeof f=="string"&&(n[l]=f);let o=typeof t.display=="object"&&t.display!==null?t.display:{},i={name:typeof o.name=="string"?o.name:"",variantTitle:typeof o.variantTitle=="string"?o.variantTitle:null,image:typeof o.image=="string"?o.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:i}}function Ce(){let e=qe(gt);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let o of t){let i=yn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function fe(e){Oe(gt,JSON.stringify(e))}function Ot(e){return Qe(gt,e)}function Tt(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of Ce()){let o=t.get(n.variantId);if(o===void 0){r.push(n);continue}let i=n.quantity-o;i>0&&r.push({...n,quantity:i})}fe(r)}function ne(){let e=qe(yt);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function Lt(e){Oe(yt,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function Te(e){return Qe(yt,e)}function It(e){let t=[],r=qe(At);if(r)try{let o=JSON.parse(r);Array.isArray(o)&&(t=o.filter(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(o=>o.ts>n),t.some(o=>o.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Oe(At,JSON.stringify(t)),!0)}var Xe="aifeatures_session",bt=null;function Et(){return bt}function bn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.token!="string"||t.token.length===0)return null;let r=null;if(typeof t.customer=="object"&&t.customer!==null){let n=t.customer;typeof n.email=="string"&&n.email.length>0&&(r={email:n.email,name:typeof n.name=="string"?n.name:null})}return{token:t.token,customer:r}}function Pe(){let e=qe(Xe);if(!e)return null;try{return bn(JSON.parse(e))}catch{return null}}function Ut(){return Pe()?.token??null}function et(e){bt=null,Oe(Xe,JSON.stringify(e))}function me(e){bt=e??null,Oe(Xe,null)}function Nt(e){return Qe(Xe,e)}var hn=1500;function $e(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function tt(e,t){return!("requestId"in e)||e.requestId===t}function ht(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;y?.type==="aifeatures:test-checkout-ack"&&tt(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),hn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function Mt(e){if(window.self!==window.top)try{return window.top.location.href=e,"navigating"}catch{if(window.open(e,"_blank"))return"stayed"}return window.location.href=e,"navigating"}function nt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,oe.useState)(!1),[o,i]=(0,oe.useState)(null),[l,f]=(0,oe.useState)(null),y=(0,oe.useRef)(!1),u=(0,oe.useRef)(null);return(0,oe.useEffect)(()=>{let c=x=>{x.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",c),()=>window.removeEventListener("pageshow",c)},[]),(0,oe.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let c=x=>{if(x.source!==window.parent)return;let k=x.data;if(k?.type!=="aifeatures:test-checkout-ack"||k.status!=="failed")return;let p=u.current;p===null||!tt(k,p)||(u.current=null,i(typeof k.error=="string"&&k.error?k.error:"The test purchase could not be created."),y.current=!1,n(!1))};return window.addEventListener("message",c),()=>window.removeEventListener("message",c)},[]),{startCheckout:(0,oe.useCallback)(async({productId:c,variantId:x,quantity:k,amount:p,metadata:A,successUrl:w,cancelUrl:b,customerEmail:a,planId:P,expectedUnitAmount:_,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),f(null),P!==void 0){let d=Ut();if(d)try{let m=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:P,...x!==void 0?{variant_id:x}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.text().catch(()=>""),h=null;try{h=g?JSON.parse(g):null}catch{h=null}if(m.ok){if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Mt(h.url)==="stayed"&&(y.current=!1,n(!1));return}let C=m.status===404&&g.trim()==="";if(m.status===401||C)me();else{i(h?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}}catch(m){i(m instanceof Error?m.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=P===void 0?ne():null,m=await fetch(`${t}/v1/p/${c}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...x!==void 0?{variant_id:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{plan_id:P}:{},...A!==void 0?{metadata:A}:{},...a!==void 0?{customer_email:a}:{},..._!==void 0&&s!==void 0&&P===void 0?{expected_unit_amount:_,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.json().catch(()=>null);if(!m.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){f({currentUnitAmount:g.current_unit_amount,currency:g.currency}),i(`The price has changed to ${z(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(g?.code==="preview_domain"){let h=$e();if(u.current=h,await ht({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{planId:P}:{},...a!==void 0?{customerEmail:a}:{},...A!==void 0?{metadata:A}:{}},h))return;u.current=null}i(g?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Mt(g.url)==="stayed"&&(y.current=!1,n(!1))}catch(d){i(d instanceof Error?d.message:"Checkout failed"),y.current=!1,n(!1)}}},[t]),loading:r,error:o,priceChange:l}}var ge=require("react");var St=20;function Vt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function ye(){let[e,t]=(0,ge.useState)([]),[r,n]=(0,ge.useState)(!1);(0,ge.useEffect)(()=>{let u=()=>t(Ce());return u(),n(!0),Ot(u)},[]);let o=(0,ge.useCallback)(u=>{let v=Ce(),c=Vt(u.quantity);return v.find(k=>k.variantId===u.variantId)?(fe(v.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):v.length>=St?{ok:!1,reason:"cart_full"}:(fe([...v,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=(0,ge.useCallback)(u=>{fe(Ce().filter(v=>v.variantId!==u))},[]),l=(0,ge.useCallback)((u,v)=>{let c=Ce();if(v<=0){fe(c.filter(k=>k.variantId!==u));return}let x=Vt(v);fe(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),f=(0,ge.useCallback)(()=>{fe([])},[]),y=e.reduce((u,v)=>u+v.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:f}}var G=require("react");var rt={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},Sn={...rt,inStock:!0,status:"error"};function vn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function it(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=ye(),[o,i]=(0,G.useState)({}),[l,f]=(0,G.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=(0,G.useState)(!0),[v,c]=(0,G.useState)(null),[x,k]=(0,G.useState)(0),p=(0,G.useRef)(new Set),A=(0,G.useMemo)(()=>JSON.stringify(r.map(_=>[_.productId,_.variantId,_.selection])),[r]),w=(0,G.useCallback)(()=>k(_=>_+1),[]);(0,G.useEffect)(()=>Te(w),[w]),(0,G.useEffect)(()=>{if(!n)return;if(r.length===0){i({}),f({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let _=!1;u(!0);let s=r,d=[...new Set(s.map(g=>g.productId))],m=async g=>{let h=new Map;return await Promise.all(d.map(async C=>{try{let S=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${g?`?country=${encodeURIComponent(g)}`:""}`);if(S.status===404){h.set(C,{kind:"not_found"});return}if(!S.ok){h.set(C,{kind:"error",message:`Request failed (${S.status})`});return}let R=await S.json();h.set(C,{kind:"ok",product:R})}catch(S){h.set(C,{kind:"error",message:S instanceof Error?S.message:"Failed to load product"})}})),h};return(async()=>{let g=ne(),h=await m(g);if(g){let T=[...h.values()].filter(V=>V.kind==="ok"),M=T.filter(V=>V.product.base_currency);M.length>0&&M.length<T.length&&(h=await m(null))}if(_)return;let C=null,S=null,R=null;for(let T of d){let M=h.get(T);!M||M.kind!=="ok"||(C===null&&M.product.shipping_rates&&(C=M.product.shipping_rates),S===null&&M.product.free_shipping_over!=null&&(S=M.product.free_shipping_over),R===null&&M.product.shipping_countries&&(R=M.product.shipping_countries))}let O={},$=new Map,J=null;for(let T of s){let M=h.get(T.productId);if(!M||M.kind==="error"){O[T.variantId]=Sn,M&&J===null&&(J=M.message);continue}if(M.kind==="not_found"){O[T.variantId]=rt;continue}let{product:V}=M;if(!V.active||V.purchasable===!1){O[T.variantId]=rt;continue}let te=V.variants??[],q=te.find(ie=>ie.id===T.variantId)??null,Y=T.variantId;if(!q){let ie=ke(te,T.selection);if(!ie){O[T.variantId]=rt;continue}let _t=$.get(T.variantId)??{};_t.reanchorTo={variantId:ie.id,selection:vn(ie)},$.set(T.variantId,_t),p.current.add(ie.id),q=ie,Y=ie.id}let N=Ae(V,T.selection)[0]??null,E={image:N,unitAmount:q.unit_amount,currency:q.currency,baseCurrency:V.base_currency??null,inStock:q.in_stock,available:q.available,maxQuantity:V.max_quantity,pdpSearch:Me(V,T.selection),status:p.current.has(Y)?"reanchored":"ok"};O[T.variantId]=E,O[Y]=E;let F=$.get(T.variantId)??{};F.display={name:V.name,variantTitle:q.title,image:N},$.set(T.variantId,F)}let B=new Set(s.map(T=>T.variantId));for(let T of[...p.current])!B.has(T)&&!(T in O)&&p.current.delete(T);if($.size>0){let T=Ce(),M=[],V=new Map,te=!1;for(let q of T){let Y=$.get(q.variantId),N={...q};Y?.reanchorTo&&(N.variantId=Y.reanchorTo.variantId,N.selection=Y.reanchorTo.selection,te=!0),Y?.display&&(N.display.name!==Y.display.name||N.display.variantTitle!==Y.display.variantTitle||N.display.image!==Y.display.image)&&(N.display=Y.display,te=!0);let E=V.get(N.variantId);if(E){E.quantity+=N.quantity,te=!0;continue}M.push(N),V.set(N.variantId,N)}te&&fe(M)}_||(i(O),f({shippingRates:C,freeShippingOver:S,shippingCountries:R}),c(J),u(!1))})(),()=>{_=!0}},[n,A,t,x]);let b=(0,G.useMemo)(()=>r.map(_=>{let s=o[_.variantId];return s?{..._,...s,image:s.image??_.display.image}:{..._,image:_.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:P}=(0,G.useMemo)(()=>{let _=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(_+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:_,currency:s}},[b]);return{lines:b,subtotal:a,currency:P,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:v,refresh:w}}var Z=require("react");var kn=2e3;function qt(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=ye(),[l,f]=(0,Z.useState)(null),[y,u]=(0,Z.useState)(!1),[v,c]=(0,Z.useState)(null),[x,k]=(0,Z.useState)(null),[p,A]=(0,Z.useState)(0);(0,Z.useEffect)(()=>(k(ne()),Te(()=>k(ne()))),[]);let w=(0,Z.useMemo)(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=(0,Z.useCallback)(()=>A(s=>s+1),[]),a=(0,Z.useRef)(0),P=(0,Z.useRef)(!1),_=(0,Z.useRef)("idle");return(0,Z.useEffect)(()=>{if(!i)return;if(o.length===0){f(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,m=!1,g,h=P.current?r:0;P.current=!0,_.current=_.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{u(!0);try{let S=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:d.signal,body:JSON.stringify({items:o.map(O=>({variant_id:O.variantId,quantity:O.quantity})),...x?{country:x}:{},...n?{shipping_option:n}:{}})});if(m||s!==a.current)return;if(!S.ok){if(S.status===429){let O=_.current==="idle";O&&(g=setTimeout(()=>{m||s!==a.current||(_.current="pending",A($=>$+1))},kn)),c(O?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else c(`Could not price this cart (${S.status})`);return}let R=await S.json();if(m||s!==a.current)return;f({currency:R.currency,subtotal:R.subtotal,shipping:R.shipping?{options:R.shipping.options.map(O=>({label:O.label,amount:O.amount,undiscountedAmount:O.undiscounted_amount})),selectedAmount:R.shipping.selected_amount,selectedLabel:R.shipping.selected_label,freeShippingOver:R.shipping.free_shipping_over,freeShippingCurrency:R.shipping.free_shipping_currency,thresholdMet:R.shipping.threshold_met,collectsAddress:R.shipping.collects_address}:null,total:R.total,totalIsFinal:R.total_is_final,tax:R.tax??null,unavailableVariantIds:R.unavailable_variant_ids}),c(null)}catch(S){if(m||d.signal.aborted||s!==a.current)return;c(S instanceof Error?S.message:"Could not price this cart")}finally{!m&&s===a.current&&u(!1)}},h);return()=>{m=!0,clearTimeout(C),g!==void 0&&clearTimeout(g),d.abort()}},[i,w,x,t,r,n,p]),{summary:l,loading:y,error:v,refresh:b}}var re=require("react");function ot(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,re.useState)(!1),[o,i]=(0,re.useState)(null),[l,f]=(0,re.useState)(null),[y,u]=(0,re.useState)(null),v=(0,re.useRef)(!1),c=(0,re.useRef)(null);return(0,re.useEffect)(()=>{let k=p=>{p.persisted&&(v.current=!1,n(!1))};return window.addEventListener("pageshow",k),()=>window.removeEventListener("pageshow",k)},[]),(0,re.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let k=p=>{if(p.source!==window.parent)return;let A=p.data;if(A?.type!=="aifeatures:test-checkout-ack"||A.status!=="failed")return;let w=c.current;w===null||!tt(A,w)||(c.current=null,i(typeof A.error=="string"&&A.error?A.error:"The test purchase could not be created."),v.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:(0,re.useCallback)(async(k,{successUrl:p,cancelUrl:A,customerEmail:w,metadata:b,shippingOption:a}={})=>{if(!v.current){v.current=!0,n(!0),i(null),f(null),u(null);try{let P=ne(),_=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:k.map(d=>({variant_id:d.variantId,quantity:d.quantity,...typeof d.unitAmount=="number"&&typeof d.currency=="string"?{expected_unit_amount:d.unitAmount,expected_currency:d.currency}:{}})),...P!==null?{country:P}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...w!==void 0?{customer_email:w}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:A??window.location.href})}),s=await _.json().catch(()=>null);if(!_.ok){if(s?.code==="shipping_option_unavailable"&&typeof s.requested=="string"&&Array.isArray(s.available)){u({requested:s.requested,available:s.available,currency:typeof s.currency=="string"?s.currency:""}),v.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let m of s.items)m&&typeof m.variant_id=="string"&&(d[m.variant_id]=m);f(d),v.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=$e();if(c.current=d,await ht({items:k.map(g=>({productId:g.productId,variantId:g.variantId,quantity:g.quantity})),...w!==void 0?{customerEmail:w}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${_.status})`),v.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),v.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=s.url;return}catch{if(window.open(s.url,"_blank")){v.current=!1,n(!1);return}}window.location.href=s.url}catch(P){i(P instanceof Error?P.message:"Checkout failed"),v.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}var he=require("react");var st=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function $t(e){return e?st.find(t=>t.country===e.toUpperCase())?.currency??null:null}var Dt=new Map;function Cn(e){let t=Dt.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),Dt.set(e,t)),t}function Bt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,he.useState)(null),[o,i]=(0,he.useState)(!1),[l,f]=(0,he.useState)(null);(0,he.useEffect)(()=>{let c=()=>n(ne());return c(),i(!0),Te(c)},[]),(0,he.useEffect)(()=>{let c=!1;return Cn(t).then(x=>{c||f(x)}),()=>{c=!0}},[t]);let y=(0,he.useCallback)(c=>{Lt(c)},[]),u=$t(l),v=o&&u!==null&&u!==$t(r);return{market:r,suggestedCountry:l,setMarket:y,markets:st,shouldPrompt:v}}var Le=require("react/jsx-runtime"),wn={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function Ft({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:f,loading:y}=ve(e,{apiUrl:r});if(y||!f)return null;let u=be(f),v=t!==void 0?u.find(x=>x.id===t)??null:f.options.length===0?u[0]??null:null;if(v){if(v.unit_amount===null)return null;let x=v.compare_at_amount!==null&&v.compare_at_amount>v.unit_amount;return(0,Le.jsxs)("span",{className:o,style:i,children:[x&&(0,Le.jsx)("span",{className:l,style:l?void 0:wn,children:z(v.compare_at_amount,v.currency,n)}),z(v.unit_amount,v.currency,n)]})}let c=Je(u);return c?(0,Le.jsx)("span",{className:o,style:i,children:c.min===c.max?z(c.min,f.currency,n):`${z(c.min,f.currency,n)} \u2013 ${z(c.max,f.currency,n)}`}):f.unit_amount===null?null:(0,Le.jsx)("span",{className:o,style:i,children:z(f.unit_amount,f.currency,n)})}var ae=require("react");var se=require("react/jsx-runtime"),Pn={marginBottom:"0.75rem"},_n={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},xn={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Rn={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},An={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},zt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},On={...zt,cursor:"pointer"},Tn=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Ln=e=>Tn.test(e),In={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},En={display:"block",width:"1.5rem",height:"1.5rem",maxWidth:"100%",maxHeight:"100%",boxSizing:"border-box",borderRadius:3,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f3f4f6",border:"1px solid rgba(0, 0, 0, 0.2)"},Un="linear-gradient(to top right, transparent calc(50% - 2px), rgba(0,0,0,0.55) calc(50% - 2px), rgba(255,255,255,0.95) calc(50% - 1px), rgba(255,255,255,0.95) calc(50% + 1px), rgba(0,0,0,0.55) calc(50% + 1px), transparent calc(50% + 2px))";function jt({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:f,optionClassName:y,optionLabelClassName:u,valueClassName:v,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[A,w]=(0,ae.useState)(r??{}),b=p?r:A,[a,P]=(0,ae.useState)(()=>new Set),_=h=>P(C=>C.has(h)?C:new Set(C).add(h));(0,ae.useEffect)(()=>{P(h=>h.size===0?h:new Set)},[e]);let s=(0,ae.useRef)(!1);(0,ae.useEffect)(()=>{if(!n||p||s.current||e.length===0||typeof window>"u"||(s.current=!0,Object.keys(A).length>0))return;let h=Ge({options:e},window.location.search);Object.keys(h).length!==0&&(w(h),o?.(h))},[n,p,e]);let d=(0,ae.useMemo)(()=>e.length>0?t.filter(h=>h.option_values.length===e.length):t,[t,e]),m=(0,ae.useRef)(void 0);if((0,ae.useEffect)(()=>{let h=ke(d,b),C=h?.id??null;m.current!==C&&(m.current=C,i?.(h))},[d,b]),e.length===0)return null;let g=(h,C)=>{let S=He(d,b,h,C);p||(w(S),n&&Ze({options:e},S)),o?.(S)};return(0,se.jsx)("div",{className:l,style:f,children:e.map(h=>(0,se.jsxs)("div",{className:y,style:y?void 0:Pn,children:[(0,se.jsx)("span",{className:u,style:u?void 0:_n,children:h.title}),(0,se.jsx)("div",{style:xn,children:h.values.map(C=>{let S=b[h.id]===C.id,R=Ye(d,b,h.id,C.id),O=R||We(d,h.id,C.id),$=[v,S?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,J=C.swatch??null,B=J&&!a.has(J)?J:null,T=B?Ln(B):!1,M=v?void 0:{...Rn,...S?An:{},...R?{}:O?On:zt,...B?{...In,textDecoration:"none"}:{}},V=R?C.value:`${C.value} \u2014 unavailable with your current selection`;return(0,se.jsx)("button",{type:"button",className:$,style:M,disabled:!O,"aria-pressed":S,"aria-label":B?V:void 0,title:B?V:void 0,"data-selected":S?"true":void 0,"data-available":R?"true":"false","data-swatch":B?T?"hex":"image":void 0,onClick:()=>g(h.id,C.id),children:B?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)("span",{"aria-hidden":"true",className:k,style:k?void 0:{...En,...T?{background:B}:{},...T&&R?{}:{backgroundImage:[...R?[]:[Un],...T?[]:[`url(${JSON.stringify(B)})`]].join(", ")}}}),T?null:(0,se.jsx)("img",{src:B,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>_(B)})]}):C.value},C.id)})})]},h.id))})}var Yt=require("react");var W=require("react/jsx-runtime"),Nn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Mn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function Kt(){return(0,W.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,W.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,W.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,W.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Wt({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,apiUrl:u,disabled:v,className:c,style:x,errorClassName:k,spinner:p=!0,children:A}){let{product:w,loading:b,error:a,refresh:P}=ve(e,{apiUrl:u}),{startCheckout:_,loading:s,error:d,priceChange:m}=nt({apiUrl:u});(0,Yt.useEffect)(()=>{m&&P()},[m,P]);let g=w!==null&&!w.payments_ready,h=w!==null&&!w.active,C=w!==null&&w.purchasable===!1,S=w!==null&&Re(w),R=w!==null?be(w):[],O=t!==void 0?R.find(E=>E.id===t)??null:!S&&R.length===1?R[0]:null,$=S&&!O,J=O!==null&&!O.in_stock,B=n??void 0,T=w?.subscription??null,M=T!==null&&T.required&&!T.ready,V=T!==null&&T.required&&T.ready&&B===void 0,te=!!v||b||!w||g||h||C||M||V||$||J||s,q;s?q=(0,W.jsxs)(W.Fragment,{children:[p&&(0,W.jsx)(Kt,{}),"Processing\u2026"]}):b?q=(0,W.jsxs)(W.Fragment,{children:[p&&(0,W.jsx)(Kt,{}),A??"Buy now"]}):g?q="Payments not set up":h||C?q="Unavailable":M?q="Currently unavailable":V?q="Select a plan":$?q="Select options":J?q="Out of stock":A!==void 0?q=A:B!==void 0?q="Subscribe":q="Buy now";let Y=d??a;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)("button",{type:"button",className:c,style:x,disabled:te,onClick:()=>{let E=o===void 0&&B===void 0&&ne()===null&&O!==null&&!O.allow_custom_amount&&typeof O.unit_amount=="number"?{expectedUnitAmount:O.unit_amount,expectedCurrency:O.currency}:{};_({productId:e,variantId:t,quantity:B!==void 0?void 0:r,amount:o,planId:B,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,...E})},children:q}),Y&&(0,W.jsxs)("div",{role:"alert",className:k,style:k?void 0:Nn,children:[Y,w===null&&!b&&a!==null&&(0,W.jsx)("button",{type:"button",onClick:P,style:Mn,children:"Tap to retry"})]})]})}var _e=require("react");var Q=require("react/jsx-runtime"),Vn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},qn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},$n=1500;function Dn(){return(0,Q.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,Q.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,Q.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,Q.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Bn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Ht({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:f,errorClassName:y,spinner:u=!0,children:v}){let{product:c,loading:x,error:k,refresh:p}=ve(e,{apiUrl:o}),{add:A}=ye(),[w,b]=(0,_e.useState)(!1),[a,P]=(0,_e.useState)(!1),_=(0,_e.useRef)(void 0);(0,_e.useEffect)(()=>()=>{_.current&&clearTimeout(_.current)},[]);let s=c!==null&&!c.payments_ready,d=c!==null&&!c.active,m=c!==null&&c.purchasable===!1,g=c!==null&&!x&&be(c).length===0,h=c!==null&&c.allow_custom_amount,C=c!==null&&c.subscription?.required===!0,S=c!==null&&Re(c),R=c!==null?be(c):[],O=t!==void 0?R.find(q=>q.id===t)??null:r!==void 0&&S?ke(R,r):!S&&R.length===1?R[0]:null,$=c!==null&&!g&&!O,J=O!==null&&!O.in_stock,B=!!i||x||!c||s||d||m||g||h||C||$||J,T=()=>{if(!c||!O)return;let q=r??Bn(O);if(!A({productId:e,variantId:O.id,quantity:n,selection:q,display:{name:c.name,variantTitle:O.title,image:Ae(c,q)[0]??null}}).ok){b(!0);return}b(!1),P(!0),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>P(!1),$n)},M;x?M=(0,Q.jsxs)(Q.Fragment,{children:[u&&(0,Q.jsx)(Dn,{}),v??"Add to cart"]}):s?M="Payments not set up":d||m||g||h?M="Unavailable":C?M="Subscription only":$?M="Select options":J?M="Out of stock":a?M="Added to cart":v!==void 0?M=v:M="Add to cart";let V=w?"Your cart is full \u2014 remove an item before adding another.":k;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)("button",{type:"button",className:l,style:f,disabled:B,"data-added":a?"true":void 0,onClick:T,children:M}),V&&(0,Q.jsxs)("div",{role:"alert",className:y,style:y?void 0:Vn,children:[V,c===null&&!x&&k!==null&&!w&&(0,Q.jsx)("button",{type:"button",onClick:p,style:qn,children:"Tap to retry"})]})]})}var H=require("react/jsx-runtime"),Jt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function Gt(){return(0,H.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,H.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,H.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,H.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Zt({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:f,style:y,errorClassName:u,spinner:v=!0,children:c}){let{items:x,hydrated:k}=ye(),{lines:p}=it({apiUrl:e}),{startCheckout:A,loading:w,error:b,conflicts:a}=ot({apiUrl:e}),P=k&&x.length===0,_=p.some(g=>g.status==="unavailable"),s=!!l||!k||P||_||w,d;w?d=(0,H.jsxs)(H.Fragment,{children:[v&&(0,H.jsx)(Gt,{}),"Processing\u2026"]}):k?P?d="Cart is empty":_?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=(0,H.jsxs)(H.Fragment,{children:[v&&(0,H.jsx)(Gt,{}),c??"Checkout"]});let m=a?Object.keys(a).length:0;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("button",{type:"button",className:f,style:y,disabled:s,onClick:()=>A(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),m>0&&(0,H.jsx)("div",{role:"alert",className:u,style:u?void 0:Jt,children:m===1?"An item in your cart changed \u2014 please review your cart and try again.":`${m} items in your cart changed \u2014 please review your cart and try again.`}),b&&(0,H.jsx)("div",{role:"alert",className:u,style:u?void 0:Jt,children:b})]})}var ue=require("react");var I=require("react/jsx-runtime"),vt="af_order_confirmation_session",Fn=1800*1e3;function Qt({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:f=1500,renderNoSession:y,renderPending:u,renderPaid:v,renderFailed:c}){let[x,k]=(0,ue.useState)(n),[p,A]=(0,ue.useState)(null),[w,b]=(0,ue.useState)(!1),a=(0,ue.useRef)(void 0);(0,ue.useEffect)(()=>{if(n!==void 0){k(n);return}if(a.current!==void 0){k(a.current);return}let d=new URL(window.location.href),m=d.searchParams.get("session_id");if(m){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(vt,JSON.stringify({id:m,ts:Date.now()}))}catch{}}else try{let g=sessionStorage.getItem(vt);if(g){let h=JSON.parse(g);typeof h.id=="string"&&typeof h.ts=="number"&&Date.now()-h.ts<=Fn?m=h.id:sessionStorage.removeItem(vt)}}catch{}a.current=m,k(m)},[n]),(0,ue.useEffect)(()=>{if(!x)return;let d=!1,m,g=Date.now(),h=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(C.ok){let S=await C.json();if(d||(A(S),S.status!=="pending"))return}}catch{}if(!d){if(Date.now()-g>=i){b(!0);return}m=setTimeout(h,o)}};return h(),()=>{d=!0,m&&clearTimeout(m)}},[x,e,o,i]);let P=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),_=(0,ue.useRef)(!1);(0,ue.useEffect)(()=>{if(!x||p===null||_.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(_.current=!0,!It(x)))return;let m=(p.line_items??[]).filter(g=>typeof g.variant_id=="string"&&g.variant_id.length>0).map(g=>({variantId:g.variant_id,quantity:g.quantity}));m.length>0&&Tt(m)},[x,p]);let s=P&&p.fulfillment.type==="redirect"?p.fulfillment.redirect_url:void 0;if((0,ue.useEffect)(()=>{if(!s||!l)return;let d=setTimeout(()=>{window.location.href=s},f);return()=>clearTimeout(d)},[s,l,f]),x===void 0)return null;if(x===null)return y?(0,I.jsx)(I.Fragment,{children:y()}):(0,I.jsxs)("div",{className:t,style:r,children:[(0,I.jsx)("h2",{children:"Thank you for your order!"}),(0,I.jsx)("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!p||p.status==="pending")return u?(0,I.jsx)(I.Fragment,{children:u({timedOut:w})}):(0,I.jsx)("div",{className:t,style:r,role:"status",children:(0,I.jsx)("p",{children:w?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(P){if(v)return(0,I.jsx)(I.Fragment,{children:v(p)});let{fulfillment:d}=p,m=p.amount_total!==void 0&&p.currency?z(p.amount_total,p.currency):null,g=d.files??[],h=g.length===0?d.download_url:void 0;return(0,I.jsxs)("div",{className:t,style:r,children:[(0,I.jsx)("h2",{children:"Thank you for your purchase!"}),p.is_test&&(0,I.jsxs)("p",{children:[(0,I.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),p.line_items&&p.line_items.length>0&&(0,I.jsx)("ul",{children:p.line_items.map((C,S)=>(0,I.jsxs)("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&(0,I.jsx)("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},S))}),m&&(0,I.jsxs)("p",{children:["Total paid: ",m]}),p.source==="subscription"&&p.subscription&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("p",{children:["Your subscription renews"," ",p.subscription.interval_count>1?`every ${p.subscription.interval_count} ${p.subscription.interval}s`:`every ${p.subscription.interval}`," ","at"," ",z(p.subscription.amount,p.subscription.currency),"."]}),(0,I.jsxs)("p",{children:["You can view, update, or cancel it any time on"," ",(0,I.jsx)("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),g.length>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)("p",{children:"Your downloads:"}),(0,I.jsx)("ul",{children:g.map((C,S)=>(0,I.jsx)("li",{children:(0,I.jsx)("a",{href:C.download_url,children:C.name})},S))})]}),h&&(0,I.jsx)("p",{children:(0,I.jsx)("a",{href:h,children:"Download your file"})}),s?(0,I.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,I.jsx)("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?(0,I.jsx)("p",{children:(0,I.jsx)("a",{href:d.redirect_url,children:"Continue to your content"})}):null,g.length===0&&!h&&!d.redirect_url&&(0,I.jsx)("p",{children:"A confirmation email is on its way to you."}),p.order_id&&(0,I.jsxs)("p",{children:["Order reference: ",(0,I.jsx)("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return c?(0,I.jsx)(I.Fragment,{children:c(p)}):(0,I.jsx)("div",{className:t,style:r,children:(0,I.jsx)("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}var at=require("react");var Se=require("react/jsx-runtime");function Ct(e,t){if(t.unit_amount!==null&&t.unit_amount!==void 0)return t.unit_amount;let r=t.percent_off_bps??0;return e-Math.floor(e*r/1e4)}function kt(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var zn={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},jn={display:"block",width:"100%",textAlign:"left",padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Kn={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600};function Xt({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:f,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:v,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,A=k?.ready===!0,w=[...k?.plans??[]].sort((S,R)=>S.position-R.position),[b,a]=(0,at.useState)(null),P=o!==void 0,_=P?o:b,s=w.map(S=>S.id).join("|"),d=w.length>0?w[0].id:null;if((0,at.useEffect)(()=>{if(!(!p||!A)&&!(_!==null&&w.some(S=>S.id===_))){if(d===null){if(_===null)return;P||a(null),i?.(null);return}P||a(d),i?.(d)}},[p,A,d,s,_,P]),!k)return null;if(!A)return p?x?(0,Se.jsx)(Se.Fragment,{children:x()}):(0,Se.jsx)("div",{className:l,style:f,"data-state":"unavailable",children:(0,Se.jsx)("p",{children:"This product is currently unavailable."})}):null;if(w.length===0)return null;let m=e?.base_currency!==void 0&&e?.base_currency!==null,g=r!==void 0?r:m?null:e?.unit_amount??null,h=n??e?.base_currency??e?.currency??"usd",C=[];if(!p){let S=g;C.push({plan:null,selected:_===null,price:S,priceLabel:S!==null?z(S,h):null,label:"One-time purchase",select:()=>{P||a(null),i?.(null)}})}for(let S of w){let R=S.unit_amount!==null?S.unit_amount:g!==null?Ct(g,S):null,O=R!==null?z(R,h):null,$=S.title&&S.title.trim().length>0?S.title.trim():`Subscribe ${kt(S)}`,J=O?`${$} \u2014 ${O} ${kt(S)}`:`${$} \u2014 billed ${kt(S)}`;C.push({plan:S,selected:_===S.id,price:R,priceLabel:O,label:J,select:()=>{P||a(S.id),i?.(S.id)}})}return(0,Se.jsx)("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?f:{...zn,...f},children:C.map(S=>{if(c)return(0,Se.jsx)("span",{style:{display:"contents"},children:c(S)},S.plan?.id??"one-time");let R=S.selected;return(0,Se.jsx)("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":S.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...jn,...R?Kn:{}},onClick:S.select,children:S.plan===null&&v!==void 0?v:S.plan===null?S.priceLabel?`One-time purchase \u2014 ${S.priceLabel}`:"One-time purchase":S.label},S.plan?.id??"one-time")})})}var X=require("react");async function de(e,t,r={}){let n;try{n=await fetch(`${e}${t}`,{method:r.method??"GET",headers:{...r.body!==void 0?{"Content-Type":"application/json"}:{},...r.token?{Authorization:`Bearer ${r.token}`}:{}},...r.body!==void 0?{body:JSON.stringify(r.body)}:{}})}catch(u){return{ok:!1,failure:{kind:"network",error:u instanceof Error?u.message:"Network error"}}}let o=await n.text().catch(()=>""),i=null;try{i=o?JSON.parse(o):null}catch{i=null}let l=typeof i=="object"&&i!==null?i:null;if(n.ok)return l===null?{ok:!1,failure:{kind:"parse_error",error:"The server sent an unreadable response \u2014 please try again"}}:{ok:!0,data:l};if(n.status===404&&o.trim()==="")return{ok:!1,failure:{kind:"unavailable"}};let f=typeof l?.code=="string"?l.code:null,y=typeof l?.error=="string"&&l.error?l.error:`Request failed (${n.status})`;return n.status===401?{ok:!1,failure:{kind:"unauthorized",code:f,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:f,error:y}}}function en(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function De(e){if(!e)return null;let t=e.includes("T")?e:e.replace(" ","T")+"Z",r=Date.parse(t);if(Number.isNaN(r))return null;try{return new Date(r).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{return null}}var Yn=1500;function tn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function Wn(e,t){return e.requestId===t}function Hn(e,t){return typeof window>"u"||!tn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;if(y?.type==="aifeatures:preview-session-ack"&&Wn(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let v=y.customer;typeof v.email=="string"&&(u={email:v.email,name:typeof v.name=="string"?v.name:null})}o({claimed:!0,token:y.token,customer:u});return}o({claimed:!0,token:null,customer:null,error:typeof y.error=="string"&&y.error?y.error:"The preview sign-in could not be created."})}},l=setTimeout(()=>o({claimed:!1}),Yn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ie(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,X.useState)(()=>Pe()),[o,i]=(0,X.useState)(null),[l,f]=(0,X.useState)(!1),[y,u]=(0,X.useState)(!1),v=(0,X.useRef)(void 0);(0,X.useEffect)(()=>Nt(()=>{let b=Pe();n(b),i(b===null?a=>Et()??a:null)}),[]);let c=(0,X.useCallback)(async b=>{u(!0);try{let a=await de(t,"/v1/account/verify",{method:"POST",body:{code:b}});if(a.ok&&typeof a.data.token=="string"){let _=a.data.customer&&typeof a.data.customer.email=="string"?{email:a.data.customer.email,name:typeof a.data.customer.name=="string"?a.data.customer.name:null}:null;return et({token:a.data.token,customer:_}),n({token:a.data.token,customer:_}),i(null),f(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):!a.ok&&a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:!a.ok&&(a.failure.kind==="http"||a.failure.kind==="unauthorized")&&a.failure.code==="invalid_code"?(i("invalid_code"),{ok:!1,code:"invalid_code",error:a.failure.error}):{ok:!1,code:"error",error:a.ok||a.failure.kind==="unavailable"?"Sign-in failed \u2014 please request a new link.":a.failure.error}}finally{u(!1)}},[t]),x=e.consumeUrlCode??!0;(0,X.useEffect)(()=>{if(!(typeof window>"u")&&v.current===void 0){if(!x){v.current=null;return}let b=new URL(window.location.href),a=b.searchParams.get("code");a&&(b.searchParams.delete("code"),window.history.replaceState(window.history.state,"",b.toString())),v.current=a,a&&c(a)}},[c,x]);let k=(0,X.useCallback)(async b=>{if(typeof window<"u"&&tn(window)){let P=await Hn(b,$e());if(P.claimed){if(P.token!==null){let _=P.customer??{email:b,name:null};return et({token:P.token,customer:_}),n({token:P.token,customer:_}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:P.error}}}let a=await de(t,"/v1/account/login",{method:"POST",body:{email:b}});return a.ok?{ok:!0,via:"email"}:a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:{ok:!1,code:"error",error:(a.failure.kind==="network",a.failure.error)}},[t]),p=(0,X.useCallback)(async()=>{let b=Pe()?.token;b&&await de(t,"/v1/account/logout",{method:"POST",token:b,body:{}}),me(),n(null),i(null)},[t]),A=(0,X.useCallback)(async()=>{let b=Pe();if(!b)return;let a=await de(t,"/v1/account/me",{token:b.token}),P=()=>Pe()?.token===b.token;if(a.ok){if(!P())return;let _=a.data.customer??b.customer;et({token:b.token,customer:_}),n({token:b.token,customer:_}),f(!1);return}if(a.failure.kind==="unauthorized"){if(!P())return;me("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){f(!0);return}},[t]);return{status:y?"pending":r?"signed_in":l?"unavailable":"signed_out",customer:r?.customer??null,token:r?.token??null,reason:r?null:o,login:k,verifyCode:c,logout:p,refresh:A}}var j=require("react");var le=require("react");var D=require("react/jsx-runtime"),wt={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},Jn={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},Gn={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},nn={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Ee={margin:0},Zn={color:"#b91c1c",margin:0};function Be({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:f}){let y=Ie({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[v,c]=(0,le.useState)(""),[x,k]=(0,le.useState)("form"),[p,A]=(0,le.useState)(!1),[w,b]=(0,le.useState)(null),[a,P]=(0,le.useState)(null),[_,s]=(0,le.useState)(!1),d=(0,le.useRef)(void 0),m=(0,le.useRef)(!1);(0,le.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]);let g=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},h=async()=>{let R=v.trim();if(!R||p||m.current)return;m.current=!0,A(!0),b(null),P(null);let O=await u.login(R);if(m.current=!1,A(!1),O.ok){if(O.via==="preview")return;k("sent"),g();return}O.code!=="unavailable"&&(b(O.code==="rate_limited"?"rate_limited":"error"),P(O.error))};if(u.status==="unavailable")return f?(0,D.jsx)(D.Fragment,{children:f()}):(0,D.jsx)("div",{className:n,style:n?o:{...wt,...o},"data-state":"unavailable",children:(0,D.jsx)("p",{style:Ee,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:v.trim(),canResend:_,resend:()=>{h(),g()},submitting:p,reset:()=>k("form")};return l?(0,D.jsx)(D.Fragment,{children:l(R)}):(0,D.jsxs)("div",{className:n,style:n?o:{...wt,...o},"data-state":"sent",children:[(0,D.jsxs)("p",{style:Ee,children:["Check your email \u2014 if ",(0,D.jsx)("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),_?(0,D.jsxs)("p",{style:Ee,children:["Didn't get it?"," ",(0,D.jsx)("button",{type:"button",style:nn,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",(0,D.jsx)("button",{type:"button",style:nn,onClick:R.reset,children:"use a different email"}),"."]}):(0,D.jsx)("p",{style:Ee,children:"It can take a minute to arrive."})]})}let C={email:v,setEmail:c,submit:()=>void h(),submitting:p,errorKind:w,errorMessage:a,reason:u.reason};if(i)return(0,D.jsx)(D.Fragment,{children:i(C)});let S=R=>{R.preventDefault(),C.submit()};return(0,D.jsxs)("form",{className:n,style:n?o:{...wt,...o},onSubmit:S,"data-state":"form",children:[u.reason==="session_expired"&&(0,D.jsx)("p",{style:Ee,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&(0,D.jsx)("p",{style:Ee,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),(0,D.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[(0,D.jsx)("span",{children:"Email address"}),(0,D.jsx)("input",{type:"email",value:v,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:Jn})]}),(0,D.jsx)("button",{type:"submit",style:Gn,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&(0,D.jsx)("p",{style:Zn,role:"alert",children:w==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}var K=require("react/jsx-runtime"),Qn={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},Xn={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},Fe={color:"#6b7280",fontSize:"0.875rem"};function er(e){switch(e.status){case"paid":return null;case"refunded":return"Refunded";case"partially_refunded":return"Partially refunded";case"disputed":return"Disputed";default:return e.status}}function ut({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?(0,K.jsx)(K.Fragment,{children:o()}):(0,K.jsxs)("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&(0,K.jsx)("h3",{children:n}),(0,K.jsx)("p",{style:Fe,children:"No orders yet."})]}):(0,K.jsxs)("div",{className:t,style:r,children:[n!==null&&(0,K.jsx)("h3",{children:n}),(0,K.jsx)("ul",{style:t?void 0:Qn,children:e.map(l=>{if(i)return(0,K.jsx)("li",{style:{display:"contents"},children:i(l)},l.id);let f=De(l.created_at),y=er(l);return(0,K.jsxs)("li",{style:t?void 0:Xn,children:[(0,K.jsxs)("div",{children:[l.order_number!==null&&(0,K.jsxs)("strong",{children:["Order #",l.order_number]})," ",f&&(0,K.jsx)("span",{style:Fe,children:f})," ",l.source==="subscription"&&(0,K.jsx)("span",{style:Fe,children:"\xB7 subscription"}),y&&(0,K.jsxs)("span",{style:Fe,children:[" \xB7 ",y]})]}),l.line_items.length>0&&(0,K.jsx)("div",{style:Fe,children:l.line_items.map(u=>u.name?`${u.quantity&&u.quantity>1?`${u.quantity} \xD7 `:""}${u.name}`:null).filter(Boolean).join(", ")}),(0,K.jsx)("div",{children:z(l.amount_total,l.currency)})]},l.id)})})]})}var ee=require("react");var U=require("react/jsx-runtime"),tr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},nr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},Ue={color:"#6b7280",fontSize:"0.875rem"},rr={color:"#b91c1c",fontSize:"0.875rem",margin:0},ir={color:"#065f46",fontSize:"0.875rem",margin:0},Pt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},xe={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},on={...xe,border:"1px solid #111827",background:"#111827",color:"white"},or={...xe,border:"1px solid #b91c1c",color:"#b91c1c"},sr={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},rn={panel:"none",mutation:null,portalRefused:!1};function ar(e){let t=De(e.current_period_end);return e.ended?{text:"This subscription has ended.",tone:"ended"}:e.cancel_at_period_end?{text:t?`Scheduled to cancel \u2014 stays active until ${t}.`:"Scheduled to cancel at the end of the current period.",tone:"warn"}:e.status==="past_due"||e.status==="unpaid"?{text:"There's a problem with your last payment \u2014 please update your card.",tone:"warn"}:e.status==="active"||e.status==="trialing"?{text:t?`Renews on ${t}.`:"Active.",tone:"ok"}:{text:`Status: ${e.status}.`,tone:"warn"}}function ur({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=(0,ee.useState)(e?.name??""),[f,y]=(0,ee.useState)(o?.line1??""),[u,v]=(0,ee.useState)(o?.line2??""),[c,x]=(0,ee.useState)(o?.city??""),[k,p]=(0,ee.useState)(o?.state??""),[A,w]=(0,ee.useState)(o?.postal_code??""),[b,a]=(0,ee.useState)(o?.country??""),P=(_,s,d,m)=>(0,U.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[(0,U.jsx)("span",{children:_}),(0,U.jsx)("input",{style:sr,value:s,onChange:g=>d(g.target.value),required:m?.required,maxLength:m?.maxLength})]});return(0,U.jsxs)("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:_=>{_.preventDefault(),r({name:i.trim()||null,address:{line1:f.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:A.trim()||null,country:b.trim().toUpperCase()}})},children:[P("Name",i,l),P("Address line 1",f,y,{required:!0}),P("Address line 2",u,v),P("City",c,x),P("State / region",k,p),P("Postal code",A,w),P("Country (2-letter code)",b,a,{required:!0,maxLength:2}),(0,U.jsxs)("div",{style:Pt,children:[(0,U.jsx)("button",{type:"submit",style:on,disabled:t,children:t?"Saving\u2026":"Save address"}),(0,U.jsx)("button",{type:"button",style:xe,onClick:n,disabled:t,children:"Cancel"})]})]})}function ze({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:f,heading:y="Your subscriptions",renderEmpty:u,renderRow:v}){let[c,x]=(0,ee.useState)(t),[k,p]=(0,ee.useState)({}),A=(0,ee.useRef)(new Set);(0,ee.useEffect)(()=>{x(t)},[t]),(0,ee.useEffect)(()=>{let s=d=>{d.persisted&&(A.current.clear(),p(m=>{let g=!1,h={};for(let[C,S]of Object.entries(m))S.mutation?.phase==="pending"?(h[C]={...S,mutation:null},g=!0):h[C]=S;return g?h:m}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let w=(s,d)=>p(m=>({...m,[s]:{...m[s]??rn,...d}})),b=s=>{x(d=>d.map(m=>m.id===s.id?s:m)),i?.(s)},a=async(s,d,m,g)=>{if(A.current.has(s.id))return{ok:!1};A.current.add(s.id);try{w(s.id,{mutation:{kind:d,phase:"pending"}});let h=await de(e,m,{method:"POST",token:r.token,body:g??{}});if(h.ok)return{ok:!0,data:h.data};let{failure:C}=h;return C.kind==="unauthorized"?(n?.({code:C.code,error:C.error}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="unavailable"?(o?.(),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="ended"?(b({...s,ended:!0,status:"canceled"}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="portal_unavailable"?(w(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(w(s.id,{mutation:{kind:d,phase:"error",error:C.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":C.error}}),{ok:!1})}finally{A.current.delete(s.id)}},P=s=>r.kind==="session"?{cancel:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/cancel`,reactivate:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/reactivate`,address:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/address`,portal:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/portal-session`}:{cancel:"/v1/account/manage/cancel",reactivate:null,address:null,portal:"/v1/account/manage/portal-session"},_=s=>{let d=k[s.id]??rn,m=P(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>w(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>w(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let g=await a(s,"cancel",m.cancel);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:m.reactivate!==null,reactivate:()=>{m.reactivate&&(async()=>{let g=await a(s,"reactivate",m.reactivate);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{m.address&&w(s.id,{panel:"address",mutation:null})},saveAddress:g=>{m.address&&(async()=>{let h=await a(s,"address",m.address,{shipping_address:g});if(h.ok){let C=h.data.subscription;C&&b(C),w(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let g=await a(s,"portal",m.portal);g.ok&&typeof g.data.url=="string"?window.location.href=g.data.url:g.ok&&w(s.id,{mutation:{kind:"portal",phase:"error",error:"Card update is temporarily unavailable."}})})()}}};return c.length===0?u?(0,U.jsx)(U.Fragment,{children:u()}):(0,U.jsxs)("div",{className:l,style:f,"data-state":"empty",children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("p",{style:Ue,children:"No subscriptions."})]}):(0,U.jsxs)("div",{className:l,style:f,children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("ul",{style:l?void 0:tr,children:c.map(s=>{let d=_(s);return v?(0,U.jsx)("li",{style:{display:"contents"},children:v(d)},s.id):(0,U.jsx)("li",{style:l?void 0:nr,"data-status":s.status,"data-ended":s.ended||void 0,children:(0,U.jsx)(lr,{ctx:d})},s.id)})})]})}function lr({ctx:e}){let t=e.subscription,r=ar(t),n=De(t.current_period_end),o=`${z(t.current_amount,t.currency)} ${en(t.plan_interval,t.plan_interval_count)}`,i=e.mutation?.phase==="pending",l=i?e.mutation?.kind:null;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{children:[(0,U.jsx)("strong",{children:t.plan_title??"Subscription"})," ",(0,U.jsxs)("span",{style:Ue,children:["\xB7 ",o]}),t.is_test&&(0,U.jsx)("span",{style:Ue,children:" \xB7 test"})]}),(0,U.jsx)("div",{style:r.tone==="warn"?void 0:Ue,children:r.text}),t.ended?(0,U.jsx)("p",{style:Ue,children:"This subscription has ended \u2014 to start again, subscribe from the product page."}):e.panel==="confirm_cancel"?(0,U.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[(0,U.jsx)("p",{style:{margin:0},children:n?`Your subscription stays active until ${n} \u2014 after that it won't renew and you won't be charged again.`:"Your subscription stays active until the end of the current billing period \u2014 after that it won't renew and you won't be charged again."}),(0,U.jsxs)("div",{style:Pt,children:[(0,U.jsx)("button",{type:"button",style:or,onClick:e.confirmCancel,disabled:i,children:l==="cancel"?"Canceling\u2026":"Confirm cancellation"}),(0,U.jsx)("button",{type:"button",style:xe,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?(0,U.jsx)(ur,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):(0,U.jsxs)("div",{style:Pt,children:[t.cancel_at_period_end?e.reactivateAvailable?(0,U.jsx)("button",{type:"button",style:on,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):(0,U.jsx)("span",{style:Ue,children:"To keep this subscription, sign in with your email address on this page."}):(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openCancelConfirm,disabled:i,children:"Cancel subscription"}),t.shipping_address!==void 0&&!t.cancel_at_period_end&&(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&(0,U.jsx)("p",{style:rr,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&(0,U.jsx)("p",{style:ir,role:"status",children:e.mutation.kind==="cancel"?n?`Cancellation scheduled \u2014 you keep access until ${n}.`:"Cancellation scheduled.":e.mutation.kind==="reactivate"?"Your subscription will continue.":e.mutation.kind==="address"?"Shipping address updated.":"Done."})]})}var L=require("react/jsx-runtime"),cr={display:"flex",flexDirection:"column",gap:"1.25rem"},sn={color:"#6b7280",fontSize:"0.875rem"},dr={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},an={color:"#b91c1c"},lt={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function un({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:f,renderHeader:y,renderPmBanner:u,renderManageExpired:v}){let c=Ie({apiUrl:e}),x=(0,j.useRef)(void 0),[k,p]=(0,j.useState)(null),[A,w]=(0,j.useState)(!1);(0,j.useEffect)(()=>{if(!(typeof window>"u")){if(x.current===void 0){let N=new URL(window.location.href),E=N.searchParams.get("manage_code"),F=N.searchParams.get("pm");(E!==null||F!==null)&&(N.searchParams.delete("manage_code"),N.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",N.toString())),x.current={manageCode:E,pmUpdated:F==="updated"}}p(x.current.manageCode),w(x.current.pmUpdated)}},[]);let[b,a]=(0,j.useState)(null),P=(0,j.useRef)(!1),_=(0,j.useRef)(0),s=(0,j.useCallback)(N=>{a({phase:"verifying"}),(async()=>{let E=await de(e,"/v1/account/manage/verify",{method:"POST",body:{manage_code:N}});if(E.ok&&typeof E.data.manage_token=="string"&&E.data.subscription){a({phase:"active",token:E.data.manage_token,sub:E.data.subscription,siteName:null});return}if(!E.ok&&E.failure.kind==="unavailable"){a({phase:"unavailable"});return}if(!E.ok&&E.failure.kind==="network"){a({phase:"error",error:E.failure.error});return}a({phase:"expired"})})()},[e]);(0,j.useEffect)(()=>{!k||P.current||(P.current=!0,s(k))},[k,s]);let d=(0,j.useCallback)(async()=>{let N=b;if(!N||N.phase!=="active")return;let E=++_.current,F=await de(e,"/v1/account/manage/subscription",{token:N.token});E===_.current&&(F.ok&&F.data.subscription?a({phase:"active",token:N.token,sub:F.data.subscription,siteName:typeof F.data.site?.name=="string"?F.data.site.name:N.siteName}):!F.ok&&F.failure.kind==="unauthorized"?a({phase:"expired"}):!F.ok&&F.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[m,g]=(0,j.useState)({phase:"loading"}),[h,C]=(0,j.useState)(0),S=h>0,R=(0,j.useRef)(0),O=c.token,$=(0,j.useCallback)(async()=>{if(!O)return;let N=++R.current,E=await de(e,"/v1/account/me",{token:O});if(N===R.current){if(E.ok){g({phase:"ready",data:E.data});return}if(E.failure.kind==="unauthorized"){me("session_expired");return}if(E.failure.kind==="unavailable"){me();return}g({phase:"error",error:E.failure.error})}},[e,O]);(0,j.useEffect)(()=>{!O||k||(g({phase:"loading"}),$())},[O,k,$]);let J=(0,j.useCallback)(async()=>{C(N=>N+1);try{b&&b.phase==="active"?await d():await $()}finally{C(N=>N-1)}},[b,d,$]),B=(0,j.useCallback)(N=>{R.current++,_.current++,a(E=>E&&E.phase==="active"&&E.sub.id===N.id?{...E,sub:N}:E),g(E=>E.phase==="ready"?{phase:"ready",data:{...E.data,subscriptions:E.data.subscriptions.map(F=>F.id===N.id?N:F)}}:E)},[]),T=t?r:{...cr,...r},M=N=>{if(!A)return null;let F={state:N.some(ie=>!ie.ended&&(ie.status==="past_due"||ie.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void J(),checking:S};return u?u(F):(0,L.jsx)("div",{style:dr,role:"status","data-pm-state":F.state,children:F.state==="retrying"?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),(0,L.jsx)("p",{style:{margin:"0.375rem 0 0"},children:(0,L.jsx)("button",{type:"button",style:lt,onClick:F.checkAgain,disabled:S,children:S?"Checking\u2026":"Check again"})})]}):(0,L.jsx)("p",{style:{margin:0},children:"Card updated \u2014 your subscription is back in good standing."})})};if(k)return!b||b.phase==="verifying"?i?(0,L.jsx)(L.Fragment,{children:i()}):(0,L.jsx)("div",{className:t,style:T,role:"status",children:(0,L.jsx)("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?(0,L.jsxs)("div",{className:t,style:T,children:[M([b.sub]),(0,L.jsx)(ze,{apiUrl:e,subscriptions:[b.sub],auth:{kind:"manage",token:b.token},heading:"Your subscription",onSubscriptionChange:B,onAuthError:()=>a({phase:"expired"}),onUnavailable:()=>a({phase:"unavailable"})})]}):b.phase==="unavailable"?(0,L.jsx)("div",{className:t,style:T,"data-state":"unavailable",children:(0,L.jsx)("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?(0,L.jsxs)("div",{className:t,style:T,children:[(0,L.jsx)("p",{style:an,role:"alert",children:b.error}),(0,L.jsx)("p",{children:(0,L.jsx)("button",{type:"button",style:lt,onClick:()=>s(k),children:"Try again"})})]}):(0,L.jsxs)("div",{className:t,style:T,"data-state":"manage-expired",children:[v?v():(0,L.jsx)("p",{children:"This manage link is no longer valid. Sign in below with the email you used at checkout to manage your subscription."}),(0,L.jsx)(Be,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?(0,L.jsx)(L.Fragment,{children:i()}):(0,L.jsx)("div",{className:t,style:T,role:"status",children:(0,L.jsx)("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return(0,L.jsx)("div",{className:t,style:T,children:(0,L.jsx)(Be,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(m.phase==="loading")return i?(0,L.jsx)(L.Fragment,{children:i()}):(0,L.jsx)("div",{className:t,style:T,role:"status",children:(0,L.jsx)("p",{children:"Loading your account\u2026"})});if(m.phase==="error")return l?(0,L.jsx)(L.Fragment,{children:l({error:m.error,retry:()=>void $()})}):(0,L.jsxs)("div",{className:t,style:T,children:[(0,L.jsxs)("p",{style:an,role:"alert",children:["We couldn't load your account \u2014 ",m.error]}),(0,L.jsx)("p",{children:(0,L.jsx)("button",{type:"button",style:lt,onClick:()=>void $(),children:"Try again"})})]});let{data:V}=m,te=V.customer??c.customer??{email:"",name:null},q=()=>void c.logout(),Y=V.orders.length===0&&V.subscriptions.length===0;return(0,L.jsxs)("div",{className:t,style:T,children:[y?y({customer:te,site:V.site??null,signOut:q}):(0,L.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[(0,L.jsxs)("div",{children:[(0,L.jsx)("h2",{style:{margin:0},children:"Your account"}),(0,L.jsxs)("p",{style:{...sn,margin:0},children:["Signed in as ",te.email]})]}),(0,L.jsx)("button",{type:"button",style:lt,onClick:q,children:"Sign out"})]}),M(V.subscriptions),Y?f?f():(0,L.jsxs)("p",{style:sn,children:["Nothing here yet \u2014 orders and subscriptions for ",te.email," ","will show up on this page."]}):(0,L.jsxs)(L.Fragment,{children:[V.subscriptions.length>0&&(0,L.jsx)(ze,{apiUrl:e,subscriptions:V.subscriptions,auth:{kind:"session",token:O},onSubscriptionChange:B,onAuthError:()=>me("session_expired"),onUnavailable:()=>me()}),(0,L.jsx)(ut,{orders:V.orders})]})]})}0&&(module.exports={AccountLogin,AccountOrders,AccountPage,AddToCartButton,AifeaturesCaptcha,BuyButton,CartCheckoutButton,MARKET_COUNTRIES,MAX_CART_LINES,OrderConfirmation,PlanPicker,ProductPrice,SubscriptionList,VariantPicker,ZERO_DECIMAL_CURRENCIES,applySelectionToUrl,formatPrice,getOptions,getVariants,isMultiVariant,isValueAvailable,isValueInCatalog,planRecurringAmount,reanchorSelection,resolveVariant,searchFromSelection,selectedImages,selectedValues,selectionFromSearch,useCart,useCartCheckout,useCartItems,useCartSummary,useCheckout,useMarket,useProduct,useSession,valueSlug,variantPriceRange});
|
|
2
|
+
"use strict";var dt=Object.defineProperty;var cn=Object.getOwnPropertyDescriptor;var dn=Object.getOwnPropertyNames;var pn=Object.prototype.hasOwnProperty;var fn=(e,t)=>{for(var r in t)dt(e,r,{get:t[r],enumerable:!0})},mn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of dn(t))!pn.call(e,o)&&o!==r&&dt(e,o,{get:()=>t[o],enumerable:!(n=cn(t,o))||n.enumerable});return e};var gn=e=>mn(dt({},"__esModule",{value:!0}),e);var fr={};fn(fr,{AccountLogin:()=>Be,AccountOrders:()=>lt,AccountPage:()=>ln,AddToCartButton:()=>Jt,AifeaturesCaptcha:()=>At,BuyButton:()=>Ht,CartCheckoutButton:()=>Qt,MARKET_COUNTRIES:()=>st,MAX_CART_LINES:()=>vt,OrderConfirmation:()=>Xt,PlanPicker:()=>en,ProductPrice:()=>zt,SubscriptionList:()=>ze,VariantPicker:()=>Kt,ZERO_DECIMAL_CURRENCIES:()=>ft,applySelectionToUrl:()=>Ze,formatPrice:()=>z,getOptions:()=>we,getVariants:()=>be,isMultiVariant:()=>Re,isValueAvailable:()=>Ye,isValueInCatalog:()=>We,planRecurringAmount:()=>wt,reanchorSelection:()=>He,resolveVariant:()=>ke,searchFromSelection:()=>Me,selectedImages:()=>Ae,selectedValues:()=>mt,selectionFromSearch:()=>Ge,useCart:()=>ye,useCartCheckout:()=>ot,useCartItems:()=>it,useCartSummary:()=>$t,useCheckout:()=>nt,useMarket:()=>Ft,useProduct:()=>ve,useSession:()=>Ie,valueSlug:()=>pe,variantPriceRange:()=>Je});module.exports=gn(fr);var Ne=require("react"),Rt=require("@marsidev/react-turnstile"),pt=require("react/jsx-runtime");function At({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=(0,Ne.useState)(null),[f,y]=(0,Ne.useState)(!0);return(0,Ne.useEffect)(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(u=>u.json()).then(u=>{l(u.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),f||!i?null:(0,pt.jsx)("div",{className:o,children:(0,pt.jsx)(Rt.Turnstile,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}var ce=require("react"),je=[1e3,3e3];function ve(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=(0,ce.useState)(null),[l,f]=(0,ce.useState)(!0),[y,u]=(0,ce.useState)(null),[v,c]=(0,ce.useState)(0),x=(0,ce.useRef)(e);(0,ce.useEffect)(()=>{let p=!1,A;f(!0),u(null),x.current!==e&&(x.current=e,i(null));let w=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let P=await a.json().catch(()=>null);if(!p)if(!a.ok||!P){if(a.status>=500&&b<je.length){A=setTimeout(()=>w(b+1),je[b]);return}u(P?.error??`Request failed (${a.status})`),i(null),f(!1)}else i(P),f(!1)}).catch(a=>{if(!p){if(b<je.length){A=setTimeout(()=>w(b+1),je[b]);return}u(a instanceof Error?a.message:"Failed to load product"),f(!1)}})};return w(0),()=>{p=!0,A&&clearTimeout(A)}},[e,r,n,v]);let k=(0,ce.useCallback)(()=>c(p=>p+1),[]);return{product:o,loading:l,error:y,refresh:k}}var ft=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function z(e,t,r){let n=ft.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function be(e){return e.variants??[]}function we(e){return e.options??[]}function Re(e){return we(e).length>0}function Ke(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ke(e,t){let r=Object.keys(t);return e.find(n=>{let o=n.option_values;return o.length!==r.length?!1:o.every(i=>t[i.option_id]===i.value_id)})??null}function Ye(e,t,r,n){return e.some(o=>{let i=Ke(o);if(i[r]!==n)return!1;for(let[l,f]of Object.entries(t))if(l!==r&&i[l]!==f)return!1;return!0})}function We(e,t,r){return e.some(n=>Ke(n)[t]===r)}function He(e,t,r,n){let o={[r]:n};for(let[l,f]of Object.entries(t)){if(l===r)continue;e.some(u=>{let v=Ke(u);return v[r]===n&&v[l]===f})&&(o[l]=f)}return e.some(l=>{let f=Ke(l);return Object.entries(o).every(([y,u])=>f[y]===u)})?o:{[r]:n}}function Je(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function mt(e,t){let r={};for(let n of we(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i&&(r[n.title]=i.value)}return r}function pe(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ge(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((i,l)=>{n.has(pe(l))||n.set(pe(l),i)});let o={};for(let i of we(e)){let l=pe(i.title);if(l.length===0)continue;let f=n.get(l);if(f===void 0)continue;let y=pe(f);if(y.length===0)continue;let u=i.values.find(v=>pe(v.value)===y);u&&(o[i.id]=u.id)}return o}function Me(e,t){let r={};for(let[n,o]of Object.entries(mt(e,t))){let i=pe(n),l=pe(o);i.length===0||l.length===0||(r[i]=l)}return r}function Ae(e,t){let r=[];for(let n of we(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i?.images?.length&&r.push(...i.images)}return r.length>0?r:e.images??[]}function Ze(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of we(e)){let o=pe(n.title);o.length!==0&&r.searchParams.delete(o)}for(let[n,o]of Object.entries(Me(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}var oe=require("react");var yt="aifeatures_cart",bt="aifeatures_market",Ot="aifeatures_cart_cleared";var gt="aifeatures:cart-storage",Ve=new Map;function qe(e){if(Ve.has(e))return Ve.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Oe(e,t){if(typeof window>"u"){Ve.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Ve.delete(e)}catch{Ve.set(e,t)}yn(e)}function yn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(gt,{detail:{key:e}}))}catch{}}function Qe(e,t){if(typeof window>"u")return()=>{};let r=o=>{(o.key===e||o.key===null)&&t()},n=o=>{o.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(gt,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(gt,n)}}function bn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[l,f]of Object.entries(t.selection))typeof f=="string"&&(n[l]=f);let o=typeof t.display=="object"&&t.display!==null?t.display:{},i={name:typeof o.name=="string"?o.name:"",variantTitle:typeof o.variantTitle=="string"?o.variantTitle:null,image:typeof o.image=="string"?o.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:i}}function Ce(){let e=qe(yt);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let o of t){let i=bn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function fe(e){Oe(yt,JSON.stringify(e))}function Tt(e){return Qe(yt,e)}function Lt(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of Ce()){let o=t.get(n.variantId);if(o===void 0){r.push(n);continue}let i=n.quantity-o;i>0&&r.push({...n,quantity:i})}fe(r)}function ne(){let e=qe(bt);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function It(e){Oe(bt,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function Te(e){return Qe(bt,e)}function Et(e){let t=[],r=qe(Ot);if(r)try{let o=JSON.parse(r);Array.isArray(o)&&(t=o.filter(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(o=>o.ts>n),t.some(o=>o.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Oe(Ot,JSON.stringify(t)),!0)}var Xe="aifeatures_session",ht=null;function Ut(){return ht}function hn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.token!="string"||t.token.length===0)return null;let r=null;if(typeof t.customer=="object"&&t.customer!==null){let n=t.customer;typeof n.email=="string"&&n.email.length>0&&(r={email:n.email,name:typeof n.name=="string"?n.name:null})}return{token:t.token,customer:r}}function Pe(){let e=qe(Xe);if(!e)return null;try{return hn(JSON.parse(e))}catch{return null}}function Nt(){return Pe()?.token??null}function et(e){ht=null,Oe(Xe,JSON.stringify(e))}function me(e){ht=e??null,Oe(Xe,null)}function Mt(e){return Qe(Xe,e)}var Sn=1500;function $e(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function tt(e,t){return!("requestId"in e)||e.requestId===t}function St(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;y?.type==="aifeatures:test-checkout-ack"&&tt(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),Sn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function Vt(e){if(window.self!==window.top)try{return window.top.location.href=e,"navigating"}catch{if(window.open(e,"_blank"))return"stayed"}return window.location.href=e,"navigating"}function nt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,oe.useState)(!1),[o,i]=(0,oe.useState)(null),[l,f]=(0,oe.useState)(null),y=(0,oe.useRef)(!1),u=(0,oe.useRef)(null);return(0,oe.useEffect)(()=>{let c=x=>{x.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",c),()=>window.removeEventListener("pageshow",c)},[]),(0,oe.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let c=x=>{if(x.source!==window.parent)return;let k=x.data;if(k?.type!=="aifeatures:test-checkout-ack"||k.status!=="failed")return;let p=u.current;p===null||!tt(k,p)||(u.current=null,i(typeof k.error=="string"&&k.error?k.error:"The test purchase could not be created."),y.current=!1,n(!1))};return window.addEventListener("message",c),()=>window.removeEventListener("message",c)},[]),{startCheckout:(0,oe.useCallback)(async({productId:c,variantId:x,quantity:k,amount:p,metadata:A,successUrl:w,cancelUrl:b,customerEmail:a,planId:P,expectedUnitAmount:_,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),f(null),P!==void 0){let d=Nt();if(d)try{let m=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:P,...x!==void 0?{variant_id:x}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.text().catch(()=>""),h=null;try{h=g?JSON.parse(g):null}catch{h=null}if(m.ok){if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Vt(h.url)==="stayed"&&(y.current=!1,n(!1));return}let C=m.status===404&&g.trim()==="";if(m.status===401||C)me();else{i(h?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}}catch(m){i(m instanceof Error?m.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=P===void 0?ne():null,m=await fetch(`${t}/v1/p/${c}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...x!==void 0?{variant_id:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{plan_id:P}:{},...A!==void 0?{metadata:A}:{},...a!==void 0?{customer_email:a}:{},..._!==void 0&&s!==void 0&&P===void 0?{expected_unit_amount:_,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.json().catch(()=>null);if(!m.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){f({currentUnitAmount:g.current_unit_amount,currency:g.currency}),i(`The price has changed to ${z(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(g?.code==="preview_domain"){let h=$e();if(u.current=h,await St({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{planId:P}:{},...a!==void 0?{customerEmail:a}:{},...A!==void 0?{metadata:A}:{}},h))return;u.current=null}i(g?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Vt(g.url)==="stayed"&&(y.current=!1,n(!1))}catch(d){i(d instanceof Error?d.message:"Checkout failed"),y.current=!1,n(!1)}}},[t]),loading:r,error:o,priceChange:l}}var ge=require("react");var vt=20;function qt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function ye(){let[e,t]=(0,ge.useState)([]),[r,n]=(0,ge.useState)(!1);(0,ge.useEffect)(()=>{let u=()=>t(Ce());return u(),n(!0),Tt(u)},[]);let o=(0,ge.useCallback)(u=>{let v=Ce(),c=qt(u.quantity);return v.find(k=>k.variantId===u.variantId)?(fe(v.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):v.length>=vt?{ok:!1,reason:"cart_full"}:(fe([...v,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=(0,ge.useCallback)(u=>{fe(Ce().filter(v=>v.variantId!==u))},[]),l=(0,ge.useCallback)((u,v)=>{let c=Ce();if(v<=0){fe(c.filter(k=>k.variantId!==u));return}let x=qt(v);fe(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),f=(0,ge.useCallback)(()=>{fe([])},[]),y=e.reduce((u,v)=>u+v.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:f}}var G=require("react");var rt={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},vn={...rt,inStock:!0,status:"error"};function kn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function it(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=ye(),[o,i]=(0,G.useState)({}),[l,f]=(0,G.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=(0,G.useState)(!0),[v,c]=(0,G.useState)(null),[x,k]=(0,G.useState)(0),p=(0,G.useRef)(new Set),A=(0,G.useMemo)(()=>JSON.stringify(r.map(_=>[_.productId,_.variantId,_.selection])),[r]),w=(0,G.useCallback)(()=>k(_=>_+1),[]);(0,G.useEffect)(()=>Te(w),[w]),(0,G.useEffect)(()=>{if(!n)return;if(r.length===0){i({}),f({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let _=!1;u(!0);let s=r,d=[...new Set(s.map(g=>g.productId))],m=async g=>{let h=new Map;return await Promise.all(d.map(async C=>{try{let S=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${g?`?country=${encodeURIComponent(g)}`:""}`);if(S.status===404){h.set(C,{kind:"not_found"});return}if(!S.ok){h.set(C,{kind:"error",message:`Request failed (${S.status})`});return}let R=await S.json();h.set(C,{kind:"ok",product:R})}catch(S){h.set(C,{kind:"error",message:S instanceof Error?S.message:"Failed to load product"})}})),h};return(async()=>{let g=ne(),h=await m(g);if(g){let T=[...h.values()].filter(V=>V.kind==="ok"),M=T.filter(V=>V.product.base_currency);M.length>0&&M.length<T.length&&(h=await m(null))}if(_)return;let C=null,S=null,R=null;for(let T of d){let M=h.get(T);!M||M.kind!=="ok"||(C===null&&M.product.shipping_rates&&(C=M.product.shipping_rates),S===null&&M.product.free_shipping_over!=null&&(S=M.product.free_shipping_over),R===null&&M.product.shipping_countries&&(R=M.product.shipping_countries))}let O={},$=new Map,J=null;for(let T of s){let M=h.get(T.productId);if(!M||M.kind==="error"){O[T.variantId]=vn,M&&J===null&&(J=M.message);continue}if(M.kind==="not_found"){O[T.variantId]=rt;continue}let{product:V}=M;if(!V.active||V.purchasable===!1){O[T.variantId]=rt;continue}let te=V.variants??[],q=te.find(ie=>ie.id===T.variantId)??null,Y=T.variantId;if(!q){let ie=ke(te,T.selection);if(!ie){O[T.variantId]=rt;continue}let xt=$.get(T.variantId)??{};xt.reanchorTo={variantId:ie.id,selection:kn(ie)},$.set(T.variantId,xt),p.current.add(ie.id),q=ie,Y=ie.id}let N=Ae(V,T.selection)[0]??null,E={image:N,unitAmount:q.unit_amount,currency:q.currency,baseCurrency:V.base_currency??null,inStock:q.in_stock,available:q.available,maxQuantity:V.max_quantity,pdpSearch:Me(V,T.selection),status:p.current.has(Y)?"reanchored":"ok"};O[T.variantId]=E,O[Y]=E;let F=$.get(T.variantId)??{};F.display={name:V.name,variantTitle:q.title,image:N},$.set(T.variantId,F)}let B=new Set(s.map(T=>T.variantId));for(let T of[...p.current])!B.has(T)&&!(T in O)&&p.current.delete(T);if($.size>0){let T=Ce(),M=[],V=new Map,te=!1;for(let q of T){let Y=$.get(q.variantId),N={...q};Y?.reanchorTo&&(N.variantId=Y.reanchorTo.variantId,N.selection=Y.reanchorTo.selection,te=!0),Y?.display&&(N.display.name!==Y.display.name||N.display.variantTitle!==Y.display.variantTitle||N.display.image!==Y.display.image)&&(N.display=Y.display,te=!0);let E=V.get(N.variantId);if(E){E.quantity+=N.quantity,te=!0;continue}M.push(N),V.set(N.variantId,N)}te&&fe(M)}_||(i(O),f({shippingRates:C,freeShippingOver:S,shippingCountries:R}),c(J),u(!1))})(),()=>{_=!0}},[n,A,t,x]);let b=(0,G.useMemo)(()=>r.map(_=>{let s=o[_.variantId];return s?{..._,...s,image:s.image??_.display.image}:{..._,image:_.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:P}=(0,G.useMemo)(()=>{let _=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(_+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:_,currency:s}},[b]);return{lines:b,subtotal:a,currency:P,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:v,refresh:w}}var Z=require("react");var Cn=2e3;function $t(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=ye(),[l,f]=(0,Z.useState)(null),[y,u]=(0,Z.useState)(!1),[v,c]=(0,Z.useState)(null),[x,k]=(0,Z.useState)(null),[p,A]=(0,Z.useState)(0);(0,Z.useEffect)(()=>(k(ne()),Te(()=>k(ne()))),[]);let w=(0,Z.useMemo)(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=(0,Z.useCallback)(()=>A(s=>s+1),[]),a=(0,Z.useRef)(0),P=(0,Z.useRef)(!1),_=(0,Z.useRef)("idle");return(0,Z.useEffect)(()=>{if(!i)return;if(o.length===0){f(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,m=!1,g,h=P.current?r:0;P.current=!0,_.current=_.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{u(!0);try{let S=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:d.signal,body:JSON.stringify({items:o.map(O=>({variant_id:O.variantId,quantity:O.quantity})),...x?{country:x}:{},...n?{shipping_option:n}:{}})});if(m||s!==a.current)return;if(!S.ok){if(S.status===429){let O=_.current==="idle";O&&(g=setTimeout(()=>{m||s!==a.current||(_.current="pending",A($=>$+1))},Cn)),c(O?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else c(`Could not price this cart (${S.status})`);return}let R=await S.json();if(m||s!==a.current)return;f({currency:R.currency,subtotal:R.subtotal,shipping:R.shipping?{options:R.shipping.options.map(O=>({label:O.label,amount:O.amount,undiscountedAmount:O.undiscounted_amount})),selectedAmount:R.shipping.selected_amount,selectedLabel:R.shipping.selected_label,freeShippingOver:R.shipping.free_shipping_over,freeShippingCurrency:R.shipping.free_shipping_currency,thresholdMet:R.shipping.threshold_met,collectsAddress:R.shipping.collects_address}:null,total:R.total,totalIsFinal:R.total_is_final,tax:R.tax??null,unavailableVariantIds:R.unavailable_variant_ids}),c(null)}catch(S){if(m||d.signal.aborted||s!==a.current)return;c(S instanceof Error?S.message:"Could not price this cart")}finally{!m&&s===a.current&&u(!1)}},h);return()=>{m=!0,clearTimeout(C),g!==void 0&&clearTimeout(g),d.abort()}},[i,w,x,t,r,n,p]),{summary:l,loading:y,error:v,refresh:b}}var re=require("react");function ot(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,re.useState)(!1),[o,i]=(0,re.useState)(null),[l,f]=(0,re.useState)(null),[y,u]=(0,re.useState)(null),v=(0,re.useRef)(!1),c=(0,re.useRef)(null);return(0,re.useEffect)(()=>{let k=p=>{p.persisted&&(v.current=!1,n(!1))};return window.addEventListener("pageshow",k),()=>window.removeEventListener("pageshow",k)},[]),(0,re.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let k=p=>{if(p.source!==window.parent)return;let A=p.data;if(A?.type!=="aifeatures:test-checkout-ack"||A.status!=="failed")return;let w=c.current;w===null||!tt(A,w)||(c.current=null,i(typeof A.error=="string"&&A.error?A.error:"The test purchase could not be created."),v.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:(0,re.useCallback)(async(k,{successUrl:p,cancelUrl:A,customerEmail:w,metadata:b,shippingOption:a}={})=>{if(!v.current){v.current=!0,n(!0),i(null),f(null),u(null);try{let P=ne(),_=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:k.map(d=>({variant_id:d.variantId,quantity:d.quantity,...typeof d.unitAmount=="number"&&typeof d.currency=="string"?{expected_unit_amount:d.unitAmount,expected_currency:d.currency}:{}})),...P!==null?{country:P}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...w!==void 0?{customer_email:w}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:A??window.location.href})}),s=await _.json().catch(()=>null);if(!_.ok){if(s?.code==="shipping_option_unavailable"&&typeof s.requested=="string"&&Array.isArray(s.available)){u({requested:s.requested,available:s.available,currency:typeof s.currency=="string"?s.currency:""}),v.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let m of s.items)m&&typeof m.variant_id=="string"&&(d[m.variant_id]=m);f(d),v.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=$e();if(c.current=d,await St({items:k.map(g=>({productId:g.productId,variantId:g.variantId,quantity:g.quantity})),...w!==void 0?{customerEmail:w}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${_.status})`),v.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),v.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=s.url;return}catch{if(window.open(s.url,"_blank")){v.current=!1,n(!1);return}}window.location.href=s.url}catch(P){i(P instanceof Error?P.message:"Checkout failed"),v.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}var he=require("react");var st=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function Dt(e){return e?st.find(t=>t.country===e.toUpperCase())?.currency??null:null}var Bt=new Map;function wn(e){let t=Bt.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),Bt.set(e,t)),t}function Ft(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,he.useState)(null),[o,i]=(0,he.useState)(!1),[l,f]=(0,he.useState)(null);(0,he.useEffect)(()=>{let c=()=>n(ne());return c(),i(!0),Te(c)},[]),(0,he.useEffect)(()=>{let c=!1;return wn(t).then(x=>{c||f(x)}),()=>{c=!0}},[t]);let y=(0,he.useCallback)(c=>{It(c)},[]),u=Dt(l),v=o&&u!==null&&u!==Dt(r);return{market:r,suggestedCountry:l,setMarket:y,markets:st,shouldPrompt:v}}var Le=require("react/jsx-runtime"),Pn={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function zt({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:f,loading:y}=ve(e,{apiUrl:r});if(y||!f)return null;let u=be(f),v=t!==void 0?u.find(x=>x.id===t)??null:f.options.length===0?u[0]??null:null;if(v){if(v.unit_amount===null)return null;let x=v.compare_at_amount!==null&&v.compare_at_amount>v.unit_amount;return(0,Le.jsxs)("span",{className:o,style:i,children:[x&&(0,Le.jsx)("span",{className:l,style:l?void 0:Pn,children:z(v.compare_at_amount,v.currency,n)}),z(v.unit_amount,v.currency,n)]})}let c=Je(u);return c?(0,Le.jsx)("span",{className:o,style:i,children:c.min===c.max?z(c.min,f.currency,n):`${z(c.min,f.currency,n)} \u2013 ${z(c.max,f.currency,n)}`}):f.unit_amount===null?null:(0,Le.jsx)("span",{className:o,style:i,children:z(f.unit_amount,f.currency,n)})}var ae=require("react");var se=require("react/jsx-runtime"),_n={marginBottom:"0.75rem"},xn={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},Rn={display:"flex",flexWrap:"wrap",gap:"0.5rem"},An={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},On={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},jt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},Tn={...jt,cursor:"pointer"},Ln=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,In=e=>Ln.test(e),En={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},Un={display:"block",width:"1.5rem",height:"1.5rem",maxWidth:"100%",maxHeight:"100%",boxSizing:"border-box",borderRadius:3,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f3f4f6",border:"1px solid rgba(0, 0, 0, 0.2)"},Nn="linear-gradient(to top right, transparent calc(50% - 2px), rgba(0,0,0,0.55) calc(50% - 2px), rgba(255,255,255,0.95) calc(50% - 1px), rgba(255,255,255,0.95) calc(50% + 1px), rgba(0,0,0,0.55) calc(50% + 1px), transparent calc(50% + 2px))";function Kt({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:f,optionClassName:y,optionLabelClassName:u,valueClassName:v,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[A,w]=(0,ae.useState)(r??{}),b=p?r:A,[a,P]=(0,ae.useState)(()=>new Set),_=h=>P(C=>C.has(h)?C:new Set(C).add(h));(0,ae.useEffect)(()=>{P(h=>h.size===0?h:new Set)},[e]);let s=(0,ae.useRef)(!1);(0,ae.useEffect)(()=>{if(!n||p||s.current||e.length===0||typeof window>"u"||(s.current=!0,Object.keys(A).length>0))return;let h=Ge({options:e},window.location.search);Object.keys(h).length!==0&&(w(h),o?.(h))},[n,p,e]);let d=(0,ae.useMemo)(()=>e.length>0?t.filter(h=>h.option_values.length===e.length):t,[t,e]),m=(0,ae.useRef)(void 0);if((0,ae.useEffect)(()=>{let h=ke(d,b),C=h?.id??null;m.current!==C&&(m.current=C,i?.(h))},[d,b]),e.length===0)return null;let g=(h,C)=>{let S=He(d,b,h,C);p||(w(S),n&&Ze({options:e},S)),o?.(S)};return(0,se.jsx)("div",{className:l,style:f,children:e.map(h=>(0,se.jsxs)("div",{className:y,style:y?void 0:_n,children:[(0,se.jsx)("span",{className:u,style:u?void 0:xn,children:h.title}),(0,se.jsx)("div",{style:Rn,children:h.values.map(C=>{let S=b[h.id]===C.id,R=Ye(d,b,h.id,C.id),O=R||We(d,h.id,C.id),$=[v,S?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,J=C.swatch??null,B=J&&!a.has(J)?J:null,T=B?In(B):!1,M=v?void 0:{...An,...S?On:{},...R?{}:O?Tn:jt,...B?{...En,textDecoration:"none"}:{}},V=R?C.value:`${C.value} \u2014 unavailable with your current selection`;return(0,se.jsx)("button",{type:"button",className:$,style:M,disabled:!O,"aria-pressed":S,"aria-label":B?V:void 0,title:B?V:void 0,"data-selected":S?"true":void 0,"data-available":R?"true":"false","data-swatch":B?T?"hex":"image":void 0,onClick:()=>g(h.id,C.id),children:B?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)("span",{"aria-hidden":"true",className:k,style:k?void 0:{...Un,...T?{background:B}:{},...T&&R?{}:{backgroundImage:[...R?[]:[Nn],...T?[]:[`url(${JSON.stringify(B)})`]].join(", ")}}}),T?null:(0,se.jsx)("img",{src:B,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>_(B)})]}):C.value},C.id)})})]},h.id))})}var Wt=require("react");function at(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}var W=require("react/jsx-runtime"),Mn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Vn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function Yt(){return(0,W.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,W.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,W.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,W.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Ht({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,apiUrl:u,disabled:v,className:c,style:x,errorClassName:k,spinner:p=!0,children:A}){let{product:w,loading:b,error:a,refresh:P}=ve(e,{apiUrl:u}),{startCheckout:_,loading:s,error:d,priceChange:m}=nt({apiUrl:u});(0,Wt.useEffect)(()=>{m&&P()},[m,P]);let g=w!==null&&!w.payments_ready&&!at(),h=w!==null&&!w.active,C=w!==null&&w.purchasable===!1,S=w!==null&&Re(w),R=w!==null?be(w):[],O=t!==void 0?R.find(E=>E.id===t)??null:!S&&R.length===1?R[0]:null,$=S&&!O,J=O!==null&&!O.in_stock,B=n??void 0,T=w?.subscription??null,M=T!==null&&T.required&&!T.ready,V=T!==null&&T.required&&T.ready&&B===void 0,te=!!v||b||!w||g||h||C||M||V||$||J||s,q;s?q=(0,W.jsxs)(W.Fragment,{children:[p&&(0,W.jsx)(Yt,{}),"Processing\u2026"]}):b?q=(0,W.jsxs)(W.Fragment,{children:[p&&(0,W.jsx)(Yt,{}),A??"Buy now"]}):g?q="Payments not set up":h||C?q="Unavailable":M?q="Currently unavailable":V?q="Select a plan":$?q="Select options":J?q="Out of stock":A!==void 0?q=A:B!==void 0?q="Subscribe":q="Buy now";let Y=d??a;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)("button",{type:"button",className:c,style:x,disabled:te,onClick:()=>{let E=o===void 0&&B===void 0&&ne()===null&&O!==null&&!O.allow_custom_amount&&typeof O.unit_amount=="number"?{expectedUnitAmount:O.unit_amount,expectedCurrency:O.currency}:{};_({productId:e,variantId:t,quantity:B!==void 0?void 0:r,amount:o,planId:B,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,...E})},children:q}),Y&&(0,W.jsxs)("div",{role:"alert",className:k,style:k?void 0:Mn,children:[Y,w===null&&!b&&a!==null&&(0,W.jsx)("button",{type:"button",onClick:P,style:Vn,children:"Tap to retry"})]})]})}var _e=require("react");var Q=require("react/jsx-runtime"),qn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},$n={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Dn=1500;function Bn(){return(0,Q.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,Q.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,Q.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,Q.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Fn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Jt({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:f,errorClassName:y,spinner:u=!0,children:v}){let{product:c,loading:x,error:k,refresh:p}=ve(e,{apiUrl:o}),{add:A}=ye(),[w,b]=(0,_e.useState)(!1),[a,P]=(0,_e.useState)(!1),_=(0,_e.useRef)(void 0);(0,_e.useEffect)(()=>()=>{_.current&&clearTimeout(_.current)},[]);let s=c!==null&&!c.payments_ready&&!at(),d=c!==null&&!c.active,m=c!==null&&c.purchasable===!1,g=c!==null&&!x&&be(c).length===0,h=c!==null&&c.allow_custom_amount,C=c!==null&&c.subscription?.required===!0,S=c!==null&&Re(c),R=c!==null?be(c):[],O=t!==void 0?R.find(q=>q.id===t)??null:r!==void 0&&S?ke(R,r):!S&&R.length===1?R[0]:null,$=c!==null&&!g&&!O,J=O!==null&&!O.in_stock,B=!!i||x||!c||s||d||m||g||h||C||$||J,T=()=>{if(!c||!O)return;let q=r??Fn(O);if(!A({productId:e,variantId:O.id,quantity:n,selection:q,display:{name:c.name,variantTitle:O.title,image:Ae(c,q)[0]??null}}).ok){b(!0);return}b(!1),P(!0),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>P(!1),Dn)},M;x?M=(0,Q.jsxs)(Q.Fragment,{children:[u&&(0,Q.jsx)(Bn,{}),v??"Add to cart"]}):s?M="Payments not set up":d||m||g||h?M="Unavailable":C?M="Subscription only":$?M="Select options":J?M="Out of stock":a?M="Added to cart":v!==void 0?M=v:M="Add to cart";let V=w?"Your cart is full \u2014 remove an item before adding another.":k;return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)("button",{type:"button",className:l,style:f,disabled:B,"data-added":a?"true":void 0,onClick:T,children:M}),V&&(0,Q.jsxs)("div",{role:"alert",className:y,style:y?void 0:qn,children:[V,c===null&&!x&&k!==null&&!w&&(0,Q.jsx)("button",{type:"button",onClick:p,style:$n,children:"Tap to retry"})]})]})}var H=require("react/jsx-runtime"),Gt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function Zt(){return(0,H.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,H.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,H.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,H.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Qt({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:f,style:y,errorClassName:u,spinner:v=!0,children:c}){let{items:x,hydrated:k}=ye(),{lines:p}=it({apiUrl:e}),{startCheckout:A,loading:w,error:b,conflicts:a}=ot({apiUrl:e}),P=k&&x.length===0,_=p.some(g=>g.status==="unavailable"),s=!!l||!k||P||_||w,d;w?d=(0,H.jsxs)(H.Fragment,{children:[v&&(0,H.jsx)(Zt,{}),"Processing\u2026"]}):k?P?d="Cart is empty":_?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=(0,H.jsxs)(H.Fragment,{children:[v&&(0,H.jsx)(Zt,{}),c??"Checkout"]});let m=a?Object.keys(a).length:0;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("button",{type:"button",className:f,style:y,disabled:s,onClick:()=>A(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),m>0&&(0,H.jsx)("div",{role:"alert",className:u,style:u?void 0:Gt,children:m===1?"An item in your cart changed \u2014 please review your cart and try again.":`${m} items in your cart changed \u2014 please review your cart and try again.`}),b&&(0,H.jsx)("div",{role:"alert",className:u,style:u?void 0:Gt,children:b})]})}var ue=require("react");var I=require("react/jsx-runtime"),kt="af_order_confirmation_session",zn=1800*1e3;function Xt({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:f=1500,renderNoSession:y,renderPending:u,renderPaid:v,renderFailed:c}){let[x,k]=(0,ue.useState)(n),[p,A]=(0,ue.useState)(null),[w,b]=(0,ue.useState)(!1),a=(0,ue.useRef)(void 0);(0,ue.useEffect)(()=>{if(n!==void 0){k(n);return}if(a.current!==void 0){k(a.current);return}let d=new URL(window.location.href),m=d.searchParams.get("session_id");if(m){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(kt,JSON.stringify({id:m,ts:Date.now()}))}catch{}}else try{let g=sessionStorage.getItem(kt);if(g){let h=JSON.parse(g);typeof h.id=="string"&&typeof h.ts=="number"&&Date.now()-h.ts<=zn?m=h.id:sessionStorage.removeItem(kt)}}catch{}a.current=m,k(m)},[n]),(0,ue.useEffect)(()=>{if(!x)return;let d=!1,m,g=Date.now(),h=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(C.ok){let S=await C.json();if(d||(A(S),S.status!=="pending"))return}}catch{}if(!d){if(Date.now()-g>=i){b(!0);return}m=setTimeout(h,o)}};return h(),()=>{d=!0,m&&clearTimeout(m)}},[x,e,o,i]);let P=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),_=(0,ue.useRef)(!1);(0,ue.useEffect)(()=>{if(!x||p===null||_.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(_.current=!0,!Et(x)))return;let m=(p.line_items??[]).filter(g=>typeof g.variant_id=="string"&&g.variant_id.length>0).map(g=>({variantId:g.variant_id,quantity:g.quantity}));m.length>0&&Lt(m)},[x,p]);let s=P&&p.fulfillment.type==="redirect"?p.fulfillment.redirect_url:void 0;if((0,ue.useEffect)(()=>{if(!s||!l)return;let d=setTimeout(()=>{window.location.href=s},f);return()=>clearTimeout(d)},[s,l,f]),x===void 0)return null;if(x===null)return y?(0,I.jsx)(I.Fragment,{children:y()}):(0,I.jsxs)("div",{className:t,style:r,children:[(0,I.jsx)("h2",{children:"Thank you for your order!"}),(0,I.jsx)("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!p||p.status==="pending")return u?(0,I.jsx)(I.Fragment,{children:u({timedOut:w})}):(0,I.jsx)("div",{className:t,style:r,role:"status",children:(0,I.jsx)("p",{children:w?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(P){if(v)return(0,I.jsx)(I.Fragment,{children:v(p)});let{fulfillment:d}=p,m=p.amount_total!==void 0&&p.currency?z(p.amount_total,p.currency):null,g=d.files??[],h=g.length===0?d.download_url:void 0;return(0,I.jsxs)("div",{className:t,style:r,children:[(0,I.jsx)("h2",{children:"Thank you for your purchase!"}),p.is_test&&(0,I.jsxs)("p",{children:[(0,I.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),p.line_items&&p.line_items.length>0&&(0,I.jsx)("ul",{children:p.line_items.map((C,S)=>(0,I.jsxs)("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&(0,I.jsx)("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},S))}),m&&(0,I.jsxs)("p",{children:["Total paid: ",m]}),p.source==="subscription"&&p.subscription&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("p",{children:["Your subscription renews"," ",p.subscription.interval_count>1?`every ${p.subscription.interval_count} ${p.subscription.interval}s`:`every ${p.subscription.interval}`," ","at"," ",z(p.subscription.amount,p.subscription.currency),"."]}),(0,I.jsxs)("p",{children:["You can view, update, or cancel it any time on"," ",(0,I.jsx)("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),g.length>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)("p",{children:"Your downloads:"}),(0,I.jsx)("ul",{children:g.map((C,S)=>(0,I.jsx)("li",{children:(0,I.jsx)("a",{href:C.download_url,children:C.name})},S))})]}),h&&(0,I.jsx)("p",{children:(0,I.jsx)("a",{href:h,children:"Download your file"})}),s?(0,I.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,I.jsx)("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?(0,I.jsx)("p",{children:(0,I.jsx)("a",{href:d.redirect_url,children:"Continue to your content"})}):null,g.length===0&&!h&&!d.redirect_url&&(0,I.jsx)("p",{children:"A confirmation email is on its way to you."}),typeof p.order_number=="number"?(0,I.jsxs)("p",{children:["Order ",(0,I.jsxs)("strong",{children:["#",p.order_number]})," \u2014 keep this if you ever need help with your order."]}):p.order_id?(0,I.jsxs)("p",{children:["Order reference: ",(0,I.jsx)("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]}):null]})}return c?(0,I.jsx)(I.Fragment,{children:c(p)}):(0,I.jsx)("div",{className:t,style:r,children:(0,I.jsx)("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}var ut=require("react");var Se=require("react/jsx-runtime");function wt(e,t){if(t.unit_amount!==null&&t.unit_amount!==void 0)return t.unit_amount;let r=t.percent_off_bps??0;return e-Math.floor(e*r/1e4)}function Ct(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var jn={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},Kn={display:"block",width:"100%",textAlign:"left",padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Yn={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600};function en({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:f,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:v,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,A=k?.ready===!0,w=[...k?.plans??[]].sort((S,R)=>S.position-R.position),[b,a]=(0,ut.useState)(null),P=o!==void 0,_=P?o:b,s=w.map(S=>S.id).join("|"),d=w.length>0?w[0].id:null;if((0,ut.useEffect)(()=>{if(!(!p||!A)&&!(_!==null&&w.some(S=>S.id===_))){if(d===null){if(_===null)return;P||a(null),i?.(null);return}P||a(d),i?.(d)}},[p,A,d,s,_,P]),!k)return null;if(!A)return p?x?(0,Se.jsx)(Se.Fragment,{children:x()}):(0,Se.jsx)("div",{className:l,style:f,"data-state":"unavailable",children:(0,Se.jsx)("p",{children:"This product is currently unavailable."})}):null;if(w.length===0)return null;let m=e?.base_currency!==void 0&&e?.base_currency!==null,g=r!==void 0?r:m?null:e?.unit_amount??null,h=n??e?.base_currency??e?.currency??"usd",C=[];if(!p){let S=g;C.push({plan:null,selected:_===null,price:S,priceLabel:S!==null?z(S,h):null,label:"One-time purchase",select:()=>{P||a(null),i?.(null)}})}for(let S of w){let R=S.unit_amount!==null?S.unit_amount:g!==null?wt(g,S):null,O=R!==null?z(R,h):null,$=S.title&&S.title.trim().length>0?S.title.trim():`Subscribe ${Ct(S)}`,J=O?`${$} \u2014 ${O} ${Ct(S)}`:`${$} \u2014 billed ${Ct(S)}`;C.push({plan:S,selected:_===S.id,price:R,priceLabel:O,label:J,select:()=>{P||a(S.id),i?.(S.id)}})}return(0,Se.jsx)("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?f:{...jn,...f},children:C.map(S=>{if(c)return(0,Se.jsx)("span",{style:{display:"contents"},children:c(S)},S.plan?.id??"one-time");let R=S.selected;return(0,Se.jsx)("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":S.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...Kn,...R?Yn:{}},onClick:S.select,children:S.plan===null&&v!==void 0?v:S.plan===null?S.priceLabel?`One-time purchase \u2014 ${S.priceLabel}`:"One-time purchase":S.label},S.plan?.id??"one-time")})})}var X=require("react");async function de(e,t,r={}){let n;try{n=await fetch(`${e}${t}`,{method:r.method??"GET",headers:{...r.body!==void 0?{"Content-Type":"application/json"}:{},...r.token?{Authorization:`Bearer ${r.token}`}:{}},...r.body!==void 0?{body:JSON.stringify(r.body)}:{}})}catch(u){return{ok:!1,failure:{kind:"network",error:u instanceof Error?u.message:"Network error"}}}let o=await n.text().catch(()=>""),i=null;try{i=o?JSON.parse(o):null}catch{i=null}let l=typeof i=="object"&&i!==null?i:null;if(n.ok)return l===null?{ok:!1,failure:{kind:"parse_error",error:"The server sent an unreadable response \u2014 please try again"}}:{ok:!0,data:l};if(n.status===404&&o.trim()==="")return{ok:!1,failure:{kind:"unavailable"}};let f=typeof l?.code=="string"?l.code:null,y=typeof l?.error=="string"&&l.error?l.error:`Request failed (${n.status})`;return n.status===401?{ok:!1,failure:{kind:"unauthorized",code:f,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:f,error:y}}}function tn(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function De(e){if(!e)return null;let t=e.includes("T")?e:e.replace(" ","T")+"Z",r=Date.parse(t);if(Number.isNaN(r))return null;try{return new Date(r).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{return null}}var Wn=1500;function nn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function Hn(e,t){return e.requestId===t}function Jn(e,t){return typeof window>"u"||!nn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;if(y?.type==="aifeatures:preview-session-ack"&&Hn(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let v=y.customer;typeof v.email=="string"&&(u={email:v.email,name:typeof v.name=="string"?v.name:null})}o({claimed:!0,token:y.token,customer:u});return}o({claimed:!0,token:null,customer:null,error:typeof y.error=="string"&&y.error?y.error:"The preview sign-in could not be created."})}},l=setTimeout(()=>o({claimed:!1}),Wn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ie(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,X.useState)(()=>Pe()),[o,i]=(0,X.useState)(null),[l,f]=(0,X.useState)(!1),[y,u]=(0,X.useState)(!1),v=(0,X.useRef)(void 0);(0,X.useEffect)(()=>Mt(()=>{let b=Pe();n(b),i(b===null?a=>Ut()??a:null)}),[]);let c=(0,X.useCallback)(async b=>{u(!0);try{let a=await de(t,"/v1/account/verify",{method:"POST",body:{code:b}});if(a.ok&&typeof a.data.token=="string"){let _=a.data.customer&&typeof a.data.customer.email=="string"?{email:a.data.customer.email,name:typeof a.data.customer.name=="string"?a.data.customer.name:null}:null;return et({token:a.data.token,customer:_}),n({token:a.data.token,customer:_}),i(null),f(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):!a.ok&&a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:!a.ok&&(a.failure.kind==="http"||a.failure.kind==="unauthorized")&&a.failure.code==="invalid_code"?(i("invalid_code"),{ok:!1,code:"invalid_code",error:a.failure.error}):{ok:!1,code:"error",error:a.ok||a.failure.kind==="unavailable"?"Sign-in failed \u2014 please request a new link.":a.failure.error}}finally{u(!1)}},[t]),x=e.consumeUrlCode??!0;(0,X.useEffect)(()=>{if(!(typeof window>"u")&&v.current===void 0){if(!x){v.current=null;return}let b=new URL(window.location.href),a=b.searchParams.get("code");a&&(b.searchParams.delete("code"),window.history.replaceState(window.history.state,"",b.toString())),v.current=a,a&&c(a)}},[c,x]);let k=(0,X.useCallback)(async b=>{if(typeof window<"u"&&nn(window)){let P=await Jn(b,$e());if(P.claimed){if(P.token!==null){let _=P.customer??{email:b,name:null};return et({token:P.token,customer:_}),n({token:P.token,customer:_}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:P.error}}}let a=await de(t,"/v1/account/login",{method:"POST",body:{email:b}});return a.ok?{ok:!0,via:"email"}:a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:{ok:!1,code:"error",error:(a.failure.kind==="network",a.failure.error)}},[t]),p=(0,X.useCallback)(async()=>{let b=Pe()?.token;b&&await de(t,"/v1/account/logout",{method:"POST",token:b,body:{}}),me(),n(null),i(null)},[t]),A=(0,X.useCallback)(async()=>{let b=Pe();if(!b)return;let a=await de(t,"/v1/account/me",{token:b.token}),P=()=>Pe()?.token===b.token;if(a.ok){if(!P())return;let _=a.data.customer??b.customer;et({token:b.token,customer:_}),n({token:b.token,customer:_}),f(!1);return}if(a.failure.kind==="unauthorized"){if(!P())return;me("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){f(!0);return}},[t]);return{status:y?"pending":r?"signed_in":l?"unavailable":"signed_out",customer:r?.customer??null,token:r?.token??null,reason:r?null:o,login:k,verifyCode:c,logout:p,refresh:A}}var j=require("react");var le=require("react");var D=require("react/jsx-runtime"),Pt={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},Gn={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},Zn={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},rn={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Ee={margin:0},Qn={color:"#b91c1c",margin:0};function Be({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:f}){let y=Ie({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[v,c]=(0,le.useState)(""),[x,k]=(0,le.useState)("form"),[p,A]=(0,le.useState)(!1),[w,b]=(0,le.useState)(null),[a,P]=(0,le.useState)(null),[_,s]=(0,le.useState)(!1),d=(0,le.useRef)(void 0),m=(0,le.useRef)(!1);(0,le.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]);let g=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},h=async()=>{let R=v.trim();if(!R||p||m.current)return;m.current=!0,A(!0),b(null),P(null);let O=await u.login(R);if(m.current=!1,A(!1),O.ok){if(O.via==="preview")return;k("sent"),g();return}O.code!=="unavailable"&&(b(O.code==="rate_limited"?"rate_limited":"error"),P(O.error))};if(u.status==="unavailable")return f?(0,D.jsx)(D.Fragment,{children:f()}):(0,D.jsx)("div",{className:n,style:n?o:{...Pt,...o},"data-state":"unavailable",children:(0,D.jsx)("p",{style:Ee,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:v.trim(),canResend:_,resend:()=>{h(),g()},submitting:p,reset:()=>k("form")};return l?(0,D.jsx)(D.Fragment,{children:l(R)}):(0,D.jsxs)("div",{className:n,style:n?o:{...Pt,...o},"data-state":"sent",children:[(0,D.jsxs)("p",{style:Ee,children:["Check your email \u2014 if ",(0,D.jsx)("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),_?(0,D.jsxs)("p",{style:Ee,children:["Didn't get it?"," ",(0,D.jsx)("button",{type:"button",style:rn,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",(0,D.jsx)("button",{type:"button",style:rn,onClick:R.reset,children:"use a different email"}),"."]}):(0,D.jsx)("p",{style:Ee,children:"It can take a minute to arrive."})]})}let C={email:v,setEmail:c,submit:()=>void h(),submitting:p,errorKind:w,errorMessage:a,reason:u.reason};if(i)return(0,D.jsx)(D.Fragment,{children:i(C)});let S=R=>{R.preventDefault(),C.submit()};return(0,D.jsxs)("form",{className:n,style:n?o:{...Pt,...o},onSubmit:S,"data-state":"form",children:[u.reason==="session_expired"&&(0,D.jsx)("p",{style:Ee,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&(0,D.jsx)("p",{style:Ee,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),(0,D.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[(0,D.jsx)("span",{children:"Email address"}),(0,D.jsx)("input",{type:"email",value:v,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:Gn})]}),(0,D.jsx)("button",{type:"submit",style:Zn,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&(0,D.jsx)("p",{style:Qn,role:"alert",children:w==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}var K=require("react/jsx-runtime"),Xn={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},er={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},Fe={color:"#6b7280",fontSize:"0.875rem"};function tr(e){switch(e.status){case"paid":return null;case"refunded":return"Refunded";case"partially_refunded":return"Partially refunded";case"disputed":return"Disputed";default:return e.status}}function lt({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?(0,K.jsx)(K.Fragment,{children:o()}):(0,K.jsxs)("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&(0,K.jsx)("h3",{children:n}),(0,K.jsx)("p",{style:Fe,children:"No orders yet."})]}):(0,K.jsxs)("div",{className:t,style:r,children:[n!==null&&(0,K.jsx)("h3",{children:n}),(0,K.jsx)("ul",{style:t?void 0:Xn,children:e.map(l=>{if(i)return(0,K.jsx)("li",{style:{display:"contents"},children:i(l)},l.id);let f=De(l.created_at),y=tr(l);return(0,K.jsxs)("li",{style:t?void 0:er,children:[(0,K.jsxs)("div",{children:[l.order_number!==null&&(0,K.jsxs)("strong",{children:["Order #",l.order_number]})," ",f&&(0,K.jsx)("span",{style:Fe,children:f})," ",l.source==="subscription"&&(0,K.jsx)("span",{style:Fe,children:"\xB7 subscription"}),y&&(0,K.jsxs)("span",{style:Fe,children:[" \xB7 ",y]})]}),l.line_items.length>0&&(0,K.jsx)("div",{style:Fe,children:l.line_items.map(u=>u.name?`${u.quantity&&u.quantity>1?`${u.quantity} \xD7 `:""}${u.name}`:null).filter(Boolean).join(", ")}),(0,K.jsx)("div",{children:z(l.amount_total,l.currency)})]},l.id)})})]})}var ee=require("react");var U=require("react/jsx-runtime"),nr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},rr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},Ue={color:"#6b7280",fontSize:"0.875rem"},ir={color:"#b91c1c",fontSize:"0.875rem",margin:0},or={color:"#065f46",fontSize:"0.875rem",margin:0},_t={display:"flex",flexWrap:"wrap",gap:"0.5rem"},xe={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},sn={...xe,border:"1px solid #111827",background:"#111827",color:"white"},sr={...xe,border:"1px solid #b91c1c",color:"#b91c1c"},ar={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},on={panel:"none",mutation:null,portalRefused:!1};function ur(e){let t=De(e.current_period_end);return e.ended?{text:"This subscription has ended.",tone:"ended"}:e.cancel_at_period_end?{text:t?`Scheduled to cancel \u2014 stays active until ${t}.`:"Scheduled to cancel at the end of the current period.",tone:"warn"}:e.status==="past_due"||e.status==="unpaid"?{text:"There's a problem with your last payment \u2014 please update your card.",tone:"warn"}:e.status==="active"||e.status==="trialing"?{text:t?`Renews on ${t}.`:"Active.",tone:"ok"}:{text:`Status: ${e.status}.`,tone:"warn"}}function lr({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=(0,ee.useState)(e?.name??""),[f,y]=(0,ee.useState)(o?.line1??""),[u,v]=(0,ee.useState)(o?.line2??""),[c,x]=(0,ee.useState)(o?.city??""),[k,p]=(0,ee.useState)(o?.state??""),[A,w]=(0,ee.useState)(o?.postal_code??""),[b,a]=(0,ee.useState)(o?.country??""),P=(_,s,d,m)=>(0,U.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[(0,U.jsx)("span",{children:_}),(0,U.jsx)("input",{style:ar,value:s,onChange:g=>d(g.target.value),required:m?.required,maxLength:m?.maxLength})]});return(0,U.jsxs)("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:_=>{_.preventDefault(),r({name:i.trim()||null,address:{line1:f.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:A.trim()||null,country:b.trim().toUpperCase()}})},children:[P("Name",i,l),P("Address line 1",f,y,{required:!0}),P("Address line 2",u,v),P("City",c,x),P("State / region",k,p),P("Postal code",A,w),P("Country (2-letter code)",b,a,{required:!0,maxLength:2}),(0,U.jsxs)("div",{style:_t,children:[(0,U.jsx)("button",{type:"submit",style:sn,disabled:t,children:t?"Saving\u2026":"Save address"}),(0,U.jsx)("button",{type:"button",style:xe,onClick:n,disabled:t,children:"Cancel"})]})]})}function ze({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:f,heading:y="Your subscriptions",renderEmpty:u,renderRow:v}){let[c,x]=(0,ee.useState)(t),[k,p]=(0,ee.useState)({}),A=(0,ee.useRef)(new Set);(0,ee.useEffect)(()=>{x(t)},[t]),(0,ee.useEffect)(()=>{let s=d=>{d.persisted&&(A.current.clear(),p(m=>{let g=!1,h={};for(let[C,S]of Object.entries(m))S.mutation?.phase==="pending"?(h[C]={...S,mutation:null},g=!0):h[C]=S;return g?h:m}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let w=(s,d)=>p(m=>({...m,[s]:{...m[s]??on,...d}})),b=s=>{x(d=>d.map(m=>m.id===s.id?s:m)),i?.(s)},a=async(s,d,m,g)=>{if(A.current.has(s.id))return{ok:!1};A.current.add(s.id);try{w(s.id,{mutation:{kind:d,phase:"pending"}});let h=await de(e,m,{method:"POST",token:r.token,body:g??{}});if(h.ok)return{ok:!0,data:h.data};let{failure:C}=h;return C.kind==="unauthorized"?(n?.({code:C.code,error:C.error}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="unavailable"?(o?.(),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="ended"?(b({...s,ended:!0,status:"canceled"}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="portal_unavailable"?(w(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(w(s.id,{mutation:{kind:d,phase:"error",error:C.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":C.error}}),{ok:!1})}finally{A.current.delete(s.id)}},P=s=>r.kind==="session"?{cancel:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/cancel`,reactivate:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/reactivate`,address:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/address`,portal:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/portal-session`}:{cancel:"/v1/account/manage/cancel",reactivate:null,address:null,portal:"/v1/account/manage/portal-session"},_=s=>{let d=k[s.id]??on,m=P(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>w(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>w(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let g=await a(s,"cancel",m.cancel);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:m.reactivate!==null,reactivate:()=>{m.reactivate&&(async()=>{let g=await a(s,"reactivate",m.reactivate);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{m.address&&w(s.id,{panel:"address",mutation:null})},saveAddress:g=>{m.address&&(async()=>{let h=await a(s,"address",m.address,{shipping_address:g});if(h.ok){let C=h.data.subscription;C&&b(C),w(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let g=await a(s,"portal",m.portal);g.ok&&typeof g.data.url=="string"?window.location.href=g.data.url:g.ok&&w(s.id,{mutation:{kind:"portal",phase:"error",error:"Card update is temporarily unavailable."}})})()}}};return c.length===0?u?(0,U.jsx)(U.Fragment,{children:u()}):(0,U.jsxs)("div",{className:l,style:f,"data-state":"empty",children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("p",{style:Ue,children:"No subscriptions."})]}):(0,U.jsxs)("div",{className:l,style:f,children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("ul",{style:l?void 0:nr,children:c.map(s=>{let d=_(s);return v?(0,U.jsx)("li",{style:{display:"contents"},children:v(d)},s.id):(0,U.jsx)("li",{style:l?void 0:rr,"data-status":s.status,"data-ended":s.ended||void 0,children:(0,U.jsx)(cr,{ctx:d})},s.id)})})]})}function cr({ctx:e}){let t=e.subscription,r=ur(t),n=De(t.current_period_end),o=`${z(t.current_amount,t.currency)} ${tn(t.plan_interval,t.plan_interval_count)}`,i=e.mutation?.phase==="pending",l=i?e.mutation?.kind:null;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{children:[(0,U.jsx)("strong",{children:t.plan_title??"Subscription"})," ",(0,U.jsxs)("span",{style:Ue,children:["\xB7 ",o]}),t.is_test&&(0,U.jsx)("span",{style:Ue,children:" \xB7 test"})]}),(0,U.jsx)("div",{style:r.tone==="warn"?void 0:Ue,children:r.text}),t.ended?(0,U.jsx)("p",{style:Ue,children:"This subscription has ended \u2014 to start again, subscribe from the product page."}):e.panel==="confirm_cancel"?(0,U.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[(0,U.jsx)("p",{style:{margin:0},children:n?`Your subscription stays active until ${n} \u2014 after that it won't renew and you won't be charged again.`:"Your subscription stays active until the end of the current billing period \u2014 after that it won't renew and you won't be charged again."}),(0,U.jsxs)("div",{style:_t,children:[(0,U.jsx)("button",{type:"button",style:sr,onClick:e.confirmCancel,disabled:i,children:l==="cancel"?"Canceling\u2026":"Confirm cancellation"}),(0,U.jsx)("button",{type:"button",style:xe,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?(0,U.jsx)(lr,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):(0,U.jsxs)("div",{style:_t,children:[t.cancel_at_period_end?e.reactivateAvailable?(0,U.jsx)("button",{type:"button",style:sn,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):(0,U.jsx)("span",{style:Ue,children:"To keep this subscription, sign in with your email address on this page."}):(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openCancelConfirm,disabled:i,children:"Cancel subscription"}),t.shipping_address!==void 0&&!t.cancel_at_period_end&&(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&(0,U.jsx)("p",{style:ir,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&(0,U.jsx)("p",{style:or,role:"status",children:e.mutation.kind==="cancel"?n?`Cancellation scheduled \u2014 you keep access until ${n}.`:"Cancellation scheduled.":e.mutation.kind==="reactivate"?"Your subscription will continue.":e.mutation.kind==="address"?"Shipping address updated.":"Done."})]})}var L=require("react/jsx-runtime"),dr={display:"flex",flexDirection:"column",gap:"1.25rem"},an={color:"#6b7280",fontSize:"0.875rem"},pr={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},un={color:"#b91c1c"},ct={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function ln({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:f,renderHeader:y,renderPmBanner:u,renderManageExpired:v}){let c=Ie({apiUrl:e}),x=(0,j.useRef)(void 0),[k,p]=(0,j.useState)(null),[A,w]=(0,j.useState)(!1);(0,j.useEffect)(()=>{if(!(typeof window>"u")){if(x.current===void 0){let N=new URL(window.location.href),E=N.searchParams.get("manage_code"),F=N.searchParams.get("pm");(E!==null||F!==null)&&(N.searchParams.delete("manage_code"),N.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",N.toString())),x.current={manageCode:E,pmUpdated:F==="updated"}}p(x.current.manageCode),w(x.current.pmUpdated)}},[]);let[b,a]=(0,j.useState)(null),P=(0,j.useRef)(!1),_=(0,j.useRef)(0),s=(0,j.useCallback)(N=>{a({phase:"verifying"}),(async()=>{let E=await de(e,"/v1/account/manage/verify",{method:"POST",body:{manage_code:N}});if(E.ok&&typeof E.data.manage_token=="string"&&E.data.subscription){a({phase:"active",token:E.data.manage_token,sub:E.data.subscription,siteName:null});return}if(!E.ok&&E.failure.kind==="unavailable"){a({phase:"unavailable"});return}if(!E.ok&&E.failure.kind==="network"){a({phase:"error",error:E.failure.error});return}a({phase:"expired"})})()},[e]);(0,j.useEffect)(()=>{!k||P.current||(P.current=!0,s(k))},[k,s]);let d=(0,j.useCallback)(async()=>{let N=b;if(!N||N.phase!=="active")return;let E=++_.current,F=await de(e,"/v1/account/manage/subscription",{token:N.token});E===_.current&&(F.ok&&F.data.subscription?a({phase:"active",token:N.token,sub:F.data.subscription,siteName:typeof F.data.site?.name=="string"?F.data.site.name:N.siteName}):!F.ok&&F.failure.kind==="unauthorized"?a({phase:"expired"}):!F.ok&&F.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[m,g]=(0,j.useState)({phase:"loading"}),[h,C]=(0,j.useState)(0),S=h>0,R=(0,j.useRef)(0),O=c.token,$=(0,j.useCallback)(async()=>{if(!O)return;let N=++R.current,E=await de(e,"/v1/account/me",{token:O});if(N===R.current){if(E.ok){g({phase:"ready",data:E.data});return}if(E.failure.kind==="unauthorized"){me("session_expired");return}if(E.failure.kind==="unavailable"){me();return}g({phase:"error",error:E.failure.error})}},[e,O]);(0,j.useEffect)(()=>{!O||k||(g({phase:"loading"}),$())},[O,k,$]);let J=(0,j.useCallback)(async()=>{C(N=>N+1);try{b&&b.phase==="active"?await d():await $()}finally{C(N=>N-1)}},[b,d,$]),B=(0,j.useCallback)(N=>{R.current++,_.current++,a(E=>E&&E.phase==="active"&&E.sub.id===N.id?{...E,sub:N}:E),g(E=>E.phase==="ready"?{phase:"ready",data:{...E.data,subscriptions:E.data.subscriptions.map(F=>F.id===N.id?N:F)}}:E)},[]),T=t?r:{...dr,...r},M=N=>{if(!A)return null;let F={state:N.some(ie=>!ie.ended&&(ie.status==="past_due"||ie.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void J(),checking:S};return u?u(F):(0,L.jsx)("div",{style:pr,role:"status","data-pm-state":F.state,children:F.state==="retrying"?(0,L.jsxs)(L.Fragment,{children:[(0,L.jsx)("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),(0,L.jsx)("p",{style:{margin:"0.375rem 0 0"},children:(0,L.jsx)("button",{type:"button",style:ct,onClick:F.checkAgain,disabled:S,children:S?"Checking\u2026":"Check again"})})]}):(0,L.jsx)("p",{style:{margin:0},children:"Card updated \u2014 your subscription is back in good standing."})})};if(k)return!b||b.phase==="verifying"?i?(0,L.jsx)(L.Fragment,{children:i()}):(0,L.jsx)("div",{className:t,style:T,role:"status",children:(0,L.jsx)("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?(0,L.jsxs)("div",{className:t,style:T,children:[M([b.sub]),(0,L.jsx)(ze,{apiUrl:e,subscriptions:[b.sub],auth:{kind:"manage",token:b.token},heading:"Your subscription",onSubscriptionChange:B,onAuthError:()=>a({phase:"expired"}),onUnavailable:()=>a({phase:"unavailable"})})]}):b.phase==="unavailable"?(0,L.jsx)("div",{className:t,style:T,"data-state":"unavailable",children:(0,L.jsx)("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?(0,L.jsxs)("div",{className:t,style:T,children:[(0,L.jsx)("p",{style:un,role:"alert",children:b.error}),(0,L.jsx)("p",{children:(0,L.jsx)("button",{type:"button",style:ct,onClick:()=>s(k),children:"Try again"})})]}):(0,L.jsxs)("div",{className:t,style:T,"data-state":"manage-expired",children:[v?v():(0,L.jsx)("p",{children:"This manage link is no longer valid. Sign in below with the email you used at checkout to manage your subscription."}),(0,L.jsx)(Be,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?(0,L.jsx)(L.Fragment,{children:i()}):(0,L.jsx)("div",{className:t,style:T,role:"status",children:(0,L.jsx)("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return(0,L.jsx)("div",{className:t,style:T,children:(0,L.jsx)(Be,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(m.phase==="loading")return i?(0,L.jsx)(L.Fragment,{children:i()}):(0,L.jsx)("div",{className:t,style:T,role:"status",children:(0,L.jsx)("p",{children:"Loading your account\u2026"})});if(m.phase==="error")return l?(0,L.jsx)(L.Fragment,{children:l({error:m.error,retry:()=>void $()})}):(0,L.jsxs)("div",{className:t,style:T,children:[(0,L.jsxs)("p",{style:un,role:"alert",children:["We couldn't load your account \u2014 ",m.error]}),(0,L.jsx)("p",{children:(0,L.jsx)("button",{type:"button",style:ct,onClick:()=>void $(),children:"Try again"})})]});let{data:V}=m,te=V.customer??c.customer??{email:"",name:null},q=()=>void c.logout(),Y=V.orders.length===0&&V.subscriptions.length===0;return(0,L.jsxs)("div",{className:t,style:T,children:[y?y({customer:te,site:V.site??null,signOut:q}):(0,L.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[(0,L.jsxs)("div",{children:[(0,L.jsx)("h2",{style:{margin:0},children:"Your account"}),(0,L.jsxs)("p",{style:{...an,margin:0},children:["Signed in as ",te.email]})]}),(0,L.jsx)("button",{type:"button",style:ct,onClick:q,children:"Sign out"})]}),M(V.subscriptions),Y?f?f():(0,L.jsxs)("p",{style:an,children:["Nothing here yet \u2014 orders and subscriptions for ",te.email," ","will show up on this page."]}):(0,L.jsxs)(L.Fragment,{children:[V.subscriptions.length>0&&(0,L.jsx)(ze,{apiUrl:e,subscriptions:V.subscriptions,auth:{kind:"session",token:O},onSubscriptionChange:B,onAuthError:()=>me("session_expired"),onUnavailable:()=>me()}),(0,L.jsx)(lt,{orders:V.orders})]})]})}0&&(module.exports={AccountLogin,AccountOrders,AccountPage,AddToCartButton,AifeaturesCaptcha,BuyButton,CartCheckoutButton,MARKET_COUNTRIES,MAX_CART_LINES,OrderConfirmation,PlanPicker,ProductPrice,SubscriptionList,VariantPicker,ZERO_DECIMAL_CURRENCIES,applySelectionToUrl,formatPrice,getOptions,getVariants,isMultiVariant,isValueAvailable,isValueInCatalog,planRecurringAmount,reanchorSelection,resolveVariant,searchFromSelection,selectedImages,selectedValues,selectionFromSearch,useCart,useCartCheckout,useCartItems,useCartSummary,useCheckout,useMarket,useProduct,useSession,valueSlug,variantPriceRange});
|
package/dist/index.d.cts
CHANGED
|
@@ -1121,8 +1121,10 @@ interface BuyButtonProps {
|
|
|
1121
1121
|
* on click, and redirects the buyer to the hosted payment page.
|
|
1122
1122
|
*
|
|
1123
1123
|
* Automatically disabled while the product loads, when the store can't take
|
|
1124
|
-
* payments yet ("Payments not set up"
|
|
1125
|
-
*
|
|
1124
|
+
* payments yet ("Payments not set up" — outside a frame only: inside the
|
|
1125
|
+
* editor preview the click becomes a simulated test purchase instead), when
|
|
1126
|
+
* the product is inactive, and when nothing is purchasable (variant rows
|
|
1127
|
+
* exist but all are deactivated).
|
|
1126
1128
|
* Checkout errors (e.g. the product was deactivated between page load and
|
|
1127
1129
|
* click) render inline after the button with role="alert".
|
|
1128
1130
|
*
|
|
@@ -1172,7 +1174,8 @@ interface AddToCartButtonProps {
|
|
|
1172
1174
|
* no checkout; pair with `<CartCheckoutButton>` on the cart surface.
|
|
1173
1175
|
*
|
|
1174
1176
|
* Automatically disabled while the product loads, when the store can't take
|
|
1175
|
-
* payments, when the product is
|
|
1177
|
+
* payments (outside a frame only — see BuyButton), when the product is
|
|
1178
|
+
* inactive/unpurchasable, until a variant
|
|
1176
1179
|
* resolves, and when the resolved variant is out of stock per the loaded
|
|
1177
1180
|
* data (advisory — the cart surface re-checks with fresh data, and checkout
|
|
1178
1181
|
* is the authority). Custom-amount (tip jar) products, legacy products with
|
|
@@ -1306,7 +1309,22 @@ interface OrderSessionSubscription {
|
|
|
1306
1309
|
interface OrderSession {
|
|
1307
1310
|
status: OrderStatus;
|
|
1308
1311
|
fulfillment: OrderFulfillment;
|
|
1309
|
-
/**
|
|
1312
|
+
/**
|
|
1313
|
+
* The buyer-facing order reference: a small per-site counter ("Order #7"),
|
|
1314
|
+
* and what the receipt email, the merchant's dashboard and the customer's
|
|
1315
|
+
* account history all quote. Prefer it over `order_id` anywhere a human
|
|
1316
|
+
* reads the reference — a buyer quoting the nanoid is quoting a number
|
|
1317
|
+
* nobody else on either side of the sale is looking at.
|
|
1318
|
+
*
|
|
1319
|
+
* Null on orders taken before numbering existed, which is the only reason
|
|
1320
|
+
* `order_id` is still rendered as a fallback.
|
|
1321
|
+
*/
|
|
1322
|
+
order_number?: number | null;
|
|
1323
|
+
/**
|
|
1324
|
+
* The internal order id (a nanoid). It is the idempotency-key source, not a
|
|
1325
|
+
* reference meant for buyers; the receipt email prints it as "Order ID"
|
|
1326
|
+
* only when `order_number` is absent.
|
|
1327
|
+
*/
|
|
1310
1328
|
order_id?: string;
|
|
1311
1329
|
/** True for a simulated owner-initiated test purchase (no money moved). */
|
|
1312
1330
|
is_test?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1121,8 +1121,10 @@ interface BuyButtonProps {
|
|
|
1121
1121
|
* on click, and redirects the buyer to the hosted payment page.
|
|
1122
1122
|
*
|
|
1123
1123
|
* Automatically disabled while the product loads, when the store can't take
|
|
1124
|
-
* payments yet ("Payments not set up"
|
|
1125
|
-
*
|
|
1124
|
+
* payments yet ("Payments not set up" — outside a frame only: inside the
|
|
1125
|
+
* editor preview the click becomes a simulated test purchase instead), when
|
|
1126
|
+
* the product is inactive, and when nothing is purchasable (variant rows
|
|
1127
|
+
* exist but all are deactivated).
|
|
1126
1128
|
* Checkout errors (e.g. the product was deactivated between page load and
|
|
1127
1129
|
* click) render inline after the button with role="alert".
|
|
1128
1130
|
*
|
|
@@ -1172,7 +1174,8 @@ interface AddToCartButtonProps {
|
|
|
1172
1174
|
* no checkout; pair with `<CartCheckoutButton>` on the cart surface.
|
|
1173
1175
|
*
|
|
1174
1176
|
* Automatically disabled while the product loads, when the store can't take
|
|
1175
|
-
* payments, when the product is
|
|
1177
|
+
* payments (outside a frame only — see BuyButton), when the product is
|
|
1178
|
+
* inactive/unpurchasable, until a variant
|
|
1176
1179
|
* resolves, and when the resolved variant is out of stock per the loaded
|
|
1177
1180
|
* data (advisory — the cart surface re-checks with fresh data, and checkout
|
|
1178
1181
|
* is the authority). Custom-amount (tip jar) products, legacy products with
|
|
@@ -1306,7 +1309,22 @@ interface OrderSessionSubscription {
|
|
|
1306
1309
|
interface OrderSession {
|
|
1307
1310
|
status: OrderStatus;
|
|
1308
1311
|
fulfillment: OrderFulfillment;
|
|
1309
|
-
/**
|
|
1312
|
+
/**
|
|
1313
|
+
* The buyer-facing order reference: a small per-site counter ("Order #7"),
|
|
1314
|
+
* and what the receipt email, the merchant's dashboard and the customer's
|
|
1315
|
+
* account history all quote. Prefer it over `order_id` anywhere a human
|
|
1316
|
+
* reads the reference — a buyer quoting the nanoid is quoting a number
|
|
1317
|
+
* nobody else on either side of the sale is looking at.
|
|
1318
|
+
*
|
|
1319
|
+
* Null on orders taken before numbering existed, which is the only reason
|
|
1320
|
+
* `order_id` is still rendered as a fallback.
|
|
1321
|
+
*/
|
|
1322
|
+
order_number?: number | null;
|
|
1323
|
+
/**
|
|
1324
|
+
* The internal order id (a nanoid). It is the idempotency-key source, not a
|
|
1325
|
+
* reference meant for buyers; the receipt email prints it as "Order ID"
|
|
1326
|
+
* only when `order_number` is absent.
|
|
1327
|
+
*/
|
|
1310
1328
|
order_id?: string;
|
|
1311
1329
|
/** True for a simulated owner-initiated test purchase (no money moved). */
|
|
1312
1330
|
is_test?: boolean;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{useState as Vt,useEffect as Ln}from"react";import{Turnstile as In}from"@marsidev/react-turnstile";import{jsx as qt}from"react/jsx-runtime";function En({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=Vt(null),[f,y]=Vt(!0);return Ln(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(u=>u.json()).then(u=>{l(u.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),f||!i?null:qt("div",{className:o,children:qt(In,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}import{useCallback as Un,useEffect as Nn,useRef as Mn,useState as $e}from"react";var De=[1e3,3e3];function ue(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=$e(null),[l,f]=$e(!0),[y,u]=$e(null),[v,c]=$e(0),x=Mn(e);Nn(()=>{let p=!1,A;f(!0),u(null),x.current!==e&&(x.current=e,i(null));let w=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let P=await a.json().catch(()=>null);if(!p)if(!a.ok||!P){if(a.status>=500&&b<De.length){A=setTimeout(()=>w(b+1),De[b]);return}u(P?.error??`Request failed (${a.status})`),i(null),f(!1)}else i(P),f(!1)}).catch(a=>{if(!p){if(b<De.length){A=setTimeout(()=>w(b+1),De[b]);return}u(a instanceof Error?a.message:"Failed to load product"),f(!1)}})};return w(0),()=>{p=!0,A&&clearTimeout(A)}},[e,r,n,v]);let k=Un(()=>c(p=>p+1),[]);return{product:o,loading:l,error:y,refresh:k}}var $t=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function F(e,t,r){let n=$t.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function oe(e){return e.variants??[]}function fe(e){return e.options??[]}function _e(e){return fe(e).length>0}function Be(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function le(e,t){let r=Object.keys(t);return e.find(n=>{let o=n.option_values;return o.length!==r.length?!1:o.every(i=>t[i.option_id]===i.value_id)})??null}function ot(e,t,r,n){return e.some(o=>{let i=Be(o);if(i[r]!==n)return!1;for(let[l,f]of Object.entries(t))if(l!==r&&i[l]!==f)return!1;return!0})}function st(e,t,r){return e.some(n=>Be(n)[t]===r)}function at(e,t,r,n){let o={[r]:n};for(let[l,f]of Object.entries(t)){if(l===r)continue;e.some(u=>{let v=Be(u);return v[r]===n&&v[l]===f})&&(o[l]=f)}return e.some(l=>{let f=Be(l);return Object.entries(o).every(([y,u])=>f[y]===u)})?o:{[r]:n}}function ut(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function Dt(e,t){let r={};for(let n of fe(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i&&(r[n.title]=i.value)}return r}function ne(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function lt(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((i,l)=>{n.has(ne(l))||n.set(ne(l),i)});let o={};for(let i of fe(e)){let l=ne(i.title);if(l.length===0)continue;let f=n.get(l);if(f===void 0)continue;let y=ne(f);if(y.length===0)continue;let u=i.values.find(v=>ne(v.value)===y);u&&(o[i.id]=u.id)}return o}function Fe(e,t){let r={};for(let[n,o]of Object.entries(Dt(e,t))){let i=ne(n),l=ne(o);i.length===0||l.length===0||(r[i]=l)}return r}function xe(e,t){let r=[];for(let n of fe(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i?.images?.length&&r.push(...i.images)}return r.length>0?r:e.images??[]}function ct(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of fe(e)){let o=ne(n.title);o.length!==0&&r.searchParams.delete(o)}for(let[n,o]of Object.entries(Fe(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}import{useCallback as Dn,useEffect as Jt,useRef as Gt,useState as gt}from"react";var pt="aifeatures_cart",ft="aifeatures_market",Bt="aifeatures_cart_cleared";var dt="aifeatures:cart-storage",Re=new Map;function Ae(e){if(Re.has(e))return Re.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function me(e,t){if(typeof window>"u"){Re.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Re.delete(e)}catch{Re.set(e,t)}Vn(e)}function Vn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(dt,{detail:{key:e}}))}catch{}}function ze(e,t){if(typeof window>"u")return()=>{};let r=o=>{(o.key===e||o.key===null)&&t()},n=o=>{o.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(dt,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(dt,n)}}function qn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[l,f]of Object.entries(t.selection))typeof f=="string"&&(n[l]=f);let o=typeof t.display=="object"&&t.display!==null?t.display:{},i={name:typeof o.name=="string"?o.name:"",variantTitle:typeof o.variantTitle=="string"?o.variantTitle:null,image:typeof o.image=="string"?o.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:i}}function se(){let e=Ae(pt);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let o of t){let i=qn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function X(e){me(pt,JSON.stringify(e))}function Ft(e){return ze(pt,e)}function zt(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of se()){let o=t.get(n.variantId);if(o===void 0){r.push(n);continue}let i=n.quantity-o;i>0&&r.push({...n,quantity:i})}X(r)}function W(){let e=Ae(ft);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function jt(e){me(ft,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function ge(e){return ze(ft,e)}function Kt(e){let t=[],r=Ae(Bt);if(r)try{let o=JSON.parse(r);Array.isArray(o)&&(t=o.filter(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(o=>o.ts>n),t.some(o=>o.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),me(Bt,JSON.stringify(t)),!0)}var je="aifeatures_session",mt=null;function Yt(){return mt}function $n(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.token!="string"||t.token.length===0)return null;let r=null;if(typeof t.customer=="object"&&t.customer!==null){let n=t.customer;typeof n.email=="string"&&n.email.length>0&&(r={email:n.email,name:typeof n.name=="string"?n.name:null})}return{token:t.token,customer:r}}function ce(){let e=Ae(je);if(!e)return null;try{return $n(JSON.parse(e))}catch{return null}}function Wt(){return ce()?.token??null}function Ke(e){mt=null,me(je,JSON.stringify(e))}function ee(e){mt=e??null,me(je,null)}function Ht(e){return ze(je,e)}var Bn=1500;function Oe(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function Ye(e,t){return!("requestId"in e)||e.requestId===t}function yt(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;y?.type==="aifeatures:test-checkout-ack"&&Ye(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),Bn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function Zt(e){if(window.self!==window.top)try{return window.top.location.href=e,"navigating"}catch{if(window.open(e,"_blank"))return"stayed"}return window.location.href=e,"navigating"}function bt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=gt(!1),[o,i]=gt(null),[l,f]=gt(null),y=Gt(!1),u=Gt(null);return Jt(()=>{let c=x=>{x.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",c),()=>window.removeEventListener("pageshow",c)},[]),Jt(()=>{if(typeof window>"u"||window.self===window.top)return;let c=x=>{if(x.source!==window.parent)return;let k=x.data;if(k?.type!=="aifeatures:test-checkout-ack"||k.status!=="failed")return;let p=u.current;p===null||!Ye(k,p)||(u.current=null,i(typeof k.error=="string"&&k.error?k.error:"The test purchase could not be created."),y.current=!1,n(!1))};return window.addEventListener("message",c),()=>window.removeEventListener("message",c)},[]),{startCheckout:Dn(async({productId:c,variantId:x,quantity:k,amount:p,metadata:A,successUrl:w,cancelUrl:b,customerEmail:a,planId:P,expectedUnitAmount:_,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),f(null),P!==void 0){let d=Wt();if(d)try{let m=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:P,...x!==void 0?{variant_id:x}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.text().catch(()=>""),h=null;try{h=g?JSON.parse(g):null}catch{h=null}if(m.ok){if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Zt(h.url)==="stayed"&&(y.current=!1,n(!1));return}let C=m.status===404&&g.trim()==="";if(m.status===401||C)ee();else{i(h?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}}catch(m){i(m instanceof Error?m.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=P===void 0?W():null,m=await fetch(`${t}/v1/p/${c}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...x!==void 0?{variant_id:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{plan_id:P}:{},...A!==void 0?{metadata:A}:{},...a!==void 0?{customer_email:a}:{},..._!==void 0&&s!==void 0&&P===void 0?{expected_unit_amount:_,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.json().catch(()=>null);if(!m.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){f({currentUnitAmount:g.current_unit_amount,currency:g.currency}),i(`The price has changed to ${F(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(g?.code==="preview_domain"){let h=Oe();if(u.current=h,await yt({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{planId:P}:{},...a!==void 0?{customerEmail:a}:{},...A!==void 0?{metadata:A}:{}},h))return;u.current=null}i(g?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Zt(g.url)==="stayed"&&(y.current=!1,n(!1))}catch(d){i(d instanceof Error?d.message:"Checkout failed"),y.current=!1,n(!1)}}},[t]),loading:r,error:o,priceChange:l}}import{useCallback as We,useEffect as Fn,useState as Qt}from"react";var en=20;function Xt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function re(){let[e,t]=Qt([]),[r,n]=Qt(!1);Fn(()=>{let u=()=>t(se());return u(),n(!0),Ft(u)},[]);let o=We(u=>{let v=se(),c=Xt(u.quantity);return v.find(k=>k.variantId===u.variantId)?(X(v.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):v.length>=en?{ok:!1,reason:"cart_full"}:(X([...v,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=We(u=>{X(se().filter(v=>v.variantId!==u))},[]),l=We((u,v)=>{let c=se();if(v<=0){X(c.filter(k=>k.variantId!==u));return}let x=Xt(v);X(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),f=We(()=>{X([])},[]),y=e.reduce((u,v)=>u+v.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:f}}import{useCallback as zn,useEffect as tn,useMemo as ht,useRef as jn,useState as Te}from"react";var He={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},Kn={...He,inStock:!0,status:"error"};function Yn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function St(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=re(),[o,i]=Te({}),[l,f]=Te({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=Te(!0),[v,c]=Te(null),[x,k]=Te(0),p=jn(new Set),A=ht(()=>JSON.stringify(r.map(_=>[_.productId,_.variantId,_.selection])),[r]),w=zn(()=>k(_=>_+1),[]);tn(()=>ge(w),[w]),tn(()=>{if(!n)return;if(r.length===0){i({}),f({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let _=!1;u(!0);let s=r,d=[...new Set(s.map(g=>g.productId))],m=async g=>{let h=new Map;return await Promise.all(d.map(async C=>{try{let S=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${g?`?country=${encodeURIComponent(g)}`:""}`);if(S.status===404){h.set(C,{kind:"not_found"});return}if(!S.ok){h.set(C,{kind:"error",message:`Request failed (${S.status})`});return}let R=await S.json();h.set(C,{kind:"ok",product:R})}catch(S){h.set(C,{kind:"error",message:S instanceof Error?S.message:"Failed to load product"})}})),h};return(async()=>{let g=W(),h=await m(g);if(g){let T=[...h.values()].filter(U=>U.kind==="ok"),E=T.filter(U=>U.product.base_currency);E.length>0&&E.length<T.length&&(h=await m(null))}if(_)return;let C=null,S=null,R=null;for(let T of d){let E=h.get(T);!E||E.kind!=="ok"||(C===null&&E.product.shipping_rates&&(C=E.product.shipping_rates),S===null&&E.product.free_shipping_over!=null&&(S=E.product.free_shipping_over),R===null&&E.product.shipping_countries&&(R=E.product.shipping_countries))}let O={},q=new Map,j=null;for(let T of s){let E=h.get(T.productId);if(!E||E.kind==="error"){O[T.variantId]=Kn,E&&j===null&&(j=E.message);continue}if(E.kind==="not_found"){O[T.variantId]=He;continue}let{product:U}=E;if(!U.active||U.purchasable===!1){O[T.variantId]=He;continue}let Y=U.variants??[],N=Y.find(H=>H.id===T.variantId)??null,z=T.variantId;if(!N){let H=le(Y,T.selection);if(!H){O[T.variantId]=He;continue}let Mt=q.get(T.variantId)??{};Mt.reanchorTo={variantId:H.id,selection:Yn(H)},q.set(T.variantId,Mt),p.current.add(H.id),N=H,z=H.id}let I=xe(U,T.selection)[0]??null,L={image:I,unitAmount:N.unit_amount,currency:N.currency,baseCurrency:U.base_currency??null,inStock:N.in_stock,available:N.available,maxQuantity:U.max_quantity,pdpSearch:Fe(U,T.selection),status:p.current.has(z)?"reanchored":"ok"};O[T.variantId]=L,O[z]=L;let B=q.get(T.variantId)??{};B.display={name:U.name,variantTitle:N.title,image:I},q.set(T.variantId,B)}let D=new Set(s.map(T=>T.variantId));for(let T of[...p.current])!D.has(T)&&!(T in O)&&p.current.delete(T);if(q.size>0){let T=se(),E=[],U=new Map,Y=!1;for(let N of T){let z=q.get(N.variantId),I={...N};z?.reanchorTo&&(I.variantId=z.reanchorTo.variantId,I.selection=z.reanchorTo.selection,Y=!0),z?.display&&(I.display.name!==z.display.name||I.display.variantTitle!==z.display.variantTitle||I.display.image!==z.display.image)&&(I.display=z.display,Y=!0);let L=U.get(I.variantId);if(L){L.quantity+=I.quantity,Y=!0;continue}E.push(I),U.set(I.variantId,I)}Y&&X(E)}_||(i(O),f({shippingRates:C,freeShippingOver:S,shippingCountries:R}),c(j),u(!1))})(),()=>{_=!0}},[n,A,t,x]);let b=ht(()=>r.map(_=>{let s=o[_.variantId];return s?{..._,...s,image:s.image??_.display.image}:{..._,image:_.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:P}=ht(()=>{let _=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(_+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:_,currency:s}},[b]);return{lines:b,subtotal:a,currency:P,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:v,refresh:w}}import{useCallback as Wn,useEffect as nn,useMemo as Hn,useRef as vt,useState as Le}from"react";var Jn=2e3;function Gn(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=re(),[l,f]=Le(null),[y,u]=Le(!1),[v,c]=Le(null),[x,k]=Le(null),[p,A]=Le(0);nn(()=>(k(W()),ge(()=>k(W()))),[]);let w=Hn(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=Wn(()=>A(s=>s+1),[]),a=vt(0),P=vt(!1),_=vt("idle");return nn(()=>{if(!i)return;if(o.length===0){f(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,m=!1,g,h=P.current?r:0;P.current=!0,_.current=_.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{u(!0);try{let S=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:d.signal,body:JSON.stringify({items:o.map(O=>({variant_id:O.variantId,quantity:O.quantity})),...x?{country:x}:{},...n?{shipping_option:n}:{}})});if(m||s!==a.current)return;if(!S.ok){if(S.status===429){let O=_.current==="idle";O&&(g=setTimeout(()=>{m||s!==a.current||(_.current="pending",A(q=>q+1))},Jn)),c(O?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else c(`Could not price this cart (${S.status})`);return}let R=await S.json();if(m||s!==a.current)return;f({currency:R.currency,subtotal:R.subtotal,shipping:R.shipping?{options:R.shipping.options.map(O=>({label:O.label,amount:O.amount,undiscountedAmount:O.undiscounted_amount})),selectedAmount:R.shipping.selected_amount,selectedLabel:R.shipping.selected_label,freeShippingOver:R.shipping.free_shipping_over,freeShippingCurrency:R.shipping.free_shipping_currency,thresholdMet:R.shipping.threshold_met,collectsAddress:R.shipping.collects_address}:null,total:R.total,totalIsFinal:R.total_is_final,tax:R.tax??null,unavailableVariantIds:R.unavailable_variant_ids}),c(null)}catch(S){if(m||d.signal.aborted||s!==a.current)return;c(S instanceof Error?S.message:"Could not price this cart")}finally{!m&&s===a.current&&u(!1)}},h);return()=>{m=!0,clearTimeout(C),g!==void 0&&clearTimeout(g),d.abort()}},[i,w,x,t,r,n,p]),{summary:l,loading:y,error:v,refresh:b}}import{useCallback as Zn,useEffect as rn,useRef as on,useState as Je}from"react";function kt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Je(!1),[o,i]=Je(null),[l,f]=Je(null),[y,u]=Je(null),v=on(!1),c=on(null);return rn(()=>{let k=p=>{p.persisted&&(v.current=!1,n(!1))};return window.addEventListener("pageshow",k),()=>window.removeEventListener("pageshow",k)},[]),rn(()=>{if(typeof window>"u"||window.self===window.top)return;let k=p=>{if(p.source!==window.parent)return;let A=p.data;if(A?.type!=="aifeatures:test-checkout-ack"||A.status!=="failed")return;let w=c.current;w===null||!Ye(A,w)||(c.current=null,i(typeof A.error=="string"&&A.error?A.error:"The test purchase could not be created."),v.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:Zn(async(k,{successUrl:p,cancelUrl:A,customerEmail:w,metadata:b,shippingOption:a}={})=>{if(!v.current){v.current=!0,n(!0),i(null),f(null),u(null);try{let P=W(),_=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:k.map(d=>({variant_id:d.variantId,quantity:d.quantity,...typeof d.unitAmount=="number"&&typeof d.currency=="string"?{expected_unit_amount:d.unitAmount,expected_currency:d.currency}:{}})),...P!==null?{country:P}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...w!==void 0?{customer_email:w}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:A??window.location.href})}),s=await _.json().catch(()=>null);if(!_.ok){if(s?.code==="shipping_option_unavailable"&&typeof s.requested=="string"&&Array.isArray(s.available)){u({requested:s.requested,available:s.available,currency:typeof s.currency=="string"?s.currency:""}),v.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let m of s.items)m&&typeof m.variant_id=="string"&&(d[m.variant_id]=m);f(d),v.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=Oe();if(c.current=d,await yt({items:k.map(g=>({productId:g.productId,variantId:g.variantId,quantity:g.quantity})),...w!==void 0?{customerEmail:w}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${_.status})`),v.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),v.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=s.url;return}catch{if(window.open(s.url,"_blank")){v.current=!1,n(!1);return}}window.location.href=s.url}catch(P){i(P instanceof Error?P.message:"Checkout failed"),v.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}import{useCallback as Qn,useEffect as sn,useState as Ct}from"react";var wt=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function an(e){return e?wt.find(t=>t.country===e.toUpperCase())?.currency??null:null}var un=new Map;function Xn(e){let t=un.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),un.set(e,t)),t}function er(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Ct(null),[o,i]=Ct(!1),[l,f]=Ct(null);sn(()=>{let c=()=>n(W());return c(),i(!0),ge(c)},[]),sn(()=>{let c=!1;return Xn(t).then(x=>{c||f(x)}),()=>{c=!0}},[t]);let y=Qn(c=>{jt(c)},[]),u=an(l),v=o&&u!==null&&u!==an(r);return{market:r,suggestedCountry:l,setMarket:y,markets:wt,shouldPrompt:v}}import{jsx as Pt,jsxs as rr}from"react/jsx-runtime";var tr={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function nr({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:f,loading:y}=ue(e,{apiUrl:r});if(y||!f)return null;let u=oe(f),v=t!==void 0?u.find(x=>x.id===t)??null:f.options.length===0?u[0]??null:null;if(v){if(v.unit_amount===null)return null;let x=v.compare_at_amount!==null&&v.compare_at_amount>v.unit_amount;return rr("span",{className:o,style:i,children:[x&&Pt("span",{className:l,style:l?void 0:tr,children:F(v.compare_at_amount,v.currency,n)}),F(v.unit_amount,v.currency,n)]})}let c=ut(u);return c?Pt("span",{className:o,style:i,children:c.min===c.max?F(c.min,f.currency,n):`${F(c.min,f.currency,n)} \u2013 ${F(c.max,f.currency,n)}`}):f.unit_amount===null?null:Pt("span",{className:o,style:i,children:F(f.unit_amount,f.currency,n)})}import{useEffect as _t,useMemo as ir,useRef as ln,useState as cn}from"react";import{Fragment as br,jsx as ye,jsxs as dn}from"react/jsx-runtime";var or={marginBottom:"0.75rem"},sr={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},ar={display:"flex",flexWrap:"wrap",gap:"0.5rem"},ur={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},lr={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},pn={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},cr={...pn,cursor:"pointer"},dr=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,pr=e=>dr.test(e),fr={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},mr={display:"block",width:"1.5rem",height:"1.5rem",maxWidth:"100%",maxHeight:"100%",boxSizing:"border-box",borderRadius:3,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f3f4f6",border:"1px solid rgba(0, 0, 0, 0.2)"},gr="linear-gradient(to top right, transparent calc(50% - 2px), rgba(0,0,0,0.55) calc(50% - 2px), rgba(255,255,255,0.95) calc(50% - 1px), rgba(255,255,255,0.95) calc(50% + 1px), rgba(0,0,0,0.55) calc(50% + 1px), transparent calc(50% + 2px))";function yr({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:f,optionClassName:y,optionLabelClassName:u,valueClassName:v,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[A,w]=cn(r??{}),b=p?r:A,[a,P]=cn(()=>new Set),_=h=>P(C=>C.has(h)?C:new Set(C).add(h));_t(()=>{P(h=>h.size===0?h:new Set)},[e]);let s=ln(!1);_t(()=>{if(!n||p||s.current||e.length===0||typeof window>"u"||(s.current=!0,Object.keys(A).length>0))return;let h=lt({options:e},window.location.search);Object.keys(h).length!==0&&(w(h),o?.(h))},[n,p,e]);let d=ir(()=>e.length>0?t.filter(h=>h.option_values.length===e.length):t,[t,e]),m=ln(void 0);if(_t(()=>{let h=le(d,b),C=h?.id??null;m.current!==C&&(m.current=C,i?.(h))},[d,b]),e.length===0)return null;let g=(h,C)=>{let S=at(d,b,h,C);p||(w(S),n&&ct({options:e},S)),o?.(S)};return ye("div",{className:l,style:f,children:e.map(h=>dn("div",{className:y,style:y?void 0:or,children:[ye("span",{className:u,style:u?void 0:sr,children:h.title}),ye("div",{style:ar,children:h.values.map(C=>{let S=b[h.id]===C.id,R=ot(d,b,h.id,C.id),O=R||st(d,h.id,C.id),q=[v,S?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,j=C.swatch??null,D=j&&!a.has(j)?j:null,T=D?pr(D):!1,E=v?void 0:{...ur,...S?lr:{},...R?{}:O?cr:pn,...D?{...fr,textDecoration:"none"}:{}},U=R?C.value:`${C.value} \u2014 unavailable with your current selection`;return ye("button",{type:"button",className:q,style:E,disabled:!O,"aria-pressed":S,"aria-label":D?U:void 0,title:D?U:void 0,"data-selected":S?"true":void 0,"data-available":R?"true":"false","data-swatch":D?T?"hex":"image":void 0,onClick:()=>g(h.id,C.id),children:D?dn(br,{children:[ye("span",{"aria-hidden":"true",className:k,style:k?void 0:{...mr,...T?{background:D}:{},...T&&R?{}:{backgroundImage:[...R?[]:[gr],...T?[]:[`url(${JSON.stringify(D)})`]].join(", ")}}}),T?null:ye("img",{src:D,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>_(D)})]}):C.value},C.id)})})]},h.id))})}import{useEffect as hr}from"react";import{Fragment as xt,jsx as de,jsxs as Ie}from"react/jsx-runtime";var Sr={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},vr={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function fn(){return Ie("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[de("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),de("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:de("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function kr({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,apiUrl:u,disabled:v,className:c,style:x,errorClassName:k,spinner:p=!0,children:A}){let{product:w,loading:b,error:a,refresh:P}=ue(e,{apiUrl:u}),{startCheckout:_,loading:s,error:d,priceChange:m}=bt({apiUrl:u});hr(()=>{m&&P()},[m,P]);let g=w!==null&&!w.payments_ready,h=w!==null&&!w.active,C=w!==null&&w.purchasable===!1,S=w!==null&&_e(w),R=w!==null?oe(w):[],O=t!==void 0?R.find(L=>L.id===t)??null:!S&&R.length===1?R[0]:null,q=S&&!O,j=O!==null&&!O.in_stock,D=n??void 0,T=w?.subscription??null,E=T!==null&&T.required&&!T.ready,U=T!==null&&T.required&&T.ready&&D===void 0,Y=!!v||b||!w||g||h||C||E||U||q||j||s,N;s?N=Ie(xt,{children:[p&&de(fn,{}),"Processing\u2026"]}):b?N=Ie(xt,{children:[p&&de(fn,{}),A??"Buy now"]}):g?N="Payments not set up":h||C?N="Unavailable":E?N="Currently unavailable":U?N="Select a plan":q?N="Select options":j?N="Out of stock":A!==void 0?N=A:D!==void 0?N="Subscribe":N="Buy now";let z=d??a;return Ie(xt,{children:[de("button",{type:"button",className:c,style:x,disabled:Y,onClick:()=>{let L=o===void 0&&D===void 0&&W()===null&&O!==null&&!O.allow_custom_amount&&typeof O.unit_amount=="number"?{expectedUnitAmount:O.unit_amount,expectedCurrency:O.currency}:{};_({productId:e,variantId:t,quantity:D!==void 0?void 0:r,amount:o,planId:D,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,...L})},children:N}),z&&Ie("div",{role:"alert",className:k,style:k?void 0:Sr,children:[z,w===null&&!b&&a!==null&&de("button",{type:"button",onClick:P,style:vr,children:"Tap to retry"})]})]})}import{useEffect as Cr,useRef as wr,useState as mn}from"react";import{Fragment as gn,jsx as be,jsxs as Ge}from"react/jsx-runtime";var Pr={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},_r={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},xr=1500;function Rr(){return Ge("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[be("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),be("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:be("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Ar(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Or({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:f,errorClassName:y,spinner:u=!0,children:v}){let{product:c,loading:x,error:k,refresh:p}=ue(e,{apiUrl:o}),{add:A}=re(),[w,b]=mn(!1),[a,P]=mn(!1),_=wr(void 0);Cr(()=>()=>{_.current&&clearTimeout(_.current)},[]);let s=c!==null&&!c.payments_ready,d=c!==null&&!c.active,m=c!==null&&c.purchasable===!1,g=c!==null&&!x&&oe(c).length===0,h=c!==null&&c.allow_custom_amount,C=c!==null&&c.subscription?.required===!0,S=c!==null&&_e(c),R=c!==null?oe(c):[],O=t!==void 0?R.find(N=>N.id===t)??null:r!==void 0&&S?le(R,r):!S&&R.length===1?R[0]:null,q=c!==null&&!g&&!O,j=O!==null&&!O.in_stock,D=!!i||x||!c||s||d||m||g||h||C||q||j,T=()=>{if(!c||!O)return;let N=r??Ar(O);if(!A({productId:e,variantId:O.id,quantity:n,selection:N,display:{name:c.name,variantTitle:O.title,image:xe(c,N)[0]??null}}).ok){b(!0);return}b(!1),P(!0),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>P(!1),xr)},E;x?E=Ge(gn,{children:[u&&be(Rr,{}),v??"Add to cart"]}):s?E="Payments not set up":d||m||g||h?E="Unavailable":C?E="Subscription only":q?E="Select options":j?E="Out of stock":a?E="Added to cart":v!==void 0?E=v:E="Add to cart";let U=w?"Your cart is full \u2014 remove an item before adding another.":k;return Ge(gn,{children:[be("button",{type:"button",className:l,style:f,disabled:D,"data-added":a?"true":void 0,onClick:T,children:E}),U&&Ge("div",{role:"alert",className:y,style:y?void 0:Pr,children:[U,c===null&&!x&&k!==null&&!w&&be("button",{type:"button",onClick:p,style:_r,children:"Tap to retry"})]})]})}import{Fragment as Rt,jsx as ae,jsxs as Ze}from"react/jsx-runtime";var yn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function bn(){return Ze("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[ae("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),ae("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:ae("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Tr({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:f,style:y,errorClassName:u,spinner:v=!0,children:c}){let{items:x,hydrated:k}=re(),{lines:p}=St({apiUrl:e}),{startCheckout:A,loading:w,error:b,conflicts:a}=kt({apiUrl:e}),P=k&&x.length===0,_=p.some(g=>g.status==="unavailable"),s=!!l||!k||P||_||w,d;w?d=Ze(Rt,{children:[v&&ae(bn,{}),"Processing\u2026"]}):k?P?d="Cart is empty":_?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=Ze(Rt,{children:[v&&ae(bn,{}),c??"Checkout"]});let m=a?Object.keys(a).length:0;return Ze(Rt,{children:[ae("button",{type:"button",className:f,style:y,disabled:s,onClick:()=>A(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),m>0&&ae("div",{role:"alert",className:u,style:u?void 0:yn,children:m===1?"An item in your cart changed \u2014 please review your cart and try again.":`${m} items in your cart changed \u2014 please review your cart and try again.`}),b&&ae("div",{role:"alert",className:u,style:u?void 0:yn,children:b})]})}import{useEffect as Qe,useRef as hn,useState as At}from"react";import{Fragment as he,jsx as $,jsxs as G}from"react/jsx-runtime";var Ot="af_order_confirmation_session",Lr=1800*1e3;function Ir({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:f=1500,renderNoSession:y,renderPending:u,renderPaid:v,renderFailed:c}){let[x,k]=At(n),[p,A]=At(null),[w,b]=At(!1),a=hn(void 0);Qe(()=>{if(n!==void 0){k(n);return}if(a.current!==void 0){k(a.current);return}let d=new URL(window.location.href),m=d.searchParams.get("session_id");if(m){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(Ot,JSON.stringify({id:m,ts:Date.now()}))}catch{}}else try{let g=sessionStorage.getItem(Ot);if(g){let h=JSON.parse(g);typeof h.id=="string"&&typeof h.ts=="number"&&Date.now()-h.ts<=Lr?m=h.id:sessionStorage.removeItem(Ot)}}catch{}a.current=m,k(m)},[n]),Qe(()=>{if(!x)return;let d=!1,m,g=Date.now(),h=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(C.ok){let S=await C.json();if(d||(A(S),S.status!=="pending"))return}}catch{}if(!d){if(Date.now()-g>=i){b(!0);return}m=setTimeout(h,o)}};return h(),()=>{d=!0,m&&clearTimeout(m)}},[x,e,o,i]);let P=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),_=hn(!1);Qe(()=>{if(!x||p===null||_.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(_.current=!0,!Kt(x)))return;let m=(p.line_items??[]).filter(g=>typeof g.variant_id=="string"&&g.variant_id.length>0).map(g=>({variantId:g.variant_id,quantity:g.quantity}));m.length>0&&zt(m)},[x,p]);let s=P&&p.fulfillment.type==="redirect"?p.fulfillment.redirect_url:void 0;if(Qe(()=>{if(!s||!l)return;let d=setTimeout(()=>{window.location.href=s},f);return()=>clearTimeout(d)},[s,l,f]),x===void 0)return null;if(x===null)return y?$(he,{children:y()}):G("div",{className:t,style:r,children:[$("h2",{children:"Thank you for your order!"}),$("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!p||p.status==="pending")return u?$(he,{children:u({timedOut:w})}):$("div",{className:t,style:r,role:"status",children:$("p",{children:w?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(P){if(v)return $(he,{children:v(p)});let{fulfillment:d}=p,m=p.amount_total!==void 0&&p.currency?F(p.amount_total,p.currency):null,g=d.files??[],h=g.length===0?d.download_url:void 0;return G("div",{className:t,style:r,children:[$("h2",{children:"Thank you for your purchase!"}),p.is_test&&G("p",{children:[$("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),p.line_items&&p.line_items.length>0&&$("ul",{children:p.line_items.map((C,S)=>G("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&$("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},S))}),m&&G("p",{children:["Total paid: ",m]}),p.source==="subscription"&&p.subscription&&G(he,{children:[G("p",{children:["Your subscription renews"," ",p.subscription.interval_count>1?`every ${p.subscription.interval_count} ${p.subscription.interval}s`:`every ${p.subscription.interval}`," ","at"," ",F(p.subscription.amount,p.subscription.currency),"."]}),G("p",{children:["You can view, update, or cancel it any time on"," ",$("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),g.length>0&&G(he,{children:[$("p",{children:"Your downloads:"}),$("ul",{children:g.map((C,S)=>$("li",{children:$("a",{href:C.download_url,children:C.name})},S))})]}),h&&$("p",{children:$("a",{href:h,children:"Download your file"})}),s?G("p",{children:["Taking you to your content\u2026"," ",$("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?$("p",{children:$("a",{href:d.redirect_url,children:"Continue to your content"})}):null,g.length===0&&!h&&!d.redirect_url&&$("p",{children:"A confirmation email is on its way to you."}),p.order_id&&G("p",{children:["Order reference: ",$("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return c?$(he,{children:c(p)}):$("div",{className:t,style:r,children:$("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}import{useEffect as Er,useState as Ur}from"react";import{Fragment as $r,jsx as Se}from"react/jsx-runtime";function Sn(e,t){if(t.unit_amount!==null&&t.unit_amount!==void 0)return t.unit_amount;let r=t.percent_off_bps??0;return e-Math.floor(e*r/1e4)}function Tt(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var Nr={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},Mr={display:"block",width:"100%",textAlign:"left",padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Vr={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600};function qr({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:f,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:v,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,A=k?.ready===!0,w=[...k?.plans??[]].sort((S,R)=>S.position-R.position),[b,a]=Ur(null),P=o!==void 0,_=P?o:b,s=w.map(S=>S.id).join("|"),d=w.length>0?w[0].id:null;if(Er(()=>{if(!(!p||!A)&&!(_!==null&&w.some(S=>S.id===_))){if(d===null){if(_===null)return;P||a(null),i?.(null);return}P||a(d),i?.(d)}},[p,A,d,s,_,P]),!k)return null;if(!A)return p?x?Se($r,{children:x()}):Se("div",{className:l,style:f,"data-state":"unavailable",children:Se("p",{children:"This product is currently unavailable."})}):null;if(w.length===0)return null;let m=e?.base_currency!==void 0&&e?.base_currency!==null,g=r!==void 0?r:m?null:e?.unit_amount??null,h=n??e?.base_currency??e?.currency??"usd",C=[];if(!p){let S=g;C.push({plan:null,selected:_===null,price:S,priceLabel:S!==null?F(S,h):null,label:"One-time purchase",select:()=>{P||a(null),i?.(null)}})}for(let S of w){let R=S.unit_amount!==null?S.unit_amount:g!==null?Sn(g,S):null,O=R!==null?F(R,h):null,q=S.title&&S.title.trim().length>0?S.title.trim():`Subscribe ${Tt(S)}`,j=O?`${q} \u2014 ${O} ${Tt(S)}`:`${q} \u2014 billed ${Tt(S)}`;C.push({plan:S,selected:_===S.id,price:R,priceLabel:O,label:j,select:()=>{P||a(S.id),i?.(S.id)}})}return Se("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?f:{...Nr,...f},children:C.map(S=>{if(c)return Se("span",{style:{display:"contents"},children:c(S)},S.plan?.id??"one-time");let R=S.selected;return Se("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":S.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...Mr,...R?Vr:{}},onClick:S.select,children:S.plan===null&&v!==void 0?v:S.plan===null?S.priceLabel?`One-time purchase \u2014 ${S.priceLabel}`:"One-time purchase":S.label},S.plan?.id??"one-time")})})}import{useCallback as Xe,useEffect as kn,useRef as Dr,useState as et}from"react";async function Z(e,t,r={}){let n;try{n=await fetch(`${e}${t}`,{method:r.method??"GET",headers:{...r.body!==void 0?{"Content-Type":"application/json"}:{},...r.token?{Authorization:`Bearer ${r.token}`}:{}},...r.body!==void 0?{body:JSON.stringify(r.body)}:{}})}catch(u){return{ok:!1,failure:{kind:"network",error:u instanceof Error?u.message:"Network error"}}}let o=await n.text().catch(()=>""),i=null;try{i=o?JSON.parse(o):null}catch{i=null}let l=typeof i=="object"&&i!==null?i:null;if(n.ok)return l===null?{ok:!1,failure:{kind:"parse_error",error:"The server sent an unreadable response \u2014 please try again"}}:{ok:!0,data:l};if(n.status===404&&o.trim()==="")return{ok:!1,failure:{kind:"unavailable"}};let f=typeof l?.code=="string"?l.code:null,y=typeof l?.error=="string"&&l.error?l.error:`Request failed (${n.status})`;return n.status===401?{ok:!1,failure:{kind:"unauthorized",code:f,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:f,error:y}}}function vn(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function Ee(e){if(!e)return null;let t=e.includes("T")?e:e.replace(" ","T")+"Z",r=Date.parse(t);if(Number.isNaN(r))return null;try{return new Date(r).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{return null}}var Br=1500;function Cn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function Fr(e,t){return e.requestId===t}function zr(e,t){return typeof window>"u"||!Cn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;if(y?.type==="aifeatures:preview-session-ack"&&Fr(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let v=y.customer;typeof v.email=="string"&&(u={email:v.email,name:typeof v.name=="string"?v.name:null})}o({claimed:!0,token:y.token,customer:u});return}o({claimed:!0,token:null,customer:null,error:typeof y.error=="string"&&y.error?y.error:"The preview sign-in could not be created."})}},l=setTimeout(()=>o({claimed:!1}),Br);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ue(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=et(()=>ce()),[o,i]=et(null),[l,f]=et(!1),[y,u]=et(!1),v=Dr(void 0);kn(()=>Ht(()=>{let b=ce();n(b),i(b===null?a=>Yt()??a:null)}),[]);let c=Xe(async b=>{u(!0);try{let a=await Z(t,"/v1/account/verify",{method:"POST",body:{code:b}});if(a.ok&&typeof a.data.token=="string"){let _=a.data.customer&&typeof a.data.customer.email=="string"?{email:a.data.customer.email,name:typeof a.data.customer.name=="string"?a.data.customer.name:null}:null;return Ke({token:a.data.token,customer:_}),n({token:a.data.token,customer:_}),i(null),f(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):!a.ok&&a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:!a.ok&&(a.failure.kind==="http"||a.failure.kind==="unauthorized")&&a.failure.code==="invalid_code"?(i("invalid_code"),{ok:!1,code:"invalid_code",error:a.failure.error}):{ok:!1,code:"error",error:a.ok||a.failure.kind==="unavailable"?"Sign-in failed \u2014 please request a new link.":a.failure.error}}finally{u(!1)}},[t]),x=e.consumeUrlCode??!0;kn(()=>{if(!(typeof window>"u")&&v.current===void 0){if(!x){v.current=null;return}let b=new URL(window.location.href),a=b.searchParams.get("code");a&&(b.searchParams.delete("code"),window.history.replaceState(window.history.state,"",b.toString())),v.current=a,a&&c(a)}},[c,x]);let k=Xe(async b=>{if(typeof window<"u"&&Cn(window)){let P=await zr(b,Oe());if(P.claimed){if(P.token!==null){let _=P.customer??{email:b,name:null};return Ke({token:P.token,customer:_}),n({token:P.token,customer:_}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:P.error}}}let a=await Z(t,"/v1/account/login",{method:"POST",body:{email:b}});return a.ok?{ok:!0,via:"email"}:a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:{ok:!1,code:"error",error:(a.failure.kind==="network",a.failure.error)}},[t]),p=Xe(async()=>{let b=ce()?.token;b&&await Z(t,"/v1/account/logout",{method:"POST",token:b,body:{}}),ee(),n(null),i(null)},[t]),A=Xe(async()=>{let b=ce();if(!b)return;let a=await Z(t,"/v1/account/me",{token:b.token}),P=()=>ce()?.token===b.token;if(a.ok){if(!P())return;let _=a.data.customer??b.customer;Ke({token:b.token,customer:_}),n({token:b.token,customer:_}),f(!1);return}if(a.failure.kind==="unauthorized"){if(!P())return;ee("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){f(!0);return}},[t]);return{status:y?"pending":r?"signed_in":l?"unavailable":"signed_out",customer:r?.customer??null,token:r?.token??null,reason:r?null:o,login:k,verifyCode:c,logout:p,refresh:A}}import{useCallback as Ve,useEffect as Nt,useRef as rt,useState as qe}from"react";import{useEffect as jr,useRef as wn,useState as ve}from"react";import{Fragment as It,jsx as K,jsxs as Ne}from"react/jsx-runtime";var Lt={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},Kr={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},Yr={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},Pn={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},ke={margin:0},Wr={color:"#b91c1c",margin:0};function tt({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:f}){let y=Ue({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[v,c]=ve(""),[x,k]=ve("form"),[p,A]=ve(!1),[w,b]=ve(null),[a,P]=ve(null),[_,s]=ve(!1),d=wn(void 0),m=wn(!1);jr(()=>()=>{d.current&&clearTimeout(d.current)},[]);let g=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},h=async()=>{let R=v.trim();if(!R||p||m.current)return;m.current=!0,A(!0),b(null),P(null);let O=await u.login(R);if(m.current=!1,A(!1),O.ok){if(O.via==="preview")return;k("sent"),g();return}O.code!=="unavailable"&&(b(O.code==="rate_limited"?"rate_limited":"error"),P(O.error))};if(u.status==="unavailable")return f?K(It,{children:f()}):K("div",{className:n,style:n?o:{...Lt,...o},"data-state":"unavailable",children:K("p",{style:ke,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:v.trim(),canResend:_,resend:()=>{h(),g()},submitting:p,reset:()=>k("form")};return l?K(It,{children:l(R)}):Ne("div",{className:n,style:n?o:{...Lt,...o},"data-state":"sent",children:[Ne("p",{style:ke,children:["Check your email \u2014 if ",K("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),_?Ne("p",{style:ke,children:["Didn't get it?"," ",K("button",{type:"button",style:Pn,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",K("button",{type:"button",style:Pn,onClick:R.reset,children:"use a different email"}),"."]}):K("p",{style:ke,children:"It can take a minute to arrive."})]})}let C={email:v,setEmail:c,submit:()=>void h(),submitting:p,errorKind:w,errorMessage:a,reason:u.reason};if(i)return K(It,{children:i(C)});let S=R=>{R.preventDefault(),C.submit()};return Ne("form",{className:n,style:n?o:{...Lt,...o},onSubmit:S,"data-state":"form",children:[u.reason==="session_expired"&&K("p",{style:ke,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&K("p",{style:ke,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),Ne("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[K("span",{children:"Email address"}),K("input",{type:"email",value:v,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:Kr})]}),K("button",{type:"submit",style:Yr,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&K("p",{style:Wr,role:"alert",children:w==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}import{Fragment as Zr,jsx as te,jsxs as Ce}from"react/jsx-runtime";var Hr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},Jr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},Me={color:"#6b7280",fontSize:"0.875rem"};function Gr(e){switch(e.status){case"paid":return null;case"refunded":return"Refunded";case"partially_refunded":return"Partially refunded";case"disputed":return"Disputed";default:return e.status}}function Et({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?te(Zr,{children:o()}):Ce("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&te("h3",{children:n}),te("p",{style:Me,children:"No orders yet."})]}):Ce("div",{className:t,style:r,children:[n!==null&&te("h3",{children:n}),te("ul",{style:t?void 0:Hr,children:e.map(l=>{if(i)return te("li",{style:{display:"contents"},children:i(l)},l.id);let f=Ee(l.created_at),y=Gr(l);return Ce("li",{style:t?void 0:Jr,children:[Ce("div",{children:[l.order_number!==null&&Ce("strong",{children:["Order #",l.order_number]})," ",f&&te("span",{style:Me,children:f})," ",l.source==="subscription"&&te("span",{style:Me,children:"\xB7 subscription"}),y&&Ce("span",{style:Me,children:[" \xB7 ",y]})]}),l.line_items.length>0&&te("div",{style:Me,children:l.line_items.map(u=>u.name?`${u.quantity&&u.quantity>1?`${u.quantity} \xD7 `:""}${u.name}`:null).filter(Boolean).join(", ")}),te("div",{children:F(l.amount_total,l.currency)})]},l.id)})})]})}import{useEffect as _n,useRef as Qr,useState as ie}from"react";import{Fragment as An,jsx as V,jsxs as Q}from"react/jsx-runtime";var Xr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},ei={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},we={color:"#6b7280",fontSize:"0.875rem"},ti={color:"#b91c1c",fontSize:"0.875rem",margin:0},ni={color:"#065f46",fontSize:"0.875rem",margin:0},Ut={display:"flex",flexWrap:"wrap",gap:"0.5rem"},pe={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Rn={...pe,border:"1px solid #111827",background:"#111827",color:"white"},ri={...pe,border:"1px solid #b91c1c",color:"#b91c1c"},ii={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},xn={panel:"none",mutation:null,portalRefused:!1};function oi(e){let t=Ee(e.current_period_end);return e.ended?{text:"This subscription has ended.",tone:"ended"}:e.cancel_at_period_end?{text:t?`Scheduled to cancel \u2014 stays active until ${t}.`:"Scheduled to cancel at the end of the current period.",tone:"warn"}:e.status==="past_due"||e.status==="unpaid"?{text:"There's a problem with your last payment \u2014 please update your card.",tone:"warn"}:e.status==="active"||e.status==="trialing"?{text:t?`Renews on ${t}.`:"Active.",tone:"ok"}:{text:`Status: ${e.status}.`,tone:"warn"}}function si({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=ie(e?.name??""),[f,y]=ie(o?.line1??""),[u,v]=ie(o?.line2??""),[c,x]=ie(o?.city??""),[k,p]=ie(o?.state??""),[A,w]=ie(o?.postal_code??""),[b,a]=ie(o?.country??""),P=(_,s,d,m)=>Q("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[V("span",{children:_}),V("input",{style:ii,value:s,onChange:g=>d(g.target.value),required:m?.required,maxLength:m?.maxLength})]});return Q("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:_=>{_.preventDefault(),r({name:i.trim()||null,address:{line1:f.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:A.trim()||null,country:b.trim().toUpperCase()}})},children:[P("Name",i,l),P("Address line 1",f,y,{required:!0}),P("Address line 2",u,v),P("City",c,x),P("State / region",k,p),P("Postal code",A,w),P("Country (2-letter code)",b,a,{required:!0,maxLength:2}),Q("div",{style:Ut,children:[V("button",{type:"submit",style:Rn,disabled:t,children:t?"Saving\u2026":"Save address"}),V("button",{type:"button",style:pe,onClick:n,disabled:t,children:"Cancel"})]})]})}function nt({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:f,heading:y="Your subscriptions",renderEmpty:u,renderRow:v}){let[c,x]=ie(t),[k,p]=ie({}),A=Qr(new Set);_n(()=>{x(t)},[t]),_n(()=>{let s=d=>{d.persisted&&(A.current.clear(),p(m=>{let g=!1,h={};for(let[C,S]of Object.entries(m))S.mutation?.phase==="pending"?(h[C]={...S,mutation:null},g=!0):h[C]=S;return g?h:m}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let w=(s,d)=>p(m=>({...m,[s]:{...m[s]??xn,...d}})),b=s=>{x(d=>d.map(m=>m.id===s.id?s:m)),i?.(s)},a=async(s,d,m,g)=>{if(A.current.has(s.id))return{ok:!1};A.current.add(s.id);try{w(s.id,{mutation:{kind:d,phase:"pending"}});let h=await Z(e,m,{method:"POST",token:r.token,body:g??{}});if(h.ok)return{ok:!0,data:h.data};let{failure:C}=h;return C.kind==="unauthorized"?(n?.({code:C.code,error:C.error}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="unavailable"?(o?.(),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="ended"?(b({...s,ended:!0,status:"canceled"}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="portal_unavailable"?(w(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(w(s.id,{mutation:{kind:d,phase:"error",error:C.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":C.error}}),{ok:!1})}finally{A.current.delete(s.id)}},P=s=>r.kind==="session"?{cancel:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/cancel`,reactivate:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/reactivate`,address:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/address`,portal:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/portal-session`}:{cancel:"/v1/account/manage/cancel",reactivate:null,address:null,portal:"/v1/account/manage/portal-session"},_=s=>{let d=k[s.id]??xn,m=P(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>w(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>w(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let g=await a(s,"cancel",m.cancel);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:m.reactivate!==null,reactivate:()=>{m.reactivate&&(async()=>{let g=await a(s,"reactivate",m.reactivate);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{m.address&&w(s.id,{panel:"address",mutation:null})},saveAddress:g=>{m.address&&(async()=>{let h=await a(s,"address",m.address,{shipping_address:g});if(h.ok){let C=h.data.subscription;C&&b(C),w(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let g=await a(s,"portal",m.portal);g.ok&&typeof g.data.url=="string"?window.location.href=g.data.url:g.ok&&w(s.id,{mutation:{kind:"portal",phase:"error",error:"Card update is temporarily unavailable."}})})()}}};return c.length===0?u?V(An,{children:u()}):Q("div",{className:l,style:f,"data-state":"empty",children:[y!==null&&V("h3",{children:y}),V("p",{style:we,children:"No subscriptions."})]}):Q("div",{className:l,style:f,children:[y!==null&&V("h3",{children:y}),V("ul",{style:l?void 0:Xr,children:c.map(s=>{let d=_(s);return v?V("li",{style:{display:"contents"},children:v(d)},s.id):V("li",{style:l?void 0:ei,"data-status":s.status,"data-ended":s.ended||void 0,children:V(ai,{ctx:d})},s.id)})})]})}function ai({ctx:e}){let t=e.subscription,r=oi(t),n=Ee(t.current_period_end),o=`${F(t.current_amount,t.currency)} ${vn(t.plan_interval,t.plan_interval_count)}`,i=e.mutation?.phase==="pending",l=i?e.mutation?.kind:null;return Q(An,{children:[Q("div",{children:[V("strong",{children:t.plan_title??"Subscription"})," ",Q("span",{style:we,children:["\xB7 ",o]}),t.is_test&&V("span",{style:we,children:" \xB7 test"})]}),V("div",{style:r.tone==="warn"?void 0:we,children:r.text}),t.ended?V("p",{style:we,children:"This subscription has ended \u2014 to start again, subscribe from the product page."}):e.panel==="confirm_cancel"?Q("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[V("p",{style:{margin:0},children:n?`Your subscription stays active until ${n} \u2014 after that it won't renew and you won't be charged again.`:"Your subscription stays active until the end of the current billing period \u2014 after that it won't renew and you won't be charged again."}),Q("div",{style:Ut,children:[V("button",{type:"button",style:ri,onClick:e.confirmCancel,disabled:i,children:l==="cancel"?"Canceling\u2026":"Confirm cancellation"}),V("button",{type:"button",style:pe,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?V(si,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):Q("div",{style:Ut,children:[t.cancel_at_period_end?e.reactivateAvailable?V("button",{type:"button",style:Rn,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):V("span",{style:we,children:"To keep this subscription, sign in with your email address on this page."}):V("button",{type:"button",style:pe,onClick:e.openCancelConfirm,disabled:i,children:"Cancel subscription"}),t.shipping_address!==void 0&&!t.cancel_at_period_end&&V("button",{type:"button",style:pe,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&V("button",{type:"button",style:pe,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&V("p",{style:ti,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&V("p",{style:ni,role:"status",children:e.mutation.kind==="cancel"?n?`Cancellation scheduled \u2014 you keep access until ${n}.`:"Cancellation scheduled.":e.mutation.kind==="reactivate"?"Your subscription will continue.":e.mutation.kind==="address"?"Shipping address updated.":"Done."})]})}import{Fragment as Pe,jsx as M,jsxs as J}from"react/jsx-runtime";var ui={display:"flex",flexDirection:"column",gap:"1.25rem"},On={color:"#6b7280",fontSize:"0.875rem"},li={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},Tn={color:"#b91c1c"},it={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function ci({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:f,renderHeader:y,renderPmBanner:u,renderManageExpired:v}){let c=Ue({apiUrl:e}),x=rt(void 0),[k,p]=qe(null),[A,w]=qe(!1);Nt(()=>{if(!(typeof window>"u")){if(x.current===void 0){let I=new URL(window.location.href),L=I.searchParams.get("manage_code"),B=I.searchParams.get("pm");(L!==null||B!==null)&&(I.searchParams.delete("manage_code"),I.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",I.toString())),x.current={manageCode:L,pmUpdated:B==="updated"}}p(x.current.manageCode),w(x.current.pmUpdated)}},[]);let[b,a]=qe(null),P=rt(!1),_=rt(0),s=Ve(I=>{a({phase:"verifying"}),(async()=>{let L=await Z(e,"/v1/account/manage/verify",{method:"POST",body:{manage_code:I}});if(L.ok&&typeof L.data.manage_token=="string"&&L.data.subscription){a({phase:"active",token:L.data.manage_token,sub:L.data.subscription,siteName:null});return}if(!L.ok&&L.failure.kind==="unavailable"){a({phase:"unavailable"});return}if(!L.ok&&L.failure.kind==="network"){a({phase:"error",error:L.failure.error});return}a({phase:"expired"})})()},[e]);Nt(()=>{!k||P.current||(P.current=!0,s(k))},[k,s]);let d=Ve(async()=>{let I=b;if(!I||I.phase!=="active")return;let L=++_.current,B=await Z(e,"/v1/account/manage/subscription",{token:I.token});L===_.current&&(B.ok&&B.data.subscription?a({phase:"active",token:I.token,sub:B.data.subscription,siteName:typeof B.data.site?.name=="string"?B.data.site.name:I.siteName}):!B.ok&&B.failure.kind==="unauthorized"?a({phase:"expired"}):!B.ok&&B.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[m,g]=qe({phase:"loading"}),[h,C]=qe(0),S=h>0,R=rt(0),O=c.token,q=Ve(async()=>{if(!O)return;let I=++R.current,L=await Z(e,"/v1/account/me",{token:O});if(I===R.current){if(L.ok){g({phase:"ready",data:L.data});return}if(L.failure.kind==="unauthorized"){ee("session_expired");return}if(L.failure.kind==="unavailable"){ee();return}g({phase:"error",error:L.failure.error})}},[e,O]);Nt(()=>{!O||k||(g({phase:"loading"}),q())},[O,k,q]);let j=Ve(async()=>{C(I=>I+1);try{b&&b.phase==="active"?await d():await q()}finally{C(I=>I-1)}},[b,d,q]),D=Ve(I=>{R.current++,_.current++,a(L=>L&&L.phase==="active"&&L.sub.id===I.id?{...L,sub:I}:L),g(L=>L.phase==="ready"?{phase:"ready",data:{...L.data,subscriptions:L.data.subscriptions.map(B=>B.id===I.id?I:B)}}:L)},[]),T=t?r:{...ui,...r},E=I=>{if(!A)return null;let B={state:I.some(H=>!H.ended&&(H.status==="past_due"||H.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void j(),checking:S};return u?u(B):M("div",{style:li,role:"status","data-pm-state":B.state,children:B.state==="retrying"?J(Pe,{children:[M("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),M("p",{style:{margin:"0.375rem 0 0"},children:M("button",{type:"button",style:it,onClick:B.checkAgain,disabled:S,children:S?"Checking\u2026":"Check again"})})]}):M("p",{style:{margin:0},children:"Card updated \u2014 your subscription is back in good standing."})})};if(k)return!b||b.phase==="verifying"?i?M(Pe,{children:i()}):M("div",{className:t,style:T,role:"status",children:M("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?J("div",{className:t,style:T,children:[E([b.sub]),M(nt,{apiUrl:e,subscriptions:[b.sub],auth:{kind:"manage",token:b.token},heading:"Your subscription",onSubscriptionChange:D,onAuthError:()=>a({phase:"expired"}),onUnavailable:()=>a({phase:"unavailable"})})]}):b.phase==="unavailable"?M("div",{className:t,style:T,"data-state":"unavailable",children:M("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?J("div",{className:t,style:T,children:[M("p",{style:Tn,role:"alert",children:b.error}),M("p",{children:M("button",{type:"button",style:it,onClick:()=>s(k),children:"Try again"})})]}):J("div",{className:t,style:T,"data-state":"manage-expired",children:[v?v():M("p",{children:"This manage link is no longer valid. Sign in below with the email you used at checkout to manage your subscription."}),M(tt,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?M(Pe,{children:i()}):M("div",{className:t,style:T,role:"status",children:M("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return M("div",{className:t,style:T,children:M(tt,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(m.phase==="loading")return i?M(Pe,{children:i()}):M("div",{className:t,style:T,role:"status",children:M("p",{children:"Loading your account\u2026"})});if(m.phase==="error")return l?M(Pe,{children:l({error:m.error,retry:()=>void q()})}):J("div",{className:t,style:T,children:[J("p",{style:Tn,role:"alert",children:["We couldn't load your account \u2014 ",m.error]}),M("p",{children:M("button",{type:"button",style:it,onClick:()=>void q(),children:"Try again"})})]});let{data:U}=m,Y=U.customer??c.customer??{email:"",name:null},N=()=>void c.logout(),z=U.orders.length===0&&U.subscriptions.length===0;return J("div",{className:t,style:T,children:[y?y({customer:Y,site:U.site??null,signOut:N}):J("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[J("div",{children:[M("h2",{style:{margin:0},children:"Your account"}),J("p",{style:{...On,margin:0},children:["Signed in as ",Y.email]})]}),M("button",{type:"button",style:it,onClick:N,children:"Sign out"})]}),E(U.subscriptions),z?f?f():J("p",{style:On,children:["Nothing here yet \u2014 orders and subscriptions for ",Y.email," ","will show up on this page."]}):J(Pe,{children:[U.subscriptions.length>0&&M(nt,{apiUrl:e,subscriptions:U.subscriptions,auth:{kind:"session",token:O},onSubscriptionChange:D,onAuthError:()=>ee("session_expired"),onUnavailable:()=>ee()}),M(Et,{orders:U.orders})]})]})}export{tt as AccountLogin,Et as AccountOrders,ci as AccountPage,Or as AddToCartButton,En as AifeaturesCaptcha,kr as BuyButton,Tr as CartCheckoutButton,wt as MARKET_COUNTRIES,en as MAX_CART_LINES,Ir as OrderConfirmation,qr as PlanPicker,nr as ProductPrice,nt as SubscriptionList,yr as VariantPicker,$t as ZERO_DECIMAL_CURRENCIES,ct as applySelectionToUrl,F as formatPrice,fe as getOptions,oe as getVariants,_e as isMultiVariant,ot as isValueAvailable,st as isValueInCatalog,Sn as planRecurringAmount,at as reanchorSelection,le as resolveVariant,Fe as searchFromSelection,xe as selectedImages,Dt as selectedValues,lt as selectionFromSearch,re as useCart,kt as useCartCheckout,St as useCartItems,Gn as useCartSummary,bt as useCheckout,er as useMarket,ue as useProduct,Ue as useSession,ne as valueSlug,ut as variantPriceRange};
|
|
2
|
+
import{useState as qt,useEffect as In}from"react";import{Turnstile as En}from"@marsidev/react-turnstile";import{jsx as $t}from"react/jsx-runtime";function Un({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=qt(null),[f,y]=qt(!0);return In(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(u=>u.json()).then(u=>{l(u.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),f||!i?null:$t("div",{className:o,children:$t(En,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}import{useCallback as Nn,useEffect as Mn,useRef as Vn,useState as $e}from"react";var De=[1e3,3e3];function ue(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=$e(null),[l,f]=$e(!0),[y,u]=$e(null),[v,c]=$e(0),x=Vn(e);Mn(()=>{let p=!1,A;f(!0),u(null),x.current!==e&&(x.current=e,i(null));let w=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let P=await a.json().catch(()=>null);if(!p)if(!a.ok||!P){if(a.status>=500&&b<De.length){A=setTimeout(()=>w(b+1),De[b]);return}u(P?.error??`Request failed (${a.status})`),i(null),f(!1)}else i(P),f(!1)}).catch(a=>{if(!p){if(b<De.length){A=setTimeout(()=>w(b+1),De[b]);return}u(a instanceof Error?a.message:"Failed to load product"),f(!1)}})};return w(0),()=>{p=!0,A&&clearTimeout(A)}},[e,r,n,v]);let k=Nn(()=>c(p=>p+1),[]);return{product:o,loading:l,error:y,refresh:k}}var Dt=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function F(e,t,r){let n=Dt.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function oe(e){return e.variants??[]}function fe(e){return e.options??[]}function _e(e){return fe(e).length>0}function Be(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function le(e,t){let r=Object.keys(t);return e.find(n=>{let o=n.option_values;return o.length!==r.length?!1:o.every(i=>t[i.option_id]===i.value_id)})??null}function st(e,t,r,n){return e.some(o=>{let i=Be(o);if(i[r]!==n)return!1;for(let[l,f]of Object.entries(t))if(l!==r&&i[l]!==f)return!1;return!0})}function at(e,t,r){return e.some(n=>Be(n)[t]===r)}function ut(e,t,r,n){let o={[r]:n};for(let[l,f]of Object.entries(t)){if(l===r)continue;e.some(u=>{let v=Be(u);return v[r]===n&&v[l]===f})&&(o[l]=f)}return e.some(l=>{let f=Be(l);return Object.entries(o).every(([y,u])=>f[y]===u)})?o:{[r]:n}}function lt(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function Bt(e,t){let r={};for(let n of fe(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i&&(r[n.title]=i.value)}return r}function ne(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function ct(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((i,l)=>{n.has(ne(l))||n.set(ne(l),i)});let o={};for(let i of fe(e)){let l=ne(i.title);if(l.length===0)continue;let f=n.get(l);if(f===void 0)continue;let y=ne(f);if(y.length===0)continue;let u=i.values.find(v=>ne(v.value)===y);u&&(o[i.id]=u.id)}return o}function Fe(e,t){let r={};for(let[n,o]of Object.entries(Bt(e,t))){let i=ne(n),l=ne(o);i.length===0||l.length===0||(r[i]=l)}return r}function xe(e,t){let r=[];for(let n of fe(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i?.images?.length&&r.push(...i.images)}return r.length>0?r:e.images??[]}function dt(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of fe(e)){let o=ne(n.title);o.length!==0&&r.searchParams.delete(o)}for(let[n,o]of Object.entries(Fe(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}import{useCallback as Bn,useEffect as Gt,useRef as Zt,useState as yt}from"react";var ft="aifeatures_cart",mt="aifeatures_market",Ft="aifeatures_cart_cleared";var pt="aifeatures:cart-storage",Re=new Map;function Ae(e){if(Re.has(e))return Re.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function me(e,t){if(typeof window>"u"){Re.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Re.delete(e)}catch{Re.set(e,t)}qn(e)}function qn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(pt,{detail:{key:e}}))}catch{}}function ze(e,t){if(typeof window>"u")return()=>{};let r=o=>{(o.key===e||o.key===null)&&t()},n=o=>{o.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(pt,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(pt,n)}}function $n(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[l,f]of Object.entries(t.selection))typeof f=="string"&&(n[l]=f);let o=typeof t.display=="object"&&t.display!==null?t.display:{},i={name:typeof o.name=="string"?o.name:"",variantTitle:typeof o.variantTitle=="string"?o.variantTitle:null,image:typeof o.image=="string"?o.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:i}}function se(){let e=Ae(ft);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let o of t){let i=$n(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function X(e){me(ft,JSON.stringify(e))}function zt(e){return ze(ft,e)}function jt(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of se()){let o=t.get(n.variantId);if(o===void 0){r.push(n);continue}let i=n.quantity-o;i>0&&r.push({...n,quantity:i})}X(r)}function W(){let e=Ae(mt);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function Kt(e){me(mt,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function ge(e){return ze(mt,e)}function Yt(e){let t=[],r=Ae(Ft);if(r)try{let o=JSON.parse(r);Array.isArray(o)&&(t=o.filter(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(o=>o.ts>n),t.some(o=>o.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),me(Ft,JSON.stringify(t)),!0)}var je="aifeatures_session",gt=null;function Wt(){return gt}function Dn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.token!="string"||t.token.length===0)return null;let r=null;if(typeof t.customer=="object"&&t.customer!==null){let n=t.customer;typeof n.email=="string"&&n.email.length>0&&(r={email:n.email,name:typeof n.name=="string"?n.name:null})}return{token:t.token,customer:r}}function ce(){let e=Ae(je);if(!e)return null;try{return Dn(JSON.parse(e))}catch{return null}}function Ht(){return ce()?.token??null}function Ke(e){gt=null,me(je,JSON.stringify(e))}function ee(e){gt=e??null,me(je,null)}function Jt(e){return ze(je,e)}var Fn=1500;function Oe(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function Ye(e,t){return!("requestId"in e)||e.requestId===t}function bt(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;y?.type==="aifeatures:test-checkout-ack"&&Ye(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),Fn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function Qt(e){if(window.self!==window.top)try{return window.top.location.href=e,"navigating"}catch{if(window.open(e,"_blank"))return"stayed"}return window.location.href=e,"navigating"}function ht(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=yt(!1),[o,i]=yt(null),[l,f]=yt(null),y=Zt(!1),u=Zt(null);return Gt(()=>{let c=x=>{x.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",c),()=>window.removeEventListener("pageshow",c)},[]),Gt(()=>{if(typeof window>"u"||window.self===window.top)return;let c=x=>{if(x.source!==window.parent)return;let k=x.data;if(k?.type!=="aifeatures:test-checkout-ack"||k.status!=="failed")return;let p=u.current;p===null||!Ye(k,p)||(u.current=null,i(typeof k.error=="string"&&k.error?k.error:"The test purchase could not be created."),y.current=!1,n(!1))};return window.addEventListener("message",c),()=>window.removeEventListener("message",c)},[]),{startCheckout:Bn(async({productId:c,variantId:x,quantity:k,amount:p,metadata:A,successUrl:w,cancelUrl:b,customerEmail:a,planId:P,expectedUnitAmount:_,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),f(null),P!==void 0){let d=Ht();if(d)try{let m=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:P,...x!==void 0?{variant_id:x}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.text().catch(()=>""),h=null;try{h=g?JSON.parse(g):null}catch{h=null}if(m.ok){if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Qt(h.url)==="stayed"&&(y.current=!1,n(!1));return}let C=m.status===404&&g.trim()==="";if(m.status===401||C)ee();else{i(h?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}}catch(m){i(m instanceof Error?m.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=P===void 0?W():null,m=await fetch(`${t}/v1/p/${c}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...x!==void 0?{variant_id:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{plan_id:P}:{},...A!==void 0?{metadata:A}:{},...a!==void 0?{customer_email:a}:{},..._!==void 0&&s!==void 0&&P===void 0?{expected_unit_amount:_,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.json().catch(()=>null);if(!m.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){f({currentUnitAmount:g.current_unit_amount,currency:g.currency}),i(`The price has changed to ${F(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(g?.code==="preview_domain"){let h=Oe();if(u.current=h,await bt({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{planId:P}:{},...a!==void 0?{customerEmail:a}:{},...A!==void 0?{metadata:A}:{}},h))return;u.current=null}i(g?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Qt(g.url)==="stayed"&&(y.current=!1,n(!1))}catch(d){i(d instanceof Error?d.message:"Checkout failed"),y.current=!1,n(!1)}}},[t]),loading:r,error:o,priceChange:l}}import{useCallback as We,useEffect as zn,useState as Xt}from"react";var tn=20;function en(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function re(){let[e,t]=Xt([]),[r,n]=Xt(!1);zn(()=>{let u=()=>t(se());return u(),n(!0),zt(u)},[]);let o=We(u=>{let v=se(),c=en(u.quantity);return v.find(k=>k.variantId===u.variantId)?(X(v.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):v.length>=tn?{ok:!1,reason:"cart_full"}:(X([...v,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=We(u=>{X(se().filter(v=>v.variantId!==u))},[]),l=We((u,v)=>{let c=se();if(v<=0){X(c.filter(k=>k.variantId!==u));return}let x=en(v);X(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),f=We(()=>{X([])},[]),y=e.reduce((u,v)=>u+v.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:f}}import{useCallback as jn,useEffect as nn,useMemo as St,useRef as Kn,useState as Te}from"react";var He={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},Yn={...He,inStock:!0,status:"error"};function Wn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function vt(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=re(),[o,i]=Te({}),[l,f]=Te({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=Te(!0),[v,c]=Te(null),[x,k]=Te(0),p=Kn(new Set),A=St(()=>JSON.stringify(r.map(_=>[_.productId,_.variantId,_.selection])),[r]),w=jn(()=>k(_=>_+1),[]);nn(()=>ge(w),[w]),nn(()=>{if(!n)return;if(r.length===0){i({}),f({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let _=!1;u(!0);let s=r,d=[...new Set(s.map(g=>g.productId))],m=async g=>{let h=new Map;return await Promise.all(d.map(async C=>{try{let S=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${g?`?country=${encodeURIComponent(g)}`:""}`);if(S.status===404){h.set(C,{kind:"not_found"});return}if(!S.ok){h.set(C,{kind:"error",message:`Request failed (${S.status})`});return}let R=await S.json();h.set(C,{kind:"ok",product:R})}catch(S){h.set(C,{kind:"error",message:S instanceof Error?S.message:"Failed to load product"})}})),h};return(async()=>{let g=W(),h=await m(g);if(g){let T=[...h.values()].filter(U=>U.kind==="ok"),E=T.filter(U=>U.product.base_currency);E.length>0&&E.length<T.length&&(h=await m(null))}if(_)return;let C=null,S=null,R=null;for(let T of d){let E=h.get(T);!E||E.kind!=="ok"||(C===null&&E.product.shipping_rates&&(C=E.product.shipping_rates),S===null&&E.product.free_shipping_over!=null&&(S=E.product.free_shipping_over),R===null&&E.product.shipping_countries&&(R=E.product.shipping_countries))}let O={},q=new Map,j=null;for(let T of s){let E=h.get(T.productId);if(!E||E.kind==="error"){O[T.variantId]=Yn,E&&j===null&&(j=E.message);continue}if(E.kind==="not_found"){O[T.variantId]=He;continue}let{product:U}=E;if(!U.active||U.purchasable===!1){O[T.variantId]=He;continue}let Y=U.variants??[],N=Y.find(J=>J.id===T.variantId)??null,z=T.variantId;if(!N){let J=le(Y,T.selection);if(!J){O[T.variantId]=He;continue}let Vt=q.get(T.variantId)??{};Vt.reanchorTo={variantId:J.id,selection:Wn(J)},q.set(T.variantId,Vt),p.current.add(J.id),N=J,z=J.id}let I=xe(U,T.selection)[0]??null,L={image:I,unitAmount:N.unit_amount,currency:N.currency,baseCurrency:U.base_currency??null,inStock:N.in_stock,available:N.available,maxQuantity:U.max_quantity,pdpSearch:Fe(U,T.selection),status:p.current.has(z)?"reanchored":"ok"};O[T.variantId]=L,O[z]=L;let B=q.get(T.variantId)??{};B.display={name:U.name,variantTitle:N.title,image:I},q.set(T.variantId,B)}let D=new Set(s.map(T=>T.variantId));for(let T of[...p.current])!D.has(T)&&!(T in O)&&p.current.delete(T);if(q.size>0){let T=se(),E=[],U=new Map,Y=!1;for(let N of T){let z=q.get(N.variantId),I={...N};z?.reanchorTo&&(I.variantId=z.reanchorTo.variantId,I.selection=z.reanchorTo.selection,Y=!0),z?.display&&(I.display.name!==z.display.name||I.display.variantTitle!==z.display.variantTitle||I.display.image!==z.display.image)&&(I.display=z.display,Y=!0);let L=U.get(I.variantId);if(L){L.quantity+=I.quantity,Y=!0;continue}E.push(I),U.set(I.variantId,I)}Y&&X(E)}_||(i(O),f({shippingRates:C,freeShippingOver:S,shippingCountries:R}),c(j),u(!1))})(),()=>{_=!0}},[n,A,t,x]);let b=St(()=>r.map(_=>{let s=o[_.variantId];return s?{..._,...s,image:s.image??_.display.image}:{..._,image:_.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:P}=St(()=>{let _=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(_+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:_,currency:s}},[b]);return{lines:b,subtotal:a,currency:P,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:v,refresh:w}}import{useCallback as Hn,useEffect as rn,useMemo as Jn,useRef as kt,useState as Le}from"react";var Gn=2e3;function Zn(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=re(),[l,f]=Le(null),[y,u]=Le(!1),[v,c]=Le(null),[x,k]=Le(null),[p,A]=Le(0);rn(()=>(k(W()),ge(()=>k(W()))),[]);let w=Jn(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=Hn(()=>A(s=>s+1),[]),a=kt(0),P=kt(!1),_=kt("idle");return rn(()=>{if(!i)return;if(o.length===0){f(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,m=!1,g,h=P.current?r:0;P.current=!0,_.current=_.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{u(!0);try{let S=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:d.signal,body:JSON.stringify({items:o.map(O=>({variant_id:O.variantId,quantity:O.quantity})),...x?{country:x}:{},...n?{shipping_option:n}:{}})});if(m||s!==a.current)return;if(!S.ok){if(S.status===429){let O=_.current==="idle";O&&(g=setTimeout(()=>{m||s!==a.current||(_.current="pending",A(q=>q+1))},Gn)),c(O?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else c(`Could not price this cart (${S.status})`);return}let R=await S.json();if(m||s!==a.current)return;f({currency:R.currency,subtotal:R.subtotal,shipping:R.shipping?{options:R.shipping.options.map(O=>({label:O.label,amount:O.amount,undiscountedAmount:O.undiscounted_amount})),selectedAmount:R.shipping.selected_amount,selectedLabel:R.shipping.selected_label,freeShippingOver:R.shipping.free_shipping_over,freeShippingCurrency:R.shipping.free_shipping_currency,thresholdMet:R.shipping.threshold_met,collectsAddress:R.shipping.collects_address}:null,total:R.total,totalIsFinal:R.total_is_final,tax:R.tax??null,unavailableVariantIds:R.unavailable_variant_ids}),c(null)}catch(S){if(m||d.signal.aborted||s!==a.current)return;c(S instanceof Error?S.message:"Could not price this cart")}finally{!m&&s===a.current&&u(!1)}},h);return()=>{m=!0,clearTimeout(C),g!==void 0&&clearTimeout(g),d.abort()}},[i,w,x,t,r,n,p]),{summary:l,loading:y,error:v,refresh:b}}import{useCallback as Qn,useEffect as on,useRef as sn,useState as Je}from"react";function Ct(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Je(!1),[o,i]=Je(null),[l,f]=Je(null),[y,u]=Je(null),v=sn(!1),c=sn(null);return on(()=>{let k=p=>{p.persisted&&(v.current=!1,n(!1))};return window.addEventListener("pageshow",k),()=>window.removeEventListener("pageshow",k)},[]),on(()=>{if(typeof window>"u"||window.self===window.top)return;let k=p=>{if(p.source!==window.parent)return;let A=p.data;if(A?.type!=="aifeatures:test-checkout-ack"||A.status!=="failed")return;let w=c.current;w===null||!Ye(A,w)||(c.current=null,i(typeof A.error=="string"&&A.error?A.error:"The test purchase could not be created."),v.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:Qn(async(k,{successUrl:p,cancelUrl:A,customerEmail:w,metadata:b,shippingOption:a}={})=>{if(!v.current){v.current=!0,n(!0),i(null),f(null),u(null);try{let P=W(),_=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:k.map(d=>({variant_id:d.variantId,quantity:d.quantity,...typeof d.unitAmount=="number"&&typeof d.currency=="string"?{expected_unit_amount:d.unitAmount,expected_currency:d.currency}:{}})),...P!==null?{country:P}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...w!==void 0?{customer_email:w}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:A??window.location.href})}),s=await _.json().catch(()=>null);if(!_.ok){if(s?.code==="shipping_option_unavailable"&&typeof s.requested=="string"&&Array.isArray(s.available)){u({requested:s.requested,available:s.available,currency:typeof s.currency=="string"?s.currency:""}),v.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let m of s.items)m&&typeof m.variant_id=="string"&&(d[m.variant_id]=m);f(d),v.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=Oe();if(c.current=d,await bt({items:k.map(g=>({productId:g.productId,variantId:g.variantId,quantity:g.quantity})),...w!==void 0?{customerEmail:w}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${_.status})`),v.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),v.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=s.url;return}catch{if(window.open(s.url,"_blank")){v.current=!1,n(!1);return}}window.location.href=s.url}catch(P){i(P instanceof Error?P.message:"Checkout failed"),v.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}import{useCallback as Xn,useEffect as an,useState as wt}from"react";var Pt=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function un(e){return e?Pt.find(t=>t.country===e.toUpperCase())?.currency??null:null}var ln=new Map;function er(e){let t=ln.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),ln.set(e,t)),t}function tr(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=wt(null),[o,i]=wt(!1),[l,f]=wt(null);an(()=>{let c=()=>n(W());return c(),i(!0),ge(c)},[]),an(()=>{let c=!1;return er(t).then(x=>{c||f(x)}),()=>{c=!0}},[t]);let y=Xn(c=>{Kt(c)},[]),u=un(l),v=o&&u!==null&&u!==un(r);return{market:r,suggestedCountry:l,setMarket:y,markets:Pt,shouldPrompt:v}}import{jsx as _t,jsxs as ir}from"react/jsx-runtime";var nr={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function rr({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:f,loading:y}=ue(e,{apiUrl:r});if(y||!f)return null;let u=oe(f),v=t!==void 0?u.find(x=>x.id===t)??null:f.options.length===0?u[0]??null:null;if(v){if(v.unit_amount===null)return null;let x=v.compare_at_amount!==null&&v.compare_at_amount>v.unit_amount;return ir("span",{className:o,style:i,children:[x&&_t("span",{className:l,style:l?void 0:nr,children:F(v.compare_at_amount,v.currency,n)}),F(v.unit_amount,v.currency,n)]})}let c=lt(u);return c?_t("span",{className:o,style:i,children:c.min===c.max?F(c.min,f.currency,n):`${F(c.min,f.currency,n)} \u2013 ${F(c.max,f.currency,n)}`}):f.unit_amount===null?null:_t("span",{className:o,style:i,children:F(f.unit_amount,f.currency,n)})}import{useEffect as xt,useMemo as or,useRef as cn,useState as dn}from"react";import{Fragment as hr,jsx as ye,jsxs as pn}from"react/jsx-runtime";var sr={marginBottom:"0.75rem"},ar={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},ur={display:"flex",flexWrap:"wrap",gap:"0.5rem"},lr={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},cr={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},fn={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},dr={...fn,cursor:"pointer"},pr=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,fr=e=>pr.test(e),mr={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},gr={display:"block",width:"1.5rem",height:"1.5rem",maxWidth:"100%",maxHeight:"100%",boxSizing:"border-box",borderRadius:3,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f3f4f6",border:"1px solid rgba(0, 0, 0, 0.2)"},yr="linear-gradient(to top right, transparent calc(50% - 2px), rgba(0,0,0,0.55) calc(50% - 2px), rgba(255,255,255,0.95) calc(50% - 1px), rgba(255,255,255,0.95) calc(50% + 1px), rgba(0,0,0,0.55) calc(50% + 1px), transparent calc(50% + 2px))";function br({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:f,optionClassName:y,optionLabelClassName:u,valueClassName:v,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[A,w]=dn(r??{}),b=p?r:A,[a,P]=dn(()=>new Set),_=h=>P(C=>C.has(h)?C:new Set(C).add(h));xt(()=>{P(h=>h.size===0?h:new Set)},[e]);let s=cn(!1);xt(()=>{if(!n||p||s.current||e.length===0||typeof window>"u"||(s.current=!0,Object.keys(A).length>0))return;let h=ct({options:e},window.location.search);Object.keys(h).length!==0&&(w(h),o?.(h))},[n,p,e]);let d=or(()=>e.length>0?t.filter(h=>h.option_values.length===e.length):t,[t,e]),m=cn(void 0);if(xt(()=>{let h=le(d,b),C=h?.id??null;m.current!==C&&(m.current=C,i?.(h))},[d,b]),e.length===0)return null;let g=(h,C)=>{let S=ut(d,b,h,C);p||(w(S),n&&dt({options:e},S)),o?.(S)};return ye("div",{className:l,style:f,children:e.map(h=>pn("div",{className:y,style:y?void 0:sr,children:[ye("span",{className:u,style:u?void 0:ar,children:h.title}),ye("div",{style:ur,children:h.values.map(C=>{let S=b[h.id]===C.id,R=st(d,b,h.id,C.id),O=R||at(d,h.id,C.id),q=[v,S?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,j=C.swatch??null,D=j&&!a.has(j)?j:null,T=D?fr(D):!1,E=v?void 0:{...lr,...S?cr:{},...R?{}:O?dr:fn,...D?{...mr,textDecoration:"none"}:{}},U=R?C.value:`${C.value} \u2014 unavailable with your current selection`;return ye("button",{type:"button",className:q,style:E,disabled:!O,"aria-pressed":S,"aria-label":D?U:void 0,title:D?U:void 0,"data-selected":S?"true":void 0,"data-available":R?"true":"false","data-swatch":D?T?"hex":"image":void 0,onClick:()=>g(h.id,C.id),children:D?pn(hr,{children:[ye("span",{"aria-hidden":"true",className:k,style:k?void 0:{...gr,...T?{background:D}:{},...T&&R?{}:{backgroundImage:[...R?[]:[yr],...T?[]:[`url(${JSON.stringify(D)})`]].join(", ")}}}),T?null:ye("img",{src:D,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>_(D)})]}):C.value},C.id)})})]},h.id))})}import{useEffect as Sr}from"react";function Ge(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}import{Fragment as Rt,jsx as de,jsxs as Ie}from"react/jsx-runtime";var vr={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},kr={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function mn(){return Ie("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[de("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),de("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:de("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Cr({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,apiUrl:u,disabled:v,className:c,style:x,errorClassName:k,spinner:p=!0,children:A}){let{product:w,loading:b,error:a,refresh:P}=ue(e,{apiUrl:u}),{startCheckout:_,loading:s,error:d,priceChange:m}=ht({apiUrl:u});Sr(()=>{m&&P()},[m,P]);let g=w!==null&&!w.payments_ready&&!Ge(),h=w!==null&&!w.active,C=w!==null&&w.purchasable===!1,S=w!==null&&_e(w),R=w!==null?oe(w):[],O=t!==void 0?R.find(L=>L.id===t)??null:!S&&R.length===1?R[0]:null,q=S&&!O,j=O!==null&&!O.in_stock,D=n??void 0,T=w?.subscription??null,E=T!==null&&T.required&&!T.ready,U=T!==null&&T.required&&T.ready&&D===void 0,Y=!!v||b||!w||g||h||C||E||U||q||j||s,N;s?N=Ie(Rt,{children:[p&&de(mn,{}),"Processing\u2026"]}):b?N=Ie(Rt,{children:[p&&de(mn,{}),A??"Buy now"]}):g?N="Payments not set up":h||C?N="Unavailable":E?N="Currently unavailable":U?N="Select a plan":q?N="Select options":j?N="Out of stock":A!==void 0?N=A:D!==void 0?N="Subscribe":N="Buy now";let z=d??a;return Ie(Rt,{children:[de("button",{type:"button",className:c,style:x,disabled:Y,onClick:()=>{let L=o===void 0&&D===void 0&&W()===null&&O!==null&&!O.allow_custom_amount&&typeof O.unit_amount=="number"?{expectedUnitAmount:O.unit_amount,expectedCurrency:O.currency}:{};_({productId:e,variantId:t,quantity:D!==void 0?void 0:r,amount:o,planId:D,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,...L})},children:N}),z&&Ie("div",{role:"alert",className:k,style:k?void 0:vr,children:[z,w===null&&!b&&a!==null&&de("button",{type:"button",onClick:P,style:kr,children:"Tap to retry"})]})]})}import{useEffect as wr,useRef as Pr,useState as gn}from"react";import{Fragment as yn,jsx as be,jsxs as Ze}from"react/jsx-runtime";var _r={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},xr={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Rr=1500;function Ar(){return Ze("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[be("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),be("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:be("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Or(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Tr({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:f,errorClassName:y,spinner:u=!0,children:v}){let{product:c,loading:x,error:k,refresh:p}=ue(e,{apiUrl:o}),{add:A}=re(),[w,b]=gn(!1),[a,P]=gn(!1),_=Pr(void 0);wr(()=>()=>{_.current&&clearTimeout(_.current)},[]);let s=c!==null&&!c.payments_ready&&!Ge(),d=c!==null&&!c.active,m=c!==null&&c.purchasable===!1,g=c!==null&&!x&&oe(c).length===0,h=c!==null&&c.allow_custom_amount,C=c!==null&&c.subscription?.required===!0,S=c!==null&&_e(c),R=c!==null?oe(c):[],O=t!==void 0?R.find(N=>N.id===t)??null:r!==void 0&&S?le(R,r):!S&&R.length===1?R[0]:null,q=c!==null&&!g&&!O,j=O!==null&&!O.in_stock,D=!!i||x||!c||s||d||m||g||h||C||q||j,T=()=>{if(!c||!O)return;let N=r??Or(O);if(!A({productId:e,variantId:O.id,quantity:n,selection:N,display:{name:c.name,variantTitle:O.title,image:xe(c,N)[0]??null}}).ok){b(!0);return}b(!1),P(!0),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>P(!1),Rr)},E;x?E=Ze(yn,{children:[u&&be(Ar,{}),v??"Add to cart"]}):s?E="Payments not set up":d||m||g||h?E="Unavailable":C?E="Subscription only":q?E="Select options":j?E="Out of stock":a?E="Added to cart":v!==void 0?E=v:E="Add to cart";let U=w?"Your cart is full \u2014 remove an item before adding another.":k;return Ze(yn,{children:[be("button",{type:"button",className:l,style:f,disabled:D,"data-added":a?"true":void 0,onClick:T,children:E}),U&&Ze("div",{role:"alert",className:y,style:y?void 0:_r,children:[U,c===null&&!x&&k!==null&&!w&&be("button",{type:"button",onClick:p,style:xr,children:"Tap to retry"})]})]})}import{Fragment as At,jsx as ae,jsxs as Qe}from"react/jsx-runtime";var bn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function hn(){return Qe("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[ae("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),ae("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:ae("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Lr({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:f,style:y,errorClassName:u,spinner:v=!0,children:c}){let{items:x,hydrated:k}=re(),{lines:p}=vt({apiUrl:e}),{startCheckout:A,loading:w,error:b,conflicts:a}=Ct({apiUrl:e}),P=k&&x.length===0,_=p.some(g=>g.status==="unavailable"),s=!!l||!k||P||_||w,d;w?d=Qe(At,{children:[v&&ae(hn,{}),"Processing\u2026"]}):k?P?d="Cart is empty":_?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=Qe(At,{children:[v&&ae(hn,{}),c??"Checkout"]});let m=a?Object.keys(a).length:0;return Qe(At,{children:[ae("button",{type:"button",className:f,style:y,disabled:s,onClick:()=>A(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),m>0&&ae("div",{role:"alert",className:u,style:u?void 0:bn,children:m===1?"An item in your cart changed \u2014 please review your cart and try again.":`${m} items in your cart changed \u2014 please review your cart and try again.`}),b&&ae("div",{role:"alert",className:u,style:u?void 0:bn,children:b})]})}import{useEffect as Xe,useRef as Sn,useState as Ot}from"react";import{Fragment as he,jsx as $,jsxs as H}from"react/jsx-runtime";var Tt="af_order_confirmation_session",Ir=1800*1e3;function Er({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:f=1500,renderNoSession:y,renderPending:u,renderPaid:v,renderFailed:c}){let[x,k]=Ot(n),[p,A]=Ot(null),[w,b]=Ot(!1),a=Sn(void 0);Xe(()=>{if(n!==void 0){k(n);return}if(a.current!==void 0){k(a.current);return}let d=new URL(window.location.href),m=d.searchParams.get("session_id");if(m){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(Tt,JSON.stringify({id:m,ts:Date.now()}))}catch{}}else try{let g=sessionStorage.getItem(Tt);if(g){let h=JSON.parse(g);typeof h.id=="string"&&typeof h.ts=="number"&&Date.now()-h.ts<=Ir?m=h.id:sessionStorage.removeItem(Tt)}}catch{}a.current=m,k(m)},[n]),Xe(()=>{if(!x)return;let d=!1,m,g=Date.now(),h=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(C.ok){let S=await C.json();if(d||(A(S),S.status!=="pending"))return}}catch{}if(!d){if(Date.now()-g>=i){b(!0);return}m=setTimeout(h,o)}};return h(),()=>{d=!0,m&&clearTimeout(m)}},[x,e,o,i]);let P=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),_=Sn(!1);Xe(()=>{if(!x||p===null||_.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(_.current=!0,!Yt(x)))return;let m=(p.line_items??[]).filter(g=>typeof g.variant_id=="string"&&g.variant_id.length>0).map(g=>({variantId:g.variant_id,quantity:g.quantity}));m.length>0&&jt(m)},[x,p]);let s=P&&p.fulfillment.type==="redirect"?p.fulfillment.redirect_url:void 0;if(Xe(()=>{if(!s||!l)return;let d=setTimeout(()=>{window.location.href=s},f);return()=>clearTimeout(d)},[s,l,f]),x===void 0)return null;if(x===null)return y?$(he,{children:y()}):H("div",{className:t,style:r,children:[$("h2",{children:"Thank you for your order!"}),$("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!p||p.status==="pending")return u?$(he,{children:u({timedOut:w})}):$("div",{className:t,style:r,role:"status",children:$("p",{children:w?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(P){if(v)return $(he,{children:v(p)});let{fulfillment:d}=p,m=p.amount_total!==void 0&&p.currency?F(p.amount_total,p.currency):null,g=d.files??[],h=g.length===0?d.download_url:void 0;return H("div",{className:t,style:r,children:[$("h2",{children:"Thank you for your purchase!"}),p.is_test&&H("p",{children:[$("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),p.line_items&&p.line_items.length>0&&$("ul",{children:p.line_items.map((C,S)=>H("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&$("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},S))}),m&&H("p",{children:["Total paid: ",m]}),p.source==="subscription"&&p.subscription&&H(he,{children:[H("p",{children:["Your subscription renews"," ",p.subscription.interval_count>1?`every ${p.subscription.interval_count} ${p.subscription.interval}s`:`every ${p.subscription.interval}`," ","at"," ",F(p.subscription.amount,p.subscription.currency),"."]}),H("p",{children:["You can view, update, or cancel it any time on"," ",$("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),g.length>0&&H(he,{children:[$("p",{children:"Your downloads:"}),$("ul",{children:g.map((C,S)=>$("li",{children:$("a",{href:C.download_url,children:C.name})},S))})]}),h&&$("p",{children:$("a",{href:h,children:"Download your file"})}),s?H("p",{children:["Taking you to your content\u2026"," ",$("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?$("p",{children:$("a",{href:d.redirect_url,children:"Continue to your content"})}):null,g.length===0&&!h&&!d.redirect_url&&$("p",{children:"A confirmation email is on its way to you."}),typeof p.order_number=="number"?H("p",{children:["Order ",H("strong",{children:["#",p.order_number]})," \u2014 keep this if you ever need help with your order."]}):p.order_id?H("p",{children:["Order reference: ",$("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]}):null]})}return c?$(he,{children:c(p)}):$("div",{className:t,style:r,children:$("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}import{useEffect as Ur,useState as Nr}from"react";import{Fragment as Dr,jsx as Se}from"react/jsx-runtime";function vn(e,t){if(t.unit_amount!==null&&t.unit_amount!==void 0)return t.unit_amount;let r=t.percent_off_bps??0;return e-Math.floor(e*r/1e4)}function Lt(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var Mr={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},Vr={display:"block",width:"100%",textAlign:"left",padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},qr={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600};function $r({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:f,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:v,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,A=k?.ready===!0,w=[...k?.plans??[]].sort((S,R)=>S.position-R.position),[b,a]=Nr(null),P=o!==void 0,_=P?o:b,s=w.map(S=>S.id).join("|"),d=w.length>0?w[0].id:null;if(Ur(()=>{if(!(!p||!A)&&!(_!==null&&w.some(S=>S.id===_))){if(d===null){if(_===null)return;P||a(null),i?.(null);return}P||a(d),i?.(d)}},[p,A,d,s,_,P]),!k)return null;if(!A)return p?x?Se(Dr,{children:x()}):Se("div",{className:l,style:f,"data-state":"unavailable",children:Se("p",{children:"This product is currently unavailable."})}):null;if(w.length===0)return null;let m=e?.base_currency!==void 0&&e?.base_currency!==null,g=r!==void 0?r:m?null:e?.unit_amount??null,h=n??e?.base_currency??e?.currency??"usd",C=[];if(!p){let S=g;C.push({plan:null,selected:_===null,price:S,priceLabel:S!==null?F(S,h):null,label:"One-time purchase",select:()=>{P||a(null),i?.(null)}})}for(let S of w){let R=S.unit_amount!==null?S.unit_amount:g!==null?vn(g,S):null,O=R!==null?F(R,h):null,q=S.title&&S.title.trim().length>0?S.title.trim():`Subscribe ${Lt(S)}`,j=O?`${q} \u2014 ${O} ${Lt(S)}`:`${q} \u2014 billed ${Lt(S)}`;C.push({plan:S,selected:_===S.id,price:R,priceLabel:O,label:j,select:()=>{P||a(S.id),i?.(S.id)}})}return Se("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?f:{...Mr,...f},children:C.map(S=>{if(c)return Se("span",{style:{display:"contents"},children:c(S)},S.plan?.id??"one-time");let R=S.selected;return Se("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":S.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...Vr,...R?qr:{}},onClick:S.select,children:S.plan===null&&v!==void 0?v:S.plan===null?S.priceLabel?`One-time purchase \u2014 ${S.priceLabel}`:"One-time purchase":S.label},S.plan?.id??"one-time")})})}import{useCallback as et,useEffect as Cn,useRef as Br,useState as tt}from"react";async function Z(e,t,r={}){let n;try{n=await fetch(`${e}${t}`,{method:r.method??"GET",headers:{...r.body!==void 0?{"Content-Type":"application/json"}:{},...r.token?{Authorization:`Bearer ${r.token}`}:{}},...r.body!==void 0?{body:JSON.stringify(r.body)}:{}})}catch(u){return{ok:!1,failure:{kind:"network",error:u instanceof Error?u.message:"Network error"}}}let o=await n.text().catch(()=>""),i=null;try{i=o?JSON.parse(o):null}catch{i=null}let l=typeof i=="object"&&i!==null?i:null;if(n.ok)return l===null?{ok:!1,failure:{kind:"parse_error",error:"The server sent an unreadable response \u2014 please try again"}}:{ok:!0,data:l};if(n.status===404&&o.trim()==="")return{ok:!1,failure:{kind:"unavailable"}};let f=typeof l?.code=="string"?l.code:null,y=typeof l?.error=="string"&&l.error?l.error:`Request failed (${n.status})`;return n.status===401?{ok:!1,failure:{kind:"unauthorized",code:f,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:f,error:y}}}function kn(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function Ee(e){if(!e)return null;let t=e.includes("T")?e:e.replace(" ","T")+"Z",r=Date.parse(t);if(Number.isNaN(r))return null;try{return new Date(r).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{return null}}var Fr=1500;function wn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function zr(e,t){return e.requestId===t}function jr(e,t){return typeof window>"u"||!wn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;if(y?.type==="aifeatures:preview-session-ack"&&zr(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let v=y.customer;typeof v.email=="string"&&(u={email:v.email,name:typeof v.name=="string"?v.name:null})}o({claimed:!0,token:y.token,customer:u});return}o({claimed:!0,token:null,customer:null,error:typeof y.error=="string"&&y.error?y.error:"The preview sign-in could not be created."})}},l=setTimeout(()=>o({claimed:!1}),Fr);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ue(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=tt(()=>ce()),[o,i]=tt(null),[l,f]=tt(!1),[y,u]=tt(!1),v=Br(void 0);Cn(()=>Jt(()=>{let b=ce();n(b),i(b===null?a=>Wt()??a:null)}),[]);let c=et(async b=>{u(!0);try{let a=await Z(t,"/v1/account/verify",{method:"POST",body:{code:b}});if(a.ok&&typeof a.data.token=="string"){let _=a.data.customer&&typeof a.data.customer.email=="string"?{email:a.data.customer.email,name:typeof a.data.customer.name=="string"?a.data.customer.name:null}:null;return Ke({token:a.data.token,customer:_}),n({token:a.data.token,customer:_}),i(null),f(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):!a.ok&&a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:!a.ok&&(a.failure.kind==="http"||a.failure.kind==="unauthorized")&&a.failure.code==="invalid_code"?(i("invalid_code"),{ok:!1,code:"invalid_code",error:a.failure.error}):{ok:!1,code:"error",error:a.ok||a.failure.kind==="unavailable"?"Sign-in failed \u2014 please request a new link.":a.failure.error}}finally{u(!1)}},[t]),x=e.consumeUrlCode??!0;Cn(()=>{if(!(typeof window>"u")&&v.current===void 0){if(!x){v.current=null;return}let b=new URL(window.location.href),a=b.searchParams.get("code");a&&(b.searchParams.delete("code"),window.history.replaceState(window.history.state,"",b.toString())),v.current=a,a&&c(a)}},[c,x]);let k=et(async b=>{if(typeof window<"u"&&wn(window)){let P=await jr(b,Oe());if(P.claimed){if(P.token!==null){let _=P.customer??{email:b,name:null};return Ke({token:P.token,customer:_}),n({token:P.token,customer:_}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:P.error}}}let a=await Z(t,"/v1/account/login",{method:"POST",body:{email:b}});return a.ok?{ok:!0,via:"email"}:a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:{ok:!1,code:"error",error:(a.failure.kind==="network",a.failure.error)}},[t]),p=et(async()=>{let b=ce()?.token;b&&await Z(t,"/v1/account/logout",{method:"POST",token:b,body:{}}),ee(),n(null),i(null)},[t]),A=et(async()=>{let b=ce();if(!b)return;let a=await Z(t,"/v1/account/me",{token:b.token}),P=()=>ce()?.token===b.token;if(a.ok){if(!P())return;let _=a.data.customer??b.customer;Ke({token:b.token,customer:_}),n({token:b.token,customer:_}),f(!1);return}if(a.failure.kind==="unauthorized"){if(!P())return;ee("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){f(!0);return}},[t]);return{status:y?"pending":r?"signed_in":l?"unavailable":"signed_out",customer:r?.customer??null,token:r?.token??null,reason:r?null:o,login:k,verifyCode:c,logout:p,refresh:A}}import{useCallback as Ve,useEffect as Mt,useRef as it,useState as qe}from"react";import{useEffect as Kr,useRef as Pn,useState as ve}from"react";import{Fragment as Et,jsx as K,jsxs as Ne}from"react/jsx-runtime";var It={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},Yr={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},Wr={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},_n={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},ke={margin:0},Hr={color:"#b91c1c",margin:0};function nt({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:f}){let y=Ue({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[v,c]=ve(""),[x,k]=ve("form"),[p,A]=ve(!1),[w,b]=ve(null),[a,P]=ve(null),[_,s]=ve(!1),d=Pn(void 0),m=Pn(!1);Kr(()=>()=>{d.current&&clearTimeout(d.current)},[]);let g=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},h=async()=>{let R=v.trim();if(!R||p||m.current)return;m.current=!0,A(!0),b(null),P(null);let O=await u.login(R);if(m.current=!1,A(!1),O.ok){if(O.via==="preview")return;k("sent"),g();return}O.code!=="unavailable"&&(b(O.code==="rate_limited"?"rate_limited":"error"),P(O.error))};if(u.status==="unavailable")return f?K(Et,{children:f()}):K("div",{className:n,style:n?o:{...It,...o},"data-state":"unavailable",children:K("p",{style:ke,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:v.trim(),canResend:_,resend:()=>{h(),g()},submitting:p,reset:()=>k("form")};return l?K(Et,{children:l(R)}):Ne("div",{className:n,style:n?o:{...It,...o},"data-state":"sent",children:[Ne("p",{style:ke,children:["Check your email \u2014 if ",K("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),_?Ne("p",{style:ke,children:["Didn't get it?"," ",K("button",{type:"button",style:_n,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",K("button",{type:"button",style:_n,onClick:R.reset,children:"use a different email"}),"."]}):K("p",{style:ke,children:"It can take a minute to arrive."})]})}let C={email:v,setEmail:c,submit:()=>void h(),submitting:p,errorKind:w,errorMessage:a,reason:u.reason};if(i)return K(Et,{children:i(C)});let S=R=>{R.preventDefault(),C.submit()};return Ne("form",{className:n,style:n?o:{...It,...o},onSubmit:S,"data-state":"form",children:[u.reason==="session_expired"&&K("p",{style:ke,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&K("p",{style:ke,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),Ne("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[K("span",{children:"Email address"}),K("input",{type:"email",value:v,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:Yr})]}),K("button",{type:"submit",style:Wr,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&K("p",{style:Hr,role:"alert",children:w==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}import{Fragment as Qr,jsx as te,jsxs as Ce}from"react/jsx-runtime";var Jr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},Gr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},Me={color:"#6b7280",fontSize:"0.875rem"};function Zr(e){switch(e.status){case"paid":return null;case"refunded":return"Refunded";case"partially_refunded":return"Partially refunded";case"disputed":return"Disputed";default:return e.status}}function Ut({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?te(Qr,{children:o()}):Ce("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&te("h3",{children:n}),te("p",{style:Me,children:"No orders yet."})]}):Ce("div",{className:t,style:r,children:[n!==null&&te("h3",{children:n}),te("ul",{style:t?void 0:Jr,children:e.map(l=>{if(i)return te("li",{style:{display:"contents"},children:i(l)},l.id);let f=Ee(l.created_at),y=Zr(l);return Ce("li",{style:t?void 0:Gr,children:[Ce("div",{children:[l.order_number!==null&&Ce("strong",{children:["Order #",l.order_number]})," ",f&&te("span",{style:Me,children:f})," ",l.source==="subscription"&&te("span",{style:Me,children:"\xB7 subscription"}),y&&Ce("span",{style:Me,children:[" \xB7 ",y]})]}),l.line_items.length>0&&te("div",{style:Me,children:l.line_items.map(u=>u.name?`${u.quantity&&u.quantity>1?`${u.quantity} \xD7 `:""}${u.name}`:null).filter(Boolean).join(", ")}),te("div",{children:F(l.amount_total,l.currency)})]},l.id)})})]})}import{useEffect as xn,useRef as Xr,useState as ie}from"react";import{Fragment as On,jsx as V,jsxs as Q}from"react/jsx-runtime";var ei={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},ti={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},we={color:"#6b7280",fontSize:"0.875rem"},ni={color:"#b91c1c",fontSize:"0.875rem",margin:0},ri={color:"#065f46",fontSize:"0.875rem",margin:0},Nt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},pe={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},An={...pe,border:"1px solid #111827",background:"#111827",color:"white"},ii={...pe,border:"1px solid #b91c1c",color:"#b91c1c"},oi={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},Rn={panel:"none",mutation:null,portalRefused:!1};function si(e){let t=Ee(e.current_period_end);return e.ended?{text:"This subscription has ended.",tone:"ended"}:e.cancel_at_period_end?{text:t?`Scheduled to cancel \u2014 stays active until ${t}.`:"Scheduled to cancel at the end of the current period.",tone:"warn"}:e.status==="past_due"||e.status==="unpaid"?{text:"There's a problem with your last payment \u2014 please update your card.",tone:"warn"}:e.status==="active"||e.status==="trialing"?{text:t?`Renews on ${t}.`:"Active.",tone:"ok"}:{text:`Status: ${e.status}.`,tone:"warn"}}function ai({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=ie(e?.name??""),[f,y]=ie(o?.line1??""),[u,v]=ie(o?.line2??""),[c,x]=ie(o?.city??""),[k,p]=ie(o?.state??""),[A,w]=ie(o?.postal_code??""),[b,a]=ie(o?.country??""),P=(_,s,d,m)=>Q("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[V("span",{children:_}),V("input",{style:oi,value:s,onChange:g=>d(g.target.value),required:m?.required,maxLength:m?.maxLength})]});return Q("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:_=>{_.preventDefault(),r({name:i.trim()||null,address:{line1:f.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:A.trim()||null,country:b.trim().toUpperCase()}})},children:[P("Name",i,l),P("Address line 1",f,y,{required:!0}),P("Address line 2",u,v),P("City",c,x),P("State / region",k,p),P("Postal code",A,w),P("Country (2-letter code)",b,a,{required:!0,maxLength:2}),Q("div",{style:Nt,children:[V("button",{type:"submit",style:An,disabled:t,children:t?"Saving\u2026":"Save address"}),V("button",{type:"button",style:pe,onClick:n,disabled:t,children:"Cancel"})]})]})}function rt({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:f,heading:y="Your subscriptions",renderEmpty:u,renderRow:v}){let[c,x]=ie(t),[k,p]=ie({}),A=Xr(new Set);xn(()=>{x(t)},[t]),xn(()=>{let s=d=>{d.persisted&&(A.current.clear(),p(m=>{let g=!1,h={};for(let[C,S]of Object.entries(m))S.mutation?.phase==="pending"?(h[C]={...S,mutation:null},g=!0):h[C]=S;return g?h:m}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let w=(s,d)=>p(m=>({...m,[s]:{...m[s]??Rn,...d}})),b=s=>{x(d=>d.map(m=>m.id===s.id?s:m)),i?.(s)},a=async(s,d,m,g)=>{if(A.current.has(s.id))return{ok:!1};A.current.add(s.id);try{w(s.id,{mutation:{kind:d,phase:"pending"}});let h=await Z(e,m,{method:"POST",token:r.token,body:g??{}});if(h.ok)return{ok:!0,data:h.data};let{failure:C}=h;return C.kind==="unauthorized"?(n?.({code:C.code,error:C.error}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="unavailable"?(o?.(),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="ended"?(b({...s,ended:!0,status:"canceled"}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="portal_unavailable"?(w(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(w(s.id,{mutation:{kind:d,phase:"error",error:C.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":C.error}}),{ok:!1})}finally{A.current.delete(s.id)}},P=s=>r.kind==="session"?{cancel:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/cancel`,reactivate:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/reactivate`,address:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/address`,portal:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/portal-session`}:{cancel:"/v1/account/manage/cancel",reactivate:null,address:null,portal:"/v1/account/manage/portal-session"},_=s=>{let d=k[s.id]??Rn,m=P(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>w(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>w(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let g=await a(s,"cancel",m.cancel);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:m.reactivate!==null,reactivate:()=>{m.reactivate&&(async()=>{let g=await a(s,"reactivate",m.reactivate);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{m.address&&w(s.id,{panel:"address",mutation:null})},saveAddress:g=>{m.address&&(async()=>{let h=await a(s,"address",m.address,{shipping_address:g});if(h.ok){let C=h.data.subscription;C&&b(C),w(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let g=await a(s,"portal",m.portal);g.ok&&typeof g.data.url=="string"?window.location.href=g.data.url:g.ok&&w(s.id,{mutation:{kind:"portal",phase:"error",error:"Card update is temporarily unavailable."}})})()}}};return c.length===0?u?V(On,{children:u()}):Q("div",{className:l,style:f,"data-state":"empty",children:[y!==null&&V("h3",{children:y}),V("p",{style:we,children:"No subscriptions."})]}):Q("div",{className:l,style:f,children:[y!==null&&V("h3",{children:y}),V("ul",{style:l?void 0:ei,children:c.map(s=>{let d=_(s);return v?V("li",{style:{display:"contents"},children:v(d)},s.id):V("li",{style:l?void 0:ti,"data-status":s.status,"data-ended":s.ended||void 0,children:V(ui,{ctx:d})},s.id)})})]})}function ui({ctx:e}){let t=e.subscription,r=si(t),n=Ee(t.current_period_end),o=`${F(t.current_amount,t.currency)} ${kn(t.plan_interval,t.plan_interval_count)}`,i=e.mutation?.phase==="pending",l=i?e.mutation?.kind:null;return Q(On,{children:[Q("div",{children:[V("strong",{children:t.plan_title??"Subscription"})," ",Q("span",{style:we,children:["\xB7 ",o]}),t.is_test&&V("span",{style:we,children:" \xB7 test"})]}),V("div",{style:r.tone==="warn"?void 0:we,children:r.text}),t.ended?V("p",{style:we,children:"This subscription has ended \u2014 to start again, subscribe from the product page."}):e.panel==="confirm_cancel"?Q("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[V("p",{style:{margin:0},children:n?`Your subscription stays active until ${n} \u2014 after that it won't renew and you won't be charged again.`:"Your subscription stays active until the end of the current billing period \u2014 after that it won't renew and you won't be charged again."}),Q("div",{style:Nt,children:[V("button",{type:"button",style:ii,onClick:e.confirmCancel,disabled:i,children:l==="cancel"?"Canceling\u2026":"Confirm cancellation"}),V("button",{type:"button",style:pe,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?V(ai,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):Q("div",{style:Nt,children:[t.cancel_at_period_end?e.reactivateAvailable?V("button",{type:"button",style:An,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):V("span",{style:we,children:"To keep this subscription, sign in with your email address on this page."}):V("button",{type:"button",style:pe,onClick:e.openCancelConfirm,disabled:i,children:"Cancel subscription"}),t.shipping_address!==void 0&&!t.cancel_at_period_end&&V("button",{type:"button",style:pe,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&V("button",{type:"button",style:pe,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&V("p",{style:ni,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&V("p",{style:ri,role:"status",children:e.mutation.kind==="cancel"?n?`Cancellation scheduled \u2014 you keep access until ${n}.`:"Cancellation scheduled.":e.mutation.kind==="reactivate"?"Your subscription will continue.":e.mutation.kind==="address"?"Shipping address updated.":"Done."})]})}import{Fragment as Pe,jsx as M,jsxs as G}from"react/jsx-runtime";var li={display:"flex",flexDirection:"column",gap:"1.25rem"},Tn={color:"#6b7280",fontSize:"0.875rem"},ci={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},Ln={color:"#b91c1c"},ot={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function di({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:f,renderHeader:y,renderPmBanner:u,renderManageExpired:v}){let c=Ue({apiUrl:e}),x=it(void 0),[k,p]=qe(null),[A,w]=qe(!1);Mt(()=>{if(!(typeof window>"u")){if(x.current===void 0){let I=new URL(window.location.href),L=I.searchParams.get("manage_code"),B=I.searchParams.get("pm");(L!==null||B!==null)&&(I.searchParams.delete("manage_code"),I.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",I.toString())),x.current={manageCode:L,pmUpdated:B==="updated"}}p(x.current.manageCode),w(x.current.pmUpdated)}},[]);let[b,a]=qe(null),P=it(!1),_=it(0),s=Ve(I=>{a({phase:"verifying"}),(async()=>{let L=await Z(e,"/v1/account/manage/verify",{method:"POST",body:{manage_code:I}});if(L.ok&&typeof L.data.manage_token=="string"&&L.data.subscription){a({phase:"active",token:L.data.manage_token,sub:L.data.subscription,siteName:null});return}if(!L.ok&&L.failure.kind==="unavailable"){a({phase:"unavailable"});return}if(!L.ok&&L.failure.kind==="network"){a({phase:"error",error:L.failure.error});return}a({phase:"expired"})})()},[e]);Mt(()=>{!k||P.current||(P.current=!0,s(k))},[k,s]);let d=Ve(async()=>{let I=b;if(!I||I.phase!=="active")return;let L=++_.current,B=await Z(e,"/v1/account/manage/subscription",{token:I.token});L===_.current&&(B.ok&&B.data.subscription?a({phase:"active",token:I.token,sub:B.data.subscription,siteName:typeof B.data.site?.name=="string"?B.data.site.name:I.siteName}):!B.ok&&B.failure.kind==="unauthorized"?a({phase:"expired"}):!B.ok&&B.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[m,g]=qe({phase:"loading"}),[h,C]=qe(0),S=h>0,R=it(0),O=c.token,q=Ve(async()=>{if(!O)return;let I=++R.current,L=await Z(e,"/v1/account/me",{token:O});if(I===R.current){if(L.ok){g({phase:"ready",data:L.data});return}if(L.failure.kind==="unauthorized"){ee("session_expired");return}if(L.failure.kind==="unavailable"){ee();return}g({phase:"error",error:L.failure.error})}},[e,O]);Mt(()=>{!O||k||(g({phase:"loading"}),q())},[O,k,q]);let j=Ve(async()=>{C(I=>I+1);try{b&&b.phase==="active"?await d():await q()}finally{C(I=>I-1)}},[b,d,q]),D=Ve(I=>{R.current++,_.current++,a(L=>L&&L.phase==="active"&&L.sub.id===I.id?{...L,sub:I}:L),g(L=>L.phase==="ready"?{phase:"ready",data:{...L.data,subscriptions:L.data.subscriptions.map(B=>B.id===I.id?I:B)}}:L)},[]),T=t?r:{...li,...r},E=I=>{if(!A)return null;let B={state:I.some(J=>!J.ended&&(J.status==="past_due"||J.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void j(),checking:S};return u?u(B):M("div",{style:ci,role:"status","data-pm-state":B.state,children:B.state==="retrying"?G(Pe,{children:[M("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),M("p",{style:{margin:"0.375rem 0 0"},children:M("button",{type:"button",style:ot,onClick:B.checkAgain,disabled:S,children:S?"Checking\u2026":"Check again"})})]}):M("p",{style:{margin:0},children:"Card updated \u2014 your subscription is back in good standing."})})};if(k)return!b||b.phase==="verifying"?i?M(Pe,{children:i()}):M("div",{className:t,style:T,role:"status",children:M("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?G("div",{className:t,style:T,children:[E([b.sub]),M(rt,{apiUrl:e,subscriptions:[b.sub],auth:{kind:"manage",token:b.token},heading:"Your subscription",onSubscriptionChange:D,onAuthError:()=>a({phase:"expired"}),onUnavailable:()=>a({phase:"unavailable"})})]}):b.phase==="unavailable"?M("div",{className:t,style:T,"data-state":"unavailable",children:M("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?G("div",{className:t,style:T,children:[M("p",{style:Ln,role:"alert",children:b.error}),M("p",{children:M("button",{type:"button",style:ot,onClick:()=>s(k),children:"Try again"})})]}):G("div",{className:t,style:T,"data-state":"manage-expired",children:[v?v():M("p",{children:"This manage link is no longer valid. Sign in below with the email you used at checkout to manage your subscription."}),M(nt,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?M(Pe,{children:i()}):M("div",{className:t,style:T,role:"status",children:M("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return M("div",{className:t,style:T,children:M(nt,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(m.phase==="loading")return i?M(Pe,{children:i()}):M("div",{className:t,style:T,role:"status",children:M("p",{children:"Loading your account\u2026"})});if(m.phase==="error")return l?M(Pe,{children:l({error:m.error,retry:()=>void q()})}):G("div",{className:t,style:T,children:[G("p",{style:Ln,role:"alert",children:["We couldn't load your account \u2014 ",m.error]}),M("p",{children:M("button",{type:"button",style:ot,onClick:()=>void q(),children:"Try again"})})]});let{data:U}=m,Y=U.customer??c.customer??{email:"",name:null},N=()=>void c.logout(),z=U.orders.length===0&&U.subscriptions.length===0;return G("div",{className:t,style:T,children:[y?y({customer:Y,site:U.site??null,signOut:N}):G("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[G("div",{children:[M("h2",{style:{margin:0},children:"Your account"}),G("p",{style:{...Tn,margin:0},children:["Signed in as ",Y.email]})]}),M("button",{type:"button",style:ot,onClick:N,children:"Sign out"})]}),E(U.subscriptions),z?f?f():G("p",{style:Tn,children:["Nothing here yet \u2014 orders and subscriptions for ",Y.email," ","will show up on this page."]}):G(Pe,{children:[U.subscriptions.length>0&&M(rt,{apiUrl:e,subscriptions:U.subscriptions,auth:{kind:"session",token:O},onSubscriptionChange:D,onAuthError:()=>ee("session_expired"),onUnavailable:()=>ee()}),M(Ut,{orders:U.orders})]})]})}export{nt as AccountLogin,Ut as AccountOrders,di as AccountPage,Tr as AddToCartButton,Un as AifeaturesCaptcha,Cr as BuyButton,Lr as CartCheckoutButton,Pt as MARKET_COUNTRIES,tn as MAX_CART_LINES,Er as OrderConfirmation,$r as PlanPicker,rr as ProductPrice,rt as SubscriptionList,br as VariantPicker,Dt as ZERO_DECIMAL_CURRENCIES,dt as applySelectionToUrl,F as formatPrice,fe as getOptions,oe as getVariants,_e as isMultiVariant,st as isValueAvailable,at as isValueInCatalog,vn as planRecurringAmount,ut as reanchorSelection,le as resolveVariant,Fe as searchFromSelection,xe as selectedImages,Bt as selectedValues,ct as selectionFromSearch,re as useCart,Ct as useCartCheckout,vt as useCartItems,Zn as useCartSummary,ht as useCheckout,tr as useMarket,ue as useProduct,Ue as useSession,ne as valueSlug,lt as variantPriceRange};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aifeatures/react",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "React components for aifeatures sites: form CAPTCHA (Cloudflare Turnstile) and headless payments (product price, buy button, order confirmation)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|