<?php
// ১. ডাটাবেজ কনফিগ ও সেশন যুক্ত করা
ini_set('display_errors', 1);
error_reporting(E_ALL);

require_once __DIR__ . '/config.php';

if (session_status() === PHP_SESSION_NONE) {
    session_start();
}

// ২. ডাটাবেজ থেকে সাইট টাইটেল তুলে আনা
try {
    $stmt = $pdo->query("SELECT site_title, site_logo FROM site_settings WHERE id = 1");
    $site_settings = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $site_settings = [
        'site_title' => 'ShopVista',
        'site_logo'  => 'default_logo.png'
    ];
}

$site_name = $site_settings['site_title'] ?? 'ShopVista';
$msg = "";

// ৩. কন্টাক্ট ফর্ম সাবমিট প্রসেসিং
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = htmlspecialchars($_POST['name'] ?? '');
    $email = htmlspecialchars($_POST['email'] ?? '');
    $message = htmlspecialchars($_POST['message'] ?? '');

    if (!empty($name) && !empty($message)) {
        // মেসেজ সফলভাবে প্রাপ্তির নোটিফিকেশন
        $msg = "<div class='alert alert-success'>ধন্যবাদ $name! আপনার মেসেজটি সফলভাবে পাঠানো হয়েছে। আমরা খুব দ্রুত আপনার সাথে যোগাযোগ করব।</div>";
    } else {
        $msg = "<div class='alert alert-danger'>অনুগ্রহ করে নাম এবং মেসেজ ঘরটি পূরণ করুন।</div>";
    }
}
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Contact Us - <?php echo htmlspecialchars($site_name); ?></title>
    
    <!-- FontAwesome Font -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        :root {
            --primary-color: #007bff;
            --secondary-color: #2b2d42;
            --whatsapp-color: #25d366;
            --text-color: #4a4a4a;
            --bg-light: #f8f9fa;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
        }

        body {
            background-color: #f4f6f9;
            color: var(--text-color);
            line-height: 1.6;
        }

        /* Hero Banner */
        .contact-hero {
            background: linear-gradient(135deg, #007bff 0%, #0056b3 100%);
            color: #ffffff;
            text-align: center;
            padding: 50px 20px;
        }

        .contact-hero h1 {
            font-size: 2.2rem;
            font-weight: 700;
            margin-bottom: 10px;
        }

        .contact-hero p {
            font-size: 1rem;
            opacity: 0.9;
            max-width: 600px;
            margin: 0 auto;
        }

        /* Container */
        .container {
            max-width: 1000px;
            margin: -30px auto 40px auto;
            padding: 0 15px;
        }

        .contact-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
            gap: 25px;
        }

        .contact-card {
            background: #ffffff;
            border-radius: 12px;
            padding: 30px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.06);
        }

        .section-title {
            font-size: 1.3rem;
            color: var(--secondary-color);
            margin-bottom: 20px;
            position: relative;
            padding-bottom: 8px;
            font-weight: 600;
        }

        .section-title::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 40px;
            height: 3px;
            background: var(--primary-color);
            border-radius: 2px;
        }

        /* Info Items */
        .info-item {
            display: flex;
            align-items: flex-start;
            gap: 15px;
            margin-bottom: 20px;
        }

        .info-icon {
            width: 45px;
            height: 45px;
            background: #e0edff;
            color: var(--primary-color);
            border-radius: 10px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.2rem;
            flex-shrink: 0;
        }

        .info-text h4 {
            font-size: 1rem;
            color: var(--secondary-color);
            margin-bottom: 3px;
        }

        .info-text p, .info-text a {
            font-size: 0.9rem;
            color: #666;
            text-decoration: none;
            word-break: break-all;
        }

        .info-text a:hover {
            color: var(--primary-color);
        }

        /* WhatsApp Button */
        .whatsapp-btn {
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            background: var(--whatsapp-color);
            color: #ffffff;
            padding: 12px 20px;
            border-radius: 8px;
            text-decoration: none;
            font-weight: 600;
            margin-top: 15px;
            transition: background 0.3s ease;
        }

        .whatsapp-btn:hover {
            background: #1ebc57;
        }

        /* Form Styles */
        .form-group {
            margin-bottom: 18px;
        }

        .form-group label {
            display: block;
            font-size: 0.88rem;
            font-weight: 600;
            margin-bottom: 6px;
            color: #444;
        }

        .form-control {
            width: 100%;
            padding: 11px 14px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 0.95rem;
            outline: none;
            transition: border-color 0.2s;
        }

        .form-control:focus {
            border-color: var(--primary-color);
        }

        textarea.form-control {
            resize: vertical;
            height: 110px;
        }

        .btn-submit {
            width: 100%;
            background: var(--primary-color);
            color: #ffffff;
            border: none;
            padding: 12px;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 600;
            cursor: pointer;
            transition: background 0.2s ease;
        }

        .btn-submit:hover {
            background: #0056b3;
        }

        /* Alerts */
        .alert {
            padding: 12px 15px;
            border-radius: 8px;
            font-size: 0.9rem;
            margin-bottom: 15px;
        }

        .alert-success {
            background: #d4edda;
            color: #155724;
            border: 1px solid #c3e6cb;
        }

        .alert-danger {
            background: #f8d7da;
            color: #721c24;
            border: 1px solid #f5c6cb;
        }

        /* Home Button */
        .back-btn-area {
            text-align: center;
            margin-top: 30px;
        }

        .btn-home {
            display: inline-block;
            background: var(--primary-color);
            color: #ffffff;
            padding: 10px 25px;
            border-radius: 25px;
            text-decoration: none;
            font-weight: 600;
            font-size: 0.9rem;
            transition: background 0.2s ease;
        }

        .btn-home:hover {
            background: #0056b3;
        }
    </style>
</head>
<body>

    <!-- Hero Banner -->
    <div class="contact-hero">
        <h1>যোগাযোগ করুন</h1>
        <p>যেকোনো প্রশ্ন, তথ্য বা সহায়তার জন্য আমাদের সাথে সরাসরি যোগাযোগ করুন</p>
    </div>

    <!-- Main Content -->
    <div class="container">
        
        <div class="contact-grid">
            
            <!-- Company Info Card -->
            <div class="contact-card">
                <h2 class="section-title">আমাদের অফিস তথ্য</h2>

                <div class="info-item">
                    <div class="info-icon">
                        <i class="fa-solid fa-building"></i>
                    </div>
                    <div class="info-text">
                        <h4>কোম্পানি / শপ</h4>
                        <p><strong>Naithe Soft</strong></p>
                    </div>
                </div>

                <div class="info-item">
                    <div class="info-icon">
                        <i class="fa-solid fa-location-dot"></i>
                    </div>
                    <div class="info-text">
                        <h4>ঠিকানা</h4>
                        <p>Katirhat Center, Hathazari, Chittagong, Bangladesh</p>
                    </div>
                </div>

                <div class="info-item">
                    <div class="info-icon">
                        <i class="fa-solid fa-globe"></i>
                    </div>
                    <div class="info-text">
                        <h4>ওয়েবসাইট</h4>
                        <p><a href="https://naithe.com" target="_blank">https://naithe.com</a></p>
                    </div>
                </div>

                <div class="info-item">
                    <div class="info-icon">
                        <i class="fa-brands fa-whatsapp"></i>
                    </div>
                    <div class="info-text">
                        <h4>হোয়াটসঅ্যাপ সাপোর্ট</h4>
                        <p>+880 1774-380298</p>
                    </div>
                </div>

                <!-- Direct WhatsApp Click Button -->
                <a href="https://wa.me/8801774380298?text=Hello%20Naithe%20Soft,%20I%20have%20a%20query." target="_blank" class="whatsapp-btn">
                    <i class="fa-brands fa-whatsapp" style="font-size: 1.3rem;"></i> সরাসরি হোয়াটসঅ্যাপে মেসেজ দিন
                </a>
            </div>

            <!-- Send Message Form -->
            <div class="contact-card">
                <h2 class="section-title">মেসেজ পাঠান</h2>
                
                <?php if (!empty($msg)) echo $msg; ?>

                <form action="contact.php" method="POST">
                    <div class="form-group">
                        <label for="name">আপনার নাম *</label>
                        <input type="text" id="name" name="name" class="form-control" placeholder="আপনার নাম লিখুন" required>
                    </div>

                    <div class="form-group">
                        <label for="email">ইমেইল বা ফোন নম্বর</label>
                        <input type="text" id="email" name="email" class="form-control" placeholder="আপনার ইমেইল বা মোবাইল নম্বর">
                    </div>

                    <div class="form-group">
                        <label for="message">আপনার মেসেজ *</label>
                        <textarea id="message" name="message" class="form-control" placeholder="আপনি কী জানতে চান তা সংক্ষেপে লিখুন..." required></textarea>
                    </div>

                    <button type="submit" class="btn-submit"><i class="fa-solid fa-paper-plane"></i> মেসেজ পাঠান</button>
                </form>
            </div>

        </div>

        <!-- Back to Home -->
        <div class="back-btn-area">
            <a href="index.php" class="btn-home"><i class="fa-solid fa-arrow-left"></i> হোম পেজে ফিরে যান</a>
        </div>

    </div>

</body>
</html>