<?php
require_once 'includes/header.php';

// Dohvatanje featured kategorija
$featured_categories = get_rows("
    SELECT c.*, 
    (SELECT COUNT(*) FROM product_categories pc JOIN products p ON pc.product_id = p.id WHERE pc.category_id = c.id AND p.status = 'active') as product_count,
    (SELECT image FROM product_images pi JOIN products p ON pi.product_id = p.id JOIN product_categories pc ON p.id = pc.product_id 
     WHERE pc.category_id = c.id AND p.status = 'active' ORDER BY pi.sort_order ASC LIMIT 1) as image
    FROM categories c
    WHERE c.parent_id IS NULL
    ORDER BY c.name ASC
    LIMIT 4
");

// Dohvatanje featured proizvoda
$featured_products = get_rows("
    SELECT p.*, 
    (SELECT image FROM product_images pi WHERE pi.product_id = p.id ORDER BY pi.sort_order ASC LIMIT 1) as image,
    (SELECT name FROM categories c JOIN product_categories pc ON c.id = pc.category_id WHERE pc.product_id = p.id LIMIT 1) as category_name
    FROM products p
    WHERE p.status = 'active'
    ORDER BY p.id DESC
    LIMIT 8
");

// Dohvatanje proizvoda na akciji
$sale_products = get_rows("
    SELECT p.*, 
    (SELECT image FROM product_images pi WHERE pi.product_id = p.id ORDER BY pi.sort_order ASC LIMIT 1) as image,
    (SELECT name FROM categories c JOIN product_categories pc ON c.id = pc.category_id WHERE pc.product_id = p.id LIMIT 1) as category_name
    FROM products p
    WHERE p.status = 'active' AND p.sale_price IS NOT NULL AND p.sale_price > 0
    ORDER BY (p.price - p.sale_price) / p.price DESC
    LIMIT 4
");

// Dohvatanje svedočenja korisnika (recenzije)
$testimonials = get_rows("
    SELECT r.*, p.name as product_name, p.slug as product_slug
    FROM reviews r
    JOIN products p ON r.product_id = p.id
    WHERE r.status = 'approved' AND r.rating >= 4
    ORDER BY r.created_at DESC
    LIMIT 3
");
?>

<!-- Price Match Banner -->
<div class="price-match-banner">
    <div class="container">
        <div class="price-match-content">
            <div class="price-match-icon">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <path d="M12 1v22"/>
                    <path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>
                </svg>
            </div>
            <div class="price-match-text">
                <strong>Price Match Garancija!</strong> Našli ste Hugong aparate po nižoj ceni? Mi ćemo ponuditi još povoljniju!
            </div>
            <a href="/price-match" class="price-match-link">Saznajte više</a>
        </div>
    </div>
</div>

<!-- Dynamic Hero Section -->
<section class="hero-section">
    <div class="hero-slider">
        <div class="hero-slide active" style="background-image: url('/assets/images/hero-bg-1.jpg')">
            <div class="hero-content">
                <h1 class="hero-title">HUGONG aparati za zavarivanje</h1>
                <p class="hero-subtitle">Profesionalni kvalitet uz najpovoljnije cene u Srbiji</p>
                <div class="hero-buttons">
                    <a href="/svi-proizvodi" class="btn-primary">Pogledaj sve aparate</a>
                    <a href="#featured-categories" class="btn-outline scroll-to">Istražite kategorije</a>
                </div>
            </div>
        </div>
        <div class="hero-slide" style="background-image: url('/assets/images/hero-bg-2.jpg')">
            <div class="hero-content">
                <h1 class="hero-title">Profesionalna IGBT tehnologija</h1>
                <p class="hero-subtitle">Ušteda energije, pouzdanost i trajnost u svim uslovima rada</p>
                <div class="hero-buttons">
                    <a href="/o-hugong-brendu" class="btn-primary">O Hugong brendu</a>
                    <a href="/kontakt" class="btn-outline">Kontaktirajte nas</a>
                </div>
            </div>
        </div>
        <div class="hero-slide" style="background-image: url('/assets/images/hero-bg-3.jpg')">
            <div class="hero-content">
                <h1 class="hero-title">Garancija 24 meseca</h1>
                <p class="hero-subtitle">Pouzdani aparati sa profesionalnom podrškom i servisom</p>
                <div class="hero-buttons">
                    <a href="/hugong-rel-aparati" class="btn-primary">REL aparati</a>
                    <a href="/hugong-tig-aparati" class="btn-outline">TIG aparati</a>
                </div>
            </div>
        </div>
        <div class="hero-controls">
            <button class="hero-prev" aria-label="Prethodni slide">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <polyline points="15 18 9 12 15 6"></polyline>
                </svg>
            </button>
            <div class="hero-dots">
                <span class="dot active" data-slide="0"></span>
                <span class="dot" data-slide="1"></span>
                <span class="dot" data-slide="2"></span>
            </div>
            <button class="hero-next" aria-label="Sledeći slide">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                    <polyline points="9 18 15 12 9 6"></polyline>
                </svg>
            </button>
        </div>
    </div>
</section>

<!-- Key Benefits Section -->
<section class="benefits-section">
    <div class="container">
        <div class="benefits-grid">
            <div class="benefit-item">
                <div class="benefit-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <circle cx="12" cy="12" r="10"></circle>
                        <polyline points="12 6 12 12 16 14"></polyline>
                    </svg>
                </div>
                <h3>Brza isporuka</h3>
                <p>Besplatna isporuka za sve porudžbine na teritoriji Srbije</p>
            </div>
            <div class="benefit-item">
                <div class="benefit-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path>
                        <polyline points="22 4 12 14.01 9 11.01"></polyline>
                    </svg>
                </div>
                <h3>Garancija kvaliteta</h3>
                <p>24 meseca garancije na sve Hugong aparate</p>
            </div>
            <div class="benefit-item">
                <div class="benefit-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M20.24 12.24a6 6 0 0 0-8.49-8.49L5 10.5V19h8.5z"></path>
                        <line x1="16" y1="8" x2="2" y2="22"></line>
                        <line x1="17.5" y1="15" x2="9" y2="15"></line>
                    </svg>
                </div>
                <h3>Najpovoljnije cene</h3>
                <p>Garantovano najniže cene u Srbiji uz Price Match garanciju</p>
            </div>
            <div class="benefit-item">
                <div class="benefit-icon">
                    <svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <path d="M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z"></path>
                    </svg>
                </div>
                <h3>Stručna podrška</h3>
                <p>Kompletna tehnička podrška i servis na teritoriji Srbije</p>
            </div>
        </div>
    </div>
</section>

<!-- Featured Categories -->
<section id="featured-categories" class="featured-categories-section">
    <div class="container">
        <div class="section-header">
            <h2 class="section-title">Istražite kategorije aparata</h2>
            <p class="section-subtitle">Pronađite idealno rešenje za vaše zavarivačke potrebe</p>
        </div>
        <div class="categories-grid">
            <?php foreach($featured_categories as $category): ?>
            <a href="/<?php echo $category['slug']; ?>" class="category-card">
                <div class="category-image">
                    <?php if (!empty($category['image'])): ?>
                    <img src="<?php echo UPLOADS_URL . '/products/' . $category['image']; ?>" alt="<?php echo $category['name']; ?> aparati za zavarivanje" loading="lazy">
                    <?php else: ?>
                    <img src="/assets/images/no-image.jpg" alt="<?php echo $category['name']; ?> aparati za zavarivanje" loading="lazy">
                    <?php endif; ?>
                    <div class="category-overlay"></div>
                </div>
                <div class="category-content">
                    <h3 class="category-title"><?php echo $category['name']; ?></h3>
                    <span class="category-count"><?php echo $category['product_count']; ?> proizvoda</span>
                    <span class="category-link">Pogledaj ponudu <i class="arrow-icon">→</i></span>
                </div>
            </a>
            <?php endforeach; ?>
        </div>
    </div>
</section>

<!-- Featured Products Section -->
<section class="featured-products-section">
    <div class="container">
        <div class="section-header">
            <h2 class="section-title">Najprodavaniji modeli</h2>
            <p class="section-subtitle">Profesionalni Hugong aparati za zavarivanje po fantastičnim cenama</p>
        </div>
        <div class="products-grid">
            <?php foreach($featured_products as $key => $product): ?>
            <?php if($key < 4): ?>
            <div class="product-card">
                <?php if (!empty($product['sale_price'])): ?>
                <span class="product-badge sale">Akcija</span>
                <?php elseif ($key < 2): ?>
                <span class="product-badge popular">Popularno</span>
                <?php endif; ?>
                <a href="/<?php echo $product['slug']; ?>" class="product-image">
                    <?php if (!empty($product['image'])): ?>
                    <img src="<?php echo UPLOADS_URL . '/products/' . $product['image']; ?>" alt="<?php echo $product['name']; ?>" loading="lazy">
                    <?php else: ?>
                    <img src="/assets/images/no-image.jpg" alt="<?php echo $product['name']; ?>" loading="lazy">
                    <?php endif; ?>
                </a>
                <div class="product-content">
                    <div class="product-category"><?php echo $product['category_name']; ?></div>
                    <h3 class="product-title">
                        <a href="/<?php echo $product['slug']; ?>"><?php echo $product['name']; ?></a>
                    </h3>
                    <div class="product-price">
                        <?php if (!empty($product['sale_price'])): ?>
                        <span class="price-current"><?php echo format_price($product['sale_price']); ?></span>
                        <span class="price-old"><?php echo format_price($product['price']); ?></span>
                        <?php else: ?>
                        <span class="price-current"><?php echo format_price($product['price']); ?></span>
                        <?php endif; ?>
                    </div>
                    <div class="product-actions">
                        <a href="/<?php echo $product['slug']; ?>" class="btn-product">Detaljnije</a>
                    </div>
                </div>
            </div>
            <?php endif; ?>
            <?php endforeach; ?>
        </div>
        <div class="section-action">
            <a href="/svi-proizvodi" class="btn-secondary">Pogledaj sve proizvode</a>
        </div>
    </div>
</section>

<!-- Special Offer Section -->
<section class="special-offer-section">
    <div class="container">
        <div class="special-offer-content">
            <div class="special-offer-text">
                <h2 class="special-offer-title">Akcijski modeli sa drastičnim popustima</h2>
                <p class="special-offer-description">Izdvajamo aparate na akciji koje možete kupiti po sniženim cenama. Garancija i kvalitet kao i za sve druge modele!</p>
                <a href="/akcijski-modeli" class="btn-primary">Pogledaj akcijske modele</a>
            </div>
            <div class="special-offer-products">
                <?php foreach($sale_products as $key => $product): ?>
                <?php if($key < 2): ?>
                <div class="special-product">
                    <div class="special-product-image">
                        <?php if (!empty($product['image'])): ?>
                        <img src="<?php echo UPLOADS_URL . '/products/' . $product['image']; ?>" alt="<?php echo $product['name']; ?>" loading="lazy">
                        <?php else: ?>
                        <img src="/assets/images/no-image.jpg" alt="<?php echo $product['name']; ?>" loading="lazy">
                        <?php endif; ?>
                    </div>
                    <div class="special-product-content">
                        <h3 class="special-product-title"><?php echo $product['name']; ?></h3>
                        <div class="special-product-price">
                            <span class="price-discount">-<?php echo round((($product['price'] - $product['sale_price']) / $product['price']) * 100); ?>%</span>
                            <span class="price-current"><?php echo format_price($product['sale_price']); ?></span>
                            <span class="price-old"><?php echo format_price($product['price']); ?></span>
                        </div>
                        <a href="/<?php echo $product['slug']; ?>" class="btn-outline">Pogledaj</a>
                    </div>
                </div>
                <?php endif; ?>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
</section>

<!-- Why Choose Us Section -->
<section class="why-choose-section">
    <div class="container">
        <div class="section-header">
            <h2 class="section-title">Zašto izabrati Hugong aparate?</h2>
            <p class="section-subtitle">35+ godina iskustva u proizvodnji profesionalnih aparata za zavarivanje</p>
        </div>
        <div class="why-choose-content">
            <div class="why-choose-image">
                <img src="/assets/images/why-hugong.jpg" alt="Hugong aparati za zavarivanje - kvalitet i pouzdanost" loading="lazy">
            </div>
            <div class="why-choose-features">
                <div class="feature-item">
                    <div class="feature-icon">
                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M22 12h-4l-3 9L9 3l-3 9H2"></path>
                        </svg>
                    </div>
                    <div class="feature-content">
                        <h3>Napredna IGBT tehnologija</h3>
                        <p>Ušteda energije do 30% uz stabilniji luk i kvalitetnije varove</p>
                    </div>
                </div>
                <div class="feature-item">
                    <div class="feature-icon">
                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            <polyline points="20 6 9 17 4 12"></polyline>
                        </svg>
                    </div>
                    <div class="feature-content">
                        <h3>Multifunkcionalni aparati</h3>
                        <p>Kombinovani MIG/MAG, REL i TIG aparati za različite primene</p>
                    </div>
                </div>
                <div class="feature-item">
                    <div class="feature-icon">
                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            <circle cx="12" cy="12" r="10"></circle>
                            <path d="M12 8v4"></path>
                            <path d="M12 16h.01"></path>
                        </svg>
                    </div>
                    <div class="feature-content">
                        <h3>Profesionalne performanse</h3>
                        <p>Digitalni displej, pulsno zavarivanje i napredne funkcije</p>
                    </div>
                </div>
                <div class="feature-item">
                    <div class="feature-icon">
                        <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                            <path d="M3 18v-6a9 9 0 0 1 18 0v6"></path>
                            <path d="M21 19a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3zM3 19a2 2 0 0 0 2 2h1a2 2 0 0 0 2-2v-3a2 2 0 0 0-2-2H3z"></path>
                        </svg>
                    </div>
                    <div class="feature-content">
                        <h3>Tehnička podrška</h3>
                        <p>Kompletna podrška, obuka i servis na teritoriji Srbije</p>
                    </div>
                </div>
            </div>
        </div>
        <div class="section-action">
            <a href="/o-hugong-brendu" class="btn-secondary">Saznajte više o Hugong brendu</a>
        </div>
    </div>
</section>

<!-- Customer Reviews Section -->
<?php if(!empty($testimonials)): ?>
<section class="testimonials-section">
    <div class="container">
        <div class="section-header">
            <h2 class="section-title">Šta kažu naši kupci</h2>
            <p class="section-subtitle">Iskustva profesionalaca koji koriste Hugong aparate</p>
        </div>
        <div class="testimonials-slider">
            <?php foreach($testimonials as $index => $testimonial): ?>
            <div class="testimonial-slide <?php echo $index === 0 ? 'active' : ''; ?>">
                <div class="testimonial-content">
                    <div class="testimonial-rating">
                        <?php for ($i = 1; $i <= 5; $i++): ?>
                            <span class="star"><?php echo $i <= $testimonial['rating'] ? '★' : '☆'; ?></span>
                        <?php endfor; ?>
                    </div>
                    <p class="testimonial-text">"<?php echo htmlspecialchars($testimonial['comment']); ?>"</p>
                    <div class="testimonial-author">
                        <div class="author-name"><?php echo htmlspecialchars($testimonial['name']); ?></div>
                        <div class="author-info"><?php echo $testimonial['product_name']; ?></div>
                    </div>
                    <a href="/<?php echo $testimonial['product_slug']; ?>" class="testimonial-link">Pogledaj proizvod</a>
                </div>
            </div>
            <?php endforeach; ?>
            <div class="testimonial-controls">
                <button class="testimonial-prev" aria-label="Prethodno iskustvo">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polyline points="15 18 9 12 15 6"></polyline>
                    </svg>
                </button>
                <div class="testimonial-dots">
                    <?php foreach($testimonials as $index => $testimonial): ?>
                    <span class="dot <?php echo $index === 0 ? 'active' : ''; ?>" data-slide="<?php echo $index; ?>"></span>
                    <?php endforeach; ?>
                </div>
                <button class="testimonial-next" aria-label="Sledeće iskustvo">
                    <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
                        <polyline points="9 18 15 12 9 6"></polyline>
                    </svg>
                </button>
            </div>
        </div>
    </div>
</section>
<?php endif; ?>

<!-- Brand Story Section -->
<section class="brand-story-section">
    <div class="container">
        <div class="brand-story-content">
            <div class="brand-logo">
                <img src="/assets/images/hugong-logo.png" alt="Hugong logo - profesionalni aparati za zavarivanje" loading="lazy">
            </div>
            <div class="brand-description">
                <h2>Kvalitet koji govori sam za sebe</h2>
                <p>Hugong je vodeći svetski proizvođač aparata za zavarivanje, osnovan 1983. godine. Kompanija je specijalizovana za proizvodnju inverterskih aparata koristeći najnoviju IGBT tehnologiju, što omogućava poboljšane performanse, efikasnost i dugotrajnost.</p>
                <p>Sa više od 35 godina iskustva, Hugong je razvio reputaciju pouzdanog proizvođača koji nudi profesionalne aparate visokog kvaliteta po pristupačnim cenama.</p>
                <a href="/kontakt" class="btn-primary">Kontaktirajte nas</a>
            </div>
        </div>
    </div>
</section>

<!-- Newsletter & Contact -->
<section class="newsletter-section">
    <div class="container">
        <div class="newsletter-container">
            <div class="newsletter-text">
                <h2>Budite u toku sa najnovijim ponudama</h2>
                <p>Prijavite se na našu mailing listu i prvi saznajte za akcije i nove modele aparata za zavarivanje</p>
            </div>
            <form class="newsletter-form" action="/subscribe.php" method="post">
                <input type="email" name="email" placeholder="Vaša email adresa" required>
                <button type="submit" class="btn-primary">Prijavi me</button>
            </form>
        </div>
    </div>
</section>

<!-- SEO Strukturirani podaci -->
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "name": "Hugong Aparati",
  "url": "https://hugong-aparati.rs",
  "logo": "https://hugong-aparati.rs/assets/images/logo.png",
  "description": "Originalni Hugong aparati za zavarivanje sa garancijom od 24 meseca. Najpovoljnije cene i besplatna isporuka za celu Srbiju.",
  "telephone": "<?php echo get_setting('contact_phone', '+381 65 8065 065'); ?>",
  "email": "<?php echo get_setting('contact_email', 'info@hugong-aparati.rs'); ?>"
}
</script>

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "WebSite",
  "url": "https://hugong-aparati.rs",
  "potentialAction": {
    "@type": "SearchAction",
    "target": "https://hugong-aparati.rs/search.php?q={search_term_string}",
    "query-input": "required name=search_term_string"
  }
}
</script>

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