import { createClient } from "@/lib/supabase-server" import { getSiteContents } from "@/lib/data" import { notFound } from "next/navigation" import Image from "next/image" import Link from "next/link" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Phone } from "lucide-react" import { ProductGallery } from "@/components/product/product-gallery" async function getProduct(id: string) { const supabase = createClient() // Fetch product const { data: product, error } = await supabase .from("products") .select("*") .eq("id", id) .eq("is_active", true) .single() if (error || !product) { return null } // Fetch images const { data: images } = await supabase .from("product_images") .select("*") .eq("product_id", id) .order("display_order", { ascending: true }) return { ...product, images: images || [] } } export default async function ProductPage({ params }: { params: { id: string } }) { const product = await getProduct(params.id) const siteSettings = await getSiteContents() const whatsappPhone = siteSettings.contact_phone ? siteSettings.contact_phone.replace(/\s+/g, '') : "905555555555" if (!product) { notFound() } // Combine main image and gallery images for a full list, filtering duplicates if necessary // Logic: If gallery images exist, use them. If not, fallback to product.image_url. // If product.image_url is in product_images, we might duplicate, but let's just use all distinct. let allImages: string[] = [] if (product.images && product.images.length > 0) { allImages = product.images.map((img: { image_url: string }) => img.image_url) } else if (product.image_url) { allImages = [product.image_url] } return (
{product.description || "Bu ürün için henüz detaylı açıklama eklenmemiştir."}
* Bu ürün hakkında detaylı bilgi ve fiyat teklifi almak için bizimle iletişime geçebilirsiniz.