import Link from 'next/link'
import { Fragment } from 'react'
import { affiliations, nationalities, authors } from '../../db/data'
import { Zilla_Slab } from 'next/font/google'
import { notFound } from 'next/navigation'
import DocumentCard from '@/app/components/DocumentCard'
import findDocumentsByAuthor from './findDocumentsByAuthor'
import cardEffects from '@/app/styles/cardEffects.module.css'
const zillaSlab = Zilla_Slab({ subsets: ['latin'], weight: ['500'] })
export default function AuthorDisplay({
author,
}: Readonly<{ author: string }>) {
const data = authors[author]
if (!data) {
notFound()
}
const { name, affiliation, image, nationality, formerAffiliations } = data
const authorsDocuments = findDocumentsByAuthor(author)
const MainPosition = () => {
const mainAffiliationShort = affiliation[0].split('@')[1]
const mainPosition = affiliation[0].split('@')[0]
const mainAffiliation = affiliations[mainAffiliationShort]
const { website } = data
return (
<>
{mainPosition} at
{mainAffiliation.name}
{website ? (
Visit {name.nickname ? name.nickname : name.first} at:{' '}
{website}
) : null}
{affiliation.map((a: string) => (
))}
>
)
}
const OtherPositions = () => {
if (affiliation.length === 1) return
return (
<>
Other Positions
{affiliation.slice(1).map((a: string, i: number) => {
const position = a.split('@')[0]
const affiliation = affiliations[a.split('@')[1]].name
return (
{position} at{' '}
{affiliation}
)
})}
>
)
}
const FormerPositions = () => {
if (!formerAffiliations) return null
return (
<>
Former Positions
{formerAffiliations?.map((a: string, i: number) => {
const position = a.split('@')[0]
const affiliation = affiliations[a.split('@')[1]].name
return (
{position} at{' '}
{affiliation}
)
})}
>
)
}
const NationalityDisplay = ({
nationality,
}: Readonly<{ nationality: string }>) => {
const nationalityData = nationalities[nationality]
const { demonym, flag } = nationalityData
return (
{demonym}
)
}
const Bio = () => {
const { bio } = data
if (!bio) return null
return (
<>
Bio:
{bio}
>
)
}
return (
{name.first}
{name.nickname ? ` "${name.nickname}"` : null} {name.last}
Ethnicity and Nationality
{nationality.map((n: string) => (
))}
{authorsDocuments.length > 0 && (
<>
Published documents
{authorsDocuments.map((d) => (
))}
>
)}
)
}