<?php
/**
 * Template Name: Bakla Contact Page
 * Description: Contact page with Bakla branding and color scheme
 *
 * @package Kipya
 */

get_header();
include get_template_directory() . '/inc/menus/menu.php';

if (isset($_POST['contact_submitted'])) {
    $name    = sanitize_text_field($_POST['contact_name']);
    $email   = sanitize_email($_POST['contact_email']);
    $phone   = sanitize_text_field($_POST['contact_phone']);
    $subject = sanitize_text_field($_POST['contact_subject']);
    $message = sanitize_textarea_field($_POST['contact_message']);

    $post_content  = "Name: $name\n";
    $post_content .= "Email: $email\n";
    $post_content .= "Phone: $phone\n";
    $post_content .= "Subject: $subject\n\n";
    $post_content .= "Message:\n$message";

    $post_id = wp_insert_post(array(
        'post_title'   => 'Contact: ' . $name . ' - ' . $subject,
        'post_content' => $post_content,
        'post_status'  => 'private',
        'post_type'    => 'contact_submission',
    ));

    if ($post_id) { $submission_success = true; }
}
?>

<main role="main" class="bakla-contact-main">

<?php 
if (has_post_thumbnail()) {
    $backgroundImg = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), 'full');
    $bg_url = $backgroundImg[0];
} else {
    $bg_url = get_template_directory_uri() . '/assets/images/default-hero.jpg';
}
?>

<!-- HERO SECTION -->
<section class="hero-section bakla-contact-hero" style="background-image: url('<?php echo esc_url($bg_url); ?>');">
    <div class="hero-overlay">
        <div class="hero-content">
            <h1 class="hero-title"><?php the_title(); ?></h1>
            <div class="hero-breadcrumb">
                <a href="<?php echo esc_url(home_url()); ?>">
                    <i class="fas fa-home"></i> 
                </a>
                <span class="separator"> > </span>
                <span><?php the_title(); ?></span>
            </div>
        </div>
    </div>
</section>

<!-- CONTACT SECTION -->
<section class="bakla-contact-section" id="bakla-contact-form">
    <div class="container">
        

        <div class="bakla-contact-grid">
            <!-- Left: Form -->
            <div class="bakla-form-wrapper">
                <div class="bakla-form-card">
                    <?php if (isset($submission_success) && $submission_success): ?>
                    <div class="bakla-success-popup active">
                        <div class="bakla-success-content">
                            <div class="bakla-success-icon">
                                <svg viewBox="0 0 52 52">
                                    <circle cx="26" cy="26" r="25" fill="var(--kpy-primary, #811411)"/>
                                    <path fill="none" stroke="#fff" stroke-width="4" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
                                </svg>
                            </div>
                            <h3>Message Sent!</h3>
                            <p>Thank you for reaching out. We'll respond within 24-48 hours.</p>
                            <button class="bakla-close-popup">Close</button>
                        </div>
                    </div>
                    <?php endif; ?>

                    <form id="bakla-contact-form" method="post" class="bakla-form">
                        <div class="bakla-form-row">
                            <div class="bakla-form-group">
                                <label class="bakla-label">Your Name <span>*</span></label>
                                <input class="bakla-input" type="text" name="contact_name" placeholder="John Doe" required>
                            </div>
                            <div class="bakla-form-group">
                                <label class="bakla-label">Email Address <span>*</span></label>
                                <input class="bakla-input" type="email" name="contact_email" placeholder="hello@baklaltd.com" required>
                            </div>
                        </div>
                        <div class="bakla-form-row">
                            <div class="bakla-form-group">
                                <label class="bakla-label">Phone Number</label>
                                <input class="bakla-input" type="tel" name="contact_phone" placeholder="+256 XXX XXX XXX">
                            </div>
                            <div class="bakla-form-group">
                                <label class="bakla-label">Department <span>*</span></label>
                                <div class="bakla-select-wrap">
                                    <select class="bakla-input bakla-select" name="contact_subject" required>
                                        <option value="" disabled selected>Select a department...</option>
                                        <option value="Digital Marketing">Digital Marketing</option>
                                        <option value="Web Services">Web Services</option>
                                        <option value="Branding & Design">Branding & Design</option>
                                        <option value="Photography & Video">Photography & Video</option>
                                        <option value="Sales & Inquiries">Sales & Inquiries</option>
                                        <option value="Support">Technical Support</option>
                                        <option value="Partnerships">Partnerships</option>
                                        <option value="Other">Other</option>
                                    </select>
                                    <i class="fas fa-chevron-down bakla-select-arrow"></i>
                                </div>
                            </div>
                        </div>
                        <div class="bakla-form-group">
                            <label class="bakla-label">Your Message <span>*</span></label>
                            <textarea class="bakla-input bakla-textarea" name="contact_message" rows="6" placeholder="Tell us about your project or inquiry..." required></textarea>
                        </div>
                        <div class="bakla-form-footer">
                            <button type="submit" name="contact_submitted" class="bakla-submit-btn">
                                <i class="fas fa-paper-plane"></i> Send Message
                            </button>
                            <p class="bakla-form-note">
                                <i class="fas fa-shield-alt"></i> Your information is secure and never shared.
                            </p>
                        </div>
                    </form>
                </div>
            </div>

            <!-- Right: Contact Info -->
            <div class="bakla-info-wrapper">
                <div class="bakla-info-card">
                    <div class="bakla-info-header">
                        <i class="fas fa-building"></i>
                        <h3>Bakla Ltd</h3>
                    </div>
                    <div class="bakla-info-items">
                        <div class="bakla-info-item">
                            <div class="bakla-info-icon"><i class="fas fa-phone-alt"></i></div>
                            <div class="bakla-info-details">
                                <span class="bakla-info-label">Phone</span>
                                <a href="tel:+256706713232" class="bakla-info-value">+256 706 713 232</a>
                                <a href="tel:+256777305812" class="bakla-info-value">+256 777 305 812</a>
                            </div>
                        </div>
                        <div class="bakla-info-item">
                            <div class="bakla-info-icon"><i class="fas fa-envelope"></i></div>
                            <div class="bakla-info-details">
                                <span class="bakla-info-label">Email</span>
                                <a href="mailto:info@baklaltd.com" class="bakla-info-value">info@baklaltd.com</a>
                            </div>
                        </div>
                        <div class="bakla-info-item">
                            <div class="bakla-info-icon"><i class="fas fa-globe"></i></div>
                            <div class="bakla-info-details">
                                <span class="bakla-info-label">Website</span>
                                <a href="https://www.baklaltd.com" target="_blank" class="bakla-info-value">www.baklaltd.com</a>
                            </div>
                        </div>
                        <div class="bakla-info-item">
                            <div class="bakla-info-icon"><i class="fas fa-map-marker-alt"></i></div>
                            <div class="bakla-info-details">
                                <span class="bakla-info-label">Office</span>
                                <span class="bakla-info-value">Bukenya Mall, Kimera Rd, Ntinda, Kampala, Uganda</span>
                            </div>
                        </div>
                    </div>
                </div>

                
            </div>
        </div>

        <!-- Map Section -->
        <div class="bakla-map-wrapper">
            <div class="bakla-map-header">
                <div class="bakla-map-title">
                    <i class="fas fa-map-pin"></i>
                    <span>Our Location</span>
                </div>
                <a href="https://maps.google.com?daddr=Bukenya+Mall+Kimera+Road+Ntinda+Kampala" target="_blank" class="bakla-directions-btn">
                    <i class="fas fa-directions"></i> Get Directions
                </a>
            </div>
            <div class="bakla-map-frame">
                <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3989.7476456!2d32.6197!3d0.3476!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x177dbc0b0b0b0b0b%3A0x0!2sBukenya+Mall%2C+Kimera+Road%2C+Ntinda%2C+Kampala%2C+Uganda!5e0!3m2!1sen!2sug!4v1700000000000!5m2!1sen!2sug" width="100%" height="400" style="border:0;" allowfullscreen="" loading="lazy"></iframe>
                <div class="bakla-map-pin">
                    <i class="fas fa-map-marker-alt"></i> Bakla Ltd — Bukenya Mall, Kimera Road, Ntinda, Kampala, Uganda
                </div>
            </div>
        </div>
    </div>
</section>

<style>

:root {
    --bakla-primary: #811411;
    --bakla-primary-rgb: 129, 20, 17;
    --bakla-secondary: #000000;
    --bakla-white: #ffffff;
    --bakla-gray: #f5f5f5;
    --bakla-border: #e8e8e8;
}
.bakla-contact-main { background: #ffffff; }


/* Contact Grid */
.bakla-contact-section { padding: 80px 0; background: #f8f9fa; }
.container { max-width: 1300px; margin: 0 auto; padding: 0 30px; }
.bakla-contact-grid { display: grid; grid-template-columns: 1fr 380px; gap: 40px; }

/* Form Styles */
.bakla-form-card { background: white; border-radius: 20px; padding: 40px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05); border: 1px solid var(--bakla-border); }
.bakla-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.bakla-form-group { margin-bottom: 20px; }
.bakla-label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--bakla-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px; }
.bakla-label span { color: var(--bakla-primary); }
.bakla-input { width: 100%; padding: 12px 16px; border: 2px solid var(--bakla-border); border-radius: 10px; font-size: 0.95rem; transition: all 0.3s ease; font-family: var(--kpy-font-body, "montserrat", sans-serif); }
.bakla-input:focus { outline: none; border-color: var(--bakla-primary); box-shadow: 0 0 0 3px rgba(129, 20, 17, 0.1); }
.bakla-select-wrap { position: relative; }
.bakla-select { appearance: none; cursor: pointer; }
.bakla-select-arrow { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--bakla-primary); pointer-events: none; font-size: 12px; }
.bakla-textarea { resize: vertical; min-height: 120px; }
.bakla-form-footer { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 15px; margin-top: 10px; }
.bakla-submit-btn { display: inline-flex; align-items: center; gap: 10px; background: var(--bakla-primary); color: white; border: none; padding: 14px 30px; border-radius: 50px; font-weight: 700; font-size: 0.9rem; cursor: pointer; transition: all 0.3s ease; font-family: var(--kpy-font-body, "montserrat", sans-serif); }
.bakla-submit-btn:hover { background: #6a0f0e; transform: translateY(-2px); box-shadow: 0 5px 15px rgba(129, 20, 17, 0.3); }
.bakla-form-note { display: flex; align-items: center; gap: 8px; font-size: 0.75rem; color: #888; margin: 0; }

/* Success Popup */
.bakla-success-popup { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background: white; border-radius: 20px; padding: 40px; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2); z-index: 1000; max-width: 400px; width: 90%; }
.bakla-success-icon { width: 60px; height: 60px; margin: 0 auto 20px; }
.bakla-success-content h3 { font-size: 1.5rem; color: var(--bakla-secondary); margin-bottom: 10px; }
.bakla-success-content p { color: #666; margin-bottom: 25px; }
.bakla-close-popup { background: var(--bakla-primary); color: white; border: none; padding: 10px 25px; border-radius: 50px; cursor: pointer; font-weight: 600; }

/* Info Cards */
.bakla-info-card, .bakla-hours-card { background: white; border-radius: 20px; padding: 30px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05); border: 1px solid var(--bakla-border); margin-bottom: 25px; }
.bakla-info-header, .bakla-hours-header { display: flex; align-items: center; gap: 12px; margin-bottom: 25px; padding-bottom: 15px; border-bottom: 2px solid var(--bakla-border); }
.bakla-info-header i, .bakla-hours-header i { font-size: 24px; color: var(--bakla-primary); }
.bakla-info-header h3, .bakla-hours-header h3 { font-size: 1.3rem; font-weight: 700; color: var(--bakla-secondary); margin: 0; }
.bakla-info-items { display: flex; flex-direction: column; gap: 20px; }
.bakla-info-item { display: flex; align-items: flex-start; gap: 15px; }
.bakla-info-icon { width: 45px; height: 45px; background: rgba(129, 20, 17, 0.1); border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.bakla-info-icon i { font-size: 20px; color: var(--bakla-primary); }
.bakla-info-details { flex: 1; }
.bakla-info-label { display: block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; color: #999; letter-spacing: 1px; margin-bottom: 5px; }
.bakla-info-value { display: block; color: var(--bakla-secondary); text-decoration: none; font-size: 0.9rem; font-weight: 500; margin: 2px 0; }
.bakla-info-value:hover { color: var(--bakla-primary); }


/* Map Section */
.bakla-map-wrapper { margin-top: 50px; }
.bakla-map-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; flex-wrap: wrap; gap: 15px; }
.bakla-map-title { display: flex; align-items: center; gap: 10px; font-size: 1rem; font-weight: 700; color: var(--bakla-secondary); }
.bakla-map-title i { color: var(--bakla-primary); font-size: 20px; }
.bakla-directions-btn { display: inline-flex; align-items: center; gap: 8px; background: var(--bakla-primary); color: white; padding: 10px 20px; border-radius: 50px; text-decoration: none; font-size: 0.85rem; font-weight: 600; transition: all 0.3s ease; }
.bakla-directions-btn:hover { background: #6a0f0e; transform: translateY(-2px); }
.bakla-map-frame { background: white; border-radius: 20px; overflow: hidden; border: 1px solid var(--bakla-border); }
.bakla-map-pin { background: var(--bakla-primary); color: white; padding: 12px 20px; font-size: 0.85rem; display: flex; align-items: center; gap: 10px; }

/* Responsive */
@media (max-width: 992px) {
    .bakla-contact-grid { grid-template-columns: 1fr; gap: 30px; }
    .bakla-section-title { font-size: 2rem; }
}
@media (max-width: 768px) {
    .container { padding: 0 20px; }
    .bakla-contact-section { padding: 50px 0; }
    .bakla-form-card { padding: 25px; }
    .bakla-form-row { grid-template-columns: 1fr; gap: 0; }
    .bakla-map-header { flex-direction: column; align-items: flex-start; }
}
</style>

<script>
document.addEventListener('DOMContentLoaded', function() {
    var closeBtn = document.querySelector('.bakla-close-popup');
    if (closeBtn) {
        closeBtn.addEventListener('click', function() {
            document.querySelector('.bakla-success-popup').classList.remove('active');
        });
    }
});
</script>

</main>

<?php get_footer(); ?>