<?php
session_start();
require_once 'admin-panal/includes/db.php';

// Fetch contact settings
$stmtContact = $pdo->query("SELECT * FROM contact_settings LIMIT 1");
$contactSet = $stmtContact->fetch(PDO::FETCH_ASSOC);

// Flash messages
$flash = $_SESSION['flash'] ?? null;
unset($_SESSION['flash']);
?>
<!DOCTYPE html>
<html lang="en">
<head>
       <!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-Z2X2T395KZ"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-Z2X2T395KZ');
</script>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Contact Us — Elegance of India</title>
  <link rel="preconnect" href="https://fonts.googleapis.com" />
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  <link href="https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap" rel="stylesheet" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css" />
  <link rel="stylesheet" href="style.css" />
  <style>
    .contact-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 80px; align-items: start; }
    .contact-form-card { background: #fdfbf8; padding: 50px; border-radius: 4px; border: 1px solid #f1ece4; }
    
    @media (max-width: 992px) {
      .contact-grid { grid-template-columns: 1fr; gap: 50px; }
      .contact-form-card { padding: 30px; }
    }
    @media (max-width: 768px) {
      .page-header { padding: 40px 0 !important; }
      .page-header h1 { font-size: 2.2rem !important; }
      .contact-section { padding: 40px 0 !important; }
    }
  </style>
</head>
<body>
<?php include 'inc/header.php'; ?>

<div class="page-header" style="background: #fdfbf8; padding: 60px 0; text-align: center; border-bottom: 1px solid #eee;">
    <div class="container">
        <h1 style="font-family: 'Playfair Display', serif; font-size: 3rem; margin-bottom: 10px;">Contact Us</h1>
        <p style="color: #888; letter-spacing: 2px; text-transform: uppercase; font-size: 0.9rem;">Reach Out To Us</p>
    </div>
</div>

    <div class="contact-section" style="padding: 80px 0; background: #fff;">
        <div class="container">
            <?php if ($flash): ?>
                <div style="padding: 15px; margin-bottom: 30px; border-radius: 4px; background: <?= $flash['type'] === 'success' ? '#d4edda' : '#f8d7da' ?>; color: <?= $flash['type'] === 'success' ? '#155724' : '#721c24' ?>; border: 1px solid <?= $flash['type'] === 'success' ? '#c3e6cb' : '#f5c6cb' ?>;">
                   <i class="fas <?= $flash['type'] === 'success' ? 'fa-check-circle' : 'fa-exclamation-circle' ?>"></i> <?= htmlspecialchars($flash['msg']) ?>
                </div>
            <?php endif; ?>

            <div class="contact-grid">
                <!-- Contact info -->
                <div>
                    <h2 style="margin-bottom: 30px; font-weight: 600;">Get In Touch</h2>
                    <?php if (!empty($contactSet['address'])): ?>
                    <div style="margin-bottom: 30px;">
                        <h4 style="color: #c9a96e; margin-bottom: 10px; font-size: 1.2rem; text-transform: uppercase; letter-spacing: 1px;">Our Store</h4>
                        <p style="color: #666; font-size: 1.1rem; line-height: 1.6; max-width: 380px;"><?= nl2br(htmlspecialchars($contactSet['address'])) ?></p>
                    </div>
                    <?php endif; ?>

                    <div style="margin-bottom: 30px;">
                        <h4 style="color: #c9a96e; margin-bottom: 10px; font-size: 1.2rem; text-transform: uppercase; letter-spacing: 1px;">Customer Care</h4>
                        <p style="color: #666; font-size: 1.1rem; line-height: 1.8;">
                           <?php if (!empty($contactSet['email'])): ?> <strong>Email:</strong> <?= htmlspecialchars($contactSet['email']) ?><br><?php endif; ?>
                           <?php if (!empty($contactSet['phone'])): ?> <strong>Phone:</strong> <?= htmlspecialchars($contactSet['phone']) ?><?php endif; ?>
                        </p>
                    </div>

                    <?php if (!empty($contactSet['hours'])): ?>
                    <div style="margin-bottom: 30px;">
                        <h4 style="color: #c9a96e; margin-bottom: 10px; font-size: 1.2rem; text-transform: uppercase; letter-spacing: 1px;">Business Hours</h4>
                        <p style="color: #666; font-size: 1.1rem; line-height: 1.6;"><?= nl2br(htmlspecialchars($contactSet['hours'])) ?></p>
                    </div>
                    <?php endif; ?>
                </div>

            <!-- Contact form -->
            <div class="contact-form-card">
                <h3 style="margin-bottom: 30px; font-weight: 600; font-size: 1.4rem;">Send a Message</h3>
                <form action="contact_process.php" method="POST">
                    <div style="margin-bottom: 20px;">
                        <label style="display: block; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; color: #888;">Full Name</label>
                        <input type="text" name="name" required style="width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 2px;">
                    </div>
                    <div style="margin-bottom: 20px;">
                        <label style="display: block; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; color: #888;">Email Address</label>
                        <input type="email" name="email" required style="width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 2px;">
                    </div>
                    <div style="margin-bottom: 20px;">
                        <label style="display: block; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 8px; color: #888;">Message</label>
                        <textarea name="message" rows="5" required style="width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 2px;"></textarea>
                    </div>
                    <button type="submit" class="btn btn-gold" style="width: 100%; padding: 15px; text-transform: uppercase; letter-spacing: 2px; font-weight: bold;">Send Message</button>
                </form>
            </div>
        </div>
    </div>
</div>

<?php include 'inc/footer.php'; ?>
</body>
</html>
