{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "app-settings-notifications",
  "type": "registry:block",
  "title": "App, notification preferences",
  "description": "A list of notification preferences, each a title, one line of explanation and a switch (applies at once) or a checkbox (saved with a button). The on/off state of every row is a prop.",
  "categories": [
    "app"
  ],
  "dependencies": [
    "zod@^4.6.5"
  ],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/block-kit.json",
    "https://ui.klarhimmel.com/r/button.json",
    "https://ui.klarhimmel.com/r/checkbox.json",
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/kit-app.json",
    "https://ui.klarhimmel.com/r/switch.json"
  ],
  "files": [
    {
      "path": "src/blocks/app-settings-notifications/spec.ts",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-settings-notifications/spec.ts",
      "content": "import { z } from 'zod';\nimport { defineSpec, t } from '../_shared/schema';\n\nconst row = z.object({ title: t(60), description: t(140), on: z.boolean() });\n\nconst schema = z.object({\n  eyebrow: t(60).optional(),\n  title: t(120),\n  description: t(300).optional(),\n  /** switch: each row applies at once. checkbox: rows are chosen, then saved. */\n  control: z.enum(['switch', 'checkbox']),\n  rows: z.array(row).min(2).max(7),\n  save: t(30),\n});\n\nexport const spec = defineSpec({\n  type: 'app-settings-notifications',\n  aliases: ['app/settings-notifications'],\n  name: 'App, notification preferences',\n  category: 'app',\n  role: 'body',\n  description: 'A list of notification preferences, each a title, one line of explanation and a switch (applies at once) or a checkbox (saved with a button). The on/off state of every row is a prop.',\n  schema,\n  defaults: {\n    \"eyebrow\": \"Settings\",\n    \"title\": \"Notifications\",\n    \"description\": \"Say what the person can choose and how it reaches them.\",\n    \"control\": \"switch\",\n    \"rows\": [\n      {\n        \"title\": \"Name an event\",\n        \"description\": \"Say what happens when it occurs.\",\n        \"on\": true\n      },\n      {\n        \"title\": \"Name a second event\",\n        \"description\": \"Say what the person learns from it.\",\n        \"on\": true\n      },\n      {\n        \"title\": \"Name a recurring one\",\n        \"description\": \"Say what it contains and how often it arrives.\",\n        \"on\": false\n      },\n      {\n        \"title\": \"Name a rare one\",\n        \"description\": \"Say what it contains and how rare it is.\",\n        \"on\": false\n      }\n    ],\n    \"save\": \"Save preferences\"\n  },\n});\n"
    },
    {
      "path": "src/blocks/app-settings-notifications/index.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/blocks/app-settings-notifications/index.tsx",
      "content": "import { useId } from 'react';\nimport { Text, withHeadingLevel } from '../../editing';\nimport { Button } from '../../ui/button';\nimport { Checkbox } from '../../ui/checkbox';\nimport { Switch } from '../../ui/switch';\nimport { Container, Section, SectionHeader } from '../_shared/kit';\nimport { AppPanel, StateSlot } from '../_shared/app-kit';\nimport { spec } from './spec';\nimport type { BlockProps } from '../types';\nimport type { z } from 'zod';\n\nexport { spec };\ntype Props = z.infer<typeof spec.schema>;\n\nfunction AppSettingsNotifications({ props }: BlockProps<Props>) {\n  const id = useId();\n  const isSwitch = props.control === 'switch';\n  return (\n    <Section labelledBy={id}>\n      <Container width=\"narrow\">\n        <SectionHeader id={id} eyebrow={props.eyebrow} title={props.title} description={props.description} />\n        <AppPanel className=\"mt-10\">\n          <form key={props.control + JSON.stringify(props.rows.map((r) => r.on))} onSubmit={(e) => e.preventDefault()}>\n            <ul className=\"divide-y divide-kh-line px-6 @xl:px-8\">\n              {props.rows.map((r, i) => {\n                const rid = `${id}-r${i}`;\n                const title = <Text path={['rows', i, 'title']} value={r.title} as=\"span\" />;\n                const text = <Text path={['rows', i, 'description']} value={r.description} as=\"span\" />;\n                return (\n                  <li key={i} className=\"py-1\">\n                    {isSwitch ? (\n                      <div className=\"flex min-h-11 items-center justify-between gap-4 py-3\">\n                        <label htmlFor={rid} className=\"flex min-w-0 flex-1 flex-col\">\n                          <span className=\"text-kh-body font-medium text-kh-ink\">{title}</span>\n                          <span className=\"text-kh-small text-kh-muted\">{text}</span>\n                        </label>\n                        <Switch id={rid} name={`row-${i}`} defaultChecked={r.on} />\n                      </div>\n                    ) : (\n                      <Checkbox id={rid} name={`row-${i}`} defaultChecked={r.on} label={title} hint={text} />\n                    )}\n                  </li>\n                );\n              })}\n            </ul>\n            <StateSlot show={!isSwitch} className=\"flex justify-end border-t border-kh-line p-6 @xl:px-8\">\n              <Button type=\"submit\">\n                <Text path={['save']} value={props.save} as=\"span\" />\n              </Button>\n            </StateSlot>\n          </form>\n        </AppPanel>\n      </Container>\n    </Section>\n  );\n}\n\nexport default withHeadingLevel(AppSettingsNotifications);\n"
    }
  ]
}
