"use client"; import { useState, useEffect } from "react"; import { Calendar, Eye } from "lucide-react"; import { Button } from "@/components/ui/button"; import Link from "next/link"; import { FaFacebookF, FaTiktok, FaYoutube, FaWhatsapp, FaInstagram, FaTwitter, FaCheck, FaLink, FaShareAlt, } from "react-icons/fa"; import { getDetail } from "@/service/landing/landing"; import { getArticleDetail } from "@/service/content/content"; export default function AudioDetail({ id }: { id: number }) { const [data, setData] = useState(null); const [loading, setLoading] = useState(true); const [copied, setCopied] = useState(false); const [showShareMenu, setShowShareMenu] = useState(false); const [selectedAudio, setSelectedAudio] = useState(0); // Salin tautan const handleCopyLink = async () => { try { await navigator.clipboard.writeText(window.location.href); setCopied(true); setTimeout(() => setCopied(false), 2000); } catch (err) { console.error("Gagal menyalin link:", err); } }; const SocialItem = ({ icon, label, }: { icon: React.ReactNode; label: string; }) => (
{icon}
{label}
); useEffect(() => { const fetchDetail = async () => { try { setLoading(true); // 1️⃣ Coba API baru const res = await getArticleDetail(id); console.log("Audio detail API response:", res); const article = res?.data?.data; if (article) { const mappedData = { id: article.id, title: article.title, description: article.description, createdAt: article.createdAt, clickCount: article.viewCount, creatorGroupLevelName: article.createdByName || "Unknown", uploadedBy: { publisher: article.createdByName || "MABES POLRI", }, files: article.files?.map((f: any) => ({ id: f.id, fileName: f.file_name, url: f.file_url, secondaryUrl: f.file_url, fileAlt: f.file_alt, size: f.size, createdAt: f.created_at, updatedAt: f.updated_at, })) || [], }; setData(mappedData); return; } // 2️⃣ Fallback ke API lama // const fallback = await getDetail(id); // setData(fallback?.data?.data); } catch (err) { console.error("Gagal memuat audio:", err); // try { // const fallback = await getDetail(id); // setData(fallback?.data?.data); // } catch (err2) { // console.error("Fallback gagal:", err2); // } } finally { setLoading(false); } }; if (id) fetchDetail(); }, [id]); if (loading) { return (

Memuat data audio...

); } if (!data) { return (

Data tidak ditemukan

); } return (
{/* Pemutar Audio Utama */}
{/* Pilihan file audio */}
{data?.files?.map((file: any, index: number) => ( ))}
{/* Informasi artikel */}
by {data?.uploadedBy?.publisher || "MABES POLRI"} {new Date(data.createdAt) .toLocaleString("id-ID", { day: "2-digit", month: "short", year: "numeric", hour: "2-digit", minute: "2-digit", hour12: false, timeZone: "Asia/Jakarta", }) .replace(".", ":")}{" "} WIB {data.clickCount || 0} Creator: {data.creatorGroupLevelName}
{/* Deskripsi */}

{data.title}

{data.description}

{/* Tombol aksi bawah */}
COPY LINK
SHARE {showShareMenu && (
} label="Facebook" /> } label="TikTok" /> } label="YouTube" /> } label="WhatsApp" /> } label="Instagram" /> } label="Twitter" />
)}
COMMENT
); } // "use client"; // import Image from "next/image"; // import { Calendar, Clock, Eye } from "lucide-react"; // import { Button } from "@/components/ui/button"; // import Link from "next/link"; // import { useState, useEffect } from "react"; // import { // FaFacebookF, // FaTiktok, // FaYoutube, // FaWhatsapp, // FaInstagram, // FaTwitter, // FaCheck, // FaLink, // FaShareAlt, // } from "react-icons/fa"; // import { getDetail, getArticleDetail } from "@/service/landing/landing"; // export default function AudioDetail({ id }: { id: string }) { // const [copied, setCopied] = useState(false); // const [showShareMenu, setShowShareMenu] = useState(false); // const [data, setData] = useState(null); // const [loading, setLoading] = useState(true); // const [selectedDoc, setSelectedDoc] = useState(0); // const [isLoading, setIsLoading] = useState(true); // useEffect(() => { // const timer = setTimeout(() => { // setIsLoading(false); // }, 3000); // return () => clearTimeout(timer); // }, []); // const handleCopyLink = async () => { // try { // await navigator.clipboard.writeText(window.location.href); // setCopied(true); // setTimeout(() => setCopied(false), 2000); // } catch (err) { // console.error("Failed to copy: ", err); // } // }; // const SocialItem = ({ // icon, // label, // }: { // icon: React.ReactNode; // label: string; // }) => ( //
//
{icon}
// {label} //
// ); // useEffect(() => { // const fetchDetail = async () => { // try { // setLoading(true); // // Try new Articles API first // const response = await getArticleDetail(id); // console.log("Article Detail API response:", response); // if (response?.error) { // console.error("Articles API failed, falling back to old API"); // // Fallback to old API // const fallbackResponse = await getDetail(id); // setData(fallbackResponse?.data?.data); // console.log( // "doc", // fallbackResponse?.data?.data.files[selectedDoc]?.secondaryUrl // ); // return; // } // // Handle new API response structure // const articleData = response?.data?.data; // if (articleData) { // // Transform article data to match old structure for backward compatibility // const transformedData = { // id: articleData.id, // title: articleData.title, // description: articleData.description, // createdAt: articleData.createdAt, // clickCount: articleData.viewCount, // creatorGroupLevelName: articleData.createdByName || "Unknown", // uploadedBy: { // publisher: articleData.createdByName || "MABES POLRI" // }, // files: articleData.files?.map((file: any) => ({ // id: file.id, // url: file.file_url, // fileName: file.file_name, // filePath: file.file_path, // fileThumbnail: file.file_thumbnail, // fileAlt: file.file_alt, // widthPixel: file.width_pixel, // heightPixel: file.height_pixel, // size: file.size, // downloadCount: file.download_count, // createdAt: file.created_at, // updatedAt: file.updated_at, // secondaryUrl: file.file_url, // For audio files, use same URL // ...file // })) || [], // ...articleData // }; // setData(transformedData); // console.log( // "doc", // transformedData.files[selectedDoc]?.secondaryUrl // ); // } // } catch (error) { // console.error("Error fetching detail:", error); // // Try fallback to old API if new API fails // try { // const fallbackResponse = await getDetail(id); // setData(fallbackResponse?.data?.data); // console.log( // "doc", // fallbackResponse?.data?.data.files[selectedDoc]?.secondaryUrl // ); // } catch (fallbackError) { // console.error("Fallback API also failed:", fallbackError); // } // } finally { // setLoading(false); // } // }; // if (id) fetchDetail(); // }, [id]); // if (loading) { // return ( //
//

Loading...

//
// ); // } // if (!data) { // return ( //
//

Data tidak ditemukan

//
// ); // } // return ( //
//
// //
//
// {data?.files?.map((file: any, index: number) => ( // // ))} //
//
//
// // by {data?.uploadedBy?.publisher || "MABES POLRI"} // // // // {new Date(data.createdAt) // .toLocaleString("id-ID", { // day: "2-digit", // month: "short", // year: "numeric", // hour: "2-digit", // minute: "2-digit", // hour12: false, // timeZone: "Asia/Jakarta", // }) // .replace(".", ":")}{" "} // WIB // // {/* // // {data.time || "-"} // */} // // // {data.clickCount || 0} // // // {" "} // Creator: {data.creatorGroupLevelName} // //
//
//
// {/* Sidebar actions */} //
//
// // COPY LINK //
//
// // SHARE // {showShareMenu && ( //
// } label="Facebook" /> // } label="TikTok" /> // } label="YouTube" /> // } label="WhatsApp" /> // } label="Instagram" /> // } label="Twitter" /> //
// )} //
//
// // // COMMENT // //
//
// {/* Content */} //
//

{data.title}

//
//

{data.description}

//
// {/* Actions bawah */} //
//
// // COPY LINK //
//
// // SHARE //
//
// // // COMMENT // //
//
//
//
//
// ); // }