import { useState, useEffect } from "react";
import { useAuth } from "@/client/components/auth-provider";
import { LoginForm } from "@/client/components/login-form";
import { UserProfile } from "@/client/components/user-profile";
import { BookingForm } from "@/client/components/booking-form";
import { AdminTreatments } from "@/client/components/admin-treatments";
import { AdminBookings } from "@/client/components/admin-bookings";
import { AdminCalendar } from "@/client/components/admin-calendar";
import { InitialDataLoader } from "@/client/components/initial-data-loader";
import { AdminAvailability } from "@/client/components/admin-availability";
import CancellationPage from "@/client/components/cancellation-page";
import LegalPage from "@/client/components/legal-page";
function App() {
const { user, isLoading, isOwner } = useAuth();
const [activeTab, setActiveTab] = useState<"booking" | "admin-treatments" | "admin-bookings" | "admin-calendar" | "admin-availability" | "profile" | "legal">("booking");
// Check for cancellation token in URL
useEffect(() => {
const path = window.location.pathname;
if (path.startsWith('/cancel/')) {
const token = path.split('/cancel/')[1];
if (token) {
// Set a special state to show cancellation page
setActiveTab("cancellation" as any);
return;
}
}
}, []);
// Handle cancellation page
const path = window.location.pathname;
if (path.startsWith('/cancel/')) {
const token = path.split('/cancel/')[1];
if (token) {
return ;
}
}
// Show loading spinner while checking authentication
if (isLoading) {
return (
Lade...
);
}
// Show login form if user is not authenticated and trying to access admin features
const needsAuth = !user && (activeTab === "admin-treatments" || activeTab === "admin-bookings" || activeTab === "admin-calendar" || activeTab === "admin-availability" || activeTab === "profile");
if (needsAuth) {
return ;
}
// Show legal page if legal tab is active
if (activeTab === "legal") {
return ;
}
const tabs = [
{ id: "booking", label: "Termin buchen", icon: "📅", requiresAuth: false },
{ id: "legal", label: "Impressum/Datenschutz", icon: "📋", requiresAuth: false },
{ id: "admin-treatments", label: "Behandlungen verwalten", icon: "💅", requiresAuth: true },
{ id: "admin-bookings", label: "Buchungen verwalten", icon: "📋", requiresAuth: true },
{ id: "admin-calendar", label: "Kalender", icon: "📆", requiresAuth: true },
{ id: "admin-availability", label: "Verfügbarkeiten", icon: "⏰", requiresAuth: true },
...(user ? [{ id: "profile", label: "Profil", icon: "👤", requiresAuth: true }] : []),
] as const;
return (
{/* Header */}
setActiveTab("booking")}
>
Stargirlnails Kiel
Professional Nail Design & Care
{user && (
Willkommen, {user.username}
{isOwner && (
Inhaber
)}
)}
{/* Navigation */}
{/* Main Content */}
{activeTab === "booking" && (
Buche deine perfekte Nagelbehandlung
Erlebe professionelle Nagelpflege mit unseren Experten.
Wähle aus unserem breiten Angebot an Behandlungen und buche noch heute deinen Termin.
)}
{activeTab === "admin-treatments" && isOwner && (
Behandlungen verwalten
Füge Behandlungen hinzu, bearbeite und verwalte deine Nagelbehandlungen.
)}
{activeTab === "admin-bookings" && isOwner && (
Buchungen verwalten
Sieh dir Kundentermine an und verwalte Buchungen.
)}
{activeTab === "admin-calendar" && isOwner && (
Kalender - Bevorstehende Buchungen
Übersichtliche Darstellung aller bevorstehenden Termine im Kalenderformat.
)}
{activeTab === "admin-availability" && isOwner && (
Verfügbarkeiten verwalten
Lege freie Slots an und entferne sie bei Bedarf.
)}
{activeTab === "profile" && user && (
Benutzerprofil
Verwalte deine Kontoinformationen und Einstellungen.
)}
{/* Footer */}
);
}
export default App;