import { NextResponse } from "next/server"
import { getSessionUser } from "@/lib/auth"
import { query } from "@/lib/db"

export async function GET() {
  try {
    const user = await getSessionUser()
    if (!user) return NextResponse.json({ error: "Unauthorized" }, { status: 401 })

    const result = await query(
      "SELECT id, name, color, sort_order FROM project_statuses WHERE is_active = true ORDER BY sort_order"
    )
    return NextResponse.json(result.rows)
  } catch (error) {
    console.error("Project statuses API error:", error)
    return NextResponse.json({ error: "Failed to load statuses" }, { status: 500 })
  }
}
