import React from "react";
import Image from "next/image";
import Link from "next/link";
import { ScrollReveal } from "@/animations/Reveal";
import { blogPosts } from "@/data/blog";

export default function BlogGrid() {
  const blogs = blogPosts;

  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) {
            .elementor-104 .elementor-element.elementor-element-c70681e {
                margin-top: var(--space-section) !important;
                margin-bottom: 16px !important;
            }
            .custom-blog-grid {
                grid-template-columns: 1fr !important;
                gap: 28px !important;
                padding: 24px 20px !important;
            }
        }

        @media (max-width: 767px) {
            .elementor-104 .elementor-element.elementor-element-c70681e {
                --padding-left: 10px !important;
                --padding-right: 10px !important;
                padding-left: 10px !important;
                padding-right: 10px !important;
            }
            .elementor-104 .elementor-element.elementor-element-3dec5cf {
                --padding-left: 0px !important;
                --padding-right: 0px !important;
                padding-left: 0 !important;
                padding-right: 0 !important;
            }
            .elementor-104 .elementor-element.elementor-element-aa12479,
            .elementor-104 .elementor-element.elementor-element-aa12479 > .elementor-widget-container,
            .elementor-104 .archive-listing,
            .elementor-104 .custom-blog-grid {
                width: 100% !important;
                max-width: 100% !important;
            }
            .elementor-104 .custom-blog-grid {
                padding-left: 0 !important;
                padding-right: 0 !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-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 18px 0 !important;
            text-transform: none !important;
            font-family: var(--font-manrope), sans-serif !important;
        }

        /* Bottom block pinned to the card base. Keeps Read More + image at the
           same vertical position across cards with different text lengths. */
        .custom-blog-bottom {
            display: flex !important;
            flex-direction: column !important;
            margin-top: auto !important;
        }

        .custom-blog-readmore {
            display: inline-flex !important;
            align-items: center !important;
            align-self: flex-start !important;
            gap: 6px !important;
            font-size: 13px !important;
            font-weight: 800 !important;
            color: #c01227 !important;
            text-transform: uppercase !important;
            letter-spacing: 0.5px !important;
            margin: 0 0 24px 0 !important;
            font-family: var(--font-manrope), sans-serif !important;
        }

        .custom-blog-readmore-arrow {
            transition: transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1) !important;
        }

        .custom-blog-card:hover .custom-blog-readmore-arrow {
            transform: translateX(5px) !important;
        }

        .custom-blog-img-container {
            position: relative !important;
            width: 100% !important;
            aspect-ratio: 4 / 3 !important;
            border-radius: 20px !important;
            overflow: hidden !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={blog.slug} delay={(i % 3) * 0.08} duration={0.8} yOffset={35}>
                      <Link href={`/blog/${blog.slug}`} className="custom-blog-card" style={{ textDecoration: "none" }}>
                        {/* Text Block at Top */}
                        <div className="flex flex-col">
                          {/* Bold Title */}
                          <h3 className="custom-blog-title">
                            {blog.title}
                          </h3>

                          {/* Description Excerpt */}
                          <p className="custom-blog-excerpt">
                            {blog.excerpt}
                          </p>
                        </div>

                        {/* Bottom block: Read more + image, pinned to the card
                            base so Read More aligns across every card regardless
                            of title / excerpt length. */}
                        <div className="custom-blog-bottom">
                          {/* Read more affordance (whole card is the link) */}
                          <span className="custom-blog-readmore">
                            Read More
                            <svg
                              className="custom-blog-readmore-arrow"
                              width="16"
                              height="16"
                              viewBox="0 0 24 24"
                              fill="none"
                              stroke="currentColor"
                              strokeWidth="2.5"
                              strokeLinecap="round"
                              strokeLinejoin="round"
                              aria-hidden="true"
                            >
                              <line x1="5" y1="12" x2="19" y2="12" />
                              <polyline points="12 5 19 12 12 19" />
                            </svg>
                          </span>

                          {/* Image */}
                          <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>
                      </Link>
                    </ScrollReveal>
                  ))}

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