import useSWR from 'swr' import axios from 'axios' import { useState } from 'react' import { Download, Terminal, Smartphone, Shield, Monitor, FileCode, Check, Copy, AlertCircle } from 'lucide-react' import clsx from 'clsx' // Interface matching the API response interface CaCertificate { name: string; type: string; serial: string; family_id?: string | null; expires_at: string; cdn_url?: string | null; linux_cdn_url?: string | null; der_cdn_url?: string | null; bat_cdn_url?: string | null; mac_cdn_url?: string | null; } const fetcher = (url: string) => axios.get(url).then(res => res.data.data) export function DynamicInstallationGuide({ locale = 'en' }: { locale?: 'en' | 'id' }) { const { data: certificates, error, isLoading } = useSWR('https://api.trustlab.dyzulk.com/api/public/ca-certificates', fetcher) const [selectedIndex, setSelectedIndex] = useState(0) const [copiedId, setCopiedId] = useState(null) const dict = { en: { errorTitle: "Unable to load live certificates.", errorDesc: "Please ensure you can access", loading: "Loading installer data...", table: { cert: "Certificate", raw: "Raw Format", linux: "One-Liner Installer", android: "Alternative (.der)", ios: "Config Profile", mac: "Config Profile", auto: "Auto-Installer" }, installer: { bat: "Installer Script (.bat)", mobile: "Config Profile", der: "Download .der", not_avail: "Not available", copy: "Copy command" } }, id: { errorTitle: "Gagal memuat sertifikat langsung.", errorDesc: "Pastikan Anda dapat mengakses", loading: "Memuat data installer...", table: { cert: "Sertifikat", raw: "Format Dasar", linux: "Installer Satu Baris", android: "Alternatif (.der)", ios: "Profil Konfigurasi", mac: "Profil Konfigurasi", auto: "Auto-Installer" }, installer: { bat: "Skrip Installer (.bat)", mobile: "Profil Konfigurasi", der: "Unduh .der", not_avail: "Tidak tersedia", copy: "Salin perintah" } } } const t = dict[locale] const handleCopy = (text: string, id: string) => { navigator.clipboard.writeText(text) setCopiedId(id) setTimeout(() => setCopiedId(null), 2000) } if (error) return (
{t.errorTitle}

{t.errorDesc} api.trustlab.dyzulk.com.

) if (isLoading || !certificates) return (
{t.loading}
) const root = certificates.find(c => c.type === 'root') const intermediates = certificates.filter(c => c.type !== 'root') const tabs = [ { id: 'windows', label: 'Windows', icon: Monitor }, { id: 'mac', label: 'macOS', icon: Monitor }, { id: 'ios', label: 'iOS', icon: Smartphone }, { id: 'android', label: 'Android', icon: Smartphone }, { id: 'linux', label: 'Linux (CLI)', icon: Terminal }, ] const activeTab = tabs[selectedIndex].id as 'windows' | 'mac' | 'ios' | 'linux' | 'android' return (
{/* Tabs Header - Nextra Style (Bottom Border) */}
{tabs.map((tab, idx) => { const isActive = selectedIndex === idx const Icon = tab.icon return ( ) })}
{/* Tab Content */}
{/* Root Row */} {root && ( )} {/* Intermediates Rows */} {intermediates.map(cert => ( ))}
{t.table.cert} {t.table.raw} {activeTab === 'linux' ? t.table.linux : activeTab === 'android' ? t.table.android : activeTab === 'ios' ? t.table.ios : activeTab === 'mac' ? t.table.mac : t.table.auto}
Root CA
{root.name}
Exp: {new Date(root.expires_at).getFullYear()}
Download .crt
Intermediate CA
{cert.name}
Download .crt
{/* Contextual Instructions Footer - Detailed Manual Steps */}
{activeTab === 'windows' && (

{locale === 'id' ? 'Instalasi Manual (Mentah .crt)' : 'Manual Installation (Raw .crt)'}

{locale === 'id' ? 'Untuk Root CA:' : 'For Root CA:'}
    {locale === 'id' ? ( <>
  1. Klik dua kali dydev-its-true.crtInstall Certificate.
  2. Pilih Local Machine (memerlukan Admin).
  3. Pilih "Place all certificates in the following store".
  4. Browse & pilih Trusted Root Certification Authorities.
  5. ) : ( <>
  6. Double-click dydev-its-true.crtInstall Certificate.
  7. Select Local Machine (requires Admin).
  8. Select "Place all certificates in the following store".
  9. Browse & select Trusted Root Certification Authorities.
  10. )}
{locale === 'id' ? 'Untuk Intermediates:' : 'For Intermediates:'}
    {locale === 'id' ? ( <>
  1. Klik dua kali file .crt.
  2. Ikuti langkah yang sama tapi pilih Intermediate Certification Authorities sebagai store.
  3. ) : ( <>
  4. Double-click the .crt file.
  5. Follow the same steps but choose Intermediate Certification Authorities as the store.
  6. )}
)} {/* Simplified for brevity - I will focus on the main logic above */}
) } // Sub-component for cleaner render logic function InstallerCell({ cert, os, handleCopy, copiedId, t }: { cert: CaCertificate, os: string, handleCopy: Function, copiedId: string | null, t: any }) { if (os === 'windows' && cert.bat_cdn_url) { return ( {t.installer.bat} ) } if ((os === 'mac' || os === 'ios') && cert.mac_cdn_url) { return ( {t.installer.mobile} ) } if (os === 'android' && cert.der_cdn_url) { return ( {t.installer.der} ) } if (os === 'linux' && cert.linux_cdn_url) { const cmd = `curl -sL ${cert.linux_cdn_url} | sudo bash` const isCopied = copiedId === cert.serial return (
{cmd}
) } return {t.installer.not_avail} }