"use client"; import { useState, useEffect } from "react"; import Image from "next/image"; import Link from "next/link"; import { Button } from "@/components/ui/button"; import { Archive, Star } from "lucide-react"; import Swal from "sweetalert2"; import withReactContent from "sweetalert2-react-content"; import { getBookmarks } from "@/service/content"; import { BookmarkItem } from "@/service/content"; import { Swiper, SwiperSlide } from "swiper/react"; import "swiper/css"; import "swiper/css/navigation"; import { Navigation } from "swiper/modules"; // Format tanggal function formatTanggal(dateString: string) { if (!dateString) return ""; return ( new Date(dateString) .toLocaleString("id-ID", { day: "2-digit", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false, timeZone: "Asia/Jakarta", }) .replace(/\./g, ":") + " WIB" ); } function getLink(item: BookmarkItem) { switch (item.article?.typeId) { case 1: return `/content/image/detail/${item.article?.id}`; case 2: return `/content/video/detail/${item.article?.id}`; case 3: return `/content/text/detail/${item.article?.id}`; case 4: return `/content/audio/detail/${item.article?.id}`; default: return "#"; } } type ForYouCardGridProps = { filterType: "My Collections" | "Archives" | "Favorites"; selectedCategory?: string; }; export default function ForYouCardGrid({ filterType }: ForYouCardGridProps) { const [bookmarks, setBookmarks] = useState([]); const [loading, setLoading] = useState(true); const MySwal = withReactContent(Swal); useEffect(() => { fetchBookmarks(); }, [filterType]); const fetchBookmarks = async () => { try { setLoading(true); const response = await getBookmarks(1, 50, filterType); if (!response?.error) { setBookmarks(response.data?.data || []); } else { MySwal.fire("Error", "Gagal memuat bookmark.", "error"); } } catch (err) { console.error(err); MySwal.fire("Error", "Terjadi kesalahan saat memuat bookmark.", "error"); } finally { setLoading(false); } }; const grouped = { image: bookmarks.filter((b) => b.article?.typeId === 1).slice(0, ), video: bookmarks.filter((b) => b.article?.typeId === 2).slice(0, 5), text: bookmarks.filter((b) => b.article?.typeId === 3).slice(0, 5), audio: bookmarks.filter((b) => b.article?.typeId === 4).slice(0, 5), }; const renderImageVideoCard = (bookmark: BookmarkItem) => (
{bookmark.article?.title

Disimpan: {formatTanggal(bookmark.createdAt)}

{bookmark.article?.title}

); const renderTextCard = (bookmark: BookmarkItem) => (
{/* Background kuning & ikon dokumen */}
{/* Konten bawah */}

Disimpan: {formatTanggal(bookmark.createdAt)}

{bookmark.article?.title}
); const renderAudioCard = (bookmark: BookmarkItem) => (
{/* Background merah & ikon audio */}
{/* Caption */}

Disimpan: {formatTanggal(bookmark.createdAt)}

{bookmark.article?.title}

); const renderSection = ( title: string, items: BookmarkItem[], type: "imagevideo" | "text" | "audio" ) => { if (!items.length) return null; return (

{title}

{items.map((bookmark) => ( {type === "imagevideo" ? renderImageVideoCard(bookmark) : type === "text" ? renderTextCard(bookmark) : renderAudioCard(bookmark)} ))}
); }; if (loading) return (
Memuat konten...
); if (bookmarks.length === 0) return (
📂

Tidak Ada Konten di {filterType}

); return (
{renderSection("📸 Image", grouped.image, "imagevideo")} {renderSection("🎬 Video", grouped.video, "imagevideo")} {renderSection("📝 Text", grouped.text, "text")} {renderSection("🎵 Audio", grouped.audio, "audio")}
); } // "use client"; // import { useEffect, useState } from "react"; // import PublicationKlFilter from "./publication-filter"; // import { Button } from "@/components/ui/button"; // import { mediaWishlist } from "@/service/landing/landing"; // const itemsPerPage = 9; // type PublicationCardGridProps = { // selectedCategory: string; // title?: string; // refresh?: boolean; // categoryFilter?: string[]; // formatFilter?: string[]; // isInstitute?: boolean; // instituteId?: string; // sortBy?: string; // }; // export default function ForYouCardGrid({ // selectedCategory, // title, // refresh, // isInstitute = false, // instituteId = "", // }: PublicationCardGridProps) { // const [currentPage, setCurrentPage] = useState(0); // const [contentImage, setContentImage] = useState([]); // const [totalPages, setTotalPages] = useState(1); // const [categoryFilter] = useState([]); // const [formatFilter] = useState([]); // const [sortBy] = useState(); // useEffect(() => { // getDataImage(); // }, [currentPage, selectedCategory, title, refresh]); // async function getDataImage() { // const filter = // categoryFilter?.length > 0 // ? categoryFilter?.sort().join(",") // : selectedCategory || ""; // const name = title ?? ""; // const format = formatFilter?.join(",") ?? ""; // const response = await mediaWishlist( // "1", // isInstitute ? instituteId : "", // name, // filter, // "12", // currentPage, // sortBy, // format // ); // setTotalPages(response?.data?.data?.totalPages || 1); // setContentImage(response?.data?.data?.content || []); // } // const goToPage = (page: number) => { // setCurrentPage(page); // }; // return ( //
// {/* Grid Card */} //
// {contentImage.length === 0 ? ( //
// Tidak ada konten ditemukan. //
// ) : ( // contentImage.map((item: any, idx: number) => ( // // )) // )} //
// {/* Pagination */} //
// {Array.from({ length: totalPages }, (_, i) => ( // // ))} //
//
// ); // }