<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>租房系统注册</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            padding: 20px;
        }
        .register-container {
            background-color: white;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            width: 450px;
        }
        h2 {
            text-align: center;
            color: #333;
            margin-bottom: 30px;
        }
        .form-group {
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #666;
            font-weight: bold;
        }
        input[type="text"],
        input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 14px;
        }
        .role-group {
            display: flex;
            gap: 20px;
            margin: 10px 0;
        }
        .role-group label {
            display: inline;
            font-weight: normal;
        }
        button {
            width: 100%;
            padding: 12px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        button:hover {
            background-color: #45a049;
        }
        .error {
            background-color: #ffebee;
            color: #c62828;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 20px;
            text-align: center;
        }
        .message {
            background-color: #e8f5e9;
            color: #2e7d32;
            padding: 10px;
            border-radius: 4px;
            margin-bottom: 20px;
            text-align: center;
        }
        .login-link {
            text-align: center;
            margin-top: 20px;
            color: #666;
        }
        .login-link a {
            color: #4CAF50;
            text-decoration: none;
        }
        .login-link a:hover {
            text-decoration: underline;
        }
        .hint {
            font-size: 12px;
            color: #999;
            margin-top: 5px;
        }
        .required {
            color: #f44336;
        }
    </style>
</head>
<body>
    <div class="register-container">
        <h2>租房系统注册</h2>
        
        <%-- 显示错误信息 --%>
        <% 
            String error = (String)request.getAttribute("error");
            if(error != null) {
        %>
            <div class="error"><%= error %></div>
        <%
            }
        %>
        
        <%-- 显示成功信息 --%>
        <% 
            String message = (String)request.getAttribute("message");
            if(message != null) {
        %>
            <div class="message"><%= message %></div>
        <%
            }
        %>
        
        <form action="${pageContext.request.contextPath}/user/register" method="post">
            <div class="form-group">
                <label>用户名 <span class="required">*</span></label>
                <input type="text" name="username" placeholder="请输入用户名" required>
            </div>
            
            <div class="form-group">
                <label>密码 <span class="required">*</span></label>
                <input type="password" name="password" placeholder="请输入密码" required>
                <div class="hint">密码长度6-20位，建议使用字母+数字组合</div>
            </div>
            
            <div class="form-group">
                <label>确认密码 <span class="required">*</span></label>
                <input type="password" name="confirmPassword" placeholder="请再次输入密码" required>
            </div>
            
            <div class="form-group">
                <label>真实姓名</label>
                <input type="text" name="realName" placeholder="请输入真实姓名">
            </div>
            
            <div class="form-group">
                <label>手机号 <span class="required">*</span></label>
                <input type="text" name="phone" placeholder="请输入11位手机号" required>
            </div>
            
            <div class="form-group">
                <label>身份证号</label>
                <input type="text" name="idCard" placeholder="请输入身份证号（可选）">
                <div class="hint">房东认证需要提供身份证号</div>
            </div>
            
            <div class="form-group">
                <label>注册角色 <span class="required">*</span></label>
                <div class="role-group">
                    <label>
                        <input type="radio" name="roleType" value="0" checked> 租客
                    </label>
                    <label>
                        <input type="radio" name="roleType" value="1"> 房东
                    </label>
                </div>
                <div class="hint">房东需要管理员审核认证后才能发布房源</div>
            </div>
            
            <button type="submit">立即注册</button>
        </form>
        
        <div class="login-link">
            已有账号？ <a href="${pageContext.request.contextPath}/user/login">返回登录</a>
        </div>
    </div>
    
    <script>
        // 简单的前端验证
        document.querySelector('form').addEventListener('submit', function(e) {
            var password = document.querySelector('input[name="password"]').value;
            var confirm = document.querySelector('input[name="confirmPassword"]').value;
            var phone = document.querySelector('input[name="phone"]').value;
            
            // 验证密码长度
            if(password.length < 6 || password.length > 20) {
                alert('密码长度应为6-20位');
                e.preventDefault();
                return false;
            }
            
            // 验证两次密码
            if(password !== confirm) {
                alert('两次输入的密码不一致');
                e.preventDefault();
                return false;
            }
            
            // 验证手机号
            var phoneReg = /^1[3-9]\d{9}$/;
            if(!phoneReg.test(phone)) {
                alert('请输入正确的11位手机号');
                e.preventDefault();
                return false;
            }
        });
    </script>
</body>
</html>