"use client"; import React, { useEffect, useState } from "react"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Carousel, CarouselApi, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, } from "@/components/ui/carousel"; import { useParams, usePathname } from "next/navigation"; import { getListContent } from "@/service/landing/landing"; import { Link, useRouter } from "@/i18n/routing"; import { Reveal } from "./Reveal"; import { useTranslations } from "next-intl"; import { Skeleton } from "../ui/skeleton"; import Image from "next/image"; import { motion } from "framer-motion"; const NewContent = (props: { group: string; type: string }) => { const [newContent, setNewContent] = useState(); const [selectedTab, setSelectedTab] = useState("image"); const [isLoading, setIsLoading] = useState(true); const router = useRouter(); const pathname = usePathname(); const params = useParams(); const locale = params?.locale; const poldaName = params?.polda_name; const satkerName = params?.satker_name; const t = useTranslations("LandingPage"); const [api, setApi] = React.useState(null); const [current, setCurrent] = React.useState(0); const [count, setCount] = React.useState(0); React.useEffect(() => { if (!api) return; setCount(api.scrollSnapList().length); setCurrent(api.selectedScrollSnap()); const onSelect = () => { setCurrent(api.selectedScrollSnap()); }; api.on("select", onSelect); return () => { api.off("select", onSelect); }; }, [api]); let prefixPath = poldaName ? `/polda/${poldaName}` : satkerName ? `/satker/${satkerName}` : "/"; useEffect(() => { const timer = setTimeout(() => { setIsLoading(false); }, 3000); return () => clearTimeout(timer); }, []); useEffect(() => { initFetch(); }, [selectedTab]); const initFetch = async () => { console.log("Satker Name : ", satkerName); const request = { title: "", page: 0, size: 5, sortBy: props.type == "popular" ? "clickCount" : "createdAt", contentTypeId: selectedTab == "image" ? "1" : selectedTab == "video" ? "2" : selectedTab == "text" ? "3" : selectedTab == "audio" ? "4" : "", group: props.group == "mabes" ? "" : props.group == "polda" && poldaName && String(poldaName)?.length > 1 ? poldaName : props.group == "satker" && satkerName && String(satkerName)?.length > 1 ? "satker-" + satkerName : "", isInt: locale == "en" ? true : false, }; const response = await getListContent(request); console.log("category", response); setNewContent(response?.data?.data?.content); }; const shimmer = (w: number, h: number) => ` `; const toBase64 = (str: string) => typeof window === "undefined" ? Buffer.from(str).toString("base64") : window.btoa(str); return (

{pathname?.split("/")[1] == "in" ? ( <> {t("content", { defaultValue: "Content" })}  {props.type == "popular" ? "Terpopuler" : props.type == "latest" ? t("new", { defaultValue: "New" }) : "Serupa"} ) : ( <> {props.type == "popular" ? "Popular" : props.type == "latest" ? t("new", { defaultValue: "New" }) : "Serupa"}   {t("content", { defaultValue: "Content" })} )}

{[ { label: t("image", { defaultValue: "Image" }), value: "image" }, { label: t("video", { defaultValue: "Video" }), value: "video" }, { label: t("text", { defaultValue: "Text" }), value: "text" }, { label: t("audio", { defaultValue: "Audio" }), value: "audio" }, ].map((tab) => ( {tab.label} ))}
{isLoading ? (
) : (
{selectedTab == "image" ? ( newContent?.length > 0 ? ( {newContent?.map((image: any) => (
router.push( prefixPath + `/image/detail/${image?.slug}` ) } className="cursor-pointer relative group overflow-hidden bg-white dark:bg-black dark:border dark:border-gray-500 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-300" > {/* Image with motion effect */} image {/* Badge category */} {/*
{image?.category?.toUpperCase() ?? "GIAT PIMPINAN"}
*/} {/* Red icon overlay */}
{" "}
{/* Caption section */}

{image?.categoryName?.toUpperCase() ?? "Giat Pimpinan"}

{image?.title}

{/* Optional metadata area (uncomment if needed) */} {/*

{formatDateToIndonesian(new Date(image?.createdAt))} {image?.timezone ?? "WIB"} | {image.clickCount}

*/}
))}
{Array.from({ length: count }).map((_, index) => (
) : (

empty

) ) : selectedTab == "audio" ? ( newContent?.length > 0 ? ( {newContent?.map((audio: any) => (
router.push( prefixPath + `/audio/detail/${audio?.slug}` ) } className="cursor-pointer bg-white dark:bg-black dark:border dark:border-gray-500 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-300 overflow-hidden" > {/* Icon Background */}
{" "}
{/* Caption */}

{audio?.categoryName?.toUpperCase() ?? "GIAT PIMPINAN"}

{audio?.title}

{/*

{formatDateToIndonesian(new Date(audio?.createdAt))} {audio?.timezone ?? "WIB"} | {audio?.clickCount}

*/}
))}
{Array.from({ length: count }).map((_, index) => (
) : (

empty

) ) : selectedTab == "video" ? ( newContent?.length > 0 ? ( {newContent?.map((video: any) => (
router.push( prefixPath + `/video/detail/${video?.slug}` ) } className="cursor-pointer relative group overflow-hidden bg-white dark:bg-black dark:border dark:border-gray-500 rounded-xl shadow-md hover:shadow-lg transition-shadow duration-300" > {/* Image with motion effect */} video {/* Badge category */} {/*
{video?.category?.toUpperCase() ?? "VIDEO"}
*/} {/* Red icon overlay */}
{" "}
{/* Caption section */}

{video?.categoryName?.toUpperCase() ?? "Giat Pimpinan"}

{video?.title}

{/* Optional metadata area (uncomment if needed) */} {/*

{formatDateToIndonesian(new Date(image?.createdAt))} {image?.timezone ?? "WIB"} | {image.clickCount}

*/}
))}
{/* Pagination Dots */}
{Array.from({ length: count }).map((_, index) => (
) : (

empty

) ) : newContent.length > 0 ? ( {newContent?.map((text: any) => (
router.push( prefixPath + `/document/detail/${text?.slug}` ) } className="cursor-pointer rounded-lg shadow-md overflow-hidden bg-white dark:bg-black dark:border dark:border-gray-500" > {/* Ikon di tengah dengan latar kuning */}
{/* Konten bawah */}
{/* Kategori merah */}
{text?.categoryName?.toUpperCase() ?? "Text"}
{/* Judul */}
{text?.title}
{/* Meta info */} {/*
{formatDateToIndonesian(new Date(text?.createdAt))} {text?.timezone ? text?.timezone : "WIB"} {text?.clickCount}
*/} {/* Download */} {/*
Download {t("document", { defaultValue: "Document" })}
*/}
))}
{/* Pagination Dots */}
{Array.from({ length: count }).map((_, index) => (
) : (

empty

)}
)}
{/*
router.push(prefixPath + `/${selectedTab}/filter?sortBy=${props.type}`)} className="cursor-pointer border text-[#bb3523] rounded-lg text-sm lg:text-md px-4 py-1 border-[#bb3523]"> {t("seeAll", { defaultValue: "See All" })}
*/}
); }; export default NewContent;