import{c as o}from"./p-2b28ea49.js";import{g as i}from"./p-dd24e53c.js";import{g as d}from"./p-f2d66ed2.js";import{i as l}from"./p-fb28f84f.js";import{u as n,a as v}from"./p-efd935a6.js";import{o as t}from"./p-b28405ea.js";const{productDonation:u}=i(),s=Object.keys(u||{}).reduce(((o,a)=>{var u;const n=d(a);return(null==n?void 0:n.id)&&(o[a]={...o[a],...(null==n?void 0:n.ad_hoc_amount)?{ad_hoc_amount:n.ad_hoc_amount}:{},...(null==n?void 0:n.price)?{selectedPrice:n.price}:{},custom_amount:(null===(u=o[a].amounts||[])||void 0===u?void 0:u.includes(n.ad_hoc_amount))?null:n.ad_hoc_amount}),o}),u),{state:a,onChange:c,on:e,set:r,get:m,dispose:f}=o({...s},((o,a)=>JSON.stringify(o)!==JSON.stringify(a))),p=o=>{const d=a[o],u=(d.amounts||[]).filter((o=>l(o,d.selectedPrice)));return u.includes(null==d?void 0:d.ad_hoc_amount)?null==d?void 0:d.ad_hoc_amount:u[0]},_=o=>{const d=a[o];return(d.amounts||[]).filter((o=>l(o,d.selectedPrice)))},j=(o,d)=>{a[o]={...a[o],...d}},b=(o,a)=>{const u=d(o);return(null==u?void 0:u.id)?n({id:u.id,data:{...{price:u.price.id,...(null==u?void 0:u.ad_hoc_amount)?{ad_hoc_amount:null==u?void 0:u.ad_hoc_amount}:{}},...a}}):v(a)};t("checkout",(()=>{Object.keys(a).forEach((o=>{var u;const n=d(o);if(n)return r(o,{...a[o],selectedPrice:n.price,ad_hoc_amount:n.ad_hoc_amount,custom_amount:(null===(u=a[o].amounts||[])||void 0===u?void 0:u.includes(n.ad_hoc_amount))?null:n.ad_hoc_amount});r(o,{...a[o],selectedPrice:null,ad_hoc_amount:null,custom_amount:null})}))})),Object.keys(a).forEach((o=>{e("set",((a,d,u)=>{var n,t,i,e,c,s;if(a===o&&((null==d?void 0:d.selectedPrice)||(null==d?void 0:d.ad_hoc_amount)||(null==d?void 0:d.custom_amount))&&((null===(n=null==d?void 0:d.selectedPrice)||void 0===n?void 0:n.id)!==(null===(t=null==u?void 0:u.selectedPrice)||void 0===t?void 0:t.id)||(null==d?void 0:d.ad_hoc_amount)!==(null==u?void 0:u.ad_hoc_amount)||(null==d?void 0:d.custom_amount)!==(null==u?void 0:u.custom_amount))){const a=(null==d?void 0:d.custom_amount)&&l(null==d?void 0:d.custom_amount,d.selectedPrice)?null==d?void 0:d.custom_amount:p(o),u=(null===(i=d.selectedPrice)||void 0===i?void 0:i.id)||(null===(s=null===(c=null===(e=d.product)||void 0===e?void 0:e.prices)||void 0===c?void 0:c.data.find((o=>null==o?void 0:o.ad_hoc)))||void 0===s?void 0:s.id);if(!u)return;b(o,{price:u,quantity:1,ad_hoc_amount:a})}}))}));export{e as a,r as b,_ as c,f as d,m as g,c as o,a as s,j as u};