const filterData={retail_price:{lowest:{min:0,max:2999},low:{min:3e3,max:4999},middle:{min:5e3,max:6999},high:{min:7e3,max:11999},highest:{min:12e3,max:Number.MAX_SAFE_INTEGER}}},similarTasteClassGroup={R1:["R01","R02"],R2:["R03","R04","R07"],R3:["R08","R09"],R4:["R06","R13"],R5:["R05","R10"],R6:["R11","R12"],RO1:["RO01","RO02"],RO2:["RO03","RO04"],W1:["W01","W04"],W2:["W02","W03"],W3:["W05","W06","W09"],W4:["W07","W08","W10"],SW1:["SW01","SW02","SW03"],S1:["S01","S04","S08"],S2:["S02","S06"],S3:["S03","S05","S07"]},titleMap={"lower-price":"\u540C\u30BF\u30A4\u30D7\u306E\u304A\u624B\u9803\u30EF\u30A4\u30F3","higher-price":"\u540C\u30BF\u30A4\u30D7\u306E\u30CF\u30A4\u30AF\u30E9\u30B9\u30EF\u30A4\u30F3","similar-type":"\u985E\u4F3C\u30BF\u30A4\u30D7\u306E\u540C\u4FA1\u683C\u5E2F\u30EF\u30A4\u30F3"},recommendSection=document.getElementById("ec-recommend"),priceRangeList=Object.keys(filterData.retail_price),currentIndexOfPriceRangeList=priceRangeList.indexOf(classifyByPriceRange(Number(recommendSection.dataset.retailPrice)));executeProductRecommendationFlow();async function executeProductRecommendationFlow(){try{const searchParams=createSearchParams(),userId=await getUserId(),[responseUserWineRatesApi,responseWineSearchApi]=await Promise.all([callUserWineRatesApi(userId),callWineSearchApi(searchParams)]);createLowerPriceRecommendationBlock(responseWineSearchApi.item_list,responseUserWineRatesApi.item_list),createHigherPriceRecommendationBlock(responseWineSearchApi.item_list,responseUserWineRatesApi.item_list),createSimilarTypeRecommendationBlock(responseWineSearchApi.item_list,responseUserWineRatesApi.item_list),initializeSwiper(".ec-recommend-item-container")}catch(e){console.error("\u30EC\u30B3\u30E1\u30F3\u30C9\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002"),console.error(e),recommendSection.style.display="none"}}function classifyByPriceRange(retailPrice){for(const[rangeName,range]of Object.entries(filterData.retail_price))if(retailPrice<=range.max)return rangeName}function getSimilarTasteClassGroupKey(){const tasteClassCd=recommendSection.dataset.tasteClassCd;for(const[groupKey,group]of Object.entries(similarTasteClassGroup))if(group.includes(tasteClassCd))return groupKey}function createSearchParams(){const key=getSimilarTasteClassGroupKey(),searchParamsTasteClasses=similarTasteClassGroup[key].map(e=>["taste_class_cd",e]);return new URLSearchParams([...searchParamsTasteClasses,["warehouse_cd","0080"],["should_exclude_stockout",!0],["can_ec_handle",!0],["can_shop_handle",!0],["page_size",5e3]]).toString()}async function callWineSearchApi(searchParams){try{const response=await fetch(`https://ynrg86u82c.execute-api.ap-northeast-1.amazonaws.com/prod/wine?${searchParams}`);if(!response.ok){const data2=await response.json();throw console.error(data2),new Error(`API\u30A8\u30E9\u30FC\u3002\u30B9\u30C6\u30FC\u30BF\u30B9\u30B3\u30FC\u30C9: ${response.status}`)}return await response.json()}catch(error){throw console.error("\u30EF\u30A4\u30F3\u691C\u7D22API\u306E\u901A\u4FE1\u306B\u5931\u6557\u3057\u307E\u3057\u305F\u3002"),error}}function createLowerPriceRecommendationBlock(wineList,itemListToExclude){const tasteClassCd=recommendSection.dataset.tasteClassCd;if(currentIndexOfPriceRangeList-1<0)return;const lowerPriceWineList=filterRecommendWine(wineList,{retail_price:[priceRangeList[currentIndexOfPriceRangeList-1]]});if(lowerPriceWineList.length===0)return;const lowerPriceSameTasteWineList=lowerPriceWineList.filter(e=>e.taste_class_cd==tasteClassCd);if(lowerPriceSameTasteWineList.length===0)return;const excludedWineList=excludeWinesBasedOnItemCd(lowerPriceSameTasteWineList,itemListToExclude);excludedWineList.length!==0&&createRecommendationBlock(randomizeWine(excludedWineList),"lower-price")}function createHigherPriceRecommendationBlock(wineList,itemListToExclude){const tasteClassCd=recommendSection.dataset.tasteClassCd;if(priceRangeList.length-1e.taste_class_cd==tasteClassCd);if(higherPriceSameTasteWineList.length===0)return;const excludedWineList=excludeWinesBasedOnItemCd(higherPriceSameTasteWineList,itemListToExclude);excludedWineList.length!==0&&createRecommendationBlock(randomizeWine(excludedWineList),"higher-price")}function createSimilarTypeRecommendationBlock(wineList,itemListToExclude){const itemCd=recommendSection.dataset.itemCd,similarTypeWineList=filterRecommendWine(wineList,{retail_price:[priceRangeList[currentIndexOfPriceRangeList]]});if(similarTypeWineList.length===0)return;const sameWineIndex=similarTypeWineList.findIndex(wine=>wine.item_cd===itemCd);if(similarTypeWineList.splice(sameWineIndex,1),similarTypeWineList.length===0)return;const excludedWineList=excludeWinesBasedOnItemCd(similarTypeWineList,itemListToExclude);excludedWineList.length!==0&&createRecommendationBlock(randomizeWine(excludedWineList),"similar-type")}function createRecommendationBlock(wineList,id){document.getElementById("ec-recommend").insertAdjacentHTML("beforeend",`
${titleMap[id]}
`),createContainer(wineList,id)}function createContainer(wineList,id){document.getElementById("ec-recommend").insertAdjacentHTML("beforeend",`
`);const fragment=document.createDocumentFragment();for(const wine of wineList)fragment.appendChild(createRecommendedWineCard(wine));document.getElementById(`${id}`).appendChild(fragment),wineList.length<=3&&document.querySelectorAll(`#${id} ~ div`).forEach(e=>{e.style.display="none"})}function createRecommendedWineCard(wine){const splittedTasteClassCd=splitTasteClassCd(wine.taste_class_cd),flagImageUrl=getNationalFlagImage(wine.origin_country_name),discountPrice=wine.special_retail_price!==null?`${wine.special_retail_price.toLocaleString()}\u5186(\u7A0E\u8FBC)`:"",wineCard=document.createElement("a");return wineCard.className="ec-recommend-item swiper-slide",wineCard.setAttribute("href",`/products/${wine.item_cd}`),wineCard.insertAdjacentHTML("afterbegin",`
${wine.taste_class_name}
${wine.item_class_name}
${splittedTasteClassCd[1]}${splittedTasteClassCd[2]}
${wine.display_name} ${wine.vintage??""}
${discountPrice} ${wine.origin_country_name} ${wine?.origin_area_list[0]?.origin_area_name??""} ${wine?.origin_area_list[1]?.origin_area_name??""} ${wine?.origin_area_list[2]?.origin_area_name??""}
${wine.retail_price.toLocaleString()}\u5186(\u7A0E\u8FBC)
`),wineCard}function randomizeWine(wineList){if(wineList.length<=6)return wineList;const randomizedWineList=[];for(;randomizedWineList.length<6;){const randomIndexNumber=Math.floor(Math.random()*wineList.length);randomizedWineList.push(wineList[randomIndexNumber]),wineList.splice(randomIndexNumber,1)}return randomizedWineList}function initializeSwiper(identifier){const mySwiper=new Swiper(identifier,{slidesPerView:"auto",spaceBetween:20,cssMode:!0,centeredSlides:!0,centeredSlidesBounds:!0,navigation:{nextEl:".swiper-button-next",prevEl:".swiper-button-prev",enabled:!1},breakpoints:{800:{navigation:{nextEl:".swiper-button-next",prevEl:".swiper-button-prev",enabled:!0}}}})} //# sourceMappingURL=/cdn/shop/t/49/assets/product_bew_recommendations_block.js.map