import { getCurrentInstance, computed, watch, onMounted } from "vue";
import { isFunction as c } from "../../../../@vue/shared/dist/shared.esm-bundler.mjs";
import { buildProp as O, definePropType as h } from "../../utils/vue/props/runtime.mjs";
import { isBoolean as o } from "../../utils/types.mjs";
import { isClient as f } from "../../../../@vueuse/shared/index.mjs";
const A = O({
  type: h(Boolean),
  default: null
}), I = O({
  type: h(Function)
}), V = (l) => {
  const u = `update:${l}`, c$1 = `onUpdate:${l}`, x = [u], B = {
    [l]: A,
    [c$1]: I
  };
  return {
    useModelToggle: ({
      indicator: o$1,
      toggleReason: r,
      shouldHideWhenRouteChanges: g,
      shouldProceed: v,
      onShow: m,
      onHide: M
    }) => {
      const n = getCurrentInstance(), { emit: p } = n, t = n.props, i = computed(() => c(t[c$1])), T = computed(() => t[l] === null), b = (e) => {
        o$1.value !== true && (o$1.value = true, r && (r.value = e), c(m) && m(e));
      }, y = (e) => {
        o$1.value !== false && (o$1.value = false, r && (r.value = e), c(M) && M(e));
      }, E = (e) => {
        if (t.disabled === true || c(v) && !v())
          return;
        const s = i.value && f;
        s && p(u, true), (T.value || !s) && b(e);
      }, a = (e) => {
        if (t.disabled === true || !f)
          return;
        const s = i.value && f;
        s && p(u, false), (T.value || !s) && y(e);
      }, C = (e) => {
        o(e) && (t.disabled && e ? i.value && p(u, false) : o$1.value !== e && (e ? b() : y()));
      }, F = () => {
        o$1.value ? a() : E();
      };
      return watch(() => t[l], C), g && n.appContext.config.globalProperties.$route !== void 0 && watch(() => ({
        ...n.proxy.$route
      }), () => {
        g.value && o$1.value && a();
      }), onMounted(() => {
        C(t[l]);
      }), {
        hide: a,
        show: E,
        toggle: F,
        hasUpdateHandler: i
      };
    },
    useModelToggleProps: B,
    useModelToggleEmits: x
  };
};
export {
  V as createModelToggleComposable
};
