import { getPayload } from "payload";
import config from "@payload-config";
import Link from "next/link";
import React from "react";

const team = [
  {
    name: "Emma Dorsey",
    role: "Senior Developer",
    imageUrl:
      "https://images.unsplash.com/photo-1505840717430-882ce147ef2d?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=8&w=1024&h=1024&q=80",
    bio: "Praesentium iure error aliquam voluptas ut libero. Commodi placeat sit iure nulla officiis. Ut ex sit repellat tempora. Qui est accusamus exercitationem natus ut voluptas. Officiis velit eos ducimus.",
    xUrl: "#",
    linkedinUrl: "#",
  },
  // More people...
];

function Team({ people }) {
  return (
    <div className="py-24 md:py-32 lg:py-40">
      <div className="mx-auto grid  grid-cols-1 gap-5 xl:grid-cols-3">
        <div className="max-w-2xl">
          <h2 className="text-3xl font-semibold tracking-tight text-pretty text-gray-900 sm:text-5xl">
            Projektteam
          </h2>
        </div>
        <ul
          role="list"
          className="mx-auto grid max-w-2xl grid-cols-1 gap-x-6 gap-y-20 sm:grid-cols-3 lg:mx-0  lg:gap-x-8 xl:col-span-2"
        >
          {people.map((person) => (
            <li key={person.id}>
              <img
                alt={"Bild von " + person.name}
                src={person?.image?.url || "/person-placeholder.svg"}
                className="aspect-3/2 w-full rounded-2xl object-cover"
              />
              <h3 className="mt-6 text-lg/8 font-semibold text-gray-900">
                {person.name}
              </h3>
              <p className="text-base/7 text-gray-600">
                {person.position == "leader"
                  ? "Projektleiter"
                  : "Projektmitarbeiter"}
              </p>
              <p className="mt-4 text-base/7 text-gray-600">
                {person.description}
              </p>
            </li>
          ))}
        </ul>
      </div>
    </div>
  );
}

export default async function Page({
  params,
}: {
  params: Promise<{ id: number }>;
}) {
  const { id } = await params;

  const payload = await getPayload({ config });

  const result = await payload.findByID({
    collection: "papers", // required
    id: id, // required
  });

  return (
    <div className="w-4/5 md:w-2/3 mx-auto pt-4 pb-16">
      <Link href="/">
        <span aria-hidden="true">&larr;</span> Zurück
      </Link>

      <h4 className="text-lg text-gray-600 pt-8">
        Diplom- und Abschlussarbeiten ({result.year})
      </h4>
      <h1 className="text-2xl md:text-4xl font-semibold">{result.title}</h1>
      <Team people={result.authors} />

      <section className="py-4">
        <h2 className="text-3xl font-semibold tracking-tight text-pretty text-gray-900 sm:text-5xl pb-4">
          Zielsetzung
        </h2>
        <p className="text-lg text-justify">{result.goal}</p>
      </section>

      <section className="py-4">
        <h2 className="text-3xl font-semibold tracking-tight text-pretty text-gray-900 sm:text-5xl pb-4">
          Problemstellung
        </h2>
        <p className="text-lg text-justify">{result.issue}</p>
      </section>

      <section className="py-4">
        <h2 className="text-3xl font-semibold tracking-tight text-pretty text-gray-900 sm:text-5xl pb-4">
          Ergebnisse
        </h2>
        <p className="text-lg text-justify">{result.result}</p>
      </section>

      <section className="py-4">
        <h2 className="text-3xl font-semibold tracking-tight text-pretty text-gray-900 sm:text-5xl pb-4">
          Technologien
        </h2>
        <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
          {result.technologies.map((technology) => (
            <div
              key={technology.id}
              className="w-full rounded-lg border border-gray-200 shadow-sm p-4 flex flex-col lg:flex-row gap-4"
            >
              <img
                alt={technology.name + " Logo"}
                src={technology.technology.url}
                className="object-fill h-16 h-16"
              />
              <div className="flex flex-col">
                <h3 className="text-2xl">{technology.technology.name}</h3>
                <p>{technology.description}</p>
              </div>
            </div>
          ))}
        </div>
      </section>


    </div>
  );
}
