"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, useRouter } 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 } 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"); 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); }; 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")} )}

{t("image")}
|
{t("video")}
|
{t("text")}
|
{t("audio")}
{isLoading ? (
) : (
{selectedTab == "image" ? ( newContent?.length > 0 ? ( {newContent?.map((image: any) => ( 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) => (
{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) => ( video

{video?.title}

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

))}
) : (

empty

) ) : newContent.length > 0 ? ( {newContent?.map((text: any) => (
{formatDateToIndonesian(new Date(text?.createdAt))} {text?.timezone ? text?.timezone : "WIB"}| {text?.clickCount}
{text?.title}
Download {t("document")}
))}
) : (

empty

)}
)}
{t("seeAll")}
); }; export default NewContent;