import Head from 'next/head';
import { useRouter } from 'next/router';

const SEOHead = ({
  title,
  description,
  keywords,
  image,
  url,
  type = 'website',
  author = 'Sempreg Technology',
  siteName = 'Suite Sempreg',
  locale = 'es_CO',
  twitterHandle = '@sempreg',
  noindex = false,
  canonical,
  structuredData
}) => {
  const router = useRouter();
  
  // URLs base
  const baseUrl = 'https://suite.sempreg.com';
  const currentUrl = url || `${baseUrl}${router.asPath}`;
  const canonicalUrl = canonical || currentUrl;
  
  // Imagen por defecto mejorada
  const defaultImage = '@/assets/img/SempregL.png';
  const ogImage = image || defaultImage;
  
  // Título optimizado
  const pageTitle = title ? `${title} | ${siteName}` : siteName;
  
  // Descripción por defecto mejorada
  const defaultDescription = 'Sempreg Suite: Soluciones tecnológicas avanzadas para contabilidad, automatización de procesos contables, informes financieros y gestión empresarial. Optimiza tu contabilidad con nuestras herramientas especializadas.';
  const metaDescription = description || defaultDescription;
  
  // Keywords por defecto
  const defaultKeywords = 'contabilidad, software contable, automatización contable, informes financieros, DIAN, facturación electrónica, Colombia, Sempreg, suite contable, gestión empresarial';
  const metaKeywords = keywords || defaultKeywords;

  return (
    <Head>
      {/* Título */}
      <title>{pageTitle}</title>
      
      {/* Meta tags básicos */}
      <meta name="description" content={metaDescription} />
      <meta name="keywords" content={metaKeywords} />
      <meta name="author" content={author} />
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <meta httpEquiv="Content-Language" content="es" />
      
      {/* Canonical URL */}
      <link rel="canonical" href={canonicalUrl} />
      
      {/* Robots */}
      {noindex && <meta name="robots" content="noindex, nofollow" />}
      
      {/* Open Graph / Facebook */}
      <meta property="og:type" content={type} />
      <meta property="og:title" content={pageTitle} />
      <meta property="og:description" content={metaDescription} />
      <meta property="og:image" content={ogImage} />
      <meta property="og:image:width" content="1200" />
      <meta property="og:image:height" content="630" />
      <meta property="og:image:alt" content={title || siteName} />
      <meta property="og:url" content={currentUrl} />
      <meta property="og:site_name" content={siteName} />
      <meta property="og:locale" content={locale} />
      
      {/* Twitter Card */}
      <meta name="twitter:card" content="summary_large_image" />
      <meta name="twitter:site" content={twitterHandle} />
      <meta name="twitter:creator" content={twitterHandle} />
      <meta name="twitter:title" content={pageTitle} />
      <meta name="twitter:description" content={metaDescription} />
      <meta name="twitter:image" content={ogImage} />
      <meta name="twitter:image:alt" content={title || siteName} />
      
      {/* LinkedIn */}
      <meta property="og:image:type" content="image/jpeg" />
      
      {/* WhatsApp */}
      <meta property="og:image:secure_url" content={ogImage} />
      
      {/* Favicon mejorado */}
      <link rel="icon" type="image/png" sizes="32x32" href="https://sempreg.com/wp-content/uploads/2021/09/cropped-simbolo-logo-e1723841306835.png" />
      <link rel="icon" type="image/png" sizes="16x16" href="https://sempreg.com/wp-content/uploads/2021/09/cropped-simbolo-logo-e1723841306835.png" />
      <link rel="apple-touch-icon" href="https://sempreg.com/wp-content/uploads/2021/09/cropped-simbolo-logo-e1723841306835.png" />
      
      {/* Structured Data */}
      {structuredData && (
        <script
          type="application/ld+json"
          dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
        />
      )}
      
      {/* Preconnect para mejorar performance */}
      <link rel="preconnect" href="https://sempreg.com" />
      <link rel="preconnect" href="https://fonts.googleapis.com" />
      <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
    </Head>
  );
};

export default SEOHead;