<?php
// 1. Output Buffering
ob_start();
session_start();

// Enable error reporting for debugging
// mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

// 2. Database Connection
if (file_exists("dbcon.php")) {
    require_once "dbcon.php"; 
} else {
    die("Error: dbcon.php not found.");
}

// Check connection variable
if (!isset($connn) || $connn->connect_error) {
    die("Database connection failed. Check dbcon.php variable name (must be \$connn).");
}

// Include PHPMailer classes
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

if (file_exists('phpmailer/src/Exception.php')) {
    require 'phpmailer/src/Exception.php';
    require 'phpmailer/src/PHPMailer.php';
    require 'phpmailer/src/SMTP.php';
}

// Processing Form Submission
if (isset($_POST['submit'])) {

    // Inputs
    $full_name    = filter_input(INPUT_POST, 'full_name', FILTER_SANITIZE_SPECIAL_CHARS);
    $email        = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
    $phone_number = filter_input(INPUT_POST, 'phone_number', FILTER_SANITIZE_SPECIAL_CHARS);
    $country      = filter_input(INPUT_POST, 'country', FILTER_SANITIZE_SPECIAL_CHARS);
    $password     = $_POST['password'];
    $con_password = $_POST['con_password'];
    
    // --- DEFAULT VALUES FOR DB ---
    $status   = "Unverified"; 
    $earnings = "0";   
    $admin    = 0;     

    // Validation
    $errors = [];
    if (empty($full_name)) $errors[] = "Full Name is required.";
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = "Invalid email format.";
    if (empty($phone_number)) $errors[] = "Phone Number is required.";
    if (empty($country)) $errors[] = "Country is required.";
    if (strlen($password) < 6) $errors[] = "Password must be at least 6 characters.";
    if ($password !== $con_password) $errors[] = "Passwords do not match.";

    // Check if email already exists
    if (empty($errors)) {
        $check_stmt = $connn->prepare("SELECT email FROM `user` WHERE `email` = ?");
        $check_stmt->bind_param("s", $email);
        $check_stmt->execute();
        $check_stmt->store_result();
        
        if ($check_stmt->num_rows > 0) {
            $errors[] = "Email address already registered.";
        }
        $check_stmt->close();
    }

    // Insert into Database
    if (empty($errors)) {
        
        // NOTE: Saving password as PLAIN TEXT as requested.
        
        $stmt = $connn->prepare("INSERT INTO `user` 
            (`full_name`, `email`, `phone_number`, `country`, `password`, `date`, `status`, `earnings`, `admin`) 
            VALUES (?, ?, ?, ?, ?, NOW(), ?, ?, ?)");
        
        // Passing $password directly (not hashed)
        $stmt->bind_param("sssssssi", $full_name, $email, $phone_number, $country, $password, $status, $earnings, $admin);

        if ($stmt->execute()) {
            $stmt->close();

            // --- Send Email ---
            if (class_exists('PHPMailer\PHPMailer\PHPMailer')) {
                try {
                    $mail = new PHPMailer(true);
                    $mail->isSMTP();
                    $mail->Host       = 'smtp.axiomvest.net'; 
                    $mail->SMTPAuth   = true;
                    $mail->Username   = 'support@axiomvest.net'; 
                    $mail->Password   = 'Mademen.2017'; 
                    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; 
                    $mail->Port       = 587; 

                    $mail->setFrom('no-reply@axiomvest.net', 'Axiom Vest');
                    $mail->addAddress($email, $full_name);
                    
                    $mail->isHTML(true);
                    $mail->Subject = 'Welcome To Axiom Vest';
                    $mail->Body    = "<h3>Welcome, " . htmlspecialchars($full_name) . "!</h3><p>Your account has been successfully created.</p>";
                    $mail->AltBody = "Welcome " . $full_name . ". Your account has been created.";
                    
                    $mail->send();
                } catch (Exception $e) {
                    // Continue even if email fails
                }
            }

            header("Location: success.php");
            exit;
        } else {
            $errors[] = "Database Error: " . $connn->error;
        }
    }

    // Handle Errors
    if (!empty($errors)) {
        $error_message = urlencode(implode(" | ", $errors));
        header("Location: " . $_SERVER['PHP_SELF'] . "?error=" . $error_message);
        exit;
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Axiom Investment - Smart investment Growth</title>
  <link rel="stylesheet" href="css/styles.css">
    <style>
    /* Mobile Menu Styles */
    .hamburger {
      display: none;
      flex-direction: column;
      cursor: pointer;
      width: 24px;
      height: 20px;
      justify-content: space-between;
      z-index: 1001;
    }

    .hamburger span {
      display: block;
      height: 2px;
      width: 100%;
      background-color: var(--text-dark);
      transition: all 0.3s ease;
    }

    /* Mobile menu active state */
    .hamburger.active span:nth-child(1) {
      transform: rotate(45deg) translate(5px, 5px);
    }

    .hamburger.active span:nth-child(2) {
      opacity: 0;
    }

    .hamburger.active span:nth-child(3) {
      transform: rotate(-45deg) translate(7px, -6px);
    }

    /* Nav Container */
    nav {
      background: white;
      box-shadow: 0 2px 10px rgba(0,0,0,0.1);
      position: sticky;
      top: 0;
      z-index: 100;
    }

    .nav-container {
      display: flex;
      justify-content: space-between;
      align-items: center;
      max-width: 1200px;
      margin: 0 auto;
      padding: 15px 20px;
      position: relative;
    }

    .logo {
      display: flex;
      align-items: center;
      font-size: 1.5rem;
      font-weight: bold;
      color: var(--text-dark);
      text-decoration: none;
    }

    .logo-icon {
      font-size: 1.8rem;
      margin-right: 8px;
      color: #ffffff;
    }

    /* Desktop Navigation */
    .nav-links {
      display: flex;
      align-items: center;
      gap: 25px;
      list-style: none;
      margin: 0;
      padding: 0;
    }

    .nav-links a {
      color: var(--text-light);
      text-decoration: none;
      font-weight: 500;
      transition: color 0.3s;
      padding: 8px 0;
    }

    .nav-links a:hover,
    .nav-links a.active {
      color: var(--primary-color);
    }

    .nav-links .btn {
      padding: 10px 20px;
      border-radius: 6px;
      text-decoration: none;
      font-weight: 600;
      font-size: 0.9rem;
      transition: all 0.3s;
    }

    .nav-links .btn-secondary {
      background: #f1f5f9;
      color: #475569 !important;
      border: 1px solid #cbd5e1;
    }

    .nav-links .btn-primary {
      background: var(--primary-color);
      color: white !important;
      border: 1px solid var(--primary-color);
    }

    .nav-links .btn-secondary:hover {
      background: #e2e8f0;
    }

    .nav-links .btn-primary:hover {
      background: var(--primary-dark);
      border-color: var(--primary-dark);
    }

    /* Overlay when menu is open */
    .nav-overlay {
      display: none;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: rgba(0,0,0,0.5);
      z-index: 999;
    }

    .nav-overlay.active {
      display: block;
    }

    /* Responsive Nav Links */
    @media (max-width: 992px) {
      .hamburger {
        display: flex;
        position: absolute;
        right: 20px;
        top: 50%;
        transform: translateY(-50%);
      }
      
      .nav-links {
        position: fixed;
        top: 0;
        right: -100%;
        width: 80%;
        max-width: 400px;
        height: 100vh;
        background: white;
        flex-direction: column;
        padding: 80px 30px 30px;
        box-shadow: -5px 0 15px rgba(0,0,0,0.1);
        transition: right 0.3s ease;
        z-index: 1000;
        overflow-y: auto;
        gap: 0;
      }
      
      .nav-links.active {
        right: 0;
      }
      
      .nav-links li {
        margin: 0;
        margin-bottom: 20px;
        width: 100%;
      }
      
      .nav-links a {
        padding: 12px 0;
        font-size: 1.1rem;
        display: block;
        width: 100%;
      }
      
      .nav-links .btn {
        width: 100%;
        text-align: center;
        margin-bottom: 10px;
        padding: 12px;
      }
      
      /* Hide regular nav links on mobile initially */
      .nav-links:not(.active) {
        display: none;
      }
    }

    /* Hide hamburger on desktop */
    @media (min-width: 993px) {
      .hamburger {
        display: none !important;
      }
      
      .nav-overlay {
        display: none !important;
      }
    }

    /* Hero Section */
    .hero {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: white;
      text-align: center;
      padding: 80px 20px;
    }

    /* CTA Section */
    .cta-section {
      background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
      color: white;
      padding: 80px 20px;
      text-align: center;
    }

    .cta-container {
      max-width: 800px;
      margin: 0 auto;
    }

    .cta-content h2 {
      font-size: 2.5rem;
      margin-bottom: 20px;
    }

    /* Buttons */
    .btn {
      display: inline-block;
      padding: 12px 28px;
      border-radius: 6px;
      text-decoration: none;
      font-weight: 600;
      transition: all 0.3s;
      border: none;
      cursor: pointer;
    }

    .btn-primary {
      background: var(--primary-color);
      color: white;
      border: 1px solid var(--primary-color);
    }

    .btn-outline {
      background: transparent;
      color: white;
      border: 2px solid white;
    }

    .btn-outline:hover {
      background: white;
      color: var(--primary-color);
    }

    /* Section Header */
    .section-header {
      text-align: center;
      margin-bottom: 40px;
    }

    .section-header h2 {
      font-size: 2rem;
      color: var(--text-dark);
      margin-bottom: 10px;
    }

    .section-header p {
      color: var(--text-light);
      font-size: 1.1rem;
    }

    /* CSS Variables */
    :root {
      --primary-color: #6366f1;
      --primary-dark: #4f46e5;
      --text-dark: #1f2937;
      --text-light: #6b7280;
    }

    /* Footer */
    footer {
      background: #1f2937;
      color: white;
      padding: 60px 20px 20px;
    }

    .footer-content {
      max-width: 1200px;
      margin: 0 auto;
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
      gap: 40px;
      margin-bottom: 40px;
    }

    .footer-section h3 {
      font-size: 1.2rem;
      margin-bottom: 20px;
      color: white;
    }

    .footer-section ul {
      list-style: none;
      padding: 0;
      margin: 0;
    }

    .footer-section ul li {
      margin-bottom: 10px;
    }

    .footer-section a {
      color: #d1d5db;
      text-decoration: none;
      transition: color 0.3s;
    }

    .footer-section a:hover {
      color: white;
    }

    /* Body styles */
    body {
      margin: 0;
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
      color: var(--text-dark);
      line-height: 1.6;
    }

    * {
      box-sizing: border-box;
    }
  </style>
</head>
<body>
  <!-- Navigation -->
   <nav>
    <div class="nav-container">
      <a href="index.html" class="logo">
        <div class="logo-icon">▲</div>
        Axiom 
      </a>
      
      <!-- Hamburger Menu Button (at far right on mobile) -->
      <div class="hamburger" id="hamburger">
        <span></span>
        <span></span>
        <span></span>
      </div>
      
      <!-- Navigation Links -->
      <ul class="nav-links" id="navLinks">
        <li><a href="index.html">Home</a></li>
        <li><a href="investment-plan.html">Invest</a></li>
        <li><a href="about-us.html" class="active">Company</a></li>
        <li><a href="legal-information.html">Legal</a></li>
        <li><a href="contact.html">Support</a></li>
        <li><a href="signup.php" class="btn btn-secondary">Get Started</a></li>
        <li><a href="login.php" class="btn btn-primary">Log In</a></li>
      </ul>
      
      <!-- Mobile Menu Overlay -->
      <div class="nav-overlay" id="navOverlay"></div>
    </div>
  </nav>

  <!-- Main Auth Section -->
  <section class="auth-section">
    <div class="auth-container">
      
      <!-- Left Side: Registration Form -->
      <div class="auth-content">
        <div class="auth-header">
          <h1>Create Account</h1>
          <p>Join over 45,000 investors building their wealth.</p>
        </div>

        <!-- Display PHP Errors Here if needed -->
        <?php if (isset($_GET['error'])): ?>
            <div class="alert-error">
                <?php echo htmlspecialchars($_GET['error']); ?>
            </div>
        <?php endif; ?>

        <form id="registerPageForm" class="auth-form" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" method="POST">
          
          <div class="form-group">
            <label for="fullName">Full Name</label>
            <div class="input-wrapper">
              <span class="input-icon">👤</span>
              <input type="text" id="fullName" name="full_name" placeholder="e.g., John Doe" required>
            </div>
          </div>

          <div class="form-row">
            <div class="form-group">
              <label for="email">Email Address</label>
              <div class="input-wrapper">
                <span class="input-icon">✉️</span>
                <input type="email" id="email" name="email" placeholder="john@example.com" required>
              </div>
            </div>
            
            <div class="form-group">
              <label for="phone">Phone Number</label>
              <div class="input-wrapper">
                <span class="input-icon">📱</span>
                <input type="tel" id="phone" name="phone_number" placeholder="+1 555 123 4567" required>
              </div>
            </div>
          </div>

          <div class="form-group">
            <label for="country">Country</label>
            <div class="input-wrapper">
              <span class="input-icon">🌍</span>
              <select id="country" name="country" required>
                <option value="" disabled selected>Select your country</option>
                <option value="US">United States</option>
                <option value="UK">United Kingdom</option>
                <option value="CA">Canada</option>
                <option value="AU">Australia</option>
                <option value="DE">Germany</option>
                <option value="FR">France</option>
                <option value="JP">Japan</option>
                <option value="CN">China</option>
                <option value="BR">Brazil</option>
                <option value="IN">India</option>
                <option value="NG">Nigeria</option>
                <option value="ZA">South Africa</option>
              </select>
            </div>
          </div>

          <div class="form-row">
            <div class="form-group">
              <label for="password">Password</label>
              <div class="input-wrapper">
                <span class="input-icon">🔒</span>
                <input type="password" id="password" name="password" placeholder="Min. 8 characters" required>
              </div>
            </div>

            <div class="form-group">
              <label for="confirmPassword">Confirm Password</label>
              <div class="input-wrapper">
                <span class="input-icon">🔑</span>
                <input type="password" id="confirmPassword" name="con_password" placeholder="Re-enter password" required>
              </div>
            </div>
          </div>

          <div class="form-options">
            <div class="checkbox-group">
              <input type="checkbox" id="terms" required>
              <label for="terms">I agree to the <a href="#" style="color:var(--primary-color)">Terms of Service</a> and <a href="#" style="color:var(--primary-color)">Privacy Policy</a>.</label>
            </div>
          </div>

          <button type="submit" name="submit" class="btn btn-primary btn-block">Create Free Account</button>
        </form>
      </div>

      <!-- Right Side: Vector Art -->
      <div class="auth-visual">
        <div class="visual-content">
          <svg class="auth-vector" viewBox="0 0 400 400" fill="none" xmlns="http://www.w3.org/2000/svg">
            <circle cx="200" cy="200" r="160" stroke="white" stroke-opacity="0.1" stroke-width="2"/>
            <circle cx="200" cy="200" r="120" stroke="white" stroke-opacity="0.2" stroke-width="2"/>
            <path d="M200 80C200 80 160 160 160 220C160 250 180 270 200 270C220 270 240 250 240 220C240 160 200 80 200 80Z" fill="white"/>
            <path d="M200 80C200 80 160 160 160 220C160 250 180 270 200 270" fill="#e2e8f0" fill-opacity="0.5"/>
            <circle cx="200" cy="180" r="15" fill="var(--secondary-color)"/>
            <circle cx="200" cy="180" r="10" fill="#f8fafc"/>
            <path d="M160 220L140 260L165 255" fill="white"/>
            <path d="M240 220L260 260L235 255" fill="white"/>
            <path d="M185 270Q200 340 215 270" fill="#f59e0b" class="flame-anim"/>
            <path d="M192 270Q200 310 208 270" fill="#fcd34d" class="flame-anim"/>
            <circle cx="150" cy="300" r="30" fill="white" fill-opacity="0.2" class="float-slow"/>
            <circle cx="250" cy="310" r="40" fill="white" fill-opacity="0.1" class="float-medium"/>
            <circle cx="100" cy="250" r="10" fill="#14b8a6" class="float-fast"/>
            <circle cx="300" cy="150" r="6" fill="#ec4899" class="float-slow"/>
            <path d="M50 300L120 240L180 260L350 100" stroke="white" stroke-width="4" stroke-linecap="round" stroke-dasharray="10 10" opacity="0.3"/>
          </svg>
          <div class="visual-text">
            <h2>Start Your Journey</h2>
            <p>Access competitive investment plans, real-time analytics, and secure asset management.</p>
          </div>
        </div>
      </div>

    </div>
  </section>
   <!-- Mobile Menu JavaScript -->
  <script>
    // Mobile Menu Toggle
    document.addEventListener('DOMContentLoaded', function() {
      const hamburger = document.getElementById('hamburger');
      const navLinks = document.getElementById('navLinks');
      const navOverlay = document.getElementById('navOverlay');
      
      // Create overlay if it doesn't exist
      if (!navOverlay && hamburger) {
        const overlay = document.createElement('div');
        overlay.className = 'nav-overlay';
        overlay.id = 'navOverlay';
        document.querySelector('nav .nav-container').appendChild(overlay);
      }
      
      // Toggle mobile menu
      function toggleMobileMenu() {
        if (hamburger && navLinks) {
          hamburger.classList.toggle('active');
          navLinks.classList.toggle('active');
          const overlay = document.getElementById('navOverlay');
          if (overlay) overlay.classList.toggle('active');
          document.body.style.overflow = navLinks.classList.contains('active') ? 'hidden' : '';
        }
      }
      
      // Close mobile menu
      function closeMobileMenu() {
        if (hamburger) hamburger.classList.remove('active');
        if (navLinks) navLinks.classList.remove('active');
        const overlay = document.getElementById('navOverlay');
        if (overlay) overlay.classList.remove('active');
        document.body.style.overflow = '';
      }
      
      // Event Listeners
      if (hamburger) {
        hamburger.addEventListener('click', toggleMobileMenu);
      }
      
      // Overlay click to close
      document.addEventListener('click', function(e) {
        const overlay = document.getElementById('navOverlay');
        if (overlay && overlay.classList.contains('active') && e.target === overlay) {
          closeMobileMenu();
        }
      });
      
      // Close menu when clicking on a link
      const navLinksList = document.querySelectorAll('.nav-links a');
      navLinksList.forEach(link => {
        link.addEventListener('click', () => {
          if (window.innerWidth <= 992) {
            closeMobileMenu();
          }
        });
      });
      
      // Close menu on window resize
      window.addEventListener('resize', function() {
        if (window.innerWidth > 992) {
          closeMobileMenu();
        }
      });
      
      // Escape key to close menu
      document.addEventListener('keydown', function(e) {
        if (e.key === 'Escape' && navLinks && navLinks.classList.contains('active')) {
          closeMobileMenu();
        }
      });
    });
  </script>
<!--Start of Tawk.to Script-->
<script type="text/javascript">
var Tawk_API=Tawk_API||{}, Tawk_LoadStart=new Date();
(function(){
var s1=document.createElement("script"),s0=document.getElementsByTagName("script")[0];
s1.async=true;
s1.src='https://embed.tawk.to/693bf96ef06cff197f812f4c/default';
s1.charset='UTF-8';
s1.setAttribute('crossorigin','*');
s0.parentNode.insertBefore(s1,s0);
})();
</script>
<!--End of Tawk.to Script-->
</body>
</html>