/* eslint-disable react-refresh/only-export-components */
import type { Article } from '@/lib/api';

interface SocialMetaTagsProps {
  article: Article;
  url?: string;
}

export function SocialMetaTags({ article, url }: SocialMetaTagsProps) {
  // This component doesn't render anything directly
  // It's used to generate meta tags for TanStack Router's head API
  // Mark props as used to avoid ESLint warnings
  void article;
  void url;
  return null;
}

export function getSocialMetaTags(article: Article, url?: string) {
  // Use article's social metadata if available, otherwise generate from article data
  const ogTitle = article.ogTitle || article.title;
  const ogDescription = article.ogDescription || article.excerpt || 'Latest news from Placebo.mk';
  const ogImage = article.ogImage || article.featuredImage || '/placeholder-image.jpg';
  const twitterTitle = article.twitterTitle || article.title;
  const twitterDescription = article.twitterDescription || article.excerpt || 'Latest news from Placebo.mk';
  const twitterImage = article.twitterImage || article.featuredImage || '/placeholder-image.jpg';
  
  // Use provided URL or construct from article ID
  const articleUrl = url || `${typeof window !== 'undefined' ? window.location.origin : ''}/articles/${article.id}`;

  const metaTags = [
    // Basic SEO
    { title: `${article.title} - Placebo.mk` },
    { name: 'description', content: ogDescription },
    
    // Open Graph tags
    { property: 'og:title', content: ogTitle },
    { property: 'og:description', content: ogDescription },
    { property: 'og:image', content: ogImage },
    { property: 'og:url', content: articleUrl },
    { property: 'og:type', content: 'article' },
    { property: 'og:locale', content: 'mk_MK' },
    
    // Twitter Card tags
    { name: 'twitter:card', content: 'summary_large_image' },
    { name: 'twitter:title', content: twitterTitle },
    { name: 'twitter:description', content: twitterDescription },
    { name: 'twitter:image', content: twitterImage },
    
    // Article-specific tags
    { property: 'article:published_time', content: article.createdAt },
    { property: 'article:modified_time', content: article.updatedAt },
  ];

  // Add author if available
  if (article.author?.name) {
    metaTags.push({ property: 'article:author', content: article.author.name });
  }

  // Add tags if available
  if (article.tags && article.tags.length > 0) {
    article.tags.forEach(tag => {
      metaTags.push({ property: 'article:tag', content: tag });
    });
  }

  return {
    meta: metaTags,
  };
}