import{U as g}from"./chunks/Url.js?ver=1.5.4";import"./chunks/Str.js?ver=1.5.4";import"./chunks/Arr.js?ver=1.5.4";import"./chunks/vue-router.js?ver=1.5.4";import"./chunks/vue.esm-bundler.js?ver=1.5.4";document.addEventListener("DOMContentLoaded",function(){const u=document.querySelectorAll("[data-fct_order_bump]");u&&u.forEach(t=>{t.addEventListener("input",function(s){var o,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=(o=window.fluent_cart_checkout_ui_service)==null?void 0:o.disableCheckoutButton)==null||p.call(o);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(),n=r.ok;return e.then(m=>({isOk:n,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,n;t.checked=!d,(n=(e=window.fluent_cart_checkout_ui_service)==null?void 0:e.enableCheckoutButton)==null||n.call(e)})})})});
