import { useState, useEffect } from "react";
import { useNavigate, useSearchParams } from "react-router-dom";
import { motion } from "framer-motion";
import logoText from "@/assets/logo-text.png";
import flourishLogo from "@/assets/flourish-logo.png";
import Assessment from "@/components/Assessment";
import Results from "@/components/Results";
import { Button } from "@/components/ui/button";
import { Heart, BookOpen, Users, Shield, LogIn, LayoutDashboard } from "lucide-react";
import { useAuth } from "@/contexts/AuthContext";
import { supabase } from "@/integrations/supabase/client";
import { disciplines } from "@/data/assessmentData";
import { useToast } from "@/hooks/use-toast";
import DisciplineIcon from "@/components/DisciplineIcon";
type View = "landing" | "assessment" | "results";
const disciplineGrid = [
{ id: "bible-study", name: "Bible Study" },
{ id: "scripture-memory", name: "Scripture Memory" },
{ id: "prayer-fasting", name: "Prayer & Fasting" },
{ id: "witness-testimony", name: "Witness & Testimony" },
{ id: "solitude-silence", name: "Solitude & Silence" },
{ id: "worship", name: "Worship" },
{ id: "sabbath-rest", name: "Sabbath & Rest" },
{ id: "giving-generosity", name: "Giving & Generosity" },
{ id: "confession", name: "Confession" },
{ id: "fellowship-community", name: "Fellowship" },
{ id: "stewardship-simplicity", name: "Stewardship" },
{ id: "spiritual-gifts", name: "Spiritual Gifts" },
];
const fadeUp = {
hidden: { opacity: 0, y: 24 },
show: (i: number) => ({
opacity: 1,
y: 0,
transition: { duration: 0.5, delay: i * 0.1 },
}),
};
const Index = () => {
const [searchParams, setSearchParams] = useSearchParams();
const [view, setView] = useState(searchParams.get("start") === "assessment" ? "assessment" : "landing");
const [scores, setScores] = useState>({});
const { user } = useAuth();
const navigate = useNavigate();
const { toast } = useToast();
useEffect(() => {
if (searchParams.get("start") === "assessment") {
searchParams.delete("start");
setSearchParams(searchParams, { replace: true });
}
}, []);
const handleComplete = async (finalScores: Record) => {
setScores(finalScores);
setView("results");
window.scrollTo(0, 0);
if (user) {
const overallAvg =
Object.values(finalScores).reduce(
(sum, s) => sum + s.reduce((a, b) => a + b, 0) / s.length,
0
) / disciplines.length;
const { error } = await supabase.from("assessment_results").insert({
user_id: user.id,
scores: finalScores,
overall_score: parseFloat(overallAvg.toFixed(1)),
});
if (error) {
toast({ title: "Error saving results", description: error.message, variant: "destructive" });
} else {
toast({ title: "Results saved!", description: "View your history in the dashboard." });
}
}
};
const handleRetake = () => {
setScores({});
setView("assessment");
window.scrollTo(0, 0);
};
if (view === "assessment") {
return (
);
}
if (view === "results") {
return (
);
}
return (
setView("landing")}>
{user ? (
) : (
)}
setView("landing")}>
{user ? (
) : (
)}
{/* Hero */}
Spiritual Health Assessment
"Examine yourselves to see whether you are in the faith; test yourselves."
— 2 Corinthians 13:5
{/* How It Works */}
How It Works
{/* Disciplines Preview */}
Areas We'll Explore
Each discipline is rooted in Scripture and essential to a healthy, sustainable walk with Christ.
{/* CTA */}
{/* Footer */}
);
};
export default Index;
{user ? (
) : (
)}
{[
{ icon: BookOpen, title: "12 Spiritual Areas", desc: "Assess your growth across key areas of the Christian life — from Bible study to spiritual gifts, from prayer to generosity." },
{ icon: Heart, title: "Honest Self-Reflection", desc: "Rate yourself on 53 questions grounded in Scripture. This isn't a test to pass — it's a mirror for your soul." },
{ icon: Shield, title: "Personalized Next Steps", desc: "Receive tailored recommendations and burnout warnings to help you keep growing — without running on empty." },
].map((item, i) => (
))}
{item.title}
{item.desc}
{disciplineGrid.map((d, i) => (
{d.name}
))}
Ready to Check Your Pulse?
This assessment takes about 10 minutes. Be honest — growth starts with awareness.
testing
Driven by curiosity and built on purpose, this is where bold thinking meets thoughtful execution. Let’s create something meaningful together.