import { type ReactNode } from 'react'
import { Tag, Calendar, ExternalLink, ChevronDown, ChevronUp, Heart, Coffee, Bug, Lightbulb, BookOpen } from 'lucide-react'
import { useTranslation } from '../../../i18n'
import { useGithubReleases } from '../../../components/Admin/useGithubReleases'
import { escapeReleaseHtml as escapeHtml, parseReleaseNotes } from '../../../utils/releaseNotes'
import { MAdminButton, MAdminCard } from './MAdminUi'
import { withoutDonationsInApp } from '../../../utils/donations'
import MSkeleton from '../../components/MSkeleton'
const REPO = 'liketrek/TREK'
// Support / community link cards (design: brand-tinted icon tile + title/sub).
// Brand hex stays as content identity; every surface/border uses --m-* tokens.
interface LinkCard {
href: string
color: string
icon: ReactNode
title: string
sub: string
}
export default function MAdminGitHubPanel({ isPrerelease = false }: { isPrerelease?: boolean }) {
const { t } = useTranslation()
const {
releases, shownReleases, loading, error, expanded, toggleExpand, hasMore, loadingMore, handleLoadMore, formatDate,
} = useGithubReleases({ isPrerelease, fillPages: true })
// Simple markdown-to-html for release notes (handles headers, bold, lists, links)
const renderBody = (body: string | null) => {
if (!body) return null
// `[label](url)` → anchor, exactly as /\[([^\]]+)\]\(([^)]+)\)/g did. Written as a
// scan because that pattern backtracks from both ends: `[^\]]` matches `[` and
// `[^)]` matches `(`, so a run of either made the engine retry the whole match from
// every one of them, reading to the end each time. Release bodies come off the
// GitHub API. Both parts are one-or-more, so `[](url)` and `[label]()` stay plain
// text; the label ends at the first `]`, the url at the first `)`.
const linkify = (text: string) => {
let out = ''
let cursor = 0
let search = 0
for (;;) {
const open = text.indexOf('[', search)
if (open === -1) break
const close = text.indexOf(']', open + 1)
if (close === -1) break // no `]` left: no later `[` can match either
// Every `[` up to `close` shares that first `]`, so they fail together.
if (close === open + 1 || text[close + 1] !== '(') {
search = close + 1
continue
}
const end = text.indexOf(')', close + 2)
if (end === -1) break // no `)` left: no later `(` can close either
if (end === close + 2) {
search = close + 1
continue
}
const label = text.slice(open + 1, close)
const url = text.slice(close + 2, end)
const safeUrl = url.startsWith('http://') || url.startsWith('https://') ? url : '#'
out += `${text.slice(cursor, open)}${label}`
cursor = end + 1
search = end + 1
}
return out + text.slice(cursor)
}
const inlineFormat = (text: string) => {
return linkify(
escapeHtml(text)
.replace(/\*\*(.+?)\*\*/g, '$1')
.replace(/`(.+?)`/g, '$1')
)
}
return parseReleaseNotes(body).map((block, idx) => {
if (block.kind === 'ul') {
return (
{t('admin.github.error')}
{error}
{t('admin.github.subtitle').replace('{repo}', REPO)}
{release.name}
)}{t('admin.github.error')} — {error}
)} {/* Load more */} {hasMore && (