import { createServerComponentClient } from "@supabase/auth-helpers-nextjs";
import { Database } from "@/types/supabase";
import { cookies } from "next/headers";
import { redirect } from "next/navigation";
import prisma from "@/lib/prisma";

async function getSession(supabase: any) {
  const {
    data: { session },
  } = await supabase.auth.getSession();
  return session;
}

async function fetchFeatures(projectID: string) {
  const supabase = createServerComponentClient<Database>({ cookies });
  const session = await getSession(supabase);

  if (!session) redirect("/auth");

  try {
    // TODO: fetch all features in this project
  } catch (err) {
    console.error(err);
  }
}

export async function FeatureList({ projectID }: { projectID: string }) {
  const features = await fetchFeatures(projectID);
  return (
    <div>
      <h1>Feature List</h1>
    </div>
  );
}
