import { MetaFunction } from "@remix-run/node";
import { useParams, useNavigate } from "@remix-run/react";
import { safeGoBack } from "~/utils/helpers";
import {
useCollectionDetail,
useSimilarCollections,
} from "~/requestHandler/use-collection-hooks";
import { Skeleton } from "~/components/ui/skeleton";
import {
Package,
RefreshCw,
ArrowRight,
ShoppingBag,
Calendar,
Sparkles,
} from "lucide-react";
import MondrianProductList from "~/components/MondrianProductList";
import HorizontalCollectionsList from "~/components/HorizontalCollectionsList";
import AIPromoteModal from "~/components/AIPromoteModal";
import { useState } from "react";
export default function CollectionDetail() {
const params = useParams();
const navigate = useNavigate();
const collectionId = params.id || "";
// AI Promote Modal State
const [isPromoteModalOpen, setIsPromoteModalOpen] = useState(false);
const {
data: collection,
isLoading,
isError,
refetch,
} = useCollectionDetail(collectionId);
const {
data: similarCollectionsData,
isLoading: isSimilarLoading,
isError: isSimilarError,
refetch: refetchSimilar,
} = useSimilarCollections(collectionId);
// Format date helper
const formatDate = (dateString?: string) => {
if (!dateString) return "";
const date = new Date(dateString);
return new Intl.DateTimeFormat("fa-IR", {
year: "numeric",
month: "long",
day: "numeric",
}).format(date);
};
const handleBack = () => {
safeGoBack(navigate);
};
// Loading state
if (isLoading) {
return (
{/* Header */}
{/* Loading Skeleton */}
{Array.from({ length: 6 }).map((_, i) => (
))}
);
}
// Error state
if (isError || !collection) {
return (
{/* Header */}
{/* Error State */}
خطا در بارگذاری کالکشن
متاسفانه در بارگذاری اطلاعات کالکشن مشکلی پیش آمد.
);
}
const products = collection.products?.results || [];
return (
{/* Header */}
{/* Content */}
{/* Collection Header */}
{/* Cover Image */}
{collection.coverImageUrl ? (

) : (
)}
{/* Collection Info */}
{collection.title || "بدون عنوان"}
{collection.description && (
{collection.description}
)}
{/* Stats Row */}
{/* Product Count */}
{collection.productCount !== undefined && (
{collection.productCount} محصول
)}
{/* Created Date */}
{collection.createdAt && (
{formatDate(collection.createdAt)}
)}
{/* Products Section */}
محصولات کالکشن
{products.length === 0 ? (
محصولی در این کالکشن وجود ندارد
هنوز محصولی به این کالکشن اضافه نشده است.
) : (
({
id: product.id || "",
title: product.title,
images: product.imageUrls || [],
basePrice: product.basePrice
? parseInt(product.basePrice)
: undefined,
}))}
fetchNextPage={() => {}}
hasNextPage={false}
isFetchingNextPage={false}
isLoading={false}
isError={false}
refetch={refetch}
emptyState={{
image: ,
title: "محصولی وجود ندارد",
description: "هنوز محصولی به این کالکشن اضافه نشده است.",
}}
/>
)}
{/* Similar Collections Section */}
{similarCollectionsData &&
similarCollectionsData?.results &&
similarCollectionsData?.results.length > 0 && (
)}
{/* AI Promote Floating Button - با انیمیشن ورود از پایین */}
{/* AI Promote Modal */}
setIsPromoteModalOpen(false)}
collectionId={collectionId}
/>
{/* Keyframe Animation for Floating Button */}
);
}
export const meta: MetaFunction = () => {
return [
{ title: "جزئیات کالکشن - ویترون" },
{
name: "description",
content: "مشاهده جزئیات کالکشن و محصولات موجود در آن.",
},
{
name: "keywords",
content: "کالکشن، محصولات، ویترون، خرید آنلاین",
},
{ name: "robots", content: "index, follow" },
{ property: "og:type", content: "website" },
{ property: "og:title", content: "جزئیات کالکشن - ویترون" },
{
property: "og:description",
content: "مشاهده جزئیات کالکشن و محصولات موجود در آن.",
},
{ property: "og:site_name", content: "ویترون" },
{ property: "og:locale", content: "fa_IR" },
{ name: "twitter:card", content: "summary_large_image" },
{ name: "twitter:title", content: "جزئیات کالکشن - ویترون" },
{
name: "twitter:description",
content: "مشاهده جزئیات کالکشن و محصولات موجود در آن.",
},
];
};