{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-02",
  "title": "Notifications by channel",
  "description": "Email, push and desktop as sections, each led by its channel switch that folds its events away, with a digest choice, quiet hours and the same unsaved-changes bar.",
  "dependencies": [
    "@base-ui/react",
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/animated-size.json",
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/motion-word-roll.json",
    "https://ui.ndekocode.dev/r/select.json",
    "https://ui.ndekocode.dev/r/switch.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/blocks/settings/settings-02/index.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from '@/registry/ndeko/ui/select';\n\nimport { ChannelEvents, Fold, SwappingLine } from './channel-sections';\nimport {\n  CHANNELS,\n  DELIVERIES,\n  DELIVERY_LINE,\n  INITIAL_NOTIFICATIONS,\n  QUIET_TIMES,\n  type Channel,\n  type ChannelId,\n  type Delivery,\n  type NotificationValues,\n  type SwitchKey,\n} from './data';\nimport {\n  ChoiceRow,\n  ErrorPresence,\n  SectionPanel,\n  SectionTabs,\n  SettingsPage,\n  SettingsRow,\n  SettingsSection,\n  SwitchRow,\n  UnsavedBar,\n  describedByOf,\n  hasChangeIn,\n  useSettingsDraft,\n  type NavItem,\n} from './settings-kit';\n\nconst SAME_TIMES_ERROR = 'Pick two different times';\n\nfunction channelOf(channelId: ChannelId): Channel {\n  const channel = CHANNELS.find((candidate) => candidate.id === channelId);\n  if (channel) {\n    return channel;\n  }\n  return CHANNELS[0];\n}\n\nfunction quietErrorOf(values: NotificationValues) {\n  const isSameTime = values.quietFrom === values.quietTo;\n  const isBroken = values.quietHours && isSameTime;\n  if (isBroken) {\n    return SAME_TIMES_ERROR;\n  }\n  return null;\n}\n\nfunction quietLineOf(values: NotificationValues) {\n  if (!values.quietHours) {\n    return 'Push arrives at any hour';\n  }\n  return `Nothing buzzes from ${values.quietFrom} to ${values.quietTo}, mentions included`;\n}\n\nfunction shownErrorOf(isShown: boolean, error: string | null) {\n  if (isShown) {\n    return error;\n  }\n  return null;\n}\n\nfunction saveMessageOf(showsQuietError: boolean) {\n  if (showsQuietError) {\n    return 'Fix the quiet hours to save';\n  }\n  return undefined;\n}\n\ntype TimeSelectProps = {\n  label: string;\n  value: string;\n  describedBy?: string;\n  isInvalid: boolean;\n  onValueChange: (value: string) => void;\n};\n\nfunction TimeSelect({\n  label,\n  value,\n  describedBy,\n  isInvalid,\n  onValueChange,\n}: TimeSelectProps) {\n  function changeValue(nextValue: unknown) {\n    const option = QUIET_TIMES.find(\n      (candidate) => candidate.value === nextValue\n    );\n    if (option) {\n      onValueChange(option.value);\n    }\n  }\n\n  return (\n    <Select items={QUIET_TIMES} value={value} onValueChange={changeValue}>\n      <SelectTrigger\n        aria-label={label}\n        aria-invalid={isInvalid}\n        aria-describedby={describedBy}\n        className='w-24 tabular-nums'\n      >\n        <SelectValue />\n      </SelectTrigger>\n      <SelectContent align='end'>\n        {QUIET_TIMES.map((time) => (\n          <SelectItem key={time.value} value={time.value}>\n            {time.label}\n          </SelectItem>\n        ))}\n      </SelectContent>\n    </Select>\n  );\n}\n\nexport default function Settings02() {\n  const settings = useSettingsDraft<NotificationValues>(INITIAL_NOTIFICATIONS);\n  const [channelId, setChannelId] = useState<ChannelId>('email');\n  const [hasSwitched, setHasSwitched] = useState(false);\n  const [isQuietErrorShown, setIsQuietErrorShown] = useState(false);\n  const quietErrorId = useId();\n  const draft = settings.draft;\n  const email = channelOf('email');\n  const push = channelOf('push');\n  const desktop = channelOf('desktop');\n  const quietError = quietErrorOf(draft);\n  const hasQuietError = Boolean(quietError);\n  const showsQuietError = isQuietErrorShown && hasQuietError;\n  const shownQuietError = shownErrorOf(showsQuietError, quietError);\n  const quietDescribedBy = describedByOf(showsQuietError, quietErrorId);\n  const quietLine = quietLineOf(draft);\n  const showsQuietTimes = draft.quietHours && draft.pushOn;\n  const deliveryLine = DELIVERY_LINE[draft.emailDelivery];\n  const saveMessage = saveMessageOf(showsQuietError);\n  const navItems: NavItem<ChannelId>[] = CHANNELS.map((channel) => ({\n    id: channel.id,\n    label: channel.label,\n    icon: channel.icon,\n    hasChanges: hasChangeIn(settings.changedKeys, channel.keys),\n  }));\n\n  function openChannel(nextChannelId: ChannelId) {\n    setChannelId(nextChannelId);\n    setHasSwitched(true);\n  }\n\n  function switchValue(key: SwitchKey, checked: boolean) {\n    settings.change(key, checked);\n  }\n\n  function changeDelivery(delivery: Delivery) {\n    settings.change('emailDelivery', delivery);\n  }\n\n  function changeQuietHours(checked: boolean) {\n    settings.change('quietHours', checked);\n    setIsQuietErrorShown(false);\n  }\n\n  function changeQuietFrom(time: string) {\n    settings.change('quietFrom', time);\n    setIsQuietErrorShown(false);\n  }\n\n  function changeQuietTo(time: string) {\n    settings.change('quietTo', time);\n    setIsQuietErrorShown(false);\n  }\n\n  function changeSound(checked: boolean) {\n    settings.change('desktopSound', checked);\n  }\n\n  function changePreview(checked: boolean) {\n    settings.change('desktopPreview', checked);\n  }\n\n  function save() {\n    if (hasQuietError) {\n      setIsQuietErrorShown(true);\n      openChannel('push');\n      return;\n    }\n    settings.save();\n  }\n\n  function discard() {\n    settings.discard();\n    setIsQuietErrorShown(false);\n  }\n\n  const bar = (\n    <UnsavedBar\n      isShown={settings.isBarShown}\n      status={settings.status}\n      changeCount={settings.changedKeys.length}\n      message={saveMessage}\n      onDiscard={discard}\n      onSave={save}\n    />\n  );\n\n  return (\n    <SettingsPage\n      title='Notifications'\n      line='Choose what reaches you on each channel. Mentions and tasks assigned to you always land in the app inbox.'\n      bar={bar}\n    >\n      <SectionTabs\n        label='Channels'\n        items={navItems}\n        value={channelId}\n        onValueChange={openChannel}\n      >\n        <SectionPanel value='email' animatesIn={hasSwitched}>\n          <ChannelEvents\n            channel={email}\n            values={draft}\n            onSwitch={switchValue}\n          />\n          <SettingsSection\n            title='Delivery'\n            line='Group emails so your inbox stays readable'\n          >\n            <ChoiceRow\n              label='Send emails'\n              line={<SwappingLine text={deliveryLine} />}\n              value={draft.emailDelivery}\n              options={DELIVERIES}\n              disabled={!draft.emailOn}\n              onValueChange={changeDelivery}\n            />\n          </SettingsSection>\n        </SectionPanel>\n        <SectionPanel value='push' animatesIn={hasSwitched}>\n          <ChannelEvents channel={push} values={draft} onSwitch={switchValue} />\n          <SettingsSection\n            title='Quiet hours'\n            line='Your phone stays silent at night, in your time zone'\n          >\n            <div>\n              <SwitchRow\n                label='Quiet hours'\n                line={<SwappingLine text={quietLine} />}\n                checked={draft.quietHours}\n                disabled={!draft.pushOn}\n                onCheckedChange={changeQuietHours}\n              />\n              <Fold isOpen={showsQuietTimes}>\n                <SettingsRow\n                  label='Silent between'\n                  line='Push waits and arrives together when it ends'\n                >\n                  <div className='flex items-center gap-2'>\n                    <TimeSelect\n                      label='Quiet hours start'\n                      value={draft.quietFrom}\n                      describedBy={quietDescribedBy}\n                      isInvalid={showsQuietError}\n                      onValueChange={changeQuietFrom}\n                    />\n                    <span className='text-muted-foreground text-xs'>and</span>\n                    <TimeSelect\n                      label='Quiet hours end'\n                      value={draft.quietTo}\n                      describedBy={quietDescribedBy}\n                      isInvalid={showsQuietError}\n                      onValueChange={changeQuietTo}\n                    />\n                  </div>\n                  <ErrorPresence id={quietErrorId} error={shownQuietError} />\n                </SettingsRow>\n              </Fold>\n            </div>\n          </SettingsSection>\n        </SectionPanel>\n        <SectionPanel value='desktop' animatesIn={hasSwitched}>\n          <ChannelEvents\n            channel={desktop}\n            values={draft}\n            onSwitch={switchValue}\n          />\n          <SettingsSection\n            title='On screen'\n            line='How a desktop notification looks and sounds'\n          >\n            <SwitchRow\n              label='Play a sound'\n              line='A short chime, at most once a minute'\n              checked={draft.desktopSound}\n              disabled={!draft.desktopOn}\n              onCheckedChange={changeSound}\n            />\n            <SwitchRow\n              label='Show the message'\n              line='Off shows only who wrote and on which task'\n              checked={draft.desktopPreview}\n              disabled={!draft.desktopOn}\n              onCheckedChange={changePreview}\n            />\n          </SettingsSection>\n        </SectionPanel>\n      </SectionTabs>\n    </SettingsPage>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/settings-02/index.tsx"
    },
    {
      "path": "registry/ndeko/blocks/settings/settings-02/channel-sections.tsx",
      "content": "'use client';\n\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useId } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\n\nimport type { Channel, NotificationValues, SwitchKey } from './data';\nimport { SETTINGS_SURFACE_BASE, SwitchRow } from './settings-kit';\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst LINE_VARIANTS: Variants = {\n  enter: { opacity: 0, y: 4 },\n  visible: { opacity: 1, y: 0 },\n  exit: { opacity: 0, y: -4 },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nfunction lineVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return LINE_VARIANTS;\n}\n\n/** A row line that swaps with the value it describes. */\nexport function SwappingLine({ text }: { text: string }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = lineVariantsOf(shouldReduceMotion);\n\n  return (\n    <span className='relative block'>\n      <AnimatePresence mode='popLayout' initial={false}>\n        <motion.span\n          key={text}\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          transition={SWAP_TRANSITION}\n          className='block'\n        >\n          {text}\n        </motion.span>\n      </AnimatePresence>\n    </span>\n  );\n}\n\ntype FoldProps = {\n  isOpen: boolean;\n  children: React.ReactNode;\n};\n\n/** Rows that fold into the row above them. The surface resizes, the rows below stay put. */\nexport function Fold({ isOpen, children }: FoldProps) {\n  return (\n    <AnimatedSize className='m-0' contentClassName='p-0'>\n      {isOpen && (\n        <div className='hairline-t border-border hairline-divide-y divide-border'>\n          {children}\n        </div>\n      )}\n    </AnimatedSize>\n  );\n}\n\ntype ChannelEventsProps = {\n  channel: Channel;\n  values: NotificationValues;\n  onSwitch: (key: SwitchKey, checked: boolean) => void;\n};\n\n/** The channel switch heads its own list; turning it off folds the events away. */\nexport function ChannelEvents({\n  channel,\n  values,\n  onSwitch,\n}: ChannelEventsProps) {\n  const headingId = useId();\n  const isOn = values[channel.masterKey];\n  const masterLine = masterLineOf(channel, isOn);\n\n  function switchMaster(checked: boolean) {\n    onSwitch(channel.masterKey, checked);\n  }\n\n  return (\n    <section aria-labelledby={headingId} className='flex flex-col gap-3'>\n      <h2 id={headingId} className='text-sm font-medium'>\n        {channel.eventsTitle}\n      </h2>\n      <div className={SETTINGS_SURFACE_BASE}>\n        <SwitchRow\n          label={channel.masterLabel}\n          line={<SwappingLine text={masterLine} />}\n          checked={isOn}\n          onCheckedChange={switchMaster}\n        />\n        <Fold isOpen={isOn}>\n          {channel.events.map((event) => {\n            function switchEvent(checked: boolean) {\n              onSwitch(event.key, checked);\n            }\n\n            return (\n              <SwitchRow\n                key={event.key}\n                label={event.label}\n                line={event.line}\n                checked={values[event.key]}\n                onCheckedChange={switchEvent}\n              />\n            );\n          })}\n        </Fold>\n      </div>\n    </section>\n  );\n}\n\nfunction masterLineOf(channel: Channel, isOn: boolean) {\n  if (isOn) {\n    return channel.masterLine;\n  }\n  return channel.offLine;\n}\n",
      "type": "registry:component",
      "target": "components/blocks/settings-02/channel-sections.tsx"
    },
    {
      "path": "registry/ndeko/blocks/settings/settings-02/settings-kit.tsx",
      "content": "'use client';\n\nimport { Radio as RadioPrimitive } from '@base-ui/react/radio';\nimport { RadioGroup as RadioGroupPrimitive } from '@base-ui/react/radio-group';\nimport { Tabs as TabsPrimitive } from '@base-ui/react/tabs';\nimport {\n  AnimatePresence,\n  motion,\n  type Transition,\n  type Variants,\n} from 'motion/react';\nimport { useEffect, useId, useState } from 'react';\n\nimport { WordRoll } from '@/components/core/word-roll';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport {\n  CheckIcon,\n  LoaderCircleIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\nimport { AnimatedSize } from '@/registry/ndeko/ui/animated-size';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input, type InputProps } from '@/registry/ndeko/ui/input';\nimport {\n  Select,\n  SelectContent,\n  SelectItem,\n  SelectTrigger,\n  SelectValue,\n} from '@/registry/ndeko/ui/select';\nimport { Switch } from '@/registry/ndeko/ui/switch';\n\nexport const SETTINGS_SURFACE_BASE =\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\nexport const SETTINGS_SURFACE = `${SETTINGS_SURFACE_BASE} hairline-divide-y divide-border`;\n\nconst ROW_LABEL = 'text-[13px] font-medium';\n\nconst SAVE_DELAY_MS = 800;\n\nconst SAVED_HOLD_MS = 1100;\n\nconst SWAP_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst THUMB_TRAVEL: Transition = { duration: 0.2, ease: [0.2, 0, 0, 1] };\n\nconst INSTANT: Transition = { duration: 0 };\n\nconst ENTER: Transition = { duration: 0.2, ease: [0.23, 1, 0.32, 1] };\n\nconst LEAVE: Transition = { duration: 0.14, ease: [0.23, 1, 0.32, 1] };\n\nconst SWAP_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst BAR_VARIANTS: Variants = {\n  enter: { opacity: 0, y: 12, scale: 0.98 },\n  visible: { opacity: 1, y: 0, scale: 1, transition: ENTER },\n  exit: { opacity: 0, y: 8, scale: 0.98, transition: LEAVE },\n};\n\nconst PANEL_VARIANTS: Variants = {\n  enter: { opacity: 0, y: 4 },\n  visible: { opacity: 1, y: 0, transition: ENTER },\n};\n\nconst DOT_VARIANTS: Variants = {\n  enter: { opacity: 0, scale: 0.4 },\n  visible: { opacity: 1, scale: 1, transition: ENTER },\n  exit: { opacity: 0, scale: 0.4, transition: LEAVE },\n};\n\nconst ERROR_VARIANTS: Variants = {\n  enter: { height: 0, opacity: 0 },\n  visible: { height: 'auto', opacity: 1, transition: ENTER },\n  exit: { height: 0, opacity: 0, transition: LEAVE },\n};\n\nconst FADE_VARIANTS: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1, transition: ENTER },\n  exit: { opacity: 0, transition: LEAVE },\n};\n\nfunction swapVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return SWAP_VARIANTS;\n}\n\nfunction barVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return BAR_VARIANTS;\n}\n\nfunction panelVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return PANEL_VARIANTS;\n}\n\nfunction errorVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return ERROR_VARIANTS;\n}\n\nexport function describedByOf(hasError: boolean, errorId: string) {\n  if (hasError) {\n    return errorId;\n  }\n  return undefined;\n}\n\nfunction thumbTravelOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return THUMB_TRAVEL;\n}\n\nfunction dotVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_VARIANTS;\n  }\n  return DOT_VARIANTS;\n}\n\nexport type SaveStatus = 'idle' | 'saving' | 'saved';\n\ntype SettingsValues = Record<string, unknown>;\n\nfunction changedKeysOf<Values extends SettingsValues>(\n  saved: Values,\n  draft: Values\n) {\n  const keys = Object.keys(saved);\n  return keys.filter((key) => !Object.is(saved[key], draft[key]));\n}\n\n/** An edit made while Saved is still showing starts a new round of changes. */\nfunction statusAfterEditOf(current: SaveStatus): SaveStatus {\n  if (current === 'saved') {\n    return 'idle';\n  }\n  return current;\n}\n\n/**\n * Keeps the saved values and the draft apart. Saving stands in for a request with a fixed\n * delay, then holds the Saved state long enough to be read.\n */\nexport function useSettingsDraft<Values extends SettingsValues>(\n  initialValues: Values\n) {\n  const [savedValues, setSavedValues] = useState(initialValues);\n  const [draft, setDraft] = useState(initialValues);\n  const [pending, setPending] = useState<Values | null>(null);\n  const [status, setStatus] = useState<SaveStatus>('idle');\n  const changedKeys = changedKeysOf(savedValues, draft);\n  const hasChanges = changedKeys.length > 0;\n  const isSettled = status === 'idle';\n  const isBarShown = hasChanges || !isSettled;\n\n  useEffect(() => {\n    if (status !== 'saving') {\n      return;\n    }\n    const timer = window.setTimeout(() => {\n      if (pending) {\n        setSavedValues(pending);\n      }\n      setStatus('saved');\n    }, SAVE_DELAY_MS);\n    return () => window.clearTimeout(timer);\n  }, [status, pending]);\n\n  useEffect(() => {\n    if (status !== 'saved') {\n      return;\n    }\n    const timer = window.setTimeout(() => setStatus('idle'), SAVED_HOLD_MS);\n    return () => window.clearTimeout(timer);\n  }, [status]);\n\n  function change<Key extends keyof Values>(key: Key, value: Values[Key]) {\n    setDraft((previous) => ({ ...previous, [key]: value }));\n    setStatus(statusAfterEditOf);\n  }\n\n  function discard() {\n    setDraft(savedValues);\n  }\n\n  function save() {\n    if (status === 'saving') {\n      return;\n    }\n    setPending(draft);\n    setStatus('saving');\n  }\n\n  return {\n    savedValues,\n    draft,\n    changedKeys,\n    status,\n    isBarShown,\n    change,\n    discard,\n    save,\n  };\n}\n\nexport function hasChangeIn(changedKeys: string[], sectionKeys: string[]) {\n  return sectionKeys.some((key) => changedKeys.includes(key));\n}\n\ntype SettingsPageProps = {\n  title: string;\n  line: string;\n  bar: React.ReactNode;\n  children: React.ReactNode;\n};\n\nexport function SettingsPage({\n  title,\n  line,\n  bar,\n  children,\n}: SettingsPageProps) {\n  return (\n    <div className='bg-background text-foreground flex min-h-dvh w-full flex-col'>\n      <div className='mx-auto flex w-full max-w-4xl flex-1 flex-col gap-6 px-4 py-8 md:gap-8 md:px-6 md:py-10'>\n        <header className='flex flex-col gap-1'>\n          <h1 className='text-2xl font-semibold text-balance sm:text-3xl'>\n            {title}\n          </h1>\n          <p className='text-muted-foreground text-[13px] text-pretty'>\n            {line}\n          </p>\n        </header>\n        {children}\n      </div>\n      {bar}\n    </div>\n  );\n}\n\nexport type NavItem<Id extends string> = {\n  id: Id;\n  label: string;\n  icon: Icon;\n  hasChanges: boolean;\n};\n\nfunction UnsavedDot({ isShown }: { isShown: boolean }) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = dotVariantsOf(shouldReduceMotion);\n\n  return (\n    <AnimatePresence initial={false}>\n      {isShown && (\n        <motion.span\n          key='dot'\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          className='bg-primary ml-auto size-1.5 shrink-0 rounded-full'\n        >\n          <span className='sr-only'>Unsaved changes</span>\n        </motion.span>\n      )}\n    </AnimatePresence>\n  );\n}\n\ntype SectionTabsProps<Id extends string> = {\n  label: string;\n  items: NavItem<Id>[];\n  value: Id;\n  onValueChange: (id: Id) => void;\n  children: React.ReactNode;\n};\n\n/** Sections as tabs: a rail beside the column on wide screens, a row above it on phones. One highlight travels between them. */\nexport function SectionTabs<Id extends string>({\n  label,\n  items,\n  value,\n  onValueChange,\n  children,\n}: SectionTabsProps<Id>) {\n  function changeValue(nextValue: unknown) {\n    const item = items.find((candidate) => candidate.id === nextValue);\n    if (item) {\n      onValueChange(item.id);\n    }\n  }\n\n  return (\n    <TabsPrimitive.Root\n      value={value}\n      onValueChange={changeValue}\n      orientation='vertical'\n      className='flex flex-col gap-6 md:grid md:grid-cols-[11rem_minmax(0,42rem)] md:items-start md:gap-10'\n    >\n      <TabsPrimitive.List\n        aria-label={label}\n        className='relative -mx-4 flex gap-1 overflow-x-auto px-4 md:sticky md:top-10 md:mx-0 md:flex-col md:overflow-visible md:px-0'\n      >\n        {items.map((item) => {\n          const ItemIcon = item.icon;\n\n          return (\n            <TabsPrimitive.Tab\n              key={item.id}\n              value={item.id}\n              className='text-muted-foreground hover:text-foreground data-active:text-foreground focus-visible:ring-ring/25 relative z-10 flex h-8 shrink-0 cursor-pointer items-center gap-2 rounded-md px-2.5 text-left text-[13px] font-medium whitespace-nowrap transition-colors duration-150 outline-none focus-visible:ring-[3px] [&_svg]:size-4 [&_svg]:shrink-0'\n            >\n              <ItemIcon />\n              {item.label}\n              <UnsavedDot isShown={item.hasChanges} />\n            </TabsPrimitive.Tab>\n          );\n        })}\n        <TabsPrimitive.Indicator className='bg-foreground/[0.06] pointer-events-none absolute top-0 left-0 h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top) rounded-md transition-[translate,width,height] duration-[250ms] ease-(--ease-in-out-strong)' />\n      </TabsPrimitive.List>\n      {children}\n    </TabsPrimitive.Root>\n  );\n}\n\ntype SectionPanelProps = {\n  value: string;\n  /** False on the section shown at first, so nothing moves on load. */\n  animatesIn: boolean;\n  children: React.ReactNode;\n};\n\nfunction panelInitialOf(animatesIn: boolean) {\n  if (animatesIn) {\n    return 'enter';\n  }\n  return false;\n}\n\nexport function SectionPanel({\n  value,\n  animatesIn,\n  children,\n}: SectionPanelProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = panelVariantsOf(shouldReduceMotion);\n  const initial = panelInitialOf(animatesIn);\n\n  return (\n    <TabsPrimitive.Panel\n      value={value}\n      className='focus-visible:ring-ring/25 rounded-xl outline-none focus-visible:ring-[3px]'\n    >\n      <motion.div\n        variants={variants}\n        initial={initial}\n        animate='visible'\n        className='flex flex-col gap-8'\n      >\n        {children}\n      </motion.div>\n    </TabsPrimitive.Panel>\n  );\n}\n\ntype SettingsSectionProps = {\n  title: string;\n  line?: string;\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 items-end justify-between gap-3'>\n        <div className='flex flex-col gap-0.5'>\n          <h2 id={headingId} className='text-sm font-medium'>\n            {title}\n          </h2>\n          {line && <p className='text-muted-foreground text-xs'>{line}</p>}\n        </div>\n        {action}\n      </div>\n      <div className={SETTINGS_SURFACE}>{children}</div>\n    </section>\n  );\n}\n\ntype SettingsRowProps = {\n  label: string;\n  line: React.ReactNode;\n  labelId?: string;\n  lineId?: string;\n  htmlFor?: string;\n  children: React.ReactNode;\n};\n\nexport function SettingsRow({\n  label,\n  line,\n  labelId,\n  lineId,\n  htmlFor,\n  children,\n}: SettingsRowProps) {\n  return (\n    <div className='flex min-h-14 flex-col gap-3 px-4 py-3 sm:flex-row sm:items-center sm:justify-between sm:gap-6'>\n      <div className='flex min-w-0 flex-col gap-0.5'>\n        {htmlFor && (\n          <label id={labelId} htmlFor={htmlFor} className={ROW_LABEL}>\n            {label}\n          </label>\n        )}\n        {!htmlFor && (\n          <p id={labelId} className={ROW_LABEL}>\n            {label}\n          </p>\n        )}\n        <p id={lineId} className='text-muted-foreground text-xs'>\n          {line}\n        </p>\n      </div>\n      <div className='flex shrink-0 flex-col sm:items-end'>{children}</div>\n    </div>\n  );\n}\n\nfunction saveLabelOf(status: SaveStatus) {\n  if (status === 'saving') {\n    return 'Saving';\n  }\n  if (status === 'saved') {\n    return 'Saved';\n  }\n  return 'Save changes';\n}\n\nfunction saveGlyphOf(status: SaveStatus) {\n  if (status === 'saving') {\n    return {\n      key: 'saving',\n      icon: <LoaderCircleIcon className='animate-spin' />,\n    };\n  }\n  if (status === 'saved') {\n    return { key: 'saved', icon: <CheckIcon /> };\n  }\n  return null;\n}\n\ntype SaveButtonProps = {\n  status: SaveStatus;\n  onSave: () => void;\n};\n\n/** The label becomes its next state and the pill resizes to it: Save changes, Saving, Saved. */\nfunction SaveButton({ status, onSave }: SaveButtonProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = swapVariantsOf(shouldReduceMotion);\n  const label = saveLabelOf(status);\n  const glyph = saveGlyphOf(status);\n  const isBusy = status !== 'idle';\n\n  return (\n    <Button\n      size='sm'\n      disabled={isBusy}\n      focusableWhenDisabled\n      onClick={onSave}\n      className='data-disabled:opacity-100'\n    >\n      <AnimatedSize\n        as='span'\n        axis='width'\n        contentClassName='relative flex items-center gap-1.5'\n      >\n        <AnimatePresence mode='popLayout' initial={false}>\n          {glyph && (\n            <motion.span\n              key={glyph.key}\n              variants={variants}\n              initial='enter'\n              animate='visible'\n              exit='exit'\n              transition={SWAP_TRANSITION}\n              className='flex'\n            >\n              {glyph.icon}\n            </motion.span>\n          )}\n        </AnimatePresence>\n        <AnimatePresence mode='popLayout' initial={false}>\n          <motion.span\n            key={label}\n            variants={variants}\n            initial='enter'\n            animate='visible'\n            exit='exit'\n            transition={SWAP_TRANSITION}\n          >\n            {label}\n          </motion.span>\n        </AnimatePresence>\n      </AnimatedSize>\n    </Button>\n  );\n}\n\nfunction changeCountLabelOf(count: number) {\n  if (count === 1) {\n    return '1 unsaved change';\n  }\n  return `${count} unsaved changes`;\n}\n\nfunction barMessageOf(status: SaveStatus, changeCount: number) {\n  if (status === 'saved') {\n    return 'All changes saved';\n  }\n  return changeCountLabelOf(changeCount);\n}\n\ntype UnsavedBarProps = {\n  isShown: boolean;\n  status: SaveStatus;\n  changeCount: number;\n  /** Replaces the count, for example to say what blocks the save. */\n  message?: string;\n  onDiscard: () => void;\n  onSave: () => void;\n};\n\nexport function UnsavedBar({\n  isShown,\n  status,\n  changeCount,\n  message,\n  onDiscard,\n  onSave,\n}: UnsavedBarProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = barVariantsOf(shouldReduceMotion);\n  const defaultText = barMessageOf(status, changeCount);\n  const text = message ?? defaultText;\n  const isBusy = status !== 'idle';\n\n  return (\n    <div className='pointer-events-none sticky bottom-0 z-20 flex justify-center px-4 pb-4'>\n      <AnimatePresence initial={false}>\n        {isShown && (\n          <motion.div\n            key='unsaved-bar'\n            role='region'\n            aria-label='Unsaved changes'\n            variants={variants}\n            initial='enter'\n            animate='visible'\n            exit='exit'\n            className='surface-raised pointer-events-auto flex w-full max-w-md items-center gap-2 rounded-full py-1.5 pr-1.5 pl-4'\n          >\n            <p\n              role='status'\n              className='min-w-0 flex-1 truncate text-[13px] tabular-nums'\n            >\n              <WordRoll text={text} value={changeCount} />\n            </p>\n            <Button\n              variant='ghost'\n              size='sm'\n              disabled={isBusy}\n              onClick={onDiscard}\n            >\n              Discard\n            </Button>\n            <SaveButton status={status} onSave={onSave} />\n          </motion.div>\n        )}\n      </AnimatePresence>\n    </div>\n  );\n}\n\nexport type ChoiceOption<Value extends string> = {\n  value: Value;\n  label: string;\n};\n\ntype SegmentedChoiceProps<Value extends string> = {\n  options: ChoiceOption<Value>[];\n  value: Value;\n  labelledBy?: string;\n  describedBy?: string;\n  disabled?: boolean;\n  onValueChange: (value: Value) => void;\n};\n\n/** A setting with two to four values as one segmented radio group. The thumb slides to the picked value. */\nexport function SegmentedChoice<Value extends string>({\n  options,\n  value,\n  labelledBy,\n  describedBy,\n  disabled,\n  onValueChange,\n}: SegmentedChoiceProps<Value>) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const travel = thumbTravelOf(shouldReduceMotion);\n  const thumbId = useId();\n\n  function changeValue(nextValue: unknown) {\n    const option = options.find((candidate) => candidate.value === nextValue);\n    if (option) {\n      onValueChange(option.value);\n    }\n  }\n\n  return (\n    <RadioGroupPrimitive\n      value={value}\n      onValueChange={changeValue}\n      disabled={disabled}\n      aria-labelledby={labelledBy}\n      aria-describedby={describedBy}\n      className='bg-foreground/[0.05] inline-flex w-fit items-center gap-0.5 rounded-lg p-0.5 data-disabled:opacity-50'\n    >\n      {options.map((option) => {\n        const isPicked = option.value === value;\n\n        return (\n          <RadioPrimitive.Root\n            key={option.value}\n            value={option.value}\n            className='text-muted-foreground hover:text-foreground data-checked:text-foreground focus-visible:ring-ring/25 relative inline-flex h-7 cursor-pointer items-center justify-center rounded-md px-3 text-[13px] font-medium whitespace-nowrap transition-colors duration-150 outline-none focus-visible:ring-[3px] data-disabled:cursor-not-allowed'\n          >\n            {isPicked && (\n              <motion.span\n                aria-hidden='true'\n                layoutId={thumbId}\n                transition={travel}\n                className='bg-card hairline-ring ring-foreground/10 dark:bg-foreground/[0.09] absolute inset-0 rounded-md shadow-[0_1px_2px_rgb(0_0_0/0.08)]'\n              />\n            )}\n            <span className='relative'>{option.label}</span>\n          </RadioPrimitive.Root>\n        );\n      })}\n    </RadioGroupPrimitive>\n  );\n}\n\ntype ErrorPresenceProps = {\n  id: string;\n  error?: string | null;\n};\n\n/** A field error that grows in under its control and folds away once the person types again. */\nexport function ErrorPresence({ id, error }: ErrorPresenceProps) {\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const variants = errorVariantsOf(shouldReduceMotion);\n\n  return (\n    <AnimatePresence initial={false}>\n      {error && (\n        <motion.p\n          key='error'\n          id={id}\n          variants={variants}\n          initial='enter'\n          animate='visible'\n          exit='exit'\n          className='text-destructive-ink overflow-hidden text-xs sm:max-w-64 sm:text-right'\n        >\n          <span className='block pt-1.5'>{error}</span>\n        </motion.p>\n      )}\n    </AnimatePresence>\n  );\n}\n\ntype TextRowProps = Pick<\n  InputProps,\n  'type' | 'autoComplete' | 'inputMode' | 'placeholder' | 'maxLength'\n> & {\n  label: string;\n  line: string;\n  value: string;\n  error?: string;\n  inputId?: string;\n  onValueChange: (value: string) => void;\n};\n\nexport function TextRow({\n  label,\n  line,\n  value,\n  error,\n  inputId,\n  onValueChange,\n  ...inputProps\n}: TextRowProps) {\n  const generatedId = useId();\n  const errorId = useId();\n  const id = inputId ?? generatedId;\n  const hasError = Boolean(error);\n  const describedBy = describedByOf(hasError, errorId);\n\n  function changeValue(event: React.ChangeEvent<HTMLInputElement>) {\n    onValueChange(event.target.value);\n  }\n\n  return (\n    <SettingsRow label={label} line={line} htmlFor={id}>\n      <Input\n        id={id}\n        value={value}\n        aria-invalid={hasError}\n        aria-describedby={describedBy}\n        onChange={changeValue}\n        className='w-full sm:w-64'\n        {...inputProps}\n      />\n      <ErrorPresence id={errorId} error={error} />\n    </SettingsRow>\n  );\n}\n\ntype SwitchRowProps = {\n  label: string;\n  line: React.ReactNode;\n  checked: boolean;\n  disabled?: boolean;\n  onCheckedChange: (checked: boolean) => void;\n};\n\nexport function SwitchRow({\n  label,\n  line,\n  checked,\n  disabled,\n  onCheckedChange,\n}: SwitchRowProps) {\n  const labelId = useId();\n  const lineId = useId();\n\n  return (\n    <SettingsRow label={label} line={line} labelId={labelId} lineId={lineId}>\n      <Switch\n        checked={checked}\n        disabled={disabled}\n        onCheckedChange={onCheckedChange}\n        aria-labelledby={labelId}\n        aria-describedby={lineId}\n      />\n    </SettingsRow>\n  );\n}\n\ntype SelectOption = { value: string; label: string };\n\ntype SelectRowProps = {\n  label: string;\n  line: React.ReactNode;\n  value: string;\n  options: SelectOption[];\n  disabled?: boolean;\n  onValueChange: (value: string) => void;\n};\n\nexport function SelectRow({\n  label,\n  line,\n  value,\n  options,\n  disabled,\n  onValueChange,\n}: SelectRowProps) {\n  const labelId = useId();\n\n  function changeValue(nextValue: unknown) {\n    const option = options.find((candidate) => candidate.value === nextValue);\n    if (option) {\n      onValueChange(option.value);\n    }\n  }\n\n  return (\n    <SettingsRow label={label} line={line} labelId={labelId}>\n      <Select\n        items={options}\n        value={value}\n        disabled={disabled}\n        onValueChange={changeValue}\n      >\n        <SelectTrigger aria-labelledby={labelId} className='w-full sm:w-64'>\n          <SelectValue />\n        </SelectTrigger>\n        <SelectContent align='end'>\n          {options.map((option) => (\n            <SelectItem key={option.value} value={option.value}>\n              {option.label}\n            </SelectItem>\n          ))}\n        </SelectContent>\n      </Select>\n    </SettingsRow>\n  );\n}\n\ntype ChoiceRowProps<Value extends string> = {\n  label: string;\n  line: React.ReactNode;\n  value: Value;\n  options: ChoiceOption<Value>[];\n  disabled?: boolean;\n  onValueChange: (value: Value) => void;\n};\n\nexport function ChoiceRow<Value extends string>({\n  label,\n  line,\n  value,\n  options,\n  disabled,\n  onValueChange,\n}: ChoiceRowProps<Value>) {\n  const labelId = useId();\n  const lineId = useId();\n\n  return (\n    <SettingsRow label={label} line={line} labelId={labelId} lineId={lineId}>\n      <SegmentedChoice\n        options={options}\n        value={value}\n        labelledBy={labelId}\n        describedBy={lineId}\n        disabled={disabled}\n        onValueChange={onValueChange}\n      />\n    </SettingsRow>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/blocks/settings-02/settings-kit.tsx"
    },
    {
      "path": "registry/ndeko/blocks/settings/settings-02/data.ts",
      "content": "import {\n  MailIcon,\n  MonitorIcon,\n  SmartphoneIcon,\n  type Icon,\n} from '@/registry/ndeko/lib/icons';\n\nexport type ChannelId = 'email' | 'push' | 'desktop';\n\nexport type Delivery = 'instant' | 'hourly' | 'daily';\n\nexport type NotificationValues = {\n  emailOn: boolean;\n  emailMentions: boolean;\n  emailAssigned: boolean;\n  emailComments: boolean;\n  emailStatus: boolean;\n  emailDue: boolean;\n  emailWeekly: boolean;\n  emailDelivery: Delivery;\n  pushOn: boolean;\n  pushMentions: boolean;\n  pushAssigned: boolean;\n  pushComments: boolean;\n  pushDue: boolean;\n  quietHours: boolean;\n  quietFrom: string;\n  quietTo: string;\n  desktopOn: boolean;\n  desktopMentions: boolean;\n  desktopAssigned: boolean;\n  desktopComments: boolean;\n  desktopStatus: boolean;\n  desktopSound: boolean;\n  desktopPreview: boolean;\n};\n\nexport type NotificationKey = keyof NotificationValues;\n\nexport type SwitchKey = Exclude<\n  NotificationKey,\n  'emailDelivery' | 'quietFrom' | 'quietTo'\n>;\n\nexport type ChannelEvent = {\n  key: SwitchKey;\n  label: string;\n  line: string;\n};\n\nexport type Channel = {\n  id: ChannelId;\n  label: string;\n  icon: Icon;\n  masterKey: SwitchKey;\n  masterLabel: string;\n  masterLine: string;\n  eventsTitle: string;\n  offLine: string;\n  keys: NotificationKey[];\n  events: ChannelEvent[];\n};\n\nexport const INITIAL_NOTIFICATIONS: NotificationValues = {\n  emailOn: true,\n  emailMentions: true,\n  emailAssigned: true,\n  emailComments: false,\n  emailStatus: false,\n  emailDue: true,\n  emailWeekly: true,\n  emailDelivery: 'hourly',\n  pushOn: true,\n  pushMentions: true,\n  pushAssigned: true,\n  pushComments: true,\n  pushDue: false,\n  quietHours: true,\n  quietFrom: '21:00',\n  quietTo: '08:00',\n  desktopOn: false,\n  desktopMentions: true,\n  desktopAssigned: true,\n  desktopComments: false,\n  desktopStatus: false,\n  desktopSound: false,\n  desktopPreview: true,\n};\n\nexport const CHANNELS: Channel[] = [\n  {\n    id: 'email',\n    label: 'Email',\n    icon: MailIcon,\n    masterKey: 'emailOn',\n    masterLabel: 'Email notifications',\n    masterLine: 'Sent to amara.okafor@tidewell.example',\n    eventsTitle: 'What reaches your inbox',\n    offLine: 'Email is off. Turn it on to choose what reaches your inbox',\n    keys: [\n      'emailOn',\n      'emailMentions',\n      'emailAssigned',\n      'emailComments',\n      'emailStatus',\n      'emailDue',\n      'emailWeekly',\n      'emailDelivery',\n    ],\n    events: [\n      {\n        key: 'emailMentions',\n        label: 'Mentions',\n        line: 'Someone writes @amara in a task or a comment',\n      },\n      {\n        key: 'emailAssigned',\n        label: 'Assigned to you',\n        line: 'A task lands on your list',\n      },\n      {\n        key: 'emailComments',\n        label: 'Comments on your tasks',\n        line: 'Replies on tasks you created or own',\n      },\n      {\n        key: 'emailStatus',\n        label: 'Status changes',\n        line: 'Tasks you follow move to another status',\n      },\n      {\n        key: 'emailDue',\n        label: 'Due date reminders',\n        line: 'The morning a task of yours is due',\n      },\n      {\n        key: 'emailWeekly',\n        label: 'Weekly summary',\n        line: 'Monday morning: your hours and what closed last week',\n      },\n    ],\n  },\n  {\n    id: 'push',\n    label: 'Mobile push',\n    icon: SmartphoneIcon,\n    masterKey: 'pushOn',\n    masterLabel: 'Push notifications',\n    masterLine: 'On the 2 phones signed in to Tidewell',\n    eventsTitle: 'What buzzes your phone',\n    offLine: 'Push is off. Turn it on to choose what reaches your phone',\n    keys: [\n      'pushOn',\n      'pushMentions',\n      'pushAssigned',\n      'pushComments',\n      'pushDue',\n      'quietHours',\n      'quietFrom',\n      'quietTo',\n    ],\n    events: [\n      {\n        key: 'pushMentions',\n        label: 'Mentions',\n        line: 'Someone writes @amara in a task or a comment',\n      },\n      {\n        key: 'pushAssigned',\n        label: 'Assigned to you',\n        line: 'A task lands on your list',\n      },\n      {\n        key: 'pushComments',\n        label: 'Comments on your tasks',\n        line: 'Replies on tasks you created or own',\n      },\n      {\n        key: 'pushDue',\n        label: 'Due date reminders',\n        line: 'An hour before a task of yours is due',\n      },\n    ],\n  },\n  {\n    id: 'desktop',\n    label: 'Desktop',\n    icon: MonitorIcon,\n    masterKey: 'desktopOn',\n    masterLabel: 'Desktop notifications',\n    masterLine: 'In this browser while Tidewell is open',\n    eventsTitle: 'What pops up on screen',\n    offLine: 'Desktop is off. Turn it on to choose what pops up on screen',\n    keys: [\n      'desktopOn',\n      'desktopMentions',\n      'desktopAssigned',\n      'desktopComments',\n      'desktopStatus',\n      'desktopSound',\n      'desktopPreview',\n    ],\n    events: [\n      {\n        key: 'desktopMentions',\n        label: 'Mentions',\n        line: 'Someone writes @amara in a task or a comment',\n      },\n      {\n        key: 'desktopAssigned',\n        label: 'Assigned to you',\n        line: 'A task lands on your list',\n      },\n      {\n        key: 'desktopComments',\n        label: 'Comments on your tasks',\n        line: 'Replies on tasks you created or own',\n      },\n      {\n        key: 'desktopStatus',\n        label: 'Status changes',\n        line: 'Tasks you follow move to another status',\n      },\n    ],\n  },\n];\n\nexport const DELIVERIES: { value: Delivery; label: string }[] = [\n  { value: 'instant', label: 'Instant' },\n  { value: 'hourly', label: 'Hourly' },\n  { value: 'daily', label: 'Daily' },\n];\n\nexport const DELIVERY_LINE: Record<Delivery, string> = {\n  instant: 'One email per notification, as it happens',\n  hourly: 'One email an hour at most, grouping what happened',\n  daily: 'One email at 8:00 with the day before',\n};\n\nexport const QUIET_TIMES = [\n  { value: '18:00', label: '18:00' },\n  { value: '19:00', label: '19:00' },\n  { value: '20:00', label: '20:00' },\n  { value: '21:00', label: '21:00' },\n  { value: '22:00', label: '22:00' },\n  { value: '23:00', label: '23:00' },\n  { value: '06:00', label: '06:00' },\n  { value: '07:00', label: '07:00' },\n  { value: '08:00', label: '08:00' },\n  { value: '09:00', label: '09:00' },\n];\n",
      "type": "registry:component",
      "target": "components/blocks/settings-02/data.ts"
    }
  ],
  "categories": [
    "blocks",
    "settings"
  ],
  "type": "registry:block"
}