{
  "$schema": "https://shadcn-vue.com/schema/registry-item.json",
  "name": "analytics-prompt",
  "type": "registry:block",
  "title": "Counting visits prompt",
  "description": "In opt-in mode, asks once whether to count the visitor’s visits.",
  "author": "spotstrap (https://kodentuzo.com/spotstrap)",
  "dependencies": [
    "@kodentuzo/spotstrap@^0.3.1",
    "@kodentuzo/spotkit@^0.3.0"
  ],
  "registryDependencies": [
    "button",
    "card"
  ],
  "files": [
    {
      "path": "components/AnalyticsPrompt.vue",
      "type": "registry:component",
      "content": "<script setup lang=\"ts\">\n// In opt-in mode only: asks once whether to count the visitor's visits. Put it in the app's\n// layout; it shows until the visitor answers, and renders nothing otherwise.\nimport { analytics } from '@kodentuzo/spotkit/client'\nimport { type AnalyticsChoice, createAnalyticsChoice, en, type Messages } from '@kodentuzo/spotstrap/blocks'\nimport { computed, onBeforeUnmount, onMounted, ref, shallowRef } from 'vue'\nimport { Button } from '@/components/ui/button'\nimport { Card, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'\n\nconst props = defineProps<{ messages?: Messages }>()\nconst t = computed(() => (props.messages ?? en).analytics.optIn)\n\nconst choice = shallowRef<AnalyticsChoice>()\nconst visible = ref(false)\nlet stop = () => {}\nonMounted(async () => {\n  // Off Spotcraft, or with config.json unreachable, there's nothing to choose: render nothing.\n  const counted = await analytics().catch(() => undefined)\n  if (!counted) return\n  choice.value = createAnalyticsChoice(counted)\n  visible.value = choice.value.promptVisible\n  stop = choice.value.subscribe(() => {\n    visible.value = choice.value?.promptVisible ?? false\n  })\n})\nonBeforeUnmount(() => stop())\n</script>\n\n<template>\n  <section\n    v-if=\"visible\"\n    :aria-label=\"t.title\"\n    class=\"fixed inset-x-4 bottom-4 z-50 mx-auto max-w-md\"\n  >\n    <Card class=\"border shadow-lg\">\n      <CardHeader>\n        <CardTitle>{{ t.title }}</CardTitle>\n        <CardDescription>{{ t.body }}</CardDescription>\n      </CardHeader>\n      <CardFooter class=\"flex justify-end gap-2\">\n        <Button variant=\"outline\" @click=\"choice?.decline()\">{{ t.decline }}</Button>\n        <Button @click=\"choice?.accept()\">{{ t.accept }}</Button>\n      </CardFooter>\n    </Card>\n  </section>\n</template>\n"
    }
  ]
}
