"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3335],{9860:function(e,l,c){c.r(l),c.d(l,{default:function(){return b}});var a=c(5893),o=c(6905),s=c.n(o),r=c(7294);function i(e){let{discount:l}=e;return l&&(0,a.jsx)("div",{className:"combo_badge",children:l})}var t=c(5675),n=c.n(t),d=c(9803),u=c(5198),p=c(6577),m=c(7041),_=c(5152);let v=c.n(_)()(()=>c.e(3134).then(c.bind(c,3134)),{loadableGenerated:{webpack:()=>[3134]}});function h(e){var l,c,o;let{product:t,closeModal:_,globalMagento:h,sarabun:b}=e,[x,j]=(0,r.useState)(null),[g,N]=(0,r.useState)(t),[f,k]=(0,r.useState)(!1),[y,F]=(0,r.useState)([]),[P,w]=(0,r.useState)([]),[S,C]=(0,r.useState)(0),[E,M]=(0,r.useState)(0),D=(null==t?void 0:t.upsell_products)||[],[X,q]=(0,r.useState)(0),A=async()=>{var e,l,c;let a=await (0,p.fq)();F(null==a?void 0:a.data);let o=[];if(null==a||null===(c=a.data)||void 0===c||null===(l=c.cart)||void 0===l||null===(e=l.items)||void 0===e||e.forEach(e=>{var l;if((null==e?void 0:null===(l=e.product)||void 0===l?void 0:l.sku)==(null==t?void 0:t.sku)){let l=s()(g,"upsell_products",[]).find(l=>{var c;return l.sku===(null==e?void 0:null===(c=e.product)||void 0===c?void 0:c.sku)});l&&o.push(l)}}),null==o?void 0:o.length)null==o||o.forEach(e=>{let l=parseFloat(s()(e,"special_price")),c=parseFloat(s()(e,"price.regularPrice.amount.value")),a=l||c;C(e=>e+a)}),N(e=>({...e,upsell_products:o}));else{let e=parseFloat(s()(t,"special_price"))||parseFloat(s()(t,"price.regularPrice.amount.value"));D.forEach(l=>{let c=parseFloat(s()(l,"special_price")),a=parseFloat(s()(l,"price.regularPrice.amount.value"));e+=c||a}),C(e)}};(0,r.useEffect)(()=>{N(t),F([]),w([]),C(0),M(0),A();let e=parseFloat(s()(t,"special_price")),l=parseFloat(s()(t,"price.regularPrice.amount.value"));C(e||l),j((0,m.getCookie)("symbol_currency")||"")},[t]),(0,r.useEffect)(()=>{var e;w((null==g?void 0:null===(e=g.upsell_products)||void 0===e?void 0:e.map(e=>null==e?void 0:e.id))||[])},[g]),(0,r.useEffect)(()=>{M(s()(t,"combo_discount_value")/100*S)},[S]);let G=(e,l,c)=>{let a;let o=c.target.checked,r=parseFloat(l);w(l=>o?[...l,e]:l.filter(l=>l!==e)),o?C(e=>e+r):C(e=>e-r),a=o?[...s()(g,"upsell_products",[]),s()(t,"upsell_products").find(l=>l.id===e)]:s()(g,"upsell_products",[]).filter(l=>l.id!==e),N(e=>({...e,upsell_products:a}))},T=async e=>{k(!0),document.body.style.overflow="hidden"};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)("div",{className:"prod_combo_card",children:[(0,a.jsx)("div",{className:"combo_prod_container current_prod",children:(0,a.jsx)("div",{className:"combo_prod_block ",children:(0,a.jsxs)("div",{className:"inner",children:[(0,a.jsxs)("div",{className:"image_block",children:[(0,a.jsx)(n(),{loader:d.X,src:"".concat(s()(t,"thumbnail.url")),alt:"".concat(s()(t,"thumbnail.label")),width:290,height:241,style:{width:"auto",height:"auto"}}),s()(t,"combo_discount_value")&&(0,a.jsx)(i,{discount:"".concat(s()(t,"combo_discount_value"),"%")})]}),(0,a.jsxs)("div",{className:"prod_combo_info",children:[t&&(0,a.jsx)("h2",{className:"".concat(b," combo_prod_title"),children:t.name}),t&&(0,a.jsx)("p",{className:"combo_prod_price",children:(0,a.jsx)(u.P,{value:s()(t,"price.regularPrice.amount.value"),currency:s()(t,"price.regularPrice.amount.currency")})})]})]})})}),(0,a.jsx)("div",{className:"combo_prod_container combo_prod",children:s()(t,"upsell_products")&&s()(t,"upsell_products").map(e=>(0,a.jsxs)("div",{className:"custom_check combo_prod_block",children:[(0,a.jsx)("input",{type:"checkbox",name:"",id:e.name,value:0,className:"check",checked:P.includes(e.id),onChange:l=>G(s()(e,"id"),s()(e,"special_price")?s()(e,"special_price"):s()(e,"price.regularPrice.amount.value"),l)}),(0,a.jsx)("label",{htmlFor:e.name,children:(0,a.jsx)("div",{className:"",children:(0,a.jsxs)("div",{className:"inner",children:[(0,a.jsxs)("div",{className:"image_block",children:[(0,a.jsx)(n(),{loader:d.X,src:"".concat(s()(e,"thumbnail.url")),alt:"".concat(s()(e,"image.label")),width:290,height:241,style:{width:"auto",height:"auto"}}),s()(t,"combo_discount_value")&&(0,a.jsx)(i,{discount:"".concat(s()(t,"combo_discount_value"),"%")})]}),(0,a.jsxs)("div",{className:"prod_combo_info",children:[t&&(0,a.jsx)("h2",{className:"".concat(b," combo_prod_title"),children:e.name}),e&&(0,a.jsx)("p",{className:"combo_prod_price",children:(0,a.jsx)(u.P,{value:s()(e,"price.regularPrice.amount.value"),currency:s()(e,"price.regularPrice.amount.currency")})})]})]})},e.id)})]},"combo-prod-block-".concat(e.id)))})]}),(0,a.jsxs)("div",{className:"combo_total",children:[(0,a.jsx)("div",{className:"combo_price",children:(0,a.jsxs)("div",{className:"combo_price_inner",children:[s()(t,"combo_discount_value")&&(null==g?void 0:null===(l=g.upsell_products)||void 0===l?void 0:l.length)>0&&(0,a.jsx)("del",{className:"actual_price",children:"".concat(x).concat(S.toFixed(2))}),(0,a.jsxs)("span",{className:"total_price",children:[(null==g?void 0:null===(c=g.upsell_products)||void 0===c?void 0:c.length)>0&&"".concat(x).concat((S.toFixed(2)-E).toFixed(2)),(null==g?void 0:null===(o=g.upsell_products)||void 0===o?void 0:o.length)<=0&&"".concat(x).concat(S.toFixed(2))]}),"                    "]})}),(0,a.jsx)("button",{onClick:T,className:"primary_cta",children:"Add To Cart"})]}),f&&(0,a.jsx)(v,{product:g,globalMagento:{...h,currencySymbol:x},closeModal:_,mainProduct:t,cartFromCartProvider:y,close_dialog:()=>{k(!1),document.body.style.overflow="auto"},popup:f,sarabun:b})]})}var b=e=>{let{product:l,closeModal:c,globalMagento:o,sarabun:r}=e;return s()(l,"upsell_products")&&s()(l,"upsell_products.length")>0&&(0,a.jsx)(a.Fragment,{children:(0,a.jsx)("div",{className:"section_bg",children:(0,a.jsx)("div",{className:"section_padding",children:(0,a.jsx)("div",{className:"main_container",children:(0,a.jsxs)("div",{className:"prod_combo",children:[(null==l?void 0:l.combo_discount_value)&&(0,a.jsxs)("h2",{className:"".concat(r," primary_title"),children:["Pick a Combo Deal with ",(0,a.jsxs)("span",{className:"combo_prod_price",children:[null==l?void 0:l.combo_discount_value,"%"]})," Discount"]}),(0,a.jsx)("div",{className:"prod_combo_inner",children:(0,a.jsx)(h,{closeModal:c,product:l,globalMagento:o,sarabun:r})})]})})})})})}}}]);