import type { Metadata } from "next";
import { prisma } from "@/lib/prisma";

export const metadata: Metadata = {
    title: "Volunteer",
    description:
        "Find upcoming volunteer opportunities with the South Forsyth Middle School PTO — sign up to help with events, dances, and school programs.",
};

export default async function VolunteerPage() {
    const opportunities = await prisma.volunteerOpportunity.findMany({
        orderBy: { date: 'asc' }
    });

    return (
        <div className="container" style={{ padding: "4rem 1.5rem" }}>
            <div className="animate-fade-in">
                <h1 style={{ fontSize: "3rem", marginBottom: "1rem" }}>Volunteer with Us</h1>
                <p style={{ color: "var(--text-muted)", fontSize: "1.2rem", marginBottom: "2rem", maxWidth: "800px" }}>
                    We could not do what we do without the amazing support of parent volunteers. Sign up below for upcoming events.
                </p>

                <div className="glass-panel" style={{ padding: "2rem", marginBottom: "3rem", borderLeft: "4px solid var(--primary)", background: "rgba(14, 165, 233, 0.05)" }}>
                    <h2 style={{ fontSize: "1.5rem", marginBottom: "1rem", color: "var(--primary)" }}>SFMS District Requirements</h2>
                    <ul style={{ color: "var(--foreground)", paddingLeft: "1.5rem", lineHeight: 1.6, marginBottom: "1.5rem", display: "flex", flexDirection: "column", gap: "0.5rem" }}>
                        <li>Please read through the <a href="https://sfms.forsyth.k12.ga.us/fs/resource-manager/view/bd829580-a642-4e1e-9c2e-0f743ba21358" target="_blank" rel="noopener noreferrer" style={{ color: "var(--primary)", textDecoration: "underline", fontWeight: 500 }}>FCS Student Code of Conduct</a>.</li>
                        <li>After reading the handbook, please view the <a href="https://www.youtube.com/watch?v=c30rJpRrd5k" target="_blank" rel="noopener noreferrer" style={{ color: "var(--primary)", textDecoration: "underline", fontWeight: 500 }}>FCS Mandated Reporter Video</a>.</li>
                        <li>On the day you are scheduled to come in, you will be required to show a driver&apos;s license and sign a confidentiality agreement.</li>
                    </ul>
                    <a href="https://sfms.forsyth.k12.ga.us/families-partners/sfms-volunteers" target="_blank" rel="noopener noreferrer" className="btn-primary" style={{ padding: "0.6rem 1.2rem", fontSize: "0.95rem", display: "inline-flex", alignItems: "center", gap: "0.5rem" }}>
                        View Official SFMS Volunteer Page ↗
                    </a>
                </div>
            </div>

            {opportunities.length === 0 ? (
                <div style={{ textAlign: "center", padding: "4rem", border: "1px dashed var(--border)", borderRadius: "16px", color: "var(--text-muted)" }}>
                    <p>No volunteer opportunities at this time. Thank you for your interest!</p>
                </div>
            ) : (
                <div style={{ display: "flex", flexDirection: "column", gap: "1.5rem" }}>
                    {opportunities.map((opp, i) => (
                        <div key={opp.id} className="glass-panel animate-fade-in" style={{ padding: "2rem", display: "flex", flexWrap: "wrap", gap: "2rem", alignItems: "center", justifyContent: "space-between", animationDelay: `${i * 0.1}s` }}>
                            <div style={{ flex: 1, minWidth: "300px" }}>
                                <div style={{ display: "flex", gap: "1rem", alignItems: "center", marginBottom: "0.75rem" }}>
                                    <h2 style={{ fontSize: "1.5rem", margin: 0 }}>{opp.title}</h2>
                                    {opp.date && new Date(opp.date) > new Date() && (
                                        <span style={{ fontSize: "0.8rem", fontWeight: 700, background: "rgba(16, 185, 129, 0.1)", color: "#064e3b", padding: "0.2rem 0.6rem", borderRadius: "9999px" }}>Upcoming</span>
                                    )}
                                </div>
                                <p style={{ color: "var(--text-muted)", marginBottom: "1rem" }}>{opp.description}</p>
                                <div style={{ display: "flex", gap: "1.5rem", fontSize: "0.9rem", color: "var(--text-muted)", fontWeight: 500 }}>
                                    {opp.date && (
                                        <span style={{ display: "flex", alignItems: "center", gap: "0.5rem" }}>🗓 {new Date(opp.date).toLocaleDateString()}</span>
                                    )}
                                    {opp.location && (
                                        <span style={{ display: "flex", alignItems: "center", gap: "0.5rem" }}>📍 {opp.location}</span>
                                    )}
                                </div>
                            </div>
                            <a href={`/volunteer/${opp.id}`} className="hover-card" style={{ display: "inline-flex", alignItems: "center", justifyContent: "center", gap: "0.5rem", padding: "0.75rem 2rem", background: "#065f46", color: "#fff", borderRadius: "9999px", fontWeight: 600, transition: "transform 0.2s, box-shadow 0.2s" }}>
                                Sign Up
                            </a>
                        </div>
                    ))}
                </div>
            )}
        </div>
    );
}
