'use client'

import Script from 'next/script'

interface BlogPostSchemaProps {
  title: string
  description: string
  image: string
  publishedTime?: string
  modifiedTime?: string
  author: string
  url: string
}

export default function BlogPostSchema({
  title,
  description,
  image,
  publishedTime,
  modifiedTime,
  author,
  url
}: BlogPostSchemaProps) {
  const fullImage = image.startsWith('http') ? image : `https://aktiv.rs${image}`

  const articleSchema = {
    '@context': 'https://schema.org',
    '@type': 'BlogPosting',
    headline: title,
    description: description,
    image: fullImage,
    datePublished: publishedTime || new Date().toISOString(),
    dateModified: modifiedTime || publishedTime || new Date().toISOString(),
    author: {
      '@type': 'Person',
      name: author
    },
    publisher: {
      '@type': 'Organization',
      name: 'AKTIV Program knjigovodstvo',
      logo: {
        '@type': 'ImageObject',
        url: 'https://aktiv.rs/images/aktiv-logo.png'
      }
    },
    mainEntityOfPage: {
      '@type': 'WebPage',
      '@id': url
    }
  }

  return (
    <Script
      id="blog-post-schema"
      type="application/ld+json"
      dangerouslySetInnerHTML={{ __html: JSON.stringify(articleSchema) }}
    />
  )
}
