<?php
// Include configuration and models using existing init.php
require_once __DIR__ . '/app/Core/init.php';

// Initialize models
$pageContentModel = new PageContent();

// Set page variables
$page_title = 'Contact Us';
$body_class = '';

// Handle form submission
$message_sent = false;
$error_message = '';

if ($_POST) {
    try {
        $name = trim($_POST['name'] ?? '');
        $email = trim($_POST['email'] ?? '');
        $subject = trim($_POST['subject'] ?? '');
        $message = trim($_POST['message'] ?? '');
        
        if (empty($name) || empty($email) || empty($subject) || empty($message)) {
            $error_message = 'Please fill in all required fields.';
        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $error_message = 'Please enter a valid email address.';
        } else {
            // In a real application, you would send an email here
            // For now, we'll just log the message and show success
            error_log("Contact form submission: Name: $name, Email: $email, Subject: $subject, Message: $message");
            $message_sent = true;
        }
    } catch (Exception $e) {
        $error_message = 'Sorry, there was an error processing your request. Please try again.';
        error_log('Contact form error: ' . $e->getMessage());
    }
}

// Get page content if available
try {
    $contact_page = $pageContentModel->findBySlug('contact-us');
} catch (Exception $e) {
    $contact_page = null;
}

// Include header template
include __DIR__ . '/templates/layouts/frontend/header.php';
?>

    <!-- start hero section -->
    <div class="py-5 bg-light">
        <div class="container">
            <div class="row justify-content-center">
                <div class="col-lg-8 text-center">
                    <h1 class="display-4 fw-bold mb-4">Contact Us</h1>
                    <p class="lead text-muted">Have a question or need help? We're here to assist you. Get in touch with our friendly support team.</p>
                </div>
            </div>
        </div>
    </div>
    <!-- end hero section -->

    <!-- start contact content -->
    <div class="py-5">
        <div class="container">
            <div class="row g-5">
                <!-- start contact form -->
                <div class="col-lg-8">
                    <?php if ($message_sent): ?>
                        <!-- success message -->
                        <div class="alert alert-success d-flex align-items-center" role="alert">
                            <i class="fas fa-check-circle me-3"></i>
                            <div>
                                <h6 class="alert-heading mb-1">Message Sent Successfully!</h6>
                                <p class="mb-0">Thank you for contacting us. We'll get back to you within 24 hours.</p>
                            </div>
                        </div>
                    <?php endif; ?>
                    
                    <?php if ($error_message): ?>
                        <!-- error message -->
                        <div class="alert alert-danger d-flex align-items-center" role="alert">
                            <i class="fas fa-exclamation-triangle me-3"></i>
                            <div>
                                <h6 class="alert-heading mb-1">Error</h6>
                                <p class="mb-0"><?= htmlspecialchars($error_message) ?></p>
                            </div>
                        </div>
                    <?php endif; ?>
                    
                    <div class="border-0 card rounded-4">
                        <div class="card-body p-4">
                            <h4 class="mb-4">Send us a Message</h4>
                            
                            <form method="POST" action="contact-us.php">
                                <div class="row g-3">
                                    <div class="col-md-6">
                                        <label for="name" class="form-label">Full Name *</label>
                                        <input type="text" class="form-control" id="name" name="name" required value="<?= htmlspecialchars($_POST['name'] ?? '') ?>">
                                    </div>
                                    <div class="col-md-6">
                                        <label for="email" class="form-label">Email Address *</label>
                                        <input type="email" class="form-control" id="email" name="email" required value="<?= htmlspecialchars($_POST['email'] ?? '') ?>">
                                    </div>
                                    <div class="col-12">
                                        <label for="subject" class="form-label">Subject *</label>
                                        <select class="form-select" id="subject" name="subject" required>
                                            <option value="">Select a subject</option>
                                            <option value="General Inquiry" <?= ($_POST['subject'] ?? '') === 'General Inquiry' ? 'selected' : '' ?>>General Inquiry</option>
                                            <option value="Technical Support" <?= ($_POST['subject'] ?? '') === 'Technical Support' ? 'selected' : '' ?>>Technical Support</option>
                                            <option value="Billing Question" <?= ($_POST['subject'] ?? '') === 'Billing Question' ? 'selected' : '' ?>>Billing Question</option>
                                            <option value="Vendor Registration" <?= ($_POST['subject'] ?? '') === 'Vendor Registration' ? 'selected' : '' ?>>Vendor Registration</option>
                                            <option value="Partnership" <?= ($_POST['subject'] ?? '') === 'Partnership' ? 'selected' : '' ?>>Partnership</option>
                                            <option value="Feedback" <?= ($_POST['subject'] ?? '') === 'Feedback' ? 'selected' : '' ?>>Feedback</option>
                                            <option value="Other" <?= ($_POST['subject'] ?? '') === 'Other' ? 'selected' : '' ?>>Other</option>
                                        </select>
                                    </div>
                                    <div class="col-12">
                                        <label for="message" class="form-label">Message *</label>
                                        <textarea class="form-control" id="message" name="message" rows="6" required placeholder="Please describe your inquiry in detail..."><?= htmlspecialchars($_POST['message'] ?? '') ?></textarea>
                                    </div>
                                    <div class="col-12">
                                        <button type="submit" class="btn btn-primary btn-lg">
                                            <i class="fas fa-paper-plane me-2"></i>Send Message
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
                <!-- end contact form -->
                
                <!-- start contact info -->
                <div class="col-lg-4">
                    <div class="border-0 card rounded-4">
                        <div class="card-body p-4">
                            <h5 class="mb-4">Get in Touch</h5>
                            
                            <!-- contact details -->
                            <div class="d-flex align-items-start mb-4">
                                <div class="bg-primary bg-opacity-10 rounded-circle d-inline-flex align-items-center justify-content-center me-3" style="width: 40px; height: 40px;">
                                    <i class="fas fa-map-marker-alt text-primary"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">Our Office</h6>
                                    <p class="text-muted mb-0">
                                        123 Business Street<br>
                                        Suite 456<br>
                                        New York, NY 10001
                                    </p>
                                </div>
                            </div>
                            
                            <div class="d-flex align-items-start mb-4">
                                <div class="bg-primary bg-opacity-10 rounded-circle d-inline-flex align-items-center justify-content-center me-3" style="width: 40px; height: 40px;">
                                    <i class="fas fa-phone text-primary"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">Phone</h6>
                                    <p class="text-muted mb-0">
                                        <a href="tel:+1234567890" class="text-decoration-none">+1 (234) 567-8900</a><br>
                                        <small>Mon-Fri: 9AM-6PM EST</small>
                                    </p>
                                </div>
                            </div>
                            
                            <div class="d-flex align-items-start mb-4">
                                <div class="bg-primary bg-opacity-10 rounded-circle d-inline-flex align-items-center justify-content-center me-3" style="width: 40px; height: 40px;">
                                    <i class="fas fa-envelope text-primary"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">Email</h6>
                                    <p class="text-muted mb-0">
                                        <a href="mailto:info@rentidium.com" class="text-decoration-none">info@rentidium.com</a><br>
                                        <a href="mailto:support@rentidium.com" class="text-decoration-none">support@rentidium.com</a>
                                    </p>
                                </div>
                            </div>
                            
                            <div class="d-flex align-items-start">
                                <div class="bg-primary bg-opacity-10 rounded-circle d-inline-flex align-items-center justify-content-center me-3" style="width: 40px; height: 40px;">
                                    <i class="fas fa-clock text-primary"></i>
                                </div>
                                <div>
                                    <h6 class="mb-1">Business Hours</h6>
                                    <p class="text-muted mb-0">
                                        Monday - Friday: 9:00 AM - 6:00 PM<br>
                                        Saturday: 10:00 AM - 4:00 PM<br>
                                        Sunday: Closed
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <!-- social media -->
                    <div class="border-0 card rounded-4 mt-4">
                        <div class="card-body p-4">
                            <h5 class="mb-4">Follow Us</h5>
                            <p class="text-muted mb-3">Stay connected with us on social media for the latest updates and tips.</p>
                            <div class="d-flex gap-3">
                                <a href="#" class="btn btn-outline-primary rounded-circle" style="width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;">
                                    <i class="fab fa-facebook-f"></i>
                                </a>
                                <a href="#" class="btn btn-outline-primary rounded-circle" style="width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;">
                                    <i class="fab fa-twitter"></i>
                                </a>
                                <a href="#" class="btn btn-outline-primary rounded-circle" style="width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;">
                                    <i class="fab fa-instagram"></i>
                                </a>
                                <a href="#" class="btn btn-outline-primary rounded-circle" style="width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;">
                                    <i class="fab fa-linkedin-in"></i>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- end contact info -->
            </div>
        </div>
    </div>
    <!-- end contact content -->

    <!-- start FAQ section -->
    <div class="py-5 bg-light">
        <div class="container">
            <div class="text-center mb-5">
                <h3 class="mb-3">Frequently Asked Questions</h3>
                <p class="text-muted">Quick answers to common questions</p>
            </div>
            
            <div class="row justify-content-center">
                <div class="col-lg-8">
                    <div class="accordion" id="contactFAQ">
                        <div class="accordion-item">
                            <h2 class="accordion-header" id="faq1">
                                <button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapse1" aria-expanded="true" aria-controls="collapse1">
                                    How quickly do you respond to inquiries?
                                </button>
                            </h2>
                            <div id="collapse1" class="accordion-collapse collapse show" aria-labelledby="faq1" data-bs-parent="#contactFAQ">
                                <div class="accordion-body">
                                    We typically respond to all inquiries within 24 hours during business days. For urgent matters, please call our support line.
                                </div>
                            </div>
                        </div>
                        
                        <div class="accordion-item">
                            <h2 class="accordion-header" id="faq2">
                                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse2" aria-expanded="false" aria-controls="collapse2">
                                    Can I become a vendor on your platform?
                                </button>
                            </h2>
                            <div id="collapse2" class="accordion-collapse collapse" aria-labelledby="faq2" data-bs-parent="#contactFAQ">
                                <div class="accordion-body">
                                    Absolutely! We're always looking for new vendors to join our platform. Please contact us with details about your items, and we'll guide you through the registration process.
                                </div>
                            </div>
                        </div>
                        
                        <div class="accordion-item">
                            <h2 class="accordion-header" id="faq3">
                                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse3" aria-expanded="false" aria-controls="collapse3">
                                    What payment methods do you accept?
                                </button>
                            </h2>
                            <div id="collapse3" class="accordion-collapse collapse" aria-labelledby="faq3" data-bs-parent="#contactFAQ">
                                <div class="accordion-body">
                                    We accept all major credit cards (Visa, MasterCard, American Express), PayPal, and bank transfers. All transactions are secured with industry-standard encryption.
                                </div>
                            </div>
                        </div>
                        
                        <div class="accordion-item">
                            <h2 class="accordion-header" id="faq4">
                                <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapse4" aria-expanded="false" aria-controls="collapse4">
                                    Is there customer support available?
                                </button>
                            </h2>
                            <div id="collapse4" class="accordion-collapse collapse" aria-labelledby="faq4" data-bs-parent="#contactFAQ">
                                <div class="accordion-body">
                                    Yes, we have a dedicated customer support team available Monday through Friday from 9 AM to 6 PM EST. You can reach us via phone, email, or the contact form on this page.
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- end FAQ section -->

    <!-- start CTA section -->
    <div class="py-5 bg-primary text-white">
        <div class="container">
            <div class="row justify-content-center text-center">
                <div class="col-lg-8">
                    <h3 class="mb-3">Still Have Questions?</h3>
                    <p class="lead mb-4">Can't find what you're looking for? Our support team is here to help you with any questions or concerns.</p>
                    <a href="tel:+1234567890" class="btn btn-light btn-lg">
                        <i class="fas fa-phone me-2"></i>Call Support
                    </a>
                </div>
            </div>
        </div>
    </div>
    <!-- end CTA section -->

<?php
// Include footer template
include __DIR__ . '/templates/layouts/frontend/footer.php';
?>