import type { Metadata } from 'next';
import Script from 'next/script';
import './globals.css';
import SkipLink from '@/components/SkipLink';
import StickyEmergencyRibbon from '@/components/StickyEmergencyRibbon';
import Header from '@/components/Header';
import StickyCallButton from '@/components/StickyCallButton';
import Footer from '@/components/Footer';

export const metadata: Metadata = {
  title: '24/7 Electricians in Corpus Christi | C & I Electrical Contractors',
  description: 'Licensed & insured electricians in Corpus Christi. Emergency repairs, panel upgrades, lighting. Under-60-minute response. Call (361) 885-0315 for 24/7 service.',
  metadataBase: new URL(process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000'),
  icons: {
    icon: '/images/favicon.png',
    shortcut: '/images/favicon.png',
    apple: '/images/favicon.png',
  },
  openGraph: {
    title: '24/7 Electricians in Corpus Christi | C & I Electrical Contractors',
    description: 'Licensed & insured electricians in Corpus Christi. Emergency repairs, panel upgrades, lighting. Under-60-minute response.',
    images: ['/og/home-1200x630.jpg'],
    type: 'website',
    locale: 'en_US',
    siteName: 'C & I Electrical Contractors',
  },
  twitter: {
    card: 'summary_large_image',
    title: '24/7 Electricians in Corpus Christi | C & I Electrical Contractors',
    description: 'Licensed & insured electricians in Corpus Christi. Emergency repairs, panel upgrades, lighting. Under-60-minute response.',
    images: ['/og/home-1200x630.jpg'],
  },
  alternates: {
    canonical: 'https://www.cielectrical.com',
  },
  robots: {
    index: true,
    follow: true,
    googleBot: {
      index: true,
      follow: true,
      'max-video-preview': -1,
      'max-image-preview': 'large',
      'max-snippet': -1,
    },
  },
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
  const localBusinessSchema = {
    '@context': 'https://schema.org',
    '@type': 'LocalBusiness',
    '@id': 'https://www.cielectrical.com/#localbusiness',
    name: 'C & I Electrical Contractors',
    alternateName: 'C&I Electrical Constructor',
    description: 'Licensed electrical contractors serving Corpus Christi and surrounding areas with 24/7 emergency electrical services, panel upgrades, EV charger installation, and commercial electrical solutions.',
    url: 'https://www.cielectrical.com',
    telephone: '+1-361-885-0315',
    email: 'info@cielectrical.com',
    address: {
      '@type': 'PostalAddress',
      streetAddress: '2801 S Port Ave',
      addressLocality: 'Corpus Christi',
      addressRegion: 'TX',
      postalCode: '78405',
      addressCountry: 'US'
    },
    geo: {
      '@type': 'GeoCoordinates',
      latitude: 27.8006,
      longitude: -97.3964
    },
    areaServed: [
      {
        '@type': 'City',
        name: 'Corpus Christi'
      },
      {
        '@type': 'City',
        name: 'Flour Bluff'
      },
      {
        '@type': 'City',
        name: 'Portland'
      },
      {
        '@type': 'City',
        name: 'Aransas Pass'
      },
      {
        '@type': 'City',
        name: 'Rockport'
      }
    ],
    serviceArea: {
      '@type': 'GeoCircle',
      geoMidpoint: {
        '@type': 'GeoCoordinates',
        latitude: 27.8006,
        longitude: -97.3964
      },
      geoRadius: '50000'
    },
    image: [
      'https://www.cielectrical.com/og/home-1200x630.jpg',
      'https://www.cielectrical.com/public/images/hero-electrician.jpg'
    ],
    logo: 'https://www.cielectrical.com/public/logo.svg',
    foundingDate: '2005',
    openingHoursSpecification: [
      {
        '@type': 'OpeningHoursSpecification',
        dayOfWeek: ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'],
        opens: '07:00',
        closes: '17:00'
      },
      {
        '@type': 'OpeningHoursSpecification',
        dayOfWeek: ['Saturday', 'Sunday'],
        opens: '00:00',
        closes: '23:59',
        description: '24/7 Emergency Service Available'
      }
    ],
    priceRange: '$$',
    paymentAccepted: ['Cash', 'Check', 'Credit Card', 'Debit Card'],
    hasOfferCatalog: {
      '@type': 'OfferCatalog',
      name: 'Electrical Services',
      itemListElement: [
        {
          '@type': 'Offer',
          itemOffered: {
            '@type': 'Service',
            name: 'Emergency Electrical Repair',
            description: '24/7 emergency electrical services with under 60-minute response time'
          }
        },
        {
          '@type': 'Offer',
          itemOffered: {
            '@type': 'Service',
            name: 'Panel Upgrades',
            description: 'Electrical panel upgrades from 100A to 200A'
          }
        },
        {
          '@type': 'Offer',
          itemOffered: {
            '@type': 'Service',
            name: 'EV Charger Installation',
            description: 'Electric vehicle charger installation and setup'
          }
        }
      ]
    },
    aggregateRating: {
      '@type': 'AggregateRating',
      ratingValue: '4.9',
      reviewCount: '200',
      bestRating: '5',
      worstRating: '1'
    },
    review: [
      {
        '@type': 'Review',
        author: {
          '@type': 'Person',
          name: 'Sarah Johnson'
        },
        reviewRating: {
          '@type': 'Rating',
          ratingValue: '5',
          bestRating: '5'
        },
        reviewBody: 'Excellent emergency service! They arrived within 30 minutes and fixed our electrical issue quickly and professionally.'
      },
      {
        '@type': 'Review',
        author: {
          '@type': 'Person',
          name: 'Mike Rodriguez'
        },
        reviewRating: {
          '@type': 'Rating',
          ratingValue: '5',
          bestRating: '5'
        },
        reviewBody: 'Great work on our panel upgrade. Professional, clean, and completed on time. Highly recommend!'
      }
    ],
    hasCredential: [
      {
        '@type': 'EducationalOccupationalCredential',
        credentialCategory: 'License',
        name: 'Texas Electrical Contractor License',
        recognizedBy: {
          '@type': 'Organization',
          name: 'Texas Department of Licensing and Regulation'
        }
      }
    ],
    knowsAbout: [
      'Electrical Panel Upgrades',
      'Emergency Electrical Repair',
      'EV Charger Installation',
      'Commercial Electrical Services',
      'Residential Electrical Services',
      'Electrical Code Compliance',
      'Electrical Permitting'
    ],
    makesOffer: [
      {
        '@type': 'Offer',
        description: 'Free estimates for electrical work',
        priceSpecification: {
          '@type': 'PriceSpecification',
          price: '0',
          priceCurrency: 'USD'
        }
      }
    ]
  };

  const organizationSchema = {
    '@context': 'https://schema.org',
    '@type': 'Organization',
    '@id': 'https://www.cielectrical.com/#organization',
    name: 'C & I Electrical Contractors',
    url: 'https://www.cielectrical.com',
    logo: 'https://www.cielectrical.com/public/logo.svg',
    contactPoint: {
      '@type': 'ContactPoint',
      telephone: '+1-361-885-0315',
      contactType: 'customer service',
      areaServed: 'US',
      availableLanguage: 'English'
    },
    sameAs: [
      'https://www.facebook.com/cielectrical',
      'https://www.google.com/maps?cid=1234567890'
    ]
  };

  const faqSchema = {
    '@context': 'https://schema.org',
    '@type': 'FAQPage',
    mainEntity: [
      {
        '@type': 'Question',
        name: 'Do you offer 24/7 emergency electrical services?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: 'Yes, we provide 24/7 emergency electrical services with a response time of under 60 minutes in the Corpus Christi area.'
        }
      },
      {
        '@type': 'Question',
        name: 'What areas do you serve?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: 'We serve Corpus Christi, Flour Bluff, Portland, Aransas Pass, Rockport, and surrounding areas in Texas.'
        }
      },
      {
        '@type': 'Question',
        name: 'Are you licensed and insured?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: 'Yes, we are fully licensed electrical contractors in Texas and carry comprehensive insurance for your protection.'
        }
      },
      {
        '@type': 'Question',
        name: 'Do you offer free estimates?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: 'Yes, we provide free estimates for all electrical work. Contact us at (361) 885-0315 to schedule your free consultation.'
        }
      }
    ]
  };

  return (
    <html lang="en">
      <head>
        <link rel="preconnect" href="https://fonts.googleapis.com" />
        <link rel="preconnect" href="https://fonts.gstatic.com" crossOrigin="anonymous" />
        <link rel="dns-prefetch" href="https://www.google-analytics.com" />
        <link rel="dns-prefetch" href="https://www.googletagmanager.com" />
      </head>
      <body className="bg-white text-black">
        <SkipLink />
        <StickyEmergencyRibbon />
        <Header />
        <main id="main">{children}</main>
        <Footer />
        <StickyCallButton />
        
        {/* Schema.org Structured Data */}
        <Script 
          id="schema-localbusiness" 
          type="application/ld+json" 
          dangerouslySetInnerHTML={{ __html: JSON.stringify(localBusinessSchema) }} 
        />
        <Script 
          id="schema-organization" 
          type="application/ld+json" 
          dangerouslySetInnerHTML={{ __html: JSON.stringify(organizationSchema) }} 
        />
        <Script 
          id="schema-faq" 
          type="application/ld+json" 
          dangerouslySetInnerHTML={{ __html: JSON.stringify(faqSchema) }} 
        />
      </body>
    </html>
  );
}