import{r as o,g as z,u as w,s as r,a as q,b as F,c as G,d as J,f as K,n as k}from"./BCLrUOBx.js";import{u as Q}from"./D7xsgz5m.js";import{u as X}from"./Ce8lFovl.js";function ee({product:t,productInventory:i,emit:T}){const c=o(!1),v=o(!1),f=o(!1),l=o(1),n=o({attribute:null,quantity:null}),C=z(),A=w(),{langCode:R}=r(A),j=Q(),{cartAction:x,buyNow:E}=j,h=q(),{getUserToken:L}=h,{profile:N}=r(h),m=F(),{setting:U}=r(m),{setToastError:y,postRequest:W,setToastMessage:O}=m,V=G(),{authenticated:_}=r(V),B=X(),{updateWishlist:D}=B,{t:g}=J(),H=K(()=>{var e,a;return((e=N.value)==null?void 0:e.id)&&((a=t.value)==null?void 0:a.wishlisted)}),M=async()=>{if(!_.value)return k("/login");c.value=!0;const e=await W({api:"userWishlistAction",params:{product_id:t.value.id}});c.value=!1,(e==null?void 0:e.status)===200?(O(e.message),D(e)):y(e.data.form.join(", "))},b=()=>{T("cart-error",n.value)},P=async(e=!1)=>{var a,s,u;if(!((a=U.value)!=null&&a.guest_checkout)&&!_.value)return k("/login");if(n.value={attribute:null,quantity:null},!((s=t.value)!=null&&s.in_stock))return y(g("detailRight.outOfStock")),!1;if(Object.values(i.value).length===0){const p=(u=t.value)==null?void 0:u.attribute.map(d=>d==null?void 0:d.title);return n.value.attribute=g("detailRight.requiredAttributes"),p.length&&(n.value.attribute+=`(${p.join(" / ")})`),b(),!1}if(i.value.quantity<l.value)return n.value.quantity=g("detailRight.exceedsInventory"),b(),!1;e?(await $(),setTimeout(()=>{C.push({path:"/shipping"})},300)):await S()},$=async()=>{const{langCode:e}=r(w()),a=q(),{getUserToken:s}=a;f.value=!0;const u=await E({payload:{user_token:await s(),product_id:t.value.id,inventory_id:i.value.id,quantity:l.value},lang:e.value});return f.value=!1,u},S=async()=>{var a,s,u;v.value=!0;const e=await L();await x({payload:{user_token:e,apiVal:{user_token:e,product_id:t.value.id,inventory_id:(a=i.value)==null?void 0:a.id,quantity:l.value},isBundle:!!((s=t.value)!=null&&s.bundle_deal),storeVal:{product:{id:t.value.id,title:t.value.title,offered:t.value.offered,selling:t.value.selling,image:t.value.image,shipping_rule:t.value.shipping_rule},inventory:i.value,quantity:l.value,selected:1,offered:0,bundle_deal:(u=t.value)==null?void 0:u.bundle_deal,shipping_type:1}},lang:R.value}),v.value=!1};return{wishListAction:M,cartAdd:S,cartError:n,ajaxingWishlist:c,buyingNow:f,addToCart:P,quantity:l,ajaxing:v,wishListed:H}}export{ee as u};
