{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-page-leave-demo",
  "title": "UsePageLeaveDemo",
  "description": "use-page-leave's hook in action.",
  "registryDependencies": [
    "card",
    "button",
    "badge",
    "https://guarahooks.com/r/use-page-leave.json"
  ],
  "files": [
    {
      "path": "registry/example/use-page-leave-demo.tsx",
      "content": "'use client';\n\nimport React, { useEffect } from 'react';\n\nimport { Badge } from '@/components/ui/badge';\nimport { Button } from '@/components/ui/button';\nimport {\n  Card,\n  CardContent,\n  CardDescription,\n  CardFooter,\n  CardHeader,\n  CardTitle,\n} from '@/components/ui/card';\n\nimport { cn } from '@/lib/utils';\n\nimport { usePageLeave } from '@/hooks/guarahooks/use-page-leave';\n\nexport default function UsePageLeaveDemo() {\n  const { isPageLeft, onPageLeave } = usePageLeave({\n    showConfirmation: true,\n    confirmationMessage:\n      'Are you sure you want to leave? Unsaved changes may be lost.',\n  });\n\n  useEffect(() => {\n    onPageLeave(() => {\n      // Custom action when the user leaves the page (tab switch)\n      // Example: save draft, send telemetry, etc.\n      // Replace this with whatever logic you need\n      // eslint-disable-next-line no-console\n      console.log('User left the page (tab switch)');\n    });\n  }, [onPageLeave]);\n\n  return (\n    <Card className=\"relative max-w-sm w-full\">\n      <CardHeader>\n        <CardTitle>usePageLeave</CardTitle>\n        <CardDescription>\n          This component demonstrates the <code>usePageLeave</code> hook to\n          detect when the user switches tabs or tries to leave the page.\n        </CardDescription>\n      </CardHeader>\n      <CardContent className=\"space-y-4\">\n        <Badge\n          variant=\"secondary\"\n          className={cn(\n            'w-fit',\n            isPageLeft\n              ? 'bg-yellow-500/30 border-yellow-500 text-yellow-700'\n              : 'bg-green-500/30 border-green-500 text-green-700',\n          )}\n        >\n          {isPageLeft\n            ? 'You left the page (tab in background)'\n            : 'You are viewing this page'}\n        </Badge>\n        <p className=\"text-sm text-muted-foreground\">\n          Open another tab or minimize the browser to see the status change.\n          <br />\n          Also try closing or reloading the page to see the confirmation alert.\n        </p>\n      </CardContent>\n      <CardFooter>\n        <Button\n          size=\"sm\"\n          variant=\"outline\"\n          onClick={() => window.location.reload()}\n        >\n          Reload page\n        </Button>\n      </CardFooter>\n    </Card>\n  );\n}\n",
      "type": "registry:example",
      "target": "components/example/use-page-leave-demo.tsx"
    }
  ],
  "type": "registry:example"
}