import { DataTable } from "./data-table";
import { getSongsWithTitles } from "@/lib/api";
import { getAuth } from "@/auth/queries/getauth";
import { z } from "zod";
import { columns } from "./colums";

const userSchema = z.object({
  UserId: z.number(),
});

const ChunithmScorePlaylog = async () => {
  const { user } = await getAuth();

  const TypedUser = userSchema.safeParse(user);

  if (!TypedUser.success) {
    return (
      <div className="p-10">
        <p>Failed to load user data</p>
      </div>
    );
  }

  const songs = await getSongsWithTitles(TypedUser.data.UserId);

  return <DataTable columns={columns} data={songs} />;
};

export default ChunithmScorePlaylog;
