'use client'

import { useTranslations } from 'next-intl'
import { ArrowRight } from 'lucide-react'
import { Link } from '@/i18n/navigation'
import AuthorAvatar from '@/components/frontend/blog/AuthorAvatar'
import AuthorSocialLinks from '@/components/frontend/blog/AuthorSocialLinks'
import type { BlogAuthorProfile } from '@/lib/db/queries/getBlogPosts'

// "About the author" box at the end of a post.
export default function AuthorBioCard({ author }: { author: BlogAuthorProfile }) {
  const t = useTranslations('BlogPage')
  const profileHref = `/blogs/author/${author.slug}`

  return (
    <section
      aria-label={t('aboutAuthor')}
      className="relative overflow-hidden rounded-2xl border border-gray-100 bg-brand-wash p-6 md:p-8"
    >
      <div className="flex flex-col sm:flex-row gap-5 sm:gap-6">
        <Link href={profileHref} className="shrink-0 self-start">
          <AuthorAvatar name={author.name} imageUrl={author.imageUrl} size={88} className="ring-4 ring-white shadow-md" />
        </Link>
        <div className="min-w-0 flex-1">
          <p className="text-xs font-semibold uppercase tracking-wider text-primary mb-1">{t('writtenBy')}</p>
          <h2 className="text-xl font-bold text-dark mb-2">
            <Link href={profileHref} className="hover:text-primary transition">{author.name}</Link>
          </h2>
          {author.bio && (
            <p className="text-gray-custom leading-relaxed whitespace-pre-line line-clamp-5 mb-4">{author.bio}</p>
          )}
          <div className="flex flex-wrap items-center justify-between gap-4">
            <AuthorSocialLinks author={author} />
            <Link
              href={profileHref}
              className="inline-flex items-center gap-1.5 text-sm font-semibold text-primary hover:gap-2.5 transition-all"
            >
              {t('viewAllPosts')} <ArrowRight size={16} className="rtl:rotate-180" />
            </Link>
          </div>
        </div>
      </div>
    </section>
  )
}
