import { Language } from './translations';

interface SEOContent {
  title: string;
  description: string;
  keywords: string;
}

const seoContent: Record<Language, SEOContent> = {
  zh: {
    title: '⚡️ TexPixel - 公式识别工具',
    description: '在线公式识别工具，支持印刷体和手写体数学公式识别，快速准确地将图片中的数学公式转换为可编辑文本。',
    keywords: '公式识别,数学公式,OCR,手写公式识别,印刷体识别,AI识别,数学工具,免费,混合文字识别,texpixel,TexPixel',
  },
  en: {
    title: '⚡️ TexPixel - Formula Recognition Tool',
    description: 'Online formula recognition tool supporting printed and handwritten math formulas. Convert images to LaTeX, MathML, and Markdown quickly and accurately.',
    keywords: 'formula recognition,math formula,OCR,handwriting recognition,latex,mathml,markdown,AI recognition,math tool,free,texpixel,TexPixel,document recognition',
  },
};

/**
 * Update document metadata based on current language
 */
export function updatePageMeta(language: Language): void {
  const content = seoContent[language];
  
  // Update title
  document.title = content.title;
  
  // Update HTML lang attribute
  document.documentElement.lang = language === 'zh' ? 'zh-CN' : 'en';
  
  // Update meta description
  const metaDescription = document.querySelector('meta[name="description"]');
  if (metaDescription) {
    metaDescription.setAttribute('content', content.description);
  }
  
  // Update meta keywords
  const metaKeywords = document.querySelector('meta[name="keywords"]');
  if (metaKeywords) {
    metaKeywords.setAttribute('content', content.keywords);
  }
  
  // Update Open Graph meta tags
  const ogTitle = document.querySelector('meta[property="og:title"]');
  if (ogTitle) {
    ogTitle.setAttribute('content', content.title);
  }
  
  const ogDescription = document.querySelector('meta[property="og:description"]');
  if (ogDescription) {
    ogDescription.setAttribute('content', content.description);
  }
  
  // Update Twitter Card meta tags
  const twitterTitle = document.querySelector('meta[name="twitter:title"]');
  if (twitterTitle) {
    twitterTitle.setAttribute('content', content.title);
  }
  
  const twitterDescription = document.querySelector('meta[name="twitter:description"]');
  if (twitterDescription) {
    twitterDescription.setAttribute('content', content.description);
  }
  
  // Update og:locale
  const ogLocale = document.querySelector('meta[property="og:locale"]');
  if (ogLocale) {
    ogLocale.setAttribute('content', language === 'zh' ? 'zh_CN' : 'en_US');
  }
}

/**
 * Get SEO content for a specific language
 */
export function getSEOContent(language: Language): SEOContent {
  return seoContent[language];
}
