import type { TAuthorResponse } from '~/apis/common/get-news'
import { formatDate } from '~/utils/formatter'

type TDetailNewsAuthor = {
  author?: TAuthorResponse
  live_at?: string
  text?: string
}

export const NewsAuthor = ({ author, live_at, text }: TDetailNewsAuthor) => {
  return (
    <div className="mb-2 flex items-center gap-2 align-middle">
      <img
        src={author?.profile_picture || '/images/profile-placeholder.svg'}
        onError={(event) => {
          event.currentTarget.src = '/images/profile-placeholder.svg'
        }}
        alt={author?.name}
        className="size-12 rounded-full bg-[#C4C4C4] object-cover"
      />

      <div>
        <h4 className="text-md">{author?.name}</h4>
        <p className="flex gap-1 text-sm">
          <span>{live_at && `${formatDate(live_at)}`}</span>
          <span>·</span>
          <span>{text}</span>
        </p>
      </div>
    </div>
  )
}
