import {
    ADMIN_DASHBOARD_URL,
    CLIENTS_DASHBOARD_URL,
    PATIENT_DASHBOARD_URL,
    REGISTER_URL
} from "@/lib/constants";
import Link from "next/link";
import LoginForm from "@/app/(auth)/_components/LoginForm";
import {redirect} from "next/navigation";
import {UserType} from "@/lib/backend/appwrite_types";
import {useAuth} from "@/lib/hooks/useAuth";

export default async function Login() {
    const {userProfile} = await useAuth();
    if (userProfile) {
        switch (userProfile.userType) {
            case UserType.ADMIN:
                redirect(ADMIN_DASHBOARD_URL)
                return;
            case UserType.PATIENT:
                redirect(PATIENT_DASHBOARD_URL)
                return;
            default:
                redirect(CLIENTS_DASHBOARD_URL)
        }

    }

    return (
        <div
            className="my-4 container-auto w-full max-w-sm p-4 bg-white border border-gray-200 rounded-lg shadow sm:p-6 md:p-8 dark:bg-gray-800 dark:border-gray-700">
            <div className="space-y-6">
                <h5 className="text-xl font-bold text-green-950 dark:text-white">Sign in to LulamaChat</h5>

                <LoginForm />

                <div className="text-sm font-medium text-gray-500 dark:text-gray-300">
                    Not registered? <Link
                    href={REGISTER_URL} className="text-green-700 hover:underline dark:text-green-500">Create
                    account</Link>
                </div>
            </div>
        </div>
    )
}