{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-06",
  "title": "License keys",
  "description": "A card per product whose key shows again group by group, Copy that turns into a check, seats in use on a meter, and Regenerate behind an in-place warning that the old key stops, after which the key rolls to its new groups while the seats empty and fill again as machines come back.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/badge.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/company-mark.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-duration.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/morph-button.json",
    "https://ui.ndekocode.dev/r/motion-number.json",
    "https://ui.ndekocode.dev/r/motion-presets.json",
    "https://ui.ndekocode.dev/r/replay-button.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/use-session.json",
    "https://ui.ndekocode.dev/r/use-timeouts.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/settings/settings-06/index.tsx",
      "content": "'use client';\n\nimport { useSession } from '@/registry/ndeko/hooks/use-session';\nimport { useTimeouts } from '@/registry/ndeko/hooks/use-timeouts';\nimport { spokenUnless } from '@/registry/ndeko/lib/demonstration';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { ClockGate } from '@/registry/ndeko/ui/live-duration';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\nimport { ReplayButton } from '@/registry/ndeko/ui/replay-button';\n\nimport { WORKSPACE_NAME, type License, type LicenseId } from './data';\nimport { LicenseCard } from './license-card';\nimport {\n  COPIED_MS,\n  INITIAL,\n  keyTextOf,\n  licenseOf,\n  LOOP_AFTER_MS,\n  reducer,\n  REGENERATE_MS,\n  RESTING,\n  RETURN_GAPS_MS,\n  returnsOf,\n  SCRIPT,\n} from './session';\nimport { SettingsFrame, SettingsSection } from './settings-frame';\n\nconst SESSION = {\n  reducer,\n  initial: INITIAL,\n  resting: RESTING,\n  script: SCRIPT,\n  loopAfter: LOOP_AFTER_MS,\n};\n\nexport default function Settings06() {\n  const {\n    ref,\n    isInView,\n    isAutoplaying,\n    state,\n    act,\n    pressed,\n    isFinished,\n    restart,\n  } = useSession(SESSION);\n  const { schedule, clearAll } = useTimeouts();\n  const message = spokenUnless(isAutoplaying, state.spoken);\n  const canReplay = isFinished && !isAutoplaying;\n\n  function focusLater(selector: string) {\n    requestAnimationFrame(() => {\n      const target = ref.current?.querySelector<HTMLElement>(selector);\n      target?.focus();\n    });\n  }\n\n  function reveal(id: LicenseId) {\n    act({ type: 'revealToggled', id });\n  }\n\n  async function copy(license: License) {\n    try {\n      await navigator.clipboard.writeText(keyTextOf(license.groups));\n    } catch {\n      act({ type: 'copyFailed' });\n      return;\n    }\n    act({ type: 'copied', id: license.id });\n    schedule(() => act({ type: 'copyFaded' }), COPIED_MS);\n  }\n\n  function toggleRegenerate(id: LicenseId) {\n    const after = reducer(state, { type: 'regenerateToggled', id });\n    act({ type: 'regenerateToggled', id });\n    if (after.confirmingId === id) {\n      focusLater(`[data-keep-key=\"${id}\"]`);\n    }\n  }\n\n  function keep() {\n    const id = state.confirmingId;\n    act({ type: 'regenerateCancelled' });\n    if (id) {\n      focusLater(`[data-regenerate=\"${id}\"]`);\n    }\n  }\n\n  /** The machines that held the old key come back one after another with the new one. */\n  function bringMachinesBack(id: LicenseId, used: number, round: number) {\n    const returns = returnsOf(used);\n    let wait = 0;\n    returns.forEach((count, index) => {\n      wait += RETURN_GAPS_MS[index];\n      schedule(() => act({ type: 'activated', id, used: count, round }), wait);\n    });\n  }\n\n  function confirm(id: LicenseId) {\n    const license = licenseOf(state, id);\n    if (!license) {\n      return;\n    }\n    const round = state.made[id] + 1;\n    act({ type: 'regenerateConfirmed', id });\n    focusLater(`[data-regenerate=\"${id}\"]`);\n    schedule(() => {\n      act({ type: 'regenerated', id });\n      bringMachinesBack(id, license.used, round);\n    }, REGENERATE_MS);\n  }\n\n  /** A key on its way belongs to the round it was asked for in. */\n  function replay() {\n    clearAll();\n    restart();\n  }\n\n  return (\n    <ClockGate isActive={isInView}>\n      <SettingsFrame\n        ref={ref}\n        title='License keys'\n        line={`The keys that unlock the Tidewell apps ${WORKSPACE_NAME} pays for. Show one again whenever you need it.`}\n        aside={\n          <ReplayButton isShown={canReplay} onReplay={replay} label='Replay' />\n        }\n      >\n        <SettingsSection\n          title='Your licenses'\n          line={\n            <span className='flex flex-wrap items-center gap-x-1.5 gap-y-1'>\n              Sample keys with DEMO in them: they unlock nothing\n              <Badge variant='secondary'>Illustrative</Badge>\n            </span>\n          }\n        >\n          <div className='grid items-start gap-4 @3xl:grid-cols-2'>\n            {state.licenses.map((license) => (\n              <LicenseCard\n                key={license.id}\n                license={license}\n                state={state}\n                pressed={pressed}\n                onReveal={reveal}\n                onCopy={copy}\n                onRegenerate={toggleRegenerate}\n                onKeep={keep}\n                onConfirm={confirm}\n              />\n            ))}\n          </div>\n        </SettingsSection>\n        <LiveRegion message={message} />\n      </SettingsFrame>\n    </ClockGate>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/settings-06/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/settings/settings-06/license-card.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { Fragment, useId } from 'react';\n\nimport { MotionNumber } from '@/components/core/motion-number';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  pressedQuietOf,\n  pressedSolidOf,\n} from '@/registry/ndeko/lib/demonstration';\nimport {\n  CheckIcon,\n  CopyIcon,\n  EyeIcon,\n  EyeOffIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { EASE_OUT_STRONG } from '@/registry/ndeko/lib/motion-presets';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Badge } from '@/registry/ndeko/ui/badge';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Fold, Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { CompanyMark } from '@/registry/ndeko/ui/company-mark';\nimport { MorphButton, type MorphState } from '@/registry/ndeko/ui/morph-button';\n\nimport {\n  NEAR_LIMIT_SHARE,\n  type License,\n  type LicenseId,\n  type LicenseStatus,\n} from './data';\nimport { keyTextOf, type LicenseState } from './session';\nimport { SURFACE } from './settings-frame';\n\nconst MASK = '••••';\n\nconst ROLL_STAGGER_S = 0.06;\n\nconst ROLL_IN = { y: '0%', opacity: 1, filter: 'blur(0px)' };\n\nconst ROLL_BELOW = { y: '100%', opacity: 0, filter: 'blur(4px)' };\n\nconst ROLL_ABOVE = { y: '-100%', opacity: 0, filter: 'blur(4px)' };\n\nconst FADE_IN = { opacity: 1 };\n\nconst FADE_OUT = { opacity: 0 };\n\nconst STATUS_VARIANT: Record<LicenseStatus, 'success' | 'warning'> = {\n  active: 'success',\n  expiring: 'warning',\n};\n\nconst REGENERATE_LABELS: Record<MorphState, string> = {\n  idle: 'Regenerate key',\n  busy: 'Regenerating',\n  done: 'Regenerated',\n};\n\ntype Tone = 'calm' | 'near';\n\nconst FILL_TONE: Record<Tone, string> = {\n  calm: 'bg-primary',\n  near: 'bg-warning',\n};\n\nconst NOTE_TONE: Record<Tone, string> = {\n  calm: 'text-muted-foreground',\n  near: 'text-warning-foreground',\n};\n\nfunction rollOf(shouldReduceMotion: boolean, index: number) {\n  const transition: Transition = {\n    duration: 0.28,\n    ease: EASE_OUT_STRONG,\n    delay: index * ROLL_STAGGER_S,\n  };\n  if (shouldReduceMotion) {\n    return { initial: FADE_OUT, animate: FADE_IN, exit: FADE_OUT, transition };\n  }\n  return {\n    initial: ROLL_BELOW,\n    animate: ROLL_IN,\n    exit: ROLL_ABOVE,\n    transition,\n  };\n}\n\n/** The first and the last groups stay readable, so a hidden key can still be told apart. */\nfunction shownGroupOf(\n  group: string,\n  index: number,\n  count: number,\n  isRevealed: boolean\n) {\n  const isEnd = index === 0 || index === count - 1;\n  if (isRevealed || isEnd) {\n    return group;\n  }\n  return MASK;\n}\n\nfunction GroupSlot({ text, index }: { text: string; index: number }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const roll = rollOf(shouldReduceMotion, index);\n\n  return (\n    <span className='relative inline-flex overflow-hidden'>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span key={text} className='inline-block' {...roll}>\n          {text}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\nfunction spokenKeyOf(groups: string[], isRevealed: boolean) {\n  if (isRevealed) {\n    return `Key ${keyTextOf(groups)}`;\n  }\n  const last = groups[groups.length - 1];\n  return `Key hidden, ends with ${last}`;\n}\n\n/** Each group rolls on its own, a beat after the one before: shown, hidden or made anew. */\nfunction KeyText({\n  groups,\n  isRevealed,\n}: {\n  groups: string[];\n  isRevealed: boolean;\n}) {\n  const shown = groups.map((group, index) =>\n    shownGroupOf(group, index, groups.length, isRevealed)\n  );\n\n  return (\n    <span className='flex min-w-0 flex-wrap items-center font-mono text-[13px]'>\n      <span className='sr-only'>{spokenKeyOf(groups, isRevealed)}</span>\n      <span aria-hidden='true' className='flex flex-wrap items-center'>\n        {shown.map((group, index) => (\n          <Fragment key={`group-${index}`}>\n            {index > 0 && (\n              <span className='text-muted-foreground px-0.5'>-</span>\n            )}\n            <GroupSlot text={group} index={index} />\n          </Fragment>\n        ))}\n      </span>\n    </span>\n  );\n}\n\nfunction toneOf(used: number, limit: number): Tone {\n  const share = used / limit;\n  if (share >= NEAR_LIMIT_SHARE) {\n    return 'near';\n  }\n  return 'calm';\n}\n\nfunction countOf(count: number, words: { one: string; many: string }) {\n  if (count === 1) {\n    return `1 ${words.one}`;\n  }\n  return `${count} ${words.many}`;\n}\n\nfunction meterNoteOf(license: License, isFresh: boolean) {\n  const left = license.limit - license.used;\n  const isFull = left <= 0;\n  if (isFresh && license.used === 0) {\n    return `Every ${license.holders.one} signs in again with the new key`;\n  }\n  if (isFull) {\n    return `All ${countOf(license.limit, license.unit)} in use: one more ${license.holders.one} cannot start`;\n  }\n  return `${countOf(left, license.unit)} left`;\n}\n\nfunction SeatMeter({\n  license,\n  isFresh,\n}: {\n  license: License;\n  isFresh: boolean;\n}) {\n  const tone = toneOf(license.used, license.limit);\n  const share = license.used / license.limit;\n  const fillStyle = { transform: `scaleX(${share})` };\n  const note = meterNoteOf(license, isFresh);\n  const label = license.meterLabel;\n  const spokenValue = `${license.used} of ${license.limit} ${license.unit.many} in use`;\n\n  return (\n    <div className='flex flex-col gap-1.5'>\n      <p className='flex items-baseline justify-between gap-3 text-xs'>\n        <span className='text-muted-foreground'>{label}</span>\n        <span className='tabular-nums'>\n          <MotionNumber value={license.used} />\n          <span className='text-muted-foreground'> of {license.limit}</span>\n        </span>\n      </p>\n      <div\n        role='meter'\n        aria-label={label}\n        aria-valuemin={0}\n        aria-valuemax={license.limit}\n        aria-valuenow={license.used}\n        aria-valuetext={spokenValue}\n        className='bg-foreground/10 h-1.5 overflow-hidden rounded-full'\n      >\n        <span\n          style={fillStyle}\n          className={cn(\n            'block h-full origin-left rounded-full transition-[transform,background-color] duration-500 ease-(--ease-out-strong) rtl:origin-right',\n            FILL_TONE[tone]\n          )}\n        />\n      </div>\n      <p className={cn('text-xs text-pretty', NOTE_TONE[tone])}>\n        <Swap swapKey={note}>{note}</Swap>\n      </p>\n    </div>\n  );\n}\n\nfunction holdersLineOf(license: License) {\n  if (license.used === 0) {\n    return `No ${license.holders.one} uses it yet, so none has to sign in again.`;\n  }\n  const holders = countOf(license.used, license.holders);\n  return `The ${holders} using it ask for the new one.`;\n}\n\ntype RegenerateConfirmProps = {\n  license: License;\n  pressed: string | null;\n  onKeep: () => void;\n  onConfirm: (id: LicenseId) => void;\n};\n\nfunction RegenerateConfirm({\n  license,\n  pressed,\n  onKeep,\n  onConfirm,\n}: RegenerateConfirmProps) {\n  const holdersLine = holdersLineOf(license);\n\n  function keepOnEscape(event: React.KeyboardEvent<HTMLDivElement>) {\n    if (event.key !== 'Escape') {\n      return;\n    }\n    event.preventDefault();\n    onKeep();\n  }\n\n  return (\n    <div\n      role='group'\n      aria-label={`Regenerate the key for ${license.product}`}\n      onKeyDown={keepOnEscape}\n      className='bg-destructive/[0.06] flex flex-col gap-3 rounded-lg p-3'\n    >\n      <p className='text-[13px] text-pretty'>\n        <span className='font-medium'>The old key stops working at once.</span>{' '}\n        {holdersLine}\n      </p>\n      <div className='flex flex-wrap justify-end gap-2'>\n        <Button\n          type='button'\n          variant='ghost'\n          size='sm'\n          data-keep-key={license.id}\n          onClick={onKeep}\n        >\n          Keep this key\n        </Button>\n        <Button\n          type='button'\n          variant='destructive'\n          size='sm'\n          onClick={() => onConfirm(license.id)}\n          className={pressedSolidOf(pressed === `confirm-${license.id}`)}\n        >\n          Regenerate key\n        </Button>\n      </div>\n    </div>\n  );\n}\n\nfunction termLineOf(license: License, isFresh: boolean) {\n  if (isFresh) {\n    return 'New key made just now. The old one no longer works';\n  }\n  return `Issued ${license.issuedOn} · ${license.termLine}`;\n}\n\nfunction revealLabelOf(isRevealed: boolean, product: string) {\n  if (isRevealed) {\n    return `Hide the key for ${product}`;\n  }\n  return `Show the key for ${product}`;\n}\n\nfunction copyLabelOf(isCopied: boolean, product: string) {\n  if (isCopied) {\n    return 'Copied';\n  }\n  return `Copy the key for ${product}`;\n}\n\nfunction regenerateStateOf(isRegenerating: boolean): MorphState {\n  if (isRegenerating) {\n    return 'busy';\n  }\n  return 'idle';\n}\n\ntype LicenseCardProps = {\n  license: License;\n  state: LicenseState;\n  pressed: string | null;\n  onReveal: (id: LicenseId) => void;\n  onCopy: (license: License) => void;\n  onRegenerate: (id: LicenseId) => void;\n  onKeep: () => void;\n  onConfirm: (id: LicenseId) => void;\n};\n\nexport function LicenseCard({\n  license,\n  state,\n  pressed,\n  onReveal,\n  onCopy,\n  onRegenerate,\n  onKeep,\n  onConfirm,\n}: LicenseCardProps) {\n  const titleId = useId();\n  const id = license.id;\n  const isRevealed = state.revealedIds.includes(id);\n  const isCopied = state.copiedId === id;\n  const isConfirming = state.confirmingId === id;\n  const isRegenerating = state.regeneratingId === id;\n  const isFresh = state.freshIds.includes(id);\n  const termLine = termLineOf(license, isFresh);\n\n  return (\n    <article\n      aria-labelledby={titleId}\n      className={cn(SURFACE, 'flex flex-col gap-4 p-4 @xl:p-5')}\n    >\n      <header className='flex items-start gap-3'>\n        <CompanyMark seed={license.product} size='lg' />\n        <div className='flex min-w-0 flex-1 flex-col gap-0.5'>\n          <h3 id={titleId} className='text-sm font-medium'>\n            {license.product}\n          </h3>\n          <p className='text-muted-foreground text-xs'>{license.plan}</p>\n        </div>\n        <Badge variant={STATUS_VARIANT[license.status]}>\n          {license.statusLabel}\n        </Badge>\n      </header>\n      <div className='flex flex-col gap-2'>\n        <div className='bg-foreground/[0.04] flex items-center gap-2 rounded-lg py-1 ps-3 pe-1'>\n          <KeyText groups={license.groups} isRevealed={isRevealed} />\n          <span className='ms-auto flex shrink-0 items-center'>\n            <Button\n              type='button'\n              variant='ghost'\n              size='icon-sm'\n              aria-label={revealLabelOf(isRevealed, license.product)}\n              onClick={() => onReveal(id)}\n              className={cn(\n                'text-muted-foreground',\n                pressedQuietOf(pressed === `reveal-${id}`)\n              )}\n            >\n              <Swap swapKey={String(isRevealed)}>\n                {isRevealed && <EyeOffIcon />}\n                {!isRevealed && <EyeIcon />}\n              </Swap>\n            </Button>\n            <Button\n              type='button'\n              variant='ghost'\n              size='icon-sm'\n              aria-label={copyLabelOf(isCopied, license.product)}\n              onClick={() => onCopy(license)}\n              className={cn(\n                'text-muted-foreground',\n                pressedQuietOf(pressed === `copy-${id}`)\n              )}\n            >\n              <Swap swapKey={String(isCopied)}>\n                {isCopied && <CheckIcon />}\n                {!isCopied && <CopyIcon />}\n              </Swap>\n            </Button>\n          </span>\n        </div>\n        <p className='text-muted-foreground flex text-xs'>\n          <Swap swapKey={termLine}>{termLine}</Swap>\n        </p>\n      </div>\n      <SeatMeter license={license} isFresh={isFresh} />\n      <div className='flex flex-col gap-3'>\n        <div className='flex justify-end'>\n          <MorphButton\n            type='button'\n            variant='outline'\n            size='sm'\n            data-regenerate={id}\n            aria-expanded={isConfirming}\n            state={regenerateStateOf(isRegenerating)}\n            labels={REGENERATE_LABELS}\n            onClick={() => onRegenerate(id)}\n            className={pressedQuietOf(pressed === `regenerate-${id}`)}\n          />\n        </div>\n        <Fold open={isConfirming}>\n          <RegenerateConfirm\n            license={license}\n            pressed={pressed}\n            onKeep={onKeep}\n            onConfirm={onConfirm}\n          />\n        </Fold>\n      </div>\n    </article>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/settings-06/license-card.tsx"
    },
    {
      "path": "registry/ndeko/blocks/settings/settings-06/settings-frame.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { rowPresenceOf, SPRING } from '@/registry/ndeko/lib/motion-presets';\n\nexport const SURFACE =\n  'bg-card hairline-ring ring-border rounded-xl shadow-[0_1px_2px_rgb(0_0_0/0.04)] dark:bg-foreground/[0.03]';\n\nconst NUDGE = { initial: { x: 4 }, animate: { x: 0 } };\n\nconst STILL = { initial: false, animate: { x: 0 } };\n\nfunction nudgeOf(shouldReduceMotion: boolean) {\n  if (shouldReduceMotion) {\n    return STILL;\n  }\n  return NUDGE;\n}\n\nexport function describedByOf(hasError: boolean, errorId: string) {\n  if (hasError) {\n    return errorId;\n  }\n  return undefined;\n}\n\ntype SettingsFrameProps = {\n  ref?: React.Ref<HTMLDivElement>;\n  title: string;\n  line: string;\n  /** Sits beside the title: the Replay of the demonstration. */\n  aside?: React.ReactNode;\n  children: React.ReactNode;\n};\n\n/** A settings page that follows its own width: one column, the title above, the sections under it. */\nexport function SettingsFrame({\n  ref,\n  title,\n  line,\n  aside,\n  children,\n}: SettingsFrameProps) {\n  return (\n    <div\n      ref={ref}\n      className='bg-background text-foreground @container min-h-dvh w-full'\n    >\n      <div className='mx-auto flex w-full max-w-3xl flex-col gap-8 px-4 py-8 @2xl:px-6 @2xl:py-10'>\n        <header className='flex flex-wrap items-start gap-x-3 gap-y-2'>\n          <div className='flex min-w-0 flex-1 basis-64 flex-col gap-1'>\n            <h1 className='text-2xl font-semibold text-balance @xl:text-3xl'>\n              {title}\n            </h1>\n            <p className='text-muted-foreground text-[13px] text-pretty'>\n              {line}\n            </p>\n          </div>\n          {aside}\n        </header>\n        {children}\n      </div>\n    </div>\n  );\n}\n\ntype SettingsSectionProps = {\n  title: string;\n  line?: React.ReactNode;\n  action?: React.ReactNode;\n  children: React.ReactNode;\n};\n\nexport function SettingsSection({\n  title,\n  line,\n  action,\n  children,\n}: SettingsSectionProps) {\n  const headingId = useId();\n\n  return (\n    <section aria-labelledby={headingId} className='flex flex-col gap-3'>\n      <div className='flex flex-wrap items-end justify-between gap-x-3 gap-y-2'>\n        <div className='flex min-w-0 flex-col gap-0.5'>\n          <h2 id={headingId} className='text-sm font-medium'>\n            {title}\n          </h2>\n          {line && (\n            <p className='text-muted-foreground text-xs text-pretty'>{line}</p>\n          )}\n        </div>\n        {action}\n      </div>\n      {children}\n    </section>\n  );\n}\n\ntype ErrorLineProps = {\n  /** The field points to it with `aria-describedby` while it shows. */\n  id: string;\n  error: string | null;\n  /** A new refusal of the same entry nudges the line again. */\n  attempts: number;\n};\n\n/** A refusal grows in under its field, nudges 4px, and folds away once the person types again. */\nexport function ErrorLine({ id, error, attempts }: ErrorLineProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const presence = rowPresenceOf(shouldReduceMotion);\n  const nudge = nudgeOf(shouldReduceMotion);\n\n  return (\n    <AnimatePresence initial={false}>\n      {error && (\n        <motion.div key='error' className='overflow-hidden' {...presence}>\n          <motion.p\n            key={attempts}\n            id={id}\n            className='text-destructive-ink pt-0.5 text-xs text-pretty'\n            transition={SPRING}\n            {...nudge}\n          >\n            {error}\n          </motion.p>\n        </motion.div>\n      )}\n    </AnimatePresence>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/settings-06/settings-frame.tsx"
    },
    {
      "path": "registry/ndeko/blocks/settings/settings-06/session.ts",
      "content": "import type { SessionStep } from '@/registry/ndeko/hooks/use-session';\n\nimport { LICENSES, NEXT_KEYS, type License, type LicenseId } from './data';\n\nexport type LicenseState = {\n  licenses: License[];\n  revealedIds: LicenseId[];\n  copiedId: LicenseId | null;\n  /** The license whose Regenerate waits for a confirm, in place under its key. */\n  confirmingId: LicenseId | null;\n  regeneratingId: LicenseId | null;\n  /** Licenses whose key was made since the page loaded: their line says the old key stopped. */\n  freshIds: LicenseId[];\n  /** Keys made per license since the page loaded. A sign-in counted for an older key is ignored. */\n  made: Record<LicenseId, number>;\n  spoken: string;\n};\n\nexport type LicenseAction =\n  | { type: 'revealToggled'; id: LicenseId }\n  | { type: 'copied'; id: LicenseId }\n  | { type: 'copyFaded' }\n  | { type: 'copyFailed' }\n  | { type: 'regenerateToggled'; id: LicenseId }\n  | { type: 'regenerateCancelled' }\n  | { type: 'regenerateConfirmed'; id: LicenseId }\n  | { type: 'regenerated'; id: LicenseId }\n  | { type: 'activated'; id: LicenseId; used: number; round: number };\n\ntype Step = SessionStep<LicenseState, LicenseAction>;\n\n/** How long a new key takes to be issued. */\nexport const REGENERATE_MS = 900;\n\n/** How long Copy shows its check. */\nexport const COPIED_MS = 1600;\n\n/** The waits between the machines that come back with a new key: a third, two thirds, then all. */\nexport const RETURN_GAPS_MS = [1500, 1300, 1200];\n\nexport const INITIAL: LicenseState = {\n  licenses: LICENSES,\n  revealedIds: [],\n  copiedId: null,\n  confirmingId: null,\n  regeneratingId: null,\n  freshIds: [],\n  made: { desktop: 0, server: 0 },\n  spoken: '',\n};\n\nexport function licenseOf(state: LicenseState, id: LicenseId) {\n  return state.licenses.find((license) => license.id === id);\n}\n\nexport function keyTextOf(groups: string[]) {\n  return groups.join('-');\n}\n\nexport function returnsOf(used: number) {\n  const first = Math.ceil(used / 3);\n  const second = Math.ceil((used * 2) / 3);\n  return [first, second, used];\n}\n\nfunction withLicense(\n  state: LicenseState,\n  id: LicenseId,\n  change: Partial<License>\n): LicenseState {\n  const licenses = state.licenses.map((license) => {\n    if (license.id !== id) {\n      return license;\n    }\n    return { ...license, ...change };\n  });\n  return { ...state, licenses };\n}\n\nfunction revealToggled(state: LicenseState, id: LicenseId): LicenseState {\n  const license = licenseOf(state, id);\n  if (!license) {\n    return state;\n  }\n  const isRevealed = state.revealedIds.includes(id);\n  if (isRevealed) {\n    const revealedIds = state.revealedIds.filter((other) => other !== id);\n    return {\n      ...state,\n      revealedIds,\n      spoken: `Key for ${license.product} hidden`,\n    };\n  }\n  const revealedIds = [...state.revealedIds, id];\n  return { ...state, revealedIds, spoken: `Key for ${license.product} shown` };\n}\n\nfunction regenerateToggled(state: LicenseState, id: LicenseId): LicenseState {\n  const isBusy = state.regeneratingId !== null;\n  if (isBusy) {\n    return state;\n  }\n  if (state.confirmingId === id) {\n    return { ...state, confirmingId: null, spoken: '' };\n  }\n  return {\n    ...state,\n    confirmingId: id,\n    spoken: 'The old key stops working once a new one is made. Confirm below',\n  };\n}\n\nfunction regenerateConfirmed(state: LicenseState, id: LicenseId): LicenseState {\n  if (state.confirmingId !== id) {\n    return state;\n  }\n  return {\n    ...state,\n    confirmingId: null,\n    regeneratingId: id,\n    spoken: 'Making a new key',\n  };\n}\n\nfunction nextGroupsOf(id: LicenseId, made: number) {\n  const keys = NEXT_KEYS[id];\n  const index = made % keys.length;\n  return keys[index];\n}\n\nfunction without(ids: LicenseId[], id: LicenseId) {\n  return ids.filter((other) => other !== id);\n}\n\n/** Every machine signs in again with the new key, so the places in use start from none. */\nfunction regenerated(state: LicenseState, id: LicenseId): LicenseState {\n  const license = licenseOf(state, id);\n  const isMaking = state.regeneratingId === id;\n  if (!license || !isMaking) {\n    return state;\n  }\n  const groups = nextGroupsOf(id, state.made[id]);\n  const next = withLicense(state, id, { groups, used: 0 });\n  return {\n    ...next,\n    regeneratingId: null,\n    revealedIds: [...without(state.revealedIds, id), id],\n    freshIds: [...without(state.freshIds, id), id],\n    made: { ...state.made, [id]: state.made[id] + 1 },\n    spoken: `New key for ${license.product}. The old one no longer works`,\n  };\n}\n\nfunction activated(\n  state: LicenseState,\n  id: LicenseId,\n  used: number,\n  round: number\n): LicenseState {\n  const license = licenseOf(state, id);\n  const isCurrentKey = state.made[id] === round;\n  if (!license || !isCurrentKey) {\n    return state;\n  }\n  const capped = Math.min(used, license.limit);\n  return withLicense(state, id, { used: capped });\n}\n\nexport function reducer(\n  state: LicenseState,\n  action: LicenseAction\n): LicenseState {\n  switch (action.type) {\n    case 'revealToggled':\n      return revealToggled(state, action.id);\n    case 'copied':\n      return { ...state, copiedId: action.id, spoken: 'Key copied' };\n    case 'copyFaded':\n      return { ...state, copiedId: null };\n    case 'copyFailed':\n      return {\n        ...state,\n        spoken: 'Copy did not work. Show the key and copy it by hand',\n      };\n    case 'regenerateToggled':\n      return regenerateToggled(state, action.id);\n    case 'regenerateCancelled':\n      return { ...state, confirmingId: null, spoken: 'The key stays as it is' };\n    case 'regenerateConfirmed':\n      return regenerateConfirmed(state, action.id);\n    case 'regenerated':\n      return regenerated(state, action.id);\n    case 'activated':\n      return activated(state, action.id, action.used, action.round);\n  }\n}\n\nconst DESKTOP_USED = licenseOf(INITIAL, 'desktop')?.used ?? 0;\n\nconst DESKTOP_RETURNS = returnsOf(DESKTOP_USED);\n\n/** The key is hidden again while the last machines are still coming back. */\nconst HIDE_AFTER_MS = 600;\n\nfunction desktopReturned(index: number): LicenseAction {\n  const used = DESKTOP_RETURNS[index];\n  return { type: 'activated', id: 'desktop', used, round: 1 };\n}\n\n/**\n * The key is shown and copied, then Regenerate asks first. That is where the page rests under\n * reduced motion: the key in full and the warning that the old one stops.\n */\nconst BEFORE_CONFIRM: Step[] = [\n  {\n    after: 1200,\n    by: 'demo',\n    press: 'reveal-desktop',\n    action: { type: 'revealToggled', id: 'desktop' },\n  },\n  {\n    after: 1300,\n    by: 'demo',\n    press: 'copy-desktop',\n    action: { type: 'copied', id: 'desktop' },\n  },\n  { after: COPIED_MS, action: { type: 'copyFaded' } },\n  {\n    after: 700,\n    by: 'demo',\n    press: 'regenerate-desktop',\n    action: { type: 'regenerateToggled', id: 'desktop' },\n  },\n];\n\nexport const SCRIPT: Step[] = [\n  ...BEFORE_CONFIRM,\n  {\n    after: 1900,\n    by: 'demo',\n    press: 'confirm-desktop',\n    action: { type: 'regenerateConfirmed', id: 'desktop' },\n  },\n  { after: REGENERATE_MS, action: { type: 'regenerated', id: 'desktop' } },\n  { after: RETURN_GAPS_MS[0], action: desktopReturned(0) },\n  { after: RETURN_GAPS_MS[1], action: desktopReturned(1) },\n  {\n    after: HIDE_AFTER_MS,\n    by: 'demo',\n    press: 'reveal-desktop',\n    action: { type: 'revealToggled', id: 'desktop' },\n  },\n  { after: RETURN_GAPS_MS[2] - HIDE_AFTER_MS, action: desktopReturned(2) },\n];\n\nfunction endOf(steps: Step[]) {\n  let state = INITIAL;\n  for (const step of steps) {\n    state = reducer(state, step.action);\n  }\n  return state;\n}\n\nexport const RESTING: LicenseState = { ...endOf(BEFORE_CONFIRM), spoken: '' };\n\nexport const LOOP_AFTER_MS = 3200;\n",
      "type": "registry:component",
      "target": "components/blocks/settings-06/session.ts"
    },
    {
      "path": "registry/ndeko/blocks/settings/settings-06/data.ts",
      "content": "export type LicenseId = 'desktop' | 'server';\n\nexport type LicenseStatus = 'active' | 'expiring';\n\nexport type License = {\n  id: LicenseId;\n  product: string;\n  plan: string;\n  /** The key in groups of four, as it is printed and typed. */\n  groups: string[];\n  issuedOn: string;\n  /** Renews on, or expires on: what happens at the end of the term. */\n  termLine: string;\n  status: LicenseStatus;\n  statusLabel: string;\n  /** What one place in the license is called, and what takes it. */\n  unit: { one: string; many: string };\n  meterLabel: string;\n  holders: { one: string; many: string };\n  used: number;\n  limit: number;\n};\n\nexport const WORKSPACE_NAME = 'Tidewell Studio';\n\n/** A share of places in use from which the meter turns to the warning pair. */\nexport const NEAR_LIMIT_SHARE = 0.8;\n\n/**\n * Sample keys, each with the word DEMO in it: they unlock nothing. A regenerated key takes the\n * next one of its product.\n */\nexport const NEXT_KEYS: Record<LicenseId, string[][]> = {\n  desktop: [\n    ['TWD', '8PLA', 'DEMO', 'W3NC', '5VJE'],\n    ['TWD', 'R2KX', 'DEMO', 'H7QB', '9MTF'],\n  ],\n  server: [\n    ['TWS', 'J4ZE', 'DEMO', 'C8LU', '2PXR'],\n    ['TWS', 'N6WD', 'DEMO', 'K3YA', '7GHS'],\n  ],\n};\n\nexport const LICENSES: License[] = [\n  {\n    id: 'desktop',\n    product: 'Tidewell Desktop',\n    plan: 'Team license, 25 seats',\n    groups: ['TWD', '4K7Q', 'DEMO', '2XM9', 'TW8R'],\n    issuedOn: 'Mar 3, 2026',\n    termLine: 'Renews Mar 3, 2027',\n    status: 'active',\n    statusLabel: 'Active',\n    unit: { one: 'seat', many: 'seats' },\n    meterLabel: 'Seats in use',\n    holders: { one: 'computer', many: 'computers' },\n    used: 18,\n    limit: 25,\n  },\n  {\n    id: 'server',\n    product: 'Tidewell Server',\n    plan: 'Self-hosted, 4 nodes',\n    groups: ['TWS', '9BHT', 'DEMO', '6QNV', 'K4DW'],\n    issuedOn: 'Dec 1, 2025',\n    termLine: 'Expires Dec 1, 2026',\n    status: 'expiring',\n    statusLabel: 'Expires in 19 days',\n    unit: { one: 'node', many: 'nodes' },\n    meterLabel: 'Nodes in use',\n    holders: { one: 'server', many: 'servers' },\n    used: 4,\n    limit: 4,\n  },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/settings-06/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "settings"
  ],
  "type": "registry:block"
}