"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, Trash2, Box, Undo2, HeartOff } 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 WIB 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" ); } // 🔹 Link detail konten 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 [contentType, setContentType] = useState< "image" | "video" | "text" | "audio" >("image"); 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); } }; // 🔹 Filter konten berdasarkan tab aktif const filtered = bookmarks.filter((b) => { const t = b.article?.typeId; switch (contentType) { case "image": return t === 1; case "video": return t === 2; case "text": return t === 3; case "audio": return t === 4; default: return true; } }); // 🔹 Aksi tombol (dummy sementara) const handleAction = (action: string, title: string) => { MySwal.fire({ icon: "info", title: action, text: `${title} berhasil di${action.toLowerCase()}.`, timer: 1200, showConfirmButton: false, }); }; const renderButtons = (bookmark: BookmarkItem) => { const title = bookmark.article?.title || "Konten"; if (filterType === "Archives") { // 🗃️ Unarchive + Delete return (
); } if (filterType === "Favorites") { // 📦 Archive + 💔 Unfavorite return (
); } // Default: My Collections → Archive + Favorite return (
); }; const renderCard = (bookmark: BookmarkItem) => (
{/* Gambar / ikon */} {bookmark.article?.typeId === 3 ? ( // 📝 TEXT
) : bookmark.article?.typeId === 4 ? ( // 🎵 AUDIO
) : ( // 📸 / 🎬
{bookmark.article?.title
)} {/* Caption */}

Disimpan: {formatTanggal(bookmark.createdAt)}

{bookmark.article?.title}

{renderButtons(bookmark)}
); if (loading) return (
Memuat konten...
); if (filtered.length === 0) return (
📂

Tidak Ada Konten di {filterType}

); return (
{/* Tab Filter Konten */}
{["image", "video", "audio", "text"].map((type) => ( ))}
{/* Slider Konten */} {filtered.map((bookmark) => ( {renderCard(bookmark)} ))}
); } // "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) => ( // // ))} //
//
// ); // }