<script setup>
import { inject, onBeforeUnmount, onMounted, onUpdated } from "vue";
import { buttonRegistryKey } from "../utils/button-registry";
defineOptions({
  name: "ShwfedActionDefinition",
  inheritAttrs: false
});
const props = defineProps({
  actionId: { type: String, required: true },
  effect: { type: null, required: false }
});
const slots = defineSlots();
const registry = inject(buttonRegistryKey, void 0);
const ownerId = crypto.randomUUID();
const isDevelopment = import.meta.dev;
let registeredActionId;
let hasWarnedMissingRegistry = false;
function warnMissingRegistry() {
  if (!isDevelopment || hasWarnedMissingRegistry) {
    return;
  }
  hasWarnedMissingRegistry = true;
  console.warn("[shwfed-action-definition] must be used inside <shwfed-actions>.");
}
function syncAction() {
  if (!registry) {
    warnMissingRegistry();
    return;
  }
  if (registeredActionId && registeredActionId !== props.actionId) {
    registry.unregisterAction(registeredActionId, ownerId);
  }
  registry.registerAction({
    ownerId,
    actionId: props.actionId,
    effect: props.effect,
    render: slots.default
  });
  registeredActionId = props.actionId;
}
syncAction();
onMounted(() => {
  syncAction();
});
onUpdated(() => {
  syncAction();
});
onBeforeUnmount(() => {
  if (!registry || !registeredActionId) {
    return;
  }
  registry.unregisterAction(registeredActionId, ownerId);
});
</script>

<template>
  <slot
    v-if="false"
    :props="{}"
    :report="() => {
}"
    :is-desktop="false"
  />
</template>
