{
  "$schema": "https://shadcn-vue.com/schema/registry-item.json",
  "name": "analytics-switch",
  "type": "registry:block",
  "title": "Count my visits",
  "description": "A switch for counting visits, wherever the instance counts them.",
  "author": "spotstrap (https://kodentuzo.com/spotstrap)",
  "dependencies": [
    "@kodentuzo/spotstrap@^0.3.1",
    "@kodentuzo/spotkit@^0.3.0"
  ],
  "registryDependencies": [
    "label",
    "switch"
  ],
  "files": [
    {
      "path": "components/AnalyticsSwitch.vue",
      "type": "registry:component",
      "content": "<script setup lang=\"ts\">\n// \"Count my visits\": shown wherever the instance counts visits for this app (opt-out and\n// opt-in). Put it in Your data. Renders nothing in server mode, or before it knows.\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 { Label } from '@/components/ui/label'\nimport { Switch } from '@/components/ui/switch'\n\nconst props = defineProps<{ messages?: Messages }>()\nconst t = computed(() => (props.messages ?? en).analytics.optOut)\n\nconst choice = shallowRef<AnalyticsChoice>()\nconst on = 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  on.value = choice.value.on\n  stop = choice.value.subscribe(() => {\n    on.value = choice.value?.on ?? false\n  })\n})\nonBeforeUnmount(() => stop())\n</script>\n\n<template>\n  <div v-if=\"choice?.switchVisible\" class=\"flex items-start justify-between gap-4\">\n    <div class=\"space-y-1\">\n      <Label for=\"spotstrap-count-visits\">{{ t.label }}</Label>\n      <p class=\"text-sm text-muted-foreground\">{{ t.help }}</p>\n    </div>\n    <Switch id=\"spotstrap-count-visits\" :model-value=\"on\" @update:model-value=\"(value: boolean) => choice?.setOn(value)\" />\n  </div>\n</template>\n"
    }
  ]
}
