import { Switch } from "@/components/ui/switch" import { Download, Star, Zap } from "lucide-react" import { navigate } from "vike/client/router" function getGitHubStarsBadgeUrl(repoUrl?: string): string | null { if (!repoUrl) return null try { const url = new URL(repoUrl) if (url.hostname === "github.com" || url.hostname === "www.github.com") { const pathParts = url.pathname.split("/").filter(Boolean) if (pathParts.length >= 2) { const owner = pathParts[0] const repo = pathParts[1] return `https://img.shields.io/github/stars/${owner}/${repo}?style=flat&logo=github&logoColor=white&labelColor=rgb(0,0,0,0)&color=rgb(30,30,30)&label=★` } } } catch { // Invalid URL, return null } return null } interface PluginCardBaseProps { id: string name: string description: string imageUrl?: string featured?: boolean repo?: string homepage?: string version?: string downloads?: number stars?: number flashCount?: number incompatibleReason?: string prominent?: boolean } interface PluginCardToggleProps extends PluginCardBaseProps { variant: "toggle" isEnabled: boolean onToggle: (enabled: boolean) => void disabled?: boolean enabledLabel?: string } interface PluginCardLinkProps extends PluginCardBaseProps { variant: "link" href?: string } interface PluginCardLinkToggleProps extends PluginCardBaseProps { variant: "link-toggle" isEnabled: boolean onToggle: (enabled: boolean) => void disabled?: boolean enabledLabel?: string } type PluginCardProps = PluginCardToggleProps | PluginCardLinkProps | PluginCardLinkToggleProps export function PluginCard(props: PluginCardProps) { const { id, name, description, imageUrl, featured = false, repo, homepage, version, downloads, stars, flashCount, incompatibleReason, prominent = false, } = props const starsBadgeUrl = getGitHubStarsBadgeUrl(repo) const isIncompatible = !!incompatibleReason const isToggle = props.variant === "toggle" const isLink = props.variant === "link" const isLinkToggle = props.variant === "link-toggle" const cardContent = ( <> {isToggle ? ( <> {/* Toggle layout: horizontal with switch on right */}
{description}
{isIncompatible && incompatibleReason && ({incompatibleReason}
)}{description}
{isIncompatible && incompatibleReason && ({incompatibleReason}
)}