<?php
session_start();
require_once 'configdb.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $fullname = $_POST['fullname'] ?? '';
    $email = $_POST['email'] ?? '';
    $phone = $_POST['phone'] ?? '';
    $password = $_POST['password'] ?? '';
    $confirm_password = $_POST['confirm_password'] ?? '';
    
    $errors = [];
    
    if (empty($fullname)) $errors[] = 'Full name is required';
    if (empty($email)) $errors[] = 'Email is required';
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = 'Invalid email format';
    if (empty($phone)) $errors[] = 'Phone number is required';
    if (strlen($password) < 6) $errors[] = 'Password must be at least 6 characters';
    if ($password !== $confirm_password) $errors[] = 'Passwords do not match';
    
    if (empty($errors)) {
        $database = new Database();
        $db = $database->getConnection();
        
        // Check if email already exists
        $check = $db->prepare("SELECT id FROM users WHERE email = :email");
        $check->bindParam(':email', $email);
        $check->execute();
        
        if ($check->fetch()) {
            $errors[] = 'Email already registered';
        } else {
            $hashed_password = password_hash($password, PASSWORD_DEFAULT);
            
            $query = "INSERT INTO users (fullname, email, phone, password, user_type) 
                      VALUES (:fullname, :email, :phone, :password, 'customer')";
            $stmt = $db->prepare($query);
            $stmt->bindParam(':fullname', $fullname);
            $stmt->bindParam(':email', $email);
            $stmt->bindParam(':phone', $phone);
            $stmt->bindParam(':password', $hashed_password);
            
            if ($stmt->execute()) {
                $_SESSION['register_success'] = true;
                header('Location: login.php?registered=1');
                exit;
            } else {
                $errors[] = 'Registration failed. Please try again.';
            }
        }
    }
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Register - Ladies Beauty Clinic</title>
    
    <!-- CSS Files -->
    <link rel="stylesheet" href="header.css">
    <link rel="stylesheet" href="footer.css">
    <link rel="stylesheet" href="style.css">
    <link rel="stylesheet" href="register.css">
    
    <!-- Font Awesome -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&family=Playfair+Display:wght@400;700&display=swap" rel="stylesheet">
    
    <style>
        
        header, footer {
            width: 100%;
            left: 0;
            right: 0;
        }
        
        /* Header styling */
        header {
            background-color: #ffffff;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            position: fixed;
            top: 0;
            z-index: 1000;
        }
        
        .header-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 15px 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        /* Footer styling */
        footer {
            background: linear-gradient(135deg, #D13370, #B01E5A); 
            padding: 60px 0 30px;
            margin-top: 50px; /* Gap between form and footer */
            width: 100%;
            color: #ffffff;
        }
        
        .footer-container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 20px;
        }
        
        .footer-content {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 40px;
            margin-bottom: 40px;
        }
        
        .footer-column h3 {
            color: #ffffff;
            font-size: 18px;
            margin-bottom: 20px;
            font-weight: 600;
            position: relative;
            padding-bottom: 10px;
            font-family: 'Playfair Display', serif;
        }
        
        .footer-column h3::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 40px;
            height: 2px;
            background-color: #ffffff;
        }
        
        .footer-column p {
            color: #ffffff;
            line-height: 1.6;
            font-size: 14px;
            margin-bottom: 20px;
            opacity: 0.9;
        }
        
        .footer-column ul {
            list-style: none;
            padding: 0;
        }
        
        .footer-column ul li {
            margin-bottom: 12px;
        }
        
        .footer-column ul li a {
            color: #ffffff;
            text-decoration: none;
            font-size: 14px;
            transition: all 0.3s ease;
            display: flex;
            align-items: center;
            gap: 8px;
            opacity: 0.9;
        }
        
        .footer-column ul li a:hover {
            color: #ffffff;
            padding-left: 5px;
            opacity: 1;
        }
        
        .footer-column ul li i {
            color: #ffffff;
            width: 20px;
            font-size: 14px;
        }
        
        .social-icons {
            display: flex;
            gap: 15px;
            margin-top: 20px;
        }
        
        .social-icons a {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 40px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            color: #ffffff;
            text-decoration: none;
            transition: all 0.3s ease;
        }
        
        .social-icons a:hover {
            background-color: #ffffff;
            color: #D13370;
            transform: translateY(-3px);
        }
        
        .copyright {
            text-align: center;
            padding-top: 30px;
            border-top: 1px solid rgba(255, 255, 255, 0.2);
            color: #ffffff;
            font-size: 14px;
            opacity: 0.9;
        }
        
        .copyright-links {
            margin-top: 10px;
        }
        
        .copyright-links a {
            color: #ffffff;
            text-decoration: none;
            margin: 0 10px;
            transition: color 0.3s ease;
            opacity: 0.9;
        }
        
        .copyright-links a:hover {
            text-decoration: underline;
            opacity: 1;
        }
        
        /* Main content area */
        body {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
            margin: 0;
            font-family: 'Poppins', sans-serif;
            background-color: #f8f9fa;
        }
        
        main {
            flex: 1;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 140px 20px 60px; /* INCREASED top padding from 120px to 140px for gap */
            background: linear-gradient(135deg, #FFE0E8 0%, #FFFFFF 100%);
            min-height: calc(100vh - 80px - 400px);
        }
        
        /* Register form styling */
        .register-wrapper {
            width: 100%;
            max-width: 550px;
            margin: 20px auto 40px; /* Added top margin of 20px for extra gap */
        }
        
        .register-card {
            background: white;
            border-radius: 20px;
            box-shadow: 0 10px 30px rgba(209, 51, 112, 0.15);
            padding: 40px;
            border: 1px solid #f0f0f0;
        }
        
        .register-header {
            text-align: center;
            margin-bottom: 30px;
        }
        
        .register-header i {
            font-size: 50px;
            color: #D13370;
            margin-bottom: 15px;
        }
        
        .register-header h1 {
            font-size: 28px;
            color: #333;
            margin-bottom: 8px;
            font-family: 'Playfair Display', serif;
        }
        
        .register-header p {
            color: #666;
            font-size: 14px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-group label {
            display: block;
            margin-bottom: 8px;
            color: #333;
            font-weight: 500;
            font-size: 14px;
        }
        
        .form-group label span {
            color: #D13370;
        }
        
        .form-group input {
            width: 100%;
            padding: 14px 16px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 14px;
            font-family: 'Poppins', sans-serif;
            transition: all 0.3s;
            box-sizing: border-box;
        }
        
        .form-group input:focus {
            outline: none;
            border-color: #D13370;
            box-shadow: 0 0 0 3px rgba(209, 51, 112, 0.1);
        }
        
        .form-row {
            display: flex;
            gap: 20px;
            margin-bottom: 20px;
        }
        
        .form-row .form-group {
            flex: 1;
            margin-bottom: 0;
        }
        
        .password-hint {
            color: #999;
            font-size: 12px;
            margin-top: 6px;
            display: block;
        }
        
        .btn-register {
            width: 100%;
            padding: 16px;
            background: #D13370;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            margin-top: 10px;
        }
        
        .btn-register:hover {
            background: #B01E5A;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(209, 51, 112, 0.3);
        }
        
        .login-link {
            text-align: center;
            margin-top: 25px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }
        
        .login-link p {
            color: #666;
            font-size: 14px;
        }
        
        .login-link a {
            color: #D13370;
            text-decoration: none;
            font-weight: 600;
        }
        
        .login-link a:hover {
            text-decoration: underline;
        }
        
        .alert {
            background: #fee;
            color: #c33;
            padding: 15px;
            border-radius: 8px;
            margin-bottom: 25px;
            font-size: 14px;
        }
        
        .alert i {
            margin-right: 8px;
        }
        
        .password-wrapper {
            position: relative;
        }
        
        .password-wrapper input {
            padding-right: 45px;
        }
        
        .toggle-password {
            position: absolute;
            right: 15px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            color: #999;
            font-size: 18px;
        }
        
        .toggle-password:hover {
            color: #D13370;
        }
        
        /* Desktop navigation */
        .desktop-nav ul {
            display: flex;
            list-style: none;
            gap: 30px;
            margin: 0;
            padding: 0;
        }
        
        .desktop-nav ul li a {
            text-decoration: none;
            color: #333;
            font-weight: 500;
            font-size: 15px;
            transition: color 0.3s ease;
        }
        
        .desktop-nav ul li a:hover,
        .desktop-nav ul li a.active {
            color: #D13370;
        }
        
        /* Mobile menu button */
        .mobile-menu-btn {
            display: none;
            background: none;
            border: none;
            font-size: 24px;
            color: #D13370;
            cursor: pointer;
        }
        
        /* Mobile navigation */
        .mobile-nav {
            position: fixed;
            top: 0;
            left: -100%;
            width: 100%;
            height: 100vh;
            background-color: #ffffff;
            transition: left 0.3s ease;
            z-index: 1001;
            padding: 80px 20px 20px;
        }
        
        .mobile-nav.active {
            left: 0;
        }
        
        .mobile-nav-close {
            position: absolute;
            top: 20px;
            right: 20px;
            background: none;
            border: none;
            font-size: 28px;
            color: #D13370;
            cursor: pointer;
        }
        
        .mobile-nav ul {
            list-style: none;
            padding: 0;
        }
        
        .mobile-nav ul li {
            margin-bottom: 20px;
        }
        
        .mobile-nav ul li a {
            text-decoration: none;
            color: #333;
            font-size: 18px;
            font-weight: 500;
            display: block;
            padding: 10px 0;
            border-bottom: 1px solid #eee;
        }
        
        /* Responsive */
        @media (max-width: 992px) {
            .footer-content {
                grid-template-columns: repeat(2, 1fr);
                gap: 30px;
            }
        }
        
        @media (max-width: 768px) {
            .desktop-nav {
                display: none;
            }
            
            .mobile-menu-btn {
                display: block;
            }
            
            .form-row {
                flex-direction: column;
                gap: 20px;
            }
            
            .register-card {
                padding: 30px 20px;
            }
            
            .register-header h1 {
                font-size: 24px;
            }
            
            .footer-content {
                grid-template-columns: 1fr;
                gap: 30px;
            }
            
            .footer-column h3::after {
                left: 0;
                transform: none;
            }
            
            main {
                padding: 120px 20px 60px; /* Slightly less padding on mobile */
            }
        }
        
        @media (max-width: 480px) {
            .register-card {
                padding: 25px 15px;
            }
            
            .register-header i {
                font-size: 40px;
            }
            
            .register-header h1 {
                font-size: 22px;
            }
            
            .btn-register {
                padding: 14px;
                font-size: 15px;
            }
            
            .logo {
                font-size: 20px;
            }
            
            .logo img {
                width: 60px;
                height: 60px;
            }
        }
    </style>
</head>
<body>
    <!-- HEADER - Full Width -->
    <header>
        <div class="header-container">
            <a href="index.php" class="logo" style="display: flex; align-items: center; gap: 15px; text-decoration: none; font-size: 24px; font-weight: bold;">
                <img src="ladies photo/logo.png" alt="Logo" style="width: 80px; height: 80px; border-radius: 50%; object-fit: cover;"/>
                LADIES <span style="color: #D13370;">BEAUTY</span> CLINIC
            </a>
            
            <nav class="desktop-nav">
                <ul>
                    <li><a href="index.php">Home</a></li>
                    <li><a href="about.php">About</a></li>
                    <li><a href="services.php">Services</a></li>
                    <li><a href="book.php">Book</a></li>
                    <li><a href="calendar.php">Calendar</a></li>
                    <li><a href="#contact">Contact Us</a></li>
                </ul>
            </nav>
            
            <button class="mobile-menu-btn" id="mobileMenuBtn">
                <i class="fas fa-bars" style="color: #D13370;"></i>
            </button>
        </div>
        
        <nav class="mobile-nav" id="mobileNav">
            <button class="mobile-nav-close" id="mobileNavClose">
                <i class="fas fa-times"></i>
            </button>
            <ul>
                <li><a href="index.php">Home</a></li>
                <li><a href="about.php">About</a></li>
                <li><a href="services.php">Services</a></li>
                <li><a href="book.php">Book</a></li>
                <li><a href="calendar.php">Calendar</a></li>
                <li><a href="#contact">Contact Us</a></li>
                <?php if (isset($_SESSION['user_id'])): ?>
                    <li><a href="logout.php">Logout (<?php echo htmlspecialchars($_SESSION['user_name']); ?>)</a></li>
                <?php else: ?>
                    <li><a href="login.php">Login</a></li>
                    <li><a href="register.php" style="color: #D13370; font-weight: 600;">Register</a></li>
                <?php endif; ?>
            </ul>
        </nav>
    </header>

    <!-- MAIN CONTENT -->
    <main>
        <div class="register-wrapper">
            <div class="register-card">
                <div class="register-header">
                    <i class="fas fa-user-plus" style="color: #D13370;"></i>
                    <h1>Create Account</h1>
                    <p>Join Ladies Beauty Clinic today</p>
                </div>
                
                <?php if (!empty($errors)): ?>
                    <div class="alert">
                        <i class="fas fa-exclamation-circle"></i>
                        <?php foreach ($errors as $error): ?>
                            <div><?php echo htmlspecialchars($error); ?></div>
                        <?php endforeach; ?>
                    </div>
                <?php endif; ?>
                
                <form method="POST">
                    <div class="form-group">
                        <label for="fullname">Full Name <span>*</span></label>
                        <input type="text" id="fullname" name="fullname" 
                               placeholder="Enter your full name"
                               value="<?php echo htmlspecialchars($_POST['fullname'] ?? ''); ?>" 
                               required>
                    </div>
                    
                    <div class="form-group">
                        <label for="email">Email Address <span>*</span></label>
                        <input type="email" id="email" name="email" 
                               placeholder="Enter your email"
                               value="<?php echo htmlspecialchars($_POST['email'] ?? ''); ?>" 
                               required>
                    </div>
                    
                    <div class="form-group">
                        <label for="phone">Phone Number <span>*</span></label>
                        <input type="tel" id="phone" name="phone" 
                               placeholder="Enter your phone number"
                               value="<?php echo htmlspecialchars($_POST['phone'] ?? ''); ?>" 
                               required>
                    </div>
                    
                    <div class="form-row">
                        <div class="form-group">
                            <label for="password">Password <span>*</span></label>
                            <div class="password-wrapper">
                                <input type="password" id="password" name="password" 
                                       placeholder="Enter password" required>
                                <i class="fas fa-eye toggle-password" onclick="togglePassword('password', this)"></i>
                            </div>
                            <small class="password-hint">Minimum 6 characters</small>
                        </div>
                        
                        <div class="form-group">
                            <label for="confirm_password">Confirm Password <span>*</span></label>
                            <div class="password-wrapper">
                                <input type="password" id="confirm_password" name="confirm_password" 
                                       placeholder="Confirm password" required>
                                <i class="fas fa-eye toggle-password" onclick="togglePassword('confirm_password', this)"></i>
                            </div>
                        </div>
                    </div>
                    
                    <button type="submit" class="btn-register">
                        Create Account <i class="fas fa-arrow-right"></i>
                    </button>
                </form>
                
                <div class="login-link">
                    <p>Already have an account? <a href="login.php">Sign in</a></p>
                </div>
            </div>
        </div>
    </main>

    <!-- FOOTER - PINK BACKGROUND with WHITE TEXT - Full Width -->
    <footer id="contact">
        <div class="footer-container">
            <div class="footer-content">
                <!-- About Us Column -->
                <div class="footer-column">
                    <h3>Ladies Beauty Clinic</h3>
                    <p>Your sanctuary of beauty and luxury. We enhance natural features, restore balance, and reveal the best version of yourself.</p>
                    <div class="social-icons">
                        <a href="https://www.facebook.com/profile.php?id=61587125655637" target="_blank"><i class="fab fa-facebook-f"></i></a>
                        <a href="https://wa.me/23057891774" target="_blank"><i class="fab fa-whatsapp"></i></a>
                        <a href="https://www.tiktok.com/@ladies.beauty.clinic" target="_blank"><i class="fab fa-tiktok"></i></a>
                    </div>
                </div>
                
                <!-- Quick Links Column -->
                <div class="footer-column">
                    <h3>Quick Links</h3>
                    <ul>
                        <li><a href="index.php"><i class="fas fa-home"></i> Home</a></li>
                        <li><a href="services.php"><i class="fas fa-spa"></i> Services</a></li>
                        <li><a href="book.php"><i class="fas fa-calendar-plus"></i> Book</a></li>
                        <li><a href="calendar.php"><i class="fas fa-calendar-alt"></i> Calendar</a></li>
                        <li><a href="#contact"><i class="fas fa-envelope"></i> Contact Us</a></li>
                    </ul>
                </div>
                
                <!-- Services Column -->
                <div class="footer-column">
                    <h3>Services</h3>
                    <ul>
                        <li><a href="services.php"><i class="fas fa-spa"></i> Skin Care</a></li>
                        <li><a href="services.php"><i class="fas fa-cut"></i> Hair Care</a></li>
                        <li><a href="services.php"><i class="fas fa-hand-paper"></i> Nail Care</a></li>
                        <li><a href="services.php"><i class="fas fa-feather-alt"></i> Facial Treatments</a></li>
                    </ul>
                </div>
                
                <!-- Contact Info Column -->
                <div class="footer-column">
                    <h3>Contact Info</h3>
                    <ul>
                        <li><a href="https://www.google.com/maps"><i class="fas fa-map-marker-alt"></i> Near Mahebourg Museum, Mahebourg</a></li>
                        <li><a href="tel:23057891774"><i class="fas fa-phone"></i> (230) 5789 1774</a></li>
                        <li><a href="mailto:ladiesbeautyclinic11@gmail.com"><i class="fas fa-envelope"></i> ladiesbeautyclinic11@gmail.com</a></li>
                    </ul>
                </div>
            </div>
            
            <div class="copyright">
                <p>&copy; 2026 Ladies Beauty Clinic. All Rights Reserved.</p>
                <div class="copyright-links">
                    <a href="#">Privacy Policy</a> | 
                    <a href="#">Terms of Service</a>
                </div>
            </div>
        </div>
    </footer>

    <script>
        // Mobile Menu Toggle
        document.getElementById('mobileMenuBtn').addEventListener('click', function() {
            document.getElementById('mobileNav').classList.add('active');
            document.body.style.overflow = 'hidden';
        });

        document.getElementById('mobileNavClose').addEventListener('click', function() {
            document.getElementById('mobileNav').classList.remove('active');
            document.body.style.overflow = '';
        });

        // Close mobile menu when clicking a link
        document.querySelectorAll('.mobile-nav a').forEach(link => {
            link.addEventListener('click', function() {
                document.getElementById('mobileNav').classList.remove('active');
                document.body.style.overflow = '';
            });
        });

        // Toggle password visibility
        function togglePassword(fieldId, icon) {
            const field = document.getElementById(fieldId);
            if (field.type === 'password') {
                field.type = 'text';
                icon.classList.remove('fa-eye');
                icon.classList.add('fa-eye-slash');
            } else {
                field.type = 'password';
                icon.classList.remove('fa-eye-slash');
                icon.classList.add('fa-eye');
            }
        }

        // Form validation
        document.querySelector('form').addEventListener('submit', function(e) {
            const password = document.getElementById('password').value;
            const confirm = document.getElementById('confirm_password').value;
            
            if (password !== confirm) {
                e.preventDefault();
                alert('Passwords do not match!');
            }
        });
    </script>
</body>
</html>



