import Link from 'next/link'
import { redirect } from 'next/navigation'
import { isAuthenticated } from '@/lib/auth'
import { readJsonFile } from '@/lib/storage'

export default async function WebhookLogsPage() {
  if (!await isAuthenticated()) {
    redirect('/login')
  }

  const logs = readJsonFile<unknown[]>('webhook-logs.json', [])

  return (
    <div className="wrap">
      <div className="top">
        <div>
          <h1>Webhook Logs</h1>
          <p>Semua log webhook masuk, outgoing, dan status ada di sini.</p>
        </div>
        <div style={{ display: 'flex', gap: 10 }}>
          <Link className="btn" href="/settings">Settings</Link>
          <Link className="btn" href="/test">Halaman Test</Link>
        </div>
      </div>

      <div className="card">
        <pre>{JSON.stringify(logs.slice().reverse(), null, 2)}</pre>
      </div>
    </div>
  )
}
