"use client"; import Footer from "@comp/Footer/page"; import Navbar from "@comp/Navbar/page"; import GalleryBox from "plugins/Gallery/page"; import { useEffect, useState } from "react"; import AddToCart from "@comp/Cards/Components/AddToCart/page"; import Image from "next/image"; import PersianNumber from "plugins/PersianNumber"; import logo from "../../../public/images/logo.png"; const ProductData = ({ params, data }) => { console.log("data", data); const [product, setProduct] = useState([]); const [specificationsHeader, setSpecificationsHeader] = useState([]); const [productBarDetail, setProductBarDetail] = useState(0); const fetchPost = async (id) => { const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/product/${id}`); const post = await res.json(); setProduct(post.product); }; const displaySpecifications = (specs) => { let data = []; if (specs?.length > 3) { specs?.slice(0, 3).forEach((spec) => { const { title, value } = spec; data.push(`${title}: ${value}`); }); } else { specs?.forEach((spec) => { const { title, value } = spec; data.push(`${title}: ${value}`); }); } setSpecificationsHeader(data); // You can replace }; const scrollToSection = (id) => { const element = document.getElementById(id); if (element) { const offset = -80; // Adjust this value as needed window.scrollTo({ top: element.offsetTop + offset, behavior: "smooth", }); } }; useEffect(() => { fetchPost(params.id[0]); }, []); useEffect(() => { displaySpecifications(product?.specifications); }, [product]); return ( <>

{data.product?.persianName}{" "}

{data?.product?.englishName}{" "}

اصالت کالای

{data?.product?.hasDiscount && (

بمب امروز

)} {!data?.product?.warranty == "" && (

{product?.warranty}

)}
{/*
*/}

{data?.product?.summery}

    {specificationsHeader.map((e, index) => (
  • {e}

  • ))}
{/* xs:sticky lg:relative xs:top-[60px] lg:top-0 ==> sticky for price=================== */}
{data?.product?.files?.length > 0 ? ( CTX.setIsOpenLightBox(true)} alt={`${product.persianName} - ${product.englishName}`} property loading="eager" /> ) : (
وسمه
)}

{data?.product?.persianName}{" "}

گارانتی{" "} اصالت{" "} و{" "} سلامت فیزیکی کالا

{true ? (
{" "}

تومان
) : (
{" "}

تومان
)}
{ setProductBarDetail(0); scrollToSection("section0"); }} >

مشخصات محصول

مشخصات

{ setProductBarDetail(2); scrollToSection("section2"); }} >

نقد و بررسی

{ setProductBarDetail(3); scrollToSection("section3"); }} >

دیدگاه مخاطبان

مخاطبان

مشخصات محصول

{product?.specifications?.map((e, index) => (

{e.title}: {" "} {e.value}{" "}

))}

نقد و برسی{" "}

{!!data?.product?.expertCheck ? (
) : (
چیزی یافت نشد
)}

دیدگاه مخاطبان{" "}

چیزی یافت نشد
{" "}
{product?.hasDiscount ? ( <>

{" "}

تومان
) : (
{" "}

تومان
)}