@aifeatures/react 0.5.4 → 0.6.0

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 CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- "use strict";var pt=Object.defineProperty;var fn=Object.getOwnPropertyDescriptor;var mn=Object.getOwnPropertyNames;var gn=Object.prototype.hasOwnProperty;var yn=(e,t)=>{for(var r in t)pt(e,r,{get:t[r],enumerable:!0})},bn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of mn(t))!gn.call(e,o)&&o!==r&&pt(e,o,{get:()=>t[o],enumerable:!(n=fn(t,o))||n.enumerable});return e};var hn=e=>bn(pt({},"__esModule",{value:!0}),e);var xr={};yn(xr,{AccountLogin:()=>Fe,AccountOrders:()=>ct,AccountPage:()=>pn,AddToCartButton:()=>Qt,AifeaturesCaptcha:()=>Tt,BuyButton:()=>Gt,CartCheckoutButton:()=>en,MARKET_COUNTRIES:()=>at,MAX_CART_LINES:()=>kt,OrderConfirmation:()=>nn,PlanPicker:()=>rn,ProductPrice:()=>Kt,SubscriptionList:()=>je,VariantPicker:()=>Yt,ZERO_DECIMAL_CURRENCIES:()=>mt,applySelectionToUrl:()=>Ze,formatPrice:()=>z,getOptions:()=>we,getVariants:()=>be,isMultiVariant:()=>Ae,isValueAvailable:()=>Ye,isValueInCatalog:()=>He,planRecurringAmount:()=>_t,reanchorSelection:()=>Je,resolveVariant:()=>ke,searchFromSelection:()=>Ve,selectedImages:()=>Oe,selectedValues:()=>gt,selectionFromSearch:()=>Qe,useCart:()=>ye,useCartCheckout:()=>st,useCartItems:()=>ot,useCartSummary:()=>Bt,useCheckout:()=>rt,useMarket:()=>jt,useProduct:()=>ve,useSession:()=>Ee,valueSlug:()=>pe,variantPriceRange:()=>Ge});module.exports=hn(xr);var Me=require("react"),Ot=require("@marsidev/react-turnstile"),ft=require("react/jsx-runtime");function Tt({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=(0,Me.useState)(null),[m,y]=(0,Me.useState)(!0);return(0,Me.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]),m||!i?null:(0,ft.jsx)("div",{className:o,children:(0,ft.jsx)(Ot.Turnstile,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}var ce=require("react"),Ke=[1e3,3e3];function ve(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=(0,ce.useState)(null),[l,m]=(0,ce.useState)(!0),[y,u]=(0,ce.useState)(null),[S,c]=(0,ce.useState)(0),x=(0,ce.useRef)(e);(0,ce.useEffect)(()=>{let p=!1,L;m(!0),u(null),x.current!==e&&(x.current=e,i(null));let C=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let w=await a.json().catch(()=>null);if(!p)if(!a.ok||!w){if(a.status>=500&&b<Ke.length){L=setTimeout(()=>C(b+1),Ke[b]);return}u(w?.error??`Request failed (${a.status})`),i(null),m(!1)}else i(w),m(!1)}).catch(a=>{if(!p){if(b<Ke.length){L=setTimeout(()=>C(b+1),Ke[b]);return}u(a instanceof Error?a.message:"Failed to load product"),m(!1)}})};return C(0),()=>{p=!0,L&&clearTimeout(L)}},[e,r,n,S]);let k=(0,ce.useCallback)(()=>c(p=>p+1),[]);return{product:o,loading:l,error:y,refresh:k}}var mt=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function z(e,t,r){let n=mt.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 Ae(e){return we(e).length>0}function We(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=We(o);if(i[r]!==n)return!1;for(let[l,m]of Object.entries(t))if(l!==r&&i[l]!==m)return!1;return!0})}function He(e,t,r){return e.some(n=>We(n)[t]===r)}function Je(e,t,r,n){let o={[r]:n};for(let[l,m]of Object.entries(t)){if(l===r)continue;e.some(u=>{let S=We(u);return S[r]===n&&S[l]===m})&&(o[l]=m)}return e.some(l=>{let m=We(l);return Object.entries(o).every(([y,u])=>m[y]===u)})?o:{[r]:n}}function Ge(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 gt(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 Qe(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 m=n.get(l);if(m===void 0)continue;let y=pe(m);if(y.length===0)continue;let u=i.values.find(S=>pe(S.value)===y);u&&(o[i.id]=u.id)}return o}function Ve(e,t){let r={};for(let[n,o]of Object.entries(gt(e,t))){let i=pe(n),l=pe(o);i.length===0||l.length===0||(r[i]=l)}return r}function Oe(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(Ve(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}var oe=require("react");var bt="aifeatures_cart",ht="aifeatures_market",Lt="aifeatures_cart_cleared";var yt="aifeatures:cart-storage",qe=new Map;function $e(e){if(qe.has(e))return qe.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Te(e,t){if(typeof window>"u"){qe.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),qe.delete(e)}catch{qe.set(e,t)}Sn(e)}function Sn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(yt,{detail:{key:e}}))}catch{}}function Xe(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(yt,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(yt,n)}}function vn(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,m]of Object.entries(t.selection))typeof m=="string"&&(n[l]=m);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=$e(bt);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=vn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function fe(e){Te(bt,JSON.stringify(e))}function It(e){return Xe(bt,e)}function Et(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=$e(ht);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function Ut(e){Te(ht,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function Le(e){return Xe(ht,e)}function Nt(e){let t=[],r=$e(Lt);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)),Te(Lt,JSON.stringify(t)),!0)}var et="aifeatures_session",St=null;function Mt(){return St}function kn(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=$e(et);if(!e)return null;try{return kn(JSON.parse(e))}catch{return null}}function Vt(){return Pe()?.token??null}function tt(e){St=null,Te(et,JSON.stringify(e))}function me(e){St=e??null,Te(et,null)}function qt(e){return Xe(et,e)}var Cn=1500;function De(){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 nt(e,t){return!("requestId"in e)||e.requestId===t}function vt(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;y?.type==="aifeatures:test-checkout-ack"&&nt(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),Cn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function $t(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 rt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,oe.useState)(!1),[o,i]=(0,oe.useState)(null),[l,m]=(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||!nt(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:L,successUrl:C,cancelUrl:b,customerEmail:a,planId:w,expectedUnitAmount:P,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),m(null),w!==void 0){let d=Vt();if(d)try{let f=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:w,...x!==void 0?{variant_id:x}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.text().catch(()=>""),g=null;try{g=h?JSON.parse(h):null}catch{g=null}if(f.ok){if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}$t(g.url)==="stayed"&&(y.current=!1,n(!1));return}let _=f.status===404&&h.trim()==="";if(f.status===401||_)me();else{i(g?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}}catch(f){i(f instanceof Error?f.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=w===void 0?ne():null,f=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&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{plan_id:w}:{},...L!==void 0?{metadata:L}:{},...a!==void 0?{customer_email:a}:{},...P!==void 0&&s!==void 0&&w===void 0?{expected_unit_amount:P,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.json().catch(()=>null);if(!f.ok){if(h?.error==="price_changed"&&typeof h.current_unit_amount=="number"&&typeof h.currency=="string"){m({currentUnitAmount:h.current_unit_amount,currency:h.currency}),i(`The price has changed to ${z(h.current_unit_amount,h.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(h?.code==="preview_domain"){let g=De();if(u.current=g,await vt({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{planId:w}:{},...a!==void 0?{customerEmail:a}:{},...L!==void 0?{metadata:L}:{}},g))return;u.current=null}i(h?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}$t(h.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 kt=20;function Dt(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),It(u)},[]);let o=(0,ge.useCallback)(u=>{let S=Ce(),c=Dt(u.quantity);return S.find(k=>k.variantId===u.variantId)?(fe(S.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):S.length>=kt?{ok:!1,reason:"cart_full"}:(fe([...S,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=(0,ge.useCallback)(u=>{fe(Ce().filter(S=>S.variantId!==u))},[]),l=(0,ge.useCallback)((u,S)=>{let c=Ce();if(S<=0){fe(c.filter(k=>k.variantId!==u));return}let x=Dt(S);fe(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),m=(0,ge.useCallback)(()=>{fe([])},[]),y=e.reduce((u,S)=>u+S.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:m}}var G=require("react");var it={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},wn={...it,inStock:!0,status:"error"};function Pn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ot(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=ye(),[o,i]=(0,G.useState)({}),[l,m]=(0,G.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=(0,G.useState)(!0),[S,c]=(0,G.useState)(null),[x,k]=(0,G.useState)(0),p=(0,G.useRef)(new Set),L=(0,G.useMemo)(()=>JSON.stringify(r.map(P=>[P.productId,P.variantId,P.selection])),[r]),C=(0,G.useCallback)(()=>k(P=>P+1),[]);(0,G.useEffect)(()=>Le(C),[C]),(0,G.useEffect)(()=>{if(!n)return;if(r.length===0){i({}),m({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let P=!1;u(!0);let s=r,d=[...new Set(s.map(h=>h.productId))],f=async h=>{let g=new Map;return await Promise.all(d.map(async _=>{try{let v=await fetch(`${t}/v1/p/${encodeURIComponent(_)}${h?`?country=${encodeURIComponent(h)}`:""}`);if(v.status===404){g.set(_,{kind:"not_found"});return}if(!v.ok){g.set(_,{kind:"error",message:`Request failed (${v.status})`});return}let R=await v.json();g.set(_,{kind:"ok",product:R})}catch(v){g.set(_,{kind:"error",message:v instanceof Error?v.message:"Failed to load product"})}})),g};return(async()=>{let h=ne(),g=await f(h);if(h){let T=[...g.values()].filter(q=>q.kind==="ok"),M=T.filter(q=>q.product.base_currency);M.length>0&&M.length<T.length&&(g=await f(null))}if(P)return;let _=null,v=null,R=null;for(let T of d){let M=g.get(T);!M||M.kind!=="ok"||(_===null&&M.product.shipping_rates&&(_=M.product.shipping_rates),v===null&&M.product.free_shipping_over!=null&&(v=M.product.free_shipping_over),R===null&&M.product.shipping_countries&&(R=M.product.shipping_countries))}let O={},D=new Map,V=null;for(let T of s){let M=g.get(T.productId);if(!M||M.kind==="error"){O[T.variantId]=wn,M&&V===null&&(V=M.message);continue}if(M.kind==="not_found"){O[T.variantId]=it;continue}let{product:q}=M;if(!q.active||q.purchasable===!1){O[T.variantId]=it;continue}let te=q.variants??[],$=te.find(ie=>ie.id===T.variantId)??null,Y=T.variantId;if(!$){let ie=ke(te,T.selection);if(!ie){O[T.variantId]=it;continue}let At=D.get(T.variantId)??{};At.reanchorTo={variantId:ie.id,selection:Pn(ie)},D.set(T.variantId,At),p.current.add(ie.id),$=ie,Y=ie.id}let N=Oe(q,T.selection)[0]??null,E={image:N,unitAmount:$.unit_amount,currency:$.currency,baseCurrency:q.base_currency??null,inStock:$.in_stock,available:$.available,maxQuantity:q.max_quantity,pdpSearch:Ve(q,T.selection),status:p.current.has(Y)?"reanchored":"ok"};O[T.variantId]=E,O[Y]=E;let j=D.get(T.variantId)??{};j.display={name:q.name,variantTitle:$.title,image:N},D.set(T.variantId,j)}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(D.size>0){let T=Ce(),M=[],q=new Map,te=!1;for(let $ of T){let Y=D.get($.variantId),N={...$};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=q.get(N.variantId);if(E){E.quantity+=N.quantity,te=!0;continue}M.push(N),q.set(N.variantId,N)}te&&fe(M)}P||(i(O),m({shippingRates:_,freeShippingOver:v,shippingCountries:R}),c(V),u(!1))})(),()=>{P=!0}},[n,L,t,x]);let b=(0,G.useMemo)(()=>r.map(P=>{let s=o[P.variantId];return s?{...P,...s,image:s.image??P.display.image}:{...P,image:P.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:w}=(0,G.useMemo)(()=>{let P=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(P+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:P,currency:s}},[b]);return{lines:b,subtotal:a,currency:w,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:S,refresh:C}}var Q=require("react");var _n=2e3;function Bt(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=ye(),[l,m]=(0,Q.useState)(null),[y,u]=(0,Q.useState)(!1),[S,c]=(0,Q.useState)(null),[x,k]=(0,Q.useState)(null),[p,L]=(0,Q.useState)(0);(0,Q.useEffect)(()=>(k(ne()),Le(()=>k(ne()))),[]);let C=(0,Q.useMemo)(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=(0,Q.useCallback)(()=>L(s=>s+1),[]),a=(0,Q.useRef)(0),w=(0,Q.useRef)(!1),P=(0,Q.useRef)("idle");return(0,Q.useEffect)(()=>{if(!i)return;if(o.length===0){m(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,f=!1,h,g=w.current?r:0;w.current=!0,P.current=P.current==="pending"?"spent":"idle";let _=setTimeout(async()=>{u(!0);try{let v=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(f||s!==a.current)return;if(!v.ok){if(v.status===429){let O=P.current==="idle";O&&(h=setTimeout(()=>{f||s!==a.current||(P.current="pending",L(D=>D+1))},_n)),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 (${v.status})`);return}let R=await v.json();if(f||s!==a.current)return;m({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(v){if(f||d.signal.aborted||s!==a.current)return;c(v instanceof Error?v.message:"Could not price this cart")}finally{!f&&s===a.current&&u(!1)}},g);return()=>{f=!0,clearTimeout(_),h!==void 0&&clearTimeout(h),d.abort()}},[i,C,x,t,r,n,p]),{summary:l,loading:y,error:S,refresh:b}}var re=require("react");function st(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,re.useState)(!1),[o,i]=(0,re.useState)(null),[l,m]=(0,re.useState)(null),[y,u]=(0,re.useState)(null),S=(0,re.useRef)(!1),c=(0,re.useRef)(null);return(0,re.useEffect)(()=>{let k=p=>{p.persisted&&(S.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 L=p.data;if(L?.type!=="aifeatures:test-checkout-ack"||L.status!=="failed")return;let C=c.current;C===null||!nt(L,C)||(c.current=null,i(typeof L.error=="string"&&L.error?L.error:"The test purchase could not be created."),S.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:(0,re.useCallback)(async(k,{successUrl:p,cancelUrl:L,customerEmail:C,metadata:b,shippingOption:a}={})=>{if(!S.current){S.current=!0,n(!0),i(null),m(null),u(null);try{let w=ne(),P=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}:{}})),...w!==null?{country:w}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...C!==void 0?{customer_email:C}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:L??window.location.href})}),s=await P.json().catch(()=>null);if(!P.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:""}),S.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let f of s.items)f&&typeof f.variant_id=="string"&&(d[f.variant_id]=f);m(d),S.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=De();if(c.current=d,await vt({items:k.map(h=>({productId:h.productId,variantId:h.variantId,quantity:h.quantity})),...C!==void 0?{customerEmail:C}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${P.status})`),S.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),S.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")){S.current=!1,n(!1);return}}window.location.href=s.url}catch(w){i(w instanceof Error?w.message:"Checkout failed"),S.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}var he=require("react");var at=[{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 Ft(e){return e?at.find(t=>t.country===e.toUpperCase())?.currency??null:null}var zt=new Map;function xn(e){let t=zt.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),zt.set(e,t)),t}function jt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,he.useState)(null),[o,i]=(0,he.useState)(!1),[l,m]=(0,he.useState)(null);(0,he.useEffect)(()=>{let c=()=>n(ne());return c(),i(!0),Le(c)},[]),(0,he.useEffect)(()=>{let c=!1;return xn(t).then(x=>{c||m(x)}),()=>{c=!0}},[t]);let y=(0,he.useCallback)(c=>{Ut(c)},[]),u=Ft(l),S=o&&u!==null&&u!==Ft(r);return{market:r,suggestedCountry:l,setMarket:y,markets:at,shouldPrompt:S}}var Ie=require("react/jsx-runtime"),Rn={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function Kt({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:m,loading:y}=ve(e,{apiUrl:r});if(y||!m)return null;let u=be(m),S=t!==void 0?u.find(x=>x.id===t)??null:m.options.length===0?u[0]??null:null;if(S){if(S.unit_amount===null)return null;let x=S.compare_at_amount!==null&&S.compare_at_amount>S.unit_amount;return(0,Ie.jsxs)("span",{className:o,style:i,children:[x&&(0,Ie.jsx)("span",{className:l,style:l?void 0:Rn,children:z(S.compare_at_amount,S.currency,n)}),z(S.unit_amount,S.currency,n)]})}let c=Ge(u);return c?(0,Ie.jsx)("span",{className:o,style:i,children:c.min===c.max?z(c.min,m.currency,n):`${z(c.min,m.currency,n)} \u2013 ${z(c.max,m.currency,n)}`}):m.unit_amount===null?null:(0,Ie.jsx)("span",{className:o,style:i,children:z(m.unit_amount,m.currency,n)})}var ae=require("react");var se=require("react/jsx-runtime"),An={marginBottom:"0.75rem"},On={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},Tn={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Ln={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},In={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},Wt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},En={...Wt,cursor:"pointer"},Un=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Nn=e=>Un.test(e),Mn={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},Vn={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)"},qn="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 Yt({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:m,optionClassName:y,optionLabelClassName:u,valueClassName:S,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[L,C]=(0,ae.useState)(r??{}),b=p?r:L,[a,w]=(0,ae.useState)(()=>new Set),P=g=>w(_=>_.has(g)?_:new Set(_).add(g));(0,ae.useEffect)(()=>{w(g=>g.size===0?g: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(L).length>0))return;let g=Qe({options:e},window.location.search);Object.keys(g).length!==0&&(C(g),o?.(g))},[n,p,e]);let d=(0,ae.useMemo)(()=>e.length>0?t.filter(g=>g.option_values.length===e.length):t,[t,e]),f=(0,ae.useRef)(void 0);if((0,ae.useEffect)(()=>{let g=ke(d,b),_=g?.id??null;f.current!==_&&(f.current=_,i?.(g))},[d,b]),e.length===0)return null;let h=(g,_)=>{let v=Je(d,b,g,_);p||(C(v),n&&Ze({options:e},v)),o?.(v)};return(0,se.jsx)("div",{className:l,style:m,children:e.map(g=>(0,se.jsxs)("div",{className:y,style:y?void 0:An,children:[(0,se.jsx)("span",{className:u,style:u?void 0:On,children:g.title}),(0,se.jsx)("div",{style:Tn,children:g.values.map(_=>{let v=b[g.id]===_.id,R=Ye(d,b,g.id,_.id),O=R||He(d,g.id,_.id),D=[S,v?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,V=_.swatch??null,B=V&&!a.has(V)?V:null,T=B?Nn(B):!1,M=S?void 0:{...Ln,...v?In:{},...R?{}:O?En:Wt,...B?{...Mn,textDecoration:"none"}:{}},q=R?_.value:`${_.value} \u2014 unavailable with your current selection`;return(0,se.jsx)("button",{type:"button",className:D,style:M,disabled:!O,"aria-pressed":v,"aria-label":B?q:void 0,title:B?q:void 0,"data-selected":v?"true":void 0,"data-available":R?"true":"false","data-swatch":B?T?"hex":"image":void 0,onClick:()=>h(g.id,_.id),children:B?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)("span",{"aria-hidden":"true",className:k,style:k?void 0:{...Vn,...T?{background:B}:{},...T&&R?{}:{backgroundImage:[...R?[]:[qn],...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:()=>P(B)})]}):_.value},_.id)})})]},g.id))})}var Jt=require("react");function ut(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}var H=require("react/jsx-runtime"),$n={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Dn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function Ht(){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 Gt({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,apiUrl:u,disabled:S,className:c,style:x,errorClassName:k,spinner:p=!0,children:L}){let{product:C,loading:b,error:a,refresh:w}=ve(e,{apiUrl:u}),{startCheckout:P,loading:s,error:d,priceChange:f}=rt({apiUrl:u});(0,Jt.useEffect)(()=>{f&&w()},[f,w]);let h=C!==null&&!C.payments_ready&&!ut(),g=C!==null&&!C.active,_=C!==null&&C.purchasable===!1,v=C!==null&&Ae(C),R=C!==null?be(C):[],O=t!==void 0?R.find(E=>E.id===t)??null:!v&&R.length===1?R[0]:null,D=v&&!O,V=O!==null&&!O.in_stock,B=n??void 0,T=C?.subscription??null,M=T!==null&&T.required&&!T.ready,q=T!==null&&T.required&&T.ready&&B===void 0,te=!!S||b||!C||h||g||_||M||q||D||V||s,$;s?$=(0,H.jsxs)(H.Fragment,{children:[p&&(0,H.jsx)(Ht,{}),"Processing\u2026"]}):b?$=(0,H.jsxs)(H.Fragment,{children:[p&&(0,H.jsx)(Ht,{}),L??"Buy now"]}):h?$="Payments not set up":g||_?$="Unavailable":M?$="Currently unavailable":q?$="Select a plan":D?$="Select options":V?$="Out of stock":L!==void 0?$=L:B!==void 0?$="Subscribe":$="Buy now";let Y=d??a;return(0,H.jsxs)(H.Fragment,{children:[(0,H.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}:{};P({productId:e,variantId:t,quantity:B!==void 0?void 0:r,amount:o,planId:B,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,...E})},children:$}),Y&&(0,H.jsxs)("div",{role:"alert",className:k,style:k?void 0:$n,children:[Y,C===null&&!b&&a!==null&&(0,H.jsx)("button",{type:"button",onClick:w,style:Dn,children:"Tap to retry"})]})]})}var _e=require("react");var Z=require("react/jsx-runtime"),Bn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Fn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},zn=1500;function jn(){return(0,Z.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,Z.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,Z.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,Z.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Kn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Qt({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:m,errorClassName:y,spinner:u=!0,children:S}){let{product:c,loading:x,error:k,refresh:p}=ve(e,{apiUrl:o}),{add:L}=ye(),[C,b]=(0,_e.useState)(!1),[a,w]=(0,_e.useState)(!1),P=(0,_e.useRef)(void 0);(0,_e.useEffect)(()=>()=>{P.current&&clearTimeout(P.current)},[]);let s=c!==null&&!c.payments_ready&&!ut(),d=c!==null&&!c.active,f=c!==null&&c.purchasable===!1,h=c!==null&&!x&&be(c).length===0,g=c!==null&&c.allow_custom_amount,_=c!==null&&c.subscription?.required===!0,v=c!==null&&Ae(c),R=c!==null?be(c):[],O=t!==void 0?R.find($=>$.id===t)??null:r!==void 0&&v?ke(R,r):!v&&R.length===1?R[0]:null,D=c!==null&&!h&&!O,V=O!==null&&!O.in_stock,B=!!i||x||!c||s||d||f||h||g||_||D||V,T=()=>{if(!c||!O)return;let $=r??Kn(O);if(!L({productId:e,variantId:O.id,quantity:n,selection:$,display:{name:c.name,variantTitle:O.title,image:Oe(c,$)[0]??null}}).ok){b(!0);return}b(!1),w(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>w(!1),zn)},M;x?M=(0,Z.jsxs)(Z.Fragment,{children:[u&&(0,Z.jsx)(jn,{}),S??"Add to cart"]}):s?M="Payments not set up":d||f||h||g?M="Unavailable":_?M="Subscription only":D?M="Select options":V?M="Out of stock":a?M="Added to cart":S!==void 0?M=S:M="Add to cart";let q=C?"Your cart is full \u2014 remove an item before adding another.":k;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)("button",{type:"button",className:l,style:m,disabled:B,"data-added":a?"true":void 0,onClick:T,children:M}),q&&(0,Z.jsxs)("div",{role:"alert",className:y,style:y?void 0:Bn,children:[q,c===null&&!x&&k!==null&&!C&&(0,Z.jsx)("button",{type:"button",onClick:p,style:Fn,children:"Tap to retry"})]})]})}var J=require("react/jsx-runtime"),Zt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function Xt(){return(0,J.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,J.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,J.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,J.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function en({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:m,style:y,errorClassName:u,spinner:S=!0,children:c}){let{items:x,hydrated:k}=ye(),{lines:p}=ot({apiUrl:e}),{startCheckout:L,loading:C,error:b,conflicts:a}=st({apiUrl:e}),w=k&&x.length===0,P=p.some(h=>h.status==="unavailable"),s=!!l||!k||w||P||C,d;C?d=(0,J.jsxs)(J.Fragment,{children:[S&&(0,J.jsx)(Xt,{}),"Processing\u2026"]}):k?w?d="Cart is empty":P?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=(0,J.jsxs)(J.Fragment,{children:[S&&(0,J.jsx)(Xt,{}),c??"Checkout"]});let f=a?Object.keys(a).length:0;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)("button",{type:"button",className:m,style:y,disabled:s,onClick:()=>L(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),f>0&&(0,J.jsx)("div",{role:"alert",className:u,style:u?void 0:Zt,children:f===1?"An item in your cart changed \u2014 please review your cart and try again.":`${f} items in your cart changed \u2014 please review your cart and try again.`}),b&&(0,J.jsx)("div",{role:"alert",className:u,style:u?void 0:Zt,children:b})]})}var ue=require("react");var A=require("react/jsx-runtime"),Wn={fontSize:"1.5rem",lineHeight:1.25,fontWeight:600,margin:"0 0 0.5rem"},xe={color:"#6b7280",fontSize:"0.875rem"},Yn={display:"inline-block",padding:"0.125rem 0.5rem",margin:"0 0 1rem",borderRadius:9999,border:"1px solid #e5e7eb",background:"#f9fafb",color:"#6b7280",fontSize:"0.75rem"},Hn={textAlign:"left",border:"1px solid #e5e7eb",borderRadius:8,overflow:"hidden",margin:"1rem 0"},Jn={listStyle:"none",margin:0,padding:0},Gn={display:"flex",alignItems:"center",gap:"0.75rem",padding:"0.75rem"},tn={width:56,height:56,flex:"0 0 auto",borderRadius:6,border:"1px solid #f3f4f6",background:"#f3f4f6",objectFit:"cover"},Qn={flex:"1 1 auto",minWidth:0},Zn={flex:"0 0 auto",whiteSpace:"nowrap"},Xn={padding:"0.75rem",borderTop:"1px solid #e5e7eb",background:"#f9fafb"},wt={display:"flex",justifyContent:"space-between",gap:"1rem",padding:"0.125rem 0"},er={...wt,fontWeight:600,marginTop:"0.5rem",paddingTop:"0.5rem",borderTop:"1px solid #e5e7eb"},tr={display:"inline-block",padding:"0.625rem 1.25rem",borderRadius:8,background:"#111827",color:"#ffffff",textDecoration:"none",fontWeight:600},Ct="af_order_confirmation_session",nr=1800*1e3;function nn({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:m=1500,renderNoSession:y,renderPending:u,renderPaid:S,renderFailed:c}){let[x,k]=(0,ue.useState)(n),[p,L]=(0,ue.useState)(null),[C,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),f=d.searchParams.get("session_id");if(f){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(Ct,JSON.stringify({id:f,ts:Date.now()}))}catch{}}else try{let h=sessionStorage.getItem(Ct);if(h){let g=JSON.parse(h);typeof g.id=="string"&&typeof g.ts=="number"&&Date.now()-g.ts<=nr?f=g.id:sessionStorage.removeItem(Ct)}}catch{}a.current=f,k(f)},[n]),(0,ue.useEffect)(()=>{if(!x)return;let d=!1,f,h=Date.now(),g=async()=>{try{let _=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(_.ok){let v=await _.json();if(d||(L(v),v.status!=="pending"))return}}catch{}if(!d){if(Date.now()-h>=i){b(!0);return}f=setTimeout(g,o)}};return g(),()=>{d=!0,f&&clearTimeout(f)}},[x,e,o,i]);let w=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),P=(0,ue.useRef)(!1);(0,ue.useEffect)(()=>{if(!x||p===null||P.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(P.current=!0,!Nt(x)))return;let f=(p.line_items??[]).filter(h=>typeof h.variant_id=="string"&&h.variant_id.length>0).map(h=>({variantId:h.variant_id,quantity:h.quantity}));f.length>0&&Et(f)},[x,p]);let s=w&&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},m);return()=>clearTimeout(d)},[s,l,m]),x===void 0)return null;if(x===null)return y?(0,A.jsx)(A.Fragment,{children:y()}):(0,A.jsxs)("div",{className:t,style:r,children:[(0,A.jsx)("h2",{children:"Thank you for your order!"}),(0,A.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,A.jsx)(A.Fragment,{children:u({timedOut:C})}):(0,A.jsx)("div",{className:t,style:r,role:"status",children:(0,A.jsx)("p",{children:C?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(w){if(S)return(0,A.jsx)(A.Fragment,{children:S(p)});let{fulfillment:d}=p,f=p.currency,h=p.amount_total!==void 0&&f?z(p.amount_total,f):null,g=p.line_items??[],_=g.some(V=>!!V.image_url),v=p.tax_behavior==="exclusive"&&typeof p.tax_total=="number"&&p.tax_total>0&&!!f,R=typeof p.shipping_total=="number"&&!!f,O=d.files??[],D=O.length===0?d.download_url:void 0;return(0,A.jsxs)("div",{className:t,style:r,children:[(0,A.jsx)("h2",{style:Wn,children:"Thank you for your purchase!"}),p.is_test&&(0,A.jsxs)("p",{style:Yn,children:[(0,A.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),(g.length>0||h)&&(0,A.jsxs)("div",{style:Hn,children:[g.length>0&&(0,A.jsx)("ul",{style:Jn,children:g.map((V,B)=>{let T=typeof V.unit_amount=="number"&&f?z(V.unit_amount*V.quantity,f):null;return(0,A.jsxs)("li",{style:{...Gn,borderBottom:B<g.length-1?"1px solid #f3f4f6":void 0,opacity:V.refunded?.6:void 0},children:[_&&(V.image_url?(0,A.jsx)("img",{src:V.image_url,alt:"",width:56,height:56,style:tn}):(0,A.jsx)("div",{style:tn,"aria-hidden":"true"})),(0,A.jsxs)("div",{style:Qn,children:[(0,A.jsx)("div",{children:V.name}),V.quantity>1&&(0,A.jsxs)("div",{style:xe,children:["Qty ",V.quantity]}),V.refunded&&(0,A.jsx)("div",{style:xe,children:(0,A.jsx)("em",{children:V.refund_reason==="oversold"?"Sold out and refunded \u2014 check your email for details":"Refunded"})})]}),T&&(0,A.jsx)("div",{style:Zn,children:T})]},B)})}),h&&(0,A.jsxs)("div",{style:Xn,children:[R&&(0,A.jsxs)("div",{style:wt,children:[(0,A.jsx)("span",{style:xe,children:"Shipping"}),(0,A.jsx)("span",{children:p.shipping_total===0?"Free":z(p.shipping_total,f)})]}),v&&(0,A.jsxs)("div",{style:wt,children:[(0,A.jsx)("span",{style:xe,children:"Tax"}),(0,A.jsx)("span",{children:z(p.tax_total,f)})]}),(0,A.jsxs)("div",{style:er,children:[(0,A.jsx)("span",{children:"Total paid"}),(0,A.jsx)("span",{children:h})]})]})]}),p.source==="subscription"&&p.subscription&&(0,A.jsxs)(A.Fragment,{children:[(0,A.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,A.jsxs)("p",{children:["You can view, update, or cancel it any time on"," ",(0,A.jsx)("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),O.length>0&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("p",{children:"Your downloads:"}),(0,A.jsx)("ul",{children:O.map((V,B)=>(0,A.jsx)("li",{children:(0,A.jsx)("a",{href:V.download_url,children:V.name})},B))})]}),D&&(0,A.jsx)("p",{children:(0,A.jsx)("a",{href:D,style:tr,children:"Download your file"})}),s?(0,A.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,A.jsx)("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?(0,A.jsx)("p",{children:(0,A.jsx)("a",{href:d.redirect_url,children:"Continue to your content"})}):null,O.length===0&&!D&&!d.redirect_url&&(0,A.jsx)("p",{style:xe,children:"A confirmation email is on its way to you."}),typeof p.order_number=="number"?(0,A.jsxs)("p",{style:xe,children:["Order ",(0,A.jsxs)("strong",{children:["#",p.order_number]})," \u2014 keep this if you ever need help with your order."]}):p.order_id?(0,A.jsxs)("p",{style:xe,children:["Order reference: ",(0,A.jsx)("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]}):null]})}return c?(0,A.jsx)(A.Fragment,{children:c(p)}):(0,A.jsx)("div",{className:t,style:r,children:(0,A.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 lt=require("react");var Se=require("react/jsx-runtime");function _t(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 Pt(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var rr={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},ir={display:"block",width:"100%",textAlign:"left",padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},or={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600};function rn({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:m,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:S,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,L=k?.ready===!0,C=[...k?.plans??[]].sort((v,R)=>v.position-R.position),[b,a]=(0,lt.useState)(null),w=o!==void 0,P=w?o:b,s=C.map(v=>v.id).join("|"),d=C.length>0?C[0].id:null;if((0,lt.useEffect)(()=>{if(!(!p||!L)&&!(P!==null&&C.some(v=>v.id===P))){if(d===null){if(P===null)return;w||a(null),i?.(null);return}w||a(d),i?.(d)}},[p,L,d,s,P,w]),!k)return null;if(!L)return p?x?(0,Se.jsx)(Se.Fragment,{children:x()}):(0,Se.jsx)("div",{className:l,style:m,"data-state":"unavailable",children:(0,Se.jsx)("p",{children:"This product is currently unavailable."})}):null;if(C.length===0)return null;let f=e?.base_currency!==void 0&&e?.base_currency!==null,h=r!==void 0?r:f?null:e?.unit_amount??null,g=n??e?.base_currency??e?.currency??"usd",_=[];if(!p){let v=h;_.push({plan:null,selected:P===null,price:v,priceLabel:v!==null?z(v,g):null,label:"One-time purchase",select:()=>{w||a(null),i?.(null)}})}for(let v of C){let R=v.unit_amount!==null?v.unit_amount:h!==null?_t(h,v):null,O=R!==null?z(R,g):null,D=v.title&&v.title.trim().length>0?v.title.trim():`Subscribe ${Pt(v)}`,V=O?`${D} \u2014 ${O} ${Pt(v)}`:`${D} \u2014 billed ${Pt(v)}`;_.push({plan:v,selected:P===v.id,price:R,priceLabel:O,label:V,select:()=>{w||a(v.id),i?.(v.id)}})}return(0,Se.jsx)("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?m:{...rr,...m},children:_.map(v=>{if(c)return(0,Se.jsx)("span",{style:{display:"contents"},children:c(v)},v.plan?.id??"one-time");let R=v.selected;return(0,Se.jsx)("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":v.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...ir,...R?or:{}},onClick:v.select,children:v.plan===null&&S!==void 0?S:v.plan===null?v.priceLabel?`One-time purchase \u2014 ${v.priceLabel}`:"One-time purchase":v.label},v.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 m=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:m,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:m,error:y}}}function on(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function Be(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 sr=1500;function sn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function ar(e,t){return e.requestId===t}function ur(e,t){return typeof window>"u"||!sn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;if(y?.type==="aifeatures:preview-session-ack"&&ar(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let S=y.customer;typeof S.email=="string"&&(u={email:S.email,name:typeof S.name=="string"?S.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}),sr);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ee(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,X.useState)(()=>Pe()),[o,i]=(0,X.useState)(null),[l,m]=(0,X.useState)(!1),[y,u]=(0,X.useState)(!1),S=(0,X.useRef)(void 0);(0,X.useEffect)(()=>qt(()=>{let b=Pe();n(b),i(b===null?a=>Mt()??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 P=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 tt({token:a.data.token,customer:P}),n({token:a.data.token,customer:P}),i(null),m(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(m(!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")&&S.current===void 0){if(!x){S.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())),S.current=a,a&&c(a)}},[c,x]);let k=(0,X.useCallback)(async b=>{if(typeof window<"u"&&sn(window)){let w=await ur(b,De());if(w.claimed){if(w.token!==null){let P=w.customer??{email:b,name:null};return tt({token:w.token,customer:P}),n({token:w.token,customer:P}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:w.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"?(m(!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]),L=(0,X.useCallback)(async()=>{let b=Pe();if(!b)return;let a=await de(t,"/v1/account/me",{token:b.token}),w=()=>Pe()?.token===b.token;if(a.ok){if(!w())return;let P=a.data.customer??b.customer;tt({token:b.token,customer:P}),n({token:b.token,customer:P}),m(!1);return}if(a.failure.kind==="unauthorized"){if(!w())return;me("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){m(!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:L}}var K=require("react");var le=require("react");var F=require("react/jsx-runtime"),xt={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},lr={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},cr={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},an={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Ue={margin:0},dr={color:"#b91c1c",margin:0};function Fe({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:m}){let y=Ee({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[S,c]=(0,le.useState)(""),[x,k]=(0,le.useState)("form"),[p,L]=(0,le.useState)(!1),[C,b]=(0,le.useState)(null),[a,w]=(0,le.useState)(null),[P,s]=(0,le.useState)(!1),d=(0,le.useRef)(void 0),f=(0,le.useRef)(!1);(0,le.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]);let h=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},g=async()=>{let R=S.trim();if(!R||p||f.current)return;f.current=!0,L(!0),b(null),w(null);let O=await u.login(R);if(f.current=!1,L(!1),O.ok){if(O.via==="preview")return;k("sent"),h();return}O.code!=="unavailable"&&(b(O.code==="rate_limited"?"rate_limited":"error"),w(O.error))};if(u.status==="unavailable")return m?(0,F.jsx)(F.Fragment,{children:m()}):(0,F.jsx)("div",{className:n,style:n?o:{...xt,...o},"data-state":"unavailable",children:(0,F.jsx)("p",{style:Ue,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:S.trim(),canResend:P,resend:()=>{g(),h()},submitting:p,reset:()=>k("form")};return l?(0,F.jsx)(F.Fragment,{children:l(R)}):(0,F.jsxs)("div",{className:n,style:n?o:{...xt,...o},"data-state":"sent",children:[(0,F.jsxs)("p",{style:Ue,children:["Check your email \u2014 if ",(0,F.jsx)("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),P?(0,F.jsxs)("p",{style:Ue,children:["Didn't get it?"," ",(0,F.jsx)("button",{type:"button",style:an,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",(0,F.jsx)("button",{type:"button",style:an,onClick:R.reset,children:"use a different email"}),"."]}):(0,F.jsx)("p",{style:Ue,children:"It can take a minute to arrive."})]})}let _={email:S,setEmail:c,submit:()=>void g(),submitting:p,errorKind:C,errorMessage:a,reason:u.reason};if(i)return(0,F.jsx)(F.Fragment,{children:i(_)});let v=R=>{R.preventDefault(),_.submit()};return(0,F.jsxs)("form",{className:n,style:n?o:{...xt,...o},onSubmit:v,"data-state":"form",children:[u.reason==="session_expired"&&(0,F.jsx)("p",{style:Ue,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&(0,F.jsx)("p",{style:Ue,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),(0,F.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[(0,F.jsx)("span",{children:"Email address"}),(0,F.jsx)("input",{type:"email",value:S,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:lr})]}),(0,F.jsx)("button",{type:"submit",style:cr,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&(0,F.jsx)("p",{style:dr,role:"alert",children:C==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}var W=require("react/jsx-runtime"),pr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},fr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},ze={color:"#6b7280",fontSize:"0.875rem"};function mr(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 ct({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?(0,W.jsx)(W.Fragment,{children:o()}):(0,W.jsxs)("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&(0,W.jsx)("h3",{children:n}),(0,W.jsx)("p",{style:ze,children:"No orders yet."})]}):(0,W.jsxs)("div",{className:t,style:r,children:[n!==null&&(0,W.jsx)("h3",{children:n}),(0,W.jsx)("ul",{style:t?void 0:pr,children:e.map(l=>{if(i)return(0,W.jsx)("li",{style:{display:"contents"},children:i(l)},l.id);let m=Be(l.created_at),y=mr(l);return(0,W.jsxs)("li",{style:t?void 0:fr,children:[(0,W.jsxs)("div",{children:[l.order_number!==null&&(0,W.jsxs)("strong",{children:["Order #",l.order_number]})," ",m&&(0,W.jsx)("span",{style:ze,children:m})," ",l.source==="subscription"&&(0,W.jsx)("span",{style:ze,children:"\xB7 subscription"}),y&&(0,W.jsxs)("span",{style:ze,children:[" \xB7 ",y]})]}),l.line_items.length>0&&(0,W.jsx)("div",{style:ze,children:l.line_items.map(u=>u.name?`${u.quantity&&u.quantity>1?`${u.quantity} \xD7 `:""}${u.name}`:null).filter(Boolean).join(", ")}),(0,W.jsx)("div",{children:z(l.amount_total,l.currency)})]},l.id)})})]})}var ee=require("react");var U=require("react/jsx-runtime"),gr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},yr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},Ne={color:"#6b7280",fontSize:"0.875rem"},br={color:"#b91c1c",fontSize:"0.875rem",margin:0},hr={color:"#065f46",fontSize:"0.875rem",margin:0},Rt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Re={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},ln={...Re,border:"1px solid #111827",background:"#111827",color:"white"},Sr={...Re,border:"1px solid #b91c1c",color:"#b91c1c"},vr={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},un={panel:"none",mutation:null,portalRefused:!1};function kr(e){let t=Be(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 Cr({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=(0,ee.useState)(e?.name??""),[m,y]=(0,ee.useState)(o?.line1??""),[u,S]=(0,ee.useState)(o?.line2??""),[c,x]=(0,ee.useState)(o?.city??""),[k,p]=(0,ee.useState)(o?.state??""),[L,C]=(0,ee.useState)(o?.postal_code??""),[b,a]=(0,ee.useState)(o?.country??""),w=(P,s,d,f)=>(0,U.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[(0,U.jsx)("span",{children:P}),(0,U.jsx)("input",{style:vr,value:s,onChange:h=>d(h.target.value),required:f?.required,maxLength:f?.maxLength})]});return(0,U.jsxs)("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:P=>{P.preventDefault(),r({name:i.trim()||null,address:{line1:m.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:L.trim()||null,country:b.trim().toUpperCase()}})},children:[w("Name",i,l),w("Address line 1",m,y,{required:!0}),w("Address line 2",u,S),w("City",c,x),w("State / region",k,p),w("Postal code",L,C),w("Country (2-letter code)",b,a,{required:!0,maxLength:2}),(0,U.jsxs)("div",{style:Rt,children:[(0,U.jsx)("button",{type:"submit",style:ln,disabled:t,children:t?"Saving\u2026":"Save address"}),(0,U.jsx)("button",{type:"button",style:Re,onClick:n,disabled:t,children:"Cancel"})]})]})}function je({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:m,heading:y="Your subscriptions",renderEmpty:u,renderRow:S}){let[c,x]=(0,ee.useState)(t),[k,p]=(0,ee.useState)({}),L=(0,ee.useRef)(new Set);(0,ee.useEffect)(()=>{x(t)},[t]),(0,ee.useEffect)(()=>{let s=d=>{d.persisted&&(L.current.clear(),p(f=>{let h=!1,g={};for(let[_,v]of Object.entries(f))v.mutation?.phase==="pending"?(g[_]={...v,mutation:null},h=!0):g[_]=v;return h?g:f}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let C=(s,d)=>p(f=>({...f,[s]:{...f[s]??un,...d}})),b=s=>{x(d=>d.map(f=>f.id===s.id?s:f)),i?.(s)},a=async(s,d,f,h)=>{if(L.current.has(s.id))return{ok:!1};L.current.add(s.id);try{C(s.id,{mutation:{kind:d,phase:"pending"}});let g=await de(e,f,{method:"POST",token:r.token,body:h??{}});if(g.ok)return{ok:!0,data:g.data};let{failure:_}=g;return _.kind==="unauthorized"?(n?.({code:_.code,error:_.error}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="unavailable"?(o?.(),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="ended"?(b({...s,ended:!0,status:"canceled"}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="portal_unavailable"?(C(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(C(s.id,{mutation:{kind:d,phase:"error",error:_.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":_.error}}),{ok:!1})}finally{L.current.delete(s.id)}},w=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"},P=s=>{let d=k[s.id]??un,f=w(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>C(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>C(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let h=await a(s,"cancel",f.cancel);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:f.reactivate!==null,reactivate:()=>{f.reactivate&&(async()=>{let h=await a(s,"reactivate",f.reactivate);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{f.address&&C(s.id,{panel:"address",mutation:null})},saveAddress:h=>{f.address&&(async()=>{let g=await a(s,"address",f.address,{shipping_address:h});if(g.ok){let _=g.data.subscription;_&&b(_),C(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let h=await a(s,"portal",f.portal);h.ok&&typeof h.data.url=="string"?window.location.href=h.data.url:h.ok&&C(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:m,"data-state":"empty",children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("p",{style:Ne,children:"No subscriptions."})]}):(0,U.jsxs)("div",{className:l,style:m,children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("ul",{style:l?void 0:gr,children:c.map(s=>{let d=P(s);return S?(0,U.jsx)("li",{style:{display:"contents"},children:S(d)},s.id):(0,U.jsx)("li",{style:l?void 0:yr,"data-status":s.status,"data-ended":s.ended||void 0,children:(0,U.jsx)(wr,{ctx:d})},s.id)})})]})}function wr({ctx:e}){let t=e.subscription,r=kr(t),n=Be(t.current_period_end),o=`${z(t.current_amount,t.currency)} ${on(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:Ne,children:["\xB7 ",o]}),t.is_test&&(0,U.jsx)("span",{style:Ne,children:" \xB7 test"})]}),(0,U.jsx)("div",{style:r.tone==="warn"?void 0:Ne,children:r.text}),t.ended?(0,U.jsx)("p",{style:Ne,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:Rt,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:Re,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?(0,U.jsx)(Cr,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):(0,U.jsxs)("div",{style:Rt,children:[t.cancel_at_period_end?e.reactivateAvailable?(0,U.jsx)("button",{type:"button",style:ln,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):(0,U.jsx)("span",{style:Ne,children:"To keep this subscription, sign in with your email address on this page."}):(0,U.jsx)("button",{type:"button",style:Re,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:Re,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&(0,U.jsx)("button",{type:"button",style:Re,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&(0,U.jsx)("p",{style:br,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&(0,U.jsx)("p",{style:hr,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 I=require("react/jsx-runtime"),Pr={display:"flex",flexDirection:"column",gap:"1.25rem"},cn={color:"#6b7280",fontSize:"0.875rem"},_r={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},dn={color:"#b91c1c"},dt={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function pn({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:m,renderHeader:y,renderPmBanner:u,renderManageExpired:S}){let c=Ee({apiUrl:e}),x=(0,K.useRef)(void 0),[k,p]=(0,K.useState)(null),[L,C]=(0,K.useState)(!1);(0,K.useEffect)(()=>{if(!(typeof window>"u")){if(x.current===void 0){let N=new URL(window.location.href),E=N.searchParams.get("manage_code"),j=N.searchParams.get("pm");(E!==null||j!==null)&&(N.searchParams.delete("manage_code"),N.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",N.toString())),x.current={manageCode:E,pmUpdated:j==="updated"}}p(x.current.manageCode),C(x.current.pmUpdated)}},[]);let[b,a]=(0,K.useState)(null),w=(0,K.useRef)(!1),P=(0,K.useRef)(0),s=(0,K.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,K.useEffect)(()=>{!k||w.current||(w.current=!0,s(k))},[k,s]);let d=(0,K.useCallback)(async()=>{let N=b;if(!N||N.phase!=="active")return;let E=++P.current,j=await de(e,"/v1/account/manage/subscription",{token:N.token});E===P.current&&(j.ok&&j.data.subscription?a({phase:"active",token:N.token,sub:j.data.subscription,siteName:typeof j.data.site?.name=="string"?j.data.site.name:N.siteName}):!j.ok&&j.failure.kind==="unauthorized"?a({phase:"expired"}):!j.ok&&j.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[f,h]=(0,K.useState)({phase:"loading"}),[g,_]=(0,K.useState)(0),v=g>0,R=(0,K.useRef)(0),O=c.token,D=(0,K.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){h({phase:"ready",data:E.data});return}if(E.failure.kind==="unauthorized"){me("session_expired");return}if(E.failure.kind==="unavailable"){me();return}h({phase:"error",error:E.failure.error})}},[e,O]);(0,K.useEffect)(()=>{!O||k||(h({phase:"loading"}),D())},[O,k,D]);let V=(0,K.useCallback)(async()=>{_(N=>N+1);try{b&&b.phase==="active"?await d():await D()}finally{_(N=>N-1)}},[b,d,D]),B=(0,K.useCallback)(N=>{R.current++,P.current++,a(E=>E&&E.phase==="active"&&E.sub.id===N.id?{...E,sub:N}:E),h(E=>E.phase==="ready"?{phase:"ready",data:{...E.data,subscriptions:E.data.subscriptions.map(j=>j.id===N.id?N:j)}}:E)},[]),T=t?r:{...Pr,...r},M=N=>{if(!L)return null;let j={state:N.some(ie=>!ie.ended&&(ie.status==="past_due"||ie.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void V(),checking:v};return u?u(j):(0,I.jsx)("div",{style:_r,role:"status","data-pm-state":j.state,children:j.state==="retrying"?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),(0,I.jsx)("p",{style:{margin:"0.375rem 0 0"},children:(0,I.jsx)("button",{type:"button",style:dt,onClick:j.checkAgain,disabled:v,children:v?"Checking\u2026":"Check again"})})]}):(0,I.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,I.jsx)(I.Fragment,{children:i()}):(0,I.jsx)("div",{className:t,style:T,role:"status",children:(0,I.jsx)("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?(0,I.jsxs)("div",{className:t,style:T,children:[M([b.sub]),(0,I.jsx)(je,{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,I.jsx)("div",{className:t,style:T,"data-state":"unavailable",children:(0,I.jsx)("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?(0,I.jsxs)("div",{className:t,style:T,children:[(0,I.jsx)("p",{style:dn,role:"alert",children:b.error}),(0,I.jsx)("p",{children:(0,I.jsx)("button",{type:"button",style:dt,onClick:()=>s(k),children:"Try again"})})]}):(0,I.jsxs)("div",{className:t,style:T,"data-state":"manage-expired",children:[S?S():(0,I.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,I.jsx)(Fe,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?(0,I.jsx)(I.Fragment,{children:i()}):(0,I.jsx)("div",{className:t,style:T,role:"status",children:(0,I.jsx)("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return(0,I.jsx)("div",{className:t,style:T,children:(0,I.jsx)(Fe,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(f.phase==="loading")return i?(0,I.jsx)(I.Fragment,{children:i()}):(0,I.jsx)("div",{className:t,style:T,role:"status",children:(0,I.jsx)("p",{children:"Loading your account\u2026"})});if(f.phase==="error")return l?(0,I.jsx)(I.Fragment,{children:l({error:f.error,retry:()=>void D()})}):(0,I.jsxs)("div",{className:t,style:T,children:[(0,I.jsxs)("p",{style:dn,role:"alert",children:["We couldn't load your account \u2014 ",f.error]}),(0,I.jsx)("p",{children:(0,I.jsx)("button",{type:"button",style:dt,onClick:()=>void D(),children:"Try again"})})]});let{data:q}=f,te=q.customer??c.customer??{email:"",name:null},$=()=>void c.logout(),Y=q.orders.length===0&&q.subscriptions.length===0;return(0,I.jsxs)("div",{className:t,style:T,children:[y?y({customer:te,site:q.site??null,signOut:$}):(0,I.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("h2",{style:{margin:0},children:"Your account"}),(0,I.jsxs)("p",{style:{...cn,margin:0},children:["Signed in as ",te.email]})]}),(0,I.jsx)("button",{type:"button",style:dt,onClick:$,children:"Sign out"})]}),M(q.subscriptions),Y?m?m():(0,I.jsxs)("p",{style:cn,children:["Nothing here yet \u2014 orders and subscriptions for ",te.email," ","will show up on this page."]}):(0,I.jsxs)(I.Fragment,{children:[q.subscriptions.length>0&&(0,I.jsx)(je,{apiUrl:e,subscriptions:q.subscriptions,auth:{kind:"session",token:O},onSubscriptionChange:B,onAuthError:()=>me("session_expired"),onUnavailable:()=>me()}),(0,I.jsx)(ct,{orders:q.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 pt=Object.defineProperty;var fn=Object.getOwnPropertyDescriptor;var mn=Object.getOwnPropertyNames;var gn=Object.prototype.hasOwnProperty;var yn=(e,t)=>{for(var r in t)pt(e,r,{get:t[r],enumerable:!0})},bn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of mn(t))!gn.call(e,o)&&o!==r&&pt(e,o,{get:()=>t[o],enumerable:!(n=fn(t,o))||n.enumerable});return e};var hn=e=>bn(pt({},"__esModule",{value:!0}),e);var xr={};yn(xr,{AccountLogin:()=>Fe,AccountOrders:()=>ct,AccountPage:()=>pn,AddToCartButton:()=>Qt,AifeaturesCaptcha:()=>Tt,BuyButton:()=>Gt,CartCheckoutButton:()=>en,MARKET_COUNTRIES:()=>at,MAX_CART_LINES:()=>kt,OrderConfirmation:()=>nn,PlanPicker:()=>rn,ProductPrice:()=>Kt,SubscriptionList:()=>je,VariantPicker:()=>Yt,ZERO_DECIMAL_CURRENCIES:()=>mt,applySelectionToUrl:()=>Ze,formatPrice:()=>z,getOptions:()=>we,getVariants:()=>be,isMultiVariant:()=>Ae,isValueAvailable:()=>Ye,isValueInCatalog:()=>He,planRecurringAmount:()=>_t,reanchorSelection:()=>Je,resolveVariant:()=>ke,searchFromSelection:()=>Ve,selectedImages:()=>Oe,selectedValues:()=>gt,selectionFromSearch:()=>Qe,useCart:()=>ye,useCartCheckout:()=>st,useCartItems:()=>ot,useCartSummary:()=>Bt,useCheckout:()=>rt,useMarket:()=>jt,useProduct:()=>ve,useSession:()=>Ee,valueSlug:()=>pe,variantPriceRange:()=>Ge});module.exports=hn(xr);var Me=require("react"),Ot=require("@marsidev/react-turnstile"),ft=require("react/jsx-runtime");function Tt({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=(0,Me.useState)(null),[m,y]=(0,Me.useState)(!0);return(0,Me.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]),m||!i?null:(0,ft.jsx)("div",{className:o,children:(0,ft.jsx)(Ot.Turnstile,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}var ce=require("react"),Ke=[1e3,3e3];function ve(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=(0,ce.useState)(null),[l,m]=(0,ce.useState)(!0),[y,u]=(0,ce.useState)(null),[S,c]=(0,ce.useState)(0),x=(0,ce.useRef)(e);(0,ce.useEffect)(()=>{let p=!1,L;m(!0),u(null),x.current!==e&&(x.current=e,i(null));let C=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let w=await a.json().catch(()=>null);if(!p)if(!a.ok||!w){if(a.status>=500&&b<Ke.length){L=setTimeout(()=>C(b+1),Ke[b]);return}u(w?.error??`Request failed (${a.status})`),i(null),m(!1)}else i(w),m(!1)}).catch(a=>{if(!p){if(b<Ke.length){L=setTimeout(()=>C(b+1),Ke[b]);return}u(a instanceof Error?a.message:"Failed to load product"),m(!1)}})};return C(0),()=>{p=!0,L&&clearTimeout(L)}},[e,r,n,S]);let k=(0,ce.useCallback)(()=>c(p=>p+1),[]);return{product:o,loading:l,error:y,refresh:k}}var mt=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function z(e,t,r){let n=mt.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 Ae(e){return we(e).length>0}function We(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=We(o);if(i[r]!==n)return!1;for(let[l,m]of Object.entries(t))if(l!==r&&i[l]!==m)return!1;return!0})}function He(e,t,r){return e.some(n=>We(n)[t]===r)}function Je(e,t,r,n){let o={[r]:n};for(let[l,m]of Object.entries(t)){if(l===r)continue;e.some(u=>{let S=We(u);return S[r]===n&&S[l]===m})&&(o[l]=m)}return e.some(l=>{let m=We(l);return Object.entries(o).every(([y,u])=>m[y]===u)})?o:{[r]:n}}function Ge(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 gt(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 Qe(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 m=n.get(l);if(m===void 0)continue;let y=pe(m);if(y.length===0)continue;let u=i.values.find(S=>pe(S.value)===y);u&&(o[i.id]=u.id)}return o}function Ve(e,t){let r={};for(let[n,o]of Object.entries(gt(e,t))){let i=pe(n),l=pe(o);i.length===0||l.length===0||(r[i]=l)}return r}function Oe(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(Ve(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}var oe=require("react");var bt="aifeatures_cart",ht="aifeatures_market",Lt="aifeatures_cart_cleared";var yt="aifeatures:cart-storage",qe=new Map;function $e(e){if(qe.has(e))return qe.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Te(e,t){if(typeof window>"u"){qe.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),qe.delete(e)}catch{qe.set(e,t)}Sn(e)}function Sn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(yt,{detail:{key:e}}))}catch{}}function Xe(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(yt,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(yt,n)}}function vn(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,m]of Object.entries(t.selection))typeof m=="string"&&(n[l]=m);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=$e(bt);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=vn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function fe(e){Te(bt,JSON.stringify(e))}function It(e){return Xe(bt,e)}function Et(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=$e(ht);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function Ut(e){Te(ht,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function Le(e){return Xe(ht,e)}function Nt(e){let t=[],r=$e(Lt);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)),Te(Lt,JSON.stringify(t)),!0)}var et="aifeatures_session",St=null;function Mt(){return St}function kn(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=$e(et);if(!e)return null;try{return kn(JSON.parse(e))}catch{return null}}function Vt(){return Pe()?.token??null}function tt(e){St=null,Te(et,JSON.stringify(e))}function me(e){St=e??null,Te(et,null)}function qt(e){return Xe(et,e)}var Cn=1500;function De(){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 nt(e,t){return!("requestId"in e)||e.requestId===t}function vt(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;y?.type==="aifeatures:test-checkout-ack"&&nt(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),Cn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function $t(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 rt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,oe.useState)(!1),[o,i]=(0,oe.useState)(null),[l,m]=(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||!nt(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:L,successUrl:C,cancelUrl:b,customerEmail:a,planId:w,expectedUnitAmount:P,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),m(null),w!==void 0){let d=Vt();if(d)try{let f=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:w,...x!==void 0?{variant_id:x}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.text().catch(()=>""),g=null;try{g=h?JSON.parse(h):null}catch{g=null}if(f.ok){if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}$t(g.url)==="stayed"&&(y.current=!1,n(!1));return}let _=f.status===404&&h.trim()==="";if(f.status===401||_)me();else{i(g?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}}catch(f){i(f instanceof Error?f.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=w===void 0?ne():null,f=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&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{plan_id:w}:{},...L!==void 0?{metadata:L}:{},...a!==void 0?{customer_email:a}:{},...P!==void 0&&s!==void 0&&w===void 0?{expected_unit_amount:P,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.json().catch(()=>null);if(!f.ok){if(h?.error==="price_changed"&&typeof h.current_unit_amount=="number"&&typeof h.currency=="string"){m({currentUnitAmount:h.current_unit_amount,currency:h.currency}),i(`The price has changed to ${z(h.current_unit_amount,h.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(h?.code==="preview_domain"){let g=De();if(u.current=g,await vt({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{planId:w}:{},...a!==void 0?{customerEmail:a}:{},...L!==void 0?{metadata:L}:{}},g))return;u.current=null}i(h?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}$t(h.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 kt=20;function Dt(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),It(u)},[]);let o=(0,ge.useCallback)(u=>{let S=Ce(),c=Dt(u.quantity);return S.find(k=>k.variantId===u.variantId)?(fe(S.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):S.length>=kt?{ok:!1,reason:"cart_full"}:(fe([...S,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=(0,ge.useCallback)(u=>{fe(Ce().filter(S=>S.variantId!==u))},[]),l=(0,ge.useCallback)((u,S)=>{let c=Ce();if(S<=0){fe(c.filter(k=>k.variantId!==u));return}let x=Dt(S);fe(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),m=(0,ge.useCallback)(()=>{fe([])},[]),y=e.reduce((u,S)=>u+S.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:m}}var G=require("react");var it={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},wn={...it,inStock:!0,status:"error"};function Pn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ot(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=ye(),[o,i]=(0,G.useState)({}),[l,m]=(0,G.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=(0,G.useState)(!0),[S,c]=(0,G.useState)(null),[x,k]=(0,G.useState)(0),p=(0,G.useRef)(new Set),L=(0,G.useMemo)(()=>JSON.stringify(r.map(P=>[P.productId,P.variantId,P.selection])),[r]),C=(0,G.useCallback)(()=>k(P=>P+1),[]);(0,G.useEffect)(()=>Le(C),[C]),(0,G.useEffect)(()=>{if(!n)return;if(r.length===0){i({}),m({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let P=!1;u(!0);let s=r,d=[...new Set(s.map(h=>h.productId))],f=async h=>{let g=new Map;return await Promise.all(d.map(async _=>{try{let v=await fetch(`${t}/v1/p/${encodeURIComponent(_)}${h?`?country=${encodeURIComponent(h)}`:""}`);if(v.status===404){g.set(_,{kind:"not_found"});return}if(!v.ok){g.set(_,{kind:"error",message:`Request failed (${v.status})`});return}let R=await v.json();g.set(_,{kind:"ok",product:R})}catch(v){g.set(_,{kind:"error",message:v instanceof Error?v.message:"Failed to load product"})}})),g};return(async()=>{let h=ne(),g=await f(h);if(h){let T=[...g.values()].filter(q=>q.kind==="ok"),M=T.filter(q=>q.product.base_currency);M.length>0&&M.length<T.length&&(g=await f(null))}if(P)return;let _=null,v=null,R=null;for(let T of d){let M=g.get(T);!M||M.kind!=="ok"||(_===null&&M.product.shipping_rates&&(_=M.product.shipping_rates),v===null&&M.product.free_shipping_over!=null&&(v=M.product.free_shipping_over),R===null&&M.product.shipping_countries&&(R=M.product.shipping_countries))}let O={},D=new Map,V=null;for(let T of s){let M=g.get(T.productId);if(!M||M.kind==="error"){O[T.variantId]=wn,M&&V===null&&(V=M.message);continue}if(M.kind==="not_found"){O[T.variantId]=it;continue}let{product:q}=M;if(!q.active||q.purchasable===!1){O[T.variantId]=it;continue}let te=q.variants??[],$=te.find(ie=>ie.id===T.variantId)??null,Y=T.variantId;if(!$){let ie=ke(te,T.selection);if(!ie){O[T.variantId]=it;continue}let At=D.get(T.variantId)??{};At.reanchorTo={variantId:ie.id,selection:Pn(ie)},D.set(T.variantId,At),p.current.add(ie.id),$=ie,Y=ie.id}let N=Oe(q,T.selection)[0]??null,E={image:N,unitAmount:$.unit_amount,currency:$.currency,baseCurrency:q.base_currency??null,inStock:$.in_stock,available:$.available,maxQuantity:q.max_quantity,pdpSearch:Ve(q,T.selection),status:p.current.has(Y)?"reanchored":"ok"};O[T.variantId]=E,O[Y]=E;let j=D.get(T.variantId)??{};j.display={name:q.name,variantTitle:$.title,image:N},D.set(T.variantId,j)}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(D.size>0){let T=Ce(),M=[],q=new Map,te=!1;for(let $ of T){let Y=D.get($.variantId),N={...$};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=q.get(N.variantId);if(E){E.quantity+=N.quantity,te=!0;continue}M.push(N),q.set(N.variantId,N)}te&&fe(M)}P||(i(O),m({shippingRates:_,freeShippingOver:v,shippingCountries:R}),c(V),u(!1))})(),()=>{P=!0}},[n,L,t,x]);let b=(0,G.useMemo)(()=>r.map(P=>{let s=o[P.variantId];return s?{...P,...s,image:s.image??P.display.image}:{...P,image:P.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:w}=(0,G.useMemo)(()=>{let P=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(P+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:P,currency:s}},[b]);return{lines:b,subtotal:a,currency:w,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:S,refresh:C}}var Q=require("react");var _n=2e3;function Bt(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=ye(),[l,m]=(0,Q.useState)(null),[y,u]=(0,Q.useState)(!1),[S,c]=(0,Q.useState)(null),[x,k]=(0,Q.useState)(null),[p,L]=(0,Q.useState)(0);(0,Q.useEffect)(()=>(k(ne()),Le(()=>k(ne()))),[]);let C=(0,Q.useMemo)(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=(0,Q.useCallback)(()=>L(s=>s+1),[]),a=(0,Q.useRef)(0),w=(0,Q.useRef)(!1),P=(0,Q.useRef)("idle");return(0,Q.useEffect)(()=>{if(!i)return;if(o.length===0){m(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,f=!1,h,g=w.current?r:0;w.current=!0,P.current=P.current==="pending"?"spent":"idle";let _=setTimeout(async()=>{u(!0);try{let v=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(f||s!==a.current)return;if(!v.ok){if(v.status===429){let O=P.current==="idle";O&&(h=setTimeout(()=>{f||s!==a.current||(P.current="pending",L(D=>D+1))},_n)),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 (${v.status})`);return}let R=await v.json();if(f||s!==a.current)return;m({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(v){if(f||d.signal.aborted||s!==a.current)return;c(v instanceof Error?v.message:"Could not price this cart")}finally{!f&&s===a.current&&u(!1)}},g);return()=>{f=!0,clearTimeout(_),h!==void 0&&clearTimeout(h),d.abort()}},[i,C,x,t,r,n,p]),{summary:l,loading:y,error:S,refresh:b}}var re=require("react");function st(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,re.useState)(!1),[o,i]=(0,re.useState)(null),[l,m]=(0,re.useState)(null),[y,u]=(0,re.useState)(null),S=(0,re.useRef)(!1),c=(0,re.useRef)(null);return(0,re.useEffect)(()=>{let k=p=>{p.persisted&&(S.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 L=p.data;if(L?.type!=="aifeatures:test-checkout-ack"||L.status!=="failed")return;let C=c.current;C===null||!nt(L,C)||(c.current=null,i(typeof L.error=="string"&&L.error?L.error:"The test purchase could not be created."),S.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:(0,re.useCallback)(async(k,{successUrl:p,cancelUrl:L,customerEmail:C,metadata:b,shippingOption:a}={})=>{if(!S.current){S.current=!0,n(!0),i(null),m(null),u(null);try{let w=ne(),P=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}:{}})),...w!==null?{country:w}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...C!==void 0?{customer_email:C}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:L??window.location.href})}),s=await P.json().catch(()=>null);if(!P.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:""}),S.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let f of s.items)f&&typeof f.variant_id=="string"&&(d[f.variant_id]=f);m(d),S.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=De();if(c.current=d,await vt({items:k.map(h=>({productId:h.productId,variantId:h.variantId,quantity:h.quantity})),...C!==void 0?{customerEmail:C}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${P.status})`),S.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),S.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")){S.current=!1,n(!1);return}}window.location.href=s.url}catch(w){i(w instanceof Error?w.message:"Checkout failed"),S.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}var he=require("react");var at=[{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 Ft(e){return e?at.find(t=>t.country===e.toUpperCase())?.currency??null:null}var zt=new Map;function xn(e){let t=zt.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),zt.set(e,t)),t}function jt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,he.useState)(null),[o,i]=(0,he.useState)(!1),[l,m]=(0,he.useState)(null);(0,he.useEffect)(()=>{let c=()=>n(ne());return c(),i(!0),Le(c)},[]),(0,he.useEffect)(()=>{let c=!1;return xn(t).then(x=>{c||m(x)}),()=>{c=!0}},[t]);let y=(0,he.useCallback)(c=>{Ut(c)},[]),u=Ft(l),S=o&&u!==null&&u!==Ft(r);return{market:r,suggestedCountry:l,setMarket:y,markets:at,shouldPrompt:S}}var Ie=require("react/jsx-runtime"),Rn={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function Kt({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:m,loading:y}=ve(e,{apiUrl:r});if(y||!m)return null;let u=be(m),S=t!==void 0?u.find(x=>x.id===t)??null:m.options.length===0?u[0]??null:null;if(S){if(S.unit_amount===null)return null;let x=S.compare_at_amount!==null&&S.compare_at_amount>S.unit_amount;return(0,Ie.jsxs)("span",{className:o,style:i,children:[x&&(0,Ie.jsx)("span",{className:l,style:l?void 0:Rn,children:z(S.compare_at_amount,S.currency,n)}),z(S.unit_amount,S.currency,n)]})}let c=Ge(u);return c?(0,Ie.jsx)("span",{className:o,style:i,children:c.min===c.max?z(c.min,m.currency,n):`${z(c.min,m.currency,n)} \u2013 ${z(c.max,m.currency,n)}`}):m.unit_amount===null?null:(0,Ie.jsx)("span",{className:o,style:i,children:z(m.unit_amount,m.currency,n)})}var ae=require("react");var se=require("react/jsx-runtime"),An={marginBottom:"0.75rem"},On={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},Tn={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Ln={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},In={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},Wt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},En={...Wt,cursor:"pointer"},Un=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Nn=e=>Un.test(e),Mn={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},Vn={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)"},qn="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 Yt({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:m,optionClassName:y,optionLabelClassName:u,valueClassName:S,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[L,C]=(0,ae.useState)(r??{}),b=p?r:L,[a,w]=(0,ae.useState)(()=>new Set),P=g=>w(_=>_.has(g)?_:new Set(_).add(g));(0,ae.useEffect)(()=>{w(g=>g.size===0?g: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(L).length>0))return;let g=Qe({options:e},window.location.search);Object.keys(g).length!==0&&(C(g),o?.(g))},[n,p,e]);let d=(0,ae.useMemo)(()=>e.length>0?t.filter(g=>g.option_values.length===e.length):t,[t,e]),f=(0,ae.useRef)(void 0);if((0,ae.useEffect)(()=>{let g=ke(d,b),_=g?.id??null;f.current!==_&&(f.current=_,i?.(g))},[d,b]),e.length===0)return null;let h=(g,_)=>{let v=Je(d,b,g,_);p||(C(v),n&&Ze({options:e},v)),o?.(v)};return(0,se.jsx)("div",{className:l,style:m,children:e.map(g=>(0,se.jsxs)("div",{className:y,style:y?void 0:An,children:[(0,se.jsx)("span",{className:u,style:u?void 0:On,children:g.title}),(0,se.jsx)("div",{style:Tn,children:g.values.map(_=>{let v=b[g.id]===_.id,R=Ye(d,b,g.id,_.id),O=R||He(d,g.id,_.id),D=[S,v?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,V=_.swatch??null,B=V&&!a.has(V)?V:null,T=B?Nn(B):!1,M=S?void 0:{...Ln,...v?In:{},...R?{}:O?En:Wt,...B?{...Mn,textDecoration:"none"}:{}},q=R?_.value:`${_.value} \u2014 unavailable with your current selection`;return(0,se.jsx)("button",{type:"button",className:D,style:M,disabled:!O,"aria-pressed":v,"aria-label":B?q:void 0,title:B?q:void 0,"data-selected":v?"true":void 0,"data-available":R?"true":"false","data-swatch":B?T?"hex":"image":void 0,onClick:()=>h(g.id,_.id),children:B?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)("span",{"aria-hidden":"true",className:k,style:k?void 0:{...Vn,...T?{background:B}:{},...T&&R?{}:{backgroundImage:[...R?[]:[qn],...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:()=>P(B)})]}):_.value},_.id)})})]},g.id))})}var Jt=require("react");function ut(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}var H=require("react/jsx-runtime"),$n={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Dn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function Ht(){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 Gt({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,apiUrl:u,disabled:S,className:c,style:x,errorClassName:k,spinner:p=!0,children:L}){let{product:C,loading:b,error:a,refresh:w}=ve(e,{apiUrl:u}),{startCheckout:P,loading:s,error:d,priceChange:f}=rt({apiUrl:u});(0,Jt.useEffect)(()=>{f&&w()},[f,w]);let h=C!==null&&!C.payments_ready&&!ut(),g=C!==null&&!C.active,_=C!==null&&C.purchasable===!1,v=C!==null&&Ae(C),R=C!==null?be(C):[],O=t!==void 0?R.find(E=>E.id===t)??null:!v&&R.length===1?R[0]:null,D=v&&!O,V=O!==null&&!O.in_stock,B=n??void 0,T=C?.subscription??null,M=T!==null&&T.required&&!T.ready,q=T!==null&&T.required&&T.ready&&B===void 0,te=!!S||b||!C||h||g||_||M||q||D||V||s,$;s?$=(0,H.jsxs)(H.Fragment,{children:[p&&(0,H.jsx)(Ht,{}),"Processing\u2026"]}):b?$=(0,H.jsxs)(H.Fragment,{children:[p&&(0,H.jsx)(Ht,{}),L??"Buy now"]}):h?$="Payments not set up":g||_?$="Unavailable":M?$="Currently unavailable":q?$="Select a plan":D?$="Select options":V?$="Out of stock":L!==void 0?$=L:B!==void 0?$="Subscribe":$="Buy now";let Y=d??a;return(0,H.jsxs)(H.Fragment,{children:[(0,H.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}:{};P({productId:e,variantId:t,quantity:B!==void 0?void 0:r,amount:o,planId:B,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,...E})},children:$}),Y&&(0,H.jsxs)("div",{role:"alert",className:k,style:k?void 0:$n,children:[Y,C===null&&!b&&a!==null&&(0,H.jsx)("button",{type:"button",onClick:w,style:Dn,children:"Tap to retry"})]})]})}var _e=require("react");var Z=require("react/jsx-runtime"),Bn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Fn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},zn=1500;function jn(){return(0,Z.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,Z.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,Z.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,Z.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Kn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Qt({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:m,errorClassName:y,spinner:u=!0,children:S}){let{product:c,loading:x,error:k,refresh:p}=ve(e,{apiUrl:o}),{add:L}=ye(),[C,b]=(0,_e.useState)(!1),[a,w]=(0,_e.useState)(!1),P=(0,_e.useRef)(void 0);(0,_e.useEffect)(()=>()=>{P.current&&clearTimeout(P.current)},[]);let s=c!==null&&!c.payments_ready&&!ut(),d=c!==null&&!c.active,f=c!==null&&c.purchasable===!1,h=c!==null&&!x&&be(c).length===0,g=c!==null&&c.allow_custom_amount,_=c!==null&&c.subscription?.required===!0,v=c!==null&&Ae(c),R=c!==null?be(c):[],O=t!==void 0?R.find($=>$.id===t)??null:r!==void 0&&v?ke(R,r):!v&&R.length===1?R[0]:null,D=c!==null&&!h&&!O,V=O!==null&&!O.in_stock,B=!!i||x||!c||s||d||f||h||g||_||D||V,T=()=>{if(!c||!O)return;let $=r??Kn(O);if(!L({productId:e,variantId:O.id,quantity:n,selection:$,display:{name:c.name,variantTitle:O.title,image:Oe(c,$)[0]??null}}).ok){b(!0);return}b(!1),w(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>w(!1),zn)},M;x?M=(0,Z.jsxs)(Z.Fragment,{children:[u&&(0,Z.jsx)(jn,{}),S??"Add to cart"]}):s?M="Payments not set up":d||f||h||g?M="Unavailable":_?M="Subscription only":D?M="Select options":V?M="Out of stock":a?M="Added to cart":S!==void 0?M=S:M="Add to cart";let q=C?"Your cart is full \u2014 remove an item before adding another.":k;return(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)("button",{type:"button",className:l,style:m,disabled:B,"data-added":a?"true":void 0,onClick:T,children:M}),q&&(0,Z.jsxs)("div",{role:"alert",className:y,style:y?void 0:Bn,children:[q,c===null&&!x&&k!==null&&!C&&(0,Z.jsx)("button",{type:"button",onClick:p,style:Fn,children:"Tap to retry"})]})]})}var J=require("react/jsx-runtime"),Zt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function Xt(){return(0,J.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,J.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,J.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,J.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function en({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:m,style:y,errorClassName:u,spinner:S=!0,children:c}){let{items:x,hydrated:k}=ye(),{lines:p}=ot({apiUrl:e}),{startCheckout:L,loading:C,error:b,conflicts:a}=st({apiUrl:e}),w=k&&x.length===0,P=p.some(h=>h.status==="unavailable"),s=!!l||!k||w||P||C,d;C?d=(0,J.jsxs)(J.Fragment,{children:[S&&(0,J.jsx)(Xt,{}),"Processing\u2026"]}):k?w?d="Cart is empty":P?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=(0,J.jsxs)(J.Fragment,{children:[S&&(0,J.jsx)(Xt,{}),c??"Checkout"]});let f=a?Object.keys(a).length:0;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)("button",{type:"button",className:m,style:y,disabled:s,onClick:()=>L(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),f>0&&(0,J.jsx)("div",{role:"alert",className:u,style:u?void 0:Zt,children:f===1?"An item in your cart changed \u2014 please review your cart and try again.":`${f} items in your cart changed \u2014 please review your cart and try again.`}),b&&(0,J.jsx)("div",{role:"alert",className:u,style:u?void 0:Zt,children:b})]})}var ue=require("react");var A=require("react/jsx-runtime"),Wn={fontSize:"1.5rem",lineHeight:1.25,fontWeight:600,margin:"0 0 0.5rem"},xe={color:"#6b7280",fontSize:"0.875rem"},Yn={display:"inline-block",padding:"0.125rem 0.5rem",margin:"0 0 1rem",borderRadius:9999,border:"1px solid #e5e7eb",background:"#f9fafb",color:"#6b7280",fontSize:"0.75rem"},Hn={textAlign:"left",border:"1px solid #e5e7eb",borderRadius:8,overflow:"hidden",margin:"1rem 0"},Jn={listStyle:"none",margin:0,padding:0},Gn={display:"flex",alignItems:"center",gap:"0.75rem",padding:"0.75rem"},tn={width:56,height:56,flex:"0 0 auto",borderRadius:6,border:"1px solid #f3f4f6",background:"#f3f4f6",objectFit:"cover"},Qn={flex:"1 1 auto",minWidth:0},Zn={flex:"0 0 auto",whiteSpace:"nowrap"},Xn={padding:"0.75rem",borderTop:"1px solid #e5e7eb",background:"#f9fafb"},wt={display:"flex",justifyContent:"space-between",gap:"1rem",padding:"0.125rem 0"},er={...wt,fontWeight:600,marginTop:"0.5rem",paddingTop:"0.5rem",borderTop:"1px solid #e5e7eb"},tr={display:"inline-block",padding:"0.625rem 1.25rem",borderRadius:8,background:"#111827",color:"#ffffff",textDecoration:"none",fontWeight:600},Ct="af_order_confirmation_session",nr=1800*1e3;function nn({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:m=1500,renderNoSession:y,renderPending:u,renderPaid:S,renderFailed:c}){let[x,k]=(0,ue.useState)(n),[p,L]=(0,ue.useState)(null),[C,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),f=d.searchParams.get("session_id");if(f){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(Ct,JSON.stringify({id:f,ts:Date.now()}))}catch{}}else try{let h=sessionStorage.getItem(Ct);if(h){let g=JSON.parse(h);typeof g.id=="string"&&typeof g.ts=="number"&&Date.now()-g.ts<=nr?f=g.id:sessionStorage.removeItem(Ct)}}catch{}a.current=f,k(f)},[n]),(0,ue.useEffect)(()=>{if(!x)return;let d=!1,f,h=Date.now(),g=async()=>{try{let _=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(_.ok){let v=await _.json();if(d||(L(v),v.status!=="pending"))return}}catch{}if(!d){if(Date.now()-h>=i){b(!0);return}f=setTimeout(g,o)}};return g(),()=>{d=!0,f&&clearTimeout(f)}},[x,e,o,i]);let w=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),P=(0,ue.useRef)(!1);(0,ue.useEffect)(()=>{if(!x||p===null||P.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(P.current=!0,!Nt(x)))return;let f=(p.line_items??[]).filter(h=>typeof h.variant_id=="string"&&h.variant_id.length>0).map(h=>({variantId:h.variant_id,quantity:h.quantity}));f.length>0&&Et(f)},[x,p]);let s=w&&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},m);return()=>clearTimeout(d)},[s,l,m]),x===void 0)return null;if(x===null)return y?(0,A.jsx)(A.Fragment,{children:y()}):(0,A.jsxs)("div",{className:t,style:r,children:[(0,A.jsx)("h2",{children:"Thank you for your order!"}),(0,A.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,A.jsx)(A.Fragment,{children:u({timedOut:C})}):(0,A.jsx)("div",{className:t,style:r,role:"status",children:(0,A.jsx)("p",{children:C?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(w){if(S)return(0,A.jsx)(A.Fragment,{children:S(p)});let{fulfillment:d}=p,f=p.currency,h=p.amount_total!==void 0&&f?z(p.amount_total,f):null,g=p.line_items??[],_=g.some(V=>!!V.image_url),v=p.tax_behavior==="exclusive"&&typeof p.tax_total=="number"&&p.tax_total>0&&!!f,R=typeof p.shipping_total=="number"&&!!f,O=d.files??[],D=O.length===0?d.download_url:void 0;return(0,A.jsxs)("div",{className:t,style:r,children:[(0,A.jsx)("h2",{style:Wn,children:"Thank you for your purchase!"}),p.is_test&&(0,A.jsxs)("p",{style:Yn,children:[(0,A.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected. Test orders only happen in the editor."]}),(g.length>0||h)&&(0,A.jsxs)("div",{style:Hn,children:[g.length>0&&(0,A.jsx)("ul",{style:Jn,children:g.map((V,B)=>{let T=typeof V.unit_amount=="number"&&f?z(V.unit_amount*V.quantity,f):null;return(0,A.jsxs)("li",{style:{...Gn,borderBottom:B<g.length-1?"1px solid #f3f4f6":void 0,opacity:V.refunded?.6:void 0},children:[_&&(V.image_url?(0,A.jsx)("img",{src:V.image_url,alt:"",width:56,height:56,style:tn}):(0,A.jsx)("div",{style:tn,"aria-hidden":"true"})),(0,A.jsxs)("div",{style:Qn,children:[(0,A.jsx)("div",{children:V.name}),V.quantity>1&&(0,A.jsxs)("div",{style:xe,children:["Qty ",V.quantity]}),V.refunded&&(0,A.jsx)("div",{style:xe,children:(0,A.jsx)("em",{children:V.refund_reason==="oversold"?"Sold out and refunded \u2014 check your email for details":"Refunded"})})]}),T&&(0,A.jsx)("div",{style:Zn,children:T})]},B)})}),h&&(0,A.jsxs)("div",{style:Xn,children:[R&&(0,A.jsxs)("div",{style:wt,children:[(0,A.jsx)("span",{style:xe,children:"Shipping"}),(0,A.jsx)("span",{children:p.shipping_total===0?"Free":z(p.shipping_total,f)})]}),v&&(0,A.jsxs)("div",{style:wt,children:[(0,A.jsx)("span",{style:xe,children:"Tax"}),(0,A.jsx)("span",{children:z(p.tax_total,f)})]}),(0,A.jsxs)("div",{style:er,children:[(0,A.jsx)("span",{children:"Total paid"}),(0,A.jsx)("span",{children:h})]})]})]}),p.source==="subscription"&&p.subscription&&(0,A.jsxs)(A.Fragment,{children:[(0,A.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,A.jsxs)("p",{children:["You can view, update, or cancel it any time on"," ",(0,A.jsx)("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),O.length>0&&(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)("p",{children:"Your downloads:"}),(0,A.jsx)("ul",{children:O.map((V,B)=>(0,A.jsx)("li",{children:(0,A.jsx)("a",{href:V.download_url,children:V.name})},B))})]}),D&&(0,A.jsx)("p",{children:(0,A.jsx)("a",{href:D,style:tr,children:"Download your file"})}),s?(0,A.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,A.jsx)("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?(0,A.jsx)("p",{children:(0,A.jsx)("a",{href:d.redirect_url,children:"Continue to your content"})}):null,O.length===0&&!D&&!d.redirect_url&&(0,A.jsx)("p",{style:xe,children:"A confirmation email is on its way to you."}),typeof p.order_number=="number"?(0,A.jsxs)("p",{style:xe,children:["Order ",(0,A.jsxs)("strong",{children:["#",p.order_number]})," \u2014 keep this if you ever need help with your order."]}):p.order_id?(0,A.jsxs)("p",{style:xe,children:["Order reference: ",(0,A.jsx)("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]}):null]})}return c?(0,A.jsx)(A.Fragment,{children:c(p)}):(0,A.jsx)("div",{className:t,style:r,children:(0,A.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 lt=require("react");var Se=require("react/jsx-runtime");function _t(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 Pt(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var rr={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},ir={display:"block",width:"100%",textAlign:"left",padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},or={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600};function rn({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:m,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:S,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,L=k?.ready===!0,C=[...k?.plans??[]].sort((v,R)=>v.position-R.position),[b,a]=(0,lt.useState)(null),w=o!==void 0,P=w?o:b,s=C.map(v=>v.id).join("|"),d=C.length>0?C[0].id:null;if((0,lt.useEffect)(()=>{if(!(!p||!L)&&!(P!==null&&C.some(v=>v.id===P))){if(d===null){if(P===null)return;w||a(null),i?.(null);return}w||a(d),i?.(d)}},[p,L,d,s,P,w]),!k)return null;if(!L)return p?x?(0,Se.jsx)(Se.Fragment,{children:x()}):(0,Se.jsx)("div",{className:l,style:m,"data-state":"unavailable",children:(0,Se.jsx)("p",{children:"This product is currently unavailable."})}):null;if(C.length===0)return null;let f=e?.base_currency!==void 0&&e?.base_currency!==null,h=r!==void 0?r:f?null:e?.unit_amount??null,g=n??e?.base_currency??e?.currency??"usd",_=[];if(!p){let v=h;_.push({plan:null,selected:P===null,price:v,priceLabel:v!==null?z(v,g):null,label:"One-time purchase",select:()=>{w||a(null),i?.(null)}})}for(let v of C){let R=v.unit_amount!==null?v.unit_amount:h!==null?_t(h,v):null,O=R!==null?z(R,g):null,D=v.title&&v.title.trim().length>0?v.title.trim():`Subscribe ${Pt(v)}`,V=O?`${D} \u2014 ${O} ${Pt(v)}`:`${D} \u2014 billed ${Pt(v)}`;_.push({plan:v,selected:P===v.id,price:R,priceLabel:O,label:V,select:()=>{w||a(v.id),i?.(v.id)}})}return(0,Se.jsx)("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?m:{...rr,...m},children:_.map(v=>{if(c)return(0,Se.jsx)("span",{style:{display:"contents"},children:c(v)},v.plan?.id??"one-time");let R=v.selected;return(0,Se.jsx)("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":v.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...ir,...R?or:{}},onClick:v.select,children:v.plan===null&&S!==void 0?S:v.plan===null?v.priceLabel?`One-time purchase \u2014 ${v.priceLabel}`:"One-time purchase":v.label},v.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 m=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:m,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:m,error:y}}}function on(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function Be(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 sr=1500;function sn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function ar(e,t){return e.requestId===t}function ur(e,t){return typeof window>"u"||!sn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;if(y?.type==="aifeatures:preview-session-ack"&&ar(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let S=y.customer;typeof S.email=="string"&&(u={email:S.email,name:typeof S.name=="string"?S.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}),sr);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ee(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,X.useState)(()=>Pe()),[o,i]=(0,X.useState)(null),[l,m]=(0,X.useState)(!1),[y,u]=(0,X.useState)(!1),S=(0,X.useRef)(void 0);(0,X.useEffect)(()=>qt(()=>{let b=Pe();n(b),i(b===null?a=>Mt()??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 P=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 tt({token:a.data.token,customer:P}),n({token:a.data.token,customer:P}),i(null),m(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(m(!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")&&S.current===void 0){if(!x){S.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())),S.current=a,a&&c(a)}},[c,x]);let k=(0,X.useCallback)(async b=>{if(typeof window<"u"&&sn(window)){let w=await ur(b,De());if(w.claimed){if(w.token!==null){let P=w.customer??{email:b,name:null};return tt({token:w.token,customer:P}),n({token:w.token,customer:P}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:w.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"?(m(!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]),L=(0,X.useCallback)(async()=>{let b=Pe();if(!b)return;let a=await de(t,"/v1/account/me",{token:b.token}),w=()=>Pe()?.token===b.token;if(a.ok){if(!w())return;let P=a.data.customer??b.customer;tt({token:b.token,customer:P}),n({token:b.token,customer:P}),m(!1);return}if(a.failure.kind==="unauthorized"){if(!w())return;me("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){m(!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:L}}var K=require("react");var le=require("react");var F=require("react/jsx-runtime"),xt={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},lr={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},cr={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},an={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Ue={margin:0},dr={color:"#b91c1c",margin:0};function Fe({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:m}){let y=Ee({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[S,c]=(0,le.useState)(""),[x,k]=(0,le.useState)("form"),[p,L]=(0,le.useState)(!1),[C,b]=(0,le.useState)(null),[a,w]=(0,le.useState)(null),[P,s]=(0,le.useState)(!1),d=(0,le.useRef)(void 0),f=(0,le.useRef)(!1);(0,le.useEffect)(()=>()=>{d.current&&clearTimeout(d.current)},[]);let h=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},g=async()=>{let R=S.trim();if(!R||p||f.current)return;f.current=!0,L(!0),b(null),w(null);let O=await u.login(R);if(f.current=!1,L(!1),O.ok){if(O.via==="preview")return;k("sent"),h();return}O.code!=="unavailable"&&(b(O.code==="rate_limited"?"rate_limited":"error"),w(O.error))};if(u.status==="unavailable")return m?(0,F.jsx)(F.Fragment,{children:m()}):(0,F.jsx)("div",{className:n,style:n?o:{...xt,...o},"data-state":"unavailable",children:(0,F.jsx)("p",{style:Ue,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:S.trim(),canResend:P,resend:()=>{g(),h()},submitting:p,reset:()=>k("form")};return l?(0,F.jsx)(F.Fragment,{children:l(R)}):(0,F.jsxs)("div",{className:n,style:n?o:{...xt,...o},"data-state":"sent",children:[(0,F.jsxs)("p",{style:Ue,children:["Check your email \u2014 if ",(0,F.jsx)("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),P?(0,F.jsxs)("p",{style:Ue,children:["Didn't get it?"," ",(0,F.jsx)("button",{type:"button",style:an,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",(0,F.jsx)("button",{type:"button",style:an,onClick:R.reset,children:"use a different email"}),"."]}):(0,F.jsx)("p",{style:Ue,children:"It can take a minute to arrive."})]})}let _={email:S,setEmail:c,submit:()=>void g(),submitting:p,errorKind:C,errorMessage:a,reason:u.reason};if(i)return(0,F.jsx)(F.Fragment,{children:i(_)});let v=R=>{R.preventDefault(),_.submit()};return(0,F.jsxs)("form",{className:n,style:n?o:{...xt,...o},onSubmit:v,"data-state":"form",children:[u.reason==="session_expired"&&(0,F.jsx)("p",{style:Ue,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&(0,F.jsx)("p",{style:Ue,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),(0,F.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[(0,F.jsx)("span",{children:"Email address"}),(0,F.jsx)("input",{type:"email",value:S,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:lr})]}),(0,F.jsx)("button",{type:"submit",style:cr,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&(0,F.jsx)("p",{style:dr,role:"alert",children:C==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}var W=require("react/jsx-runtime"),pr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},fr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},ze={color:"#6b7280",fontSize:"0.875rem"};function mr(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 ct({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?(0,W.jsx)(W.Fragment,{children:o()}):(0,W.jsxs)("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&(0,W.jsx)("h3",{children:n}),(0,W.jsx)("p",{style:ze,children:"No orders yet."})]}):(0,W.jsxs)("div",{className:t,style:r,children:[n!==null&&(0,W.jsx)("h3",{children:n}),(0,W.jsx)("ul",{style:t?void 0:pr,children:e.map(l=>{if(i)return(0,W.jsx)("li",{style:{display:"contents"},children:i(l)},l.id);let m=Be(l.created_at),y=mr(l);return(0,W.jsxs)("li",{style:t?void 0:fr,children:[(0,W.jsxs)("div",{children:[l.order_number!==null&&(0,W.jsxs)("strong",{children:["Order #",l.order_number]})," ",m&&(0,W.jsx)("span",{style:ze,children:m})," ",l.source==="subscription"&&(0,W.jsx)("span",{style:ze,children:"\xB7 subscription"}),y&&(0,W.jsxs)("span",{style:ze,children:[" \xB7 ",y]})]}),l.line_items.length>0&&(0,W.jsx)("div",{style:ze,children:l.line_items.map(u=>u.name?`${u.quantity&&u.quantity>1?`${u.quantity} \xD7 `:""}${u.name}`:null).filter(Boolean).join(", ")}),(0,W.jsx)("div",{children:z(l.amount_total,l.currency)})]},l.id)})})]})}var ee=require("react");var U=require("react/jsx-runtime"),gr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},yr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},Ne={color:"#6b7280",fontSize:"0.875rem"},br={color:"#b91c1c",fontSize:"0.875rem",margin:0},hr={color:"#065f46",fontSize:"0.875rem",margin:0},Rt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Re={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},ln={...Re,border:"1px solid #111827",background:"#111827",color:"white"},Sr={...Re,border:"1px solid #b91c1c",color:"#b91c1c"},vr={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},un={panel:"none",mutation:null,portalRefused:!1};function kr(e){let t=Be(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 Cr({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=(0,ee.useState)(e?.name??""),[m,y]=(0,ee.useState)(o?.line1??""),[u,S]=(0,ee.useState)(o?.line2??""),[c,x]=(0,ee.useState)(o?.city??""),[k,p]=(0,ee.useState)(o?.state??""),[L,C]=(0,ee.useState)(o?.postal_code??""),[b,a]=(0,ee.useState)(o?.country??""),w=(P,s,d,f)=>(0,U.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[(0,U.jsx)("span",{children:P}),(0,U.jsx)("input",{style:vr,value:s,onChange:h=>d(h.target.value),required:f?.required,maxLength:f?.maxLength})]});return(0,U.jsxs)("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:P=>{P.preventDefault(),r({name:i.trim()||null,address:{line1:m.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:L.trim()||null,country:b.trim().toUpperCase()}})},children:[w("Name",i,l),w("Address line 1",m,y,{required:!0}),w("Address line 2",u,S),w("City",c,x),w("State / region",k,p),w("Postal code",L,C),w("Country (2-letter code)",b,a,{required:!0,maxLength:2}),(0,U.jsxs)("div",{style:Rt,children:[(0,U.jsx)("button",{type:"submit",style:ln,disabled:t,children:t?"Saving\u2026":"Save address"}),(0,U.jsx)("button",{type:"button",style:Re,onClick:n,disabled:t,children:"Cancel"})]})]})}function je({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:m,heading:y="Your subscriptions",renderEmpty:u,renderRow:S}){let[c,x]=(0,ee.useState)(t),[k,p]=(0,ee.useState)({}),L=(0,ee.useRef)(new Set);(0,ee.useEffect)(()=>{x(t)},[t]),(0,ee.useEffect)(()=>{let s=d=>{d.persisted&&(L.current.clear(),p(f=>{let h=!1,g={};for(let[_,v]of Object.entries(f))v.mutation?.phase==="pending"?(g[_]={...v,mutation:null},h=!0):g[_]=v;return h?g:f}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let C=(s,d)=>p(f=>({...f,[s]:{...f[s]??un,...d}})),b=s=>{x(d=>d.map(f=>f.id===s.id?s:f)),i?.(s)},a=async(s,d,f,h)=>{if(L.current.has(s.id))return{ok:!1};L.current.add(s.id);try{C(s.id,{mutation:{kind:d,phase:"pending"}});let g=await de(e,f,{method:"POST",token:r.token,body:h??{}});if(g.ok)return{ok:!0,data:g.data};let{failure:_}=g;return _.kind==="unauthorized"?(n?.({code:_.code,error:_.error}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="unavailable"?(o?.(),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="ended"?(b({...s,ended:!0,status:"canceled"}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="portal_unavailable"?(C(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(C(s.id,{mutation:{kind:d,phase:"error",error:_.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":_.error}}),{ok:!1})}finally{L.current.delete(s.id)}},w=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"},P=s=>{let d=k[s.id]??un,f=w(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>C(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>C(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let h=await a(s,"cancel",f.cancel);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:f.reactivate!==null,reactivate:()=>{f.reactivate&&(async()=>{let h=await a(s,"reactivate",f.reactivate);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{f.address&&C(s.id,{panel:"address",mutation:null})},saveAddress:h=>{f.address&&(async()=>{let g=await a(s,"address",f.address,{shipping_address:h});if(g.ok){let _=g.data.subscription;_&&b(_),C(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let h=await a(s,"portal",f.portal);h.ok&&typeof h.data.url=="string"?window.location.href=h.data.url:h.ok&&C(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:m,"data-state":"empty",children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("p",{style:Ne,children:"No subscriptions."})]}):(0,U.jsxs)("div",{className:l,style:m,children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("ul",{style:l?void 0:gr,children:c.map(s=>{let d=P(s);return S?(0,U.jsx)("li",{style:{display:"contents"},children:S(d)},s.id):(0,U.jsx)("li",{style:l?void 0:yr,"data-status":s.status,"data-ended":s.ended||void 0,children:(0,U.jsx)(wr,{ctx:d})},s.id)})})]})}function wr({ctx:e}){let t=e.subscription,r=kr(t),n=Be(t.current_period_end),o=`${z(t.current_amount,t.currency)} ${on(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:Ne,children:["\xB7 ",o]}),t.is_test&&(0,U.jsx)("span",{style:Ne,children:" \xB7 test"})]}),(0,U.jsx)("div",{style:r.tone==="warn"?void 0:Ne,children:r.text}),t.ended?(0,U.jsx)("p",{style:Ne,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:Rt,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:Re,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?(0,U.jsx)(Cr,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):(0,U.jsxs)("div",{style:Rt,children:[t.cancel_at_period_end?e.reactivateAvailable?(0,U.jsx)("button",{type:"button",style:ln,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):(0,U.jsx)("span",{style:Ne,children:"To keep this subscription, sign in with your email address on this page."}):(0,U.jsx)("button",{type:"button",style:Re,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:Re,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&(0,U.jsx)("button",{type:"button",style:Re,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&(0,U.jsx)("p",{style:br,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&(0,U.jsx)("p",{style:hr,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 I=require("react/jsx-runtime"),Pr={display:"flex",flexDirection:"column",gap:"1.25rem"},cn={color:"#6b7280",fontSize:"0.875rem"},_r={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},dn={color:"#b91c1c"},dt={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function pn({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:m,renderHeader:y,renderPmBanner:u,renderManageExpired:S}){let c=Ee({apiUrl:e}),x=(0,K.useRef)(void 0),[k,p]=(0,K.useState)(null),[L,C]=(0,K.useState)(!1);(0,K.useEffect)(()=>{if(!(typeof window>"u")){if(x.current===void 0){let N=new URL(window.location.href),E=N.searchParams.get("manage_code"),j=N.searchParams.get("pm");(E!==null||j!==null)&&(N.searchParams.delete("manage_code"),N.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",N.toString())),x.current={manageCode:E,pmUpdated:j==="updated"}}p(x.current.manageCode),C(x.current.pmUpdated)}},[]);let[b,a]=(0,K.useState)(null),w=(0,K.useRef)(!1),P=(0,K.useRef)(0),s=(0,K.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,K.useEffect)(()=>{!k||w.current||(w.current=!0,s(k))},[k,s]);let d=(0,K.useCallback)(async()=>{let N=b;if(!N||N.phase!=="active")return;let E=++P.current,j=await de(e,"/v1/account/manage/subscription",{token:N.token});E===P.current&&(j.ok&&j.data.subscription?a({phase:"active",token:N.token,sub:j.data.subscription,siteName:typeof j.data.site?.name=="string"?j.data.site.name:N.siteName}):!j.ok&&j.failure.kind==="unauthorized"?a({phase:"expired"}):!j.ok&&j.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[f,h]=(0,K.useState)({phase:"loading"}),[g,_]=(0,K.useState)(0),v=g>0,R=(0,K.useRef)(0),O=c.token,D=(0,K.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){h({phase:"ready",data:E.data});return}if(E.failure.kind==="unauthorized"){me("session_expired");return}if(E.failure.kind==="unavailable"){me();return}h({phase:"error",error:E.failure.error})}},[e,O]);(0,K.useEffect)(()=>{!O||k||(h({phase:"loading"}),D())},[O,k,D]);let V=(0,K.useCallback)(async()=>{_(N=>N+1);try{b&&b.phase==="active"?await d():await D()}finally{_(N=>N-1)}},[b,d,D]),B=(0,K.useCallback)(N=>{R.current++,P.current++,a(E=>E&&E.phase==="active"&&E.sub.id===N.id?{...E,sub:N}:E),h(E=>E.phase==="ready"?{phase:"ready",data:{...E.data,subscriptions:E.data.subscriptions.map(j=>j.id===N.id?N:j)}}:E)},[]),T=t?r:{...Pr,...r},M=N=>{if(!L)return null;let j={state:N.some(ie=>!ie.ended&&(ie.status==="past_due"||ie.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void V(),checking:v};return u?u(j):(0,I.jsx)("div",{style:_r,role:"status","data-pm-state":j.state,children:j.state==="retrying"?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),(0,I.jsx)("p",{style:{margin:"0.375rem 0 0"},children:(0,I.jsx)("button",{type:"button",style:dt,onClick:j.checkAgain,disabled:v,children:v?"Checking\u2026":"Check again"})})]}):(0,I.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,I.jsx)(I.Fragment,{children:i()}):(0,I.jsx)("div",{className:t,style:T,role:"status",children:(0,I.jsx)("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?(0,I.jsxs)("div",{className:t,style:T,children:[M([b.sub]),(0,I.jsx)(je,{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,I.jsx)("div",{className:t,style:T,"data-state":"unavailable",children:(0,I.jsx)("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?(0,I.jsxs)("div",{className:t,style:T,children:[(0,I.jsx)("p",{style:dn,role:"alert",children:b.error}),(0,I.jsx)("p",{children:(0,I.jsx)("button",{type:"button",style:dt,onClick:()=>s(k),children:"Try again"})})]}):(0,I.jsxs)("div",{className:t,style:T,"data-state":"manage-expired",children:[S?S():(0,I.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,I.jsx)(Fe,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?(0,I.jsx)(I.Fragment,{children:i()}):(0,I.jsx)("div",{className:t,style:T,role:"status",children:(0,I.jsx)("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return(0,I.jsx)("div",{className:t,style:T,children:(0,I.jsx)(Fe,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(f.phase==="loading")return i?(0,I.jsx)(I.Fragment,{children:i()}):(0,I.jsx)("div",{className:t,style:T,role:"status",children:(0,I.jsx)("p",{children:"Loading your account\u2026"})});if(f.phase==="error")return l?(0,I.jsx)(I.Fragment,{children:l({error:f.error,retry:()=>void D()})}):(0,I.jsxs)("div",{className:t,style:T,children:[(0,I.jsxs)("p",{style:dn,role:"alert",children:["We couldn't load your account \u2014 ",f.error]}),(0,I.jsx)("p",{children:(0,I.jsx)("button",{type:"button",style:dt,onClick:()=>void D(),children:"Try again"})})]});let{data:q}=f,te=q.customer??c.customer??{email:"",name:null},$=()=>void c.logout(),Y=q.orders.length===0&&q.subscriptions.length===0;return(0,I.jsxs)("div",{className:t,style:T,children:[y?y({customer:te,site:q.site??null,signOut:$}):(0,I.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("h2",{style:{margin:0},children:"Your account"}),(0,I.jsxs)("p",{style:{...cn,margin:0},children:["Signed in as ",te.email]})]}),(0,I.jsx)("button",{type:"button",style:dt,onClick:$,children:"Sign out"})]}),M(q.subscriptions),Y?m?m():(0,I.jsxs)("p",{style:cn,children:["Nothing here yet \u2014 orders and subscriptions for ",te.email," ","will show up on this page."]}):(0,I.jsxs)(I.Fragment,{children:[q.subscriptions.length>0&&(0,I.jsx)(je,{apiUrl:e,subscriptions:q.subscriptions,auth:{kind:"session",token:O},onSubscriptionChange:B,onAuthError:()=>me("session_expired"),onUnavailable:()=>me()}),(0,I.jsx)(ct,{orders:q.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.js CHANGED
@@ -1,2 +1,2 @@
1
1
  "use client";
2
- import{useState as Dt,useEffect as Nn}from"react";import{Turnstile as Mn}from"@marsidev/react-turnstile";import{jsx as Bt}from"react/jsx-runtime";function Vn({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=Dt(null),[m,y]=Dt(!0);return Nn(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(u=>u.json()).then(u=>{l(u.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),m||!i?null:Bt("div",{className:o,children:Bt(Mn,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}import{useCallback as qn,useEffect as $n,useRef as Dn,useState as De}from"react";var Be=[1e3,3e3];function ue(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=De(null),[l,m]=De(!0),[y,u]=De(null),[S,c]=De(0),x=Dn(e);$n(()=>{let p=!1,T;m(!0),u(null),x.current!==e&&(x.current=e,i(null));let C=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let w=await a.json().catch(()=>null);if(!p)if(!a.ok||!w){if(a.status>=500&&b<Be.length){T=setTimeout(()=>C(b+1),Be[b]);return}u(w?.error??`Request failed (${a.status})`),i(null),m(!1)}else i(w),m(!1)}).catch(a=>{if(!p){if(b<Be.length){T=setTimeout(()=>C(b+1),Be[b]);return}u(a instanceof Error?a.message:"Failed to load product"),m(!1)}})};return C(0),()=>{p=!0,T&&clearTimeout(T)}},[e,r,n,S]);let k=qn(()=>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 oe(e){return e.variants??[]}function me(e){return e.options??[]}function xe(e){return me(e).length>0}function Fe(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 at(e,t,r,n){return e.some(o=>{let i=Fe(o);if(i[r]!==n)return!1;for(let[l,m]of Object.entries(t))if(l!==r&&i[l]!==m)return!1;return!0})}function ut(e,t,r){return e.some(n=>Fe(n)[t]===r)}function lt(e,t,r,n){let o={[r]:n};for(let[l,m]of Object.entries(t)){if(l===r)continue;e.some(u=>{let S=Fe(u);return S[r]===n&&S[l]===m})&&(o[l]=m)}return e.some(l=>{let m=Fe(l);return Object.entries(o).every(([y,u])=>m[y]===u)})?o:{[r]:n}}function ct(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 zt(e,t){let r={};for(let n of me(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 dt(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 me(e)){let l=ne(i.title);if(l.length===0)continue;let m=n.get(l);if(m===void 0)continue;let y=ne(m);if(y.length===0)continue;let u=i.values.find(S=>ne(S.value)===y);u&&(o[i.id]=u.id)}return o}function ze(e,t){let r={};for(let[n,o]of Object.entries(zt(e,t))){let i=ne(n),l=ne(o);i.length===0||l.length===0||(r[i]=l)}return r}function Re(e,t){let r=[];for(let n of me(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 pt(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of me(e)){let o=ne(n.title);o.length!==0&&r.searchParams.delete(o)}for(let[n,o]of Object.entries(ze(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}import{useCallback as jn,useEffect as Zt,useRef as Xt,useState as bt}from"react";var mt="aifeatures_cart",gt="aifeatures_market",jt="aifeatures_cart_cleared";var ft="aifeatures:cart-storage",Ae=new Map;function Oe(e){if(Ae.has(e))return Ae.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function ge(e,t){if(typeof window>"u"){Ae.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Ae.delete(e)}catch{Ae.set(e,t)}Bn(e)}function Bn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(ft,{detail:{key:e}}))}catch{}}function je(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(ft,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(ft,n)}}function Fn(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,m]of Object.entries(t.selection))typeof m=="string"&&(n[l]=m);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=Oe(mt);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=Fn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function X(e){ge(mt,JSON.stringify(e))}function Kt(e){return je(mt,e)}function Wt(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 H(){let e=Oe(gt);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function Yt(e){ge(gt,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function ye(e){return je(gt,e)}function Ht(e){let t=[],r=Oe(jt);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)),ge(jt,JSON.stringify(t)),!0)}var Ke="aifeatures_session",yt=null;function Jt(){return yt}function zn(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=Oe(Ke);if(!e)return null;try{return zn(JSON.parse(e))}catch{return null}}function Gt(){return ce()?.token??null}function We(e){yt=null,ge(Ke,JSON.stringify(e))}function ee(e){yt=e??null,ge(Ke,null)}function Qt(e){return je(Ke,e)}var Kn=1500;function Te(){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 ht(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;y?.type==="aifeatures:test-checkout-ack"&&Ye(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),Kn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function en(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 St(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=bt(!1),[o,i]=bt(null),[l,m]=bt(null),y=Xt(!1),u=Xt(null);return Zt(()=>{let c=x=>{x.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",c),()=>window.removeEventListener("pageshow",c)},[]),Zt(()=>{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:jn(async({productId:c,variantId:x,quantity:k,amount:p,metadata:T,successUrl:C,cancelUrl:b,customerEmail:a,planId:w,expectedUnitAmount:P,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),m(null),w!==void 0){let d=Gt();if(d)try{let f=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:w,...x!==void 0?{variant_id:x}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.text().catch(()=>""),g=null;try{g=h?JSON.parse(h):null}catch{g=null}if(f.ok){if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}en(g.url)==="stayed"&&(y.current=!1,n(!1));return}let _=f.status===404&&h.trim()==="";if(f.status===401||_)ee();else{i(g?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}}catch(f){i(f instanceof Error?f.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=w===void 0?H():null,f=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&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{plan_id:w}:{},...T!==void 0?{metadata:T}:{},...a!==void 0?{customer_email:a}:{},...P!==void 0&&s!==void 0&&w===void 0?{expected_unit_amount:P,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.json().catch(()=>null);if(!f.ok){if(h?.error==="price_changed"&&typeof h.current_unit_amount=="number"&&typeof h.currency=="string"){m({currentUnitAmount:h.current_unit_amount,currency:h.currency}),i(`The price has changed to ${z(h.current_unit_amount,h.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(h?.code==="preview_domain"){let g=Te();if(u.current=g,await ht({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{planId:w}:{},...a!==void 0?{customerEmail:a}:{},...T!==void 0?{metadata:T}:{}},g))return;u.current=null}i(h?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}en(h.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 He,useEffect as Wn,useState as tn}from"react";var rn=20;function nn(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function re(){let[e,t]=tn([]),[r,n]=tn(!1);Wn(()=>{let u=()=>t(se());return u(),n(!0),Kt(u)},[]);let o=He(u=>{let S=se(),c=nn(u.quantity);return S.find(k=>k.variantId===u.variantId)?(X(S.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):S.length>=rn?{ok:!1,reason:"cart_full"}:(X([...S,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=He(u=>{X(se().filter(S=>S.variantId!==u))},[]),l=He((u,S)=>{let c=se();if(S<=0){X(c.filter(k=>k.variantId!==u));return}let x=nn(S);X(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),m=He(()=>{X([])},[]),y=e.reduce((u,S)=>u+S.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:m}}import{useCallback as Yn,useEffect as on,useMemo as vt,useRef as Hn,useState as Le}from"react";var Je={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},Jn={...Je,inStock:!0,status:"error"};function Gn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function kt(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=re(),[o,i]=Le({}),[l,m]=Le({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=Le(!0),[S,c]=Le(null),[x,k]=Le(0),p=Hn(new Set),T=vt(()=>JSON.stringify(r.map(P=>[P.productId,P.variantId,P.selection])),[r]),C=Yn(()=>k(P=>P+1),[]);on(()=>ye(C),[C]),on(()=>{if(!n)return;if(r.length===0){i({}),m({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let P=!1;u(!0);let s=r,d=[...new Set(s.map(h=>h.productId))],f=async h=>{let g=new Map;return await Promise.all(d.map(async _=>{try{let v=await fetch(`${t}/v1/p/${encodeURIComponent(_)}${h?`?country=${encodeURIComponent(h)}`:""}`);if(v.status===404){g.set(_,{kind:"not_found"});return}if(!v.ok){g.set(_,{kind:"error",message:`Request failed (${v.status})`});return}let R=await v.json();g.set(_,{kind:"ok",product:R})}catch(v){g.set(_,{kind:"error",message:v instanceof Error?v.message:"Failed to load product"})}})),g};return(async()=>{let h=H(),g=await f(h);if(h){let O=[...g.values()].filter(M=>M.kind==="ok"),E=O.filter(M=>M.product.base_currency);E.length>0&&E.length<O.length&&(g=await f(null))}if(P)return;let _=null,v=null,R=null;for(let O of d){let E=g.get(O);!E||E.kind!=="ok"||(_===null&&E.product.shipping_rates&&(_=E.product.shipping_rates),v===null&&E.product.free_shipping_over!=null&&(v=E.product.free_shipping_over),R===null&&E.product.shipping_countries&&(R=E.product.shipping_countries))}let A={},$=new Map,N=null;for(let O of s){let E=g.get(O.productId);if(!E||E.kind==="error"){A[O.variantId]=Jn,E&&N===null&&(N=E.message);continue}if(E.kind==="not_found"){A[O.variantId]=Je;continue}let{product:M}=E;if(!M.active||M.purchasable===!1){A[O.variantId]=Je;continue}let Y=M.variants??[],V=Y.find(J=>J.id===O.variantId)??null,K=O.variantId;if(!V){let J=le(Y,O.selection);if(!J){A[O.variantId]=Je;continue}let $t=$.get(O.variantId)??{};$t.reanchorTo={variantId:J.id,selection:Gn(J)},$.set(O.variantId,$t),p.current.add(J.id),V=J,K=J.id}let I=Re(M,O.selection)[0]??null,L={image:I,unitAmount:V.unit_amount,currency:V.currency,baseCurrency:M.base_currency??null,inStock:V.in_stock,available:V.available,maxQuantity:M.max_quantity,pdpSearch:ze(M,O.selection),status:p.current.has(K)?"reanchored":"ok"};A[O.variantId]=L,A[K]=L;let F=$.get(O.variantId)??{};F.display={name:M.name,variantTitle:V.title,image:I},$.set(O.variantId,F)}let D=new Set(s.map(O=>O.variantId));for(let O of[...p.current])!D.has(O)&&!(O in A)&&p.current.delete(O);if($.size>0){let O=se(),E=[],M=new Map,Y=!1;for(let V of O){let K=$.get(V.variantId),I={...V};K?.reanchorTo&&(I.variantId=K.reanchorTo.variantId,I.selection=K.reanchorTo.selection,Y=!0),K?.display&&(I.display.name!==K.display.name||I.display.variantTitle!==K.display.variantTitle||I.display.image!==K.display.image)&&(I.display=K.display,Y=!0);let L=M.get(I.variantId);if(L){L.quantity+=I.quantity,Y=!0;continue}E.push(I),M.set(I.variantId,I)}Y&&X(E)}P||(i(A),m({shippingRates:_,freeShippingOver:v,shippingCountries:R}),c(N),u(!1))})(),()=>{P=!0}},[n,T,t,x]);let b=vt(()=>r.map(P=>{let s=o[P.variantId];return s?{...P,...s,image:s.image??P.display.image}:{...P,image:P.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:w}=vt(()=>{let P=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(P+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:P,currency:s}},[b]);return{lines:b,subtotal:a,currency:w,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:S,refresh:C}}import{useCallback as Qn,useEffect as sn,useMemo as Zn,useRef as Ct,useState as Ie}from"react";var Xn=2e3;function er(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=re(),[l,m]=Ie(null),[y,u]=Ie(!1),[S,c]=Ie(null),[x,k]=Ie(null),[p,T]=Ie(0);sn(()=>(k(H()),ye(()=>k(H()))),[]);let C=Zn(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=Qn(()=>T(s=>s+1),[]),a=Ct(0),w=Ct(!1),P=Ct("idle");return sn(()=>{if(!i)return;if(o.length===0){m(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,f=!1,h,g=w.current?r:0;w.current=!0,P.current=P.current==="pending"?"spent":"idle";let _=setTimeout(async()=>{u(!0);try{let v=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:d.signal,body:JSON.stringify({items:o.map(A=>({variant_id:A.variantId,quantity:A.quantity})),...x?{country:x}:{},...n?{shipping_option:n}:{}})});if(f||s!==a.current)return;if(!v.ok){if(v.status===429){let A=P.current==="idle";A&&(h=setTimeout(()=>{f||s!==a.current||(P.current="pending",T($=>$+1))},Xn)),c(A?"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 (${v.status})`);return}let R=await v.json();if(f||s!==a.current)return;m({currency:R.currency,subtotal:R.subtotal,shipping:R.shipping?{options:R.shipping.options.map(A=>({label:A.label,amount:A.amount,undiscountedAmount:A.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(v){if(f||d.signal.aborted||s!==a.current)return;c(v instanceof Error?v.message:"Could not price this cart")}finally{!f&&s===a.current&&u(!1)}},g);return()=>{f=!0,clearTimeout(_),h!==void 0&&clearTimeout(h),d.abort()}},[i,C,x,t,r,n,p]),{summary:l,loading:y,error:S,refresh:b}}import{useCallback as tr,useEffect as an,useRef as un,useState as Ge}from"react";function wt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Ge(!1),[o,i]=Ge(null),[l,m]=Ge(null),[y,u]=Ge(null),S=un(!1),c=un(null);return an(()=>{let k=p=>{p.persisted&&(S.current=!1,n(!1))};return window.addEventListener("pageshow",k),()=>window.removeEventListener("pageshow",k)},[]),an(()=>{if(typeof window>"u"||window.self===window.top)return;let k=p=>{if(p.source!==window.parent)return;let T=p.data;if(T?.type!=="aifeatures:test-checkout-ack"||T.status!=="failed")return;let C=c.current;C===null||!Ye(T,C)||(c.current=null,i(typeof T.error=="string"&&T.error?T.error:"The test purchase could not be created."),S.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:tr(async(k,{successUrl:p,cancelUrl:T,customerEmail:C,metadata:b,shippingOption:a}={})=>{if(!S.current){S.current=!0,n(!0),i(null),m(null),u(null);try{let w=H(),P=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}:{}})),...w!==null?{country:w}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...C!==void 0?{customer_email:C}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:T??window.location.href})}),s=await P.json().catch(()=>null);if(!P.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:""}),S.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let f of s.items)f&&typeof f.variant_id=="string"&&(d[f.variant_id]=f);m(d),S.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=Te();if(c.current=d,await ht({items:k.map(h=>({productId:h.productId,variantId:h.variantId,quantity:h.quantity})),...C!==void 0?{customerEmail:C}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${P.status})`),S.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),S.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")){S.current=!1,n(!1);return}}window.location.href=s.url}catch(w){i(w instanceof Error?w.message:"Checkout failed"),S.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}import{useCallback as nr,useEffect as ln,useState as Pt}from"react";var _t=[{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 cn(e){return e?_t.find(t=>t.country===e.toUpperCase())?.currency??null:null}var dn=new Map;function rr(e){let t=dn.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),dn.set(e,t)),t}function ir(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Pt(null),[o,i]=Pt(!1),[l,m]=Pt(null);ln(()=>{let c=()=>n(H());return c(),i(!0),ye(c)},[]),ln(()=>{let c=!1;return rr(t).then(x=>{c||m(x)}),()=>{c=!0}},[t]);let y=nr(c=>{Yt(c)},[]),u=cn(l),S=o&&u!==null&&u!==cn(r);return{market:r,suggestedCountry:l,setMarket:y,markets:_t,shouldPrompt:S}}import{jsx as xt,jsxs as ar}from"react/jsx-runtime";var or={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function sr({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:m,loading:y}=ue(e,{apiUrl:r});if(y||!m)return null;let u=oe(m),S=t!==void 0?u.find(x=>x.id===t)??null:m.options.length===0?u[0]??null:null;if(S){if(S.unit_amount===null)return null;let x=S.compare_at_amount!==null&&S.compare_at_amount>S.unit_amount;return ar("span",{className:o,style:i,children:[x&&xt("span",{className:l,style:l?void 0:or,children:z(S.compare_at_amount,S.currency,n)}),z(S.unit_amount,S.currency,n)]})}let c=ct(u);return c?xt("span",{className:o,style:i,children:c.min===c.max?z(c.min,m.currency,n):`${z(c.min,m.currency,n)} \u2013 ${z(c.max,m.currency,n)}`}):m.unit_amount===null?null:xt("span",{className:o,style:i,children:z(m.unit_amount,m.currency,n)})}import{useEffect as Rt,useMemo as ur,useRef as pn,useState as fn}from"react";import{Fragment as kr,jsx as be,jsxs as mn}from"react/jsx-runtime";var lr={marginBottom:"0.75rem"},cr={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},dr={display:"flex",flexWrap:"wrap",gap:"0.5rem"},pr={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},fr={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},gn={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},mr={...gn,cursor:"pointer"},gr=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,yr=e=>gr.test(e),br={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},hr={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)"},Sr="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 vr({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:m,optionClassName:y,optionLabelClassName:u,valueClassName:S,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[T,C]=fn(r??{}),b=p?r:T,[a,w]=fn(()=>new Set),P=g=>w(_=>_.has(g)?_:new Set(_).add(g));Rt(()=>{w(g=>g.size===0?g:new Set)},[e]);let s=pn(!1);Rt(()=>{if(!n||p||s.current||e.length===0||typeof window>"u"||(s.current=!0,Object.keys(T).length>0))return;let g=dt({options:e},window.location.search);Object.keys(g).length!==0&&(C(g),o?.(g))},[n,p,e]);let d=ur(()=>e.length>0?t.filter(g=>g.option_values.length===e.length):t,[t,e]),f=pn(void 0);if(Rt(()=>{let g=le(d,b),_=g?.id??null;f.current!==_&&(f.current=_,i?.(g))},[d,b]),e.length===0)return null;let h=(g,_)=>{let v=lt(d,b,g,_);p||(C(v),n&&pt({options:e},v)),o?.(v)};return be("div",{className:l,style:m,children:e.map(g=>mn("div",{className:y,style:y?void 0:lr,children:[be("span",{className:u,style:u?void 0:cr,children:g.title}),be("div",{style:dr,children:g.values.map(_=>{let v=b[g.id]===_.id,R=at(d,b,g.id,_.id),A=R||ut(d,g.id,_.id),$=[S,v?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,N=_.swatch??null,D=N&&!a.has(N)?N:null,O=D?yr(D):!1,E=S?void 0:{...pr,...v?fr:{},...R?{}:A?mr:gn,...D?{...br,textDecoration:"none"}:{}},M=R?_.value:`${_.value} \u2014 unavailable with your current selection`;return be("button",{type:"button",className:$,style:E,disabled:!A,"aria-pressed":v,"aria-label":D?M:void 0,title:D?M:void 0,"data-selected":v?"true":void 0,"data-available":R?"true":"false","data-swatch":D?O?"hex":"image":void 0,onClick:()=>h(g.id,_.id),children:D?mn(kr,{children:[be("span",{"aria-hidden":"true",className:k,style:k?void 0:{...hr,...O?{background:D}:{},...O&&R?{}:{backgroundImage:[...R?[]:[Sr],...O?[]:[`url(${JSON.stringify(D)})`]].join(", ")}}}),O?null:be("img",{src:D,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>P(D)})]}):_.value},_.id)})})]},g.id))})}import{useEffect as Cr}from"react";function Qe(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}import{Fragment as At,jsx as de,jsxs as Ee}from"react/jsx-runtime";var wr={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Pr={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function yn(){return Ee("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 _r({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,apiUrl:u,disabled:S,className:c,style:x,errorClassName:k,spinner:p=!0,children:T}){let{product:C,loading:b,error:a,refresh:w}=ue(e,{apiUrl:u}),{startCheckout:P,loading:s,error:d,priceChange:f}=St({apiUrl:u});Cr(()=>{f&&w()},[f,w]);let h=C!==null&&!C.payments_ready&&!Qe(),g=C!==null&&!C.active,_=C!==null&&C.purchasable===!1,v=C!==null&&xe(C),R=C!==null?oe(C):[],A=t!==void 0?R.find(L=>L.id===t)??null:!v&&R.length===1?R[0]:null,$=v&&!A,N=A!==null&&!A.in_stock,D=n??void 0,O=C?.subscription??null,E=O!==null&&O.required&&!O.ready,M=O!==null&&O.required&&O.ready&&D===void 0,Y=!!S||b||!C||h||g||_||E||M||$||N||s,V;s?V=Ee(At,{children:[p&&de(yn,{}),"Processing\u2026"]}):b?V=Ee(At,{children:[p&&de(yn,{}),T??"Buy now"]}):h?V="Payments not set up":g||_?V="Unavailable":E?V="Currently unavailable":M?V="Select a plan":$?V="Select options":N?V="Out of stock":T!==void 0?V=T:D!==void 0?V="Subscribe":V="Buy now";let K=d??a;return Ee(At,{children:[de("button",{type:"button",className:c,style:x,disabled:Y,onClick:()=>{let L=o===void 0&&D===void 0&&H()===null&&A!==null&&!A.allow_custom_amount&&typeof A.unit_amount=="number"?{expectedUnitAmount:A.unit_amount,expectedCurrency:A.currency}:{};P({productId:e,variantId:t,quantity:D!==void 0?void 0:r,amount:o,planId:D,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,...L})},children:V}),K&&Ee("div",{role:"alert",className:k,style:k?void 0:wr,children:[K,C===null&&!b&&a!==null&&de("button",{type:"button",onClick:w,style:Pr,children:"Tap to retry"})]})]})}import{useEffect as xr,useRef as Rr,useState as bn}from"react";import{Fragment as hn,jsx as he,jsxs as Ze}from"react/jsx-runtime";var Ar={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Or={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Tr=1500;function Lr(){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:[he("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),he("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:he("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Ir(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Er({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:m,errorClassName:y,spinner:u=!0,children:S}){let{product:c,loading:x,error:k,refresh:p}=ue(e,{apiUrl:o}),{add:T}=re(),[C,b]=bn(!1),[a,w]=bn(!1),P=Rr(void 0);xr(()=>()=>{P.current&&clearTimeout(P.current)},[]);let s=c!==null&&!c.payments_ready&&!Qe(),d=c!==null&&!c.active,f=c!==null&&c.purchasable===!1,h=c!==null&&!x&&oe(c).length===0,g=c!==null&&c.allow_custom_amount,_=c!==null&&c.subscription?.required===!0,v=c!==null&&xe(c),R=c!==null?oe(c):[],A=t!==void 0?R.find(V=>V.id===t)??null:r!==void 0&&v?le(R,r):!v&&R.length===1?R[0]:null,$=c!==null&&!h&&!A,N=A!==null&&!A.in_stock,D=!!i||x||!c||s||d||f||h||g||_||$||N,O=()=>{if(!c||!A)return;let V=r??Ir(A);if(!T({productId:e,variantId:A.id,quantity:n,selection:V,display:{name:c.name,variantTitle:A.title,image:Re(c,V)[0]??null}}).ok){b(!0);return}b(!1),w(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>w(!1),Tr)},E;x?E=Ze(hn,{children:[u&&he(Lr,{}),S??"Add to cart"]}):s?E="Payments not set up":d||f||h||g?E="Unavailable":_?E="Subscription only":$?E="Select options":N?E="Out of stock":a?E="Added to cart":S!==void 0?E=S:E="Add to cart";let M=C?"Your cart is full \u2014 remove an item before adding another.":k;return Ze(hn,{children:[he("button",{type:"button",className:l,style:m,disabled:D,"data-added":a?"true":void 0,onClick:O,children:E}),M&&Ze("div",{role:"alert",className:y,style:y?void 0:Ar,children:[M,c===null&&!x&&k!==null&&!C&&he("button",{type:"button",onClick:p,style:Or,children:"Tap to retry"})]})]})}import{Fragment as Ot,jsx as ae,jsxs as Xe}from"react/jsx-runtime";var Sn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function vn(){return Xe("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 Ur({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:m,style:y,errorClassName:u,spinner:S=!0,children:c}){let{items:x,hydrated:k}=re(),{lines:p}=kt({apiUrl:e}),{startCheckout:T,loading:C,error:b,conflicts:a}=wt({apiUrl:e}),w=k&&x.length===0,P=p.some(h=>h.status==="unavailable"),s=!!l||!k||w||P||C,d;C?d=Xe(Ot,{children:[S&&ae(vn,{}),"Processing\u2026"]}):k?w?d="Cart is empty":P?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=Xe(Ot,{children:[S&&ae(vn,{}),c??"Checkout"]});let f=a?Object.keys(a).length:0;return Xe(Ot,{children:[ae("button",{type:"button",className:m,style:y,disabled:s,onClick:()=>T(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),f>0&&ae("div",{role:"alert",className:u,style:u?void 0:Sn,children:f===1?"An item in your cart changed \u2014 please review your cart and try again.":`${f} items in your cart changed \u2014 please review your cart and try again.`}),b&&ae("div",{role:"alert",className:u,style:u?void 0:Sn,children:b})]})}import{useEffect as et,useRef as kn,useState as Tt}from"react";import{Fragment as Se,jsx as U,jsxs as j}from"react/jsx-runtime";var Nr={fontSize:"1.5rem",lineHeight:1.25,fontWeight:600,margin:"0 0 0.5rem"},pe={color:"#6b7280",fontSize:"0.875rem"},Mr={display:"inline-block",padding:"0.125rem 0.5rem",margin:"0 0 1rem",borderRadius:9999,border:"1px solid #e5e7eb",background:"#f9fafb",color:"#6b7280",fontSize:"0.75rem"},Vr={textAlign:"left",border:"1px solid #e5e7eb",borderRadius:8,overflow:"hidden",margin:"1rem 0"},qr={listStyle:"none",margin:0,padding:0},$r={display:"flex",alignItems:"center",gap:"0.75rem",padding:"0.75rem"},Cn={width:56,height:56,flex:"0 0 auto",borderRadius:6,border:"1px solid #f3f4f6",background:"#f3f4f6",objectFit:"cover"},Dr={flex:"1 1 auto",minWidth:0},Br={flex:"0 0 auto",whiteSpace:"nowrap"},Fr={padding:"0.75rem",borderTop:"1px solid #e5e7eb",background:"#f9fafb"},It={display:"flex",justifyContent:"space-between",gap:"1rem",padding:"0.125rem 0"},zr={...It,fontWeight:600,marginTop:"0.5rem",paddingTop:"0.5rem",borderTop:"1px solid #e5e7eb"},jr={display:"inline-block",padding:"0.625rem 1.25rem",borderRadius:8,background:"#111827",color:"#ffffff",textDecoration:"none",fontWeight:600},Lt="af_order_confirmation_session",Kr=1800*1e3;function Wr({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:m=1500,renderNoSession:y,renderPending:u,renderPaid:S,renderFailed:c}){let[x,k]=Tt(n),[p,T]=Tt(null),[C,b]=Tt(!1),a=kn(void 0);et(()=>{if(n!==void 0){k(n);return}if(a.current!==void 0){k(a.current);return}let d=new URL(window.location.href),f=d.searchParams.get("session_id");if(f){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(Lt,JSON.stringify({id:f,ts:Date.now()}))}catch{}}else try{let h=sessionStorage.getItem(Lt);if(h){let g=JSON.parse(h);typeof g.id=="string"&&typeof g.ts=="number"&&Date.now()-g.ts<=Kr?f=g.id:sessionStorage.removeItem(Lt)}}catch{}a.current=f,k(f)},[n]),et(()=>{if(!x)return;let d=!1,f,h=Date.now(),g=async()=>{try{let _=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(_.ok){let v=await _.json();if(d||(T(v),v.status!=="pending"))return}}catch{}if(!d){if(Date.now()-h>=i){b(!0);return}f=setTimeout(g,o)}};return g(),()=>{d=!0,f&&clearTimeout(f)}},[x,e,o,i]);let w=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),P=kn(!1);et(()=>{if(!x||p===null||P.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(P.current=!0,!Ht(x)))return;let f=(p.line_items??[]).filter(h=>typeof h.variant_id=="string"&&h.variant_id.length>0).map(h=>({variantId:h.variant_id,quantity:h.quantity}));f.length>0&&Wt(f)},[x,p]);let s=w&&p.fulfillment.type==="redirect"?p.fulfillment.redirect_url:void 0;if(et(()=>{if(!s||!l)return;let d=setTimeout(()=>{window.location.href=s},m);return()=>clearTimeout(d)},[s,l,m]),x===void 0)return null;if(x===null)return y?U(Se,{children:y()}):j("div",{className:t,style:r,children:[U("h2",{children:"Thank you for your order!"}),U("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?U(Se,{children:u({timedOut:C})}):U("div",{className:t,style:r,role:"status",children:U("p",{children:C?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(w){if(S)return U(Se,{children:S(p)});let{fulfillment:d}=p,f=p.currency,h=p.amount_total!==void 0&&f?z(p.amount_total,f):null,g=p.line_items??[],_=g.some(N=>!!N.image_url),v=p.tax_behavior==="exclusive"&&typeof p.tax_total=="number"&&p.tax_total>0&&!!f,R=typeof p.shipping_total=="number"&&!!f,A=d.files??[],$=A.length===0?d.download_url:void 0;return j("div",{className:t,style:r,children:[U("h2",{style:Nr,children:"Thank you for your purchase!"}),p.is_test&&j("p",{style:Mr,children:[U("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),(g.length>0||h)&&j("div",{style:Vr,children:[g.length>0&&U("ul",{style:qr,children:g.map((N,D)=>{let O=typeof N.unit_amount=="number"&&f?z(N.unit_amount*N.quantity,f):null;return j("li",{style:{...$r,borderBottom:D<g.length-1?"1px solid #f3f4f6":void 0,opacity:N.refunded?.6:void 0},children:[_&&(N.image_url?U("img",{src:N.image_url,alt:"",width:56,height:56,style:Cn}):U("div",{style:Cn,"aria-hidden":"true"})),j("div",{style:Dr,children:[U("div",{children:N.name}),N.quantity>1&&j("div",{style:pe,children:["Qty ",N.quantity]}),N.refunded&&U("div",{style:pe,children:U("em",{children:N.refund_reason==="oversold"?"Sold out and refunded \u2014 check your email for details":"Refunded"})})]}),O&&U("div",{style:Br,children:O})]},D)})}),h&&j("div",{style:Fr,children:[R&&j("div",{style:It,children:[U("span",{style:pe,children:"Shipping"}),U("span",{children:p.shipping_total===0?"Free":z(p.shipping_total,f)})]}),v&&j("div",{style:It,children:[U("span",{style:pe,children:"Tax"}),U("span",{children:z(p.tax_total,f)})]}),j("div",{style:zr,children:[U("span",{children:"Total paid"}),U("span",{children:h})]})]})]}),p.source==="subscription"&&p.subscription&&j(Se,{children:[j("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),"."]}),j("p",{children:["You can view, update, or cancel it any time on"," ",U("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),A.length>0&&j(Se,{children:[U("p",{children:"Your downloads:"}),U("ul",{children:A.map((N,D)=>U("li",{children:U("a",{href:N.download_url,children:N.name})},D))})]}),$&&U("p",{children:U("a",{href:$,style:jr,children:"Download your file"})}),s?j("p",{children:["Taking you to your content\u2026"," ",U("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?U("p",{children:U("a",{href:d.redirect_url,children:"Continue to your content"})}):null,A.length===0&&!$&&!d.redirect_url&&U("p",{style:pe,children:"A confirmation email is on its way to you."}),typeof p.order_number=="number"?j("p",{style:pe,children:["Order ",j("strong",{children:["#",p.order_number]})," \u2014 keep this if you ever need help with your order."]}):p.order_id?j("p",{style:pe,children:["Order reference: ",U("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]}):null]})}return c?U(Se,{children:c(p)}):U("div",{className:t,style:r,children:U("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 Yr,useState as Hr}from"react";import{Fragment as Xr,jsx as ve}from"react/jsx-runtime";function wn(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 Et(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var Jr={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},Gr={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 Zr({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:m,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:S,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,T=k?.ready===!0,C=[...k?.plans??[]].sort((v,R)=>v.position-R.position),[b,a]=Hr(null),w=o!==void 0,P=w?o:b,s=C.map(v=>v.id).join("|"),d=C.length>0?C[0].id:null;if(Yr(()=>{if(!(!p||!T)&&!(P!==null&&C.some(v=>v.id===P))){if(d===null){if(P===null)return;w||a(null),i?.(null);return}w||a(d),i?.(d)}},[p,T,d,s,P,w]),!k)return null;if(!T)return p?x?ve(Xr,{children:x()}):ve("div",{className:l,style:m,"data-state":"unavailable",children:ve("p",{children:"This product is currently unavailable."})}):null;if(C.length===0)return null;let f=e?.base_currency!==void 0&&e?.base_currency!==null,h=r!==void 0?r:f?null:e?.unit_amount??null,g=n??e?.base_currency??e?.currency??"usd",_=[];if(!p){let v=h;_.push({plan:null,selected:P===null,price:v,priceLabel:v!==null?z(v,g):null,label:"One-time purchase",select:()=>{w||a(null),i?.(null)}})}for(let v of C){let R=v.unit_amount!==null?v.unit_amount:h!==null?wn(h,v):null,A=R!==null?z(R,g):null,$=v.title&&v.title.trim().length>0?v.title.trim():`Subscribe ${Et(v)}`,N=A?`${$} \u2014 ${A} ${Et(v)}`:`${$} \u2014 billed ${Et(v)}`;_.push({plan:v,selected:P===v.id,price:R,priceLabel:A,label:N,select:()=>{w||a(v.id),i?.(v.id)}})}return ve("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?m:{...Jr,...m},children:_.map(v=>{if(c)return ve("span",{style:{display:"contents"},children:c(v)},v.plan?.id??"one-time");let R=v.selected;return ve("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":v.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...Gr,...R?Qr:{}},onClick:v.select,children:v.plan===null&&S!==void 0?S:v.plan===null?v.priceLabel?`One-time purchase \u2014 ${v.priceLabel}`:"One-time purchase":v.label},v.plan?.id??"one-time")})})}import{useCallback as tt,useEffect as _n,useRef as ei,useState as nt}from"react";async function Q(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 m=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:m,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:m,error:y}}}function Pn(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function Ue(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 ti=1500;function xn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function ni(e,t){return e.requestId===t}function ri(e,t){return typeof window>"u"||!xn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;if(y?.type==="aifeatures:preview-session-ack"&&ni(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let S=y.customer;typeof S.email=="string"&&(u={email:S.email,name:typeof S.name=="string"?S.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}),ti);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ne(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=nt(()=>ce()),[o,i]=nt(null),[l,m]=nt(!1),[y,u]=nt(!1),S=ei(void 0);_n(()=>Qt(()=>{let b=ce();n(b),i(b===null?a=>Jt()??a:null)}),[]);let c=tt(async b=>{u(!0);try{let a=await Q(t,"/v1/account/verify",{method:"POST",body:{code:b}});if(a.ok&&typeof a.data.token=="string"){let P=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 We({token:a.data.token,customer:P}),n({token:a.data.token,customer:P}),i(null),m(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(m(!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;_n(()=>{if(!(typeof window>"u")&&S.current===void 0){if(!x){S.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())),S.current=a,a&&c(a)}},[c,x]);let k=tt(async b=>{if(typeof window<"u"&&xn(window)){let w=await ri(b,Te());if(w.claimed){if(w.token!==null){let P=w.customer??{email:b,name:null};return We({token:w.token,customer:P}),n({token:w.token,customer:P}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:w.error}}}let a=await Q(t,"/v1/account/login",{method:"POST",body:{email:b}});return a.ok?{ok:!0,via:"email"}:a.failure.kind==="unavailable"?(m(!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=tt(async()=>{let b=ce()?.token;b&&await Q(t,"/v1/account/logout",{method:"POST",token:b,body:{}}),ee(),n(null),i(null)},[t]),T=tt(async()=>{let b=ce();if(!b)return;let a=await Q(t,"/v1/account/me",{token:b.token}),w=()=>ce()?.token===b.token;if(a.ok){if(!w())return;let P=a.data.customer??b.customer;We({token:b.token,customer:P}),n({token:b.token,customer:P}),m(!1);return}if(a.failure.kind==="unauthorized"){if(!w())return;ee("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){m(!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:T}}import{useCallback as qe,useEffect as qt,useRef as ot,useState as $e}from"react";import{useEffect as ii,useRef as Rn,useState as ke}from"react";import{Fragment as Nt,jsx as W,jsxs as Me}from"react/jsx-runtime";var Ut={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},oi={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},si={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},An={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Ce={margin:0},ai={color:"#b91c1c",margin:0};function rt({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:m}){let y=Ne({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[S,c]=ke(""),[x,k]=ke("form"),[p,T]=ke(!1),[C,b]=ke(null),[a,w]=ke(null),[P,s]=ke(!1),d=Rn(void 0),f=Rn(!1);ii(()=>()=>{d.current&&clearTimeout(d.current)},[]);let h=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},g=async()=>{let R=S.trim();if(!R||p||f.current)return;f.current=!0,T(!0),b(null),w(null);let A=await u.login(R);if(f.current=!1,T(!1),A.ok){if(A.via==="preview")return;k("sent"),h();return}A.code!=="unavailable"&&(b(A.code==="rate_limited"?"rate_limited":"error"),w(A.error))};if(u.status==="unavailable")return m?W(Nt,{children:m()}):W("div",{className:n,style:n?o:{...Ut,...o},"data-state":"unavailable",children:W("p",{style:Ce,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:S.trim(),canResend:P,resend:()=>{g(),h()},submitting:p,reset:()=>k("form")};return l?W(Nt,{children:l(R)}):Me("div",{className:n,style:n?o:{...Ut,...o},"data-state":"sent",children:[Me("p",{style:Ce,children:["Check your email \u2014 if ",W("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),P?Me("p",{style:Ce,children:["Didn't get it?"," ",W("button",{type:"button",style:An,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",W("button",{type:"button",style:An,onClick:R.reset,children:"use a different email"}),"."]}):W("p",{style:Ce,children:"It can take a minute to arrive."})]})}let _={email:S,setEmail:c,submit:()=>void g(),submitting:p,errorKind:C,errorMessage:a,reason:u.reason};if(i)return W(Nt,{children:i(_)});let v=R=>{R.preventDefault(),_.submit()};return Me("form",{className:n,style:n?o:{...Ut,...o},onSubmit:v,"data-state":"form",children:[u.reason==="session_expired"&&W("p",{style:Ce,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&W("p",{style:Ce,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),Me("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[W("span",{children:"Email address"}),W("input",{type:"email",value:S,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:oi})]}),W("button",{type:"submit",style:si,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&W("p",{style:ai,role:"alert",children:C==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}import{Fragment as di,jsx as te,jsxs as we}from"react/jsx-runtime";var ui={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},li={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},Ve={color:"#6b7280",fontSize:"0.875rem"};function ci(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 Mt({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?te(di,{children:o()}):we("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&te("h3",{children:n}),te("p",{style:Ve,children:"No orders yet."})]}):we("div",{className:t,style:r,children:[n!==null&&te("h3",{children:n}),te("ul",{style:t?void 0:ui,children:e.map(l=>{if(i)return te("li",{style:{display:"contents"},children:i(l)},l.id);let m=Ue(l.created_at),y=ci(l);return we("li",{style:t?void 0:li,children:[we("div",{children:[l.order_number!==null&&we("strong",{children:["Order #",l.order_number]})," ",m&&te("span",{style:Ve,children:m})," ",l.source==="subscription"&&te("span",{style:Ve,children:"\xB7 subscription"}),y&&we("span",{style:Ve,children:[" \xB7 ",y]})]}),l.line_items.length>0&&te("div",{style:Ve,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:z(l.amount_total,l.currency)})]},l.id)})})]})}import{useEffect as On,useRef as pi,useState as ie}from"react";import{Fragment as In,jsx as B,jsxs as Z}from"react/jsx-runtime";var fi={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},mi={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},Pe={color:"#6b7280",fontSize:"0.875rem"},gi={color:"#b91c1c",fontSize:"0.875rem",margin:0},yi={color:"#065f46",fontSize:"0.875rem",margin:0},Vt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},fe={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Ln={...fe,border:"1px solid #111827",background:"#111827",color:"white"},bi={...fe,border:"1px solid #b91c1c",color:"#b91c1c"},hi={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},Tn={panel:"none",mutation:null,portalRefused:!1};function Si(e){let t=Ue(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 vi({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=ie(e?.name??""),[m,y]=ie(o?.line1??""),[u,S]=ie(o?.line2??""),[c,x]=ie(o?.city??""),[k,p]=ie(o?.state??""),[T,C]=ie(o?.postal_code??""),[b,a]=ie(o?.country??""),w=(P,s,d,f)=>Z("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[B("span",{children:P}),B("input",{style:hi,value:s,onChange:h=>d(h.target.value),required:f?.required,maxLength:f?.maxLength})]});return Z("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:P=>{P.preventDefault(),r({name:i.trim()||null,address:{line1:m.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:T.trim()||null,country:b.trim().toUpperCase()}})},children:[w("Name",i,l),w("Address line 1",m,y,{required:!0}),w("Address line 2",u,S),w("City",c,x),w("State / region",k,p),w("Postal code",T,C),w("Country (2-letter code)",b,a,{required:!0,maxLength:2}),Z("div",{style:Vt,children:[B("button",{type:"submit",style:Ln,disabled:t,children:t?"Saving\u2026":"Save address"}),B("button",{type:"button",style:fe,onClick:n,disabled:t,children:"Cancel"})]})]})}function it({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:m,heading:y="Your subscriptions",renderEmpty:u,renderRow:S}){let[c,x]=ie(t),[k,p]=ie({}),T=pi(new Set);On(()=>{x(t)},[t]),On(()=>{let s=d=>{d.persisted&&(T.current.clear(),p(f=>{let h=!1,g={};for(let[_,v]of Object.entries(f))v.mutation?.phase==="pending"?(g[_]={...v,mutation:null},h=!0):g[_]=v;return h?g:f}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let C=(s,d)=>p(f=>({...f,[s]:{...f[s]??Tn,...d}})),b=s=>{x(d=>d.map(f=>f.id===s.id?s:f)),i?.(s)},a=async(s,d,f,h)=>{if(T.current.has(s.id))return{ok:!1};T.current.add(s.id);try{C(s.id,{mutation:{kind:d,phase:"pending"}});let g=await Q(e,f,{method:"POST",token:r.token,body:h??{}});if(g.ok)return{ok:!0,data:g.data};let{failure:_}=g;return _.kind==="unauthorized"?(n?.({code:_.code,error:_.error}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="unavailable"?(o?.(),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="ended"?(b({...s,ended:!0,status:"canceled"}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="portal_unavailable"?(C(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(C(s.id,{mutation:{kind:d,phase:"error",error:_.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":_.error}}),{ok:!1})}finally{T.current.delete(s.id)}},w=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"},P=s=>{let d=k[s.id]??Tn,f=w(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>C(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>C(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let h=await a(s,"cancel",f.cancel);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:f.reactivate!==null,reactivate:()=>{f.reactivate&&(async()=>{let h=await a(s,"reactivate",f.reactivate);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{f.address&&C(s.id,{panel:"address",mutation:null})},saveAddress:h=>{f.address&&(async()=>{let g=await a(s,"address",f.address,{shipping_address:h});if(g.ok){let _=g.data.subscription;_&&b(_),C(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let h=await a(s,"portal",f.portal);h.ok&&typeof h.data.url=="string"?window.location.href=h.data.url:h.ok&&C(s.id,{mutation:{kind:"portal",phase:"error",error:"Card update is temporarily unavailable."}})})()}}};return c.length===0?u?B(In,{children:u()}):Z("div",{className:l,style:m,"data-state":"empty",children:[y!==null&&B("h3",{children:y}),B("p",{style:Pe,children:"No subscriptions."})]}):Z("div",{className:l,style:m,children:[y!==null&&B("h3",{children:y}),B("ul",{style:l?void 0:fi,children:c.map(s=>{let d=P(s);return S?B("li",{style:{display:"contents"},children:S(d)},s.id):B("li",{style:l?void 0:mi,"data-status":s.status,"data-ended":s.ended||void 0,children:B(ki,{ctx:d})},s.id)})})]})}function ki({ctx:e}){let t=e.subscription,r=Si(t),n=Ue(t.current_period_end),o=`${z(t.current_amount,t.currency)} ${Pn(t.plan_interval,t.plan_interval_count)}`,i=e.mutation?.phase==="pending",l=i?e.mutation?.kind:null;return Z(In,{children:[Z("div",{children:[B("strong",{children:t.plan_title??"Subscription"})," ",Z("span",{style:Pe,children:["\xB7 ",o]}),t.is_test&&B("span",{style:Pe,children:" \xB7 test"})]}),B("div",{style:r.tone==="warn"?void 0:Pe,children:r.text}),t.ended?B("p",{style:Pe,children:"This subscription has ended \u2014 to start again, subscribe from the product page."}):e.panel==="confirm_cancel"?Z("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[B("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."}),Z("div",{style:Vt,children:[B("button",{type:"button",style:bi,onClick:e.confirmCancel,disabled:i,children:l==="cancel"?"Canceling\u2026":"Confirm cancellation"}),B("button",{type:"button",style:fe,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?B(vi,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):Z("div",{style:Vt,children:[t.cancel_at_period_end?e.reactivateAvailable?B("button",{type:"button",style:Ln,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):B("span",{style:Pe,children:"To keep this subscription, sign in with your email address on this page."}):B("button",{type:"button",style:fe,onClick:e.openCancelConfirm,disabled:i,children:"Cancel subscription"}),t.shipping_address!==void 0&&!t.cancel_at_period_end&&B("button",{type:"button",style:fe,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&B("button",{type:"button",style:fe,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&B("p",{style:gi,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&B("p",{style:yi,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 _e,jsx as q,jsxs as G}from"react/jsx-runtime";var Ci={display:"flex",flexDirection:"column",gap:"1.25rem"},En={color:"#6b7280",fontSize:"0.875rem"},wi={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},Un={color:"#b91c1c"},st={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function Pi({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:m,renderHeader:y,renderPmBanner:u,renderManageExpired:S}){let c=Ne({apiUrl:e}),x=ot(void 0),[k,p]=$e(null),[T,C]=$e(!1);qt(()=>{if(!(typeof window>"u")){if(x.current===void 0){let I=new URL(window.location.href),L=I.searchParams.get("manage_code"),F=I.searchParams.get("pm");(L!==null||F!==null)&&(I.searchParams.delete("manage_code"),I.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",I.toString())),x.current={manageCode:L,pmUpdated:F==="updated"}}p(x.current.manageCode),C(x.current.pmUpdated)}},[]);let[b,a]=$e(null),w=ot(!1),P=ot(0),s=qe(I=>{a({phase:"verifying"}),(async()=>{let L=await Q(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]);qt(()=>{!k||w.current||(w.current=!0,s(k))},[k,s]);let d=qe(async()=>{let I=b;if(!I||I.phase!=="active")return;let L=++P.current,F=await Q(e,"/v1/account/manage/subscription",{token:I.token});L===P.current&&(F.ok&&F.data.subscription?a({phase:"active",token:I.token,sub:F.data.subscription,siteName:typeof F.data.site?.name=="string"?F.data.site.name:I.siteName}):!F.ok&&F.failure.kind==="unauthorized"?a({phase:"expired"}):!F.ok&&F.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[f,h]=$e({phase:"loading"}),[g,_]=$e(0),v=g>0,R=ot(0),A=c.token,$=qe(async()=>{if(!A)return;let I=++R.current,L=await Q(e,"/v1/account/me",{token:A});if(I===R.current){if(L.ok){h({phase:"ready",data:L.data});return}if(L.failure.kind==="unauthorized"){ee("session_expired");return}if(L.failure.kind==="unavailable"){ee();return}h({phase:"error",error:L.failure.error})}},[e,A]);qt(()=>{!A||k||(h({phase:"loading"}),$())},[A,k,$]);let N=qe(async()=>{_(I=>I+1);try{b&&b.phase==="active"?await d():await $()}finally{_(I=>I-1)}},[b,d,$]),D=qe(I=>{R.current++,P.current++,a(L=>L&&L.phase==="active"&&L.sub.id===I.id?{...L,sub:I}:L),h(L=>L.phase==="ready"?{phase:"ready",data:{...L.data,subscriptions:L.data.subscriptions.map(F=>F.id===I.id?I:F)}}:L)},[]),O=t?r:{...Ci,...r},E=I=>{if(!T)return null;let F={state:I.some(J=>!J.ended&&(J.status==="past_due"||J.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void N(),checking:v};return u?u(F):q("div",{style:wi,role:"status","data-pm-state":F.state,children:F.state==="retrying"?G(_e,{children:[q("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),q("p",{style:{margin:"0.375rem 0 0"},children:q("button",{type:"button",style:st,onClick:F.checkAgain,disabled:v,children:v?"Checking\u2026":"Check again"})})]}):q("p",{style:{margin:0},children:"Card updated \u2014 your subscription is back in good standing."})})};if(k)return!b||b.phase==="verifying"?i?q(_e,{children:i()}):q("div",{className:t,style:O,role:"status",children:q("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?G("div",{className:t,style:O,children:[E([b.sub]),q(it,{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"?q("div",{className:t,style:O,"data-state":"unavailable",children:q("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?G("div",{className:t,style:O,children:[q("p",{style:Un,role:"alert",children:b.error}),q("p",{children:q("button",{type:"button",style:st,onClick:()=>s(k),children:"Try again"})})]}):G("div",{className:t,style:O,"data-state":"manage-expired",children:[S?S():q("p",{children:"This manage link is no longer valid. Sign in below with the email you used at checkout to manage your subscription."}),q(rt,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?q(_e,{children:i()}):q("div",{className:t,style:O,role:"status",children:q("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return q("div",{className:t,style:O,children:q(rt,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(f.phase==="loading")return i?q(_e,{children:i()}):q("div",{className:t,style:O,role:"status",children:q("p",{children:"Loading your account\u2026"})});if(f.phase==="error")return l?q(_e,{children:l({error:f.error,retry:()=>void $()})}):G("div",{className:t,style:O,children:[G("p",{style:Un,role:"alert",children:["We couldn't load your account \u2014 ",f.error]}),q("p",{children:q("button",{type:"button",style:st,onClick:()=>void $(),children:"Try again"})})]});let{data:M}=f,Y=M.customer??c.customer??{email:"",name:null},V=()=>void c.logout(),K=M.orders.length===0&&M.subscriptions.length===0;return G("div",{className:t,style:O,children:[y?y({customer:Y,site:M.site??null,signOut:V}):G("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[G("div",{children:[q("h2",{style:{margin:0},children:"Your account"}),G("p",{style:{...En,margin:0},children:["Signed in as ",Y.email]})]}),q("button",{type:"button",style:st,onClick:V,children:"Sign out"})]}),E(M.subscriptions),K?m?m():G("p",{style:En,children:["Nothing here yet \u2014 orders and subscriptions for ",Y.email," ","will show up on this page."]}):G(_e,{children:[M.subscriptions.length>0&&q(it,{apiUrl:e,subscriptions:M.subscriptions,auth:{kind:"session",token:A},onSubscriptionChange:D,onAuthError:()=>ee("session_expired"),onUnavailable:()=>ee()}),q(Mt,{orders:M.orders})]})]})}export{rt as AccountLogin,Mt as AccountOrders,Pi as AccountPage,Er as AddToCartButton,Vn as AifeaturesCaptcha,_r as BuyButton,Ur as CartCheckoutButton,_t as MARKET_COUNTRIES,rn as MAX_CART_LINES,Wr as OrderConfirmation,Zr as PlanPicker,sr as ProductPrice,it as SubscriptionList,vr as VariantPicker,Ft as ZERO_DECIMAL_CURRENCIES,pt as applySelectionToUrl,z as formatPrice,me as getOptions,oe as getVariants,xe as isMultiVariant,at as isValueAvailable,ut as isValueInCatalog,wn as planRecurringAmount,lt as reanchorSelection,le as resolveVariant,ze as searchFromSelection,Re as selectedImages,zt as selectedValues,dt as selectionFromSearch,re as useCart,wt as useCartCheckout,kt as useCartItems,er as useCartSummary,St as useCheckout,ir as useMarket,ue as useProduct,Ne as useSession,ne as valueSlug,ct as variantPriceRange};
2
+ import{useState as Dt,useEffect as Nn}from"react";import{Turnstile as Mn}from"@marsidev/react-turnstile";import{jsx as Bt}from"react/jsx-runtime";function Vn({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=Dt(null),[m,y]=Dt(!0);return Nn(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(u=>u.json()).then(u=>{l(u.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),m||!i?null:Bt("div",{className:o,children:Bt(Mn,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}import{useCallback as qn,useEffect as $n,useRef as Dn,useState as De}from"react";var Be=[1e3,3e3];function ue(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=De(null),[l,m]=De(!0),[y,u]=De(null),[S,c]=De(0),x=Dn(e);$n(()=>{let p=!1,T;m(!0),u(null),x.current!==e&&(x.current=e,i(null));let C=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let w=await a.json().catch(()=>null);if(!p)if(!a.ok||!w){if(a.status>=500&&b<Be.length){T=setTimeout(()=>C(b+1),Be[b]);return}u(w?.error??`Request failed (${a.status})`),i(null),m(!1)}else i(w),m(!1)}).catch(a=>{if(!p){if(b<Be.length){T=setTimeout(()=>C(b+1),Be[b]);return}u(a instanceof Error?a.message:"Failed to load product"),m(!1)}})};return C(0),()=>{p=!0,T&&clearTimeout(T)}},[e,r,n,S]);let k=qn(()=>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 oe(e){return e.variants??[]}function me(e){return e.options??[]}function xe(e){return me(e).length>0}function Fe(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 at(e,t,r,n){return e.some(o=>{let i=Fe(o);if(i[r]!==n)return!1;for(let[l,m]of Object.entries(t))if(l!==r&&i[l]!==m)return!1;return!0})}function ut(e,t,r){return e.some(n=>Fe(n)[t]===r)}function lt(e,t,r,n){let o={[r]:n};for(let[l,m]of Object.entries(t)){if(l===r)continue;e.some(u=>{let S=Fe(u);return S[r]===n&&S[l]===m})&&(o[l]=m)}return e.some(l=>{let m=Fe(l);return Object.entries(o).every(([y,u])=>m[y]===u)})?o:{[r]:n}}function ct(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 zt(e,t){let r={};for(let n of me(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 dt(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 me(e)){let l=ne(i.title);if(l.length===0)continue;let m=n.get(l);if(m===void 0)continue;let y=ne(m);if(y.length===0)continue;let u=i.values.find(S=>ne(S.value)===y);u&&(o[i.id]=u.id)}return o}function ze(e,t){let r={};for(let[n,o]of Object.entries(zt(e,t))){let i=ne(n),l=ne(o);i.length===0||l.length===0||(r[i]=l)}return r}function Re(e,t){let r=[];for(let n of me(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 pt(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of me(e)){let o=ne(n.title);o.length!==0&&r.searchParams.delete(o)}for(let[n,o]of Object.entries(ze(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}import{useCallback as jn,useEffect as Zt,useRef as Xt,useState as bt}from"react";var mt="aifeatures_cart",gt="aifeatures_market",jt="aifeatures_cart_cleared";var ft="aifeatures:cart-storage",Ae=new Map;function Oe(e){if(Ae.has(e))return Ae.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function ge(e,t){if(typeof window>"u"){Ae.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Ae.delete(e)}catch{Ae.set(e,t)}Bn(e)}function Bn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(ft,{detail:{key:e}}))}catch{}}function je(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(ft,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(ft,n)}}function Fn(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,m]of Object.entries(t.selection))typeof m=="string"&&(n[l]=m);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=Oe(mt);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=Fn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function X(e){ge(mt,JSON.stringify(e))}function Kt(e){return je(mt,e)}function Wt(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 H(){let e=Oe(gt);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function Yt(e){ge(gt,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function ye(e){return je(gt,e)}function Ht(e){let t=[],r=Oe(jt);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)),ge(jt,JSON.stringify(t)),!0)}var Ke="aifeatures_session",yt=null;function Jt(){return yt}function zn(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=Oe(Ke);if(!e)return null;try{return zn(JSON.parse(e))}catch{return null}}function Gt(){return ce()?.token??null}function We(e){yt=null,ge(Ke,JSON.stringify(e))}function ee(e){yt=e??null,ge(Ke,null)}function Qt(e){return je(Ke,e)}var Kn=1500;function Te(){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 ht(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;y?.type==="aifeatures:test-checkout-ack"&&Ye(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),Kn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function en(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 St(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=bt(!1),[o,i]=bt(null),[l,m]=bt(null),y=Xt(!1),u=Xt(null);return Zt(()=>{let c=x=>{x.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",c),()=>window.removeEventListener("pageshow",c)},[]),Zt(()=>{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:jn(async({productId:c,variantId:x,quantity:k,amount:p,metadata:T,successUrl:C,cancelUrl:b,customerEmail:a,planId:w,expectedUnitAmount:P,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),m(null),w!==void 0){let d=Gt();if(d)try{let f=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${d}`},body:JSON.stringify({product_id:c,plan_id:w,...x!==void 0?{variant_id:x}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.text().catch(()=>""),g=null;try{g=h?JSON.parse(h):null}catch{g=null}if(f.ok){if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}en(g.url)==="stayed"&&(y.current=!1,n(!1));return}let _=f.status===404&&h.trim()==="";if(f.status===401||_)ee();else{i(g?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}}catch(f){i(f instanceof Error?f.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let d=w===void 0?H():null,f=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&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{plan_id:w}:{},...T!==void 0?{metadata:T}:{},...a!==void 0?{customer_email:a}:{},...P!==void 0&&s!==void 0&&w===void 0?{expected_unit_amount:P,expected_currency:s}:{},...d!==null?{country:d}:{},success_url:C??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),h=await f.json().catch(()=>null);if(!f.ok){if(h?.error==="price_changed"&&typeof h.current_unit_amount=="number"&&typeof h.currency=="string"){m({currentUnitAmount:h.current_unit_amount,currency:h.currency}),i(`The price has changed to ${z(h.current_unit_amount,h.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(h?.code==="preview_domain"){let g=Te();if(u.current=g,await ht({productId:c,...x!==void 0?{variantId:x}:{},...k!==void 0&&w===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...w!==void 0?{planId:w}:{},...a!==void 0?{customerEmail:a}:{},...T!==void 0?{metadata:T}:{}},g))return;u.current=null}i(h?.error??`Checkout failed (${f.status})`),y.current=!1,n(!1);return}if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}en(h.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 He,useEffect as Wn,useState as tn}from"react";var rn=20;function nn(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function re(){let[e,t]=tn([]),[r,n]=tn(!1);Wn(()=>{let u=()=>t(se());return u(),n(!0),Kt(u)},[]);let o=He(u=>{let S=se(),c=nn(u.quantity);return S.find(k=>k.variantId===u.variantId)?(X(S.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+c,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):S.length>=rn?{ok:!1,reason:"cart_full"}:(X([...S,{productId:u.productId,variantId:u.variantId,quantity:c,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=He(u=>{X(se().filter(S=>S.variantId!==u))},[]),l=He((u,S)=>{let c=se();if(S<=0){X(c.filter(k=>k.variantId!==u));return}let x=nn(S);X(c.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),m=He(()=>{X([])},[]),y=e.reduce((u,S)=>u+S.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:m}}import{useCallback as Yn,useEffect as on,useMemo as vt,useRef as Hn,useState as Le}from"react";var Je={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},Jn={...Je,inStock:!0,status:"error"};function Gn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function kt(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=re(),[o,i]=Le({}),[l,m]=Le({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=Le(!0),[S,c]=Le(null),[x,k]=Le(0),p=Hn(new Set),T=vt(()=>JSON.stringify(r.map(P=>[P.productId,P.variantId,P.selection])),[r]),C=Yn(()=>k(P=>P+1),[]);on(()=>ye(C),[C]),on(()=>{if(!n)return;if(r.length===0){i({}),m({shippingRates:null,freeShippingOver:null,shippingCountries:null}),c(null),u(!1);return}let P=!1;u(!0);let s=r,d=[...new Set(s.map(h=>h.productId))],f=async h=>{let g=new Map;return await Promise.all(d.map(async _=>{try{let v=await fetch(`${t}/v1/p/${encodeURIComponent(_)}${h?`?country=${encodeURIComponent(h)}`:""}`);if(v.status===404){g.set(_,{kind:"not_found"});return}if(!v.ok){g.set(_,{kind:"error",message:`Request failed (${v.status})`});return}let R=await v.json();g.set(_,{kind:"ok",product:R})}catch(v){g.set(_,{kind:"error",message:v instanceof Error?v.message:"Failed to load product"})}})),g};return(async()=>{let h=H(),g=await f(h);if(h){let O=[...g.values()].filter(M=>M.kind==="ok"),E=O.filter(M=>M.product.base_currency);E.length>0&&E.length<O.length&&(g=await f(null))}if(P)return;let _=null,v=null,R=null;for(let O of d){let E=g.get(O);!E||E.kind!=="ok"||(_===null&&E.product.shipping_rates&&(_=E.product.shipping_rates),v===null&&E.product.free_shipping_over!=null&&(v=E.product.free_shipping_over),R===null&&E.product.shipping_countries&&(R=E.product.shipping_countries))}let A={},$=new Map,N=null;for(let O of s){let E=g.get(O.productId);if(!E||E.kind==="error"){A[O.variantId]=Jn,E&&N===null&&(N=E.message);continue}if(E.kind==="not_found"){A[O.variantId]=Je;continue}let{product:M}=E;if(!M.active||M.purchasable===!1){A[O.variantId]=Je;continue}let Y=M.variants??[],V=Y.find(J=>J.id===O.variantId)??null,K=O.variantId;if(!V){let J=le(Y,O.selection);if(!J){A[O.variantId]=Je;continue}let $t=$.get(O.variantId)??{};$t.reanchorTo={variantId:J.id,selection:Gn(J)},$.set(O.variantId,$t),p.current.add(J.id),V=J,K=J.id}let I=Re(M,O.selection)[0]??null,L={image:I,unitAmount:V.unit_amount,currency:V.currency,baseCurrency:M.base_currency??null,inStock:V.in_stock,available:V.available,maxQuantity:M.max_quantity,pdpSearch:ze(M,O.selection),status:p.current.has(K)?"reanchored":"ok"};A[O.variantId]=L,A[K]=L;let F=$.get(O.variantId)??{};F.display={name:M.name,variantTitle:V.title,image:I},$.set(O.variantId,F)}let D=new Set(s.map(O=>O.variantId));for(let O of[...p.current])!D.has(O)&&!(O in A)&&p.current.delete(O);if($.size>0){let O=se(),E=[],M=new Map,Y=!1;for(let V of O){let K=$.get(V.variantId),I={...V};K?.reanchorTo&&(I.variantId=K.reanchorTo.variantId,I.selection=K.reanchorTo.selection,Y=!0),K?.display&&(I.display.name!==K.display.name||I.display.variantTitle!==K.display.variantTitle||I.display.image!==K.display.image)&&(I.display=K.display,Y=!0);let L=M.get(I.variantId);if(L){L.quantity+=I.quantity,Y=!0;continue}E.push(I),M.set(I.variantId,I)}Y&&X(E)}P||(i(A),m({shippingRates:_,freeShippingOver:v,shippingCountries:R}),c(N),u(!1))})(),()=>{P=!0}},[n,T,t,x]);let b=vt(()=>r.map(P=>{let s=o[P.variantId];return s?{...P,...s,image:s.image??P.display.image}:{...P,image:P.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:w}=vt(()=>{let P=0,s=null;for(let d of b)d.unitAmount===null||d.currency===null||(P+=d.unitAmount*d.quantity,s=s??d.currency);return{subtotal:P,currency:s}},[b]);return{lines:b,subtotal:a,currency:w,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:S,refresh:C}}import{useCallback as Qn,useEffect as sn,useMemo as Zn,useRef as Ct,useState as Ie}from"react";var Xn=2e3;function er(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=re(),[l,m]=Ie(null),[y,u]=Ie(!1),[S,c]=Ie(null),[x,k]=Ie(null),[p,T]=Ie(0);sn(()=>(k(H()),ye(()=>k(H()))),[]);let C=Zn(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=Qn(()=>T(s=>s+1),[]),a=Ct(0),w=Ct(!1),P=Ct("idle");return sn(()=>{if(!i)return;if(o.length===0){m(null),c(null),u(!1);return}let s=++a.current,d=new AbortController,f=!1,h,g=w.current?r:0;w.current=!0,P.current=P.current==="pending"?"spent":"idle";let _=setTimeout(async()=>{u(!0);try{let v=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:d.signal,body:JSON.stringify({items:o.map(A=>({variant_id:A.variantId,quantity:A.quantity})),...x?{country:x}:{},...n?{shipping_option:n}:{}})});if(f||s!==a.current)return;if(!v.ok){if(v.status===429){let A=P.current==="idle";A&&(h=setTimeout(()=>{f||s!==a.current||(P.current="pending",T($=>$+1))},Xn)),c(A?"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 (${v.status})`);return}let R=await v.json();if(f||s!==a.current)return;m({currency:R.currency,subtotal:R.subtotal,shipping:R.shipping?{options:R.shipping.options.map(A=>({label:A.label,amount:A.amount,undiscountedAmount:A.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(v){if(f||d.signal.aborted||s!==a.current)return;c(v instanceof Error?v.message:"Could not price this cart")}finally{!f&&s===a.current&&u(!1)}},g);return()=>{f=!0,clearTimeout(_),h!==void 0&&clearTimeout(h),d.abort()}},[i,C,x,t,r,n,p]),{summary:l,loading:y,error:S,refresh:b}}import{useCallback as tr,useEffect as an,useRef as un,useState as Ge}from"react";function wt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Ge(!1),[o,i]=Ge(null),[l,m]=Ge(null),[y,u]=Ge(null),S=un(!1),c=un(null);return an(()=>{let k=p=>{p.persisted&&(S.current=!1,n(!1))};return window.addEventListener("pageshow",k),()=>window.removeEventListener("pageshow",k)},[]),an(()=>{if(typeof window>"u"||window.self===window.top)return;let k=p=>{if(p.source!==window.parent)return;let T=p.data;if(T?.type!=="aifeatures:test-checkout-ack"||T.status!=="failed")return;let C=c.current;C===null||!Ye(T,C)||(c.current=null,i(typeof T.error=="string"&&T.error?T.error:"The test purchase could not be created."),S.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:tr(async(k,{successUrl:p,cancelUrl:T,customerEmail:C,metadata:b,shippingOption:a}={})=>{if(!S.current){S.current=!0,n(!0),i(null),m(null),u(null);try{let w=H(),P=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}:{}})),...w!==null?{country:w}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...C!==void 0?{customer_email:C}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:T??window.location.href})}),s=await P.json().catch(()=>null);if(!P.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:""}),S.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let d={};for(let f of s.items)f&&typeof f.variant_id=="string"&&(d[f.variant_id]=f);m(d),S.current=!1,n(!1);return}if(s?.code==="preview_domain"){let d=Te();if(c.current=d,await ht({items:k.map(h=>({productId:h.productId,variantId:h.variantId,quantity:h.quantity})),...C!==void 0?{customerEmail:C}:{},...b!==void 0?{metadata:b}:{}},d))return;c.current=null}i(s?.error??`Checkout failed (${P.status})`),S.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),S.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")){S.current=!1,n(!1);return}}window.location.href=s.url}catch(w){i(w instanceof Error?w.message:"Checkout failed"),S.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}import{useCallback as nr,useEffect as ln,useState as Pt}from"react";var _t=[{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 cn(e){return e?_t.find(t=>t.country===e.toUpperCase())?.currency??null:null}var dn=new Map;function rr(e){let t=dn.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),dn.set(e,t)),t}function ir(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=Pt(null),[o,i]=Pt(!1),[l,m]=Pt(null);ln(()=>{let c=()=>n(H());return c(),i(!0),ye(c)},[]),ln(()=>{let c=!1;return rr(t).then(x=>{c||m(x)}),()=>{c=!0}},[t]);let y=nr(c=>{Yt(c)},[]),u=cn(l),S=o&&u!==null&&u!==cn(r);return{market:r,suggestedCountry:l,setMarket:y,markets:_t,shouldPrompt:S}}import{jsx as xt,jsxs as ar}from"react/jsx-runtime";var or={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function sr({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:m,loading:y}=ue(e,{apiUrl:r});if(y||!m)return null;let u=oe(m),S=t!==void 0?u.find(x=>x.id===t)??null:m.options.length===0?u[0]??null:null;if(S){if(S.unit_amount===null)return null;let x=S.compare_at_amount!==null&&S.compare_at_amount>S.unit_amount;return ar("span",{className:o,style:i,children:[x&&xt("span",{className:l,style:l?void 0:or,children:z(S.compare_at_amount,S.currency,n)}),z(S.unit_amount,S.currency,n)]})}let c=ct(u);return c?xt("span",{className:o,style:i,children:c.min===c.max?z(c.min,m.currency,n):`${z(c.min,m.currency,n)} \u2013 ${z(c.max,m.currency,n)}`}):m.unit_amount===null?null:xt("span",{className:o,style:i,children:z(m.unit_amount,m.currency,n)})}import{useEffect as Rt,useMemo as ur,useRef as pn,useState as fn}from"react";import{Fragment as kr,jsx as be,jsxs as mn}from"react/jsx-runtime";var lr={marginBottom:"0.75rem"},cr={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},dr={display:"flex",flexWrap:"wrap",gap:"0.5rem"},pr={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},fr={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},gn={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},mr={...gn,cursor:"pointer"},gr=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,yr=e=>gr.test(e),br={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},hr={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)"},Sr="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 vr({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:m,optionClassName:y,optionLabelClassName:u,valueClassName:S,selectedValueClassName:c,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[T,C]=fn(r??{}),b=p?r:T,[a,w]=fn(()=>new Set),P=g=>w(_=>_.has(g)?_:new Set(_).add(g));Rt(()=>{w(g=>g.size===0?g:new Set)},[e]);let s=pn(!1);Rt(()=>{if(!n||p||s.current||e.length===0||typeof window>"u"||(s.current=!0,Object.keys(T).length>0))return;let g=dt({options:e},window.location.search);Object.keys(g).length!==0&&(C(g),o?.(g))},[n,p,e]);let d=ur(()=>e.length>0?t.filter(g=>g.option_values.length===e.length):t,[t,e]),f=pn(void 0);if(Rt(()=>{let g=le(d,b),_=g?.id??null;f.current!==_&&(f.current=_,i?.(g))},[d,b]),e.length===0)return null;let h=(g,_)=>{let v=lt(d,b,g,_);p||(C(v),n&&pt({options:e},v)),o?.(v)};return be("div",{className:l,style:m,children:e.map(g=>mn("div",{className:y,style:y?void 0:lr,children:[be("span",{className:u,style:u?void 0:cr,children:g.title}),be("div",{style:dr,children:g.values.map(_=>{let v=b[g.id]===_.id,R=at(d,b,g.id,_.id),A=R||ut(d,g.id,_.id),$=[S,v?c:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,N=_.swatch??null,D=N&&!a.has(N)?N:null,O=D?yr(D):!1,E=S?void 0:{...pr,...v?fr:{},...R?{}:A?mr:gn,...D?{...br,textDecoration:"none"}:{}},M=R?_.value:`${_.value} \u2014 unavailable with your current selection`;return be("button",{type:"button",className:$,style:E,disabled:!A,"aria-pressed":v,"aria-label":D?M:void 0,title:D?M:void 0,"data-selected":v?"true":void 0,"data-available":R?"true":"false","data-swatch":D?O?"hex":"image":void 0,onClick:()=>h(g.id,_.id),children:D?mn(kr,{children:[be("span",{"aria-hidden":"true",className:k,style:k?void 0:{...hr,...O?{background:D}:{},...O&&R?{}:{backgroundImage:[...R?[]:[Sr],...O?[]:[`url(${JSON.stringify(D)})`]].join(", ")}}}),O?null:be("img",{src:D,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>P(D)})]}):_.value},_.id)})})]},g.id))})}import{useEffect as Cr}from"react";function Qe(){if(typeof window>"u")return!1;try{return window.self!==window.top}catch{return!0}}import{Fragment as At,jsx as de,jsxs as Ee}from"react/jsx-runtime";var wr={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Pr={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function yn(){return Ee("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 _r({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,apiUrl:u,disabled:S,className:c,style:x,errorClassName:k,spinner:p=!0,children:T}){let{product:C,loading:b,error:a,refresh:w}=ue(e,{apiUrl:u}),{startCheckout:P,loading:s,error:d,priceChange:f}=St({apiUrl:u});Cr(()=>{f&&w()},[f,w]);let h=C!==null&&!C.payments_ready&&!Qe(),g=C!==null&&!C.active,_=C!==null&&C.purchasable===!1,v=C!==null&&xe(C),R=C!==null?oe(C):[],A=t!==void 0?R.find(L=>L.id===t)??null:!v&&R.length===1?R[0]:null,$=v&&!A,N=A!==null&&!A.in_stock,D=n??void 0,O=C?.subscription??null,E=O!==null&&O.required&&!O.ready,M=O!==null&&O.required&&O.ready&&D===void 0,Y=!!S||b||!C||h||g||_||E||M||$||N||s,V;s?V=Ee(At,{children:[p&&de(yn,{}),"Processing\u2026"]}):b?V=Ee(At,{children:[p&&de(yn,{}),T??"Buy now"]}):h?V="Payments not set up":g||_?V="Unavailable":E?V="Currently unavailable":M?V="Select a plan":$?V="Select options":N?V="Out of stock":T!==void 0?V=T:D!==void 0?V="Subscribe":V="Buy now";let K=d??a;return Ee(At,{children:[de("button",{type:"button",className:c,style:x,disabled:Y,onClick:()=>{let L=o===void 0&&D===void 0&&H()===null&&A!==null&&!A.allow_custom_amount&&typeof A.unit_amount=="number"?{expectedUnitAmount:A.unit_amount,expectedCurrency:A.currency}:{};P({productId:e,variantId:t,quantity:D!==void 0?void 0:r,amount:o,planId:D,metadata:i,successUrl:l,cancelUrl:m,customerEmail:y,...L})},children:V}),K&&Ee("div",{role:"alert",className:k,style:k?void 0:wr,children:[K,C===null&&!b&&a!==null&&de("button",{type:"button",onClick:w,style:Pr,children:"Tap to retry"})]})]})}import{useEffect as xr,useRef as Rr,useState as bn}from"react";import{Fragment as hn,jsx as he,jsxs as Ze}from"react/jsx-runtime";var Ar={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Or={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Tr=1500;function Lr(){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:[he("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),he("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:he("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Ir(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Er({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:m,errorClassName:y,spinner:u=!0,children:S}){let{product:c,loading:x,error:k,refresh:p}=ue(e,{apiUrl:o}),{add:T}=re(),[C,b]=bn(!1),[a,w]=bn(!1),P=Rr(void 0);xr(()=>()=>{P.current&&clearTimeout(P.current)},[]);let s=c!==null&&!c.payments_ready&&!Qe(),d=c!==null&&!c.active,f=c!==null&&c.purchasable===!1,h=c!==null&&!x&&oe(c).length===0,g=c!==null&&c.allow_custom_amount,_=c!==null&&c.subscription?.required===!0,v=c!==null&&xe(c),R=c!==null?oe(c):[],A=t!==void 0?R.find(V=>V.id===t)??null:r!==void 0&&v?le(R,r):!v&&R.length===1?R[0]:null,$=c!==null&&!h&&!A,N=A!==null&&!A.in_stock,D=!!i||x||!c||s||d||f||h||g||_||$||N,O=()=>{if(!c||!A)return;let V=r??Ir(A);if(!T({productId:e,variantId:A.id,quantity:n,selection:V,display:{name:c.name,variantTitle:A.title,image:Re(c,V)[0]??null}}).ok){b(!0);return}b(!1),w(!0),P.current&&clearTimeout(P.current),P.current=setTimeout(()=>w(!1),Tr)},E;x?E=Ze(hn,{children:[u&&he(Lr,{}),S??"Add to cart"]}):s?E="Payments not set up":d||f||h||g?E="Unavailable":_?E="Subscription only":$?E="Select options":N?E="Out of stock":a?E="Added to cart":S!==void 0?E=S:E="Add to cart";let M=C?"Your cart is full \u2014 remove an item before adding another.":k;return Ze(hn,{children:[he("button",{type:"button",className:l,style:m,disabled:D,"data-added":a?"true":void 0,onClick:O,children:E}),M&&Ze("div",{role:"alert",className:y,style:y?void 0:Ar,children:[M,c===null&&!x&&k!==null&&!C&&he("button",{type:"button",onClick:p,style:Or,children:"Tap to retry"})]})]})}import{Fragment as Ot,jsx as ae,jsxs as Xe}from"react/jsx-runtime";var Sn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function vn(){return Xe("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 Ur({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:m,style:y,errorClassName:u,spinner:S=!0,children:c}){let{items:x,hydrated:k}=re(),{lines:p}=kt({apiUrl:e}),{startCheckout:T,loading:C,error:b,conflicts:a}=wt({apiUrl:e}),w=k&&x.length===0,P=p.some(h=>h.status==="unavailable"),s=!!l||!k||w||P||C,d;C?d=Xe(Ot,{children:[S&&ae(vn,{}),"Processing\u2026"]}):k?w?d="Cart is empty":P?d="Remove unavailable items":c!==void 0?d=c:d="Checkout":d=Xe(Ot,{children:[S&&ae(vn,{}),c??"Checkout"]});let f=a?Object.keys(a).length:0;return Xe(Ot,{children:[ae("button",{type:"button",className:m,style:y,disabled:s,onClick:()=>T(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:d}),f>0&&ae("div",{role:"alert",className:u,style:u?void 0:Sn,children:f===1?"An item in your cart changed \u2014 please review your cart and try again.":`${f} items in your cart changed \u2014 please review your cart and try again.`}),b&&ae("div",{role:"alert",className:u,style:u?void 0:Sn,children:b})]})}import{useEffect as et,useRef as kn,useState as Tt}from"react";import{Fragment as Se,jsx as U,jsxs as j}from"react/jsx-runtime";var Nr={fontSize:"1.5rem",lineHeight:1.25,fontWeight:600,margin:"0 0 0.5rem"},pe={color:"#6b7280",fontSize:"0.875rem"},Mr={display:"inline-block",padding:"0.125rem 0.5rem",margin:"0 0 1rem",borderRadius:9999,border:"1px solid #e5e7eb",background:"#f9fafb",color:"#6b7280",fontSize:"0.75rem"},Vr={textAlign:"left",border:"1px solid #e5e7eb",borderRadius:8,overflow:"hidden",margin:"1rem 0"},qr={listStyle:"none",margin:0,padding:0},$r={display:"flex",alignItems:"center",gap:"0.75rem",padding:"0.75rem"},Cn={width:56,height:56,flex:"0 0 auto",borderRadius:6,border:"1px solid #f3f4f6",background:"#f3f4f6",objectFit:"cover"},Dr={flex:"1 1 auto",minWidth:0},Br={flex:"0 0 auto",whiteSpace:"nowrap"},Fr={padding:"0.75rem",borderTop:"1px solid #e5e7eb",background:"#f9fafb"},It={display:"flex",justifyContent:"space-between",gap:"1rem",padding:"0.125rem 0"},zr={...It,fontWeight:600,marginTop:"0.5rem",paddingTop:"0.5rem",borderTop:"1px solid #e5e7eb"},jr={display:"inline-block",padding:"0.625rem 1.25rem",borderRadius:8,background:"#111827",color:"#ffffff",textDecoration:"none",fontWeight:600},Lt="af_order_confirmation_session",Kr=1800*1e3;function Wr({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:m=1500,renderNoSession:y,renderPending:u,renderPaid:S,renderFailed:c}){let[x,k]=Tt(n),[p,T]=Tt(null),[C,b]=Tt(!1),a=kn(void 0);et(()=>{if(n!==void 0){k(n);return}if(a.current!==void 0){k(a.current);return}let d=new URL(window.location.href),f=d.searchParams.get("session_id");if(f){d.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",d.toString());try{sessionStorage.setItem(Lt,JSON.stringify({id:f,ts:Date.now()}))}catch{}}else try{let h=sessionStorage.getItem(Lt);if(h){let g=JSON.parse(h);typeof g.id=="string"&&typeof g.ts=="number"&&Date.now()-g.ts<=Kr?f=g.id:sessionStorage.removeItem(Lt)}}catch{}a.current=f,k(f)},[n]),et(()=>{if(!x)return;let d=!1,f,h=Date.now(),g=async()=>{try{let _=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(_.ok){let v=await _.json();if(d||(T(v),v.status!=="pending"))return}}catch{}if(!d){if(Date.now()-h>=i){b(!0);return}f=setTimeout(g,o)}};return g(),()=>{d=!0,f&&clearTimeout(f)}},[x,e,o,i]);let w=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),P=kn(!1);et(()=>{if(!x||p===null||P.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(P.current=!0,!Ht(x)))return;let f=(p.line_items??[]).filter(h=>typeof h.variant_id=="string"&&h.variant_id.length>0).map(h=>({variantId:h.variant_id,quantity:h.quantity}));f.length>0&&Wt(f)},[x,p]);let s=w&&p.fulfillment.type==="redirect"?p.fulfillment.redirect_url:void 0;if(et(()=>{if(!s||!l)return;let d=setTimeout(()=>{window.location.href=s},m);return()=>clearTimeout(d)},[s,l,m]),x===void 0)return null;if(x===null)return y?U(Se,{children:y()}):j("div",{className:t,style:r,children:[U("h2",{children:"Thank you for your order!"}),U("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?U(Se,{children:u({timedOut:C})}):U("div",{className:t,style:r,role:"status",children:U("p",{children:C?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(w){if(S)return U(Se,{children:S(p)});let{fulfillment:d}=p,f=p.currency,h=p.amount_total!==void 0&&f?z(p.amount_total,f):null,g=p.line_items??[],_=g.some(N=>!!N.image_url),v=p.tax_behavior==="exclusive"&&typeof p.tax_total=="number"&&p.tax_total>0&&!!f,R=typeof p.shipping_total=="number"&&!!f,A=d.files??[],$=A.length===0?d.download_url:void 0;return j("div",{className:t,style:r,children:[U("h2",{style:Nr,children:"Thank you for your purchase!"}),p.is_test&&j("p",{style:Mr,children:[U("strong",{children:"Test purchase"})," \u2014 no payment was collected. Test orders only happen in the editor."]}),(g.length>0||h)&&j("div",{style:Vr,children:[g.length>0&&U("ul",{style:qr,children:g.map((N,D)=>{let O=typeof N.unit_amount=="number"&&f?z(N.unit_amount*N.quantity,f):null;return j("li",{style:{...$r,borderBottom:D<g.length-1?"1px solid #f3f4f6":void 0,opacity:N.refunded?.6:void 0},children:[_&&(N.image_url?U("img",{src:N.image_url,alt:"",width:56,height:56,style:Cn}):U("div",{style:Cn,"aria-hidden":"true"})),j("div",{style:Dr,children:[U("div",{children:N.name}),N.quantity>1&&j("div",{style:pe,children:["Qty ",N.quantity]}),N.refunded&&U("div",{style:pe,children:U("em",{children:N.refund_reason==="oversold"?"Sold out and refunded \u2014 check your email for details":"Refunded"})})]}),O&&U("div",{style:Br,children:O})]},D)})}),h&&j("div",{style:Fr,children:[R&&j("div",{style:It,children:[U("span",{style:pe,children:"Shipping"}),U("span",{children:p.shipping_total===0?"Free":z(p.shipping_total,f)})]}),v&&j("div",{style:It,children:[U("span",{style:pe,children:"Tax"}),U("span",{children:z(p.tax_total,f)})]}),j("div",{style:zr,children:[U("span",{children:"Total paid"}),U("span",{children:h})]})]})]}),p.source==="subscription"&&p.subscription&&j(Se,{children:[j("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),"."]}),j("p",{children:["You can view, update, or cancel it any time on"," ",U("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),A.length>0&&j(Se,{children:[U("p",{children:"Your downloads:"}),U("ul",{children:A.map((N,D)=>U("li",{children:U("a",{href:N.download_url,children:N.name})},D))})]}),$&&U("p",{children:U("a",{href:$,style:jr,children:"Download your file"})}),s?j("p",{children:["Taking you to your content\u2026"," ",U("a",{href:s,children:"Continue if you are not redirected"})]}):d.redirect_url?U("p",{children:U("a",{href:d.redirect_url,children:"Continue to your content"})}):null,A.length===0&&!$&&!d.redirect_url&&U("p",{style:pe,children:"A confirmation email is on its way to you."}),typeof p.order_number=="number"?j("p",{style:pe,children:["Order ",j("strong",{children:["#",p.order_number]})," \u2014 keep this if you ever need help with your order."]}):p.order_id?j("p",{style:pe,children:["Order reference: ",U("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]}):null]})}return c?U(Se,{children:c(p)}):U("div",{className:t,style:r,children:U("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 Yr,useState as Hr}from"react";import{Fragment as Xr,jsx as ve}from"react/jsx-runtime";function wn(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 Et(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var Jr={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},Gr={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 Zr({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:m,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:S,renderOption:c,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,T=k?.ready===!0,C=[...k?.plans??[]].sort((v,R)=>v.position-R.position),[b,a]=Hr(null),w=o!==void 0,P=w?o:b,s=C.map(v=>v.id).join("|"),d=C.length>0?C[0].id:null;if(Yr(()=>{if(!(!p||!T)&&!(P!==null&&C.some(v=>v.id===P))){if(d===null){if(P===null)return;w||a(null),i?.(null);return}w||a(d),i?.(d)}},[p,T,d,s,P,w]),!k)return null;if(!T)return p?x?ve(Xr,{children:x()}):ve("div",{className:l,style:m,"data-state":"unavailable",children:ve("p",{children:"This product is currently unavailable."})}):null;if(C.length===0)return null;let f=e?.base_currency!==void 0&&e?.base_currency!==null,h=r!==void 0?r:f?null:e?.unit_amount??null,g=n??e?.base_currency??e?.currency??"usd",_=[];if(!p){let v=h;_.push({plan:null,selected:P===null,price:v,priceLabel:v!==null?z(v,g):null,label:"One-time purchase",select:()=>{w||a(null),i?.(null)}})}for(let v of C){let R=v.unit_amount!==null?v.unit_amount:h!==null?wn(h,v):null,A=R!==null?z(R,g):null,$=v.title&&v.title.trim().length>0?v.title.trim():`Subscribe ${Et(v)}`,N=A?`${$} \u2014 ${A} ${Et(v)}`:`${$} \u2014 billed ${Et(v)}`;_.push({plan:v,selected:P===v.id,price:R,priceLabel:A,label:N,select:()=>{w||a(v.id),i?.(v.id)}})}return ve("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?m:{...Jr,...m},children:_.map(v=>{if(c)return ve("span",{style:{display:"contents"},children:c(v)},v.plan?.id??"one-time");let R=v.selected;return ve("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":v.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...Gr,...R?Qr:{}},onClick:v.select,children:v.plan===null&&S!==void 0?S:v.plan===null?v.priceLabel?`One-time purchase \u2014 ${v.priceLabel}`:"One-time purchase":v.label},v.plan?.id??"one-time")})})}import{useCallback as tt,useEffect as _n,useRef as ei,useState as nt}from"react";async function Q(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 m=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:m,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:m,error:y}}}function Pn(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function Ue(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 ti=1500;function xn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function ni(e,t){return e.requestId===t}function ri(e,t){return typeof window>"u"||!xn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=m=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(m))},i=m=>{if(m.source!==window.parent)return;let y=m.data;if(y?.type==="aifeatures:preview-session-ack"&&ni(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let S=y.customer;typeof S.email=="string"&&(u={email:S.email,name:typeof S.name=="string"?S.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}),ti);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ne(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=nt(()=>ce()),[o,i]=nt(null),[l,m]=nt(!1),[y,u]=nt(!1),S=ei(void 0);_n(()=>Qt(()=>{let b=ce();n(b),i(b===null?a=>Jt()??a:null)}),[]);let c=tt(async b=>{u(!0);try{let a=await Q(t,"/v1/account/verify",{method:"POST",body:{code:b}});if(a.ok&&typeof a.data.token=="string"){let P=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 We({token:a.data.token,customer:P}),n({token:a.data.token,customer:P}),i(null),m(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(m(!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;_n(()=>{if(!(typeof window>"u")&&S.current===void 0){if(!x){S.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())),S.current=a,a&&c(a)}},[c,x]);let k=tt(async b=>{if(typeof window<"u"&&xn(window)){let w=await ri(b,Te());if(w.claimed){if(w.token!==null){let P=w.customer??{email:b,name:null};return We({token:w.token,customer:P}),n({token:w.token,customer:P}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:w.error}}}let a=await Q(t,"/v1/account/login",{method:"POST",body:{email:b}});return a.ok?{ok:!0,via:"email"}:a.failure.kind==="unavailable"?(m(!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=tt(async()=>{let b=ce()?.token;b&&await Q(t,"/v1/account/logout",{method:"POST",token:b,body:{}}),ee(),n(null),i(null)},[t]),T=tt(async()=>{let b=ce();if(!b)return;let a=await Q(t,"/v1/account/me",{token:b.token}),w=()=>ce()?.token===b.token;if(a.ok){if(!w())return;let P=a.data.customer??b.customer;We({token:b.token,customer:P}),n({token:b.token,customer:P}),m(!1);return}if(a.failure.kind==="unauthorized"){if(!w())return;ee("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){m(!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:T}}import{useCallback as qe,useEffect as qt,useRef as ot,useState as $e}from"react";import{useEffect as ii,useRef as Rn,useState as ke}from"react";import{Fragment as Nt,jsx as W,jsxs as Me}from"react/jsx-runtime";var Ut={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},oi={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},si={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},An={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Ce={margin:0},ai={color:"#b91c1c",margin:0};function rt({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:m}){let y=Ne({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[S,c]=ke(""),[x,k]=ke("form"),[p,T]=ke(!1),[C,b]=ke(null),[a,w]=ke(null),[P,s]=ke(!1),d=Rn(void 0),f=Rn(!1);ii(()=>()=>{d.current&&clearTimeout(d.current)},[]);let h=()=>{s(!1),d.current&&clearTimeout(d.current),d.current=setTimeout(()=>s(!0),r)},g=async()=>{let R=S.trim();if(!R||p||f.current)return;f.current=!0,T(!0),b(null),w(null);let A=await u.login(R);if(f.current=!1,T(!1),A.ok){if(A.via==="preview")return;k("sent"),h();return}A.code!=="unavailable"&&(b(A.code==="rate_limited"?"rate_limited":"error"),w(A.error))};if(u.status==="unavailable")return m?W(Nt,{children:m()}):W("div",{className:n,style:n?o:{...Ut,...o},"data-state":"unavailable",children:W("p",{style:Ce,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:S.trim(),canResend:P,resend:()=>{g(),h()},submitting:p,reset:()=>k("form")};return l?W(Nt,{children:l(R)}):Me("div",{className:n,style:n?o:{...Ut,...o},"data-state":"sent",children:[Me("p",{style:Ce,children:["Check your email \u2014 if ",W("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),P?Me("p",{style:Ce,children:["Didn't get it?"," ",W("button",{type:"button",style:An,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",W("button",{type:"button",style:An,onClick:R.reset,children:"use a different email"}),"."]}):W("p",{style:Ce,children:"It can take a minute to arrive."})]})}let _={email:S,setEmail:c,submit:()=>void g(),submitting:p,errorKind:C,errorMessage:a,reason:u.reason};if(i)return W(Nt,{children:i(_)});let v=R=>{R.preventDefault(),_.submit()};return Me("form",{className:n,style:n?o:{...Ut,...o},onSubmit:v,"data-state":"form",children:[u.reason==="session_expired"&&W("p",{style:Ce,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&W("p",{style:Ce,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),Me("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[W("span",{children:"Email address"}),W("input",{type:"email",value:S,onChange:R=>c(R.target.value),autoComplete:"email",required:!0,style:oi})]}),W("button",{type:"submit",style:si,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&W("p",{style:ai,role:"alert",children:C==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}import{Fragment as di,jsx as te,jsxs as we}from"react/jsx-runtime";var ui={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},li={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},Ve={color:"#6b7280",fontSize:"0.875rem"};function ci(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 Mt({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?te(di,{children:o()}):we("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&te("h3",{children:n}),te("p",{style:Ve,children:"No orders yet."})]}):we("div",{className:t,style:r,children:[n!==null&&te("h3",{children:n}),te("ul",{style:t?void 0:ui,children:e.map(l=>{if(i)return te("li",{style:{display:"contents"},children:i(l)},l.id);let m=Ue(l.created_at),y=ci(l);return we("li",{style:t?void 0:li,children:[we("div",{children:[l.order_number!==null&&we("strong",{children:["Order #",l.order_number]})," ",m&&te("span",{style:Ve,children:m})," ",l.source==="subscription"&&te("span",{style:Ve,children:"\xB7 subscription"}),y&&we("span",{style:Ve,children:[" \xB7 ",y]})]}),l.line_items.length>0&&te("div",{style:Ve,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:z(l.amount_total,l.currency)})]},l.id)})})]})}import{useEffect as On,useRef as pi,useState as ie}from"react";import{Fragment as In,jsx as B,jsxs as Z}from"react/jsx-runtime";var fi={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},mi={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},Pe={color:"#6b7280",fontSize:"0.875rem"},gi={color:"#b91c1c",fontSize:"0.875rem",margin:0},yi={color:"#065f46",fontSize:"0.875rem",margin:0},Vt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},fe={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Ln={...fe,border:"1px solid #111827",background:"#111827",color:"white"},bi={...fe,border:"1px solid #b91c1c",color:"#b91c1c"},hi={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},Tn={panel:"none",mutation:null,portalRefused:!1};function Si(e){let t=Ue(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 vi({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=ie(e?.name??""),[m,y]=ie(o?.line1??""),[u,S]=ie(o?.line2??""),[c,x]=ie(o?.city??""),[k,p]=ie(o?.state??""),[T,C]=ie(o?.postal_code??""),[b,a]=ie(o?.country??""),w=(P,s,d,f)=>Z("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[B("span",{children:P}),B("input",{style:hi,value:s,onChange:h=>d(h.target.value),required:f?.required,maxLength:f?.maxLength})]});return Z("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:P=>{P.preventDefault(),r({name:i.trim()||null,address:{line1:m.trim(),line2:u.trim()||null,city:c.trim()||null,state:k.trim()||null,postal_code:T.trim()||null,country:b.trim().toUpperCase()}})},children:[w("Name",i,l),w("Address line 1",m,y,{required:!0}),w("Address line 2",u,S),w("City",c,x),w("State / region",k,p),w("Postal code",T,C),w("Country (2-letter code)",b,a,{required:!0,maxLength:2}),Z("div",{style:Vt,children:[B("button",{type:"submit",style:Ln,disabled:t,children:t?"Saving\u2026":"Save address"}),B("button",{type:"button",style:fe,onClick:n,disabled:t,children:"Cancel"})]})]})}function it({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:m,heading:y="Your subscriptions",renderEmpty:u,renderRow:S}){let[c,x]=ie(t),[k,p]=ie({}),T=pi(new Set);On(()=>{x(t)},[t]),On(()=>{let s=d=>{d.persisted&&(T.current.clear(),p(f=>{let h=!1,g={};for(let[_,v]of Object.entries(f))v.mutation?.phase==="pending"?(g[_]={...v,mutation:null},h=!0):g[_]=v;return h?g:f}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let C=(s,d)=>p(f=>({...f,[s]:{...f[s]??Tn,...d}})),b=s=>{x(d=>d.map(f=>f.id===s.id?s:f)),i?.(s)},a=async(s,d,f,h)=>{if(T.current.has(s.id))return{ok:!1};T.current.add(s.id);try{C(s.id,{mutation:{kind:d,phase:"pending"}});let g=await Q(e,f,{method:"POST",token:r.token,body:h??{}});if(g.ok)return{ok:!0,data:g.data};let{failure:_}=g;return _.kind==="unauthorized"?(n?.({code:_.code,error:_.error}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="unavailable"?(o?.(),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="ended"?(b({...s,ended:!0,status:"canceled"}),C(s.id,{mutation:null,panel:"none"}),{ok:!1}):_.kind==="http"&&_.code==="portal_unavailable"?(C(s.id,{portalRefused:!0,mutation:{kind:d,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(C(s.id,{mutation:{kind:d,phase:"error",error:_.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":_.error}}),{ok:!1})}finally{T.current.delete(s.id)}},w=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"},P=s=>{let d=k[s.id]??Tn,f=w(s);return{subscription:s,panel:d.panel,mutation:d.mutation,portalHidden:s.is_test||d.portalRefused,openCancelConfirm:()=>C(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>C(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let h=await a(s,"cancel",f.cancel);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:f.reactivate!==null,reactivate:()=>{f.reactivate&&(async()=>{let h=await a(s,"reactivate",f.reactivate);if(h.ok){let g=h.data.subscription;g&&b(g),C(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{f.address&&C(s.id,{panel:"address",mutation:null})},saveAddress:h=>{f.address&&(async()=>{let g=await a(s,"address",f.address,{shipping_address:h});if(g.ok){let _=g.data.subscription;_&&b(_),C(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let h=await a(s,"portal",f.portal);h.ok&&typeof h.data.url=="string"?window.location.href=h.data.url:h.ok&&C(s.id,{mutation:{kind:"portal",phase:"error",error:"Card update is temporarily unavailable."}})})()}}};return c.length===0?u?B(In,{children:u()}):Z("div",{className:l,style:m,"data-state":"empty",children:[y!==null&&B("h3",{children:y}),B("p",{style:Pe,children:"No subscriptions."})]}):Z("div",{className:l,style:m,children:[y!==null&&B("h3",{children:y}),B("ul",{style:l?void 0:fi,children:c.map(s=>{let d=P(s);return S?B("li",{style:{display:"contents"},children:S(d)},s.id):B("li",{style:l?void 0:mi,"data-status":s.status,"data-ended":s.ended||void 0,children:B(ki,{ctx:d})},s.id)})})]})}function ki({ctx:e}){let t=e.subscription,r=Si(t),n=Ue(t.current_period_end),o=`${z(t.current_amount,t.currency)} ${Pn(t.plan_interval,t.plan_interval_count)}`,i=e.mutation?.phase==="pending",l=i?e.mutation?.kind:null;return Z(In,{children:[Z("div",{children:[B("strong",{children:t.plan_title??"Subscription"})," ",Z("span",{style:Pe,children:["\xB7 ",o]}),t.is_test&&B("span",{style:Pe,children:" \xB7 test"})]}),B("div",{style:r.tone==="warn"?void 0:Pe,children:r.text}),t.ended?B("p",{style:Pe,children:"This subscription has ended \u2014 to start again, subscribe from the product page."}):e.panel==="confirm_cancel"?Z("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[B("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."}),Z("div",{style:Vt,children:[B("button",{type:"button",style:bi,onClick:e.confirmCancel,disabled:i,children:l==="cancel"?"Canceling\u2026":"Confirm cancellation"}),B("button",{type:"button",style:fe,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?B(vi,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):Z("div",{style:Vt,children:[t.cancel_at_period_end?e.reactivateAvailable?B("button",{type:"button",style:Ln,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):B("span",{style:Pe,children:"To keep this subscription, sign in with your email address on this page."}):B("button",{type:"button",style:fe,onClick:e.openCancelConfirm,disabled:i,children:"Cancel subscription"}),t.shipping_address!==void 0&&!t.cancel_at_period_end&&B("button",{type:"button",style:fe,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&B("button",{type:"button",style:fe,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&B("p",{style:gi,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&B("p",{style:yi,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 _e,jsx as q,jsxs as G}from"react/jsx-runtime";var Ci={display:"flex",flexDirection:"column",gap:"1.25rem"},En={color:"#6b7280",fontSize:"0.875rem"},wi={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},Un={color:"#b91c1c"},st={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function Pi({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:m,renderHeader:y,renderPmBanner:u,renderManageExpired:S}){let c=Ne({apiUrl:e}),x=ot(void 0),[k,p]=$e(null),[T,C]=$e(!1);qt(()=>{if(!(typeof window>"u")){if(x.current===void 0){let I=new URL(window.location.href),L=I.searchParams.get("manage_code"),F=I.searchParams.get("pm");(L!==null||F!==null)&&(I.searchParams.delete("manage_code"),I.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",I.toString())),x.current={manageCode:L,pmUpdated:F==="updated"}}p(x.current.manageCode),C(x.current.pmUpdated)}},[]);let[b,a]=$e(null),w=ot(!1),P=ot(0),s=qe(I=>{a({phase:"verifying"}),(async()=>{let L=await Q(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]);qt(()=>{!k||w.current||(w.current=!0,s(k))},[k,s]);let d=qe(async()=>{let I=b;if(!I||I.phase!=="active")return;let L=++P.current,F=await Q(e,"/v1/account/manage/subscription",{token:I.token});L===P.current&&(F.ok&&F.data.subscription?a({phase:"active",token:I.token,sub:F.data.subscription,siteName:typeof F.data.site?.name=="string"?F.data.site.name:I.siteName}):!F.ok&&F.failure.kind==="unauthorized"?a({phase:"expired"}):!F.ok&&F.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[f,h]=$e({phase:"loading"}),[g,_]=$e(0),v=g>0,R=ot(0),A=c.token,$=qe(async()=>{if(!A)return;let I=++R.current,L=await Q(e,"/v1/account/me",{token:A});if(I===R.current){if(L.ok){h({phase:"ready",data:L.data});return}if(L.failure.kind==="unauthorized"){ee("session_expired");return}if(L.failure.kind==="unavailable"){ee();return}h({phase:"error",error:L.failure.error})}},[e,A]);qt(()=>{!A||k||(h({phase:"loading"}),$())},[A,k,$]);let N=qe(async()=>{_(I=>I+1);try{b&&b.phase==="active"?await d():await $()}finally{_(I=>I-1)}},[b,d,$]),D=qe(I=>{R.current++,P.current++,a(L=>L&&L.phase==="active"&&L.sub.id===I.id?{...L,sub:I}:L),h(L=>L.phase==="ready"?{phase:"ready",data:{...L.data,subscriptions:L.data.subscriptions.map(F=>F.id===I.id?I:F)}}:L)},[]),O=t?r:{...Ci,...r},E=I=>{if(!T)return null;let F={state:I.some(J=>!J.ended&&(J.status==="past_due"||J.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void N(),checking:v};return u?u(F):q("div",{style:wi,role:"status","data-pm-state":F.state,children:F.state==="retrying"?G(_e,{children:[q("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),q("p",{style:{margin:"0.375rem 0 0"},children:q("button",{type:"button",style:st,onClick:F.checkAgain,disabled:v,children:v?"Checking\u2026":"Check again"})})]}):q("p",{style:{margin:0},children:"Card updated \u2014 your subscription is back in good standing."})})};if(k)return!b||b.phase==="verifying"?i?q(_e,{children:i()}):q("div",{className:t,style:O,role:"status",children:q("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?G("div",{className:t,style:O,children:[E([b.sub]),q(it,{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"?q("div",{className:t,style:O,"data-state":"unavailable",children:q("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?G("div",{className:t,style:O,children:[q("p",{style:Un,role:"alert",children:b.error}),q("p",{children:q("button",{type:"button",style:st,onClick:()=>s(k),children:"Try again"})})]}):G("div",{className:t,style:O,"data-state":"manage-expired",children:[S?S():q("p",{children:"This manage link is no longer valid. Sign in below with the email you used at checkout to manage your subscription."}),q(rt,{apiUrl:e,session:c,resendDelayMs:n,...o})]});if(c.status==="pending")return i?q(_e,{children:i()}):q("div",{className:t,style:O,role:"status",children:q("p",{children:"Signing you in\u2026"})});if(c.status!=="signed_in")return q("div",{className:t,style:O,children:q(rt,{apiUrl:e,session:c,resendDelayMs:n,...o})});if(f.phase==="loading")return i?q(_e,{children:i()}):q("div",{className:t,style:O,role:"status",children:q("p",{children:"Loading your account\u2026"})});if(f.phase==="error")return l?q(_e,{children:l({error:f.error,retry:()=>void $()})}):G("div",{className:t,style:O,children:[G("p",{style:Un,role:"alert",children:["We couldn't load your account \u2014 ",f.error]}),q("p",{children:q("button",{type:"button",style:st,onClick:()=>void $(),children:"Try again"})})]});let{data:M}=f,Y=M.customer??c.customer??{email:"",name:null},V=()=>void c.logout(),K=M.orders.length===0&&M.subscriptions.length===0;return G("div",{className:t,style:O,children:[y?y({customer:Y,site:M.site??null,signOut:V}):G("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[G("div",{children:[q("h2",{style:{margin:0},children:"Your account"}),G("p",{style:{...En,margin:0},children:["Signed in as ",Y.email]})]}),q("button",{type:"button",style:st,onClick:V,children:"Sign out"})]}),E(M.subscriptions),K?m?m():G("p",{style:En,children:["Nothing here yet \u2014 orders and subscriptions for ",Y.email," ","will show up on this page."]}):G(_e,{children:[M.subscriptions.length>0&&q(it,{apiUrl:e,subscriptions:M.subscriptions,auth:{kind:"session",token:A},onSubscriptionChange:D,onAuthError:()=>ee("session_expired"),onUnavailable:()=>ee()}),q(Mt,{orders:M.orders})]})]})}export{rt as AccountLogin,Mt as AccountOrders,Pi as AccountPage,Er as AddToCartButton,Vn as AifeaturesCaptcha,_r as BuyButton,Ur as CartCheckoutButton,_t as MARKET_COUNTRIES,rn as MAX_CART_LINES,Wr as OrderConfirmation,Zr as PlanPicker,sr as ProductPrice,it as SubscriptionList,vr as VariantPicker,Ft as ZERO_DECIMAL_CURRENCIES,pt as applySelectionToUrl,z as formatPrice,me as getOptions,oe as getVariants,xe as isMultiVariant,at as isValueAvailable,ut as isValueInCatalog,wn as planRecurringAmount,lt as reanchorSelection,le as resolveVariant,ze as searchFromSelection,Re as selectedImages,zt as selectedValues,dt as selectionFromSearch,re as useCart,wt as useCartCheckout,kt as useCartItems,er as useCartSummary,St as useCheckout,ir as useMarket,ue as useProduct,Ne as useSession,ne as valueSlug,ct as variantPriceRange};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aifeatures/react",
3
- "version": "0.5.4",
3
+ "version": "0.6.0",
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",