var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key2 of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key2) && key2 !== except)
        __defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var index_exports = {};
__export(index_exports, {
  Deferred: () => deferred_default,
  Head: () => head_default,
  Link: () => link_default,
  WhenVisible: () => whenVisible_default,
  createInertiaApp: () => createInertiaApp,
  router: () => import_core10.router,
  useForm: () => useForm,
  usePage: () => usePage,
  usePoll: () => usePoll,
  usePrefetch: () => usePrefetch,
  useRemember: () => useRemember
});
module.exports = __toCommonJS(index_exports);
var import_core10 = require("@inertiajs/core");

// src/app.ts
var import_core3 = require("@inertiajs/core");
var import_vue2 = require("vue");

// src/remember.ts
var import_core = require("@inertiajs/core");
var import_es_toolkit = require("es-toolkit");
var remember = {
  created() {
    if (!this.$options.remember) {
      return;
    }
    if (Array.isArray(this.$options.remember)) {
      this.$options.remember = { data: this.$options.remember };
    }
    if (typeof this.$options.remember === "string") {
      this.$options.remember = { data: [this.$options.remember] };
    }
    if (typeof this.$options.remember.data === "string") {
      this.$options.remember = { data: [this.$options.remember.data] };
    }
    const rememberKey = this.$options.remember.key instanceof Function ? this.$options.remember.key.call(this) : this.$options.remember.key;
    const restored = import_core.router.restore(rememberKey);
    const rememberable = this.$options.remember.data.filter((key2) => {
      return !(this[key2] !== null && typeof this[key2] === "object" && this[key2].__rememberable === false);
    });
    const hasCallbacks = (key2) => {
      return this[key2] !== null && typeof this[key2] === "object" && typeof this[key2].__remember === "function" && typeof this[key2].__restore === "function";
    };
    rememberable.forEach((key2) => {
      if (this[key2] !== void 0 && restored !== void 0 && restored[key2] !== void 0) {
        hasCallbacks(key2) ? this[key2].__restore(restored[key2]) : this[key2] = restored[key2];
      }
      this.$watch(
        key2,
        () => {
          import_core.router.remember(
            rememberable.reduce(
              (data, key3) => ({
                ...data,
                [key3]: (0, import_es_toolkit.cloneDeep)(hasCallbacks(key3) ? this[key3].__remember() : this[key3])
              }),
              {}
            ),
            rememberKey
          );
        },
        { immediate: true, deep: true }
      );
    });
  }
};
var remember_default = remember;

// src/useForm.ts
var import_core2 = require("@inertiajs/core");
var import_es_toolkit2 = require("es-toolkit");
var import_compat = require("es-toolkit/compat");
var import_vue = require("vue");
function useForm(rememberKeyOrData, maybeData) {
  const rememberKey = typeof rememberKeyOrData === "string" ? rememberKeyOrData : null;
  const data = (typeof rememberKeyOrData === "string" ? maybeData : rememberKeyOrData) ?? {};
  const restored = rememberKey ? import_core2.router.restore(rememberKey) : null;
  let defaults = typeof data === "function" ? (0, import_es_toolkit2.cloneDeep)(data()) : (0, import_es_toolkit2.cloneDeep)(data);
  let cancelToken = null;
  let recentlySuccessfulTimeoutId = null;
  let transform = (data2) => data2;
  const form = (0, import_vue.reactive)({
    ...restored ? restored.data : (0, import_es_toolkit2.cloneDeep)(defaults),
    isDirty: false,
    errors: restored ? restored.errors : {},
    hasErrors: false,
    processing: false,
    progress: null,
    wasSuccessful: false,
    recentlySuccessful: false,
    data() {
      return Object.keys(defaults).reduce((carry, key2) => {
        return (0, import_compat.set)(carry, key2, (0, import_compat.get)(this, key2));
      }, {});
    },
    transform(callback) {
      transform = callback;
      return this;
    },
    defaults(fieldOrFields, maybeValue) {
      if (typeof data === "function") {
        throw new Error("You cannot call `defaults()` when using a function to define your form data.");
      }
      if (typeof fieldOrFields === "undefined") {
        defaults = (0, import_es_toolkit2.cloneDeep)(this.data());
        this.isDirty = false;
      } else {
        defaults = typeof fieldOrFields === "string" ? (0, import_compat.set)((0, import_es_toolkit2.cloneDeep)(defaults), fieldOrFields, maybeValue) : Object.assign({}, (0, import_es_toolkit2.cloneDeep)(defaults), fieldOrFields);
      }
      return this;
    },
    reset(...fields) {
      const resolvedData = typeof data === "function" ? (0, import_es_toolkit2.cloneDeep)(data()) : (0, import_es_toolkit2.cloneDeep)(defaults);
      const clonedData = (0, import_es_toolkit2.cloneDeep)(resolvedData);
      if (fields.length === 0) {
        defaults = clonedData;
        Object.assign(this, resolvedData);
      } else {
        ;
        fields.filter((key2) => (0, import_compat.has)(clonedData, key2)).forEach((key2) => {
          (0, import_compat.set)(defaults, key2, (0, import_compat.get)(clonedData, key2));
          (0, import_compat.set)(this, key2, (0, import_compat.get)(resolvedData, key2));
        });
      }
      return this;
    },
    setError(fieldOrFields, maybeValue) {
      Object.assign(this.errors, typeof fieldOrFields === "string" ? { [fieldOrFields]: maybeValue } : fieldOrFields);
      this.hasErrors = Object.keys(this.errors).length > 0;
      return this;
    },
    clearErrors(...fields) {
      this.errors = Object.keys(this.errors).reduce(
        (carry, field) => ({
          ...carry,
          ...fields.length > 0 && !fields.includes(field) ? { [field]: this.errors[field] } : {}
        }),
        {}
      );
      this.hasErrors = Object.keys(this.errors).length > 0;
      return this;
    },
    resetAndClearErrors(...fields) {
      this.reset(...fields);
      this.clearErrors(...fields);
      return this;
    },
    submit(...args) {
      const objectPassed = typeof args[0] === "object";
      const method = objectPassed ? args[0].method : args[0];
      const url = objectPassed ? args[0].url : args[1];
      const options = (objectPassed ? args[1] : args[2]) ?? {};
      const data2 = transform(this.data());
      const _options = {
        ...options,
        onCancelToken: (token) => {
          cancelToken = token;
          if (options.onCancelToken) {
            return options.onCancelToken(token);
          }
        },
        onBefore: (visit) => {
          this.wasSuccessful = false;
          this.recentlySuccessful = false;
          clearTimeout(recentlySuccessfulTimeoutId);
          if (options.onBefore) {
            return options.onBefore(visit);
          }
        },
        onStart: (visit) => {
          this.processing = true;
          if (options.onStart) {
            return options.onStart(visit);
          }
        },
        onProgress: (event) => {
          this.progress = event;
          if (options.onProgress) {
            return options.onProgress(event);
          }
        },
        onSuccess: async (page2) => {
          this.processing = false;
          this.progress = null;
          this.clearErrors();
          this.wasSuccessful = true;
          this.recentlySuccessful = true;
          recentlySuccessfulTimeoutId = setTimeout(() => this.recentlySuccessful = false, 2e3);
          const onSuccess = options.onSuccess ? await options.onSuccess(page2) : null;
          defaults = (0, import_es_toolkit2.cloneDeep)(this.data());
          this.isDirty = false;
          return onSuccess;
        },
        onError: (errors) => {
          this.processing = false;
          this.progress = null;
          this.clearErrors().setError(errors);
          if (options.onError) {
            return options.onError(errors);
          }
        },
        onCancel: () => {
          this.processing = false;
          this.progress = null;
          if (options.onCancel) {
            return options.onCancel();
          }
        },
        onFinish: (visit) => {
          this.processing = false;
          this.progress = null;
          cancelToken = null;
          if (options.onFinish) {
            return options.onFinish(visit);
          }
        }
      };
      if (method === "delete") {
        import_core2.router.delete(url, { ..._options, data: data2 });
      } else {
        import_core2.router[method](url, data2, _options);
      }
    },
    get(url, options) {
      this.submit("get", url, options);
    },
    post(url, options) {
      this.submit("post", url, options);
    },
    put(url, options) {
      this.submit("put", url, options);
    },
    patch(url, options) {
      this.submit("patch", url, options);
    },
    delete(url, options) {
      this.submit("delete", url, options);
    },
    cancel() {
      if (cancelToken) {
        cancelToken.cancel();
      }
    },
    __rememberable: rememberKey === null,
    __remember() {
      return { data: this.data(), errors: this.errors };
    },
    __restore(restored2) {
      Object.assign(this, restored2.data);
      this.setError(restored2.errors);
    }
  });
  (0, import_vue.watch)(
    form,
    (newValue) => {
      form.isDirty = !(0, import_es_toolkit2.isEqual)(form.data(), defaults);
      if (rememberKey) {
        import_core2.router.remember((0, import_es_toolkit2.cloneDeep)(newValue.__remember()), rememberKey);
      }
    },
    { immediate: true, deep: true }
  );
  return form;
}

// src/app.ts
var component = (0, import_vue2.ref)(null);
var page = (0, import_vue2.ref)(null);
var layout = (0, import_vue2.shallowRef)(null);
var key = (0, import_vue2.ref)(null);
var headManager = null;
var App = (0, import_vue2.defineComponent)({
  name: "Inertia",
  props: {
    initialPage: {
      type: Object,
      required: true
    },
    initialComponent: {
      type: Object,
      required: false
    },
    resolveComponent: {
      type: Function,
      required: false
    },
    titleCallback: {
      type: Function,
      required: false,
      default: (title) => title
    },
    onHeadUpdate: {
      type: Function,
      required: false,
      default: () => () => {
      }
    }
  },
  setup({ initialPage, initialComponent, resolveComponent, titleCallback, onHeadUpdate }) {
    component.value = initialComponent ? (0, import_vue2.markRaw)(initialComponent) : null;
    page.value = initialPage;
    key.value = null;
    const isServer = typeof window === "undefined";
    headManager = (0, import_core3.createHeadManager)(isServer, titleCallback, onHeadUpdate);
    if (!isServer) {
      import_core3.router.init({
        initialPage,
        resolveComponent,
        swapComponent: async (args) => {
          component.value = (0, import_vue2.markRaw)(args.component);
          page.value = args.page;
          key.value = args.preserveState ? key.value : Date.now();
        }
      });
      import_core3.router.on("navigate", () => headManager.forceUpdate());
    }
    return () => {
      if (component.value) {
        component.value.inheritAttrs = !!component.value.inheritAttrs;
        const child = (0, import_vue2.h)(component.value, {
          ...page.value.props,
          key: key.value
        });
        if (layout.value) {
          component.value.layout = layout.value;
          layout.value = null;
        }
        if (component.value.layout) {
          if (typeof component.value.layout === "function") {
            return component.value.layout(import_vue2.h, child);
          }
          return (Array.isArray(component.value.layout) ? component.value.layout : [component.value.layout]).concat(child).reverse().reduce((child2, layout2) => {
            layout2.inheritAttrs = !!layout2.inheritAttrs;
            return (0, import_vue2.h)(layout2, { ...page.value.props }, () => child2);
          });
        }
        return child;
      }
    };
  }
});
var app_default = App;
var plugin = {
  install(app) {
    import_core3.router.form = useForm;
    Object.defineProperty(app.config.globalProperties, "$inertia", { get: () => import_core3.router });
    Object.defineProperty(app.config.globalProperties, "$page", { get: () => page.value });
    Object.defineProperty(app.config.globalProperties, "$headManager", { get: () => headManager });
    app.mixin(remember_default);
  }
};
function usePage() {
  return (0, import_vue2.reactive)({
    props: (0, import_vue2.computed)(() => page.value?.props),
    url: (0, import_vue2.computed)(() => page.value?.url),
    component: (0, import_vue2.computed)(() => page.value?.component),
    version: (0, import_vue2.computed)(() => page.value?.version),
    clearHistory: (0, import_vue2.computed)(() => page.value?.clearHistory),
    deferredProps: (0, import_vue2.computed)(() => page.value?.deferredProps),
    mergeProps: (0, import_vue2.computed)(() => page.value?.mergeProps),
    deepMergeProps: (0, import_vue2.computed)(() => page.value?.deepMergeProps),
    matchPropsOn: (0, import_vue2.computed)(() => page.value?.matchPropsOn),
    rememberedState: (0, import_vue2.computed)(() => page.value?.rememberedState),
    encryptHistory: (0, import_vue2.computed)(() => page.value?.encryptHistory)
  });
}

// src/createInertiaApp.ts
var import_core4 = require("@inertiajs/core");
var import_vue3 = require("vue");
async function createInertiaApp({
  id = "app",
  resolve,
  setup,
  title,
  progress = {},
  page: page2,
  render
}) {
  const isServer = typeof window === "undefined";
  const el = isServer ? null : document.getElementById(id);
  const initialPage = page2 || JSON.parse(el.dataset.page);
  const resolveComponent = (name) => Promise.resolve(resolve(name)).then((module2) => module2.default || module2);
  let head = [];
  const vueApp = await Promise.all([
    resolveComponent(initialPage.component),
    import_core4.router.decryptHistory().catch(() => {
    })
  ]).then(([initialComponent]) => {
    return setup({
      el,
      App: app_default,
      props: {
        initialPage,
        initialComponent,
        resolveComponent,
        titleCallback: title,
        onHeadUpdate: isServer ? (elements) => head = elements : null
      },
      plugin
    });
  });
  if (!isServer && progress) {
    (0, import_core4.setupProgress)(progress);
  }
  if (isServer) {
    const body = await render(
      (0, import_vue3.createSSRApp)({
        render: () => (0, import_vue3.h)("div", {
          id,
          "data-page": JSON.stringify(initialPage),
          innerHTML: vueApp ? render(vueApp) : ""
        })
      })
    );
    return { head, body };
  }
}

// src/deferred.ts
var import_vue4 = require("vue");
var deferred_default = (0, import_vue4.defineComponent)({
  name: "Deferred",
  props: {
    data: {
      type: [String, Array],
      required: true
    }
  },
  render() {
    const keys = Array.isArray(this.$props.data) ? this.$props.data : [this.$props.data];
    if (!this.$slots.fallback) {
      throw new Error("`<Deferred>` requires a `<template #fallback>` slot");
    }
    return keys.every((key2) => this.$page.props[key2] !== void 0) ? this.$slots.default() : this.$slots.fallback();
  }
});

// src/head.ts
var import_es_toolkit3 = require("es-toolkit");
var import_vue5 = require("vue");
var Head = (0, import_vue5.defineComponent)({
  props: {
    title: {
      type: String,
      required: false
    }
  },
  data() {
    return {
      provider: this.$headManager.createProvider()
    };
  },
  beforeUnmount() {
    this.provider.disconnect();
  },
  methods: {
    isUnaryTag(node) {
      return [
        "area",
        "base",
        "br",
        "col",
        "embed",
        "hr",
        "img",
        "input",
        "keygen",
        "link",
        "meta",
        "param",
        "source",
        "track",
        "wbr"
      ].indexOf(node.type) > -1;
    },
    renderTagStart(node) {
      node.props = node.props || {};
      node.props.inertia = node.props["head-key"] !== void 0 ? node.props["head-key"] : "";
      const attrs = Object.keys(node.props).reduce((carry, name) => {
        const value = String(node.props[name]);
        if (["key", "head-key"].includes(name)) {
          return carry;
        } else if (value === "") {
          return carry + ` ${name}`;
        } else {
          return carry + ` ${name}="${(0, import_es_toolkit3.escape)(value)}"`;
        }
      }, "");
      return `<${node.type}${attrs}>`;
    },
    renderTagChildren(node) {
      return typeof node.children === "string" ? node.children : node.children.reduce((html, child) => html + this.renderTag(child), "");
    },
    isFunctionNode(node) {
      return typeof node.type === "function";
    },
    isComponentNode(node) {
      return typeof node.type === "object";
    },
    isCommentNode(node) {
      return /(comment|cmt)/i.test(node.type.toString());
    },
    isFragmentNode(node) {
      return /(fragment|fgt|symbol\(\))/i.test(node.type.toString());
    },
    isTextNode(node) {
      return /(text|txt)/i.test(node.type.toString());
    },
    renderTag(node) {
      if (this.isTextNode(node)) {
        return node.children;
      } else if (this.isFragmentNode(node)) {
        return "";
      } else if (this.isCommentNode(node)) {
        return "";
      }
      let html = this.renderTagStart(node);
      if (node.children) {
        html += this.renderTagChildren(node);
      }
      if (!this.isUnaryTag(node)) {
        html += `</${node.type}>`;
      }
      return html;
    },
    addTitleElement(elements) {
      if (this.title && !elements.find((tag) => tag.startsWith("<title"))) {
        elements.push(`<title inertia>${this.title}</title>`);
      }
      return elements;
    },
    renderNodes(nodes) {
      return this.addTitleElement(
        nodes.flatMap((node) => this.resolveNode(node)).map((node) => this.renderTag(node)).filter((node) => node)
      );
    },
    resolveNode(node) {
      if (this.isFunctionNode(node)) {
        return this.resolveNode(node.type());
      } else if (this.isComponentNode(node)) {
        console.warn(`Using components in the <Head> component is not supported.`);
        return [];
      } else if (this.isTextNode(node) && node.children) {
        return node;
      } else if (this.isFragmentNode(node) && node.children) {
        return node.children.flatMap((child) => this.resolveNode(child));
      } else if (this.isCommentNode(node)) {
        return [];
      } else {
        return node;
      }
    }
  },
  render() {
    this.provider.update(this.renderNodes(this.$slots.default ? this.$slots.default() : []));
  }
});
var head_default = Head;

// src/link.ts
var import_core5 = require("@inertiajs/core");
var import_vue6 = require("vue");
var Link = (0, import_vue6.defineComponent)({
  name: "Link",
  props: {
    as: {
      type: String,
      default: "a"
    },
    data: {
      type: Object,
      default: () => ({})
    },
    href: {
      type: [String, Object],
      required: true
    },
    method: {
      type: String,
      default: "get"
    },
    replace: {
      type: Boolean,
      default: false
    },
    preserveScroll: {
      type: Boolean,
      default: false
    },
    preserveState: {
      type: Boolean,
      default: null
    },
    only: {
      type: Array,
      default: () => []
    },
    except: {
      type: Array,
      default: () => []
    },
    headers: {
      type: Object,
      default: () => ({})
    },
    queryStringArrayFormat: {
      type: String,
      default: "brackets"
    },
    async: {
      type: Boolean,
      default: false
    },
    prefetch: {
      type: [Boolean, String, Array],
      default: false
    },
    cacheFor: {
      type: [Number, String, Array],
      default: 0
    },
    onStart: {
      type: Function,
      default: (_visit) => {
      }
    },
    onProgress: {
      type: Function,
      default: () => {
      }
    },
    onFinish: {
      type: Function,
      default: () => {
      }
    },
    onBefore: {
      type: Function,
      default: () => {
      }
    },
    onCancel: {
      type: Function,
      default: () => {
      }
    },
    onSuccess: {
      type: Function,
      default: () => {
      }
    },
    onError: {
      type: Function,
      default: () => {
      }
    },
    onCancelToken: {
      type: Function,
      default: () => {
      }
    }
  },
  setup(props, { slots, attrs }) {
    const inFlightCount = (0, import_vue6.ref)(0);
    const hoverTimeout = (0, import_vue6.ref)(null);
    const prefetchModes = (0, import_vue6.computed)(() => {
      if (props.prefetch === true) {
        return ["hover"];
      }
      if (props.prefetch === false) {
        return [];
      }
      if (Array.isArray(props.prefetch)) {
        return props.prefetch;
      }
      return [props.prefetch];
    });
    const cacheForValue = (0, import_vue6.computed)(() => {
      if (props.cacheFor !== 0) {
        return props.cacheFor;
      }
      if (prefetchModes.value.length === 1 && prefetchModes.value[0] === "click") {
        return 0;
      }
      return 3e4;
    });
    (0, import_vue6.onMounted)(() => {
      if (prefetchModes.value.includes("mount")) {
        prefetch();
      }
    });
    (0, import_vue6.onUnmounted)(() => {
      clearTimeout(hoverTimeout.value);
    });
    const method = (0, import_vue6.computed)(
      () => typeof props.href === "object" ? props.href.method : props.method.toLowerCase()
    );
    const as = (0, import_vue6.computed)(() => method.value !== "get" ? "button" : props.as.toLowerCase());
    const mergeDataArray = (0, import_vue6.computed)(
      () => (0, import_core5.mergeDataIntoQueryString)(
        method.value,
        typeof props.href === "object" ? props.href.url : props.href || "",
        props.data,
        props.queryStringArrayFormat
      )
    );
    const href = (0, import_vue6.computed)(() => mergeDataArray.value[0]);
    const data = (0, import_vue6.computed)(() => mergeDataArray.value[1]);
    const elProps = (0, import_vue6.computed)(() => ({
      a: { href: href.value },
      button: { type: "button" }
    }));
    const baseParams = (0, import_vue6.computed)(() => ({
      data: data.value,
      method: method.value,
      replace: props.replace,
      preserveScroll: props.preserveScroll,
      preserveState: props.preserveState ?? method.value !== "get",
      only: props.only,
      except: props.except,
      headers: props.headers,
      async: props.async
    }));
    const visitParams = (0, import_vue6.computed)(() => ({
      ...baseParams.value,
      onCancelToken: props.onCancelToken,
      onBefore: props.onBefore,
      onStart: (event) => {
        inFlightCount.value++;
        props.onStart(event);
      },
      onProgress: props.onProgress,
      onFinish: (event) => {
        inFlightCount.value--;
        props.onFinish(event);
      },
      onCancel: props.onCancel,
      onSuccess: props.onSuccess,
      onError: props.onError
    }));
    const prefetch = () => {
      import_core5.router.prefetch(href.value, baseParams.value, { cacheFor: cacheForValue.value });
    };
    const regularEvents = {
      onClick: (event) => {
        if ((0, import_core5.shouldIntercept)(event)) {
          event.preventDefault();
          import_core5.router.visit(href.value, visitParams.value);
        }
      }
    };
    const prefetchHoverEvents = {
      onMouseenter: () => {
        hoverTimeout.value = setTimeout(() => {
          prefetch();
        }, 75);
      },
      onMouseleave: () => {
        clearTimeout(hoverTimeout.value);
      },
      onClick: regularEvents.onClick
    };
    const prefetchClickEvents = {
      onMousedown: (event) => {
        if ((0, import_core5.shouldIntercept)(event)) {
          event.preventDefault();
          prefetch();
        }
      },
      onMouseup: (event) => {
        event.preventDefault();
        import_core5.router.visit(href.value, visitParams.value);
      },
      onClick: (event) => {
        if ((0, import_core5.shouldIntercept)(event)) {
          event.preventDefault();
        }
      }
    };
    return () => {
      return (0, import_vue6.h)(
        as.value,
        {
          ...attrs,
          ...elProps.value[as.value] || {},
          "data-loading": inFlightCount.value > 0 ? "" : void 0,
          ...(() => {
            if (prefetchModes.value.includes("hover")) {
              return prefetchHoverEvents;
            }
            if (prefetchModes.value.includes("click")) {
              return prefetchClickEvents;
            }
            return regularEvents;
          })()
        },
        slots
      );
    };
  }
});
var link_default = Link;

// src/usePoll.ts
var import_core6 = require("@inertiajs/core");
var import_vue7 = require("vue");
function usePoll(interval, requestOptions = {}, options = {
  keepAlive: false,
  autoStart: true
}) {
  const { stop, start } = import_core6.router.poll(interval, requestOptions, {
    ...options,
    autoStart: false
  });
  (0, import_vue7.onMounted)(() => {
    if (options.autoStart ?? true) {
      start();
    }
  });
  (0, import_vue7.onUnmounted)(() => {
    stop();
  });
  return {
    stop,
    start
  };
}

// src/usePrefetch.ts
var import_core7 = require("@inertiajs/core");
var import_vue8 = require("vue");
function usePrefetch(options = {}) {
  const isPrefetching = (0, import_vue8.ref)(false);
  const lastUpdatedAt = (0, import_vue8.ref)(null);
  const isPrefetched = (0, import_vue8.ref)(false);
  const cached = typeof window === "undefined" ? null : import_core7.router.getCached(window.location.pathname, options);
  const inFlight = typeof window === "undefined" ? null : import_core7.router.getPrefetching(window.location.pathname, options);
  lastUpdatedAt.value = cached?.staleTimestamp || null;
  isPrefetching.value = inFlight !== null;
  isPrefetched.value = cached !== null;
  let onPrefetchedListener;
  let onPrefetchingListener;
  (0, import_vue8.onMounted)(() => {
    onPrefetchingListener = import_core7.router.on("prefetching", (e) => {
      if (e.detail.visit.url.pathname === window.location.pathname) {
        isPrefetching.value = true;
      }
    });
    onPrefetchedListener = import_core7.router.on("prefetched", (e) => {
      if (e.detail.visit.url.pathname === window.location.pathname) {
        isPrefetching.value = false;
        isPrefetched.value = true;
      }
    });
  });
  (0, import_vue8.onUnmounted)(() => {
    onPrefetchedListener();
    onPrefetchingListener();
  });
  return {
    lastUpdatedAt,
    isPrefetching,
    isPrefetched,
    flush: () => import_core7.router.flush(window.location.pathname, options)
  };
}

// src/useRemember.ts
var import_core8 = require("@inertiajs/core");
var import_es_toolkit4 = require("es-toolkit");
var import_vue9 = require("vue");
function useRemember(data, key2) {
  if (typeof data === "object" && data !== null && data.__rememberable === false) {
    return data;
  }
  const restored = import_core8.router.restore(key2);
  const type = (0, import_vue9.isReactive)(data) ? import_vue9.reactive : import_vue9.ref;
  const hasCallbacks = typeof data.__remember === "function" && typeof data.__restore === "function";
  const remembered = type(restored === void 0 ? data : hasCallbacks ? data.__restore(restored) : restored);
  (0, import_vue9.watch)(
    remembered,
    (newValue) => {
      import_core8.router.remember((0, import_es_toolkit4.cloneDeep)(hasCallbacks ? data.__remember() : newValue), key2);
    },
    { immediate: true, deep: true }
  );
  return remembered;
}

// src/whenVisible.ts
var import_core9 = require("@inertiajs/core");
var import_vue10 = require("vue");
var whenVisible_default = (0, import_vue10.defineComponent)({
  name: "WhenVisible",
  props: {
    data: {
      type: [String, Array]
    },
    params: {
      type: Object
    },
    buffer: {
      type: Number,
      default: 0
    },
    as: {
      type: String,
      default: "div"
    },
    always: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      loaded: false,
      fetching: false,
      observer: null
    };
  },
  unmounted() {
    this.observer?.disconnect();
  },
  mounted() {
    this.observer = new IntersectionObserver(
      (entries) => {
        if (!entries[0].isIntersecting) {
          return;
        }
        if (!this.$props.always) {
          this.observer.disconnect();
        }
        if (this.fetching) {
          return;
        }
        this.fetching = true;
        const reloadParams = this.getReloadParams();
        import_core9.router.reload({
          ...reloadParams,
          onStart: (e) => {
            this.fetching = true;
            reloadParams.onStart?.(e);
          },
          onFinish: (e) => {
            this.loaded = true;
            this.fetching = false;
            reloadParams.onFinish?.(e);
          }
        });
      },
      {
        rootMargin: `${this.$props.buffer}px`
      }
    );
    this.observer.observe(this.$el.nextSibling);
  },
  methods: {
    getReloadParams() {
      if (this.$props.data) {
        return {
          only: Array.isArray(this.$props.data) ? this.$props.data : [this.$props.data]
        };
      }
      if (!this.$props.params) {
        throw new Error("You must provide either a `data` or `params` prop.");
      }
      return this.$props.params;
    }
  },
  render() {
    const els = [];
    if (this.$props.always || !this.loaded) {
      els.push((0, import_vue10.h)(this.$props.as));
    }
    if (!this.loaded) {
      els.push(this.$slots.fallback ? this.$slots.fallback() : null);
    } else if (this.$slots.default) {
      els.push(this.$slots.default());
    }
    return els;
  }
});
//# sourceMappingURL=index.js.map
