{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-07",
  "title": "Terms dialog",
  "description": "Terms that can be accepted only once read to the end.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/dialog.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/dialog/dialog-07.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Dialog,\n  DialogClose,\n  DialogContent,\n  DialogDescription,\n  DialogFooter,\n  DialogHeader,\n  DialogTitle,\n  DialogTrigger,\n} from '@/registry/ndeko/ui/dialog';\n\ntype TermsSection = {\n  title: string;\n  text: string;\n  items?: string[];\n};\n\nconst TERMS_SECTIONS: TermsSection[] = [\n  {\n    title: 'Acceptance of terms',\n    text: 'By creating an account or using the service, you agree to these terms. If you use it for a company, you confirm that you can accept them on its behalf.',\n  },\n  {\n    title: 'Your account',\n    text: 'Keep your password private and tell us right away if you think someone else used your account. You are responsible for what happens under it.',\n  },\n  {\n    title: 'Your content',\n    text: 'You own what you upload. You give us the permission we need to store, display and back it up so the service works.',\n  },\n  {\n    title: 'Acceptable use',\n    text: 'Do not use the service to:',\n    items: [\n      'break the law or the rights of others',\n      'send spam or malware',\n      'probe or overload our systems',\n      'resell access without an agreement with us',\n    ],\n  },\n  {\n    title: 'Payments',\n    text: 'Paid plans renew automatically until you cancel. Prices can change with 30 days of notice by email.',\n  },\n  {\n    title: 'Limitation of liability',\n    text: 'The service is provided as is. We are not liable for indirect losses, and our total liability is limited to what you paid in the last 12 months.',\n  },\n  {\n    title: 'Changes to these terms',\n    text: 'We email you before a material change takes effect. Using the service after that date means you accept the new terms.',\n  },\n  {\n    title: 'Ending the agreement',\n    text: 'You can close your account at any time. We may suspend an account that breaks these terms, and we tell you why.',\n  },\n  {\n    title: 'Governing law',\n    text: 'These terms are governed by the laws of the country where the company is registered, without regard to conflict of law rules.',\n  },\n];\n\nconst END_TOLERANCE_PX = 4;\n\nconst HINT_TRANSITION: Transition = { duration: 0.15, ease: [0.2, 0, 0, 1] };\n\nconst SCROLL_BODY =\n  'min-h-0 flex-1 overflow-y-auto px-6 pt-5 pb-5 outline-none focus-visible:ring-[3px] focus-visible:ring-ring/25 focus-visible:ring-inset [mask-image:linear-gradient(to_bottom,transparent,black_1.25rem,black_calc(100%_-_1.25rem),transparent)]';\n\nfunction isScrolledToEnd(element: HTMLElement) {\n  const visibleBottom = element.scrollTop + element.clientHeight;\n  const contentEnd = element.scrollHeight - END_TOLERANCE_PX;\n  return visibleBottom >= contentEnd;\n}\n\nfunction hintExitOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return { opacity: 0 };\n  }\n  return { opacity: 0, filter: 'blur(2px)' };\n}\n\nexport default function Dialog07() {\n  const [hasReadToEnd, setHasReadToEnd] = useState(false);\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const hintExit = hintExitOf(shouldReduceMotion);\n\n  function markReadAtEnd(event: React.UIEvent<HTMLDivElement>) {\n    if (isScrolledToEnd(event.currentTarget)) {\n      setHasReadToEnd(true);\n    }\n  }\n\n  return (\n    <Dialog>\n      <DialogTrigger render={<Button variant='outline' />}>\n        Review terms\n      </DialogTrigger>\n      <DialogContent\n        animateSize={false}\n        className='h-[min(640px,80dvh)] overflow-hidden p-0'\n        contentClassName='h-full gap-0'\n      >\n        <DialogHeader className='px-6 pt-6 pr-12'>\n          <DialogTitle>Terms of service</DialogTitle>\n        </DialogHeader>\n        <div tabIndex={0} onScroll={markReadAtEnd} className={SCROLL_BODY}>\n          <DialogDescription\n            render={<div />}\n            className='flex flex-col gap-4 leading-relaxed'\n          >\n            {TERMS_SECTIONS.map((section) => (\n              <section key={section.title} className='flex flex-col gap-1'>\n                <h3 className='text-foreground font-medium'>{section.title}</h3>\n                <p>{section.text}</p>\n                {section.items && (\n                  <ul className='list-disc ps-5'>\n                    {section.items.map((item) => (\n                      <li key={item}>{item}</li>\n                    ))}\n                  </ul>\n                )}\n              </section>\n            ))}\n          </DialogDescription>\n        </div>\n        <DialogFooter className='px-6 pt-4 pb-6 sm:items-center'>\n          <AnimatePresence initial={false}>\n            {!hasReadToEnd && (\n              <motion.span\n                key='hint'\n                className='text-muted-foreground grow text-xs max-sm:text-center'\n                exit={hintExit}\n                transition={HINT_TRANSITION}\n              >\n                Scroll to the end to accept.\n              </motion.span>\n            )}\n          </AnimatePresence>\n          <DialogClose render={<Button variant='outline' size='lg' />}>\n            Cancel\n          </DialogClose>\n          <DialogClose disabled={!hasReadToEnd} render={<Button size='lg' />}>\n            Accept terms\n          </DialogClose>\n        </DialogFooter>\n      </DialogContent>\n    </Dialog>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "categories": [
    "components",
    "dialog"
  ],
  "type": "registry:component"
}