<?php
// contact.php - Dynamic Contact Page
require_once 'includes/config.php';
require_once 'includes/site-data.php';

$success = '';
$error = '';

// Use dynamic email from settings
$admin_email = $S['email1'] ?? 'admin@banglalms.com';

if($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['send_message'])) {
    $name = trim($_POST['name'] ?? '');
    $email = trim($_POST['email'] ?? '');
    $phone = trim($_POST['phone'] ?? '');
    $subject = trim($_POST['subject'] ?? '');
    $message = trim($_POST['message'] ?? '');
    
    if(empty($name) || empty($email) || empty($message)) {
        $error = 'নাম, ইমেইল এবং মেসেজ প্রয়োজন';
    } elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
        $error = 'সঠিক ইমেইল অ্যাড্রেস লিখুন';
    } else {
        try {
            $stmt = $pdo->prepare("INSERT INTO contact_messages (name, email, phone, subject, message, created_at) VALUES (?, ?, ?, ?, ?, NOW())");
            $stmt->execute([$name, $email, $phone, $subject, $message]);
            
            $headers = "From: $email\r\nReply-To: $email\r\nContent-Type: text/html; charset=UTF-8";
            $email_body = "<h3>নতুন মেসেজ - " . htmlspecialchars($S['site_title'] ?? 'LMS') . "</h3>
                <p><strong>নাম:</strong> $name</p><p><strong>ইমেইল:</strong> $email</p>
                <p><strong>ফোন:</strong> $phone</p><p><strong>বিষয়:</strong> $subject</p>
                <p><strong>মেসেজ:</strong><br>$message</p>";
            @mail($admin_email, "Contact: $subject", $email_body, $headers);
            
            $success = 'আপনার মেসেজ সফলভাবে পাঠানো হয়েছে! আমরা শীঘ্রই যোগাযোগ করব।';
        } catch(PDOException $e) {
            $error = 'মেসেজ পাঠাতে সমস্যা হয়েছে। আবার চেষ্টা করুন।';
        }
    }
}
?>
<!DOCTYPE html>
<html lang="bn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>যোগাযোগ - <?= htmlspecialchars($S['site_title'] ?? 'বাংলা LMS') ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
    <style>
        :root { --primary: <?= $S['primary_color'] ?? '#6C5CE7' ?>; --gradient-1: linear-gradient(135deg, <?= $S['primary_color'] ?? '#667eea' ?>, <?= $S['primary_color'] ?? '#764ba2' ?>dd); --gradient-2: linear-gradient(135deg, #f093fb, #f5576c); --gradient-3: linear-gradient(135deg, #4facfe, #00f2fe); --gradient-4: linear-gradient(135deg, #43e97b, #38f9d7); --shadow: 0 5px 25px rgba(0,0,0,0.1); --shadow-lg: 0 15px 45px rgba(0,0,0,0.15); }
        * { margin:0; padding:0; box-sizing:border-box; }
        body { background:#f0f2f8; font-family:'Segoe UI','Hind Siliguri',Arial,sans-serif; }
        .bg-animation { position:fixed; top:0; left:0; width:100%; height:100%; z-index:0; pointer-events:none; }
        .bg-circle { position:absolute; border-radius:50%; opacity:0.06; animation:floatCircle 20s infinite ease-in-out; }
        .bg-circle:nth-child(1) { width:500px; height:500px; background:<?=$S['primary_color']??'#667eea'?>; top:-100px; left:-100px; }
        .bg-circle:nth-child(2) { width:350px; height:350px; background:#f5576c; bottom:-50px; right:-50px; animation-delay:7s; }
        .bg-circle:nth-child(3) { width:250px; height:250px; background:#4facfe; top:50%; right:10%; animation-delay:14s; }
        @keyframes floatCircle { 0%,100%{transform:translate(0,0)scale(1)} 33%{transform:translate(30px,-40px)scale(1.1)} 66%{transform:translate(-20px,30px)scale(0.9)} }
        .navbar { background:rgba(255,255,255,0.9); backdrop-filter:blur(15px); box-shadow:0 2px 10px rgba(0,0,0,0.08); padding:15px 0; position:sticky; top:0; z-index:1000; }
        .navbar-brand { font-weight:800; font-size:1.4rem; background:var(--gradient-1); -webkit-background-clip:text; -webkit-text-fill-color:transparent; text-decoration:none; }
        .page-header { background:var(--gradient-1); color:white; padding:60px 0; text-align:center; position:relative; overflow:hidden; }
        .page-header::after { content:''; position:absolute; bottom:-50px; left:50%; transform:translateX(-50%); width:100px; height:100px; background:#f0f2f8; border-radius:50%; }
        .page-header h1 { font-weight:800; font-size:2.5rem; position:relative; z-index:1; }
        .container { max-width:1200px; margin:0 auto; padding:40px 20px; position:relative; z-index:1; }
        .contact-info-card { background:white; border-radius:20px; padding:30px; text-align:center; box-shadow:var(--shadow); transition:all 0.4s; height:100%; }
        .contact-info-card:hover { transform:translateY(-10px); box-shadow:var(--shadow-lg); }
        .icon-circle { width:70px; height:70px; border-radius:50%; display:inline-flex; align-items:center; justify-content:center; font-size:1.8rem; color:white; margin-bottom:20px; transition:0.3s; }
        .contact-info-card:hover .icon-circle { transform:rotate(10deg)scale(1.1); }
        .icon-purple { background:var(--gradient-1); } .icon-pink { background:var(--gradient-2); } .icon-blue { background:var(--gradient-3); } .icon-green { background:var(--gradient-4); }
        .contact-info-card h5 { font-weight:700; margin-bottom:10px; color:#1a1a2e; }
        .contact-info-card p, .contact-info-card a { color:#666; text-decoration:none; font-size:0.95rem; }
        .contact-info-card a:hover { color:var(--primary); }
        .contact-form-card { background:white; border-radius:25px; padding:40px; box-shadow:var(--shadow-lg); position:relative; overflow:hidden; }
        .contact-form-card::before { content:''; position:absolute; top:0; left:0; width:100%; height:5px; background:var(--gradient-1); }
        .form-control { border-radius:12px; padding:14px 18px; border:2px solid #e8eaef; transition:0.3s; font-size:0.95rem; background:#fafbfd; width:100%; margin-bottom:12px; }
        .form-control:focus { border-color:var(--primary); box-shadow:0 0 0 4px rgba(108,92,231,0.08); background:white; outline:none; }
        .form-label { font-weight:600; margin-bottom:6px; color:#444; display:block; }
        .btn-submit { background:var(--gradient-1); color:white; border:none; border-radius:50px; padding:15px 40px; font-weight:700; font-size:1.05rem; cursor:pointer; transition:0.3s; width:100%; }
        .btn-submit:hover { transform:translateY(-3px); box-shadow:0 15px 35px rgba(108,92,231,0.4); }
        .map-container { border-radius:25px; overflow:hidden; box-shadow:var(--shadow-lg); height:350px; }
        .map-container iframe { width:100%; height:100%; border:none; }
        .social-link { display:inline-flex; align-items:center; justify-content:center; width:50px; height:50px; border-radius:50%; color:white; font-size:1.3rem; margin:0 8px; transition:0.3s; text-decoration:none; }
        .social-link:hover { transform:translateY(-8px)rotate(10deg); color:white; }
        .social-fb { background:#1877f2; } .social-yt { background:#ff0000; } .social-ig { background:linear-gradient(45deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888); } .social-li { background:#0077b5; }
        .alert { border-radius:15px; padding:16px 20px; font-weight:500; border:none; margin-bottom:15px; }
        .alert-success { background:#eaffea; color:#2d7d46; } .alert-danger { background:#ffeaea; color:#c33; }
        @media (max-width:768px) { .page-header h1 { font-size:1.8rem; } .page-header { padding:40px 0; } .contact-form-card { padding:25px; } }
    </style>
</head>
<body>

<div class="bg-animation"><div class="bg-circle"></div><div class="bg-circle"></div><div class="bg-circle"></div></div>

<nav class="navbar">
    <div class="container" style="display:flex;justify-content:space-between;align-items:center;">
        <a href="index.php" class="navbar-brand">
            <?php if(($S['use_image_logo']??'0')=='1' && !empty($S['logo_image']) && file_exists('uploads/logo/'.$S['logo_image'])): ?>
                <img src="uploads/logo/<?=$S['logo_image']?>" alt="<?=htmlspecialchars($S['site_title']??'LMS')?>" style="height:36px;">
            <?php else: ?>
                <i class="fas <?=$S['logo_icon']??'fa-graduation-cap'?> me-2"></i><?=htmlspecialchars($S['logo_text']??'বাংলা LMS')?>
            <?php endif; ?>
        </a>
        <div style="display:flex;gap:15px;">
            <a href="index.php" style="color:#555;text-decoration:none;font-weight:500;">হোম</a>
            <a href="courses.php" style="color:#555;text-decoration:none;font-weight:500;">কোর্স</a>
            <a href="about.php" style="color:#555;text-decoration:none;font-weight:500;">আমাদের সম্পর্কে</a>
            <a href="contact.php" style="color:var(--primary);text-decoration:none;font-weight:600;">যোগাযোগ</a>
        </div>
    </div>
</nav>

<div class="page-header">
    <div class="container"><h1>📬 যোগাযোগ করুন</h1><p>আমাদের সাথে যোগাযোগ করতে নিচের ফর্মটি ব্যবহার করুন</p></div>
</div>

<div class="container">
    
    <!-- Contact Info Cards - DYNAMIC -->
    <div class="row g-4 mb-5" data-aos="fade-up">
        <div class="col-md-3">
            <div class="contact-info-card">
                <div class="icon-circle icon-purple"><i class="fas fa-map-marker-alt"></i></div>
                <h5>ঠিকানা</h5>
                <p><?= nl2br(htmlspecialchars(($S['address_line1']??'')."\n".($S['address_line2']??''))) ?></p>
            </div>
        </div>
        <div class="col-md-3">
            <div class="contact-info-card">
                <div class="icon-circle icon-pink"><i class="fas fa-phone"></i></div>
                <h5>ফোন</h5>
                <?php if(!empty($S['phone1'])): ?><a href="tel:<?=$S['phone1']?>"><?=htmlspecialchars($S['phone1'])?></a><br><?php endif; ?>
                <?php if(!empty($S['phone2'])): ?><a href="tel:<?=$S['phone2']?>"><?=htmlspecialchars($S['phone2'])?></a><?php endif; ?>
            </div>
        </div>
        <div class="col-md-3">
            <div class="contact-info-card">
                <div class="icon-circle icon-blue"><i class="fas fa-envelope"></i></div>
                <h5>ইমেইল</h5>
                <?php if(!empty($S['email1'])): ?><a href="mailto:<?=$S['email1']?>"><?=htmlspecialchars($S['email1'])?></a><br><?php endif; ?>
                <?php if(!empty($S['email2'])): ?><a href="mailto:<?=$S['email2']?>"><?=htmlspecialchars($S['email2'])?></a><?php endif; ?>
            </div>
        </div>
        <div class="col-md-3">
            <div class="contact-info-card">
                <div class="icon-circle icon-green"><i class="fas fa-clock"></i></div>
                <h5>অফিস সময়</h5>
                <p><?= nl2br(htmlspecialchars($S['office_hours'] ?? 'শনি - বৃহস্পতি<br>সকাল ৯টা - রাত ১০টা')) ?></p>
            </div>
        </div>
    </div>
    
    <div class="row g-4">
        <div class="col-lg-7" data-aos="fade-right">
            <div class="contact-form-card">
                <h3 class="mb-4">✉️ মেসেজ পাঠান</h3>
                <?php if($success): ?><div class="alert alert-success"><i class="fas fa-check-circle me-2"></i><?=$success?></div><?php endif; ?>
                <?php if($error): ?><div class="alert alert-danger"><i class="fas fa-exclamation-circle me-2"></i><?=$error?></div><?php endif; ?>
                <form method="POST">
                    <input type="hidden" name="send_message" value="1">
                    <div class="row">
                        <div class="col-md-6"><label class="form-label">আপনার নাম *</label><input type="text" name="name" class="form-control" placeholder="আপনার পূর্ণ নাম" required></div>
                        <div class="col-md-6"><label class="form-label">ইমেইল *</label><input type="email" name="email" class="form-control" placeholder="example@email.com" required></div>
                        <div class="col-md-6"><label class="form-label">ফোন নম্বর</label><input type="text" name="phone" class="form-control" placeholder="০১XXXXXXXXX"></div>
                        <div class="col-md-6"><label class="form-label">বিষয়</label><select name="subject" class="form-control"><option value="">সাধারণ জিজ্ঞাসা</option><option value="কোর্স">কোর্স সম্পর্কে</option><option value="এনরোলমেন্ট">এনরোলমেন্ট হেল্প</option><option value="পেমেন্ট">পেমেন্ট ইস্যু</option><option value="টেকনিক্যাল">টেকনিক্যাল সাপোর্ট</option><option value="অন্যান্য">অন্যান্য</option></select></div>
                        <div class="col-12"><label class="form-label">আপনার মেসেজ *</label><textarea name="message" class="form-control" rows="5" placeholder="আপনার মেসেজ লিখুন..." required></textarea></div>
                    </div>
                    <button type="submit" class="btn-submit"><i class="fas fa-paper-plane me-2"></i>মেসেজ পাঠান</button>
                </form>
            </div>
        </div>
        
        <div class="col-lg-5" data-aos="fade-left">
            <?php if(!empty($S['map_embed_url'])): ?>
                <div class="map-container mb-4"><iframe src="<?=htmlspecialchars($S['map_embed_url'])?>" allowfullscreen="" loading="lazy"></iframe></div>
            <?php endif; ?>
            
            <div class="text-center p-4 bg-white rounded-4 shadow-sm">
                <h5 class="mb-3">🔗 সোশ্যাল মিডিয়া</h5>
                <div>
                    <?php if(!empty($S['facebook_url'])): ?><a href="<?=htmlspecialchars($S['facebook_url'])?>" target="_blank" class="social-link social-fb"><i class="fab fa-facebook-f"></i></a><?php endif; ?>
                    <?php if(!empty($S['youtube_url'])): ?><a href="<?=htmlspecialchars($S['youtube_url'])?>" target="_blank" class="social-link social-yt"><i class="fab fa-youtube"></i></a><?php endif; ?>
                    <?php if(!empty($S['instagram_url'])): ?><a href="<?=htmlspecialchars($S['instagram_url'])?>" target="_blank" class="social-link social-ig"><i class="fab fa-instagram"></i></a><?php endif; ?>
                    <?php if(!empty($S['linkedin_url'])): ?><a href="<?=htmlspecialchars($S['linkedin_url'])?>" target="_blank" class="social-link social-li"><i class="fab fa-linkedin-in"></i></a><?php endif; ?>
                </div>
                <?php if(!empty($S['whatsapp_number'])): ?>
                    <hr class="my-4"><h6>📱 হোয়াটসঅ্যাপ</h6>
                    <a href="https://wa.me/<?=$S['whatsapp_number']?>" target="_blank" class="btn btn-success rounded-pill px-4"><i class="fab fa-whatsapp me-2"></i>+<?=$S['whatsapp_number']?></a>
                <?php endif; ?>
            </div>
        </div>
    </div>
</div>

<footer style="background:#1a1a2e;color:white;text-align:center;padding:20px;margin-top:60px;">
    <p class="mb-0">&copy; <?=date('Y')?> <?=htmlspecialchars($S['footer_text']??'বাংলা LMS | সর্বস্বত্ব সংরক্ষিত')?></p>
</footer>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>AOS.init({duration:800,easing:'ease-in-out',once:true});</script>
</body>
</html>