"use client";

import CookieConsent from "react-cookie-consent";
import { useEffect, useState } from "react";
import { getCurrentLocale, type SupportedLocale } from "../../lib/locale";

const copy: Record<SupportedLocale, { button: string; text: string }> = {
  pl: {
    button: "Akceptuję",
    text: "Używamy plików cookies, aby poprawić Twoje doświadczenia na stronie.",
  },
  en: {
    button: "Accept",
    text: "We use cookies to improve your experience on our website.",
  },
  de: {
    button: "Akzeptieren",
    text: "Wir verwenden Cookies, um Ihre Erfahrung auf unserer Website zu verbessern.",
  },
};

export default function ClientCookieConsent() {
  const [locale, setLocale] = useState<SupportedLocale>("pl");

  useEffect(() => {
    setLocale(getCurrentLocale());
  }, []);

  return (
    <CookieConsent
      location="bottom"
      buttonText={copy[locale].button}
      cookieName="cookieConsent"
      style={{ background: "#1f1f1f", color: "#fff" }}
      buttonStyle={{
        background: "#eea71f",
        color: "#000",
        fontWeight: "bold",
        borderRadius: "9999px",
        padding: "8px 16px",
      }}
      expires={365}
    >
      {copy[locale].text}
    </CookieConsent>
  );
}
