import React, { useEffect, useState } from 'react';
import LoadingScreen from '../../components/LoadingScreen';
import Hero from '../../components/Hero';
import Mission from '../../components/Mission';
import Services from '../../components/Services';
import Process from '../../components/Process';
import Blog from '../../components/Blog';
import Testimonials from '../../components/Testimonials';
import CTA from '../../components/CTA';
import SEO from '../../components/SEO';
import FAQ from '../../components/FAQ';
import AreasWeServe from '../../components/AreasWeServe';
import { locationData } from '../data/seoData';

const HomePage: React.FC = () => {
    const [isLoading, setIsLoading] = useState(() => {
        if (typeof window !== 'undefined') {
            return !sessionStorage.getItem('home_loaded');
        }
        return false;
    });

    useEffect(() => {
        window.scrollTo(0, 0);

        if (isLoading) {
            sessionStorage.setItem('home_loaded', 'true');
        }
    }, [isLoading]);

    // Enhanced LocalBusiness Schema per SEO plan
    const schema = {
        "@context": "https://schema.org",
        "@type": "ITService",
        "name": "Bay Area IT",
        "image": "https://bayareait.services/logo.svg",
        "@id": "https://bayareait.services",
        "url": "https://bayareait.services",
        "telephone": "+1-361-765-8400",
        "priceRange": "$$",
        "address": {
            "@type": "PostalAddress",
            "streetAddress": "1001 Blucher St",
            "addressLocality": "Corpus Christi",
            "addressRegion": "TX",
            "postalCode": "78401",
            "addressCountry": "US"
        },
        "geo": {
            "@type": "GeoCoordinates",
            "latitude": 27.800583,
            "longitude": -97.39638
        },
        "areaServed": [
            { "@type": "City", "name": "Corpus Christi" },
            { "@type": "City", "name": "Portland" },
            { "@type": "City", "name": "Rockport" },
            { "@type": "City", "name": "Aransas Pass" },
            { "@type": "City", "name": "Kingsville" }
        ],
        "serviceType": [
            "IT Support",
            "IT Help Desk",
            "Computer Support",
            "Outsourced IT Services",
            "Computer Network Support",
            "Cyber Security"
        ],
        "openingHoursSpecification": {
            "@type": "OpeningHoursSpecification",
            "dayOfWeek": [
                "Monday",
                "Tuesday",
                "Wednesday",
                "Thursday",
                "Friday"
            ],
            "opens": "08:00",
            "closes": "18:00"
        }
    };

    return (
        <>
            {isLoading && <LoadingScreen onComplete={() => setIsLoading(false)} />}
            <SEO
                title="IT Service & IT Support for Businesses in Corpus Christi, TX"
                description="Reliable IT support and IT services for businesses in Corpus Christi, TX. Fast response, outsourced IT support & help desk solutions. Call now."
                keywords={["IT Service", "IT Support", "Corpus Christi", "IT Help Desk"]}
                canonicalUrl="https://bayareait.services/"
                schema={schema}
            />
            <Hero />
            <Mission />
            <Services preview={true} />
            <Process />
            <Blog />
            <Testimonials />
            <AreasWeServe />
            <FAQ items={locationData[0].faq} />
            <CTA />
        </>
    );
};

export default HomePage;
