import{U as g}from"./Url-D4lOoZOf.js";import"./Str-Ckn63bs5.js";import"./vue.esm-bundler-DZdE0M9V.js";import"./Arr-MwYQQ3qa.js";document.addEventListener("DOMContentLoaded",function(){const u=document.querySelectorAll("[data-fct_order_bump]");u&&u.forEach(t=>{t.addEventListener("input",function(s){var n,p;s.preventDefault();let c=t.getAttribute("data-upgrade_to"),i=t.getAttribute("data-upgrade_form"),_=t.getAttribute("data-fct_bump_id");const d=s.target.checked;if(d||(i=t.getAttribute("data-upgrade_to"),c=t.getAttribute("data-upgrade_form")),(!c||!i)&&!_)return;(p=(n=window.fluent_cart_checkout_ui_service)==null?void 0:n.disableCheckoutButton)==null||p.call(n);let l=window.fluentcart_checkout_vars.ajaxurl+"?action=fluent_cart_checkout_routes&fc_checkout_action=apply_order_bump";const h=new URLSearchParams(window.location.search),a={};h.has("fct_cart_hash")&&(a.fct_cart_hash=h.get("fct_cart_hash")),a.upgrade_to=c,a.upgrade_form=i,a.is_upgraded=d?"yes":"no",a.bump_id=_;const f=g.appendQueryParams(l,a);fetch(f,{method:"POST",headers:{"X-WP-Nonce":window.fluentCartRestVars.rest.nonce,"Content-Type":"application/json"},credentials:"include"}).then(r=>{let e=r.json(),o=r.ok;return e.then(m=>({isOk:o,data:m}))}).then(r=>{var e;if(!r.isOk)throw new Error(r.data.message||"Something went wrong");if((e=r.data)!=null&&e.shipping_changed){window.location.reload();return}window.dispatchEvent(new Event("fluentCartNotifyCartDrawerItemChanged"))}).catch(r=>{var e,o;t.checked=!d,(o=(e=window.fluent_cart_checkout_ui_service)==null?void 0:e.enableCheckoutButton)==null||o.call(e)})})})});
