import React, { useEffect, useMemo, useState } from "react"; import { getPriceString, isValidSpecValue } from "../../utils/functions"; import ColorChips from "../ColorChips"; import PickLabel from "../PickLabel"; import Score from "../Score"; import StarRating from "../StarRating"; import Button from "../UI/Button"; import Heading from "../UI/Heading"; import { BookmarkDefault, BookmarkPressed, ComparisonDefault, ComparisonPressed, } from "../UI/Icon"; import Text from "../UI/Text"; import { NosearchPickProps } from "./NosearchPick.types"; import NosearchPickReview from "./NosearchPickReview"; import NosearchPickReviewSlider from "./NosearchPickReviewSlider"; const NosearchPick = ({ data: { goodsName, modelName, brandName, productCategoryName, price, imageUrl, pickType, scrapStatus, compareStatus, reviewAvg, reviewCnt, reviews, colors, scoreMetaMap, onClickScrapButton, onClickCompareButton, onClickAllReviewsButton, }, index, vertical = true, imageSize, outlined = true, showIndex = false, showScore = false, showReview = true, hideColors = false, showOnlyNosearchTwoLines = false, useBackgroundColorOnInformation = false, showActionButtonsOnInformation = true, useCategoryNameOnPickLabel = false, showPickLabelOnImage = false, brandNameClassName = "text-body-5 font-bold", goodsNameClassName = "text-body-5 font-bold", modelNameClassName = "text-body-5 font-bold", priceClassName = "text-body-10", Image, isMobile = true, }: NosearchPickProps) => { const imageSizeMap = { s: "w-[12rem] h-[12rem]", l: "w-[12rem] h-[12rem] pc:w-[18rem] pc:h-[18rem]", // pick }; const IMAGE_SIZE = imageSizeMap[imageSize]; const [isLiked, setIsLiked] = useState(scrapStatus); const [isCompared, setIsCompared] = useState(compareStatus); const firstReview = useMemo(() => { return reviews === undefined || reviews.length === 0 ? "" : reviews.filter((review) => review.type === "nosearch")[0]?.content ?? ""; }, [reviews]); useEffect(() => { setIsLiked(scrapStatus); setIsCompared(compareStatus); }, [scrapStatus, compareStatus]); return (
{/* image */}
{Image ? ( {`nosearchPick_${brandName}_${modelName}_${goodsName}`} ) : ( {`nosearchPick_${brandName}_${modelName}_${goodsName}`} )} {showPickLabelOnImage && (
)} {showIndex && index && (
{index}
)}
{!hideColors && colors && ( )}
{/* information */}
{!showPickLabelOnImage && (
)} {isValidSpecValue(brandName) && (

{brandName}

)} {isValidSpecValue(goodsName) && (

{goodsName}

)} {isValidSpecValue(modelName) && (

{modelName}

)}

{getPriceString(price)}

{reviewAvg && reviewCnt ? (
({reviewCnt}) } />
) : ( "" )}
{/* score - non vertical UI */} {!vertical && showScore && scoreMetaMap && (

)}
{/* Buttons */} {showActionButtonsOnInformation && (
{onClickScrapButton && ( )}
)}
{vertical && !showScore && showReview &&
} {/* score - vertical UI */} {vertical && showScore && scoreMetaMap && (
)} {/* product reviews */} {showReview && reviews && reviews.length !== 0 && ( <> {vertical ? (
{showOnlyNosearchTwoLines ? ( review.type === "nosearch")[0] } reviewCnt={1} /> ) : ( reviews.map((review, reviewIndex) => { return ( ); }) )} {/* TODO: 전체보기 페이지 개발 전까지 주석 처리 */} {/* 홈 페이지에서 Mobile버전일 경우 */} {/* {reviews.length > 3 && (
{ e.preventDefault(); onClickAllReviewsButton && onClickAllReviewsButton(); }} > 구매후기
전체보기
)} */}
) : ( )} )}
); }; export default NosearchPick;