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-d7c7b076.js";import{o as t}from"./p-53e7f7d7.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:r,set:e,get:m,dispose:p}=o({...s},((o,d)=>JSON.stringify(o)!==JSON.stringify(d))),f=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 e(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});e(o,{...a[o],selectedPrice:null,ad_hoc_amount:null,custom_amount:null})}))})),Object.keys(a).forEach((o=>{r("set",((d,a,u)=>{var n,t,i,c,e,s;if(d===o&&((null==a?void 0:a.selectedPrice)||(null==a?void 0:a.ad_hoc_amount)||(null==a?void 0:a.custom_amount))&&((null===(n=null==a?void 0:a.selectedPrice)||void 0===n?void 0:n.id)!==(null===(t=null==u?void 0:u.selectedPrice)||void 0===t?void 0:t.id)||(null==a?void 0:a.ad_hoc_amount)!==(null==u?void 0:u.ad_hoc_amount)||(null==a?void 0:a.custom_amount)!==(null==u?void 0:u.custom_amount))){const d=(null==a?void 0:a.custom_amount)&&l(null==a?void 0:a.custom_amount,a.selectedPrice)?null==a?void 0:a.custom_amount:f(o),u=(null===(i=a.selectedPrice)||void 0===i?void 0:i.id)||(null===(s=null===(e=null===(c=a.product)||void 0===c?void 0:c.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(!u)return;b(o,{price:u,quantity:1,ad_hoc_amount:d})}}))}));export{r as a,e as b,_ as c,p as d,m as g,c as o,a as s,j as u};