<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.hrs.model.entity.User" %>
<%
    User loginUser = (User) session.getAttribute("loginUser");
    if (loginUser == null || !"1".equals(loginUser.getRoleType())) {
        response.sendRedirect(request.getContextPath() + "/user/login");
        return;
    }
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>房东首页 - 租房系统</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: Arial, "微软雅黑", sans-serif;
            background-color: #f5f5f5;
        }
        
        .header {
            background-color: #ff9800;
            color: white;
            padding: 15px 0;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .container {
            width: 1200px;
            margin: 0 auto;
        }
        
        .logo {
            float: left;
            font-size: 24px;
            font-weight: bold;
        }
        
        .nav {
            float: right;
            margin-top: 5px;
        }
        
        .nav a {
            color: white;
            text-decoration: none;
            margin-left: 20px;
            padding: 5px 10px;
        }
        
        .nav a:hover {
            background-color: #fb8c00;
            border-radius: 4px;
        }
        
        .user-info {
            float: right;
            margin-right: 20px;
            font-size: 14px;
        }
        
        .clearfix::after {
            content: "";
            clear: both;
            display: table;
        }
        
        .welcome-card {
            background-color: white;
            border-radius: 8px;
            padding: 30px;
            margin-top: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            text-align: center;
        }
        
        .welcome-card h1 {
            color: #333;
            margin-bottom: 20px;
        }
        
        .welcome-card p {
            color: #666;
            margin-bottom: 30px;
        }
        
        .stats {
            display: flex;
            gap: 20px;
            justify-content: center;
            margin-top: 30px;
        }
        
        .stat-card {
            background-color: #f9f9f9;
            padding: 20px;
            border-radius: 8px;
            width: 200px;
            text-align: center;
        }
        
        .stat-number {
            font-size: 32px;
            font-weight: bold;
            color: #ff9800;
        }
        
        .stat-label {
            color: #666;
            margin-top: 10px;
        }
        
        .btn {
            display: inline-block;
            padding: 10px 20px;
            background-color: #ff9800;
            color: white;
            text-decoration: none;
            border-radius: 4px;
            margin: 0 10px;
        }
        
        .btn:hover {
            background-color: #fb8c00;
        }
        
        .footer {
            background-color: #333;
            color: white;
            text-align: center;
            padding: 20px;
            margin-top: 40px;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="container clearfix">
            <div class="logo">🏠 房东后台</div>
            <div class="user-info">
                欢迎，<%= loginUser.getRealName() %> |
                <a href="${pageContext.request.contextPath}/user/logout" style="color:white;">退出</a>
            </div>
            <div class="nav">
                <a href="${pageContext.request.contextPath}/landlord/house/list">房源管理</a>
                <a href="${pageContext.request.contextPath}/landlord/reservation/list">预约管理</a>
                <a href="${pageContext.request.contextPath}/landlord/order/list">订单管理</a>
            </div>
        </div>
    </div>
    
    <div class="container">
        <div class="welcome-card">
            <h1>欢迎房东，<%= loginUser.getRealName() %>！</h1>
            <p>欢迎来到租房系统房东后台，您可以管理房源、查看预约、处理订单。</p>
            
            <div class="stats">
                <div class="stat-card">
                    <div class="stat-number" id="houseCount">-</div>
                    <div class="stat-label">我的房源</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number" id="reservationCount">-</div>
                    <div class="stat-label">待处理预约</div>
                </div>
            </div>
            
            <div style="margin-top: 30px;">
                <a href="${pageContext.request.contextPath}/landlord/house/list" class="btn">管理房源</a>
                <a href="${pageContext.request.contextPath}/landlord/reservation/list" class="btn">查看预约</a>
            </div>
        </div>
    </div>
    
    <div class="footer">
        <p>© 2026 租房系统 | 让租房更简单</p>
    </div>
    
    <script>
        // 加载统计数据
        fetch('${pageContext.request.contextPath}/landlord/statistics')
            .then(response => response.json())
            .then(data => {
                document.getElementById('houseCount').innerText = data.houseCount || 0;
                document.getElementById('reservationCount').innerText = data.reservationCount || 0;
            })
            .catch(err => console.log('加载统计数据失败', err));
    </script>
</body>
</html>