"use client"; import React, { useEffect, useState } from "react"; import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Carousel, CarouselContent, CarouselItem, CarouselNext, CarouselPrevious, } from "@/components/ui/carousel"; import { useParams, usePathname } from "next/navigation"; import { Icon } from "@iconify/react/dist/iconify.js"; import { formatDateToIndonesian, secondToTimes } from "@/utils/globals"; 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"; 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"); 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")}  {props.type == "popular" ? "Terpopuler" : props.type == "latest" ? t("new") : "Serupa"} ) : ( <> {props.type == "popular" ? "Popular" : props.type == "latest" ? t("new") : "Serupa"}   {t("content")} )}

{[ { label: "video", value: "video" }, { label: "Audio", value: "audio" }, { label: "Foto", value: "image" }, { label: "Teks", value: "text" }, ].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 shadow-md hover:shadow-lg" > image

{image?.title}

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

))}
) : (

empty

) ) : selectedTab == "audio" ? ( newContent?.length > 0 ? ( {newContent?.map((audio: any) => (
router.push( prefixPath + `/audio/detail/${audio?.slug}` ) } className="cursor-pointer flex flex-row sm:flex-row items-center bg-white dark:bg-gray-800 shadow-md border rounded-lg p-4 my-3 gap-4 w-full " >
{formatDateToIndonesian( new Date(audio?.createdAt) )}{" "} {audio?.timezone ? audio?.timezone : "WIB"}{" "} | {" "}   {audio?.clickCount}{" "}
{audio?.title}

{" "} {audio?.duration ? secondToTimes(Number(audio?.duration)) : "00:00:00"}

))}
) : (

empty

) ) : selectedTab == "video" ? ( newContent?.length > 0 ? ( {newContent?.map((video: any) => (
router.push( prefixPath + `/video/detail/${video?.slug}` ) } className="cursor-pointer relative group rounded-md overflow-hidden shadow-md hover:shadow-lg" > video

{video?.title}

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

))}
) : (

empty

) ) : newContent.length > 0 ? ( {newContent?.map((text: any) => (
router.push( prefixPath + `/document/detail/${text?.slug}` ) } className="flex flex-row bg-yellow-500 sm:flex-row items-center dark:bg-gray-800 cursor-pointer shadow-md rounded-lg p-4 gap-4" >
{formatDateToIndonesian( new Date(text?.createdAt) )} {text?.timezone ? text?.timezone : "WIB"}| {text?.clickCount}
{text?.title}
Download {t("document")}
))}
) : (

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")}
); }; export default NewContent;