import type { Metadata } from "next"
import Image from "next/image"
import Link from "next/link"
import { notFound } from "next/navigation"
import { TEAM_MEMBERS } from "@/lib/team-data"

interface Props {
  params: Promise<{ id: string }>
}

export async function generateStaticParams() {
  return TEAM_MEMBERS.map((member) => ({ id: member.slug }))
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
  const { id } = await params
  const member = TEAM_MEMBERS.find((m) => m.slug === id)
  if (!member) return { title: "能力模块未找到" }
  return {
    title: `${member.name} | DAL Code`,
    description: member.bio,
    openGraph: {
      title: `${member.name} | ${member.role}`,
      description: member.bio,
      images: [{ url: member.image }],
    },
  }
}

export default async function TeamMemberPage({ params }: Props) {
  const { id } = await params
  const member = TEAM_MEMBERS.find((m) => m.slug === id)
  if (!member) notFound()

  return (
    <main>
      <section className="section-small top overflow-hidden">
        <div className="w-layout-blockcontainer container-default w-container">
          <div className="inner-container _650px center">
            <div className="text-center">
              <div className="team-member-avatar-large" style={{ position: "relative", width: 200, height: 200, margin: "0 auto", borderRadius: "50%", overflow: "hidden" }}>
                <Image
                  src={member.image}
                  alt={member.name}
                  fill
                  style={{ objectFit: "cover" }}
                  priority
                />
              </div>
              <div className="mg-top-regular">
                <h1>{member.name}</h1>
              </div>
              <div className="mg-top-4x-extra-small">
                <div className="subtitle">{member.role}</div>
              </div>
              <div className="mg-top-4x-extra-small">
                <p>{member.bio}</p>
              </div>
            </div>
          </div>
          <div className="mg-top-regular">
            <div className="inner-container _650px center">
              <div className="blog-post-rich-text w-richtext">
                <h2>能力故事</h2>
                {member.story.map((paragraph) => (
                  <p key={paragraph}>{paragraph}</p>
                ))}
              </div>
            </div>
          </div>
          <div className="mg-top-regular">
            <div className="inner-container _650px center text-center">
              <Link href="/about" className="primary-button w-inline-block">
                <div className="button-content">
                  <div>返回能力版图</div>
                  <div className="button-icon-wrapper primary">
                    <svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 17 17" fill="none" className="squared-icon">
                      <path d="M6.25391 3.45312L10.7458 8.01563L6.25391 12.5781" stroke="currentColor" strokeWidth="1.5" strokeLinecap="square" />
                    </svg>
                    <div className="button-icon-bg" />
                    <div className="button-icon-bg-inside" />
                  </div>
                </div>
              </Link>
            </div>
          </div>
        </div>
      </section>
    </main>
  )
}
