import { s as __toESM } from "./chunk-BNovOVIE.js";
import { _ as Logger } from "./button-Dj4BTre0.js";
import { t as require_react } from "./react-DA-nE2FX.js";
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
import { u as createLucideIcon } from "./dist-D3ZI9nhS.js";
require_compiler_runtime(), require_react();
var TOAST_LIMIT = 1, TOAST_REMOVE_DELAY = 1e4, count = 0;
function genId() {
  return count = (count + 1) % Number.MAX_VALUE, count.toString();
}
var toastTimeouts = /* @__PURE__ */ new Map(), addToRemoveQueue = (e) => {
  if (toastTimeouts.has(e)) return;
  let p = setTimeout(() => {
    toastTimeouts.delete(e), dispatch({
      type: "REMOVE_TOAST",
      toastId: e
    });
  }, TOAST_REMOVE_DELAY);
  toastTimeouts.set(e, p);
};
const reducer = (e, p) => {
  switch (p.type) {
    case "ADD_TOAST":
      return {
        ...e,
        toasts: [p.toast, ...e.toasts].slice(0, TOAST_LIMIT)
      };
    case "UPDATE_TOAST":
      return {
        ...e,
        toasts: e.toasts.map((e2) => e2.id === p.toast.id ? {
          ...e2,
          ...p.toast
        } : e2)
      };
    case "DISMISS_TOAST": {
      let { toastId: m } = p;
      return m ? addToRemoveQueue(m) : e.toasts.forEach((e2) => {
        addToRemoveQueue(e2.id);
      }), {
        ...e,
        toasts: e.toasts.map((e2) => e2.id === m || m === void 0 ? {
          ...e2,
          open: false
        } : e2)
      };
    }
    case "REMOVE_TOAST":
      return p.toastId === void 0 ? {
        ...e,
        toasts: []
      } : {
        ...e,
        toasts: e.toasts.filter((e2) => e2.id !== p.toastId)
      };
    case "UPSERT_TOAST":
      return e.toasts.findIndex((e2) => e2.id === p.toast.id) > -1 ? {
        ...e,
        toasts: e.toasts.map((e2) => e2.id === p.toast.id ? {
          ...e2,
          ...p.toast
        } : e2)
      } : {
        ...e,
        toasts: [p.toast, ...e.toasts].slice(0, TOAST_LIMIT)
      };
  }
};
var listeners = /* @__PURE__ */ new Set(), memoryState = { toasts: [] };
function dispatch(e) {
  memoryState = reducer(memoryState, e), listeners.forEach((e2) => {
    e2(memoryState);
  });
}
function toast({ id: e, ...p }) {
  let m = e || genId(), h = (e2) => dispatch({
    type: "UPDATE_TOAST",
    toast: {
      ...e2,
      id: m
    }
  }), g = () => dispatch({
    type: "DISMISS_TOAST",
    toastId: m
  }), _ = (e2) => dispatch({
    type: "UPSERT_TOAST",
    toast: {
      ...e2,
      id: m,
      open: true,
      onOpenChange: (e3) => {
        e3 || g();
      }
    }
  });
  return dispatch({
    type: "ADD_TOAST",
    toast: {
      ...p,
      id: m,
      open: true,
      onOpenChange: (e2) => {
        e2 || g();
      }
    }
  }), {
    id: m,
    dismiss: g,
    update: h,
    upsert: _
  };
}
var Copy = createLucideIcon("copy", [["rect", {
  width: "14",
  height: "14",
  x: "8",
  y: "8",
  rx: "2",
  ry: "2",
  key: "17jyea"
}], ["path", {
  d: "M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",
  key: "zix9uf"
}]]);
async function copyToClipboard(e, m) {
  if (navigator.clipboard === void 0) {
    Logger.warn("navigator.clipboard is not supported"), window.prompt("Copy to clipboard: Ctrl+C, Enter", e);
    return;
  }
  if (m && navigator.clipboard.write) try {
    let p = new ClipboardItem({
      "text/html": new Blob([m], { type: "text/html" }),
      "text/plain": new Blob([e], { type: "text/plain" })
    });
    await navigator.clipboard.write([p]);
    return;
  } catch {
    Logger.warn("Failed to write rich text, falling back to plain text");
  }
  await navigator.clipboard.writeText(e).catch(() => {
    Logger.warn("Failed to copy to clipboard using navigator.clipboard"), window.prompt("Copy to clipboard: Ctrl+C, Enter", e);
  });
}
export {
  Copy as n,
  toast as r,
  copyToClipboard as t
};
