"use client";
import Link from "next/link";
import Image from "next/image";
import { ChevronLeft, ImageIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import { getFeaturedImageUrl, type WpPost } from "@/lib/wp-api";
import { formatDateShamsi } from "@/lib/format-date";
import { cn } from "@/lib/utils";
function stripHtml(html: string): string {
return html.replace(/<[^>]*>/g, "").trim();
}
/** کارت با تصویر بهصورت پسزمینه و عنوان + توضیح در پایین با overlay */
function PostCard({
post,
size = "default",
}: {
post: WpPost;
size?: "large" | "default";
}) {
const excerpt =
stripHtml(post.excerpt.rendered) ||
stripHtml(post.content.rendered).slice(0, size === "large" ? 280 : 120);
const date = post.date ? formatDateShamsi(post.date) : null;
const authorName = post._embedded?.author?.[0]?.name ?? null;
const thumbnailUrl = getFeaturedImageUrl(post, size === "large" ? "medium_large" : "medium");
const href = `/blog/${encodeURIComponent(post.slug)}`;
return (
{/* پسزمینه: تصویر تمام کارت */}
{thumbnailUrl ? (
) : (
)}
{/* گرادیان شفاف و متن در پایین */}
);
}
/** کارت ردیفی: تصویر کنار عنوان، بدون توضیح */
function PostCardRow({ post }: { post: WpPost }) {
const date = post.date ? formatDateShamsi(post.date) : null;
const authorName = post._embedded?.author?.[0]?.name ?? null;
const thumbnailUrl = getFeaturedImageUrl(post, "medium");
const href = `/blog/${encodeURIComponent(post.slug)}`;
return (
{/* نیمه عنوان + نویسنده */}
);
}
const DEFAULT_TITLE = "از دانشنامه";
const DEFAULT_CAPTION =
"از داده تا بینش؛ یادداشتها و تجربههایی که مسیر شما را روشنتر میکنند.";
const DEFAULT_CTA_LABEL = "مشاهده همه مقالات";
const DEFAULT_CTA_HREF = "/blog";
interface FeaturedPostsGridProps {
posts: WpPost[];
/** عنوان بخش */
title?: string;
/** کپشن زیر عنوان */
caption?: string;
/** متن دکمه CTA */
ctaLabel?: string;
/** لینک CTA (پیشفرض: /blog) */
ctaHref?: string;
}
export function FeaturedPostsGrid({
posts,
title = DEFAULT_TITLE,
caption = DEFAULT_CAPTION,
ctaLabel = DEFAULT_CTA_LABEL,
ctaHref = DEFAULT_CTA_HREF,
}: FeaturedPostsGridProps) {
if (!posts.length) return null;
const [first, second, third, fourth] = posts;
return (
{/* کارت بزرگ: در RTL سمت چپ، در LTR سمت راست */}
{first && (
)}
{/* سه کارت کوچک: یک بالا، دو پایین */}
{second && (
)}
{third && (
)}
مطالب بیشتر در دانشنامه
);
}