import{c as o}from"./p-03631502.js";import{g as i}from"./p-9dbc54d6.js";import{g as d}from"./p-6b5d827f.js";import{i as l}from"./p-93127aa7.js";import{u as n,a as v}from"./p-1712c78c.js";import{o as t}from"./p-53e7f7d7.js";const{productDonation:u}=i(),s=Object.keys(u||{}).reduce(((o,u)=>{var n;const t=d(u);return(null==t?void 0:t.id)&&(o[u]={...o[u],...(null==t?void 0:t.ad_hoc_amount)?{ad_hoc_amount:t.ad_hoc_amount}:{},...(null==t?void 0:t.price)?{selectedPrice:t.price}:{},custom_amount:(null===(n=o[u].amounts||[])||void 0===n?void 0:n.includes(t.ad_hoc_amount))?null:t.ad_hoc_amount}),o}),u),{state:c,onChange:a,on:r,set:e,get:m,dispose:p}=o({...s},((o,d)=>JSON.stringify(o)!==JSON.stringify(d))),f=o=>{const d=c[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=c[o];return(d.amounts||[]).filter((o=>l(o,d.selectedPrice)))},j=(o,d)=>{c[o]={...c[o],...d}},h=(o,u)=>{const t=d(o);return(null==t?void 0:t.id)?n({id:t.id,data:{...{price:t.price.id,...(null==t?void 0:t.ad_hoc_amount)?{ad_hoc_amount:null==t?void 0:t.ad_hoc_amount}:{}},...u}}):v(u)};t("checkout",(()=>{Object.keys(c).forEach((o=>{var u;const n=d(o);if(n)return e(o,{...c[o],selectedPrice:n.price,ad_hoc_amount:n.ad_hoc_amount,custom_amount:(null===(u=c[o].amounts||[])||void 0===u?void 0:u.includes(n.ad_hoc_amount))?null:n.ad_hoc_amount});e(o,{...c[o],selectedPrice:null,ad_hoc_amount:null,custom_amount:null})}))})),Object.keys(c).forEach((o=>{r("set",((d,u,n)=>{var t,c,i,a,e,s;if(d===o&&((null==u?void 0:u.selectedPrice)||(null==u?void 0:u.ad_hoc_amount)||(null==u?void 0:u.custom_amount))&&((null===(t=null==u?void 0:u.selectedPrice)||void 0===t?void 0:t.id)!==(null===(c=null==n?void 0:n.selectedPrice)||void 0===c?void 0:c.id)||(null==u?void 0:u.ad_hoc_amount)!==(null==n?void 0:n.ad_hoc_amount)||(null==u?void 0:u.custom_amount)!==(null==n?void 0:n.custom_amount))){const d=(null==u?void 0:u.custom_amount)&&l(null==u?void 0:u.custom_amount,u.selectedPrice)?null==u?void 0:u.custom_amount:f(o),n=(null===(i=u.selectedPrice)||void 0===i?void 0:i.id)||(null===(s=null===(e=null===(a=u.product)||void 0===a?void 0:a.prices)||void 0===e?void 0:e.data.find((o=>null==o?void 0:o.ad_hoc)))||void 0===s?void 0:s.id);if(!n)return;h(o,{price:n,quantity:1,ad_hoc_amount:d})}}))}));export{r as a,e as b,_ as c,p as d,m as g,a as o,c as s,j as u};