import React, { useEffect } from "react";

const ClearCache: React.FC = () => {
  useEffect(() => {
    console.log("🧹 Limpando TUDO...");

    // Limpar localStorage
    localStorage.clear();
    console.log("✅ localStorage limpo");

    // Limpar sessionStorage
    sessionStorage.clear();
    console.log("✅ sessionStorage limpo");

    // Limpar cookies
    document.cookie.split(";").forEach((c) => {
      document.cookie = c
        .replace(/^ +/, "")
        .replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/");
    });
    console.log("✅ Cookies limpos");

    // Aguardar 1 segundo e redirecionar
    setTimeout(() => {
      console.log("🔄 Redirecionando para home...");
      window.location.href = "/";
    }, 1000);
  }, []);

  return (
    <div className="min-h-screen flex items-center justify-center bg-gradient-to-br from-blue-50 to-indigo-100">
      <div className="text-center p-8 bg-white rounded-xl shadow-2xl max-w-md">
        <div className="mb-6">
          <div className="animate-spin rounded-full h-16 w-16 border-b-4 border-blue-600 mx-auto"></div>
        </div>
        <h1 className="text-2xl font-bold text-gray-900 mb-2">
          🧹 Limpando Cache
        </h1>
        <p className="text-gray-600 mb-4">
          Removendo todas as sessões e dados armazenados...
        </p>
        <div className="space-y-2 text-sm text-gray-500">
          <p>✅ localStorage</p>
          <p>✅ sessionStorage</p>
          <p>✅ Cookies</p>
        </div>
        <p className="mt-6 text-xs text-gray-400">
          Você será redirecionado em instantes...
        </p>
      </div>
    </div>
  );
};

export default ClearCache;
