"use client"; import { Suspense, useEffect, useState } from "react"; import { useSearchParams } from "next/navigation"; import { useTranslation } from "@/i18n/navigation"; import Footer from "@/app/components/Footer"; import { apiFetch } from "@/app/lib/api-client"; type FeedbackType = "suggestion" | "bug" | "report"; function FeedbackForm() { const { t } = useTranslation("feedback"); const searchParams = useSearchParams(); const initialType = searchParams.get("type") === "report" ? "report" : "suggestion"; const reportTarget = searchParams.get("target") || ""; const [submitted, setSubmitted] = useState(false); const [form, setForm] = useState({ type: initialType as FeedbackType, email: "", title: "", content: "", targetId: reportTarget, }); useEffect(() => { if (reportTarget) { setForm((prev) => ({ ...prev, type: "report", targetId: reportTarget, title: prev.title || t("reportTitle").replace("{target}", reportTarget), content: prev.content || t("reportContent").replace("{target}", reportTarget), })); } }, [reportTarget, t]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); await apiFetch("/api/feedback", { method: "POST", body: JSON.stringify(form), }); setSubmitted(true); }; return (

{form.type === "report" ? t("reportPageTitle") : t("title")}

{form.type === "report" ? t("reportPageSubtitle") : t("subtitle")}

{submitted ? (
🙏

{t("successTitle")}

{t("successDesc")}

) : (
{(["suggestion", "bug", "report"] as FeedbackType[]).map((type) => ( ))}
{form.type === "report" && form.targetId ? (
{t("reportTargetLabel")}: {form.targetId}
) : null}
setForm((f) => ({ ...f, email: e.target.value }))} placeholder={t("emailPlaceholder")} className="w-full rounded-xl border border-gray-200 bg-white px-4 py-3 text-gray-900 placeholder-gray-400 focus:border-[#ff4d4f] focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100" />
setForm((f) => ({ ...f, title: e.target.value }))} placeholder={t("titlePlaceholder")} className="w-full rounded-xl border border-gray-200 bg-white px-4 py-3 text-gray-900 placeholder-gray-400 focus:border-[#ff4d4f] focus:outline-none focus:ring-2 focus:ring-[#ff4d4f]/20 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-100" />