{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "lining-wear",
  "title": "Lining Wear",
  "description": "A dunning card for past-due subscriptions where the clutch grip on 'active' is a friction lining that wears down: every failed charge slips the pad and permanently scores one lamination, and the plate disengages to 'paused' once the lining is spent.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/lining-wear/component.tsx",
      "content": "\"use client\";\n\nimport { useEffect, useId, useRef, useState } from \"react\";\n\n// ---------------------------------------------------------------------------\n// LiningWear — a dunning / payment-retry card that renders the subscription's\n// grip on \"active\" as a clutch friction lining wearing down, not a yellow\n// past-due badge. One governing scalar, `lining = attemptsRemaining /\n// maxAttempts`, drives everything: pad height (base x lining) with\n// laminations ruled every segment so remaining depth is countable at rest;\n// each FAILED charge (attemptsUsed increasing) is one abrasion event — the\n// pad+label group slips sideways under load by (1 - lining) x 12px (capped:\n// a worn clutch grips worse, so later failures slip further) and settles\n// back with a spring whose duration eases 300ms -> 700ms as lining drops\n// (the same settle also carries the pad's one-segment drop, so the last\n// failure's heavier, slower settle reads as the plate physically\n// disengaging toward \"paused\" rather than a special-cased animation). One\n// lamination abrades away per failure, leaving a permanent scored line at a\n// fixed position that nothing later ever redraws over, and one debris tick\n// drops into the row below. Wear is monotonic within a billing cycle: no\n// code path here ever removes a scored line or a debris tick while `cycleId`\n// is unchanged, because that would erase the datum a past-due customer and\n// support both need (\"this card has already failed three times\"). Recovery\n// is a distinct re-line, triggered only by a `cycleId` change: the old\n// scored block is snapshotted into a small half-visible \"last cycle\" well\n// and a fresh, unscored pad swaps in — never a health-bar refill.\n//\n// Status is text first, not carried by the graphic: a plain paragraph reads\n// e.g. \"Payment failed, attempt 2 of 4. Next retry Thu 21 Aug.\", a second\n// line spells out attempts remaining, the retry schedule is a real <ol>, and\n// \"Update payment method\" is a real button. The wear graphic itself is\n// aria-hidden and holds no interactive control. Each new failure announces\n// exactly once through a role=alert/aria-live=assertive span — genuinely\n// urgent, not routine chatter. prefers-reduced-motion drops the slip/settle\n// transform outright; laminations still decrement and scored lines still\n// accumulate on the very same render, so the state is never motion-gated.\n//\n// Direct-DOM refs carry the one hot-path transform (the grip's FLIP-style\n// translate); every other visual (scored lines, laminations, debris,\n// schedule, status text) is plain declarative React driven by props. Zero\n// dependencies, DOM + CSS only, no canvas.\n// ---------------------------------------------------------------------------\n\nexport interface LiningWearProps {\n  /** Subscription / plan name shown in the card header. Default \"Pro plan\". */\n  planName?: string;\n  /**\n   * Failed charge attempts so far THIS billing cycle. Monotonic within a\n   * cycle — increment by 1 each time a charge attempt fails. Reset to 0\n   * (together with a changed `cycleId`) once a charge succeeds and a new\n   * cycle begins; that is the only sanctioned way this component's wear\n   * ever goes down.\n   */\n  attemptsUsed: number;\n  /** Total attempts allotted before the subscription pauses. Default 4. */\n  maxAttempts?: number;\n  /**\n   * Calendar label for every retry slot, oldest first, length `maxAttempts`\n   * (e.g. [\"Mon 14 Aug\", \"Thu 17 Aug\", \"Sun 20 Aug\", \"Wed 23 Aug\"]). Drives\n   * both the status line's \"next retry\" text and the schedule list.\n   */\n  attemptDates: string[];\n  /**\n   * Change this (any new value) to start a fresh billing cycle: the current\n   * scored pad retires into the \"last cycle\" well and a clean, unscored\n   * pad swaps in. Pass `attemptsUsed={0}` alongside the new id.\n   */\n  cycleId?: string | number;\n  /** Called when the visitor presses \"Update payment method\". */\n  onUpdatePayment?: () => void;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nconst FRAME_H = 64;\nconst SLIP_MAX_PX = 12;\nconst SETTLE_MIN_MS = 300;\nconst SETTLE_MAX_MS = 700;\nconst EASE_SETTLE = \"cubic-bezier(0.34, 1.56, 0.64, 1)\";\n\nfunction segmentH(maxAttempts: number) {\n  return FRAME_H / Math.max(1, maxAttempts);\n}\n\n// Deterministic pseudo-random in [0,1) so debris drift never differs between\n// server and client renders (a real Math.random() here would hydrate wrong).\nfunction hash01(seed: number) {\n  const x = Math.sin(seed * 12.9898) * 43758.5453;\n  return x - Math.floor(x);\n}\n\nfunction computeSettle(lining: number) {\n  const clampedLining = Math.min(1, Math.max(0, lining));\n  const slip = Math.round((1 - clampedLining) * SLIP_MAX_PX * 10) / 10;\n  const ms = Math.round(SETTLE_MIN_MS + (1 - clampedLining) * (SETTLE_MAX_MS - SETTLE_MIN_MS));\n  return { slip, ms };\n}\n\nfunction animateGripStep(\n  el: HTMLDivElement | null,\n  fromTopPx: number,\n  toTopPx: number,\n  slipPx: number,\n  ms: number,\n  reduced: boolean\n) {\n  if (!el) return;\n  if (reduced) {\n    el.style.transition = \"none\";\n    el.style.transform = \"translate(0px, 0px)\";\n    return;\n  }\n  // FLIP: land at the new resting position instantly (the React-controlled\n  // `top` already moved there), then hold the OLD visual position plus the\n  // sideways slip via transform, and only next frame ease both back to zero.\n  el.style.transition = \"none\";\n  el.style.transform = `translate(${slipPx}px, ${fromTopPx - toTopPx}px)`;\n  requestAnimationFrame(() => {\n    requestAnimationFrame(() => {\n      el.style.transition = `transform ${ms}ms ${EASE_SETTLE}`;\n      el.style.transform = \"translate(0px, 0px)\";\n    });\n  });\n}\n\nfunction statusText(attemptsUsed: number, maxAttempts: number, attemptDates: string[]) {\n  if (attemptsUsed <= 0) {\n    return `Payment active. ${maxAttempts} of ${maxAttempts} retry attempts available.`;\n  }\n  if (attemptsUsed < maxAttempts) {\n    const next = attemptDates[attemptsUsed] ?? \"soon\";\n    return `Payment failed, attempt ${attemptsUsed} of ${maxAttempts}. Next retry ${next}.`;\n  }\n  return `Payment failed ${maxAttempts} times this cycle. Subscription paused — update your payment method to resume.`;\n}\n\ninterface LastCycle {\n  attemptsUsed: number;\n  maxAttempts: number;\n}\n\nexport function LiningWear({\n  planName = \"Pro plan\",\n  attemptsUsed,\n  maxAttempts = 4,\n  attemptDates,\n  cycleId,\n  onUpdatePayment,\n  className = \"\",\n}: LiningWearProps) {\n  const gripRef = useRef<HTMLDivElement | null>(null);\n  const topPxRef = useRef(0);\n  const reducedRef = useRef(false);\n  const prevAttemptsRef = useRef(0);\n  const prevCycleRef = useRef<string | number | undefined>(cycleId);\n  const firstRunRef = useRef(true);\n\n  const [liveMsg, setLiveMsg] = useState(\"\");\n  const [lastCycle, setLastCycle] = useState<LastCycle | null>(null);\n  const [wellEntering, setWellEntering] = useState(false);\n\n  const introId = useId();\n\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    reducedRef.current = mq.matches;\n    const onChange = () => {\n      reducedRef.current = mq.matches;\n    };\n    mq.addEventListener(\"change\", onChange);\n    return () => mq.removeEventListener(\"change\", onChange);\n  }, []);\n\n  const clamped = Math.max(0, Math.min(attemptsUsed, maxAttempts));\n\n  useEffect(() => {\n    const prevAttempts = prevAttemptsRef.current;\n    const prevCycle = prevCycleRef.current;\n    prevAttemptsRef.current = clamped;\n    prevCycleRef.current = cycleId;\n\n    if (firstRunRef.current) {\n      firstRunRef.current = false;\n      topPxRef.current = clamped * segmentH(maxAttempts);\n      return;\n    }\n\n    const cycleChanged = prevCycle !== cycleId;\n    if (cycleChanged) {\n      // Re-line: retire the worn block into the \"last cycle\" well instead of\n      // erasing it, then swap in a fresh unscored pad with no animation of\n      // its own — the well entrance is what carries the transition.\n      setLastCycle({ attemptsUsed: prevAttempts, maxAttempts });\n      topPxRef.current = clamped * segmentH(maxAttempts);\n      if (gripRef.current) {\n        gripRef.current.style.transition = \"none\";\n        gripRef.current.style.transform = \"translate(0px, 0px)\";\n      }\n      setWellEntering(true);\n      requestAnimationFrame(() => requestAnimationFrame(() => setWellEntering(false)));\n      return;\n    }\n\n    if (clamped > prevAttempts) {\n      const lining = (maxAttempts - clamped) / maxAttempts;\n      const { slip, ms } = computeSettle(lining);\n      const newTop = clamped * segmentH(maxAttempts);\n      animateGripStep(gripRef.current, topPxRef.current, newTop, slip, ms, reducedRef.current);\n      topPxRef.current = newTop;\n      setLiveMsg(statusText(clamped, maxAttempts, attemptDates));\n    } else if (clamped !== prevAttempts) {\n      // Defensive: attemptsUsed dropped without a cycleId change. That\n      // shouldn't happen per contract, but resync silently rather than\n      // pretend a lamination came back.\n      topPxRef.current = clamped * segmentH(maxAttempts);\n      if (gripRef.current) {\n        gripRef.current.style.transition = \"none\";\n        gripRef.current.style.transform = \"translate(0px, 0px)\";\n      }\n    }\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [clamped, cycleId, maxAttempts]);\n\n  const remaining = maxAttempts - clamped;\n  const disengaged = clamped >= maxAttempts;\n  const segH = segmentH(maxAttempts);\n  const gripTop = clamped * segH;\n  const gripH = FRAME_H - gripTop;\n\n  return (\n    <div\n      className={`w-full max-w-sm rounded-[12px] border border-border bg-background p-5 ${className}`}\n    >\n      <style>{CSS}</style>\n\n      <div className=\"flex items-start justify-between gap-3\">\n        <div className=\"min-w-0\">\n          <p className=\"truncate text-sm font-medium text-foreground\">{planName}</p>\n          <p id={introId} className=\"mt-1 text-xs text-ns-muted\">\n            {statusText(clamped, maxAttempts, attemptDates)}\n          </p>\n        </div>\n\n        {/* Wear mechanism — purely decorative, aria-hidden. Every fact it\n            encodes is also written as plain text elsewhere on the card. */}\n        <div className=\"flex shrink-0 flex-col items-center gap-1\" aria-hidden=\"true\">\n          <div\n            className=\"relative w-[92px] overflow-hidden rounded-[6px] border border-border bg-background\"\n            style={{ height: FRAME_H }}\n          >\n            {/* Permanent scored lines — one per past failure, fixed position,\n                never moved or removed while this cycle lives. */}\n            {Array.from({ length: clamped }, (_, i) => (\n              <div\n                key={`scar-${i}`}\n                className=\"absolute left-0 right-0 bg-foreground\"\n                style={{ top: (i + 1) * segH - 1, height: 1.5 }}\n              />\n            ))}\n\n            {/* The grip: remaining lining + laminations + the \"active\"/\n                \"paused\" label, all sliding and settling together as one\n                unit — the slip lives on this ref's transform only. */}\n            <div\n              ref={gripRef}\n              className=\"ns-lw-grip absolute left-0 right-0\"\n              style={{ top: gripTop, height: gripH }}\n            >\n              <div className=\"h-full w-full border-t-2 border-t-foreground bg-border/25\">\n                {Array.from({ length: Math.max(0, remaining - 1) }, (_, i) => (\n                  <div\n                    key={`lam-${i}`}\n                    className=\"absolute left-0 right-0 h-px bg-border\"\n                    style={{ top: (i + 1) * segH }}\n                  />\n                ))}\n              </div>\n              <span className=\"absolute left-1.5 top-0.5 font-mono text-[8px] uppercase tracking-wider text-foreground\">\n                {disengaged ? \"Paused\" : \"Active\"}\n              </span>\n            </div>\n          </div>\n\n          {/* Debris ticks — one per failed attempt this cycle, drifting. */}\n          <div className=\"flex h-2.5 items-end gap-[3px]\">\n            {Array.from({ length: clamped }, (_, i) => {\n              const j = hash01(i + 1);\n              return (\n                <span\n                  key={`debris-${i}`}\n                  className=\"block w-[2px] bg-ns-muted\"\n                  style={{\n                    height: 3 + j * 3,\n                    transform: `translateY(${j * 2}px) rotate(${(j - 0.5) * 24}deg)`,\n                  }}\n                />\n              );\n            })}\n          </div>\n\n          {/* Last cycle well — half-visible retired block from the cycle\n              before this one, swapped in only on a cycleId change. */}\n          {lastCycle && (\n            <div\n              className={`ns-lw-well flex items-center gap-1 opacity-40 ${wellEntering ? \"ns-lw-well-enter\" : \"\"}`}\n            >\n              <span className=\"font-mono text-[8px] uppercase tracking-wide text-ns-muted\">\n                last cycle\n              </span>\n              <div className=\"flex gap-[1.5px]\">\n                {Array.from({ length: lastCycle.maxAttempts }, (_, i) => (\n                  <span\n                    key={i}\n                    className={`h-1.5 w-1 ${i < lastCycle.attemptsUsed ? \"bg-foreground\" : \"border border-border\"}`}\n                  />\n                ))}\n              </div>\n            </div>\n          )}\n        </div>\n      </div>\n\n      <p className=\"mt-3 text-xs text-foreground\">\n        {remaining} of {maxAttempts} retry attempts remaining.\n      </p>\n\n      <ol className=\"mt-3 divide-y divide-border border-t border-border\">\n        {attemptDates.slice(0, maxAttempts).map((date, i) => {\n          const state = i < clamped ? \"Failed\" : i === clamped && !disengaged ? \"Scheduled\" : \"Pending\";\n          return (\n            <li key={i} className=\"flex items-center justify-between gap-3 py-1.5 text-xs\">\n              <span className=\"text-foreground\">Attempt {i + 1}</span>\n              <span className=\"font-mono text-ns-muted\">{date}</span>\n              <span className=\"font-mono text-[10px] uppercase tracking-wide text-foreground\">\n                {state}\n              </span>\n            </li>\n          );\n        })}\n      </ol>\n\n      <button\n        type=\"button\"\n        onClick={onUpdatePayment}\n        aria-describedby={introId}\n        className=\"mt-4 w-full rounded-[6px] border border-border bg-background px-3 py-2 text-sm font-medium text-foreground transition-colors duration-150 hover:bg-border/50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ns-accent\"\n      >\n        Update payment method\n      </button>\n\n      {/* Fires once per new failure. Genuinely urgent, so assertive — not\n          the routine-status polite region other indicators in this\n          registry use. */}\n      <span role=\"alert\" aria-live=\"assertive\" aria-atomic=\"true\" className=\"sr-only\">\n        {liveMsg}\n      </span>\n    </div>\n  );\n}\n\nconst CSS = `\n.ns-lw-well{transition:opacity 260ms ease-out, transform 260ms ease-out;}\n.ns-lw-well-enter{opacity:0 !important;transform:translateX(-6px);}\n@media (prefers-reduced-motion: reduce){\n  .ns-lw-grip{transition:none !important;transform:translate(0px,0px) !important;}\n  .ns-lw-well,.ns-lw-well-enter{transition:none !important;transform:none !important;opacity:0.4 !important;}\n}\n`;\n",
      "type": "registry:ui",
      "target": "components/ui/lining-wear.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-ns-accent": "var(--ns-accent)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "ns-accent": "#006bff"
    },
    "dark": {
      "ns-muted": "#8f8f8f"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "billing",
      "subscription",
      "dunning",
      "status",
      "retry",
      "card",
      "aria-live",
      "accessibility"
    ],
    "instruction": "Build the past-due surface for a billing/subscription card as a clutch friction lining wearing down, not a yellow badge. One governing scalar, `lining = attemptsRemaining / maxAttempts` (attemptsRemaining = maxAttempts - attemptsUsed), drives the whole graphic. A 92x64px frame holds a 'grip': the remaining lining pad, height = 64 * lining, filled at var(--border)/25% with a var(--foreground) 2px top edge (the live wear boundary) and internal 1px var(--border) lamination rules every FRAME_H/maxAttempts px, so remaining depth is literally countable at rest by counting stripes. An 'Active'/'Paused' label sits pinned to the grip's top edge. `attemptsUsed` is a controlled prop, monotonic within a cycle (the caller increments it by 1 per failed charge). Each increase is one abrasion event: the whole grip (pad + laminations + label, one ref, one FLIP-style transform) slips sideways by (1 - lining) * 12px, capped at 12px so the label never leaves the card's reading line, then settles back to 0 with a spring whose duration eases from 300ms at lining=1 down to 700ms at lining=0 (a worn clutch grips worse and settles slower) — the SAME settle carries the grip's one-segment drop to its new resting position via the FLIP delta, so the final failure's heavier settle reads as the plate physically disengaging toward 'Paused' rather than a special-cased transition. Simultaneously (plain declarative render, not animated) one permanent scored line appears at var(--foreground) at the exact y where that lamination sheared off — a fixed position nothing later ever redraws, so all of a cycle's scars stay visible stacked above the current, shorter pad — and one debris tick drops into a row below the frame, deterministically jittered in height/rotation/offset (a seeded sine hash, never Math.random, so server and client render identically) so the row reads as drifting sediment, not a bar chart. Wear is strictly monotonic within a cycle: no code path decrements attemptsUsed or removes a scored line/debris tick on its own — the forbidden shape is a health bar that refills on success, because refilling erases the exact datum a past-due customer and support both need ('this card has already failed three times this month'). Recovery is a distinct re-line, triggered only by changing the `cycleId` prop (pass it alongside resetting attemptsUsed to 0): the current scored/debris state is snapshotted into a small 'last cycle' well (a tiny row of filled/outline ticks plus the label 'last cycle', fading in to 40% opacity) and an entirely fresh, unscored pad swaps in with no scored lines of its own. Every fact the graphic carries is ALSO written as real text outside the aria-hidden wrapper: a status paragraph reads exactly 'Payment failed, attempt 2 of 4. Next retry Thu 21 Aug.' (or the active/paused variants) built from `attemptsUsed`/`maxAttempts`/`attemptDates`; a second line spells out 'N of maxAttempts retry attempts remaining'; the retry schedule renders as a real `<ol>` of Attempt N / date / Failed-Scheduled-Pending built from the `attemptDates` array (oldest first); and 'Update payment method' is a real `<button onClick={onUpdatePayment}>` — nothing interactive lives inside the aria-hidden mechanism. Each NEW failure (attemptsUsed increasing) announces exactly once through a dedicated `role=alert aria-live=assertive aria-atomic=true` sr-only span holding the same status sentence — assertive because a failed charge is genuinely urgent, unlike the polite/throttled chatter appropriate to routine autosave or sync indicators. prefers-reduced-motion drops the grip's slip/settle transform entirely (it snaps straight to its resolved position) and disables the last-cycle well's entrance transition, but the lamination count, the scored lines and the debris ticks still decrement/accumulate on the very same render — the wear record is never gated behind motion. Direct-DOM refs carry only the grip's transform (a FLIP two-rAF handoff, matching the ratchet/retry components already in this registry); every other visual — scored lines, laminations, debris, schedule, status text — is plain declarative React keyed off props, no imperative DOM writes needed for those. Zero dependencies, DOM + CSS only, no canvas, no SVG required."
  },
  "type": "registry:ui"
}