import React, { useState } from 'react';
import { PublicHeader } from '@/Components/PublicHeader';
import { PublicFooter } from '@/Components/PublicFooter';
import { SEOHead } from '@/Components/SEOHead';
import { ServiceCard } from '@/Components/ServiceCard';
import { Link } from '@inertiajs/react';
import { Code2, Smartphone, Layout, TrendingUp, Server, ShieldCheck, Cpu, ShoppingBag, ArrowRight, CheckCircle2 } from 'lucide-react';

interface ServicesIndexProps {
    categories: any[];
    services: any[];
}

export default function Index({ categories, services }: ServicesIndexProps) {
    const [selectedCategory, setSelectedCategory] = useState<string>('all');

    const filteredServices = selectedCategory === 'all'
        ? services
        : services.filter(s => s.category?.slug === selectedCategory || s.category_id?.toString() === selectedCategory);

    const techStacks = [
        { category: 'Frontend', tools: ['React', 'Inertia.js', 'Next.js', 'Tailwind CSS', 'TypeScript'] },
        { category: 'Backend & APIs', tools: ['PHP 8.5', 'Laravel 12', 'Node.js', 'GraphQL', 'RESTful APIs'] },
        { category: 'Databases & Cache', tools: ['MySQL', 'PostgreSQL', 'Redis Caching', 'Memcached', 'ClickHouse'] },
        { category: 'Mobile & Cloud', tools: ['Flutter', 'React Native', 'AWS', 'Docker', 'Kubernetes'] },
    ];


    const engagementSteps = [
        {
            number: '01',
            title: 'Technical Discovery',
            description: 'In-depth analysis of your business logic, system requirements, data schemas, and user flows.',
        },
        {
            number: '02',
            title: 'Architecture & Design',
            description: 'Designing accessible Figma prototypes, component design systems, and resilient database ERDs.',
        },
        {
            number: '03',
            title: 'Sprint Development',
            description: 'Agile development cycles with continuous automated Pest testing, code reviews, and weekly demos.',
        },
        {
            number: '04',
            title: 'Launch & Support',
            description: 'Zero-downtime deployment, server monitoring, security auditing, and continuous 24/7 maintenance.',
        },
    ];

    return (
        <div className="min-h-screen bg-[#060B18] text-slate-100 flex flex-col font-sans">
            <SEOHead
                title="IT Services & Software Solutions | Tech in Soul"
                description="Explore Tech in Soul web development, mobile application design, SEO optimization, UI/UX prototyping, and cloud DevOps services."
            />

            <PublicHeader />

            <main className="flex-grow pt-32 pb-20">
                {/* Hero Header */}
                <div className="max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-12 text-center space-y-4 mb-16">
                    <span className="text-xs font-bold text-[#00F2FE] uppercase tracking-widest bg-[#00F2FE]/10 px-3.5 py-1 rounded-full border border-[#00F2FE]/20 inline-block">
                        OUR SPECIALIZATIONS
                    </span>
                    <h1 className="text-4xl sm:text-6xl font-extrabold text-white tracking-tight leading-tight">
                        End-to-End Digital <span className="text-gradient-aqua">Services</span>
                    </h1>
                    <p className="text-slate-400 text-base sm:text-lg max-w-2xl mx-auto leading-relaxed">
                        We build, optimize, and scale software solutions tailored to your unique market challenges and business objectives.
                    </p>
                </div>

                {/* Category Filter Pills */}
                <div className="max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-12 mb-12">
                    <div className="flex flex-wrap items-center justify-center gap-2 sm:gap-3">
                        <button
                            onClick={() => setSelectedCategory('all')}
                            className={`px-5 py-2.5 rounded-xl text-xs font-bold transition-all ${
                                selectedCategory === 'all'
                                    ? 'bg-[#00F2FE] text-[#060B18] shadow-lg shadow-[#00F2FE]/20'
                                    : 'bg-[#0B132B] text-slate-300 border border-slate-800 hover:border-[#00F2FE]/40'
                            }`}
                        >
                            All Offerings ({services.length})
                        </button>
                        {categories.map((cat) => {
                            const count = services.filter(s => s.category?.slug === cat.slug || s.category_id === cat.id).length;
                            return (
                                <button
                                    key={cat.id}
                                    onClick={() => setSelectedCategory(cat.slug)}
                                    className={`px-5 py-2.5 rounded-xl text-xs font-bold transition-all ${
                                        selectedCategory === cat.slug
                                            ? 'bg-[#00F2FE] text-[#060B18] shadow-lg shadow-[#00F2FE]/20'
                                            : 'bg-[#0B132B] text-slate-300 border border-slate-800 hover:border-[#00F2FE]/40'
                                    }`}
                                >
                                    {cat.name} ({count})
                                </button>
                            );
                        })}
                    </div>
                </div>

                {/* Services Grid */}
                <div className="max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-12 mb-24">
                    {filteredServices.length === 0 ? (
                        <div className="glass-card rounded-3xl p-12 text-center text-slate-400 max-w-lg mx-auto border border-slate-800">
                            <h3 className="text-lg font-bold text-white mb-2">No Services Available</h3>
                            <p className="text-xs text-slate-400">Our team is currently updating our service offerings. Check back soon!</p>
                        </div>
                    ) : (
                        <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
                            {filteredServices.map((service) => (
                                <ServiceCard key={service.id} service={service} />
                            ))}
                        </div>
                    )}
                </div>

                {/* Tech Stack Showcase */}
                <div className="max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-12 mb-24 space-y-12">
                    <div className="text-center max-w-2xl mx-auto space-y-2">
                        <span className="text-xs font-bold text-[#00F2FE] uppercase tracking-widest">
                            TECHNOLOGY STACK
                        </span>
                        <h2 className="text-3xl sm:text-4xl font-bold text-white">Frameworks & Tools We Excel In</h2>
                    </div>

                    <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                        {techStacks.map((stack, idx) => (
                            <div key={idx} className="glass-card rounded-2xl p-6 border border-slate-800 space-y-4">
                                <h3 className="text-base font-bold text-[#00F2FE]">{stack.category}</h3>
                                <ul className="space-y-2">
                                    {stack.tools.map((tool, tIdx) => (
                                        <li key={tIdx} className="text-xs text-slate-300 flex items-center gap-2">
                                            <CheckCircle2 className="w-3.5 h-3.5 text-[#00F2FE]" />
                                            <span>{tool}</span>
                                        </li>
                                    ))}
                                </ul>
                            </div>
                        ))}
                    </div>
                </div>

                {/* 4-Step Engagement Process */}
                <div className="max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-12 mb-24 space-y-12">
                    <div className="text-center max-w-2xl mx-auto space-y-2">
                        <span className="text-xs font-bold text-[#00F2FE] uppercase tracking-widest">
                            ENGAGEMENT MODEL
                        </span>
                        <h2 className="text-3xl sm:text-4xl font-bold text-white">How We Execute Projects</h2>
                    </div>

                    <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                        {engagementSteps.map((step, idx) => (
                            <div key={idx} className="glass-card rounded-2xl p-8 border border-slate-800 space-y-3 relative">
                                <div className="text-3xl font-extrabold text-[#00F2FE]/40 font-mono">{step.number}</div>
                                <h3 className="text-lg font-bold text-white">{step.title}</h3>
                                <p className="text-xs text-slate-400 leading-relaxed">{step.description}</p>
                            </div>
                        ))}
                    </div>
                </div>

                {/* Consultation CTA Banner */}
                <div className="max-w-[1600px] mx-auto px-4 sm:px-6 lg:px-12">
                    <div className="glass-card rounded-3xl p-8 sm:p-12 border border-[#00F2FE]/30 flex flex-col md:flex-row items-center justify-between gap-8">
                        <div className="space-y-3 max-w-2xl">
                            <span className="text-xs font-bold text-[#00F2FE] uppercase tracking-widest">
                                NEED CUSTOM SOFTWARE ARCHITECTURE?
                            </span>
                            <h3 className="text-3xl font-bold text-white">Discuss Your Requirements with Our Engineers</h3>
                            <p className="text-xs sm:text-sm text-slate-400 leading-relaxed">
                                Get a dedicated technical scope, architecture proposal, and timeline for your web, mobile, or cloud infrastructure project.
                            </p>
                        </div>
                        <Link href="/contact" className="btn-aqua px-8 py-4 rounded-xl font-bold text-sm shrink-0 flex items-center gap-2">
                            Request Technical Proposal <ArrowRight className="w-4 h-4" />
                        </Link>
                    </div>
                </div>
            </main>

            <PublicFooter />
        </div>
    );
}
