// src/copy-action.ts
var copyAction = (node) => {
  const handleClick = (event) => {
    const target = event.target;
    const button = target.closest("button.copy");
    if (button) {
      const codeText = button.getAttribute("data-code");
      if (codeText) {
        navigator.clipboard.writeText(codeText).then(() => {
          button.classList.add("copied");
          setTimeout(() => {
            button.classList.remove("copied");
          }, 2000);
        }).catch((err) => {
          console.error("Failed to copy code:", err);
        });
      } else {
        const codeBlock = button.closest(".mdsvex-shiki")?.querySelector("code");
        if (codeBlock) {
          navigator.clipboard.writeText(codeBlock.textContent || "").then(() => {
            button.classList.add("copied");
            setTimeout(() => {
              button.classList.remove("copied");
            }, 2000);
          }).catch((err) => {
            console.error("Failed to copy code:", err);
          });
        }
      }
    }
  };
  node.addEventListener("click", handleClick);
  return {
    destroy() {
      node.removeEventListener("click", handleClick);
    }
  };
};
export {
  copyAction
};
