import React from "react";
import Image from "next/image";
import { ScrollReveal } from "@/animations/Reveal";

export default function BlogGrid() {
  const blogs = [
    {
      date: "Apl.06/2025",
      title: "How AI Is Transforming Last-Mile EV Delivery",
      excerpt: "Machine learning and real-time data are reshaping how fleets plan, dispatch, and adapt — making every kilometre smarter than the last.",
      category: "Technology",
      image: "/images/blog-post-pic-17.png",
    },
    {
      date: "Apl.06/2025",
      title: "The EV Paradox: Solving Range Anxiety for Urban Fleets",
      excerpt: "Electric vehicles promise sustainability, but battery constraints introduce a new routing challenge. Here's how MileTruth™ AI solves it before dispatch.",
      category: "EV Fleet",
      image: "/images/blog-post-pic-18-840x840.jpg",
    },
    {
      date: "Apl.06/2025",
      title: "42% Less Distance: Insights from Our Hyderabad Hub",
      excerpt: "A detailed look at how Doormile's MileTruth routing engine delivered measurable efficiency gains — fewer vehicles, less fuel, and zero SLA misses.",
      category: "Case Study",
      image: "/images/blog-post-pic-15.png",
    },
    {
      date: "Apl.06/2025",
      title: "MileTruth™ AI — 10 Stages to Smarter Dispatch",
      excerpt: "From order ingestion to final route output in under 45ms — a technical walkthrough of the ten-stage pipeline at the heart of our routing engine.",
      category: "MileTruth",
      image: "/images/blog-post-pic-31.png",
    },
    {
      date: "Apl.06/2025",
      title: "Why Mathematical Precision Beats Heuristics in Routing",
      excerpt: "Most routing tools guess. We calculate. Powered by Google OR-Tools, MileTruth evaluates six parallel strategy universes to select the optimal route every time.",
      category: "Technology",
      image: "/images/blog-post-pic-14.jpeg",
    },
    {
      date: "Apl.06/2025",
      title: "Fleet Reduction Without Compromising Delivery Volume",
      excerpt: "Deploying 37% fewer vehicles while handling the same order volumes isn't a trade-off — it's the result of smarter routing intelligence applied at every dispatch.",
      category: "Fleet Management",
      image: "/images/blog-post-pic-8.jpeg",
    },
    {
      date: "Apl.06/2025",
      title: "Building a Greener City: The Future of Urban Logistics",
      excerpt: "Cities are demanding cleaner delivery. We explore how AI-powered EV fleets and optimised routing create a path to zero-emission last-mile logistics at city scale.",
      category: "Sustainability",
      image: "/images/blog-post-pic-6.jpeg",
    },
    {
      date: "Apl.06/2025",
      title: "How Doormile Maintains 99.9% SLA Compliance at Scale",
      excerpt: "Hitting SLA targets 99.9% of the time isn't luck — it's the product of ETA pre-validation, real-time rebalancing, and a routing engine built with delivery reliability as its first constraint.",
      category: "Operations",
      image: "/images/blog-post-pic-4.jpeg",
    },
    {
      date: "Apl.06/2025",
      title: "Battery Simulation: The Secret to EV Route Pre-Validation",
      excerpt: "Before a single rider leaves the hub, MileTruth™ simulates every route against real charge capacity — eliminating mid-route failures and protecting your fulfillment rate.",
      category: "EV Fleet",
      image: "/images/blog-post-pic-3.jpeg",
    },
  ];

  return (
    <div className="elementor-element elementor-element-c70681e e-flex e-con-boxed cut-corner-no sticky-container-off e-con e-parent" data-id="c70681e" data-element_type="container" data-e-type="container">
      <style dangerouslySetInnerHTML={{ __html: `
        .custom-blog-grid {
            display: grid !important;
            grid-template-columns: repeat(3, 1fr) !important;
            gap: 40px !important;
            width: 100% !important;
            max-width: 1200px !important;
            margin: 0 auto !important;
            padding: 40px 20px !important;
        }
        
        @media (max-width: 1024px) {
            .custom-blog-grid {
                grid-template-columns: repeat(2, 1fr) !important;
            }
        }
        @media (max-width: 768px) {
            .custom-blog-grid {
                grid-template-columns: 1fr !important;
                gap: 48px !important;
            }
        }

        .custom-blog-card {
            display: flex !important;
            flex-direction: column !important;
            justify-content: space-between !important;
            height: 100% !important;
            background: #ffffff !important;
            border: 1px solid rgba(0, 0, 0, 0.08) !important;
            border-radius: 28px !important;
            padding: 28px !important;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03) !important;
            transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.4s ease !important;
            cursor: pointer !important;
        }
        
        .custom-blog-card:hover {
            transform: translateY(-8px) !important;
            box-shadow: 0 20px 40px rgba(192, 18, 39, 0.12) !important;
            border-color: rgba(192, 18, 39, 0.2) !important;
        }

        .custom-blog-date {
            font-size: 12px !important;
            font-weight: 700 !important;
            color: #94a3b8 !important;
            text-transform: uppercase !important;
            letter-spacing: 1px !important;
            margin-bottom: 8px !important;
            display: block !important;
            font-family: var(--font-manrope), sans-serif !important;
        }

        .custom-blog-divider {
            width: 100% !important;
            height: 1px !important;
            background: rgba(0, 0, 0, 0.08) !important;
            margin-bottom: 20px !important;
        }

        .custom-blog-title {
            font-size: 20px !important;
            font-weight: 800 !important;
            color: #1e293b !important;
            line-height: 1.35 !important;
            text-transform: none !important;
            letter-spacing: -0.4px !important;
            margin: 0 0 12px 0 !important;
            display: -webkit-box !important;
            -webkit-line-clamp: 2 !important;
            -webkit-box-orient: vertical !important;
            overflow: hidden !important;
            transition: color 0.2s ease !important;
            font-family: var(--font-manrope), sans-serif !important;
        }
        
        .custom-blog-card:hover .custom-blog-title {
            color: #c01227 !important;
        }

        .custom-blog-excerpt {
            font-size: 13.5px !important;
            font-weight: 500 !important;
            color: #64748b !important;
            line-height: 1.6 !important;
            margin: 0 0 24px 0 !important;
            text-transform: none !important;
            font-family: var(--font-manrope), sans-serif !important;
        }

        .custom-blog-img-container {
            position: relative !important;
            width: 100% !important;
            aspect-ratio: 4 / 3 !important;
            border-radius: 20px !important;
            overflow: hidden !important;
            margin-top: auto !important;
            box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05) !important;
        }

        .custom-blog-badge {
            position: absolute !important;
            top: 14px !important;
            left: 14px !important;
            z-index: 5 !important;
            background: #c01227 !important;
            color: #ffffff !important;
            font-size: 9px !important;
            font-weight: 800 !important;
            text-transform: uppercase !important;
            letter-spacing: 1.2px !important;
            padding: 4px 10px !important;
            border-radius: 6px !important;
            box-shadow: 0 4px 10px rgba(192, 18, 39, 0.2) !important;
            font-family: var(--font-manrope), sans-serif !important;
        }
      `}} />
      <div className="e-con-inner">
        <div className="elementor-element elementor-element-3dec5cf e-con-full e-flex cut-corner-no sticky-container-off e-con e-child" data-id="3dec5cf" data-element_type="container" data-e-type="container">
          <div className="elementor-element elementor-element-aa12479 elementor-widget elementor-widget-logico_blog_listing" data-id="aa12479" data-element_type="widget" data-e-type="widget" data-widget_type="logico_blog_listing.default">
            <div className="elementor-widget-container">
              <div className="archive-listing">
                <div className="custom-blog-grid">
                  
                  {blogs.map((blog, i) => (
                    <ScrollReveal key={i} delay={(i % 3) * 0.08} duration={0.8} yOffset={35}>
                      <div className="custom-blog-card">
                        {/* Text Block at Top */}
                        <div className="flex flex-col">
                          {/* Date */}
                          <span className="custom-blog-date">
                            {blog.date}
                          </span>
                          
                          {/* Thin divider line */}
                          <div className="custom-blog-divider" />
                          
                          {/* Bold Title */}
                          <h3 className="custom-blog-title">
                            {blog.title}
                          </h3>
                          
                          {/* Description Excerpt */}
                          <p className="custom-blog-excerpt">
                            {blog.excerpt}
                          </p>
                        </div>

                        {/* Image at Bottom */}
                        <div className="custom-blog-img-container">
                          <Image 
                            src={blog.image} 
                            alt={blog.title} 
                            fill
                            style={{ objectFit: "cover" }}
                            sizes="(max-width: 768px) 100vw, 33vw"
                          />
                          {/* Category Badge overlay */}
                          <span className="custom-blog-badge">
                            {blog.category}
                          </span>
                        </div>
                      </div>
                    </ScrollReveal>
                  ))}

                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}
