import { Post } from 'types/payload-types'
import Image from 'next/image'
import { COLLECTION_SLUG_POST } from '@/app/(payload)/collections/config'

interface Props {
  post: Post
}

export default function PostEntry(props: Props) {
  if (typeof props.post.thumbnail === 'string') return

  return (
    <a
      className="py-4 border-secondary decoration-transparent"
      href={`/${COLLECTION_SLUG_POST}${props.post.path}`}
    >
      <article className="flex px-5 py-3 gap-8">
        <Image
          src={props.post.thumbnail.url || ''}
          width={150}
          height={150}
          alt={props.post.thumbnail.alt || ''}
          layout="fixed"
        />

        <div className="flex flex-col gap-4 w-full">
          <div className="flex justify-between w-full">
            <h3 className="">{props.post.title}</h3>
            {props.post.publishedDate && (
              <p className="font-light">
                {new Date(props.post.publishedDate).toLocaleDateString('de-DE')}
              </p>
            )}
          </div>
          {props.post.summary && <p className="max-w-prose">{props.post.summary}</p>}
        </div>
        {/* {props.post.author.name && (
        <p>
          {props.post.author.name}
        </p>
    )} */}
      </article>
    </a>
  )
}
