{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "mrdoge-match-highlight-adapter",
  "title": "Match Highlight Adapter (Mr. Doge SDK)",
  "description": "Maps a real matches.get()/matches.subscribe() response onto Match Highlight's props.",
  "dependencies": [
    "@mrdoge/protocol"
  ],
  "registryDependencies": [
    "match-highlight"
  ],
  "files": [
    {
      "path": "lib/mrdoge-adapters/match-highlight.ts",
      "content": "import type { Match, MatchDetail } from \"@mrdoge/protocol\"\nimport type { MatchHighlightCompetitionMatch, MatchHighlightDataProps } from \"@/registry/mrdoge-ui/match-highlight/match-highlight\"\n\n// Public, unauthenticated, cached CDN. Not part of the Team/Region shape\n// itself. See /docs/reference/images.\nfunction teamLogoUrl(teamId: number) {\n  return `https://api.mrdoge.co/images/teams/${teamId}.png`\n}\n\nfunction regionLogoUrl(regionId: number) {\n  return `https://api.mrdoge.co/images/regions/${regionId}.png`\n}\n\n/**\n * Maps a real `matches.get()` / `matches.subscribe()` response to Match\n * Highlight's props. If the SDK's shape changes, this fails to compile.\n *\n * Cards and corners are soccer-specific. MatchStats is a discriminated\n * union per sport, so this narrows before reading them; other sports get\n * no stats row at all rather than misleading zeros.\n *\n * Doesn't populate `competitionMatches`/`onOpenCompetitionMatches`/\n * `onSelectCompetitionMatch`: those need a live query for \"other matches\n * today in this competition\", which a single-match adapter can't run on\n * its own. Add them at the call site (see the demo).\n */\nexport function matchToMatchHighlightProps(match: MatchDetail): MatchHighlightDataProps {\n  const stats = match.stats?.sport === \"soccer\" ? match.stats : undefined\n  const clock = match.stats?.clock\n\n  return {\n    status: match.status,\n    competition: match.competition.name,\n    region: { name: match.region.name, logoUrl: regionLogoUrl(match.region.id) },\n    kickoff: match.startTime,\n    home: {\n      name: match.homeTeam.name,\n      logoUrl: teamLogoUrl(match.homeTeam.id),\n      yellowCards: stats?.homeYellowCards,\n      redCards: stats?.homeRedCards,\n      corners: stats?.homeCorners,\n    },\n    away: {\n      name: match.awayTeam.name,\n      logoUrl: teamLogoUrl(match.awayTeam.id),\n      yellowCards: stats?.awayYellowCards,\n      redCards: stats?.awayRedCards,\n      corners: stats?.awayCorners,\n    },\n    homeScore: match.stats?.homeScore,\n    awayScore: match.stats?.awayScore,\n    clock: clock\n      ? {\n          state: clock.state,\n          display: clock.display,\n          displayLong: clock.displayLong,\n          elapsedSeconds: clock.elapsedSeconds,\n          referenceTime: clock.referenceTime,\n          minute: clock.minute,\n          stoppage: clock.stoppage,\n        }\n      : undefined,\n  }\n}\n\nfunction toCompetitionMatchInfo(match: Match): string | undefined {\n  if (match.status === \"upcoming\") {\n    return new Date(match.startTime).toLocaleTimeString(undefined, { hour: \"numeric\", minute: \"2-digit\", hour12: false })\n  }\n  if (match.stats?.homeScore != null && match.stats?.awayScore != null) {\n    return `${match.stats.homeScore}-${match.stats.awayScore}`\n  }\n  return undefined\n}\n\n/**\n * Maps a real `matches.list({ competitionIds: [...], date })` response\n * onto Match Highlight's `competitionMatches` prop: excludes the match\n * you're already viewing and sorts by kickoff time. Pure mapping only;\n * running that query lazily (e.g. only once the dropdown first opens) is\n * the caller's job. See the demo.\n */\nexport function matchesToCompetitionMatches(matches: Match[], excludeMatchId: string): MatchHighlightCompetitionMatch[] {\n  return matches\n    .filter((match) => match.id !== excludeMatchId)\n    .sort((a, b) => a.startTime.localeCompare(b.startTime))\n    .map((match) => ({\n      id: match.id,\n      home: { name: match.homeTeam.name, logoUrl: teamLogoUrl(match.homeTeam.id) },\n      away: { name: match.awayTeam.name, logoUrl: teamLogoUrl(match.awayTeam.id) },\n      info: toCompetitionMatchInfo(match),\n    }))\n}\n",
      "type": "registry:lib",
      "target": "lib/mrdoge-adapters/match-highlight.ts"
    }
  ],
  "type": "registry:lib"
}