(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[359],{66976:function(e,t,s){(window.__NEXT_P=window.__NEXT_P||[]).push(["/[market]/guest/favorites",function(){return s(6619)}])},23655:function(e,t,s){"use strict";s.d(t,{Z:function(){return j}});var a=s(85893),r=s(67294),i=s(11163),n=s(25675),o=s.n(n),l=s(2668),c=s(51485),u=s.n(c),d=s(76839),f=s(34469),h=s(84670),v=s(52268),p=s(49638),m=s(85680);function j(e){let{list:t,products:s,userLists:n}=e,c=(0,r.useContext)(h.Z),j=(0,i.useRouter)(),[N,g]=(0,r.useState)(!1),[x,w]=(0,r.useState)(!1),[k,S]=(0,r.useState)(!1),[I,C]=(0,r.useState)(t.notes),[y,_]=(0,r.useState)(!0);(0,r.useEffect)(()=>{!1===k?_(!0):_(!1)},[k]);let b=(0,r.useCallback)(async(e,t)=>{let s={};g(!0),s="all"==t.id?await E(e):await Z(e,t),c.updateUserLists(s),g(!1)},[t]),E=async e=>{let t=await fetch("/api/user/favorite");if(200!==t.status)return{};let s=await t.json();return s},Z=(0,r.useCallback)(async(e,t)=>{let a;let r=s.filter(e=>e.selected),i=e.filter(e=>!r.filter(t=>t.sku===e.sku).length);if(i.length){let e=[...i].map(e=>e.favoriteId);a="/api/user/favorite?a=add-to-list&favoriteIds=".concat(e.join(","),"&userId=").concat(t.userId,"&listId=").concat(t.id)}else{let s=r.filter(t=>!e.filter(e=>e.sku===t.sku).length);if(s.length){let e=[...s].map(e=>e.favoriteId);a="/api/user/favorite?a=remove-from-list&favoriteIds=".concat(e.join(","),"&userId=").concat(t.userId,"&listId=").concat(t.id)}}if(!a)return n;let o=await fetch(a).catch(e=>console.error("Error adding favorites to list",e));if(200!=o.status)return{};let l=await o.json();return l},[s,n]),F=(0,r.useCallback)((e,s,a)=>{C(s),t.notes=s},[t]),O=(0,r.useCallback)(()=>{S(!k)},[k]),P=(0,r.useCallback)(async()=>{let e="/api/user/favorite?a=update-list-notes&listId=".concat(t.id,"¬es=").concat(t.notes,"&userId=").concat(t.userId);await fetch(e).catch(e=>console.error("Error updating notes for list",e)),S(!1)},[t]),L="all"==t.id&&"guest"==t.userId;return(0,a.jsxs)("div",{className:u().FavoriteContainer,"data-component":"Favorites",children:[(0,a.jsxs)("div",{className:u().CreateFavoriteList,children:[(0,a.jsx)("h2",{children:"These Are Your Favorite Items"}),(0,a.jsxs)("p",{className:u().HeartIndication,children:["These are the floors that you",(0,a.jsx)(o(),{src:"/static/img/icon-fav-fill-blush.svg",alt:"heart",width:"20",height:"16",style:{maxWidth:"100%",height:"auto"}}),".",c.user&&(0,a.jsx)(a.Fragment,{children:"Create curated lists for every project."})]}),c.user&&(0,a.jsx)(d.Z,{modalClassName:"ModalCreateProductList",purpose:"Create a New List",show:x,setShow:w,children:(0,a.jsx)(f.Z,{onSubmit:()=>{w(!1),j.push("".concat((0,m.KZ)(),"/favorites"))}})})]}),c.user&&(0,a.jsxs)("div",{className:u().FavoriteInfo,children:[(0,a.jsx)("div",{className:u().OrangeBar}),(0,a.jsxs)("div",{className:u().favoriteContent,children:[(0,a.jsx)("h3",{children:t.name}),(0,a.jsx)("p",{className:u().favoriteNotes,children:"Notes"}),(0,a.jsx)(v.Z,{disabled:y,slug:"notes",val:t.notes,onChange:F}),(0,a.jsx)("div",{className:u().editNoteBtnContainer,children:(0,a.jsx)("a",{className:u().editNoteBtn,href:"#",onClick:e=>{e.preventDefault(),k?P():O()},children:k?"Save Notes":"Edit Notes"})})]})]}),(0,a.jsxs)("div",{className:u().FavoriteProductList,style:{position:"relative"},children:[N&&(0,a.jsx)(p.Z,{spinner:"Spinner-Blush"}),!!(null==s?void 0:s.length)&&(0,a.jsx)(l.Z,{products:s,options:{hideFilters:!0,isFavoriteList:!0,showItemDetail:!0,isEditableView:"all"!==t.id,isResults:!1,guestUser:L,onSelectedProductChange:e=>b(e,t)}})]})]})}},6619:function(e,t,s){"use strict";s.r(t),s.d(t,{__N_SSP:function(){return c},default:function(){return u}});var a=s(85893),r=s(67294),i=s(56816),n=s(23655),o=s(35181);let l=async()=>{let e=JSON.parse(window.localStorage.getItem("product-favorites"));if(!e)return[];let t=e.filter(e=>!e.product);if(!t.length)return e;let s=await fetch("/api/products/get-by-skus",{body:JSON.stringify({skus:t.map(e=>e.Sku)}),method:"POST"});if(!s.ok)return e;let a=await s.json();return e.forEach(e=>{e.product||(e.product=a.filter(t=>t.sku===e.Sku).pop())}),window.localStorage.setItem("product-favorites",JSON.stringify(e)),e};var c=!0;function u(e){let{market:t,globalData:s}=e;(0,o.Z)(s,t);let[c,u]=(0,r.useState)([]),[d,f]=(0,r.useState)([]);return(0,r.useEffect)(()=>{let e=async()=>{let e=await l();if(!e)return;f({name:"My Favorites",id:"all",userId:"guest"});let t=function(e){let t=e.map(e=>e.product).filter(e=>e);return t}(e);u(t)};e()},[]),(0,a.jsx)(i.Z,{market:t,children:(0,a.jsx)("section",{className:"content-top",children:(0,a.jsx)("section",{className:"main-content-grid",children:(0,a.jsx)("div",{children:(0,a.jsx)("section",{children:(0,a.jsx)(n.Z,{list:d,products:c})})})})})})}}},function(e){e.O(0,[9831,3888,2668,5631,9774,2888,179],function(){return e(e.s=66976)}),_N_E=e.O()}]);