{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "settings-page",
  "title": "Settings Page",
  "description": "A settings screen in three decisions: one page with one save bar, one section at a time beside a side nav, or each group as its own plate with its own Save.",
  "dependencies": [
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "utils",
    "https://miseui.junsu4621.workers.dev/r/button.json",
    "https://miseui.junsu4621.workers.dev/r/input.json",
    "https://miseui.junsu4621.workers.dev/r/label.json",
    "https://miseui.junsu4621.workers.dev/r/materialize.json",
    "https://miseui.junsu4621.workers.dev/r/select.json",
    "https://miseui.junsu4621.workers.dev/r/switch.json"
  ],
  "files": [
    {
      "path": "registry/miseui/blocks/settings-page.tsx",
      "content": "import { SettingsCardsView } from \"./settings-page-cards\"\nimport type { SettingsSection, SettingsValues, SettingsViewProps } from \"./settings-page-form\"\nimport { SettingsSectionsView } from \"./settings-page-sections\"\nimport { SettingsSidebarView } from \"./settings-page-sidebar\"\n\ntype SettingsPageVariant = \"sections\" | \"sidebar\" | \"cards\"\n\ninterface SettingsPageProps extends SettingsViewProps {\n  /** `sections` one long page with one save bar, `sidebar` one section at a time beside a side nav, `cards` each group its own plate with its own Save. Anything else is `sections`. */\n  variant?: SettingsPageVariant\n}\n\nfunction SettingsPage({ variant, ...props }: SettingsPageProps) {\n  if (variant === \"sidebar\") return <SettingsSidebarView {...props} />\n  if (variant === \"cards\") return <SettingsCardsView {...props} />\n  return <SettingsSectionsView {...props} />\n}\n\nexport { SettingsPage, type SettingsPageProps, type SettingsPageVariant, type SettingsSection, type SettingsValues }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-sections.tsx",
      "content": "import type * as React from \"react\"\nimport { useId, useState } from \"react\"\nimport { useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { Materialize } from \"@/registry/miseui/ui/materialize\"\nimport { useSettingsForm, type SettingsSection, type SettingsViewProps } from \"./settings-page-form\"\nimport { SettingsRowView } from \"./settings-page-parts\"\nimport { SAMPLE_SECTIONS } from \"./settings-page-sample\"\nimport { SaveBar, SOFT_SHADOW_CLASS } from \"./settings-page-savebar\"\n\ninterface SectionNavProps {\n  sections: readonly SettingsSection[]\n  active: string\n  onSelect: (id: string) => void\n}\n\nfunction SectionNav({ sections, active, onSelect }: SectionNavProps) {\n  return (\n    <nav aria-label=\"Settings sections\" className=\"min-w-0 @3xl:sticky @3xl:top-8 @3xl:self-start\">\n      <ul className=\"flex gap-1 overflow-x-auto @3xl:flex-col @3xl:overflow-visible\">\n        {sections.map((section) => (\n          <li key={section.id} className={cn(\"shrink-0\", section.tone === \"danger\" && \"@3xl:mt-4\")}>\n            <button\n              type=\"button\"\n              aria-current={section.id === active ? \"true\" : undefined}\n              onClick={() => onSelect(section.id)}\n              className={cn(\n                \"inline-flex h-9 w-full items-center rounded-md px-3 text-[13px] whitespace-nowrap outline-none\",\n                \"transition-colors duration-(--duration-fast) ease-(--ease-mise)\",\n                \"focus-visible:ring-[3px] focus-visible:ring-inset focus-visible:ring-ring/50\",\n                section.id === active ? \"bg-background dark:bg-card text-foreground shadow-xs\" : \"text-muted-foreground hover:bg-background/60\",\n              )}\n            >\n              {section.title}\n            </button>\n          </li>\n        ))}\n      </ul>\n    </nav>\n  )\n}\n\nfunction SectionBlock({ section, anchorId, children }: { section: SettingsSection; anchorId: string; children: React.ReactNode }) {\n  const danger = section.tone === \"danger\"\n  return (\n    <section id={anchorId} aria-labelledby={`${anchorId}-title`} className={cn(\"flex scroll-mt-8 flex-col gap-4\", danger && \"mt-4 border-t pt-12\")}>\n      {/* Inline, so one tone-split sentence reads as a single thought while the heading stays a real heading. */}\n      <div className=\"text-[15px] leading-relaxed text-pretty\">\n        <h3 id={`${anchorId}-title`} className=\"inline font-medium\">\n          {section.title}\n        </h3>\n        {section.description ? (\n          <>\n            <span aria-hidden=\"true\">. </span>\n            <p className=\"inline text-muted-foreground\">{section.description}</p>\n          </>\n        ) : null}\n      </div>\n      <div className={cn(\"flex flex-col divide-y rounded-2xl border bg-background dark:bg-card\", danger ? \"border-destructive/40\" : SOFT_SHADOW_CLASS)}>{children}</div>\n    </section>\n  )\n}\n\ninterface SectionListProps {\n  sections: readonly SettingsSection[]\n  form: ReturnType<typeof useSettingsForm>\n  fieldId: (id: string) => string\n  anchorId: (id: string) => string\n}\n\nfunction SectionList({ sections, form, fieldId, anchorId }: SectionListProps) {\n  return sections.map((section) => (\n    <SectionBlock key={section.id} section={section} anchorId={anchorId(section.id)}>\n      {section.rows.map((row) => (\n        <SettingsRowView\n          key={row.id}\n          row={row}\n          fieldId={fieldId(row.id)}\n          value={form.values[row.id]}\n          error={form.errors[row.id]}\n          onChange={(value) => form.update(row.id, value)}\n          onBlur={() => form.touch(row.id)}\n        />\n      ))}\n    </SectionBlock>\n  ))\n}\n\nfunction SettingsSectionsView({ title = \"Settings.\", titleQuiet = \"Nothing changes until you save.\", sections = SAMPLE_SECTIONS, onSave, className, ...props }: SettingsViewProps) {\n  const baseId = useId()\n  const reduceMotion = useReducedMotion()\n  const [activeSection, setActiveSection] = useState(sections[0]?.id ?? \"\")\n  const form = useSettingsForm(sections, onSave)\n  const fieldId = (id: string) => `${baseId}-field-${id}`\n  const anchorId = (id: string) => `${baseId}-section-${id}`\n  const errorCount = Object.keys(form.errors).length\n  const barVisible = form.changedIds.length > 0 || form.status === \"saved\" || form.status === \"saving\"\n\n  const goToSection = (id: string) => {\n    setActiveSection(id)\n    document.getElementById(anchorId(id))?.scrollIntoView?.({ behavior: reduceMotion ? \"auto\" : \"smooth\", block: \"start\" })\n  }\n  const save = async () => {\n    const firstInvalid = await form.save()\n    if (firstInvalid) document.getElementById(fieldId(firstInvalid))?.focus()\n  }\n\n  return (\n    <div data-slot=\"settings-page\" data-variant=\"sections\" className={cn(\"@container w-full bg-muted dark:bg-background\", className)} {...props}>\n      <div className=\"mx-auto flex max-w-5xl flex-col gap-8 px-4 py-8 @2xl:gap-12 @2xl:px-8 @2xl:py-12\">\n        <h2 className=\"text-display text-3xl text-balance @2xl:text-4xl\">\n          {title} {titleQuiet ? <span className=\"text-muted-foreground\">{titleQuiet}</span> : null}\n        </h2>\n        <div className=\"grid min-w-0 gap-8 @3xl:grid-cols-[176px_minmax(0,1fr)] @3xl:gap-12\">\n          <SectionNav sections={sections} active={activeSection} onSelect={goToSection} />\n          <div className=\"flex min-w-0 flex-col gap-12\">\n            <SectionList sections={sections} form={form} fieldId={fieldId} anchorId={anchorId} />\n            {/* Stays in the flow and sticks: it never covers the last row, and it follows a long page. */}\n            <Materialize show={barVisible} origin=\"50% 100%\" className=\"sticky bottom-4 z-10\">\n              <SaveBar\n                status={form.status}\n                changedCount={form.changedIds.length}\n                errorCount={errorCount}\n                onDiscard={form.discard}\n                onSave={save}\n              />\n            </Materialize>\n          </div>\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { SettingsSectionsView }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-sidebar.tsx",
      "content": "import { useId, useState } from \"react\"\nimport { flushSync } from \"react-dom\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { Materialize } from \"@/registry/miseui/ui/materialize\"\nimport { useSettingsForm, type SettingsSection, type SettingsViewProps } from \"./settings-page-form\"\nimport { SETTINGS_TOUCH_CLASS, SettingsRowView } from \"./settings-page-parts\"\nimport { SAMPLE_SECTIONS } from \"./settings-page-sample\"\nimport { SaveBar, SOFT_SHADOW_CLASS } from \"./settings-page-savebar\"\n\ninterface SideNavProps {\n  sections: readonly SettingsSection[]\n  active: string\n  changedIds: readonly string[]\n  errorIds: readonly string[]\n  onSelect: (id: string) => void\n}\n\nfunction countIn(section: SettingsSection, ids: readonly string[]) {\n  return section.rows.filter((row) => ids.includes(row.id)).length\n}\n\n/** The count travels with the section, because an edit on a screen that is no longer showing is easy to forget. */\nfunction SideNavItem({ section, active, changed, invalid, onSelect }: { section: SettingsSection; active: boolean; changed: number; invalid: boolean; onSelect: () => void }) {\n  const Icon = section.icon\n  return (\n    <button\n      type=\"button\"\n      aria-current={active ? \"page\" : undefined}\n      aria-label={changed > 0 ? `${section.title}, ${changed} unsaved` : undefined}\n      onClick={onSelect}\n      className={cn(\n        \"inline-flex h-9 w-full items-center gap-3 rounded-md px-3 text-start text-[13px] whitespace-nowrap outline-none pointer-coarse:h-10\",\n        \"transition-colors duration-(--duration-fast) ease-(--ease-mise)\",\n        \"focus-visible:ring-[3px] focus-visible:ring-inset focus-visible:ring-ring/50\",\n        active ? \"bg-background text-foreground shadow-xs dark:bg-card\" : \"text-muted-foreground hover:bg-background/60\",\n      )}\n    >\n      {Icon ? <Icon className=\"size-4 shrink-0\" /> : null}\n      <span className=\"min-w-0 flex-1\">{section.title}</span>\n      {changed > 0 ? (\n        <span className={cn(\"shrink-0 tabular-nums\", invalid ? \"text-destructive\" : \"text-muted-foreground\")}>{changed}</span>\n      ) : null}\n    </button>\n  )\n}\n\nfunction SideNav({ sections, active, changedIds, errorIds, onSelect }: SideNavProps) {\n  return (\n    <nav aria-label=\"Settings sections\" className=\"min-w-0\">\n      {/* A scroller of its own when narrow, so five labels never push the page sideways on a phone. */}\n      <ul className=\"flex gap-1 overflow-x-auto @3xl:flex-col @3xl:overflow-visible\">\n        {sections.map((section) => (\n          <li key={section.id} className={cn(\"shrink-0\", section.tone === \"danger\" && \"@3xl:mt-3 @3xl:border-t @3xl:pt-3\")}>\n            <SideNavItem\n              section={section}\n              active={section.id === active}\n              changed={countIn(section, changedIds)}\n              invalid={countIn(section, errorIds) > 0}\n              onSelect={() => onSelect(section.id)}\n            />\n          </li>\n        ))}\n      </ul>\n    </nav>\n  )\n}\n\nfunction SectionPanel({ section, form, fieldId }: { section: SettingsSection; form: ReturnType<typeof useSettingsForm>; fieldId: (id: string) => string }) {\n  const danger = section.tone === \"danger\"\n  return (\n    <section aria-label={section.title} className=\"flex flex-col gap-6\">\n      <h3 className=\"text-display text-2xl text-balance @2xl:text-3xl\">\n        {section.title}. {section.description ? <span className=\"text-muted-foreground\">{section.description}</span> : null}\n      </h3>\n      <div className={cn(\"flex flex-col divide-y rounded-2xl border bg-background dark:bg-card\", danger ? \"border-destructive/40\" : SOFT_SHADOW_CLASS)}>\n        {section.rows.map((row) => (\n          <SettingsRowView\n            key={row.id}\n            row={row}\n            fieldId={fieldId(row.id)}\n            value={form.values[row.id]}\n            error={form.errors[row.id]}\n            onChange={(value) => form.update(row.id, value)}\n            onBlur={() => form.touch(row.id)}\n          />\n        ))}\n      </div>\n    </section>\n  )\n}\n\nfunction SettingsSidebarView({ title = \"Settings.\", titleQuiet = \"Nothing changes until you save.\", sections = SAMPLE_SECTIONS, onSave, className, ...props }: SettingsViewProps) {\n  const baseId = useId()\n  const [activeId, setActiveId] = useState(sections[0]?.id ?? \"\")\n  const form = useSettingsForm(sections, onSave)\n  const fieldId = (id: string) => `${baseId}-field-${id}`\n  const section = sections.find((item) => item.id === activeId) ?? sections[0]\n  const errorIds = Object.keys(form.errors)\n  const barVisible = form.changedIds.length > 0 || form.status === \"saved\" || form.status === \"saving\"\n\n  const save = async () => {\n    const firstInvalid = await form.save()\n    if (!firstInvalid) return\n    // The problem may sit in a section that is not showing, where nobody would ever find it.\n    // flushSync: the field only exists once that section has rendered, and focus has to land on it now.\n    const home = sections.find((item) => item.rows.some((row) => row.id === firstInvalid))\n    flushSync(() => setActiveId(home?.id ?? activeId))\n    document.getElementById(fieldId(firstInvalid))?.focus()\n  }\n\n  return (\n    <div data-slot=\"settings-page\" data-variant=\"sidebar\" className={cn(\"@container w-full bg-muted dark:bg-background\", SETTINGS_TOUCH_CLASS, className)} {...props}>\n      <div className=\"grid min-h-[640px] grid-cols-[minmax(0,1fr)] grid-rows-[auto_1fr] @3xl:grid-cols-[240px_minmax(0,1fr)] @3xl:grid-rows-1\">\n        <aside className=\"min-w-0 border-b @3xl:border-r @3xl:border-b-0\">\n          <div className=\"flex min-w-0 flex-col gap-4 p-4 @3xl:sticky @3xl:top-0 @3xl:py-8\">\n            <div className=\"flex flex-col gap-1 px-3\">\n              <h2 className=\"text-title text-xl\">{title}</h2>\n              {titleQuiet ? <p className=\"text-[13px] leading-relaxed text-pretty text-muted-foreground\">{titleQuiet}</p> : null}\n            </div>\n            <SideNav sections={sections} active={section?.id ?? \"\"} changedIds={form.changedIds} errorIds={errorIds} onSelect={setActiveId} />\n          </div>\n        </aside>\n        {/* Its own container: the rows inside must answer to this column, not to the width of the whole block. */}\n        <div className=\"@container min-w-0\">\n          <div className=\"flex flex-col gap-8 p-4 @3xl:p-8 @5xl:p-12\">\n            {section ? <SectionPanel key={section.id} section={section} form={form} fieldId={fieldId} /> : null}\n            <Materialize show={barVisible} origin=\"50% 100%\" className=\"sticky bottom-4 z-10\">\n              <SaveBar status={form.status} changedCount={form.changedIds.length} errorCount={errorIds.length} onDiscard={form.discard} onSave={save} />\n            </Materialize>\n          </div>\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { SettingsSidebarView }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-cards.tsx",
      "content": "import { useId, useMemo } from \"react\"\nimport { Check, CircleAlert } from \"lucide-react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport { isEditable, useSettingsForm, type OnSave, type SettingsSection, type SettingsViewProps } from \"./settings-page-form\"\nimport { SETTINGS_TOUCH_CLASS, SettingsRowView } from \"./settings-page-parts\"\nimport { SAMPLE_SECTIONS } from \"./settings-page-sample\"\nimport { saveBarMessage, SOFT_SHADOW_CLASS } from \"./settings-page-savebar\"\n\ninterface CardFooterProps {\n  title: string\n  form: ReturnType<typeof useSettingsForm>\n  onSave: () => void\n}\n\nfunction CardFooter({ title, form, onSave }: CardFooterProps) {\n  const changed = form.changedIds.length > 0\n  const errorCount = Object.keys(form.errors).length\n  const saving = form.status === \"saving\"\n  const problem = form.status === \"failed\" || errorCount > 0\n  const idle = !changed && form.status === \"idle\"\n  const unavailable = !changed || saving\n  return (\n    <div className=\"flex flex-wrap items-center justify-between gap-3 rounded-b-2xl border-t bg-muted/40 p-3 pl-4 @2xl:pl-6 dark:bg-transparent\">\n      <p role=\"status\" className={cn(\"flex items-center gap-2 text-[13px]\", problem ? \"text-destructive\" : \"text-muted-foreground\")}>\n        {form.status === \"saved\" ? <Check aria-hidden=\"true\" className=\"size-4\" /> : null}\n        {problem ? <CircleAlert aria-hidden=\"true\" className=\"size-4\" /> : null}\n        {idle ? \"Up to date\" : saveBarMessage({ status: form.status, changedCount: form.changedIds.length, errorCount })}\n      </p>\n      <div className=\"ml-auto flex gap-2\">\n        {changed && !saving ? (\n          <Button variant=\"ghost\" className=\"pointer-coarse:h-10\" onClick={form.discard}>\n            Discard\n          </Button>\n        ) : null}\n        {/* aria-disabled, not disabled: the button stays in place after a save, and a disabled one would drop keyboard focus. */}\n        <Button\n          variant={changed ? \"mise\" : \"outline\"}\n          aria-label={`Save ${title}`}\n          aria-disabled={unavailable || undefined}\n          effect={saving ? \"shimmer\" : undefined}\n          onClick={unavailable ? undefined : onSave}\n          className={cn(\"pointer-coarse:h-10\", !changed && \"opacity-50 hover:bg-background\")}\n        >\n          {saving ? \"Saving\" : \"Save\"}\n        </Button>\n      </div>\n    </div>\n  )\n}\n\nfunction SettingsCard({ section, onSave }: { section: SettingsSection; onSave?: OnSave }) {\n  const baseId = useId()\n  const single = useMemo(() => [section], [section])\n  const form = useSettingsForm(single, onSave)\n  const fieldId = (id: string) => `${baseId}-field-${id}`\n  const titleId = `${baseId}-title`\n  const danger = section.tone === \"danger\"\n\n  const save = async () => {\n    const firstInvalid = await form.save()\n    if (firstInvalid) document.getElementById(fieldId(firstInvalid))?.focus()\n  }\n\n  return (\n    <section aria-labelledby={titleId} className={cn(\"@container rounded-2xl border bg-background dark:bg-card\", danger ? \"mt-4 border-destructive/40\" : SOFT_SHADOW_CLASS)}>\n      <header className=\"flex flex-col gap-1 p-4 @2xl:px-6 @2xl:pt-6\">\n        <h3 id={titleId} className=\"text-title text-lg\">\n          {section.title}\n        </h3>\n        {section.description ? <p className=\"text-[13px] leading-relaxed text-pretty text-muted-foreground\">{section.description}</p> : null}\n      </header>\n      <div className=\"flex flex-col divide-y border-t\">\n        {section.rows.map((row) => (\n          <SettingsRowView\n            key={row.id}\n            row={row}\n            fieldId={fieldId(row.id)}\n            value={form.values[row.id]}\n            error={form.errors[row.id]}\n            onChange={(value) => form.update(row.id, value)}\n            onBlur={() => form.touch(row.id)}\n          />\n        ))}\n      </div>\n      {/* Read-only and destructive rows act on their own, so a group of only those has nothing to save. */}\n      {section.rows.some(isEditable) ? <CardFooter title={section.title} form={form} onSave={save} /> : null}\n    </section>\n  )\n}\n\nfunction SettingsCardsView({ title = \"Settings.\", titleQuiet = \"Each group saves on its own.\", sections = SAMPLE_SECTIONS, onSave, className, ...props }: SettingsViewProps) {\n  return (\n    <div data-slot=\"settings-page\" data-variant=\"cards\" className={cn(\"@container w-full bg-muted dark:bg-background\", SETTINGS_TOUCH_CLASS, className)} {...props}>\n      <div className=\"mx-auto flex max-w-3xl flex-col gap-8 px-4 py-8 @2xl:gap-12 @2xl:px-8 @2xl:py-12\">\n        <h2 className=\"text-display text-3xl text-balance @2xl:text-4xl\">\n          {title} {titleQuiet ? <span className=\"text-muted-foreground\">{titleQuiet}</span> : null}\n        </h2>\n        <div className=\"flex min-w-0 flex-col gap-6\">\n          {sections.map((section) => (\n            <SettingsCard key={section.id} section={section} onSave={onSave} />\n          ))}\n        </div>\n      </div>\n    </div>\n  )\n}\n\nexport { SettingsCardsView }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-savebar.tsx",
      "content": "import { Check, CircleAlert } from \"lucide-react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport type { SaveStatus } from \"./settings-page-form\"\n\n/** Tinted from the ink, and off in dark mode, where a light-tinted shadow would read as a glow. */\nconst SOFT_SHADOW_CLASS =\n  \"shadow-[0_1px_2px_color-mix(in_oklab,var(--foreground)_6%,transparent),0_16px_32px_-16px_color-mix(in_oklab,var(--foreground)_16%,transparent)] dark:shadow-none\"\n\ninterface SaveBarProps {\n  status: SaveStatus\n  changedCount: number\n  errorCount: number\n  onDiscard: () => void\n  onSave: () => void\n}\n\nfunction saveBarMessage({ status, changedCount, errorCount }: Omit<SaveBarProps, \"onDiscard\" | \"onSave\">) {\n  if (status === \"saved\") return \"Changes saved\"\n  if (status === \"failed\") return \"Could not save. Your changes are still here.\"\n  if (errorCount > 0) return errorCount === 1 ? \"Fix 1 field to save\" : `Fix ${errorCount} fields to save`\n  return changedCount === 1 ? \"1 unsaved change\" : `${changedCount} unsaved changes`\n}\n\nfunction SaveBar({ status, changedCount, errorCount, onDiscard, onSave }: SaveBarProps) {\n  const saving = status === \"saving\"\n  const problem = status === \"failed\" || errorCount > 0\n  return (\n    <div className=\"material flex flex-wrap items-center justify-between gap-3 rounded-2xl border p-3 pl-4 shadow-md\">\n      <p role=\"status\" className={cn(\"flex items-center gap-2 text-[13px]\", problem && \"text-destructive\")}>\n        {status === \"saved\" ? <Check aria-hidden=\"true\" className=\"size-4\" /> : null}\n        {problem ? <CircleAlert aria-hidden=\"true\" className=\"size-4\" /> : null}\n        {saveBarMessage({ status, changedCount, errorCount })}\n      </p>\n      {status === \"saved\" ? null : (\n        <div className=\"ml-auto flex gap-2\">\n          <Button variant=\"ghost\" disabled={saving} onClick={onDiscard}>\n            Discard\n          </Button>\n          <Button variant=\"mise\" disabled={saving} effect={saving ? \"shimmer\" : undefined} onClick={onSave}>\n            {saving ? \"Saving\" : \"Save changes\"}\n          </Button>\n        </div>\n      )}\n    </div>\n  )\n}\n\nexport { SaveBar, saveBarMessage, SOFT_SHADOW_CLASS }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-parts.tsx",
      "content": "import { Button } from \"@/registry/miseui/ui/button\"\nimport { Input } from \"@/registry/miseui/ui/input\"\nimport { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from \"@/registry/miseui/ui/select\"\nimport { Switch } from \"@/registry/miseui/ui/switch\"\nimport { DangerRow } from \"./settings-page-danger\"\nimport { descriptionId, RESPONSIVE_ROW_CLASS, RowText } from \"./settings-page-row-text\"\nimport type {\n  SettingsInfoRow,\n  SettingsRow,\n  SettingsSelectRow,\n  SettingsSwitchRow,\n  SettingsTextRow,\n  SettingsValue,\n} from \"./settings-page-form\"\n\nconst ROW_CLASS = RESPONSIVE_ROW_CLASS\n\n/** The new layouts only: the sections default keeps the sizes people already copied. */\nconst SETTINGS_TOUCH_CLASS = \"pointer-coarse:[&_input]:h-10 pointer-coarse:[&_[data-slot=button]]:h-10 pointer-coarse:[&_[data-slot=select-trigger]]:h-10 pointer-coarse:[&_[data-slot=switch]]:relative pointer-coarse:[&_[data-slot=switch]]:after:absolute pointer-coarse:[&_[data-slot=switch]]:after:-inset-3\"\nconst errorId = (id: string) => `${id}-error`\n\ninterface FieldProps<Row> {\n  row: Row\n  fieldId: string\n  value: SettingsValue\n  error?: string\n  onChange: (value: SettingsValue) => void\n  onBlur: () => void\n}\n\nfunction TextRow({ row, fieldId, value, error, onChange, onBlur }: FieldProps<SettingsTextRow>) {\n  const described = [row.description && descriptionId(fieldId), error && errorId(fieldId)].filter(Boolean).join(\" \")\n  return (\n    <div className={ROW_CLASS}>\n      <RowText row={row} htmlFor={fieldId} fieldId={fieldId} />\n      <div className=\"min-w-0\">\n        <Input\n          id={fieldId}\n          type={row.type ?? \"text\"}\n          autoComplete={row.autoComplete}\n          value={String(value)}\n          aria-invalid={error ? true : undefined}\n          aria-describedby={described || undefined}\n          onChange={(event) => onChange(event.target.value)}\n          onBlur={onBlur}\n        />\n        {error ? (\n          <p id={errorId(fieldId)} className=\"mt-2 text-[13px] text-destructive\">\n            {error}\n          </p>\n        ) : null}\n      </div>\n    </div>\n  )\n}\n\nfunction SelectRow({ row, fieldId, value, onChange }: FieldProps<SettingsSelectRow>) {\n  return (\n    <div className={ROW_CLASS}>\n      <RowText row={row} htmlFor={fieldId} fieldId={fieldId} />\n      <Select value={String(value)} onValueChange={onChange}>\n        <SelectTrigger\n          id={fieldId}\n          aria-describedby={row.description ? descriptionId(fieldId) : undefined}\n          className=\"w-full\"\n        >\n          <SelectValue />\n        </SelectTrigger>\n        <SelectContent>\n          {row.options.map((option) => (\n            <SelectItem key={option.value} value={option.value}>\n              {option.label}\n            </SelectItem>\n          ))}\n        </SelectContent>\n      </Select>\n    </div>\n  )\n}\n\n/** The one row that stays side by side when narrow: a switch alone on its own line reads as detached from its label. */\nfunction SwitchRow({ row, fieldId, value, onChange }: FieldProps<SettingsSwitchRow>) {\n  return (\n    <div className=\"flex items-center justify-between gap-4 p-4 @2xl:gap-8 @2xl:px-6\">\n      <RowText row={row} htmlFor={fieldId} fieldId={fieldId} />\n      <Switch\n        id={fieldId}\n        checked={Boolean(value)}\n        aria-describedby={row.description ? descriptionId(fieldId) : undefined}\n        onCheckedChange={onChange}\n      />\n    </div>\n  )\n}\n\nfunction InfoRow({ row, fieldId }: { row: SettingsInfoRow; fieldId: string }) {\n  return (\n    <div className=\"flex flex-wrap items-center justify-between gap-3 p-4 @2xl:gap-8 @2xl:px-6\">\n      <RowText row={row} fieldId={fieldId} />\n      <div className=\"flex shrink-0 items-center gap-4\">\n        {row.value ? <span className=\"text-[13px] text-muted-foreground\">{row.value}</span> : null}\n        {row.actionLabel ? (\n          <Button variant=\"outline\" size=\"sm\" onClick={row.onAction}>\n            {row.actionLabel}\n          </Button>\n        ) : null}\n      </div>\n    </div>\n  )\n}\n\ninterface SettingsRowViewProps {\n  row: SettingsRow\n  fieldId: string\n  value: SettingsValue | undefined\n  error?: string\n  onChange: (value: SettingsValue) => void\n  onBlur: () => void\n}\n\nfunction SettingsRowView({ row, fieldId, value, error, onChange, onBlur }: SettingsRowViewProps) {\n  if (row.kind === \"info\") return <InfoRow row={row} fieldId={fieldId} />\n  if (row.kind === \"danger\") return <DangerRow row={row} fieldId={fieldId} />\n  const field = { fieldId, value: value ?? row.value, error, onChange, onBlur }\n  if (row.kind === \"text\") return <TextRow row={row} {...field} />\n  if (row.kind === \"select\") return <SelectRow row={row} {...field} />\n  return <SwitchRow row={row} {...field} />\n}\n\nexport { SETTINGS_TOUCH_CLASS, SettingsRowView }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-row-text.tsx",
      "content": "import { Label } from \"@/registry/miseui/ui/label\"\nimport type { SettingsRow } from \"./settings-page-form\"\n\nconst LABEL_CLASS = \"text-[15px] leading-normal font-normal\"\nconst DESCRIPTION_CLASS = \"mt-1 text-[13px] leading-relaxed text-pretty text-muted-foreground\"\n/** Label and description on the left, the control on the right; one above the other when narrow. */\nconst RESPONSIVE_ROW_CLASS = \"grid gap-3 p-4 @2xl:grid-cols-[minmax(0,1fr)_minmax(0,280px)] @2xl:gap-8 @2xl:px-6\"\n\nconst descriptionId = (id: string) => `${id}-description`\n\nfunction RowText({ row, htmlFor, fieldId }: { row: SettingsRow; htmlFor?: string; fieldId: string }) {\n  return (\n    <div className=\"min-w-0\">\n      {htmlFor ? (\n        <Label htmlFor={htmlFor} className={LABEL_CLASS}>\n          {row.label}\n        </Label>\n      ) : (\n        <p className={LABEL_CLASS}>{row.label}</p>\n      )}\n      {row.description ? (\n        <p id={descriptionId(fieldId)} className={DESCRIPTION_CLASS}>\n          {row.description}\n        </p>\n      ) : null}\n    </div>\n  )\n}\n\nexport { descriptionId, RESPONSIVE_ROW_CLASS, RowText }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-danger.tsx",
      "content": "import { useState } from \"react\"\nimport { cn } from \"@/registry/miseui/lib/utils\"\nimport { Button } from \"@/registry/miseui/ui/button\"\nimport type { SettingsDangerRow } from \"./settings-page-form\"\nimport { RESPONSIVE_ROW_CLASS, RowText } from \"./settings-page-row-text\"\n\nfunction DangerDone({ row, onUndo }: { row: SettingsDangerRow; onUndo: () => void }) {\n  return (\n    <div className=\"flex flex-wrap items-center gap-3\">\n      <p role=\"status\" className=\"text-[13px] text-pretty text-muted-foreground\">\n        {row.doneMessage}\n      </p>\n      <Button variant=\"outline\" size=\"sm\" onClick={onUndo}>\n        Undo\n      </Button>\n    </div>\n  )\n}\n\nfunction DangerControls({ row }: { row: SettingsDangerRow }) {\n  const [step, setStep] = useState<\"idle\" | \"confirm\" | \"done\">(\"idle\")\n  if (step === \"done\") {\n    const undo = () => {\n      setStep(\"idle\")\n      row.onUndo?.()\n    }\n    return <DangerDone row={row} onUndo={undo} />\n  }\n  if (step === \"confirm\") {\n    const confirm = () => {\n      setStep(\"done\")\n      row.onConfirm?.()\n    }\n    return (\n      <div className=\"flex flex-wrap gap-2\">\n        {/* Focus lands on the safe choice, so a second press of Enter cannot confirm by accident. */}\n        <Button variant=\"outline\" size=\"sm\" autoFocus onClick={() => setStep(\"idle\")}>\n          {row.cancelLabel}\n        </Button>\n        <Button variant=\"destructive\" size=\"sm\" onClick={confirm}>\n          {row.confirmLabel}\n        </Button>\n      </div>\n    )\n  }\n  return (\n    <Button\n      variant=\"outline\"\n      size=\"sm\"\n      className=\"border-destructive/40 text-destructive hover:bg-destructive/10 hover:text-destructive\"\n      onClick={() => setStep(\"confirm\")}\n    >\n      {row.actionLabel}\n    </Button>\n  )\n}\n\nfunction DangerRow({ row, fieldId }: { row: SettingsDangerRow; fieldId: string }) {\n  return (\n    <div className={cn(RESPONSIVE_ROW_CLASS, \"@2xl:items-center\")}>\n      <RowText row={row} fieldId={fieldId} />\n      <div className=\"flex min-w-0 @2xl:justify-end\">\n        <DangerControls row={row} />\n      </div>\n    </div>\n  )\n}\n\nexport { DangerRow }\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-form.ts",
      "content": "import type * as React from \"react\"\nimport { useEffect, useMemo, useState } from \"react\"\n\ntype SettingsValue = string | boolean\ntype SettingsValues = Readonly<Record<string, SettingsValue>>\n\ninterface SettingsRowBase {\n  id: string\n  label: string\n  description?: string\n}\n\ninterface SettingsTextRow extends SettingsRowBase {\n  kind: \"text\"\n  value: string\n  type?: \"text\" | \"email\"\n  autoComplete?: string\n  /** Return a message to block saving, or undefined when the value is fine. */\n  validate?: (value: string) => string | undefined\n}\n\ninterface SettingsSwitchRow extends SettingsRowBase {\n  kind: \"switch\"\n  value: boolean\n}\n\ninterface SettingsSelectRow extends SettingsRowBase {\n  kind: \"select\"\n  value: string\n  options: ReadonlyArray<{ value: string; label: string }>\n}\n\n/** Read-only, with an optional action that leaves this page: nothing here waits for Save. */\ninterface SettingsInfoRow extends SettingsRowBase {\n  kind: \"info\"\n  value?: string\n  actionLabel?: string\n  onAction?: () => void\n}\n\n/** Asks twice, and offers an undo after, instead of warning once and hoping. */\ninterface SettingsDangerRow extends SettingsRowBase {\n  kind: \"danger\"\n  actionLabel: string\n  confirmLabel: string\n  cancelLabel: string\n  doneMessage: string\n  onConfirm?: () => void\n  onUndo?: () => void\n}\n\ntype SettingsRow = SettingsTextRow | SettingsSwitchRow | SettingsSelectRow | SettingsInfoRow | SettingsDangerRow\ntype EditableRow = SettingsTextRow | SettingsSwitchRow | SettingsSelectRow\n\ninterface SettingsSection {\n  id: string\n  title: string\n  description?: string\n  /** Pushes the section away from the rest and marks its edge, so it cannot be hit on the way to something else. */\n  tone?: \"danger\"\n  /** Shown beside the title in the `sidebar` design. */\n  icon?: React.ComponentType<{ className?: string }>\n  rows: readonly SettingsRow[]\n}\n\ntype SaveStatus = \"idle\" | \"saving\" | \"saved\" | \"failed\"\ntype OnSave = (values: SettingsValues, changedIds: readonly string[]) => void | Promise<void>\n\ninterface SettingsViewProps extends Omit<React.ComponentProps<\"div\">, \"title\"> {\n  title?: string\n  /** Continues the title in the same size, one tone quieter. */\n  titleQuiet?: string\n  sections?: readonly SettingsSection[]\n  /** Receives the editable values and the ids that changed. Reject to keep the edits on screen and offer a retry. In the `cards` design it receives one group at a time. */\n  onSave?: OnSave\n}\n\n/** Long enough to read \"Changes saved\" without looking for it, short enough not to linger. */\nconst SAVED_MESSAGE_MS = 2400\n\nconst isEditable = (row: SettingsRow): row is EditableRow =>\n  row.kind === \"text\" || row.kind === \"switch\" || row.kind === \"select\"\n\nfunction editableRows(sections: readonly SettingsSection[]) {\n  return sections.flatMap((section) => section.rows.filter(isEditable))\n}\n\nfunction valuesOf(rows: readonly EditableRow[]): SettingsValues {\n  return Object.fromEntries(rows.map((row) => [row.id, row.value]))\n}\n\nfunction errorsOf(rows: readonly EditableRow[], values: SettingsValues): Readonly<Record<string, string>> {\n  const entries = rows.flatMap((row) => {\n    if (row.kind !== \"text\" || !row.validate) return []\n    const message = row.validate(String(values[row.id] ?? \"\"))\n    return message ? [[row.id, message] as const] : []\n  })\n  return Object.fromEntries(entries)\n}\n\nfunction useSavedMessage(status: SaveStatus, clear: () => void) {\n  useEffect(() => {\n    if (status !== \"saved\") return\n    const id = window.setTimeout(clear, SAVED_MESSAGE_MS)\n    return () => window.clearTimeout(id)\n  }, [status, clear])\n}\n\n/** Start values are read once. To reload them from the server, remount with a new `key`. */\nfunction useSettingsForm(sections: readonly SettingsSection[], onSave?: OnSave) {\n  const rows = useMemo(() => editableRows(sections), [sections])\n  const [baseline, setBaseline] = useState(() => valuesOf(rows))\n  const [values, setValues] = useState(baseline)\n  const [touched, setTouched] = useState<ReadonlySet<string>>(new Set())\n  const [status, setStatus] = useState<SaveStatus>(\"idle\")\n  const clearStatus = useMemo(() => () => setStatus(\"idle\"), [])\n  useSavedMessage(status, clearStatus)\n\n  const changedIds = rows.filter((row) => values[row.id] !== baseline[row.id]).map((row) => row.id)\n  const errors = errorsOf(rows, values)\n  const invalidIds = rows.filter((row) => errors[row.id]).map((row) => row.id)\n\n  const update = (id: string, value: SettingsValue) => {\n    setValues((current) => ({ ...current, [id]: value }))\n    setStatus(\"idle\")\n  }\n  const touch = (id: string) => setTouched((current) => new Set(current).add(id))\n  const discard = () => {\n    setValues(baseline)\n    setTouched(new Set())\n    setStatus(\"idle\")\n  }\n  /** Resolves to the first invalid row, so the page can move focus to it. */\n  const save = async (): Promise<string | undefined> => {\n    if (invalidIds.length > 0) {\n      setTouched(new Set(invalidIds))\n      return invalidIds[0]\n    }\n    setStatus(\"saving\")\n    try {\n      await onSave?.(values, changedIds)\n      setBaseline(values)\n      setTouched(new Set())\n      setStatus(\"saved\")\n    } catch {\n      // Nothing is thrown away: the edits stay on screen, ready for another try.\n      setStatus(\"failed\")\n    }\n    return undefined\n  }\n\n  const visibleErrors = Object.fromEntries(Object.entries(errors).filter(([id]) => touched.has(id)))\n  return { values, changedIds, errors: visibleErrors, status, update, touch, discard, save }\n}\n\nexport {\n  isEditable,\n  useSettingsForm,\n  type OnSave,\n  type SaveStatus,\n  type SettingsDangerRow,\n  type SettingsInfoRow,\n  type SettingsRow,\n  type SettingsSection,\n  type SettingsSelectRow,\n  type SettingsSwitchRow,\n  type SettingsTextRow,\n  type SettingsValue,\n  type SettingsValues,\n  type SettingsViewProps,\n}\n",
      "type": "registry:component"
    },
    {
      "path": "registry/miseui/blocks/settings-page-sample.ts",
      "content": "import { Bell, CreditCard, TriangleAlert, UserRound } from \"lucide-react\"\nimport type { SettingsSection } from \"./settings-page-form\"\n\n/** Invented sample content. The person, the plan and every figure are made up. */\n\nconst EMAIL_PATTERN = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/\n\nconst SAMPLE_SECTIONS: readonly SettingsSection[] = [\n  {\n    id: \"profile\",\n    title: \"Profile\",\n    description: \"How you appear to the people in this workspace.\",\n    icon: UserRound,\n    rows: [\n      {\n        kind: \"text\",\n        id: \"name\",\n        label: \"Display name\",\n        description: \"Shown next to your comments and invoices.\",\n        value: \"Mina Okafor\",\n        autoComplete: \"name\",\n        validate: (value) => (value.trim() ? undefined : \"Add a name so your team knows who this is.\"),\n      },\n      {\n        kind: \"text\",\n        id: \"email\",\n        label: \"Email\",\n        description: \"Where receipts and sign-in links go.\",\n        value: \"mina@example.com\",\n        type: \"email\",\n        autoComplete: \"email\",\n        validate: (value) => (EMAIL_PATTERN.test(value.trim()) ? undefined : \"That does not look like an email address.\"),\n      },\n      {\n        kind: \"select\",\n        id: \"timezone\",\n        label: \"Time zone\",\n        description: \"Used for the weekly summary and report dates.\",\n        value: \"seoul\",\n        options: [\n          { value: \"seoul\", label: \"Seoul (GMT+9)\" },\n          { value: \"london\", label: \"London (GMT+0)\" },\n          { value: \"new-york\", label: \"New York (GMT-5)\" },\n        ],\n      },\n    ],\n  },\n  {\n    id: \"notifications\",\n    title: \"Notifications\",\n    description: \"Only what you would want to be interrupted for.\",\n    icon: Bell,\n    rows: [\n      {\n        kind: \"switch\",\n        id: \"failed-payments\",\n        label: \"Failed payments\",\n        description: \"The moment a charge fails, so you can follow up the same day.\",\n        value: true,\n      },\n      {\n        kind: \"switch\",\n        id: \"weekly-summary\",\n        label: \"Weekly summary\",\n        description: \"Monday at 9:00, last week's numbers in one email.\",\n        value: true,\n      },\n      {\n        kind: \"switch\",\n        id: \"product-news\",\n        label: \"Product news\",\n        description: \"A short note when something ships, about once a month.\",\n        value: false,\n      },\n    ],\n  },\n  {\n    id: \"plan\",\n    title: \"Plan\",\n    icon: CreditCard,\n    rows: [\n      {\n        kind: \"info\",\n        id: \"current-plan\",\n        label: \"Team\",\n        description: \"$84 per month, renews on December 14.\",\n        actionLabel: \"Change plan\",\n      },\n      { kind: \"info\", id: \"seats\", label: \"Seats\", description: \"2 seats are free to invite into.\", value: \"4 of 6 used\" },\n    ],\n  },\n  {\n    id: \"danger\",\n    title: \"Delete workspace\",\n    tone: \"danger\",\n    icon: TriangleAlert,\n    rows: [\n      {\n        kind: \"danger\",\n        id: \"delete-workspace\",\n        label: \"Delete this workspace\",\n        description: \"Removes 1,284 customer records and every invite. You get 14 days to change your mind.\",\n        actionLabel: \"Delete workspace\",\n        confirmLabel: \"Yes, delete it\",\n        cancelLabel: \"Keep workspace\",\n        doneMessage: \"Deletion scheduled for 14 days from now.\",\n      },\n    ],\n  },\n]\n\nexport { SAMPLE_SECTIONS }\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "blocks"
  ],
  "type": "registry:block"
}