'use client'; import { Suspense, useEffect, useState } from 'react'; import { useRouter, useSearchParams } from 'next/navigation'; import { logoUrl } from '@/lib/assets'; import Navbar from '@/components/Navbar'; import Footer from '@/components/Footer'; import { useLanguage } from '@/lib/language-context'; import { getTranslation } from '@/lib/translations'; import { motion, AnimatePresence } from 'framer-motion'; import { User, Lock, MapPin, LogIn, Phone, MessageCircle } from 'lucide-react'; type LoginTab = 'customer' | 'staff'; function GoogleIcon({ className }: { className?: string }) { return ( ); } function LoginPageContent() { const router = useRouter(); const searchParams = useSearchParams(); const { language } = useLanguage(); const t = getTranslation(language); const initialTab = searchParams.get('tab') === 'staff' ? 'staff' : 'customer'; const [activeTab, setActiveTab] = useState(initialTab); const [formData, setFormData] = useState({ username: '', password: '', site: '' }); const [isSubmitted, setIsSubmitted] = useState(false); const [loginError, setLoginError] = useState(''); const [isSubmitting, setIsSubmitting] = useState(false); const [customerError, setCustomerError] = useState(''); useEffect(() => { const tab = searchParams.get('tab'); if (tab === 'staff' || tab === 'customer') { setActiveTab(tab); } const error = searchParams.get('error'); if (error) { const errorMessages: Record = { google_not_configured: t.auth.customer.notConfigured, google_denied: t.auth.customer.googleDenied, google_failed: t.auth.customer.googleFailed, invalid_state: t.auth.customer.googleFailed, missing_code: t.auth.customer.googleFailed, }; setCustomerError(errorMessages[error] ?? t.auth.customer.googleFailed); setActiveTab('customer'); } }, [searchParams, t.auth.customer]); useEffect(() => { const checkCustomerSession = async () => { try { const response = await fetch('/api/auth/customer/session', { cache: 'no-store' }); const data = (await response.json()) as { authenticated: boolean }; if (data.authenticated) { router.replace('/account'); } } catch { // Stay on login page. } }; void checkCustomerSession(); }, [router]); const handleChange = (e: React.ChangeEvent) => { const { name, value } = e.target; setFormData((prev) => ({ ...prev, [name]: value })); }; const handleStaffSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoginError(''); setIsSubmitting(true); try { const response = await fetch('/api/admin/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username: formData.username, password: formData.password, }), }); if (response.ok) { setLoginError(t.auth.accessDenied); return; } if (formData.username.trim() === 'admin') { setLoginError(t.auth.accessDenied); return; } setIsSubmitted(true); } catch { setLoginError('Could not sign in right now. Please try again.'); } finally { setIsSubmitting(false); } }; const resetStaffForm = () => { setFormData({ username: '', password: '', site: '' }); setIsSubmitted(false); setLoginError(''); }; const handleGoogleSignIn = () => { setCustomerError(''); const returnTo = searchParams.get('returnTo'); const authUrl = returnTo && returnTo.startsWith('/') && !returnTo.startsWith('//') ? `/api/auth/google?returnTo=${encodeURIComponent(returnTo)}` : '/api/auth/google'; window.location.href = authUrl; }; const panelTitle = activeTab === 'customer' ? t.auth.customer.title : t.auth.title; const panelSubtitle = activeTab === 'customer' ? t.auth.customer.subtitle : t.auth.subtitle; const panelBadge = activeTab === 'customer' ? t.auth.customer.badge : 'STAFF PORTAL'; return (
{panelBadge}

{panelTitle}

{panelSubtitle}

Shahi Kitchen
Shahi
Kitchen
{activeTab === 'customer' ? 'CUSTOMER ACCESS' : 'STAFF ACCESS'}

Two locations serving Shahi Indian & Pakistani hospitality in Gothenburg since 2016.

ASKIM • BACKAPLAN
Shahi Kitchen
{(['customer', 'staff'] as const).map((tab) => ( ))}
{activeTab === 'customer' ? ( {customerError && (

{customerError}

)}

{t.auth.customer.footerNote}

) : !isSubmitted ? (

Select the location you are working at today.

{loginError && (

{loginError}

)}

{t.auth.footerNote}

) : (

{t.auth.construction.title}

{t.auth.construction.message}

We appreciate your patience while we build a seamless experience.

)}

SHAHI KITCHEN • GOTHENBURG • EST 2016

); } export default function LoginPage() { return ( Loading… } > ); }