{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"price-position","title":"Price position","description":"Where our prices sit against a competitor (12% above, 4% below, in line), as a chip or as a badge with the index and matched-line evidence on hover.","dependencies":["lucide-react"],"registryDependencies":["https://ui.twelfth.ai/r/market-side.json","https://ui.twelfth.ai/r/one-open.json","https://ui.twelfth.ai/r/retail-format.json","popover"],"files":[{"path":"src/registry/catman/ui/price-position.tsx","content":"\"use client\"\n\nimport type { ReactNode } from \"react\"\nimport { MinusIcon } from \"lucide-react\"\n\nimport { Popover, PopoverContent, PopoverTrigger } from \"@/components/ui/popover\"\nimport { cn } from \"@/lib/utils\"\nimport { useOneOpen } from \"@/registry/catman/lib/one-open\"\nimport { formatIndex, formatPosition, formatUnits } from \"@/registry/catman/lib/retail-format\"\nimport { MarketArrow, marketSideFromPosition, marketToneClass } from \"@/registry/catman/ui/market-side\"\n\n/**\n * Where our prices sit against a competitor's: \"12% above\", \"4% below\", \"In\n * line\". The position is the median gap across comparable lines, in percent,\n * ours vs theirs; null when there are too few matched lines to say.\n *\n * Part of the twelfth catman registry (`@twelfth/price-position`).\n */\nexport const positionLabel = formatPosition\n\nconst CHIP = \"inline-flex items-center gap-1 whitespace-nowrap rounded-md px-2 py-1 text-xs tabular-nums\"\n\nfunction chipTone(positionPct: number | null) {\n  const side = marketSideFromPosition(positionPct)\n  return { side, className: cn(marketToneClass[side], (side === \"level\" || side === \"unknown\") && \"bg-secondary\") }\n}\n\nfunction ChipFace({ positionPct }: { positionPct: number | null }) {\n  const { side } = chipTone(positionPct)\n  return (\n    <>\n      {side === \"level\" ? <MinusIcon aria-hidden className=\"size-3\" /> : side === \"unknown\" ? null : <MarketArrow side={side} pointing=\"ours\" className=\"size-3\" />}\n      <span>{positionLabel(positionPct)}</span>\n    </>\n  )\n}\n\n/** The chip alone, for a table cell or an inline mention. */\nexport function PricePositionChip({ positionPct, className }: { positionPct: number | null; className?: string }) {\n  return (\n    <span className={cn(CHIP, chipTone(positionPct).className, className)}>\n      <ChipFace positionPct={positionPct} />\n    </span>\n  )\n}\n\nexport type PricePositionEvidence = {\n  /** Lines matched to the competitor in the period. */\n  matched: number\n  /** Of those, how many we price above. */\n  above: number\n  /** And below. */\n  below: number\n}\n\n/**\n * The chip with the evidence behind it on hover or focus: the index, how many\n * lines it rests on, and which way they split. A position without its count is\n * a number nobody can argue with, which is the wrong kind of number.\n */\nexport function PricePositionBadge({\n  competitor,\n  positionPct,\n  evidence,\n  period,\n  channel,\n  action,\n  className,\n}: {\n  competitor: string\n  positionPct: number | null\n  evidence: PricePositionEvidence\n  /** e.g. \"8-week comparison\" or \"Last observed prices\". */\n  period?: string\n  /** e.g. \"Direct retail\" or \"Marketplace sellers\". */\n  channel?: string\n  /** A link or button under the evidence, e.g. to the matched lines. */\n  action?: ReactNode\n  className?: string\n}) {\n  const label = positionLabel(positionPct)\n  const subtitle = [period, channel].filter(Boolean).join(\" · \")\n  const [open, setOpen] = useOneOpen()\n  return (\n    <Popover open={open} onOpenChange={setOpen}>\n      <PopoverTrigger\n        openOnHover\n        delay={40}\n        closeDelay={80}\n        aria-label={`Our price position against ${competitor}: ${label}`}\n        className={cn(CHIP, \"outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring\", chipTone(positionPct).className, className)}\n      >\n        <ChipFace positionPct={positionPct} />\n      </PopoverTrigger>\n      <PopoverContent align=\"start\" sideOffset={7} className=\"w-72 max-w-[calc(100vw-2rem)] p-3 text-xs\">\n        {/* One child: stock popovers stack their children with a gap. */}\n        <div>\n          <p className=\"font-medium text-popover-foreground\">Our prices vs {competitor}</p>\n          {subtitle ? <p className=\"mt-0.5 text-muted-foreground\">{subtitle}</p> : null}\n          <div className=\"mt-3 flex items-baseline justify-between gap-3\">\n            <span className=\"text-base font-semibold\">{label}</span>\n            {positionPct !== null ? <span className=\"font-mono tabular-nums text-muted-foreground\">Index {formatIndex(positionPct)}</span> : null}\n        </div>\n        <dl className=\"mt-3 space-y-1.5 border-y py-2.5\">\n          <div className=\"flex justify-between gap-3\"><dt className=\"text-muted-foreground\">Matched lines</dt><dd className=\"font-mono tabular-nums\">{formatUnits(evidence.matched)}</dd></div>\n          <div className=\"flex justify-between gap-3\"><dt className=\"text-muted-foreground\">Our lines priced above</dt><dd className=\"font-mono tabular-nums\">{formatUnits(evidence.above)}</dd></div>\n          <div className=\"flex justify-between gap-3\"><dt className=\"text-muted-foreground\">Our lines priced below</dt><dd className=\"font-mono tabular-nums\">{formatUnits(evidence.below)}</dd></div>\n        </dl>\n        <p className=\"mt-2 text-muted-foreground\">{positionPct === null ? \"Not enough comparable prices for a position in this period.\" : \"The median price gap across comparable lines. Index 100 is parity; above 100 means our prices are higher.\"}</p>\n        {action ? <div className=\"mt-3\">{action}</div> : null}\n        </div>\n      </PopoverContent>\n    </Popover>\n  )\n}\n","type":"registry:ui"}],"type":"registry:ui"}