"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import Link from "next/link"; import { listDataRegional } from "@/service/landing/landing"; import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, } from "@/components/ui/carousel"; interface ContentItem { id: number; slug: string; title: string; thumbnailLink?: string; categoryName?: string; } interface RegionOrSatker { name: string; slug: string; logo: string; } interface AllContentPageProps { typeId: string; // 1 = image, 2 = video, 3 = text, 4 = audio title: string; basePath: "image" | "video" | "document" | "audio"; mode: "polda" | "satker"; dataList: RegionOrSatker[]; } export default function AllContentPage({ typeId, title, basePath, mode, dataList, }: AllContentPageProps) { const [contents, setContents] = useState>({}); useEffect(() => { async function fetchData() { const promises = dataList.map(async (region) => { try { const res = await listDataRegional( typeId, "", "", "", "", "", "", "", "", 10, 0, "createdAt" ); return { slug: region.slug, data: res?.data?.data?.content || [] }; } catch { return { slug: region.slug, data: [] }; } }); const resultsArray = await Promise.all(promises); const results: Record = {}; resultsArray.forEach((r) => { results[r.slug] = r.data; }); setContents(results); } fetchData(); }, [typeId, dataList]); function renderCard(item: ContentItem, regionSlug: string) { const href = `/${mode}/${regionSlug}/${basePath}/detail/${item.slug}`; if (basePath === "image" || basePath === "video") { return ( {item.thumbnailLink && ( {item.title} )}
{item.title}
); } if (basePath === "document") { return (
{item.categoryName?.toUpperCase() ?? "Document"}
{item.title}
); } if (basePath === "audio") { return (

{item.categoryName?.toUpperCase() ?? "Audio"}

{item.title}

); } } return (

{title}

{dataList.map((region) => (
{/* Header */}
{region.name}

{region.name}

{/* Carousel Konten */} {contents[region.slug]?.length > 0 ? ( {contents[region.slug].map((item) => ( {renderCard(item, region.slug)} ))} ) : (

Tidak ada konten di {region.name}

)}
))}
); }