<?php
require_once 'admin/config/db.php';

// Fetch Latest Portfolio Items (Top 6)
$portfolio_stmt = $pdo->query("
    SELECT p.*, c.name as category_name 
    FROM portfolio_items p
    LEFT JOIN portfolio_categories c ON p.category_id = c.id
    WHERE p.status = 'published' 
    ORDER BY p.created_at DESC 
    LIMIT 6
");
$latest_portfolio = $portfolio_stmt->fetchAll();

// Fetch Latest Blog Posts (Top 3)
$blog_stmt = $pdo->query("
    SELECT p.*, c.name as category_name 
    FROM blog_posts p
    LEFT JOIN blog_categories c ON p.category_id = c.id
    WHERE p.status = 'published' 
    ORDER BY p.created_at DESC 
    LIMIT 3
");
$latest_blogs = $blog_stmt->fetchAll();

include 'includes/header.php';
?>

    <!-- Hero Section -->
    <section class="hero" id="hero">
        <!-- Hero Background Image (To be added via CSS) -->
        <div class="hero-overlay"></div>
        <div class="container hero-content">
            <span class="hero-subtitle">Architecture | Interiors | Construction</span>
            <h1 class="hero-title"><span style="color: #f0b71c;">Get Your Dream Home</span><br>Designed & Built in One
                Place</h1>
            <div class="hero-accent-line"></div>
            <p class="hero-text">Our in-hand experts help you to have a complete furnished<br>house right from planning,
                constructing & interior designing and<br>let you unfold your sweetest dream into reality.</p>
            <div class="hero-buttons">
                <a href="contact-us.php" class="btn btn-hero-outline-white">TALK TO US</a>
                <a href="get-a-free-quote.php" class="btn btn-hero-solid-gold">GET A QUOTE</a>
            </div>
        </div>
    </section>

    <!-- About Section -->
    <section class="about section-padding" id="about">
        <div class="container about-grid">
            <div class="about-image">
                <img src="assets/img/about-us-diagram.png"
                    alt="MK Construction phases: Architectural Design, Approvals, Structure & Planning, Interiors"
                    class="img-fluid rounded shadow" style="width:100%; height:auto;">
            </div>

            <div class="about-text-content">
                <h2 class="section-title">We Execute Every Phase From<br>Designing To Construction</h2>
                <div class="title-divider"></div>
                <h4 class="about-subtitle">Transform a Dream Home into Reality in 120 days</h4>

                <p>MK Construction & Builder is a leading construction company in Krishnagiri that takes care of your
                    home planning right from contemplating the design structure, elevating into beautiful construction
                    and designing your special interiors. We primarily focus on personalized customer-centric approach,
                    uncompromising business ethics, and utmost transparency.</p>

                <a href="get-a-free-quote.php" class="btn btn-yellow mt-4">Get A Quote</a>
            </div>
        </div>
    </section>

    <!-- Services Section -->
    <section class="services section-padding bg-light" id="services">
        <div class="container">
            <div class="section-header text-center">
                <span class="section-subtitle">Our Expertise</span>
                <h2 class="section-title">We Provide Comprehensive Services</h2>
                <p class="section-desc">From massive construction projects to intricate interior designs, MK
                    Construction covers it all.</p>
            </div>

            <div class="services-scroll-wrapper">
                <div class="services-scroll-container">
                    <!-- Service 1: Construction -->
                    <div class="service-scroll-card">
                        <div class="service-card-image">
                            <img src="assets/img/construction.jpg?v=<?php echo time(); ?>" alt="Construction Services">
                            <div class="service-card-overlay">
                                <h3>Construction</h3>
                            </div>
                        </div>
                        <div class="service-card-body">
                            <p>End-to-end commercial and residential construction services focusing on durability and excellence.</p>
                            <a href="construction-company-in-krishnagiri.php" class="service-link">View Details <i class="fa-solid fa-arrow-right"></i></a>
                        </div>
                    </div>

                    <!-- Service 2: Home Builder -->
                    <div class="service-scroll-card">
                        <div class="service-card-image">
                            <img src="assets/img/home_builder.jpg?v=<?php echo time(); ?>" alt="Home Builder">
                            <div class="service-card-overlay">
                                <h3>Home Builder</h3>
                            </div>
                        </div>
                        <div class="service-card-body">
                            <p>Crafting custom dream homes tailored precisely to your lifestyle and aesthetic preferences.</p>
                            <a href="home-builder-in-krishnagiri.php" class="service-link">View Details <i class="fa-solid fa-arrow-right"></i></a>
                        </div>
                    </div>

                    <!-- Service 3: Interior Design -->
                    <div class="service-scroll-card">
                        <div class="service-card-image">
                            <img src="assets/img/interior_design.jpg?v=<?php echo time(); ?>" alt="Interior Design">
                            <div class="service-card-overlay">
                                <h3>Interior Design</h3>
                            </div>
                        </div>
                        <div class="service-card-body">
                            <p>Transforming interior spaces into beautiful, functional, and deeply personalized environments.</p>
                            <a href="interior-designers-in-krishnagiri.php" class="service-link">View Details <i class="fa-solid fa-arrow-right"></i></a>
                        </div>
                    </div>

                    <!-- Service 4: Architecture -->
                    <div class="service-scroll-card">
                        <div class="service-card-image">
                            <img src="assets/img/architecture.jpg?v=<?php echo time(); ?>" alt="Architecture">
                            <div class="service-card-overlay">
                                <h3>Architecture</h3>
                            </div>
                        </div>
                        <div class="service-card-body">
                            <p>Innovative architectural design blending modern aesthetics with sustainable engineering.</p>
                            <a href="architecture-firm-in-krishnagiri.php" class="service-link">View Details <i class="fa-solid fa-arrow-right"></i></a>
                        </div>
                    </div>

                    <!-- Service 5: Other Services -->
                    <div class="service-scroll-card featured-scroll-card">
                        <div class="service-card-image">
                            <img src="assets/img/approvals.jpg?v=<?php echo time(); ?>" alt="Specialized Services">
                            <div class="service-card-overlay">
                                <h3>Other Services</h3>
                            </div>
                        </div>
                        <div class="service-card-body">
                            <p>Vasthu Planning, Approvals, Site Supervision, Elevators, Real Estate & Home Loans.</p>
                            <a href="other-services.php" class="service-link">Explore More <i class="fa-solid fa-arrow-right"></i></a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Latest Portfolio Section -->
    <section class="portfolio-recent section-padding bg-light" id="portfolio">
        <div class="container">
            <div class="section-header text-center">
                <span class="section-subtitle">Our Work</span>
                <h2 class="section-title">Latest <span>Projects</span></h2>
            </div>
            
            <div class="services-scroll-wrapper">
                <div class="services-scroll-container">
                    <?php if(count($latest_portfolio) > 0): ?>
                        <?php foreach($latest_portfolio as $item): ?>
                            <div class="service-scroll-card">
                                <div class="service-card-image">
                                    <img src="<?= htmlspecialchars($item['image_path']) ?>?v=<?= time() ?>" alt="<?= htmlspecialchars($item['title']) ?>">
                                    <div class="service-card-overlay">
                                        <h3><?= htmlspecialchars($item['category_name']) ?></h3>
                                    </div>
                                </div>
                                <div class="service-card-body">
                                    <h4 style="margin-bottom: 10px; font-family: var(--font-serif);"><?= htmlspecialchars($item['title']) ?></h4>
                                    <p><?= (strlen(strip_tags($item['description'])) > 100) ? substr(strip_tags($item['description']), 0, 100) . '...' : strip_tags($item['description']) ?></p>
                                    <a href="portfolio-details.php?slug=<?= htmlspecialchars($item['slug']) ?>" class="service-link">View Project <i class="fa-solid fa-arrow-right"></i></a>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    <?php else: ?>
                        <div class="text-center" style="width: 100%; padding: 40px;">
                            <p>No recent projects found.</p>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
            
            <div class="text-center mt-4">
                <a href="portfolio.php" class="btn btn-outline-dark">View All Portfolio</a>
            </div>
        </div>
    </section>

    <!-- Call to Action Banner -->
    <section class="cta-banner">
        <div class="container cta-content">
            <div class="cta-text">
                <h2>Ready to Start Your Construction Journey?</h2>
                <p>Contact N. Karthik today for expert consultation and a personalized quote.</p>
            </div>
            <div class="cta-action">
                <a href="tel:+918525009751" class="btn btn-primary btn-large"><i class="fa-solid fa-phone"></i> Call +91
                    85250 09751</a>
            </div>
        </div>
    </section>

    <!-- Latest Blogs Section -->
    <section class="blog-recent section-padding" id="blog">
        <div class="container">
            <div class="section-header text-center">
                <span class="section-subtitle">Our Insights</span>
                <h2 class="section-title">Latest <span>Articles</span></h2>
            </div>
            
            <div class="blog-grid" style="display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 30px; margin-top: 50px;">
                <?php if(count($latest_blogs) > 0): ?>
                    <?php foreach($latest_blogs as $post): 
                        $date = new DateTime($post['created_at']);
                        $formatted_date = $date->format('d M, Y');
                    ?>
                        <div class="blog-card" style="background: var(--white); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm); border: 1px solid rgba(0,0,0,0.05); transition: var(--transition);">
                            <div class="blog-image" style="height: 240px; overflow: hidden;">
                                <a href="blog-details.php?slug=<?= htmlspecialchars($post['slug']) ?>">
                                    <img src="<?= htmlspecialchars($post['image_path']) ?>" alt="<?= htmlspecialchars($post['title']) ?>" style="width: 100%; height: 100%; object-fit: cover; transition: transform 0.5s ease;">
                                </a>
                            </div>
                            <div class="blog-content" style="padding: 25px;">
                                <div class="blog-meta" style="display: flex; gap: 15px; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 12px;">
                                    <span><i class="fa-regular fa-calendar" style="color: var(--primary-color);"></i> <?= $formatted_date ?></span>
                                    <span><i class="fa-solid fa-folder" style="color: var(--primary-color);"></i> <?= htmlspecialchars($post['category_name']) ?></span>
                                </div>
                                <h3 style="font-family: var(--font-serif); font-size: 1.4rem; margin-bottom: 15px; line-height: 1.4;">
                                    <a href="blog-details.php?slug=<?= htmlspecialchars($post['slug']) ?>" style="color: var(--dark-nav); text-decoration: none;"><?= htmlspecialchars($post['title']) ?></a>
                                </h3>
                                <p style="color: var(--text-muted); font-size: 0.95rem; line-height: 1.6; margin-bottom: 20px;">
                                    <?= (strlen(strip_tags($post['content'])) > 120) ? substr(strip_tags($post['content']), 0, 120) . '...' : strip_tags($post['content']) ?>
                                </p>
                                <a href="blog-details.php?slug=<?= htmlspecialchars($post['slug']) ?>" class="service-link">Read More <i class="fa-solid fa-arrow-right"></i></a>
                            </div>
                        </div>
                    <?php endforeach; ?>
                <?php else: ?>
                    <div class="text-center" style="grid-column: 1 / -1; padding: 40px;">
                        <p>No recent articles found.</p>
                    </div>
                <?php endif; ?>
            </div>
            
            <div class="text-center mt-4">
                <a href="blog.php" class="btn btn-outline-dark">Explore Our Blog</a>
            </div>
        </div>
    </section>

    <!-- Contact Section -->
    <section class="contact section-padding" id="contact">
        <div class="container">
            <div class="section-header text-center">
                <span class="section-subtitle">Get In Touch</span>
                <h2 class="section-title">Contact Us For Free Consultation</h2>
            </div>
            <div class="contact-grid">
                <div class="contact-details">
                    <div class="contact-card">
                        <div class="contact-icon"><i class="fa-solid fa-user-tie"></i></div>
                        <div class="contact-info">
                            <h4>Proprietor</h4>
                            <p>N. Karthik</p>
                        </div>
                    </div>
                    <div class="contact-card">
                        <div class="contact-icon"><i class="fa-solid fa-location-dot"></i></div>
                        <div class="contact-info">
                            <h4>Office Address</h4>
                            <p>Bangalore Road, Beside Union Bank,<br>SBI ATM, First Floor,<br>Krishnagiri – 635001.</p>
                        </div>
                    </div>
                    <div class="contact-card">
                        <div class="contact-icon"><i class="fa-solid fa-envelope"></i></div>
                        <div class="contact-info">
                            <h4>Email Address</h4>
                            <p><a href="mailto:sgirkarthik1993@gmail.com">sgirkarthik1993@gmail.com</a></p>
                        </div>
                    </div>
                    <div class="contact-card">
                        <div class="contact-icon"><i class="fa-solid fa-phone"></i></div>
                        <div class="contact-info">
                            <h4>Phone Number</h4>
                            <p><a href="tel:+918525009751">+91 85250 09751</a></p>
                        </div>
                    </div>
                </div>
                <div class="contact-map box-shadow rounded overflow-hidden">
                    <iframe
                        src="https://www.google.com/maps/embed?pb=!1m14!1m8!1m3!1d3896.223835694297!2d78.2130063!3d12.526989!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zMTLCsDMxJzM3LjIiTiA3OMKwMTInNDYuOCJF!5e0!3m2!1sen!2sin!4v1700000000000!5m2!1sen!2sin"
                        width="100%" height="450" style="border:0;" allowfullscreen="" loading="lazy"
                        referrerpolicy="no-referrer-when-downgrade"></iframe>
                </div>
            </div>
        </div>
    </section>

<?php include 'includes/footer.php'; ?>
