"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 } from "@/utils/globals"; import { getListContent } from "@/service/landing/landing"; import { Link } from "@/i18n/routing"; import { Reveal } from "./Reveal"; import { useTranslations } from "next-intl"; const NewContent = (props: { group: string, type: string }) => { const [newContent, setNewContent] = useState(); const [selectedTab, setSelectedTab] = useState("image"); 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(() => { 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 : "", }; 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")}
{selectedTab == "video" ? ( newContent?.length > 0 ? ( {newContent?.map((video: any) => (

{video?.title}

{formatDateToIndonesian(new Date(video?.createdAt))} {video?.timezone ? video?.timezone : "WIB"} | {video.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}
))}
) : (

empty

) ) : selectedTab == "image" ? ( newContent?.length > 0 ? ( {newContent?.map((image: any) => (

{image?.title}

{formatDateToIndonesian(new Date(image?.createdAt))} {image?.timezone ? image?.timezone : "WIB"}| {image?.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;