@aifeatures/react 0.3.1 → 0.5.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 Ue=Object.defineProperty;var Ct=Object.getOwnPropertyDescriptor;var St=Object.getOwnPropertyNames;var vt=Object.prototype.hasOwnProperty;var kt=(e,t)=>{for(var r in t)Ue(e,r,{get:t[r],enumerable:!0})},wt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of St(t))!vt.call(e,i)&&i!==r&&Ue(e,i,{get:()=>t[i],enumerable:!(n=Ct(t,i))||n.enumerable});return e};var _t=e=>wt(Ue({},"__esModule",{value:!0}),e);var Zt={};kt(Zt,{AddToCartButton:()=>mt,AifeaturesCaptcha:()=>Ge,BuyButton:()=>pt,CartCheckoutButton:()=>ht,MARKET_COUNTRIES:()=>Ae,MAX_CART_LINES:()=>We,OrderConfirmation:()=>bt,ProductPrice:()=>ut,VariantPicker:()=>lt,ZERO_DECIMAL_CURRENCIES:()=>Me,applySelectionToUrl:()=>Re,formatPrice:()=>F,getOptions:()=>le,getVariants:()=>ie,isMultiVariant:()=>fe,isValueAvailable:()=>ke,isValueInCatalog:()=>we,reanchorSelection:()=>_e,resolveVariant:()=>ue,searchFromSelection:()=>be,selectedImages:()=>pe,selectedValues:()=>Ne,selectionFromSearch:()=>xe,useCart:()=>re,useCartCheckout:()=>Ee,useCartItems:()=>Le,useCartSummary:()=>it,useCheckout:()=>Oe,useMarket:()=>st,useProduct:()=>se,valueSlug:()=>ee,variantPriceRange:()=>Pe});module.exports=_t(Zt);var he=require("react"),Je=require("@marsidev/react-turnstile"),Ve=require("react/jsx-runtime");function Ge({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:i}){let[o,p]=(0,he.useState)(null),[l,h]=(0,he.useState)(!0);return(0,he.useEffect)(()=>{h(!0),fetch(`${t}/f/${e}/config`).then(s=>s.json()).then(s=>{p(s.turnstile_sitekey),h(!1)}).catch(()=>{h(!1)})},[e,t]),l||!o?null:(0,Ve.jsx)("div",{className:i,children:(0,Ve.jsx)(Je.Turnstile,{siteKey:o,onSuccess:r,onError:n,onExpire:n,options:{theme:"light"}})})}var X=require("react"),Se=[1e3,3e3];function se(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[i,o]=(0,X.useState)(null),[p,l]=(0,X.useState)(!0),[h,s]=(0,X.useState)(null),[d,a]=(0,X.useState)(0),b=(0,X.useRef)(e);(0,X.useEffect)(()=>{let u=!1,P;l(!0),s(null),b.current!==e&&(b.current=e,o(null));let I=O=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async R=>{let T=await R.json().catch(()=>null);if(!u)if(!R.ok||!T){if(R.status>=500&&O<Se.length){P=setTimeout(()=>I(O+1),Se[O]);return}s(T?.error??`Request failed (${R.status})`),o(null),l(!1)}else o(T),l(!1)}).catch(R=>{if(!u){if(O<Se.length){P=setTimeout(()=>I(O+1),Se[O]);return}s(R instanceof Error?R.message:"Failed to load product"),l(!1)}})};return I(0),()=>{u=!0,P&&clearTimeout(P)}},[e,r,n,d]);let m=(0,X.useCallback)(()=>a(u=>u+1),[]);return{product:i,loading:p,error:h,refresh:m}}var Me=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function F(e,t,r){let n=Me.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 ie(e){return e.variants??[]}function le(e){return e.options??[]}function fe(e){return le(e).length>0}function ve(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ue(e,t){let r=Object.keys(t);return e.find(n=>{let i=n.option_values;return i.length!==r.length?!1:i.every(o=>t[o.option_id]===o.value_id)})??null}function ke(e,t,r,n){return e.some(i=>{let o=ve(i);if(o[r]!==n)return!1;for(let[p,l]of Object.entries(t))if(p!==r&&o[p]!==l)return!1;return!0})}function we(e,t,r){return e.some(n=>ve(n)[t]===r)}function _e(e,t,r,n){let i={[r]:n};for(let[p,l]of Object.entries(t)){if(p===r)continue;e.some(s=>{let d=ve(s);return d[r]===n&&d[p]===l})&&(i[p]=l)}return e.some(p=>{let l=ve(p);return Object.entries(i).every(([h,s])=>l[h]===s)})?i:{[r]:n}}function Pe(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 Ne(e,t){let r={};for(let n of le(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(p=>p.id===i);o&&(r[n.title]=o.value)}return r}function ee(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function xe(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((o,p)=>{n.has(ee(p))||n.set(ee(p),o)});let i={};for(let o of le(e)){let p=ee(o.title);if(p.length===0)continue;let l=n.get(p);if(l===void 0)continue;let h=ee(l);if(h.length===0)continue;let s=o.values.find(d=>ee(d.value)===h);s&&(i[o.id]=s.id)}return i}function be(e,t){let r={};for(let[n,i]of Object.entries(Ne(e,t))){let o=ee(n),p=ee(i);o.length===0||p.length===0||(r[o]=p)}return r}function pe(e,t){let r=[];for(let n of le(e)){let i=t[n.id];if(!i)continue;let o=n.values.find(p=>p.id===i);o?.images?.length&&r.push(...o.images)}return r.length>0?r:e.images??[]}function Re(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of le(e)){let i=ee(n.title);i.length!==0&&r.searchParams.delete(i)}for(let[n,i]of Object.entries(be(e,t)))r.searchParams.set(n,i);window.history.replaceState(window.history.state,"",r.toString())}var H=require("react");var Be="aifeatures_cart",De="aifeatures_market",Qe="aifeatures_cart_cleared";var qe="aifeatures:cart-storage",Ce=new Map;function $e(e){if(Ce.has(e))return Ce.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Fe(e,t){if(typeof window>"u"){Ce.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Ce.delete(e)}catch{Ce.set(e,t)}Pt(e)}function Pt(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(qe,{detail:{key:e}}))}catch{}}function Ze(e,t){if(typeof window>"u")return()=>{};let r=i=>{(i.key===e||i.key===null)&&t()},n=i=>{i.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(qe,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(qe,n)}}function xt(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[p,l]of Object.entries(t.selection))typeof l=="string"&&(n[p]=l);let i=typeof t.display=="object"&&t.display!==null?t.display:{},o={name:typeof i.name=="string"?i.name:"",variantTitle:typeof i.variantTitle=="string"?i.variantTitle:null,image:typeof i.image=="string"?i.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:o}}function ce(){let e=$e(Be);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let i of t){let o=xt(i);o&&!n.has(o.variantId)&&(n.add(o.variantId),r.push(o))}return r}function te(e){Fe(Be,JSON.stringify(e))}function Xe(e){return Ze(Be,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 i=t.get(n.variantId);if(i===void 0){r.push(n);continue}let o=n.quantity-i;o>0&&r.push({...n,quantity:o})}te(r)}function j(){let e=$e(De);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function tt(e){Fe(De,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function me(e){return Ze(De,e)}function nt(e){let t=[],r=$e(Qe);if(r)try{let i=JSON.parse(r);Array.isArray(i)&&(t=i.filter(o=>typeof o=="object"&&o!==null&&typeof o.id=="string"&&typeof o.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(i=>i.ts>n),t.some(i=>i.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Fe(Qe,JSON.stringify(t)),!0)}var Rt=1500;function je(){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 Ie(e,t){return!("requestId"in e)||e.requestId===t}function ze(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,i=l=>{n||(n=!0,window.removeEventListener("message",o),clearTimeout(p),r(l))},o=l=>{if(l.source!==window.parent)return;let h=l.data;h?.type==="aifeatures:test-checkout-ack"&&Ie(h,t)&&i(h.status==="accepted")},p=setTimeout(()=>i(!1),Rt);window.addEventListener("message",o);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{i(!1)}})}function Oe(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,H.useState)(!1),[i,o]=(0,H.useState)(null),[p,l]=(0,H.useState)(null),h=(0,H.useRef)(!1),s=(0,H.useRef)(null);return(0,H.useEffect)(()=>{let a=b=>{b.persisted&&(h.current=!1,n(!1))};return window.addEventListener("pageshow",a),()=>window.removeEventListener("pageshow",a)},[]),(0,H.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let a=b=>{if(b.source!==window.parent)return;let m=b.data;if(m?.type!=="aifeatures:test-checkout-ack"||m.status!=="failed")return;let u=s.current;u===null||!Ie(m,u)||(s.current=null,o(typeof m.error=="string"&&m.error?m.error:"The test purchase could not be created."),h.current=!1,n(!1))};return window.addEventListener("message",a),()=>window.removeEventListener("message",a)},[]),{startCheckout:(0,H.useCallback)(async({productId:a,variantId:b,quantity:m,amount:u,metadata:P,successUrl:I,cancelUrl:O,customerEmail:R,expectedUnitAmount:T,expectedCurrency:v})=>{if(!h.current){h.current=!0,n(!0),o(null),l(null);try{let f=j(),c=await fetch(`${t}/v1/p/${a}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...b!==void 0?{variant_id:b}:{},...m!==void 0?{quantity:m}:{},...u!==void 0?{amount:u}:{},...P!==void 0?{metadata:P}:{},...R!==void 0?{customer_email:R}:{},...T!==void 0&&v!==void 0?{expected_unit_amount:T,expected_currency:v}:{},...f!==null?{country:f}:{},success_url:I??`${window.location.origin}/order/confirmation`,cancel_url:O??window.location.href})}),g=await c.json().catch(()=>null);if(!c.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){l({currentUnitAmount:g.current_unit_amount,currency:g.currency}),o(`The price has changed to ${F(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),h.current=!1,n(!1);return}if(g?.code==="preview_domain"){let k=je();if(s.current=k,await ze({productId:a,...b!==void 0?{variantId:b}:{},...m!==void 0?{quantity:m}:{},...u!==void 0?{amount:u}:{},...R!==void 0?{customerEmail:R}:{}},k))return;s.current=null}o(g?.error??`Checkout failed (${c.status})`),h.current=!1,n(!1);return}if(!g?.url){o("Checkout failed: no redirect URL returned"),h.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=g.url;return}catch{if(window.open(g.url,"_blank")){h.current=!1,n(!1);return}}window.location.href=g.url}catch(f){o(f instanceof Error?f.message:"Checkout failed"),h.current=!1,n(!1)}}},[t]),loading:r,error:i,priceChange:p}}var ne=require("react");var We=20;function rt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function re(){let[e,t]=(0,ne.useState)([]),[r,n]=(0,ne.useState)(!1);(0,ne.useEffect)(()=>{let s=()=>t(ce());return s(),n(!0),Xe(s)},[]);let i=(0,ne.useCallback)(s=>{let d=ce(),a=rt(s.quantity);return d.find(m=>m.variantId===s.variantId)?(te(d.map(m=>m.variantId===s.variantId?{...m,quantity:m.quantity+a,selection:s.selection??m.selection,display:s.display}:m)),{ok:!0}):d.length>=We?{ok:!1,reason:"cart_full"}:(te([...d,{productId:s.productId,variantId:s.variantId,quantity:a,selection:s.selection??{},display:s.display}]),{ok:!0})},[]),o=(0,ne.useCallback)(s=>{te(ce().filter(d=>d.variantId!==s))},[]),p=(0,ne.useCallback)((s,d)=>{let a=ce();if(d<=0){te(a.filter(m=>m.variantId!==s));return}let b=rt(d);te(a.map(m=>m.variantId===s?{...m,quantity:b}:m))},[]),l=(0,ne.useCallback)(()=>{te([])},[]),h=e.reduce((s,d)=>s+d.quantity,0);return{items:e,count:h,hydrated:r,add:i,remove:o,setQuantity:p,clear:l}}var N=require("react");var Te={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},It={...Te,inStock:!0,status:"error"};function Ot(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Le(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=re(),[i,o]=(0,N.useState)({}),[p,l]=(0,N.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[h,s]=(0,N.useState)(!0),[d,a]=(0,N.useState)(null),[b,m]=(0,N.useState)(0),u=(0,N.useRef)(new Set),P=(0,N.useMemo)(()=>JSON.stringify(r.map(v=>[v.productId,v.variantId,v.selection])),[r]),I=(0,N.useCallback)(()=>m(v=>v+1),[]);(0,N.useEffect)(()=>me(I),[I]),(0,N.useEffect)(()=>{if(!n)return;if(r.length===0){o({}),l({shippingRates:null,freeShippingOver:null,shippingCountries:null}),a(null),s(!1);return}let v=!1;s(!0);let f=r,c=[...new Set(f.map(k=>k.productId))],g=async k=>{let y=new Map;return await Promise.all(c.map(async C=>{try{let _=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${k?`?country=${encodeURIComponent(k)}`:""}`);if(_.status===404){y.set(C,{kind:"not_found"});return}if(!_.ok){y.set(C,{kind:"error",message:`Request failed (${_.status})`});return}let w=await _.json();y.set(C,{kind:"ok",product:w})}catch(_){y.set(C,{kind:"error",message:_ instanceof Error?_.message:"Failed to load product"})}})),y};return(async()=>{let k=j(),y=await g(k);if(k){let S=[...y.values()].filter(U=>U.kind==="ok"),E=S.filter(U=>U.product.base_currency);E.length>0&&E.length<S.length&&(y=await g(null))}if(v)return;let C=null,_=null,w=null;for(let S of c){let E=y.get(S);!E||E.kind!=="ok"||(C===null&&E.product.shipping_rates&&(C=E.product.shipping_rates),_===null&&E.product.free_shipping_over!=null&&(_=E.product.free_shipping_over),w===null&&E.product.shipping_countries&&(w=E.product.shipping_countries))}let L={},B=new Map,Q=null;for(let S of f){let E=y.get(S.productId);if(!E||E.kind==="error"){L[S.variantId]=It,E&&Q===null&&(Q=E.message);continue}if(E.kind==="not_found"){L[S.variantId]=Te;continue}let{product:U}=E;if(!U.active||U.purchasable===!1){L[S.variantId]=Te;continue}let W=U.variants??[],Z=W.find(ae=>ae.id===S.variantId)??null,K=S.variantId;if(!Z){let ae=ue(W,S.selection);if(!ae){L[S.variantId]=Te;continue}let Ye=B.get(S.variantId)??{};Ye.reanchorTo={variantId:ae.id,selection:Ot(ae)},B.set(S.variantId,Ye),u.current.add(ae.id),Z=ae,K=ae.id}let $=pe(U,S.selection)[0]??null,ye={image:$,unitAmount:Z.unit_amount,currency:Z.currency,baseCurrency:U.base_currency??null,inStock:Z.in_stock,available:Z.available,maxQuantity:U.max_quantity,pdpSearch:be(U,S.selection),status:u.current.has(K)?"reanchored":"ok"};L[S.variantId]=ye,L[K]=ye;let He=B.get(S.variantId)??{};He.display={name:U.name,variantTitle:Z.title,image:$},B.set(S.variantId,He)}let A=new Set(f.map(S=>S.variantId));for(let S of[...u.current])!A.has(S)&&!(S in L)&&u.current.delete(S);if(B.size>0){let S=ce(),E=[],U=new Map,W=!1;for(let Z of S){let K=B.get(Z.variantId),$={...Z};K?.reanchorTo&&($.variantId=K.reanchorTo.variantId,$.selection=K.reanchorTo.selection,W=!0),K?.display&&($.display.name!==K.display.name||$.display.variantTitle!==K.display.variantTitle||$.display.image!==K.display.image)&&($.display=K.display,W=!0);let ye=U.get($.variantId);if(ye){ye.quantity+=$.quantity,W=!0;continue}E.push($),U.set($.variantId,$)}W&&te(E)}v||(o(L),l({shippingRates:C,freeShippingOver:_,shippingCountries:w}),a(Q),s(!1))})(),()=>{v=!0}},[n,P,t,b]);let O=(0,N.useMemo)(()=>r.map(v=>{let f=i[v.variantId];return f?{...v,...f,image:f.image??v.display.image}:{...v,image:v.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,i]),{subtotal:R,currency:T}=(0,N.useMemo)(()=>{let v=0,f=null;for(let c of O)c.unitAmount===null||c.currency===null||(v+=c.unitAmount*c.quantity,f=f??c.currency);return{subtotal:v,currency:f}},[O]);return{lines:O,subtotal:R,currency:T,shippingRates:p.shippingRates,freeShippingOver:p.freeShippingOver,shippingCountries:p.shippingCountries,loading:h,error:d,refresh:I}}var q=require("react");var Tt=2e3;function it(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:i,hydrated:o}=re(),[p,l]=(0,q.useState)(null),[h,s]=(0,q.useState)(!1),[d,a]=(0,q.useState)(null),[b,m]=(0,q.useState)(null),[u,P]=(0,q.useState)(0);(0,q.useEffect)(()=>(m(j()),me(()=>m(j()))),[]);let I=(0,q.useMemo)(()=>i.map(f=>`${f.variantId}:${f.quantity}`).sort().join(","),[i]),O=(0,q.useCallback)(()=>P(f=>f+1),[]),R=(0,q.useRef)(0),T=(0,q.useRef)(!1),v=(0,q.useRef)("idle");return(0,q.useEffect)(()=>{if(!o)return;if(i.length===0){l(null),a(null),s(!1);return}let f=++R.current,c=new AbortController,g=!1,k,y=T.current?r:0;T.current=!0,v.current=v.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{s(!0);try{let _=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:c.signal,body:JSON.stringify({items:i.map(L=>({variant_id:L.variantId,quantity:L.quantity})),...b?{country:b}:{},...n?{shipping_option:n}:{}})});if(g||f!==R.current)return;if(!_.ok){if(_.status===429){let L=v.current==="idle";L&&(k=setTimeout(()=>{g||f!==R.current||(v.current="pending",P(B=>B+1))},Tt)),a(L?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else a(`Could not price this cart (${_.status})`);return}let w=await _.json();if(g||f!==R.current)return;l({currency:w.currency,subtotal:w.subtotal,shipping:w.shipping?{options:w.shipping.options.map(L=>({label:L.label,amount:L.amount,undiscountedAmount:L.undiscounted_amount})),selectedAmount:w.shipping.selected_amount,selectedLabel:w.shipping.selected_label,freeShippingOver:w.shipping.free_shipping_over,freeShippingCurrency:w.shipping.free_shipping_currency,thresholdMet:w.shipping.threshold_met,collectsAddress:w.shipping.collects_address}:null,total:w.total,totalIsFinal:w.total_is_final,tax:w.tax??null,unavailableVariantIds:w.unavailable_variant_ids}),a(null)}catch(_){if(g||c.signal.aborted||f!==R.current)return;a(_ instanceof Error?_.message:"Could not price this cart")}finally{!g&&f===R.current&&s(!1)}},y);return()=>{g=!0,clearTimeout(C),k!==void 0&&clearTimeout(k),c.abort()}},[o,I,b,t,r,n,u]),{summary:p,loading:h,error:d,refresh:O}}var z=require("react");function Ee(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,z.useState)(!1),[i,o]=(0,z.useState)(null),[p,l]=(0,z.useState)(null),[h,s]=(0,z.useState)(null),d=(0,z.useRef)(!1),a=(0,z.useRef)(null);return(0,z.useEffect)(()=>{let m=u=>{u.persisted&&(d.current=!1,n(!1))};return window.addEventListener("pageshow",m),()=>window.removeEventListener("pageshow",m)},[]),(0,z.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let m=u=>{if(u.source!==window.parent)return;let P=u.data;if(P?.type!=="aifeatures:test-checkout-ack"||P.status!=="failed")return;let I=a.current;I===null||!Ie(P,I)||(a.current=null,o(typeof P.error=="string"&&P.error?P.error:"The test purchase could not be created."),d.current=!1,n(!1))};return window.addEventListener("message",m),()=>window.removeEventListener("message",m)},[]),{startCheckout:(0,z.useCallback)(async(m,{successUrl:u,cancelUrl:P,customerEmail:I,metadata:O,shippingOption:R}={})=>{if(!d.current){d.current=!0,n(!0),o(null),l(null),s(null);try{let T=j(),v=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:m.map(c=>({variant_id:c.variantId,quantity:c.quantity,...typeof c.unitAmount=="number"&&typeof c.currency=="string"?{expected_unit_amount:c.unitAmount,expected_currency:c.currency}:{}})),...T!==null?{country:T}:{},...R?{shipping_option:R}:{},...O!==void 0?{metadata:O}:{},...I!==void 0?{customer_email:I}:{},success_url:u??`${window.location.origin}/order/confirmation`,cancel_url:P??window.location.href})}),f=await v.json().catch(()=>null);if(!v.ok){if(f?.code==="shipping_option_unavailable"&&typeof f.requested=="string"&&Array.isArray(f.available)){s({requested:f.requested,available:f.available,currency:typeof f.currency=="string"?f.currency:""}),d.current=!1,n(!1);return}if(f?.error==="cart_conflict"&&Array.isArray(f.items)){let c={};for(let g of f.items)g&&typeof g.variant_id=="string"&&(c[g.variant_id]=g);l(c),d.current=!1,n(!1);return}if(f?.code==="preview_domain"){let c=je();if(a.current=c,await ze({items:m.map(k=>({productId:k.productId,variantId:k.variantId,quantity:k.quantity})),...I!==void 0?{customerEmail:I}:{}},c))return;a.current=null}o(f?.error??`Checkout failed (${v.status})`),d.current=!1,n(!1);return}if(!f?.url){o("Checkout failed: no redirect URL returned"),d.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=f.url;return}catch{if(window.open(f.url,"_blank")){d.current=!1,n(!1);return}}window.location.href=f.url}catch(T){o(T instanceof Error?T.message:"Checkout failed"),d.current=!1,n(!1)}}},[t]),loading:r,error:i,conflicts:p,shippingConflict:h}}var oe=require("react");var Ae=[{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 ot(e){return e?Ae.find(t=>t.country===e.toUpperCase())?.currency??null:null}var at=new Map;function Lt(e){let t=at.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),at.set(e,t)),t}function st(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,oe.useState)(null),[i,o]=(0,oe.useState)(!1),[p,l]=(0,oe.useState)(null);(0,oe.useEffect)(()=>{let a=()=>n(j());return a(),o(!0),me(a)},[]),(0,oe.useEffect)(()=>{let a=!1;return Lt(t).then(b=>{a||l(b)}),()=>{a=!0}},[t]);let h=(0,oe.useCallback)(a=>{tt(a)},[]),s=ot(p),d=i&&s!==null&&s!==ot(r);return{market:r,suggestedCountry:p,setMarket:h,markets:Ae,shouldPrompt:d}}var ge=require("react/jsx-runtime"),Et={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function ut({productId:e,variantId:t,apiUrl:r,locale:n,className:i,style:o,compareAtClassName:p}){let{product:l,loading:h}=se(e,{apiUrl:r});if(h||!l)return null;let s=ie(l),d=t!==void 0?s.find(b=>b.id===t)??null:l.options.length===0?s[0]??null:null;if(d){if(d.unit_amount===null)return null;let b=d.compare_at_amount!==null&&d.compare_at_amount>d.unit_amount;return(0,ge.jsxs)("span",{className:i,style:o,children:[b&&(0,ge.jsx)("span",{className:p,style:p?void 0:Et,children:F(d.compare_at_amount,d.currency,n)}),F(d.unit_amount,d.currency,n)]})}let a=Pe(s);return a?(0,ge.jsx)("span",{className:i,style:o,children:a.min===a.max?F(a.min,l.currency,n):`${F(a.min,l.currency,n)} \u2013 ${F(a.max,l.currency,n)}`}):l.unit_amount===null?null:(0,ge.jsx)("span",{className:i,style:o,children:F(l.unit_amount,l.currency,n)})}var J=require("react");var Y=require("react/jsx-runtime"),At={marginBottom:"0.75rem"},Ut={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},Vt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Mt={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Nt={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},ct={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},qt={...ct,cursor:"pointer"},Bt=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Dt=e=>Bt.test(e),$t={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},Ft={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)"},jt="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 lt({options:e,variants:t,value:r,syncUrl:n=!0,onChange:i,onVariantChange:o,className:p,style:l,optionClassName:h,optionLabelClassName:s,valueClassName:d,selectedValueClassName:a,unavailableValueClassName:b,swatchClassName:m}){let u=r!==void 0,[P,I]=(0,J.useState)(r??{}),O=u?r:P,[R,T]=(0,J.useState)(()=>new Set),v=y=>T(C=>C.has(y)?C:new Set(C).add(y));(0,J.useEffect)(()=>{T(y=>y.size===0?y:new Set)},[e]);let f=(0,J.useRef)(!1);(0,J.useEffect)(()=>{if(!n||u||f.current||e.length===0||typeof window>"u"||(f.current=!0,Object.keys(P).length>0))return;let y=xe({options:e},window.location.search);Object.keys(y).length!==0&&(I(y),i?.(y))},[n,u,e]);let c=(0,J.useMemo)(()=>e.length>0?t.filter(y=>y.option_values.length===e.length):t,[t,e]),g=(0,J.useRef)(void 0);if((0,J.useEffect)(()=>{let y=ue(c,O),C=y?.id??null;g.current!==C&&(g.current=C,o?.(y))},[c,O]),e.length===0)return null;let k=(y,C)=>{let _=_e(c,O,y,C);u||(I(_),n&&Re({options:e},_)),i?.(_)};return(0,Y.jsx)("div",{className:p,style:l,children:e.map(y=>(0,Y.jsxs)("div",{className:h,style:h?void 0:At,children:[(0,Y.jsx)("span",{className:s,style:s?void 0:Ut,children:y.title}),(0,Y.jsx)("div",{style:Vt,children:y.values.map(C=>{let _=O[y.id]===C.id,w=ke(c,O,y.id,C.id),L=w||we(c,y.id,C.id),B=[d,_?a:void 0,w?void 0:b].filter(Boolean).join(" ")||void 0,Q=C.swatch??null,A=Q&&!R.has(Q)?Q:null,S=A?Dt(A):!1,E=d?void 0:{...Mt,..._?Nt:{},...w?{}:L?qt:ct,...A?{...$t,textDecoration:"none"}:{}},U=w?C.value:`${C.value} \u2014 unavailable with your current selection`;return(0,Y.jsx)("button",{type:"button",className:B,style:E,disabled:!L,"aria-pressed":_,"aria-label":A?U:void 0,title:A?U:void 0,"data-selected":_?"true":void 0,"data-available":w?"true":"false","data-swatch":A?S?"hex":"image":void 0,onClick:()=>k(y.id,C.id),children:A?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)("span",{"aria-hidden":"true",className:m,style:m?void 0:{...Ft,...S?{background:A}:{},...S&&w?{}:{backgroundImage:[...w?[]:[jt],...S?[]:[`url(${JSON.stringify(A)})`]].join(", ")}}}),S?null:(0,Y.jsx)("img",{src:A,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>v(A)})]}):C.value},C.id)})})]},y.id))})}var ft=require("react");var V=require("react/jsx-runtime"),zt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Wt={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function dt(){return(0,V.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,V.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,V.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,V.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function pt({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:p,customerEmail:l,apiUrl:h,disabled:s,className:d,style:a,errorClassName:b,spinner:m=!0,children:u}){let{product:P,loading:I,error:O,refresh:R}=se(e,{apiUrl:h}),{startCheckout:T,loading:v,error:f,priceChange:c}=Oe({apiUrl:h});(0,ft.useEffect)(()=>{c&&R()},[c,R]);let g=P!==null&&!P.payments_ready,k=P!==null&&!P.active,y=P!==null&&P.purchasable===!1,C=P!==null&&fe(P),_=P!==null?ie(P):[],w=t!==void 0?_.find(U=>U.id===t)??null:!C&&_.length===1?_[0]:null,L=C&&!w,B=w!==null&&!w.in_stock,Q=!!s||I||!P||g||k||y||L||B||v,A;v?A=(0,V.jsxs)(V.Fragment,{children:[m&&(0,V.jsx)(dt,{}),"Processing\u2026"]}):I?A=(0,V.jsxs)(V.Fragment,{children:[m&&(0,V.jsx)(dt,{}),u??"Buy now"]}):g?A="Payments not set up":k||y?A="Unavailable":L?A="Select options":B?A="Out of stock":u!==void 0?A=u:A="Buy now";let S=f??O;return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)("button",{type:"button",className:d,style:a,disabled:Q,onClick:()=>{let U=n===void 0&&j()===null&&w!==null&&!w.allow_custom_amount&&typeof w.unit_amount=="number"?{expectedUnitAmount:w.unit_amount,expectedCurrency:w.currency}:{};T({productId:e,variantId:t,quantity:r,amount:n,metadata:i,successUrl:o,cancelUrl:p,customerEmail:l,...U})},children:A}),S&&(0,V.jsxs)("div",{role:"alert",className:b,style:b?void 0:zt,children:[S,P===null&&!I&&O!==null&&(0,V.jsx)("button",{type:"button",onClick:R,style:Wt,children:"Tap to retry"})]})]})}var de=require("react");var D=require("react/jsx-runtime"),Kt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Ht={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Yt=1500;function Jt(){return(0,D.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,D.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,D.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,D.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Gt(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function mt({productId:e,variantId:t,selection:r,quantity:n,apiUrl:i,disabled:o,className:p,style:l,errorClassName:h,spinner:s=!0,children:d}){let{product:a,loading:b,error:m,refresh:u}=se(e,{apiUrl:i}),{add:P}=re(),[I,O]=(0,de.useState)(!1),[R,T]=(0,de.useState)(!1),v=(0,de.useRef)(void 0);(0,de.useEffect)(()=>()=>{v.current&&clearTimeout(v.current)},[]);let f=a!==null&&!a.payments_ready,c=a!==null&&!a.active,g=a!==null&&a.purchasable===!1,k=a!==null&&!b&&ie(a).length===0,y=a!==null&&a.allow_custom_amount,C=a!==null&&fe(a),_=a!==null?ie(a):[],w=t!==void 0?_.find(W=>W.id===t)??null:r!==void 0&&C?ue(_,r):!C&&_.length===1?_[0]:null,L=a!==null&&!k&&!w,B=w!==null&&!w.in_stock,Q=!!o||b||!a||f||c||g||k||y||L||B,A=()=>{if(!a||!w)return;let W=r??Gt(w);if(!P({productId:e,variantId:w.id,quantity:n,selection:W,display:{name:a.name,variantTitle:w.title,image:pe(a,W)[0]??null}}).ok){O(!0);return}O(!1),T(!0),v.current&&clearTimeout(v.current),v.current=setTimeout(()=>T(!1),Yt)},S;b?S=(0,D.jsxs)(D.Fragment,{children:[s&&(0,D.jsx)(Jt,{}),d??"Add to cart"]}):f?S="Payments not set up":c||g||k||y?S="Unavailable":L?S="Select options":B?S="Out of stock":R?S="Added to cart":d!==void 0?S=d:S="Add to cart";let E=I?"Your cart is full \u2014 remove an item before adding another.":m;return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("button",{type:"button",className:p,style:l,disabled:Q,"data-added":R?"true":void 0,onClick:A,children:S}),E&&(0,D.jsxs)("div",{role:"alert",className:h,style:h?void 0:Kt,children:[E,a===null&&!b&&m!==null&&!I&&(0,D.jsx)("button",{type:"button",onClick:u,style:Ht,children:"Tap to retry"})]})]})}var M=require("react/jsx-runtime"),gt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function yt(){return(0,M.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,M.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,M.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,M.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function ht({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o,disabled:p,className:l,style:h,errorClassName:s,spinner:d=!0,children:a}){let{items:b,hydrated:m}=re(),{lines:u}=Le({apiUrl:e}),{startCheckout:P,loading:I,error:O,conflicts:R}=Ee({apiUrl:e}),T=m&&b.length===0,v=u.some(k=>k.status==="unavailable"),f=!!p||!m||T||v||I,c;I?c=(0,M.jsxs)(M.Fragment,{children:[d&&(0,M.jsx)(yt,{}),"Processing\u2026"]}):m?T?c="Cart is empty":v?c="Remove unavailable items":a!==void 0?c=a:c="Checkout":c=(0,M.jsxs)(M.Fragment,{children:[d&&(0,M.jsx)(yt,{}),a??"Checkout"]});let g=R?Object.keys(R).length:0;return(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)("button",{type:"button",className:l,style:h,disabled:f,onClick:()=>P(u,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:i,shippingOption:o}),children:c}),g>0&&(0,M.jsx)("div",{role:"alert",className:s,style:s?void 0:gt,children:g===1?"An item in your cart changed \u2014 please review your cart and try again.":`${g} items in your cart changed \u2014 please review your cart and try again.`}),O&&(0,M.jsx)("div",{role:"alert",className:s,style:s?void 0:gt,children:O})]})}var G=require("react");var x=require("react/jsx-runtime"),Ke="af_order_confirmation_session",Qt=1800*1e3;function bt({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:i=2e3,pollTimeoutMs:o=6e4,followRedirect:p=!0,redirectDelayMs:l=1500,renderNoSession:h,renderPending:s,renderPaid:d,renderFailed:a}){let[b,m]=(0,G.useState)(n),[u,P]=(0,G.useState)(null),[I,O]=(0,G.useState)(!1),R=(0,G.useRef)(void 0);(0,G.useEffect)(()=>{if(n!==void 0){m(n);return}if(R.current!==void 0){m(R.current);return}let c=new URL(window.location.href),g=c.searchParams.get("session_id");if(g){c.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",c.toString());try{sessionStorage.setItem(Ke,JSON.stringify({id:g,ts:Date.now()}))}catch{}}else try{let k=sessionStorage.getItem(Ke);if(k){let y=JSON.parse(k);typeof y.id=="string"&&typeof y.ts=="number"&&Date.now()-y.ts<=Qt?g=y.id:sessionStorage.removeItem(Ke)}}catch{}R.current=g,m(g)},[n]),(0,G.useEffect)(()=>{if(!b)return;let c=!1,g,k=Date.now(),y=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(b)}`);if(C.ok){let _=await C.json();if(c||(P(_),_.status!=="pending"))return}}catch{}if(!c){if(Date.now()-k>=o){O(!0);return}g=setTimeout(y,i)}};return y(),()=>{c=!0,g&&clearTimeout(g)}},[b,e,i,o]);let T=u!==null&&(u.status==="paid"||u.status==="partially_refunded"),v=(0,G.useRef)(!1);(0,G.useEffect)(()=>{if(!b||u===null||v.current||!(u.status==="paid"||u.status==="partially_refunded"||u.is_test===!0)||(v.current=!0,!nt(b)))return;let g=(u.line_items??[]).filter(k=>typeof k.variant_id=="string"&&k.variant_id.length>0).map(k=>({variantId:k.variant_id,quantity:k.quantity}));g.length>0&&et(g)},[b,u]);let f=T&&u.fulfillment.type==="redirect"?u.fulfillment.redirect_url:void 0;if((0,G.useEffect)(()=>{if(!f||!p)return;let c=setTimeout(()=>{window.location.href=f},l);return()=>clearTimeout(c)},[f,p,l]),b===void 0)return null;if(b===null)return h?(0,x.jsx)(x.Fragment,{children:h()}):(0,x.jsxs)("div",{className:t,style:r,children:[(0,x.jsx)("h2",{children:"Thank you for your order!"}),(0,x.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(!u||u.status==="pending")return s?(0,x.jsx)(x.Fragment,{children:s({timedOut:I})}):(0,x.jsx)("div",{className:t,style:r,role:"status",children:(0,x.jsx)("p",{children:I?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(T){if(d)return(0,x.jsx)(x.Fragment,{children:d(u)});let{fulfillment:c}=u,g=u.amount_total!==void 0&&u.currency?F(u.amount_total,u.currency):null,k=c.files??[],y=k.length===0?c.download_url:void 0;return(0,x.jsxs)("div",{className:t,style:r,children:[(0,x.jsx)("h2",{children:"Thank you for your purchase!"}),u.is_test&&(0,x.jsxs)("p",{children:[(0,x.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),u.line_items&&u.line_items.length>0&&(0,x.jsx)("ul",{children:u.line_items.map((C,_)=>(0,x.jsxs)("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&(0,x.jsx)("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},_))}),g&&(0,x.jsxs)("p",{children:["Total paid: ",g]}),k.length>0&&(0,x.jsxs)(x.Fragment,{children:[(0,x.jsx)("p",{children:"Your downloads:"}),(0,x.jsx)("ul",{children:k.map((C,_)=>(0,x.jsx)("li",{children:(0,x.jsx)("a",{href:C.download_url,children:C.name})},_))})]}),y&&(0,x.jsx)("p",{children:(0,x.jsx)("a",{href:y,children:"Download your file"})}),f?(0,x.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,x.jsx)("a",{href:f,children:"Continue if you are not redirected"})]}):c.redirect_url?(0,x.jsx)("p",{children:(0,x.jsx)("a",{href:c.redirect_url,children:"Continue to your content"})}):null,k.length===0&&!y&&!c.redirect_url&&(0,x.jsx)("p",{children:"A confirmation email is on its way to you."}),u.order_id&&(0,x.jsxs)("p",{children:["Order reference: ",(0,x.jsx)("code",{children:u.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return a?(0,x.jsx)(x.Fragment,{children:a(u)}):(0,x.jsx)("div",{className:t,style:r,children:(0,x.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."})})}0&&(module.exports={AddToCartButton,AifeaturesCaptcha,BuyButton,CartCheckoutButton,MARKET_COUNTRIES,MAX_CART_LINES,OrderConfirmation,ProductPrice,VariantPicker,ZERO_DECIMAL_CURRENCIES,applySelectionToUrl,formatPrice,getOptions,getVariants,isMultiVariant,isValueAvailable,isValueInCatalog,reanchorSelection,resolveVariant,searchFromSelection,selectedImages,selectedValues,selectionFromSearch,useCart,useCartCheckout,useCartItems,useCartSummary,useCheckout,useMarket,useProduct,valueSlug,variantPriceRange});
2
+ "use strict";var ct=Object.defineProperty;var ln=Object.getOwnPropertyDescriptor;var cn=Object.getOwnPropertyNames;var dn=Object.prototype.hasOwnProperty;var pn=(e,t)=>{for(var r in t)ct(e,r,{get:t[r],enumerable:!0})},fn=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of cn(t))!dn.call(e,o)&&o!==r&&ct(e,o,{get:()=>t[o],enumerable:!(n=ln(t,o))||n.enumerable});return e};var mn=e=>fn(ct({},"__esModule",{value:!0}),e);var pr={};pn(pr,{AccountLogin:()=>Be,AccountOrders:()=>ut,AccountPage:()=>un,AddToCartButton:()=>Ht,AifeaturesCaptcha:()=>Rt,BuyButton:()=>Wt,CartCheckoutButton:()=>Zt,MARKET_COUNTRIES:()=>st,MAX_CART_LINES:()=>St,OrderConfirmation:()=>Qt,PlanPicker:()=>Xt,ProductPrice:()=>Ft,SubscriptionList:()=>ze,VariantPicker:()=>jt,ZERO_DECIMAL_CURRENCIES:()=>pt,applySelectionToUrl:()=>Ze,formatPrice:()=>z,getOptions:()=>we,getVariants:()=>be,isMultiVariant:()=>Re,isValueAvailable:()=>Ye,isValueInCatalog:()=>We,planRecurringAmount:()=>Ct,reanchorSelection:()=>He,resolveVariant:()=>ke,searchFromSelection:()=>Me,selectedImages:()=>Ae,selectedValues:()=>ft,selectionFromSearch:()=>Ge,useCart:()=>ye,useCartCheckout:()=>ot,useCartItems:()=>it,useCartSummary:()=>qt,useCheckout:()=>nt,useMarket:()=>Bt,useProduct:()=>ve,useSession:()=>Ie,valueSlug:()=>pe,variantPriceRange:()=>Je});module.exports=mn(pr);var Ne=require("react"),xt=require("@marsidev/react-turnstile"),dt=require("react/jsx-runtime");function Rt({formId:e,apiUrl:t="https://aifeatures.dev",onVerify:r,onError:n,className:o}){let[i,l]=(0,Ne.useState)(null),[f,y]=(0,Ne.useState)(!0);return(0,Ne.useEffect)(()=>{y(!0),fetch(`${t}/f/${e}/config`).then(u=>u.json()).then(u=>{l(u.turnstile_sitekey),y(!1)}).catch(()=>{y(!1)})},[e,t]),f||!i?null:(0,dt.jsx)("div",{className:o,children:(0,dt.jsx)(xt.Turnstile,{siteKey:i,onSuccess:r,onError:n,onExpire:n,options:{theme:"light",appearance:"interaction-only"}})})}var ce=require("react"),je=[1e3,3e3];function ve(e,t={}){let r=t.apiUrl??"https://aifeatures.dev",n=t.country??null,[o,i]=(0,ce.useState)(null),[l,f]=(0,ce.useState)(!0),[y,u]=(0,ce.useState)(null),[v,d]=(0,ce.useState)(0),x=(0,ce.useRef)(e);(0,ce.useEffect)(()=>{let p=!1,O;f(!0),u(null),x.current!==e&&(x.current=e,i(null));let w=b=>{fetch(`${r}/v1/p/${encodeURIComponent(e)}${n?`?country=${encodeURIComponent(n)}`:""}`).then(async a=>{let P=await a.json().catch(()=>null);if(!p)if(!a.ok||!P){if(a.status>=500&&b<je.length){O=setTimeout(()=>w(b+1),je[b]);return}u(P?.error??`Request failed (${a.status})`),i(null),f(!1)}else i(P),f(!1)}).catch(a=>{if(!p){if(b<je.length){O=setTimeout(()=>w(b+1),je[b]);return}u(a instanceof Error?a.message:"Failed to load product"),f(!1)}})};return w(0),()=>{p=!0,O&&clearTimeout(O)}},[e,r,n,v]);let k=(0,ce.useCallback)(()=>d(p=>p+1),[]);return{product:o,loading:l,error:y,refresh:k}}var pt=new Set(["bif","clp","djf","gnf","jpy","kmf","krw","mga","pyg","rwf","vnd","vuv","xaf","xof","xpf"]);function z(e,t,r){let n=pt.has(t.toLowerCase())?e:e/100;try{return new Intl.NumberFormat(r,{style:"currency",currency:t.toUpperCase()}).format(n)}catch{return`${n} ${t.toUpperCase()}`}}function be(e){return e.variants??[]}function we(e){return e.options??[]}function Re(e){return we(e).length>0}function Ke(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function ke(e,t){let r=Object.keys(t);return e.find(n=>{let o=n.option_values;return o.length!==r.length?!1:o.every(i=>t[i.option_id]===i.value_id)})??null}function Ye(e,t,r,n){return e.some(o=>{let i=Ke(o);if(i[r]!==n)return!1;for(let[l,f]of Object.entries(t))if(l!==r&&i[l]!==f)return!1;return!0})}function We(e,t,r){return e.some(n=>Ke(n)[t]===r)}function He(e,t,r,n){let o={[r]:n};for(let[l,f]of Object.entries(t)){if(l===r)continue;e.some(u=>{let v=Ke(u);return v[r]===n&&v[l]===f})&&(o[l]=f)}return e.some(l=>{let f=Ke(l);return Object.entries(o).every(([y,u])=>f[y]===u)})?o:{[r]:n}}function Je(e){let t=e.map(r=>r.unit_amount).filter(r=>r!==null);return t.length===0?null:{min:Math.min(...t),max:Math.max(...t)}}function ft(e,t){let r={};for(let n of we(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i&&(r[n.title]=i.value)}return r}function pe(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}function Ge(e,t){let r=t instanceof URLSearchParams?t:new URLSearchParams(t),n=new Map;r.forEach((i,l)=>{n.has(pe(l))||n.set(pe(l),i)});let o={};for(let i of we(e)){let l=pe(i.title);if(l.length===0)continue;let f=n.get(l);if(f===void 0)continue;let y=pe(f);if(y.length===0)continue;let u=i.values.find(v=>pe(v.value)===y);u&&(o[i.id]=u.id)}return o}function Me(e,t){let r={};for(let[n,o]of Object.entries(ft(e,t))){let i=pe(n),l=pe(o);i.length===0||l.length===0||(r[i]=l)}return r}function Ae(e,t){let r=[];for(let n of we(e)){let o=t[n.id];if(!o)continue;let i=n.values.find(l=>l.id===o);i?.images?.length&&r.push(...i.images)}return r.length>0?r:e.images??[]}function Ze(e,t){if(typeof window>"u")return;let r=new URL(window.location.href);for(let n of we(e)){let o=pe(n.title);o.length!==0&&r.searchParams.delete(o)}for(let[n,o]of Object.entries(Me(e,t)))r.searchParams.set(n,o);window.history.replaceState(window.history.state,"",r.toString())}var oe=require("react");var gt="aifeatures_cart",yt="aifeatures_market",At="aifeatures_cart_cleared";var mt="aifeatures:cart-storage",Ve=new Map;function qe(e){if(Ve.has(e))return Ve.get(e)??null;if(typeof window>"u")return null;try{return window.localStorage.getItem(e)}catch{return null}}function Oe(e,t){if(typeof window>"u"){Ve.set(e,t);return}try{t===null?window.localStorage.removeItem(e):window.localStorage.setItem(e,t),Ve.delete(e)}catch{Ve.set(e,t)}gn(e)}function gn(e){if(!(typeof window>"u"))try{window.dispatchEvent(new CustomEvent(mt,{detail:{key:e}}))}catch{}}function Qe(e,t){if(typeof window>"u")return()=>{};let r=o=>{(o.key===e||o.key===null)&&t()},n=o=>{o.detail?.key===e&&t()};return window.addEventListener("storage",r),window.addEventListener(mt,n),()=>{window.removeEventListener("storage",r),window.removeEventListener(mt,n)}}function yn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.productId!="string"||t.productId.length===0||typeof t.variantId!="string"||t.variantId.length===0)return null;let r=typeof t.quantity=="number"&&Number.isFinite(t.quantity)?Math.max(1,Math.floor(t.quantity)):1,n={};if(typeof t.selection=="object"&&t.selection!==null)for(let[l,f]of Object.entries(t.selection))typeof f=="string"&&(n[l]=f);let o=typeof t.display=="object"&&t.display!==null?t.display:{},i={name:typeof o.name=="string"?o.name:"",variantTitle:typeof o.variantTitle=="string"?o.variantTitle:null,image:typeof o.image=="string"?o.image:null};return{productId:t.productId,variantId:t.variantId,quantity:r,selection:n,display:i}}function Ce(){let e=qe(gt);if(!e)return[];let t;try{t=JSON.parse(e)}catch{return[]}if(!Array.isArray(t))return[];let r=[],n=new Set;for(let o of t){let i=yn(o);i&&!n.has(i.variantId)&&(n.add(i.variantId),r.push(i))}return r}function fe(e){Oe(gt,JSON.stringify(e))}function Ot(e){return Qe(gt,e)}function Tt(e){let t=new Map;for(let n of e)!n.variantId||!(n.quantity>0)||t.set(n.variantId,(t.get(n.variantId)??0)+n.quantity);if(t.size===0)return;let r=[];for(let n of Ce()){let o=t.get(n.variantId);if(o===void 0){r.push(n);continue}let i=n.quantity-o;i>0&&r.push({...n,quantity:i})}fe(r)}function ne(){let e=qe(yt);return typeof e!="string"||!/^[A-Za-z]{2}$/.test(e)?null:e.toUpperCase()}function Lt(e){Oe(yt,e!==null&&/^[A-Za-z]{2}$/.test(e)?e.toUpperCase():null)}function Te(e){return Qe(yt,e)}function It(e){let t=[],r=qe(At);if(r)try{let o=JSON.parse(r);Array.isArray(o)&&(t=o.filter(i=>typeof i=="object"&&i!==null&&typeof i.id=="string"&&typeof i.ts=="number"))}catch{}let n=Date.now()-6048e5;return t=t.filter(o=>o.ts>n),t.some(o=>o.id===e)?!1:(t.push({id:e,ts:Date.now()}),t.length>200&&(t=t.slice(-200)),Oe(At,JSON.stringify(t)),!0)}var Xe="aifeatures_session",bt=null;function Et(){return bt}function bn(e){if(typeof e!="object"||e===null)return null;let t=e;if(typeof t.token!="string"||t.token.length===0)return null;let r=null;if(typeof t.customer=="object"&&t.customer!==null){let n=t.customer;typeof n.email=="string"&&n.email.length>0&&(r={email:n.email,name:typeof n.name=="string"?n.name:null})}return{token:t.token,customer:r}}function Pe(){let e=qe(Xe);if(!e)return null;try{return bn(JSON.parse(e))}catch{return null}}function Ut(){return Pe()?.token??null}function et(e){bt=null,Oe(Xe,JSON.stringify(e))}function me(e){bt=e??null,Oe(Xe,null)}function Nt(e){return Qe(Xe,e)}var hn=1500;function $e(){try{if(typeof crypto<"u"&&"randomUUID"in crypto)return crypto.randomUUID()}catch{}return`req_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`}function tt(e,t){return!("requestId"in e)||e.requestId===t}function ht(e,t){return typeof window>"u"||window.self===window.top?Promise.resolve(!1):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;y?.type==="aifeatures:test-checkout-ack"&&tt(y,t)&&o(y.status==="accepted")},l=setTimeout(()=>o(!1),hn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:test-checkout",requestId:t,...e},"*")}catch{o(!1)}})}function Mt(e){if(window.self!==window.top)try{return window.top.location.href=e,"navigating"}catch{if(window.open(e,"_blank"))return"stayed"}return window.location.href=e,"navigating"}function nt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,oe.useState)(!1),[o,i]=(0,oe.useState)(null),[l,f]=(0,oe.useState)(null),y=(0,oe.useRef)(!1),u=(0,oe.useRef)(null);return(0,oe.useEffect)(()=>{let d=x=>{x.persisted&&(y.current=!1,n(!1))};return window.addEventListener("pageshow",d),()=>window.removeEventListener("pageshow",d)},[]),(0,oe.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let d=x=>{if(x.source!==window.parent)return;let k=x.data;if(k?.type!=="aifeatures:test-checkout-ack"||k.status!=="failed")return;let p=u.current;p===null||!tt(k,p)||(u.current=null,i(typeof k.error=="string"&&k.error?k.error:"The test purchase could not be created."),y.current=!1,n(!1))};return window.addEventListener("message",d),()=>window.removeEventListener("message",d)},[]),{startCheckout:(0,oe.useCallback)(async({productId:d,variantId:x,quantity:k,amount:p,metadata:O,successUrl:w,cancelUrl:b,customerEmail:a,planId:P,expectedUnitAmount:_,expectedCurrency:s})=>{if(!y.current){if(y.current=!0,n(!0),i(null),f(null),P!==void 0){let c=Ut();if(c)try{let m=await fetch(`${t}/v1/account/subscribe`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${c}`},body:JSON.stringify({product_id:d,plan_id:P,...x!==void 0?{variant_id:x}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.text().catch(()=>""),h=null;try{h=g?JSON.parse(g):null}catch{h=null}if(m.ok){if(!h?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Mt(h.url)==="stayed"&&(y.current=!1,n(!1));return}let C=m.status===404&&g.trim()==="";if(m.status===401||C)me();else{i(h?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}}catch(m){i(m instanceof Error?m.message:"Checkout failed"),y.current=!1,n(!1);return}}try{let c=P===void 0?ne():null,m=await fetch(`${t}/v1/p/${d}/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({...x!==void 0?{variant_id:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{plan_id:P}:{},...O!==void 0?{metadata:O}:{},...a!==void 0?{customer_email:a}:{},..._!==void 0&&s!==void 0&&P===void 0?{expected_unit_amount:_,expected_currency:s}:{},...c!==null?{country:c}:{},success_url:w??`${window.location.origin}/order/confirmation`,cancel_url:b??window.location.href})}),g=await m.json().catch(()=>null);if(!m.ok){if(g?.error==="price_changed"&&typeof g.current_unit_amount=="number"&&typeof g.currency=="string"){f({currentUnitAmount:g.current_unit_amount,currency:g.currency}),i(`The price has changed to ${z(g.current_unit_amount,g.currency)} \u2014 please review and try again.`),y.current=!1,n(!1);return}if(g?.code==="preview_domain"){let h=$e();if(u.current=h,await ht({productId:d,...x!==void 0?{variantId:x}:{},...k!==void 0&&P===void 0?{quantity:k}:{},...p!==void 0?{amount:p}:{},...P!==void 0?{planId:P}:{},...a!==void 0?{customerEmail:a}:{},...O!==void 0?{metadata:O}:{}},h))return;u.current=null}i(g?.error??`Checkout failed (${m.status})`),y.current=!1,n(!1);return}if(!g?.url){i("Checkout failed: no redirect URL returned"),y.current=!1,n(!1);return}Mt(g.url)==="stayed"&&(y.current=!1,n(!1))}catch(c){i(c instanceof Error?c.message:"Checkout failed"),y.current=!1,n(!1)}}},[t]),loading:r,error:o,priceChange:l}}var ge=require("react");var St=20;function Vt(e){return typeof e!="number"||!Number.isFinite(e)?1:Math.max(1,Math.floor(e))}function ye(){let[e,t]=(0,ge.useState)([]),[r,n]=(0,ge.useState)(!1);(0,ge.useEffect)(()=>{let u=()=>t(Ce());return u(),n(!0),Ot(u)},[]);let o=(0,ge.useCallback)(u=>{let v=Ce(),d=Vt(u.quantity);return v.find(k=>k.variantId===u.variantId)?(fe(v.map(k=>k.variantId===u.variantId?{...k,quantity:k.quantity+d,selection:u.selection??k.selection,display:u.display}:k)),{ok:!0}):v.length>=St?{ok:!1,reason:"cart_full"}:(fe([...v,{productId:u.productId,variantId:u.variantId,quantity:d,selection:u.selection??{},display:u.display}]),{ok:!0})},[]),i=(0,ge.useCallback)(u=>{fe(Ce().filter(v=>v.variantId!==u))},[]),l=(0,ge.useCallback)((u,v)=>{let d=Ce();if(v<=0){fe(d.filter(k=>k.variantId!==u));return}let x=Vt(v);fe(d.map(k=>k.variantId===u?{...k,quantity:x}:k))},[]),f=(0,ge.useCallback)(()=>{fe([])},[]),y=e.reduce((u,v)=>u+v.quantity,0);return{items:e,count:y,hydrated:r,add:o,remove:i,setQuantity:l,clear:f}}var G=require("react");var rt={image:null,unitAmount:null,currency:null,baseCurrency:null,inStock:!1,available:null,maxQuantity:null,pdpSearch:{},status:"unavailable"},Sn={...rt,inStock:!0,status:"error"};function vn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function it(e={}){let t=e.apiUrl??"https://aifeatures.dev",{items:r,hydrated:n}=ye(),[o,i]=(0,G.useState)({}),[l,f]=(0,G.useState)({shippingRates:null,freeShippingOver:null,shippingCountries:null}),[y,u]=(0,G.useState)(!0),[v,d]=(0,G.useState)(null),[x,k]=(0,G.useState)(0),p=(0,G.useRef)(new Set),O=(0,G.useMemo)(()=>JSON.stringify(r.map(_=>[_.productId,_.variantId,_.selection])),[r]),w=(0,G.useCallback)(()=>k(_=>_+1),[]);(0,G.useEffect)(()=>Te(w),[w]),(0,G.useEffect)(()=>{if(!n)return;if(r.length===0){i({}),f({shippingRates:null,freeShippingOver:null,shippingCountries:null}),d(null),u(!1);return}let _=!1;u(!0);let s=r,c=[...new Set(s.map(g=>g.productId))],m=async g=>{let h=new Map;return await Promise.all(c.map(async C=>{try{let S=await fetch(`${t}/v1/p/${encodeURIComponent(C)}${g?`?country=${encodeURIComponent(g)}`:""}`);if(S.status===404){h.set(C,{kind:"not_found"});return}if(!S.ok){h.set(C,{kind:"error",message:`Request failed (${S.status})`});return}let R=await S.json();h.set(C,{kind:"ok",product:R})}catch(S){h.set(C,{kind:"error",message:S instanceof Error?S.message:"Failed to load product"})}})),h};return(async()=>{let g=ne(),h=await m(g);if(g){let A=[...h.values()].filter(V=>V.kind==="ok"),M=A.filter(V=>V.product.base_currency);M.length>0&&M.length<A.length&&(h=await m(null))}if(_)return;let C=null,S=null,R=null;for(let A of c){let M=h.get(A);!M||M.kind!=="ok"||(C===null&&M.product.shipping_rates&&(C=M.product.shipping_rates),S===null&&M.product.free_shipping_over!=null&&(S=M.product.free_shipping_over),R===null&&M.product.shipping_countries&&(R=M.product.shipping_countries))}let L={},$=new Map,Q=null;for(let A of s){let M=h.get(A.productId);if(!M||M.kind==="error"){L[A.variantId]=Sn,M&&Q===null&&(Q=M.message);continue}if(M.kind==="not_found"){L[A.variantId]=rt;continue}let{product:V}=M;if(!V.active||V.purchasable===!1){L[A.variantId]=rt;continue}let Y=V.variants??[],q=Y.find(ie=>ie.id===A.variantId)??null,J=A.variantId;if(!q){let ie=ke(Y,A.selection);if(!ie){L[A.variantId]=rt;continue}let _t=$.get(A.variantId)??{};_t.reanchorTo={variantId:ie.id,selection:vn(ie)},$.set(A.variantId,_t),p.current.add(ie.id),q=ie,J=ie.id}let N=Ae(V,A.selection)[0]??null,E={image:N,unitAmount:q.unit_amount,currency:q.currency,baseCurrency:V.base_currency??null,inStock:q.in_stock,available:q.available,maxQuantity:V.max_quantity,pdpSearch:Me(V,A.selection),status:p.current.has(J)?"reanchored":"ok"};L[A.variantId]=E,L[J]=E;let F=$.get(A.variantId)??{};F.display={name:V.name,variantTitle:q.title,image:N},$.set(A.variantId,F)}let B=new Set(s.map(A=>A.variantId));for(let A of[...p.current])!B.has(A)&&!(A in L)&&p.current.delete(A);if($.size>0){let A=Ce(),M=[],V=new Map,Y=!1;for(let q of A){let J=$.get(q.variantId),N={...q};J?.reanchorTo&&(N.variantId=J.reanchorTo.variantId,N.selection=J.reanchorTo.selection,Y=!0),J?.display&&(N.display.name!==J.display.name||N.display.variantTitle!==J.display.variantTitle||N.display.image!==J.display.image)&&(N.display=J.display,Y=!0);let E=V.get(N.variantId);if(E){E.quantity+=N.quantity,Y=!0;continue}M.push(N),V.set(N.variantId,N)}Y&&fe(M)}_||(i(L),f({shippingRates:C,freeShippingOver:S,shippingCountries:R}),d(Q),u(!1))})(),()=>{_=!0}},[n,O,t,x]);let b=(0,G.useMemo)(()=>r.map(_=>{let s=o[_.variantId];return s?{..._,...s,image:s.image??_.display.image}:{..._,image:_.display.image,unitAmount:null,currency:null,baseCurrency:null,inStock:!0,available:null,maxQuantity:null,pdpSearch:{},status:"ok"}}),[r,o]),{subtotal:a,currency:P}=(0,G.useMemo)(()=>{let _=0,s=null;for(let c of b)c.unitAmount===null||c.currency===null||(_+=c.unitAmount*c.quantity,s=s??c.currency);return{subtotal:_,currency:s}},[b]);return{lines:b,subtotal:a,currency:P,shippingRates:l.shippingRates,freeShippingOver:l.freeShippingOver,shippingCountries:l.shippingCountries,loading:y,error:v,refresh:w}}var Z=require("react");var kn=2e3;function qt(e={}){let t=e.apiUrl??"https://aifeatures.dev",r=e.debounceMs??250,n=e.shippingOption??null,{items:o,hydrated:i}=ye(),[l,f]=(0,Z.useState)(null),[y,u]=(0,Z.useState)(!1),[v,d]=(0,Z.useState)(null),[x,k]=(0,Z.useState)(null),[p,O]=(0,Z.useState)(0);(0,Z.useEffect)(()=>(k(ne()),Te(()=>k(ne()))),[]);let w=(0,Z.useMemo)(()=>o.map(s=>`${s.variantId}:${s.quantity}`).sort().join(","),[o]),b=(0,Z.useCallback)(()=>O(s=>s+1),[]),a=(0,Z.useRef)(0),P=(0,Z.useRef)(!1),_=(0,Z.useRef)("idle");return(0,Z.useEffect)(()=>{if(!i)return;if(o.length===0){f(null),d(null),u(!1);return}let s=++a.current,c=new AbortController,m=!1,g,h=P.current?r:0;P.current=!0,_.current=_.current==="pending"?"spent":"idle";let C=setTimeout(async()=>{u(!0);try{let S=await fetch(`${t}/v1/p/checkout/summary`,{method:"POST",headers:{"Content-Type":"application/json"},signal:c.signal,body:JSON.stringify({items:o.map(L=>({variant_id:L.variantId,quantity:L.quantity})),...x?{country:x}:{},...n?{shipping_option:n}:{}})});if(m||s!==a.current)return;if(!S.ok){if(S.status===429){let L=_.current==="idle";L&&(g=setTimeout(()=>{m||s!==a.current||(_.current="pending",O($=>$+1))},kn)),d(L?"Too many updates \u2014 retrying shortly":"Too many updates \u2014 the total will refresh on the next cart change")}else d(`Could not price this cart (${S.status})`);return}let R=await S.json();if(m||s!==a.current)return;f({currency:R.currency,subtotal:R.subtotal,shipping:R.shipping?{options:R.shipping.options.map(L=>({label:L.label,amount:L.amount,undiscountedAmount:L.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}),d(null)}catch(S){if(m||c.signal.aborted||s!==a.current)return;d(S instanceof Error?S.message:"Could not price this cart")}finally{!m&&s===a.current&&u(!1)}},h);return()=>{m=!0,clearTimeout(C),g!==void 0&&clearTimeout(g),c.abort()}},[i,w,x,t,r,n,p]),{summary:l,loading:y,error:v,refresh:b}}var re=require("react");function ot(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,re.useState)(!1),[o,i]=(0,re.useState)(null),[l,f]=(0,re.useState)(null),[y,u]=(0,re.useState)(null),v=(0,re.useRef)(!1),d=(0,re.useRef)(null);return(0,re.useEffect)(()=>{let k=p=>{p.persisted&&(v.current=!1,n(!1))};return window.addEventListener("pageshow",k),()=>window.removeEventListener("pageshow",k)},[]),(0,re.useEffect)(()=>{if(typeof window>"u"||window.self===window.top)return;let k=p=>{if(p.source!==window.parent)return;let O=p.data;if(O?.type!=="aifeatures:test-checkout-ack"||O.status!=="failed")return;let w=d.current;w===null||!tt(O,w)||(d.current=null,i(typeof O.error=="string"&&O.error?O.error:"The test purchase could not be created."),v.current=!1,n(!1))};return window.addEventListener("message",k),()=>window.removeEventListener("message",k)},[]),{startCheckout:(0,re.useCallback)(async(k,{successUrl:p,cancelUrl:O,customerEmail:w,metadata:b,shippingOption:a}={})=>{if(!v.current){v.current=!0,n(!0),i(null),f(null),u(null);try{let P=ne(),_=await fetch(`${t}/v1/p/checkout`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:k.map(c=>({variant_id:c.variantId,quantity:c.quantity,...typeof c.unitAmount=="number"&&typeof c.currency=="string"?{expected_unit_amount:c.unitAmount,expected_currency:c.currency}:{}})),...P!==null?{country:P}:{},...a?{shipping_option:a}:{},...b!==void 0?{metadata:b}:{},...w!==void 0?{customer_email:w}:{},success_url:p??`${window.location.origin}/order/confirmation`,cancel_url:O??window.location.href})}),s=await _.json().catch(()=>null);if(!_.ok){if(s?.code==="shipping_option_unavailable"&&typeof s.requested=="string"&&Array.isArray(s.available)){u({requested:s.requested,available:s.available,currency:typeof s.currency=="string"?s.currency:""}),v.current=!1,n(!1);return}if(s?.error==="cart_conflict"&&Array.isArray(s.items)){let c={};for(let m of s.items)m&&typeof m.variant_id=="string"&&(c[m.variant_id]=m);f(c),v.current=!1,n(!1);return}if(s?.code==="preview_domain"){let c=$e();if(d.current=c,await ht({items:k.map(g=>({productId:g.productId,variantId:g.variantId,quantity:g.quantity})),...w!==void 0?{customerEmail:w}:{},...b!==void 0?{metadata:b}:{}},c))return;d.current=null}i(s?.error??`Checkout failed (${_.status})`),v.current=!1,n(!1);return}if(!s?.url){i("Checkout failed: no redirect URL returned"),v.current=!1,n(!1);return}if(window.self!==window.top)try{window.top.location.href=s.url;return}catch{if(window.open(s.url,"_blank")){v.current=!1,n(!1);return}}window.location.href=s.url}catch(P){i(P instanceof Error?P.message:"Checkout failed"),v.current=!1,n(!1)}}},[t]),loading:r,error:o,conflicts:l,shippingConflict:y}}var he=require("react");var st=[{country:"US",currency:"usd"},{country:"GB",currency:"gbp"},{country:"CA",currency:"cad"},{country:"AU",currency:"aud"},{country:"NZ",currency:"nzd"},{country:"JP",currency:"jpy"},{country:"CH",currency:"chf"},{country:"SE",currency:"sek"},{country:"NO",currency:"nok"},{country:"DK",currency:"dkk"},{country:"PL",currency:"pln"},{country:"CZ",currency:"czk"},{country:"SG",currency:"sgd"},{country:"HK",currency:"hkd"},{country:"MX",currency:"mxn"},{country:"BR",currency:"brl"},{country:"IN",currency:"inr"},{country:"ZA",currency:"zar"},{country:"AE",currency:"aed"},{country:"IL",currency:"ils"},{country:"AT",currency:"eur"},{country:"BE",currency:"eur"},{country:"HR",currency:"eur"},{country:"CY",currency:"eur"},{country:"EE",currency:"eur"},{country:"FI",currency:"eur"},{country:"FR",currency:"eur"},{country:"DE",currency:"eur"},{country:"GR",currency:"eur"},{country:"IE",currency:"eur"},{country:"IT",currency:"eur"},{country:"LV",currency:"eur"},{country:"LT",currency:"eur"},{country:"LU",currency:"eur"},{country:"MT",currency:"eur"},{country:"NL",currency:"eur"},{country:"PT",currency:"eur"},{country:"SK",currency:"eur"},{country:"SI",currency:"eur"},{country:"ES",currency:"eur"}];function $t(e){return e?st.find(t=>t.country===e.toUpperCase())?.currency??null:null}var Dt=new Map;function Cn(e){let t=Dt.get(e);return t||(t=fetch(`${e}/v1/geo`).then(async r=>{if(!r.ok)return null;let n=await r.json().catch(()=>null);return typeof n?.country=="string"&&/^[A-Za-z]{2}$/.test(n.country)?n.country.toUpperCase():null}).catch(()=>null),Dt.set(e,t)),t}function Bt(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,he.useState)(null),[o,i]=(0,he.useState)(!1),[l,f]=(0,he.useState)(null);(0,he.useEffect)(()=>{let d=()=>n(ne());return d(),i(!0),Te(d)},[]),(0,he.useEffect)(()=>{let d=!1;return Cn(t).then(x=>{d||f(x)}),()=>{d=!0}},[t]);let y=(0,he.useCallback)(d=>{Lt(d)},[]),u=$t(l),v=o&&u!==null&&u!==$t(r);return{market:r,suggestedCountry:l,setMarket:y,markets:st,shouldPrompt:v}}var Le=require("react/jsx-runtime"),wn={textDecoration:"line-through",opacity:.6,marginRight:"0.4em"};function Ft({productId:e,variantId:t,apiUrl:r,locale:n,className:o,style:i,compareAtClassName:l}){let{product:f,loading:y}=ve(e,{apiUrl:r});if(y||!f)return null;let u=be(f),v=t!==void 0?u.find(x=>x.id===t)??null:f.options.length===0?u[0]??null:null;if(v){if(v.unit_amount===null)return null;let x=v.compare_at_amount!==null&&v.compare_at_amount>v.unit_amount;return(0,Le.jsxs)("span",{className:o,style:i,children:[x&&(0,Le.jsx)("span",{className:l,style:l?void 0:wn,children:z(v.compare_at_amount,v.currency,n)}),z(v.unit_amount,v.currency,n)]})}let d=Je(u);return d?(0,Le.jsx)("span",{className:o,style:i,children:d.min===d.max?z(d.min,f.currency,n):`${z(d.min,f.currency,n)} \u2013 ${z(d.max,f.currency,n)}`}):f.unit_amount===null?null:(0,Le.jsx)("span",{className:o,style:i,children:z(f.unit_amount,f.currency,n)})}var ae=require("react");var se=require("react/jsx-runtime"),Pn={marginBottom:"0.75rem"},_n={display:"block",fontSize:"0.875rem",fontWeight:600,marginBottom:"0.375rem"},xn={display:"flex",flexWrap:"wrap",gap:"0.5rem"},Rn={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},An={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600},zt={opacity:.4,textDecoration:"line-through",cursor:"not-allowed"},On={...zt,cursor:"pointer"},Tn=/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/,Ln=e=>Tn.test(e),In={padding:"0.375rem",width:"2.25rem",height:"2.25rem",lineHeight:0},En={display:"block",width:"1.5rem",height:"1.5rem",maxWidth:"100%",maxHeight:"100%",boxSizing:"border-box",borderRadius:3,backgroundSize:"cover",backgroundPosition:"center",backgroundColor:"#f3f4f6",border:"1px solid rgba(0, 0, 0, 0.2)"},Un="linear-gradient(to top right, transparent calc(50% - 2px), rgba(0,0,0,0.55) calc(50% - 2px), rgba(255,255,255,0.95) calc(50% - 1px), rgba(255,255,255,0.95) calc(50% + 1px), rgba(0,0,0,0.55) calc(50% + 1px), transparent calc(50% + 2px))";function jt({options:e,variants:t,value:r,syncUrl:n=!0,onChange:o,onVariantChange:i,className:l,style:f,optionClassName:y,optionLabelClassName:u,valueClassName:v,selectedValueClassName:d,unavailableValueClassName:x,swatchClassName:k}){let p=r!==void 0,[O,w]=(0,ae.useState)(r??{}),b=p?r:O,[a,P]=(0,ae.useState)(()=>new Set),_=h=>P(C=>C.has(h)?C:new Set(C).add(h));(0,ae.useEffect)(()=>{P(h=>h.size===0?h:new Set)},[e]);let s=(0,ae.useRef)(!1);(0,ae.useEffect)(()=>{if(!n||p||s.current||e.length===0||typeof window>"u"||(s.current=!0,Object.keys(O).length>0))return;let h=Ge({options:e},window.location.search);Object.keys(h).length!==0&&(w(h),o?.(h))},[n,p,e]);let c=(0,ae.useMemo)(()=>e.length>0?t.filter(h=>h.option_values.length===e.length):t,[t,e]),m=(0,ae.useRef)(void 0);if((0,ae.useEffect)(()=>{let h=ke(c,b),C=h?.id??null;m.current!==C&&(m.current=C,i?.(h))},[c,b]),e.length===0)return null;let g=(h,C)=>{let S=He(c,b,h,C);p||(w(S),n&&Ze({options:e},S)),o?.(S)};return(0,se.jsx)("div",{className:l,style:f,children:e.map(h=>(0,se.jsxs)("div",{className:y,style:y?void 0:Pn,children:[(0,se.jsx)("span",{className:u,style:u?void 0:_n,children:h.title}),(0,se.jsx)("div",{style:xn,children:h.values.map(C=>{let S=b[h.id]===C.id,R=Ye(c,b,h.id,C.id),L=R||We(c,h.id,C.id),$=[v,S?d:void 0,R?void 0:x].filter(Boolean).join(" ")||void 0,Q=C.swatch??null,B=Q&&!a.has(Q)?Q:null,A=B?Ln(B):!1,M=v?void 0:{...Rn,...S?An:{},...R?{}:L?On:zt,...B?{...In,textDecoration:"none"}:{}},V=R?C.value:`${C.value} \u2014 unavailable with your current selection`;return(0,se.jsx)("button",{type:"button",className:$,style:M,disabled:!L,"aria-pressed":S,"aria-label":B?V:void 0,title:B?V:void 0,"data-selected":S?"true":void 0,"data-available":R?"true":"false","data-swatch":B?A?"hex":"image":void 0,onClick:()=>g(h.id,C.id),children:B?(0,se.jsxs)(se.Fragment,{children:[(0,se.jsx)("span",{"aria-hidden":"true",className:k,style:k?void 0:{...En,...A?{background:B}:{},...A&&R?{}:{backgroundImage:[...R?[]:[Un],...A?[]:[`url(${JSON.stringify(B)})`]].join(", ")}}}),A?null:(0,se.jsx)("img",{src:B,alt:"","aria-hidden":"true",referrerPolicy:"no-referrer",style:{display:"none"},onError:()=>_(B)})]}):C.value},C.id)})})]},h.id))})}var Yt=require("react");var W=require("react/jsx-runtime"),Nn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},Mn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function Kt(){return(0,W.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,W.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,W.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,W.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Wt({productId:e,variantId:t,quantity:r,planId:n,amount:o,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,apiUrl:u,disabled:v,className:d,style:x,errorClassName:k,spinner:p=!0,children:O}){let{product:w,loading:b,error:a,refresh:P}=ve(e,{apiUrl:u}),{startCheckout:_,loading:s,error:c,priceChange:m}=nt({apiUrl:u});(0,Yt.useEffect)(()=>{m&&P()},[m,P]);let g=w!==null&&!w.payments_ready,h=w!==null&&!w.active,C=w!==null&&w.purchasable===!1,S=w!==null&&Re(w),R=w!==null?be(w):[],L=t!==void 0?R.find(E=>E.id===t)??null:!S&&R.length===1?R[0]:null,$=S&&!L,Q=L!==null&&!L.in_stock,B=n??void 0,A=w?.subscription??null,M=A!==null&&A.required&&!A.ready,V=A!==null&&A.required&&A.ready&&B===void 0,Y=!!v||b||!w||g||h||C||M||V||$||Q||s,q;s?q=(0,W.jsxs)(W.Fragment,{children:[p&&(0,W.jsx)(Kt,{}),"Processing\u2026"]}):b?q=(0,W.jsxs)(W.Fragment,{children:[p&&(0,W.jsx)(Kt,{}),O??"Buy now"]}):g?q="Payments not set up":h||C?q="Unavailable":M?q="Currently unavailable":V?q="Select a plan":$?q="Select options":Q?q="Out of stock":O!==void 0?q=O:B!==void 0?q="Subscribe":q="Buy now";let J=c??a;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)("button",{type:"button",className:d,style:x,disabled:Y,onClick:()=>{let E=o===void 0&&B===void 0&&ne()===null&&L!==null&&!L.allow_custom_amount&&typeof L.unit_amount=="number"?{expectedUnitAmount:L.unit_amount,expectedCurrency:L.currency}:{};_({productId:e,variantId:t,quantity:B!==void 0?void 0:r,amount:o,planId:B,metadata:i,successUrl:l,cancelUrl:f,customerEmail:y,...E})},children:q}),J&&(0,W.jsxs)("div",{role:"alert",className:k,style:k?void 0:Nn,children:[J,w===null&&!b&&a!==null&&(0,W.jsx)("button",{type:"button",onClick:P,style:Mn,children:"Tap to retry"})]})]})}var _e=require("react");var X=require("react/jsx-runtime"),Vn={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"},qn={background:"none",border:"none",padding:0,marginLeft:"0.35em",font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},$n=1500;function Dn(){return(0,X.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,X.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,X.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,X.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Bn(e){let t={};for(let r of e.option_values)t[r.option_id]=r.value_id;return t}function Ht({productId:e,variantId:t,selection:r,quantity:n,apiUrl:o,disabled:i,className:l,style:f,errorClassName:y,spinner:u=!0,children:v}){let{product:d,loading:x,error:k,refresh:p}=ve(e,{apiUrl:o}),{add:O}=ye(),[w,b]=(0,_e.useState)(!1),[a,P]=(0,_e.useState)(!1),_=(0,_e.useRef)(void 0);(0,_e.useEffect)(()=>()=>{_.current&&clearTimeout(_.current)},[]);let s=d!==null&&!d.payments_ready,c=d!==null&&!d.active,m=d!==null&&d.purchasable===!1,g=d!==null&&!x&&be(d).length===0,h=d!==null&&d.allow_custom_amount,C=d!==null&&Re(d),S=d!==null?be(d):[],R=t!==void 0?S.find(Y=>Y.id===t)??null:r!==void 0&&C?ke(S,r):!C&&S.length===1?S[0]:null,L=d!==null&&!g&&!R,$=R!==null&&!R.in_stock,Q=!!i||x||!d||s||c||m||g||h||L||$,B=()=>{if(!d||!R)return;let Y=r??Bn(R);if(!O({productId:e,variantId:R.id,quantity:n,selection:Y,display:{name:d.name,variantTitle:R.title,image:Ae(d,Y)[0]??null}}).ok){b(!0);return}b(!1),P(!0),_.current&&clearTimeout(_.current),_.current=setTimeout(()=>P(!1),$n)},A;x?A=(0,X.jsxs)(X.Fragment,{children:[u&&(0,X.jsx)(Dn,{}),v??"Add to cart"]}):s?A="Payments not set up":c||m||g||h?A="Unavailable":L?A="Select options":$?A="Out of stock":a?A="Added to cart":v!==void 0?A=v:A="Add to cart";let M=w?"Your cart is full \u2014 remove an item before adding another.":k;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)("button",{type:"button",className:l,style:f,disabled:Q,"data-added":a?"true":void 0,onClick:B,children:A}),M&&(0,X.jsxs)("div",{role:"alert",className:y,style:y?void 0:Vn,children:[M,d===null&&!x&&k!==null&&!w&&(0,X.jsx)("button",{type:"button",onClick:p,style:qn,children:"Tap to retry"})]})]})}var H=require("react/jsx-runtime"),Jt={color:"#b91c1c",fontSize:"0.875rem",marginTop:"0.5rem"};function Gt(){return(0,H.jsxs)("svg",{width:"1em",height:"1em",viewBox:"0 0 24 24",fill:"none","aria-hidden":"true",focusable:"false",style:{display:"inline-block",marginRight:"0.5em",verticalAlign:"-0.125em",flexShrink:0},children:[(0,H.jsx)("circle",{cx:"12",cy:"12",r:"9",stroke:"currentColor",strokeOpacity:"0.25",strokeWidth:"3"}),(0,H.jsx)("path",{d:"M21 12a9 9 0 0 0-9-9",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",children:(0,H.jsx)("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.8s",repeatCount:"indefinite"})})]})}function Zt({apiUrl:e,successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i,disabled:l,className:f,style:y,errorClassName:u,spinner:v=!0,children:d}){let{items:x,hydrated:k}=ye(),{lines:p}=it({apiUrl:e}),{startCheckout:O,loading:w,error:b,conflicts:a}=ot({apiUrl:e}),P=k&&x.length===0,_=p.some(g=>g.status==="unavailable"),s=!!l||!k||P||_||w,c;w?c=(0,H.jsxs)(H.Fragment,{children:[v&&(0,H.jsx)(Gt,{}),"Processing\u2026"]}):k?P?c="Cart is empty":_?c="Remove unavailable items":d!==void 0?c=d:c="Checkout":c=(0,H.jsxs)(H.Fragment,{children:[v&&(0,H.jsx)(Gt,{}),d??"Checkout"]});let m=a?Object.keys(a).length:0;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("button",{type:"button",className:f,style:y,disabled:s,onClick:()=>O(p,{successUrl:t,cancelUrl:r,customerEmail:n,metadata:o,shippingOption:i}),children:c}),m>0&&(0,H.jsx)("div",{role:"alert",className:u,style:u?void 0:Jt,children:m===1?"An item in your cart changed \u2014 please review your cart and try again.":`${m} items in your cart changed \u2014 please review your cart and try again.`}),b&&(0,H.jsx)("div",{role:"alert",className:u,style:u?void 0:Jt,children:b})]})}var ue=require("react");var I=require("react/jsx-runtime"),vt="af_order_confirmation_session",Fn=1800*1e3;function Qt({apiUrl:e="https://aifeatures.dev",className:t,style:r,sessionId:n,pollIntervalMs:o=2e3,pollTimeoutMs:i=6e4,followRedirect:l=!0,redirectDelayMs:f=1500,renderNoSession:y,renderPending:u,renderPaid:v,renderFailed:d}){let[x,k]=(0,ue.useState)(n),[p,O]=(0,ue.useState)(null),[w,b]=(0,ue.useState)(!1),a=(0,ue.useRef)(void 0);(0,ue.useEffect)(()=>{if(n!==void 0){k(n);return}if(a.current!==void 0){k(a.current);return}let c=new URL(window.location.href),m=c.searchParams.get("session_id");if(m){c.searchParams.delete("session_id"),window.history.replaceState(window.history.state,"",c.toString());try{sessionStorage.setItem(vt,JSON.stringify({id:m,ts:Date.now()}))}catch{}}else try{let g=sessionStorage.getItem(vt);if(g){let h=JSON.parse(g);typeof h.id=="string"&&typeof h.ts=="number"&&Date.now()-h.ts<=Fn?m=h.id:sessionStorage.removeItem(vt)}}catch{}a.current=m,k(m)},[n]),(0,ue.useEffect)(()=>{if(!x)return;let c=!1,m,g=Date.now(),h=async()=>{try{let C=await fetch(`${e}/v1/o/session/${encodeURIComponent(x)}`);if(C.ok){let S=await C.json();if(c||(O(S),S.status!=="pending"))return}}catch{}if(!c){if(Date.now()-g>=i){b(!0);return}m=setTimeout(h,o)}};return h(),()=>{c=!0,m&&clearTimeout(m)}},[x,e,o,i]);let P=p!==null&&(p.status==="paid"||p.status==="partially_refunded"),_=(0,ue.useRef)(!1);(0,ue.useEffect)(()=>{if(!x||p===null||_.current||!(p.status==="paid"||p.status==="partially_refunded"||p.is_test===!0)||(_.current=!0,!It(x)))return;let m=(p.line_items??[]).filter(g=>typeof g.variant_id=="string"&&g.variant_id.length>0).map(g=>({variantId:g.variant_id,quantity:g.quantity}));m.length>0&&Tt(m)},[x,p]);let s=P&&p.fulfillment.type==="redirect"?p.fulfillment.redirect_url:void 0;if((0,ue.useEffect)(()=>{if(!s||!l)return;let c=setTimeout(()=>{window.location.href=s},f);return()=>clearTimeout(c)},[s,l,f]),x===void 0)return null;if(x===null)return y?(0,I.jsx)(I.Fragment,{children:y()}):(0,I.jsxs)("div",{className:t,style:r,children:[(0,I.jsx)("h2",{children:"Thank you for your order!"}),(0,I.jsx)("p",{children:"If you completed a payment, a confirmation email with your receipt and any download links is on its way to you. This page can only show live order details right after checkout."})]});if(!p||p.status==="pending")return u?(0,I.jsx)(I.Fragment,{children:u({timedOut:w})}):(0,I.jsx)("div",{className:t,style:r,role:"status",children:(0,I.jsx)("p",{children:w?"This is taking longer than expected. You will receive an email confirmation once your payment is processed.":"Confirming your payment\u2026"})});if(P){if(v)return(0,I.jsx)(I.Fragment,{children:v(p)});let{fulfillment:c}=p,m=p.amount_total!==void 0&&p.currency?z(p.amount_total,p.currency):null,g=c.files??[],h=g.length===0?c.download_url:void 0;return(0,I.jsxs)("div",{className:t,style:r,children:[(0,I.jsx)("h2",{children:"Thank you for your purchase!"}),p.is_test&&(0,I.jsxs)("p",{children:[(0,I.jsx)("strong",{children:"Test purchase"})," \u2014 no payment was collected."]}),p.line_items&&p.line_items.length>0&&(0,I.jsx)("ul",{children:p.line_items.map((C,S)=>(0,I.jsxs)("li",{children:[C.quantity>1?`${C.quantity} \xD7 `:"",C.name,C.refunded&&(0,I.jsx)("em",{children:C.refund_reason==="oversold"?" \u2014 sold out and refunded; check your email for details":" \u2014 refunded"})]},S))}),m&&(0,I.jsxs)("p",{children:["Total paid: ",m]}),p.source==="subscription"&&p.subscription&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("p",{children:["Your subscription renews"," ",p.subscription.interval_count>1?`every ${p.subscription.interval_count} ${p.subscription.interval}s`:`every ${p.subscription.interval}`," ","at"," ",z(p.subscription.amount,p.subscription.currency),"."]}),(0,I.jsxs)("p",{children:["You can view, update, or cancel it any time on"," ",(0,I.jsx)("a",{href:"/account",children:"your account page"})," \u2014 sign in with the email you used at checkout."]})]}),g.length>0&&(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)("p",{children:"Your downloads:"}),(0,I.jsx)("ul",{children:g.map((C,S)=>(0,I.jsx)("li",{children:(0,I.jsx)("a",{href:C.download_url,children:C.name})},S))})]}),h&&(0,I.jsx)("p",{children:(0,I.jsx)("a",{href:h,children:"Download your file"})}),s?(0,I.jsxs)("p",{children:["Taking you to your content\u2026"," ",(0,I.jsx)("a",{href:s,children:"Continue if you are not redirected"})]}):c.redirect_url?(0,I.jsx)("p",{children:(0,I.jsx)("a",{href:c.redirect_url,children:"Continue to your content"})}):null,g.length===0&&!h&&!c.redirect_url&&(0,I.jsx)("p",{children:"A confirmation email is on its way to you."}),p.order_id&&(0,I.jsxs)("p",{children:["Order reference: ",(0,I.jsx)("code",{children:p.order_id})," \u2014 keep this if you ever need help with your order."]})]})}return d?(0,I.jsx)(I.Fragment,{children:d(p)}):(0,I.jsx)("div",{className:t,style:r,children:(0,I.jsx)("p",{children:"We couldn't confirm your payment. If you were charged, you'll receive an email confirmation \u2014 otherwise you can safely try again."})})}var at=require("react");var Se=require("react/jsx-runtime");function Ct(e,t){if(t.unit_amount!==null&&t.unit_amount!==void 0)return t.unit_amount;let r=t.percent_off_bps??0;return e-Math.floor(e*r/1e4)}function kt(e){return e.interval_count>1?`every ${e.interval_count} ${e.interval}s`:`every ${e.interval}`}var zn={display:"flex",flexDirection:"column",gap:"0.5rem",marginBottom:"0.75rem"},jn={display:"block",width:"100%",textAlign:"left",padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},Kn={borderColor:"#111827",boxShadow:"inset 0 0 0 1px #111827",fontWeight:600};function Xt({product:e,subscription:t,baseUnitAmount:r,currency:n,value:o,onChange:i,className:l,style:f,optionClassName:y,selectedOptionClassName:u,oneTimeLabel:v,renderOption:d,renderUnavailable:x}){let k=t??e?.subscription??null,p=k?.required===!0,O=k?.ready===!0,w=[...k?.plans??[]].sort((S,R)=>S.position-R.position),[b,a]=(0,at.useState)(null),P=o!==void 0,_=P?o:b,s=w.map(S=>S.id).join("|"),c=w.length>0?w[0].id:null;if((0,at.useEffect)(()=>{if(!(!p||!O)&&!(_!==null&&w.some(S=>S.id===_))){if(c===null){if(_===null)return;P||a(null),i?.(null);return}P||a(c),i?.(c)}},[p,O,c,s,_,P]),!k)return null;if(!O)return p?x?(0,Se.jsx)(Se.Fragment,{children:x()}):(0,Se.jsx)("div",{className:l,style:f,"data-state":"unavailable",children:(0,Se.jsx)("p",{children:"This product is currently unavailable."})}):null;if(w.length===0)return null;let m=e?.base_currency!==void 0&&e?.base_currency!==null,g=r!==void 0?r:m?null:e?.unit_amount??null,h=n??e?.base_currency??e?.currency??"usd",C=[];if(!p){let S=g;C.push({plan:null,selected:_===null,price:S,priceLabel:S!==null?z(S,h):null,label:"One-time purchase",select:()=>{P||a(null),i?.(null)}})}for(let S of w){let R=S.unit_amount!==null?S.unit_amount:g!==null?Ct(g,S):null,L=R!==null?z(R,h):null,$=S.title&&S.title.trim().length>0?S.title.trim():`Subscribe ${kt(S)}`,Q=L?`${$} \u2014 ${L} ${kt(S)}`:`${$} \u2014 billed ${kt(S)}`;C.push({plan:S,selected:_===S.id,price:R,priceLabel:L,label:Q,select:()=>{P||a(S.id),i?.(S.id)}})}return(0,Se.jsx)("div",{role:"radiogroup","aria-label":"Purchase options",className:l,style:l?f:{...zn,...f},children:C.map(S=>{if(d)return(0,Se.jsx)("span",{style:{display:"contents"},children:d(S)},S.plan?.id??"one-time");let R=S.selected;return(0,Se.jsx)("button",{type:"button",role:"radio","aria-checked":R,"data-selected":R?"true":void 0,"data-plan-id":S.plan?.id,className:[y,R?u:void 0].filter(Boolean).join(" ")||void 0,style:y?void 0:{...jn,...R?Kn:{}},onClick:S.select,children:S.plan===null&&v!==void 0?v:S.plan===null?S.priceLabel?`One-time purchase \u2014 ${S.priceLabel}`:"One-time purchase":S.label},S.plan?.id??"one-time")})})}var ee=require("react");async function de(e,t,r={}){let n;try{n=await fetch(`${e}${t}`,{method:r.method??"GET",headers:{...r.body!==void 0?{"Content-Type":"application/json"}:{},...r.token?{Authorization:`Bearer ${r.token}`}:{}},...r.body!==void 0?{body:JSON.stringify(r.body)}:{}})}catch(u){return{ok:!1,failure:{kind:"network",error:u instanceof Error?u.message:"Network error"}}}let o=await n.text().catch(()=>""),i=null;try{i=o?JSON.parse(o):null}catch{i=null}let l=typeof i=="object"&&i!==null?i:null;if(n.ok)return l===null?{ok:!1,failure:{kind:"parse_error",error:"The server sent an unreadable response \u2014 please try again"}}:{ok:!0,data:l};if(n.status===404&&o.trim()==="")return{ok:!1,failure:{kind:"unavailable"}};let f=typeof l?.code=="string"?l.code:null,y=typeof l?.error=="string"&&l.error?l.error:`Request failed (${n.status})`;return n.status===401?{ok:!1,failure:{kind:"unauthorized",code:f,error:y}}:{ok:!1,failure:{kind:"http",status:n.status,code:f,error:y}}}function en(e,t){return t>1?`every ${t} ${e}s`:`every ${e}`}function De(e){if(!e)return null;let t=e.includes("T")?e:e.replace(" ","T")+"Z",r=Date.parse(t);if(Number.isNaN(r))return null;try{return new Date(r).toLocaleDateString(void 0,{year:"numeric",month:"long",day:"numeric"})}catch{return null}}var Yn=1500;function tn(e){if(!e)return!1;try{return e.self!==e.top}catch{return!0}}function Wn(e,t){return e.requestId===t}function Hn(e,t){return typeof window>"u"||!tn(window)?Promise.resolve({claimed:!1}):new Promise(r=>{let n=!1,o=f=>{n||(n=!0,window.removeEventListener("message",i),clearTimeout(l),r(f))},i=f=>{if(f.source!==window.parent)return;let y=f.data;if(y?.type==="aifeatures:preview-session-ack"&&Wn(y??{},t)){if(typeof y.token=="string"&&y.token.length>0){let u=null;if(typeof y.customer=="object"&&y.customer!==null){let v=y.customer;typeof v.email=="string"&&(u={email:v.email,name:typeof v.name=="string"?v.name:null})}o({claimed:!0,token:y.token,customer:u});return}o({claimed:!0,token:null,customer:null,error:typeof y.error=="string"&&y.error?y.error:"The preview sign-in could not be created."})}},l=setTimeout(()=>o({claimed:!1}),Yn);window.addEventListener("message",i);try{window.parent.postMessage({type:"aifeatures:preview-session",requestId:t,email:e},"*")}catch{o({claimed:!1})}})}function Ie(e={}){let t=e.apiUrl??"https://aifeatures.dev",[r,n]=(0,ee.useState)(()=>Pe()),[o,i]=(0,ee.useState)(null),[l,f]=(0,ee.useState)(!1),[y,u]=(0,ee.useState)(!1),v=(0,ee.useRef)(void 0);(0,ee.useEffect)(()=>Nt(()=>{let b=Pe();n(b),i(b===null?a=>Et()??a:null)}),[]);let d=(0,ee.useCallback)(async b=>{u(!0);try{let a=await de(t,"/v1/account/verify",{method:"POST",body:{code:b}});if(a.ok&&typeof a.data.token=="string"){let _=a.data.customer&&typeof a.data.customer.email=="string"?{email:a.data.customer.email,name:typeof a.data.customer.name=="string"?a.data.customer.name:null}:null;return et({token:a.data.token,customer:_}),n({token:a.data.token,customer:_}),i(null),f(!1),{ok:!0}}return!a.ok&&a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):!a.ok&&a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:!a.ok&&(a.failure.kind==="http"||a.failure.kind==="unauthorized")&&a.failure.code==="invalid_code"?(i("invalid_code"),{ok:!1,code:"invalid_code",error:a.failure.error}):{ok:!1,code:"error",error:a.ok||a.failure.kind==="unavailable"?"Sign-in failed \u2014 please request a new link.":a.failure.error}}finally{u(!1)}},[t]),x=e.consumeUrlCode??!0;(0,ee.useEffect)(()=>{if(!(typeof window>"u")&&v.current===void 0){if(!x){v.current=null;return}let b=new URL(window.location.href),a=b.searchParams.get("code");a&&(b.searchParams.delete("code"),window.history.replaceState(window.history.state,"",b.toString())),v.current=a,a&&d(a)}},[d,x]);let k=(0,ee.useCallback)(async b=>{if(typeof window<"u"&&tn(window)){let P=await Hn(b,$e());if(P.claimed){if(P.token!==null){let _=P.customer??{email:b,name:null};return et({token:P.token,customer:_}),n({token:P.token,customer:_}),i(null),{ok:!0,via:"preview"}}return{ok:!1,code:"error",error:P.error}}}let a=await de(t,"/v1/account/login",{method:"POST",body:{email:b}});return a.ok?{ok:!0,via:"email"}:a.failure.kind==="unavailable"?(f(!0),{ok:!1,code:"unavailable",error:"Sign-in is temporarily unavailable \u2014 please try again later."}):a.failure.kind==="http"&&a.failure.status===429?{ok:!1,code:"rate_limited",error:a.failure.error}:{ok:!1,code:"error",error:(a.failure.kind==="network",a.failure.error)}},[t]),p=(0,ee.useCallback)(async()=>{let b=Pe()?.token;b&&await de(t,"/v1/account/logout",{method:"POST",token:b,body:{}}),me(),n(null),i(null)},[t]),O=(0,ee.useCallback)(async()=>{let b=Pe();if(!b)return;let a=await de(t,"/v1/account/me",{token:b.token}),P=()=>Pe()?.token===b.token;if(a.ok){if(!P())return;let _=a.data.customer??b.customer;et({token:b.token,customer:_}),n({token:b.token,customer:_}),f(!1);return}if(a.failure.kind==="unauthorized"){if(!P())return;me("session_expired"),n(null),i("session_expired");return}if(a.failure.kind==="unavailable"){f(!0);return}},[t]);return{status:y?"pending":r?"signed_in":l?"unavailable":"signed_out",customer:r?.customer??null,token:r?.token??null,reason:r?null:o,login:k,verifyCode:d,logout:p,refresh:O}}var j=require("react");var le=require("react");var D=require("react/jsx-runtime"),wt={display:"flex",flexDirection:"column",gap:"0.75rem",maxWidth:"24rem"},Jn={padding:"0.5rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"1rem"},Gn={padding:"0.5rem 0.75rem",border:"1px solid #111827",borderRadius:6,background:"#111827",color:"white",cursor:"pointer",fontSize:"1rem"},nn={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"},Ee={margin:0},Zn={color:"#b91c1c",margin:0};function Be({apiUrl:e,session:t,resendDelayMs:r=3e4,className:n,style:o,renderForm:i,renderSent:l,renderUnavailable:f}){let y=Ie({apiUrl:e,consumeUrlCode:t===void 0}),u=t??y,[v,d]=(0,le.useState)(""),[x,k]=(0,le.useState)("form"),[p,O]=(0,le.useState)(!1),[w,b]=(0,le.useState)(null),[a,P]=(0,le.useState)(null),[_,s]=(0,le.useState)(!1),c=(0,le.useRef)(void 0),m=(0,le.useRef)(!1);(0,le.useEffect)(()=>()=>{c.current&&clearTimeout(c.current)},[]);let g=()=>{s(!1),c.current&&clearTimeout(c.current),c.current=setTimeout(()=>s(!0),r)},h=async()=>{let R=v.trim();if(!R||p||m.current)return;m.current=!0,O(!0),b(null),P(null);let L=await u.login(R);if(m.current=!1,O(!1),L.ok){if(L.via==="preview")return;k("sent"),g();return}L.code!=="unavailable"&&(b(L.code==="rate_limited"?"rate_limited":"error"),P(L.error))};if(u.status==="unavailable")return f?(0,D.jsx)(D.Fragment,{children:f()}):(0,D.jsx)("div",{className:n,style:n?o:{...wt,...o},"data-state":"unavailable",children:(0,D.jsx)("p",{style:Ee,children:"Sign-in is temporarily unavailable \u2014 please try again in a few minutes."})});if(x==="sent"){let R={email:v.trim(),canResend:_,resend:()=>{h(),g()},submitting:p,reset:()=>k("form")};return l?(0,D.jsx)(D.Fragment,{children:l(R)}):(0,D.jsxs)("div",{className:n,style:n?o:{...wt,...o},"data-state":"sent",children:[(0,D.jsxs)("p",{style:Ee,children:["Check your email \u2014 if ",(0,D.jsx)("strong",{children:R.email})," has orders with this store, a sign-in link is on its way. It expires after a few minutes."]}),_?(0,D.jsxs)("p",{style:Ee,children:["Didn't get it?"," ",(0,D.jsx)("button",{type:"button",style:nn,onClick:R.resend,disabled:p,children:"Send it again"})," ","or"," ",(0,D.jsx)("button",{type:"button",style:nn,onClick:R.reset,children:"use a different email"}),"."]}):(0,D.jsx)("p",{style:Ee,children:"It can take a minute to arrive."})]})}let C={email:v,setEmail:d,submit:()=>void h(),submitting:p,errorKind:w,errorMessage:a,reason:u.reason};if(i)return(0,D.jsx)(D.Fragment,{children:i(C)});let S=R=>{R.preventDefault(),C.submit()};return(0,D.jsxs)("form",{className:n,style:n?o:{...wt,...o},onSubmit:S,"data-state":"form",children:[u.reason==="session_expired"&&(0,D.jsx)("p",{style:Ee,role:"status",children:"Your session has expired \u2014 sign in again to continue."}),u.reason==="invalid_code"&&(0,D.jsx)("p",{style:Ee,role:"status",children:"That sign-in link is invalid or has expired. Enter your email and we'll send you a new one."}),(0,D.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.375rem"},children:[(0,D.jsx)("span",{children:"Email address"}),(0,D.jsx)("input",{type:"email",value:v,onChange:R=>d(R.target.value),autoComplete:"email",required:!0,style:Jn})]}),(0,D.jsx)("button",{type:"submit",style:Gn,disabled:p,children:p?"Sending\u2026":u.reason==="invalid_code"?"Email me a new link":"Email me a sign-in link"}),a&&(0,D.jsx)("p",{style:Zn,role:"alert",children:w==="rate_limited"?"Too many attempts \u2014 please wait a moment and try again.":a})]})}var K=require("react/jsx-runtime"),Qn={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},Xn={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem"},Fe={color:"#6b7280",fontSize:"0.875rem"};function er(e){switch(e.status){case"paid":return null;case"refunded":return"Refunded";case"partially_refunded":return"Partially refunded";case"disputed":return"Disputed";default:return e.status}}function ut({orders:e,className:t,style:r,heading:n="Your orders",renderEmpty:o,renderOrder:i}){return e.length===0?o?(0,K.jsx)(K.Fragment,{children:o()}):(0,K.jsxs)("div",{className:t,style:r,"data-state":"empty",children:[n!==null&&(0,K.jsx)("h3",{children:n}),(0,K.jsx)("p",{style:Fe,children:"No orders yet."})]}):(0,K.jsxs)("div",{className:t,style:r,children:[n!==null&&(0,K.jsx)("h3",{children:n}),(0,K.jsx)("ul",{style:t?void 0:Qn,children:e.map(l=>{if(i)return(0,K.jsx)("li",{style:{display:"contents"},children:i(l)},l.id);let f=De(l.created_at),y=er(l);return(0,K.jsxs)("li",{style:t?void 0:Xn,children:[(0,K.jsxs)("div",{children:[l.order_number!==null&&(0,K.jsxs)("strong",{children:["Order #",l.order_number]})," ",f&&(0,K.jsx)("span",{style:Fe,children:f})," ",l.source==="subscription"&&(0,K.jsx)("span",{style:Fe,children:"\xB7 subscription"}),y&&(0,K.jsxs)("span",{style:Fe,children:[" \xB7 ",y]})]}),l.line_items.length>0&&(0,K.jsx)("div",{style:Fe,children:l.line_items.map(u=>u.name?`${u.quantity&&u.quantity>1?`${u.quantity} \xD7 `:""}${u.name}`:null).filter(Boolean).join(", ")}),(0,K.jsx)("div",{children:z(l.amount_total,l.currency)})]},l.id)})})]})}var te=require("react");var U=require("react/jsx-runtime"),tr={listStyle:"none",margin:0,padding:0,display:"flex",flexDirection:"column",gap:"0.75rem"},nr={border:"1px solid #e5e7eb",borderRadius:8,padding:"0.75rem",display:"flex",flexDirection:"column",gap:"0.5rem"},Ue={color:"#6b7280",fontSize:"0.875rem"},rr={color:"#b91c1c",fontSize:"0.875rem",margin:0},ir={color:"#065f46",fontSize:"0.875rem",margin:0},Pt={display:"flex",flexWrap:"wrap",gap:"0.5rem"},xe={padding:"0.375rem 0.75rem",border:"1px solid #d1d5db",borderRadius:6,background:"white",cursor:"pointer",fontSize:"0.875rem"},on={...xe,border:"1px solid #111827",background:"#111827",color:"white"},or={...xe,border:"1px solid #b91c1c",color:"#b91c1c"},sr={padding:"0.375rem 0.5rem",border:"1px solid #d1d5db",borderRadius:6,fontSize:"0.875rem",width:"100%",boxSizing:"border-box"},rn={panel:"none",mutation:null,portalRefused:!1};function ar(e){let t=De(e.current_period_end);return e.ended?{text:"This subscription has ended.",tone:"ended"}:e.cancel_at_period_end?{text:t?`Scheduled to cancel \u2014 stays active until ${t}.`:"Scheduled to cancel at the end of the current period.",tone:"warn"}:e.status==="past_due"||e.status==="unpaid"?{text:"There's a problem with your last payment \u2014 please update your card.",tone:"warn"}:e.status==="active"||e.status==="trialing"?{text:t?`Renews on ${t}.`:"Active.",tone:"ok"}:{text:`Status: ${e.status}.`,tone:"warn"}}function ur({initial:e,pending:t,onSave:r,onCancel:n}){let o=e?.address??null,[i,l]=(0,te.useState)(e?.name??""),[f,y]=(0,te.useState)(o?.line1??""),[u,v]=(0,te.useState)(o?.line2??""),[d,x]=(0,te.useState)(o?.city??""),[k,p]=(0,te.useState)(o?.state??""),[O,w]=(0,te.useState)(o?.postal_code??""),[b,a]=(0,te.useState)(o?.country??""),P=(_,s,c,m)=>(0,U.jsxs)("label",{style:{display:"flex",flexDirection:"column",gap:"0.25rem",fontSize:"0.875rem"},children:[(0,U.jsx)("span",{children:_}),(0,U.jsx)("input",{style:sr,value:s,onChange:g=>c(g.target.value),required:m?.required,maxLength:m?.maxLength})]});return(0,U.jsxs)("form",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},onSubmit:_=>{_.preventDefault(),r({name:i.trim()||null,address:{line1:f.trim(),line2:u.trim()||null,city:d.trim()||null,state:k.trim()||null,postal_code:O.trim()||null,country:b.trim().toUpperCase()}})},children:[P("Name",i,l),P("Address line 1",f,y,{required:!0}),P("Address line 2",u,v),P("City",d,x),P("State / region",k,p),P("Postal code",O,w),P("Country (2-letter code)",b,a,{required:!0,maxLength:2}),(0,U.jsxs)("div",{style:Pt,children:[(0,U.jsx)("button",{type:"submit",style:on,disabled:t,children:t?"Saving\u2026":"Save address"}),(0,U.jsx)("button",{type:"button",style:xe,onClick:n,disabled:t,children:"Cancel"})]})]})}function ze({apiUrl:e="https://aifeatures.dev",subscriptions:t,auth:r,onAuthError:n,onUnavailable:o,onSubscriptionChange:i,className:l,style:f,heading:y="Your subscriptions",renderEmpty:u,renderRow:v}){let[d,x]=(0,te.useState)(t),[k,p]=(0,te.useState)({}),O=(0,te.useRef)(new Set);(0,te.useEffect)(()=>{x(t)},[t]),(0,te.useEffect)(()=>{let s=c=>{c.persisted&&(O.current.clear(),p(m=>{let g=!1,h={};for(let[C,S]of Object.entries(m))S.mutation?.phase==="pending"?(h[C]={...S,mutation:null},g=!0):h[C]=S;return g?h:m}))};return window.addEventListener("pageshow",s),()=>window.removeEventListener("pageshow",s)},[]);let w=(s,c)=>p(m=>({...m,[s]:{...m[s]??rn,...c}})),b=s=>{x(c=>c.map(m=>m.id===s.id?s:m)),i?.(s)},a=async(s,c,m,g)=>{if(O.current.has(s.id))return{ok:!1};O.current.add(s.id);try{w(s.id,{mutation:{kind:c,phase:"pending"}});let h=await de(e,m,{method:"POST",token:r.token,body:g??{}});if(h.ok)return{ok:!0,data:h.data};let{failure:C}=h;return C.kind==="unauthorized"?(n?.({code:C.code,error:C.error}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="unavailable"?(o?.(),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="ended"?(b({...s,ended:!0,status:"canceled"}),w(s.id,{mutation:null,panel:"none"}),{ok:!1}):C.kind==="http"&&C.code==="portal_unavailable"?(w(s.id,{portalRefused:!0,mutation:{kind:c,phase:"error",error:"Card update is temporarily unavailable."}}),{ok:!1}):(w(s.id,{mutation:{kind:c,phase:"error",error:C.kind==="network"?"That didn't go through \u2014 please check your connection and try again.":C.error}}),{ok:!1})}finally{O.current.delete(s.id)}},P=s=>r.kind==="session"?{cancel:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/cancel`,reactivate:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/reactivate`,address:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/address`,portal:`/v1/account/subscriptions/${encodeURIComponent(s.id)}/portal-session`}:{cancel:"/v1/account/manage/cancel",reactivate:null,address:null,portal:"/v1/account/manage/portal-session"},_=s=>{let c=k[s.id]??rn,m=P(s);return{subscription:s,panel:c.panel,mutation:c.mutation,portalHidden:s.is_test||c.portalRefused,openCancelConfirm:()=>w(s.id,{panel:"confirm_cancel",mutation:null}),closePanel:()=>w(s.id,{panel:"none",mutation:null}),confirmCancel:()=>{(async()=>{let g=await a(s,"cancel",m.cancel);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"cancel",phase:"success"}})}})()},reactivateAvailable:m.reactivate!==null,reactivate:()=>{m.reactivate&&(async()=>{let g=await a(s,"reactivate",m.reactivate);if(g.ok){let h=g.data.subscription;h&&b(h),w(s.id,{panel:"none",mutation:{kind:"reactivate",phase:"success"}})}})()},openAddressForm:()=>{m.address&&w(s.id,{panel:"address",mutation:null})},saveAddress:g=>{m.address&&(async()=>{let h=await a(s,"address",m.address,{shipping_address:g});if(h.ok){let C=h.data.subscription;C&&b(C),w(s.id,{panel:"none",mutation:{kind:"address",phase:"success"}})}})()},openPortal:()=>{(async()=>{let g=await a(s,"portal",m.portal);g.ok&&typeof g.data.url=="string"?window.location.href=g.data.url:g.ok&&w(s.id,{mutation:{kind:"portal",phase:"error",error:"Card update is temporarily unavailable."}})})()}}};return d.length===0?u?(0,U.jsx)(U.Fragment,{children:u()}):(0,U.jsxs)("div",{className:l,style:f,"data-state":"empty",children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("p",{style:Ue,children:"No subscriptions."})]}):(0,U.jsxs)("div",{className:l,style:f,children:[y!==null&&(0,U.jsx)("h3",{children:y}),(0,U.jsx)("ul",{style:l?void 0:tr,children:d.map(s=>{let c=_(s);return v?(0,U.jsx)("li",{style:{display:"contents"},children:v(c)},s.id):(0,U.jsx)("li",{style:l?void 0:nr,"data-status":s.status,"data-ended":s.ended||void 0,children:(0,U.jsx)(lr,{ctx:c})},s.id)})})]})}function lr({ctx:e}){let t=e.subscription,r=ar(t),n=De(t.current_period_end),o=`${z(t.current_amount,t.currency)} ${en(t.plan_interval,t.plan_interval_count)}`,i=e.mutation?.phase==="pending",l=i?e.mutation?.kind:null;return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{children:[(0,U.jsx)("strong",{children:t.plan_title??"Subscription"})," ",(0,U.jsxs)("span",{style:Ue,children:["\xB7 ",o]}),t.is_test&&(0,U.jsx)("span",{style:Ue,children:" \xB7 test"})]}),(0,U.jsx)("div",{style:r.tone==="warn"?void 0:Ue,children:r.text}),t.ended?(0,U.jsx)("p",{style:Ue,children:"This subscription has ended \u2014 to start again, subscribe from the product page."}):e.panel==="confirm_cancel"?(0,U.jsxs)("div",{style:{display:"flex",flexDirection:"column",gap:"0.5rem"},children:[(0,U.jsx)("p",{style:{margin:0},children:n?`Your subscription stays active until ${n} \u2014 after that it won't renew and you won't be charged again.`:"Your subscription stays active until the end of the current billing period \u2014 after that it won't renew and you won't be charged again."}),(0,U.jsxs)("div",{style:Pt,children:[(0,U.jsx)("button",{type:"button",style:or,onClick:e.confirmCancel,disabled:i,children:l==="cancel"?"Canceling\u2026":"Confirm cancellation"}),(0,U.jsx)("button",{type:"button",style:xe,onClick:e.closePanel,disabled:i,children:"Keep subscription"})]})]}):e.panel==="address"?(0,U.jsx)(ur,{initial:t.shipping_address??null,pending:l==="address",onSave:e.saveAddress,onCancel:e.closePanel}):(0,U.jsxs)("div",{style:Pt,children:[t.cancel_at_period_end?e.reactivateAvailable?(0,U.jsx)("button",{type:"button",style:on,onClick:e.reactivate,disabled:i,children:l==="reactivate"?"Resuming\u2026":"Keep my subscription"}):(0,U.jsx)("span",{style:Ue,children:"To keep this subscription, sign in with your email address on this page."}):(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openCancelConfirm,disabled:i,children:"Cancel subscription"}),t.shipping_address!==void 0&&!t.cancel_at_period_end&&(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openAddressForm,disabled:i,children:"Update shipping address"}),!e.portalHidden&&(0,U.jsx)("button",{type:"button",style:xe,onClick:e.openPortal,disabled:i,children:l==="portal"?"Opening\u2026":"Update card"})]}),e.mutation?.phase==="error"&&(0,U.jsx)("p",{style:rr,role:"alert",children:e.mutation.error}),e.mutation?.phase==="success"&&(0,U.jsx)("p",{style:ir,role:"status",children:e.mutation.kind==="cancel"?n?`Cancellation scheduled \u2014 you keep access until ${n}.`:"Cancellation scheduled.":e.mutation.kind==="reactivate"?"Your subscription will continue.":e.mutation.kind==="address"?"Shipping address updated.":"Done."})]})}var T=require("react/jsx-runtime"),cr={display:"flex",flexDirection:"column",gap:"1.25rem"},sn={color:"#6b7280",fontSize:"0.875rem"},dr={border:"1px solid #d1d5db",borderRadius:8,padding:"0.75rem"},an={color:"#b91c1c"},lt={background:"none",border:"none",padding:0,font:"inherit",color:"inherit",textDecoration:"underline",cursor:"pointer"};function un({apiUrl:e="https://aifeatures.dev",className:t,style:r,resendDelayMs:n,loginProps:o,renderLoading:i,renderError:l,renderEmpty:f,renderHeader:y,renderPmBanner:u,renderManageExpired:v}){let d=Ie({apiUrl:e}),x=(0,j.useRef)(void 0),[k,p]=(0,j.useState)(null),[O,w]=(0,j.useState)(!1);(0,j.useEffect)(()=>{if(!(typeof window>"u")){if(x.current===void 0){let N=new URL(window.location.href),E=N.searchParams.get("manage_code"),F=N.searchParams.get("pm");(E!==null||F!==null)&&(N.searchParams.delete("manage_code"),N.searchParams.delete("pm"),window.history.replaceState(window.history.state,"",N.toString())),x.current={manageCode:E,pmUpdated:F==="updated"}}p(x.current.manageCode),w(x.current.pmUpdated)}},[]);let[b,a]=(0,j.useState)(null),P=(0,j.useRef)(!1),_=(0,j.useRef)(0),s=(0,j.useCallback)(N=>{a({phase:"verifying"}),(async()=>{let E=await de(e,"/v1/account/manage/verify",{method:"POST",body:{manage_code:N}});if(E.ok&&typeof E.data.manage_token=="string"&&E.data.subscription){a({phase:"active",token:E.data.manage_token,sub:E.data.subscription,siteName:null});return}if(!E.ok&&E.failure.kind==="unavailable"){a({phase:"unavailable"});return}if(!E.ok&&E.failure.kind==="network"){a({phase:"error",error:E.failure.error});return}a({phase:"expired"})})()},[e]);(0,j.useEffect)(()=>{!k||P.current||(P.current=!0,s(k))},[k,s]);let c=(0,j.useCallback)(async()=>{let N=b;if(!N||N.phase!=="active")return;let E=++_.current,F=await de(e,"/v1/account/manage/subscription",{token:N.token});E===_.current&&(F.ok&&F.data.subscription?a({phase:"active",token:N.token,sub:F.data.subscription,siteName:typeof F.data.site?.name=="string"?F.data.site.name:N.siteName}):!F.ok&&F.failure.kind==="unauthorized"?a({phase:"expired"}):!F.ok&&F.failure.kind==="unavailable"&&a({phase:"unavailable"}))},[e,b]),[m,g]=(0,j.useState)({phase:"loading"}),[h,C]=(0,j.useState)(0),S=h>0,R=(0,j.useRef)(0),L=d.token,$=(0,j.useCallback)(async()=>{if(!L)return;let N=++R.current,E=await de(e,"/v1/account/me",{token:L});if(N===R.current){if(E.ok){g({phase:"ready",data:E.data});return}if(E.failure.kind==="unauthorized"){me("session_expired");return}if(E.failure.kind==="unavailable"){me();return}g({phase:"error",error:E.failure.error})}},[e,L]);(0,j.useEffect)(()=>{!L||k||(g({phase:"loading"}),$())},[L,k,$]);let Q=(0,j.useCallback)(async()=>{C(N=>N+1);try{b&&b.phase==="active"?await c():await $()}finally{C(N=>N-1)}},[b,c,$]),B=(0,j.useCallback)(N=>{R.current++,_.current++,a(E=>E&&E.phase==="active"&&E.sub.id===N.id?{...E,sub:N}:E),g(E=>E.phase==="ready"?{phase:"ready",data:{...E.data,subscriptions:E.data.subscriptions.map(F=>F.id===N.id?N:F)}}:E)},[]),A=t?r:{...cr,...r},M=N=>{if(!O)return null;let F={state:N.some(ie=>!ie.ended&&(ie.status==="past_due"||ie.status==="unpaid"))?"retrying":"recovered",checkAgain:()=>void Q(),checking:S};return u?u(F):(0,T.jsx)("div",{style:dr,role:"status","data-pm-state":F.state,children:F.state==="retrying"?(0,T.jsxs)(T.Fragment,{children:[(0,T.jsx)("p",{style:{margin:0},children:"Card updated \u2014 we're retrying your payment. This can take a few minutes."}),(0,T.jsx)("p",{style:{margin:"0.375rem 0 0"},children:(0,T.jsx)("button",{type:"button",style:lt,onClick:F.checkAgain,disabled:S,children:S?"Checking\u2026":"Check again"})})]}):(0,T.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,T.jsx)(T.Fragment,{children:i()}):(0,T.jsx)("div",{className:t,style:A,role:"status",children:(0,T.jsx)("p",{children:"Opening your subscription\u2026"})}):b.phase==="active"?(0,T.jsxs)("div",{className:t,style:A,children:[M([b.sub]),(0,T.jsx)(ze,{apiUrl:e,subscriptions:[b.sub],auth:{kind:"manage",token:b.token},heading:"Your subscription",onSubscriptionChange:B,onAuthError:()=>a({phase:"expired"}),onUnavailable:()=>a({phase:"unavailable"})})]}):b.phase==="unavailable"?(0,T.jsx)("div",{className:t,style:A,"data-state":"unavailable",children:(0,T.jsx)("p",{children:"Subscription management is temporarily unavailable \u2014 please try again in a few minutes."})}):b.phase==="error"?(0,T.jsxs)("div",{className:t,style:A,children:[(0,T.jsx)("p",{style:an,role:"alert",children:b.error}),(0,T.jsx)("p",{children:(0,T.jsx)("button",{type:"button",style:lt,onClick:()=>s(k),children:"Try again"})})]}):(0,T.jsxs)("div",{className:t,style:A,"data-state":"manage-expired",children:[v?v():(0,T.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,T.jsx)(Be,{apiUrl:e,session:d,resendDelayMs:n,...o})]});if(d.status==="pending")return i?(0,T.jsx)(T.Fragment,{children:i()}):(0,T.jsx)("div",{className:t,style:A,role:"status",children:(0,T.jsx)("p",{children:"Signing you in\u2026"})});if(d.status!=="signed_in")return(0,T.jsx)("div",{className:t,style:A,children:(0,T.jsx)(Be,{apiUrl:e,session:d,resendDelayMs:n,...o})});if(m.phase==="loading")return i?(0,T.jsx)(T.Fragment,{children:i()}):(0,T.jsx)("div",{className:t,style:A,role:"status",children:(0,T.jsx)("p",{children:"Loading your account\u2026"})});if(m.phase==="error")return l?(0,T.jsx)(T.Fragment,{children:l({error:m.error,retry:()=>void $()})}):(0,T.jsxs)("div",{className:t,style:A,children:[(0,T.jsxs)("p",{style:an,role:"alert",children:["We couldn't load your account \u2014 ",m.error]}),(0,T.jsx)("p",{children:(0,T.jsx)("button",{type:"button",style:lt,onClick:()=>void $(),children:"Try again"})})]});let{data:V}=m,Y=V.customer??d.customer??{email:"",name:null},q=()=>void d.logout(),J=V.orders.length===0&&V.subscriptions.length===0;return(0,T.jsxs)("div",{className:t,style:A,children:[y?y({customer:Y,site:V.site??null,signOut:q}):(0,T.jsxs)("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"baseline",gap:"1rem",flexWrap:"wrap"},children:[(0,T.jsxs)("div",{children:[(0,T.jsx)("h2",{style:{margin:0},children:"Your account"}),(0,T.jsxs)("p",{style:{...sn,margin:0},children:["Signed in as ",Y.email]})]}),(0,T.jsx)("button",{type:"button",style:lt,onClick:q,children:"Sign out"})]}),M(V.subscriptions),J?f?f():(0,T.jsxs)("p",{style:sn,children:["Nothing here yet \u2014 orders and subscriptions for ",Y.email," ","will show up on this page."]}):(0,T.jsxs)(T.Fragment,{children:[V.subscriptions.length>0&&(0,T.jsx)(ze,{apiUrl:e,subscriptions:V.subscriptions,auth:{kind:"session",token:L},onSubscriptionChange:B,onAuthError:()=>me("session_expired"),onUnavailable:()=>me()}),(0,T.jsx)(ut,{orders:V.orders})]})]})}0&&(module.exports={AccountLogin,AccountOrders,AccountPage,AddToCartButton,AifeaturesCaptcha,BuyButton,CartCheckoutButton,MARKET_COUNTRIES,MAX_CART_LINES,OrderConfirmation,PlanPicker,ProductPrice,SubscriptionList,VariantPicker,ZERO_DECIMAL_CURRENCIES,applySelectionToUrl,formatPrice,getOptions,getVariants,isMultiVariant,isValueAvailable,isValueInCatalog,planRecurringAmount,reanchorSelection,resolveVariant,searchFromSelection,selectedImages,selectedValues,selectionFromSearch,useCart,useCartCheckout,useCartItems,useCartSummary,useCheckout,useMarket,useProduct,useSession,valueSlug,variantPriceRange});