{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-post-card",
  "title": "Post card",
  "description": "A social post card built from static props: author, text, pictures, date and counts. Nothing is fetched.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/post-card.tsx",
      "content": "import { Fragment } from 'react';\n\nimport { cn } from '@/lib/utils';\nimport {\n  BookmarkIcon,\n  BadgeCheckIcon,\n  HeartIcon,\n  MessageCircleIcon,\n  RepeatIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\nimport { Avatar, AvatarImage } from '@/registry/ndeko/ui/avatar';\n\nexport type PostAuthor = {\n  name: string;\n  handle: string;\n  avatar?: string;\n  verified?: boolean;\n};\n\nexport type PostMedia = {\n  src: string;\n  alt: string;\n};\n\nexport type PostCounts = {\n  replies?: number;\n  reposts?: number;\n  likes?: number;\n  bookmarks?: number;\n  views?: number;\n};\n\ntype StatName = 'replies' | 'reposts' | 'likes' | 'bookmarks';\n\ntype StatDefinition = {\n  name: StatName;\n  icon: Icon;\n  singular: string;\n  plural: string;\n};\n\nconst STATS: StatDefinition[] = [\n  {\n    name: 'replies',\n    icon: MessageCircleIcon,\n    singular: 'reply',\n    plural: 'replies',\n  },\n  {\n    name: 'reposts',\n    icon: RepeatIcon,\n    singular: 'repost',\n    plural: 'reposts',\n  },\n  { name: 'likes', icon: HeartIcon, singular: 'like', plural: 'likes' },\n  {\n    name: 'bookmarks',\n    icon: BookmarkIcon,\n    singular: 'bookmark',\n    plural: 'bookmarks',\n  },\n];\n\nconst HIGHLIGHT_PATTERN = /(@\\w+|#\\w+|https?:\\/\\/\\S+)/g;\n\nconst HIGHLIGHT_TEST = /^(@\\w+|#\\w+|https?:\\/\\/\\S+)$/;\n\nconst MEDIA_LAYOUTS: Record<number, string[]> = {\n  1: ['col-span-2 row-span-2'],\n  2: ['row-span-2', 'row-span-2'],\n  3: ['row-span-2', '', ''],\n  4: ['', '', '', ''],\n};\n\nconst MAX_MEDIA = 4;\n\nfunction dateOf(value: Date | string) {\n  if (value instanceof Date) {\n    return value;\n  }\n  return new Date(value);\n}\n\nfunction compactOf(count: number, locale: string) {\n  const format = new Intl.NumberFormat(locale, {\n    notation: 'compact',\n    maximumFractionDigits: 1,\n  });\n  return format.format(count);\n}\n\nfunction spokenCountOf(count: number, singular: string, plural: string) {\n  if (count === 1) {\n    return `1 ${singular}`;\n  }\n  return `${count} ${plural}`;\n}\n\nfunction spokenViewsOf(views: number) {\n  if (views === 1) {\n    return 'view';\n  }\n  return 'views';\n}\n\nfunction timeOf(date: Date, locale: string, timeZone: string) {\n  const format = new Intl.DateTimeFormat(locale, {\n    hour: 'numeric',\n    minute: '2-digit',\n    timeZone,\n  });\n  return format.format(date);\n}\n\nfunction dayOf(date: Date, locale: string, timeZone: string) {\n  const format = new Intl.DateTimeFormat(locale, {\n    month: 'short',\n    day: 'numeric',\n    year: 'numeric',\n    timeZone,\n  });\n  return format.format(date);\n}\n\nfunction PostText({ text }: { text: string }) {\n  const parts = text.split(HIGHLIGHT_PATTERN);\n\n  return (\n    <p className='mt-3 text-sm leading-relaxed text-pretty whitespace-pre-line'>\n      {parts.map((part, index) => {\n        const isHighlight = HIGHLIGHT_TEST.test(part);\n        if (isHighlight) {\n          return (\n            <span key={index} className='text-primary-ink'>\n              {part}\n            </span>\n          );\n        }\n        return <Fragment key={index}>{part}</Fragment>;\n      })}\n    </p>\n  );\n}\n\nfunction PostMediaGrid({ media }: { media: PostMedia[] }) {\n  const shown = media.slice(0, MAX_MEDIA);\n  const layout = MEDIA_LAYOUTS[shown.length];\n\n  return (\n    <div className='mt-3 grid aspect-video grid-cols-2 grid-rows-2 gap-0.5 overflow-hidden rounded-lg'>\n      {shown.map((item, index) => (\n        // eslint-disable-next-line @next/next/no-img-element -- registry items land in any React app, where next/image may not exist\n        <img\n          key={item.src}\n          src={item.src}\n          alt={item.alt}\n          loading='lazy'\n          className={cn('bg-muted size-full object-cover', layout[index])}\n        />\n      ))}\n    </div>\n  );\n}\n\nfunction PostStat({\n  stat,\n  count,\n  locale,\n}: {\n  stat: StatDefinition;\n  count: number;\n  locale: string;\n}) {\n  const StatIcon = stat.icon;\n\n  return (\n    <li className='text-muted-foreground flex items-center gap-1.5 text-[13px]'>\n      <StatIcon className='size-4' />\n      <span aria-hidden='true' className='tabular-nums'>\n        {compactOf(count, locale)}\n      </span>\n      <span className='sr-only'>\n        {spokenCountOf(count, stat.singular, stat.plural)}\n      </span>\n    </li>\n  );\n}\n\nfunction hasCount(count: number | undefined): count is number {\n  return count !== undefined;\n}\n\nexport type PostCardProps = Omit<\n  React.ComponentProps<'article'>,\n  'children'\n> & {\n  author: PostAuthor;\n  text: string;\n  date: Date | string;\n  media?: PostMedia[];\n  counts?: PostCounts;\n  href?: string;\n  locale?: string;\n  timeZone?: string;\n};\n\nexport function PostCard({\n  author,\n  text,\n  date,\n  media = [],\n  counts = {},\n  href,\n  locale = 'en-US',\n  timeZone = 'UTC',\n  className,\n  ...props\n}: PostCardProps) {\n  const postedAt = dateOf(date);\n  const time = timeOf(postedAt, locale, timeZone);\n  const day = dayOf(postedAt, locale, timeZone);\n  const hasMedia = media.length > 0;\n  const views = counts.views;\n  const hasViews = hasCount(views);\n  const shownStats = STATS.filter((stat) => hasCount(counts[stat.name]));\n  const timestamp = (\n    <time dateTime={postedAt.toISOString()}>\n      {time} · {day}\n    </time>\n  );\n\n  return (\n    <article\n      className={cn(\n        'bg-card text-card-foreground hairline-ring ring-border w-full max-w-lg rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n        className\n      )}\n      {...props}\n    >\n      <header className='flex items-center gap-3'>\n        <Avatar className='size-10' seed={author.name}>\n          {author.avatar && <AvatarImage src={author.avatar} alt='' />}\n        </Avatar>\n        <div className='flex min-w-0 flex-col'>\n          <span className='flex min-w-0 items-center gap-1'>\n            <span className='truncate text-sm font-semibold'>\n              {author.name}\n            </span>\n            {author.verified && (\n              <>\n                <BadgeCheckIcon className='text-primary-ink size-4 shrink-0' />\n                <span className='sr-only'>Verified account</span>\n              </>\n            )}\n          </span>\n          <span className='text-muted-foreground truncate text-[13px]'>\n            @{author.handle}\n          </span>\n        </div>\n      </header>\n      <PostText text={text} />\n      {hasMedia && <PostMediaGrid media={media} />}\n      <footer>\n        <p className='text-muted-foreground mt-3 text-[13px]'>\n          {href && (\n            <a\n              href={href}\n              className='hover:text-foreground focus-visible:ring-ring/25 rounded-sm underline-offset-4 outline-none hover:underline focus-visible:ring-3'\n            >\n              {timestamp}\n            </a>\n          )}\n          {!href && timestamp}\n          {hasViews && (\n            <>\n              {' · '}\n              <span className='text-foreground font-medium tabular-nums'>\n                {compactOf(views, locale)}\n              </span>{' '}\n              {spokenViewsOf(views)}\n            </>\n          )}\n        </p>\n        {shownStats.length > 0 && (\n          <ul className='mt-3 flex items-center gap-6'>\n            {shownStats.map((stat) => (\n              <PostStat\n                key={stat.name}\n                stat={stat}\n                count={counts[stat.name] ?? 0}\n                locale={locale}\n              />\n            ))}\n          </ul>\n        )}\n      </footer>\n    </article>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/post-card.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}