"use client";

import { useEffect } from "react";

declare global {
  interface Window {
    AgentaBug?: boolean;
  }
}

export default function FeedbackButton() {
  useEffect(() => {
    if (typeof window === "undefined") return;
    if (window.AgentaBug || document.getElementById("feedback-btn-fixed")) return;

    const btn = document.createElement("button");
    btn.id = "feedback-btn-fixed";
    btn.innerHTML = "💬";
    btn.title = "Click to leave feedback";
    btn.style.cssText =
      "position: fixed; bottom: 20px; right: 20px; width: 48px; height: 48px; border-radius: 50%; background: #2563eb; color: white; border: none; cursor: pointer; font-size: 22px; z-index: 99999; box-shadow: 0 4px 12px rgba(0,0,0,0.2);";

    btn.onmouseenter = () => {
      btn.style.transform = "scale(1.1)";
    };
    btn.onmouseleave = () => {
      btn.style.transform = "scale(1)";
    };

    btn.onclick = () => {
      const note = prompt("What would you like to change or improve?");
      if (note) {
        alert("Thank you! Your feedback: " + note + "\n\n(This is a placeholder - proper feedback tool coming soon)");
      }
    };

    document.body.appendChild(btn);
    window.AgentaBug = true;
  }, []);

  return null;
}