<%@ 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 || !"2".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: #2196F3;
            color: white;
            padding: 15px 0;
            box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        }
        
        .container {
            width: 1200px;
            margin: 0 auto;
            overflow: hidden;
        }
        
        .logo {
            float: left;
            font-size: 24px;
            font-weight: bold;
        }
        
        .logo span {
            font-size: 14px;
            margin-left: 5px;
        }
        
        .nav {
            float: right;
            margin-top: 5px;
        }
        
        .nav a {
            color: white;
            text-decoration: none;
            margin-left: 20px;
            padding: 5px 10px;
        }
        
        .nav a:hover, .nav a.active {
            background-color: #1976D2;
            border-radius: 4px;
        }
        
        .user-info {
            float: right;
            margin-right: 20px;
            font-size: 14px;
        }
        
        .breadcrumb {
            background-color: white;
            padding: 12px 0;
            margin-bottom: 20px;
            border-radius: 4px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        }
        
        .breadcrumb a {
            color: #2196F3;
            text-decoration: none;
        }
        
        .welcome-card {
            background: linear-gradient(135deg, #2196F3 0%, #1976D2 100%);
            color: white;
            padding: 40px;
            border-radius: 8px;
            margin-bottom: 30px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        }
        
        .welcome-card h1 {
            font-size: 28px;
            margin-bottom: 15px;
        }
        
        .welcome-card p {
            font-size: 16px;
            opacity: 0.9;
        }
        
        .stats-row {
            display: flex;
            gap: 20px;
            margin-bottom: 30px;
        }
        
        .stat-card {
            background-color: white;
            padding: 25px;
            border-radius: 8px;
            flex: 1;
            text-align: center;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            transition: transform 0.3s;
        }
        
        .stat-card:hover {
            transform: translateY(-5px);
        }
        
        .stat-icon {
            font-size: 48px;
            margin-bottom: 10px;
        }
        
        .stat-number {
            font-size: 32px;
            font-weight: bold;
            margin-bottom: 5px;
        }
        
        .stat-label {
            color: #666;
            font-size: 14px;
        }
        
        .stat-user .stat-number { color: #2196F3; }
        .stat-house .stat-number { color: #4CAF50; }
        .stat-order .stat-number { color: #ff9800; }
        .stat-pending .stat-number { color: #f44336; }
        
        .quick-actions {
            background-color: white;
            border-radius: 8px;
            padding: 20px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .quick-actions h3 {
            margin-bottom: 20px;
            color: #333;
            border-left: 4px solid #2196F3;
            padding-left: 15px;
        }
        
        .action-buttons {
            display: flex;
            gap: 15px;
            flex-wrap: wrap;
        }
        
        .action-btn {
            background-color: #f5f5f5;
            padding: 15px 25px;
            border-radius: 8px;
            text-decoration: none;
            color: #333;
            transition: all 0.3s;
            text-align: center;
            min-width: 120px;
        }
        
        .action-btn:hover {
            background-color: #2196F3;
            color: white;
            transform: translateY(-3px);
        }
        
        .action-btn .icon {
            font-size: 24px;
            display: block;
            margin-bottom: 8px;
        }
        
        .footer {
            background-color: #333;
            color: white;
            text-align: center;
            padding: 20px;
            margin-top: 40px;
        }
        
        .clearfix::after {
            content: "";
            clear: both;
            display: table;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="container clearfix">
            <div class="logo">👑 租房系统管理后台 <span>Administrator</span></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}/admin/index.jsp" class="active">首页</a>
                <a href="${pageContext.request.contextPath}/admin/user/list">用户管理</a>
                <a href="${pageContext.request.contextPath}/admin/house/list">房源审核</a>
                <a href="${pageContext.request.contextPath}/admin/order/list">订单管理</a>
            </div>
        </div>
    </div>
    
    <div class="container">
        <div class="breadcrumb">
            <a href="${pageContext.request.contextPath}/admin/index.jsp">首页</a> &gt;
            <span>控制台</span>
        </div>
        
        <div class="welcome-card">
            <h1>欢迎回来，<%= loginUser.getRealName() %>！</h1>
            <p>今天是 <%= new java.text.SimpleDateFormat("yyyy年MM月dd日 EEEE").format(new java.util.Date()) %></p>
            <p style="margin-top: 10px;">您可以通过下方面板管理系统数据</p>
        </div>
        
        <div class="stats-row" id="statsRow">
            <div class="stat-card stat-user">
                <div class="stat-icon">👥</div>
                <div class="stat-number" id="userCount">-</div>
                <div class="stat-label">注册用户</div>
            </div>
            <div class="stat-card stat-house">
                <div class="stat-icon">🏠</div>
                <div class="stat-number" id="houseCount">-</div>
                <div class="stat-label">房源总数</div>
            </div>
            <div class="stat-card stat-order">
                <div class="stat-icon">📦</div>
                <div class="stat-number" id="orderCount">-</div>
                <div class="stat-label">订单总数</div>
            </div>
            <div class="stat-card stat-pending">
                <div class="stat-icon">⏳</div>
                <div class="stat-number" id="pendingCount">-</div>
                <div class="stat-label">待审核房源</div>
            </div>
        </div>
        
        <div class="quick-actions">
            <h3>快捷操作</h3>
            <div class="action-buttons">
                <a href="${pageContext.request.contextPath}/admin/user/list" class="action-btn">
                    <span class="icon">👤</span>
                    用户管理
                </a>
                <a href="${pageContext.request.contextPath}/admin/house/list" class="action-btn">
                    <span class="icon">🏠</span>
                    房源审核
                </a>
                <a href="${pageContext.request.contextPath}/admin/order/list" class="action-btn">
                    <span class="icon">📦</span>
                    订单管理
                </a>
            </div>
        </div>
    </div>
    
    <div class="footer">
        <p>© 2026 租房系统 | 管理员后台 | 让租房更简单</p>
    </div>
    
    <script>
        // 加载统计数据
        function loadStats() {
            fetch('${pageContext.request.contextPath}/admin/statistics')
                .then(response => response.json())
                .then(data => {
                    document.getElementById('userCount').innerText = data.userCount || 0;
                    document.getElementById('houseCount').innerText = data.houseCount || 0;
                    document.getElementById('orderCount').innerText = data.orderCount || 0;
                    document.getElementById('pendingCount').innerText = data.pendingCount || 0;
                })
                .catch(err => {
                    console.log('加载统计数据失败，使用默认值');
                    document.getElementById('userCount').innerText = '-';
                    document.getElementById('houseCount').innerText = '-';
                    document.getElementById('orderCount').innerText = '-';
                    document.getElementById('pendingCount').innerText = '-';
                });
        }
        
        loadStats();
    </script>
</body>
</html>