@aifeatures/react 0.2.0 → 0.3.1

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,68 +1,2 @@
1
1
  "use client";
2
- "use strict";
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
-
21
- // src/index.ts
22
- var index_exports = {};
23
- __export(index_exports, {
24
- AifeaturesCaptcha: () => AifeaturesCaptcha
25
- });
26
- module.exports = __toCommonJS(index_exports);
27
-
28
- // src/AifeaturesCaptcha.tsx
29
- var import_react = require("react");
30
- var import_react_turnstile = require("@marsidev/react-turnstile");
31
- var import_jsx_runtime = require("react/jsx-runtime");
32
- function AifeaturesCaptcha({
33
- formId,
34
- apiUrl = "https://aifeatures.dev",
35
- onVerify,
36
- onError,
37
- className
38
- }) {
39
- const [sitekey, setSitekey] = (0, import_react.useState)(null);
40
- const [isLoading, setIsLoading] = (0, import_react.useState)(true);
41
- (0, import_react.useEffect)(() => {
42
- setIsLoading(true);
43
- fetch(`${apiUrl}/f/${formId}/config`).then((r) => r.json()).then((config) => {
44
- setSitekey(config.turnstile_sitekey);
45
- setIsLoading(false);
46
- }).catch(() => {
47
- setIsLoading(false);
48
- });
49
- }, [formId, apiUrl]);
50
- if (isLoading || !sitekey) {
51
- return null;
52
- }
53
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
54
- import_react_turnstile.Turnstile,
55
- {
56
- siteKey: sitekey,
57
- onSuccess: onVerify,
58
- onError,
59
- onExpire: onError,
60
- options: { theme: "light" }
61
- }
62
- ) });
63
- }
64
- // Annotate the CommonJS export names for ESM import in node:
65
- 0 && (module.exports = {
66
- AifeaturesCaptcha
67
- });
68
- //# sourceMappingURL=index.cjs.map
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});