import React, { useState, useEffect } from "react";
import { Navbar } from "./components/Navbar";
import { Home } from "./pages/Home";
import { Dashboard } from "./pages/Dashboard";
import { Login } from "./pages/Login";
import { Register } from "./pages/Register";
import { CalendarPage } from "./pages/Calendar";
import { TeamPage } from "./pages/Team";
import { FinancePage } from "./pages/Finance";
import { SettingsPage } from "./pages/Settings";
import { AlbumsPage } from "./pages/Albums";
import { AuthProvider, useAuth } from "./contexts/AuthContext";
import { DataProvider } from "./contexts/DataContext";
import { Construction } from "lucide-react";

const AppContent: React.FC = () => {
  const { user } = useAuth();
  const [currentPage, setCurrentPage] = useState("home");

  useEffect(() => {
    if (user && currentPage === "login") {
      setCurrentPage("dashboard");
    }
  }, [user, currentPage]);

  const renderPage = () => {
    if (currentPage === "home")
      return (
        <Home onEnter={() => setCurrentPage(user ? "dashboard" : "login")} />
      );
    if (currentPage === "login") return user ? <Dashboard /> : <Login />;
    if (currentPage === "register") return user ? <Dashboard /> : <Register onNavigate={setCurrentPage} />;

    if (!user) return <Login />;

    switch (currentPage) {
      case "dashboard":
      case "events":
        return <Dashboard initialView="list" />;

      case "request-event":
        return <Dashboard initialView="create" />;

      case "uploads":
        return <Dashboard initialView="uploads" />;

      case "calendar":
        return <CalendarPage />;

      case "team":
        return <TeamPage />;

      case "finance":
        return <FinancePage />;

      case "settings":
        return <SettingsPage />;

      case "albums":
        return <AlbumsPage />;

      default:
        return <Dashboard initialView="list" />;
    }
  };

  return (
    <div className="min-h-screen bg-white">
      <Navbar onNavigate={setCurrentPage} currentPage={currentPage} />
      <main>{renderPage()}</main>

      {currentPage === "home" && (
        <footer className="bg-white border-t border-gray-100 py-12">
          <div className="max-w-7xl mx-auto px-4 flex flex-col md:flex-row justify-between items-center text-sm text-gray-500">
            <p>&copy; 2025 PhotumFormaturas. Todos os direitos reservados.</p>
            <div className="flex space-x-6 mt-4 md:mt-0">
              <a href="#" className="hover:text-brand-black">
                Política de Privacidade
              </a>
              <a href="#" className="hover:text-brand-black">
                Termos de Uso
              </a>
              <a href="#" className="hover:text-brand-black">
                Instagram
              </a>
            </div>
          </div>
        </footer>
      )}
    </div>
  );
};

function App() {
  return (
    <AuthProvider>
      <DataProvider>
        <AppContent />
      </DataProvider>
    </AuthProvider>
  );
}

export default App;
