import { inject as t, watch as n, onBeforeUnmount as d } from "vue";
function v(a, u) {
  const o = t("map"), f = t("isLoaded");
  let e = null;
  n(
    // Watch both isLoaded and the container ref (if it's a ref)
    () => [f?.value, typeof u != "function" ? u.value : !0],
    ([i, l]) => {
      if (!(!i || !o?.value || e)) {
        if (typeof u != "function") {
          if (!l) return;
          e = {
            onAdd() {
              return u.value;
            },
            onRemove() {
            }
          };
        } else
          e = u();
        o.value.addControl(e, a.position);
      }
    },
    { immediate: !0 }
  ), d(() => {
    o?.value && e && o.value.removeControl(e);
  });
}
export {
  v as u
};
