<header class="dashboard-header">
  <h1>设计组长工作台</h1>
  <!-- 核心数据指标卡片 -->
  <div class="dashboard-metrics">
    <div class="metric-card" (click)="filterByStatus('overdue')">
      <div class="metric-icon warning">⚠️</div>
      <div class="metric-content">
        <div class="metric-count">{{ overdueProjects.length }}</div>
        <div class="metric-label">已延期项目</div>
      </div>
    </div>
    <div class="metric-card" (click)="filterByStatus('dueSoon')">
      <div class="metric-icon info">⏳</div>
      <div class="metric-content">
        <div class="metric-count">{{ dueSoonProjects.length }}</div>
        <div class="metric-label">临期项目(3天内)</div>
      </div>
    </div>
    <div class="metric-card" (click)="filterByStatus('pendingApproval')">
      <div class="metric-icon info">📋</div>
      <div class="metric-content">
        <div class="metric-count">{{ pendingApprovalProjects.length }}</div>
        <div class="metric-label">待组长确认项目</div>
      </div>
    </div>
    <div class="metric-card" (click)="filterByStatus('pendingAssignment')">
      <div class="metric-icon primary">🎯</div>
      <div class="metric-content">
        <div class="metric-count">{{ pendingAssignmentProjects.length }}</div>
        <div class="metric-label">待分配方案项目</div>
      </div>
    </div>
  </div>
</header>

<main class="dashboard-main">
  <!-- 项目监控大盘 -->
  <section class="monitoring-section">
    <div class="section-header">
      <h2>项目监控大盘</h2>
      <div class="section-filters">
        <select (change)="filterProjects($event)" class="custom-select">
          <option value="all">全部项目</option>
          <option value="soft">软装项目</option>
          <option value="hard">硬装项目</option>
        </select>
        <select (change)="filterByUrgency($event)" class="custom-select">
          <option value="all">全部紧急程度</option>
          <option value="high">高</option>
          <option value="medium">中</option>
          <option value="low">低</option>
        </select>
        <select (change)="onStatusChange($event)" class="custom-select">
          <option value="all">全部状态</option>
          <option value="progress">进行中</option>
          <option value="completed">已完成</option>
          <option value="overdue">已延期</option>
          <option value="dueSoon">临期(3天内)</option>
          <option value="pendingApproval">待确认</option>
          <option value="pendingAssignment">待分配</option>
        </select>
        <select (change)="onDesignerChange($event)" class="custom-select">
          <option value="all">全部设计师</option>
          @for (d of designers; track d) {
            <option [value]="d">{{ d }}</option>
          }
        </select>
        <select (change)="onMemberTypeChange($event)" class="custom-select">
          <option value="all">全部会员</option>
          <option value="vip">VIP会员</option>
          <option value="normal">普通会员</option>
        </select>
        <!-- 支持数百项目的下拉筛选 -->
        <select [(ngModel)]="selectedProjectId" (change)="selectProject()" class="custom-select project-selector">
          <option value="">选择项目</option>
          @for (project of projects; track project.id) {
            <option [value]="project.id">{{ project.name }}</option>
          }
        </select>
        <!-- 新增：时间窗快捷筛选按钮组 -->
        <div class="time-window-buttons">
          <button [class.active]="selectedTimeWindow === 'all'" (click)="filterByTimeWindow('all')">全部</button>
          <button [class.active]="selectedTimeWindow === 'today'" (click)="filterByTimeWindow('today')">今天到期</button>
          <button [class.active]="selectedTimeWindow === 'threeDays'" (click)="filterByTimeWindow('threeDays')">3天内</button>
          <button [class.active]="selectedTimeWindow === 'sevenDays'" (click)="filterByTimeWindow('sevenDays')">7天内</button>
        </div>
      </div>
    </div>
    
    <!-- 项目看板 - 横向展开10个项目阶段 -->
    <div class="project-kanban">
      <!-- 新增：公共横向滚动容器，保证表头与表体同步滚动 -->
      <div class="kanban-scroll">
        <!-- 阶段标题 -->
        <div class="kanban-header">
          @for (core of corePhases; track core.id) {
            <div class="kanban-column-header">
              <h3>{{ core.name }}</h3>
              <span class="stage-count">{{ getProjectCountByCorePhase(core.id) }}</span>
            </div>
          }
        </div>
        <!-- 项目卡片 -->
        <div class="kanban-body">
          @for (core of corePhases; track core.id) {
            <div class="kanban-column">
              @for (project of getProjectsByCorePhase(core.id); track project.id) {
                <div class="project-card" 
                     (click)="viewProjectDetails(project.id)"
                     [class.overdue]="project.isOverdue" 
                     [class.high-urgency]="project.urgency === 'high'"
                     [class.due-soon]="project.dueSoon && !project.isOverdue">
                  <div class="project-card-header">
                    <h4 [routerLink]="['/team-leader/project-review', project.id]" (click)="$event.stopPropagation()">{{ project.name }}</h4>
                    <div class="right-badges">
                      <span class="member-badge" [class.vip]="project.memberType === 'vip'">{{ project.memberType === 'vip' ? 'VIP' : '普通' }}</span>
                      <span class="project-urgency" [class]="'urgency-' + project.urgency">{{ getUrgencyLabel(project.urgency) }}</span>
                    </div>
                  </div>
                  <div class="project-card-content">
                    <p>负责人: {{ project.designerName || '未分配' }}</p>
                    <p class="deadline">{{ project.isOverdue ? '超期' + project.overdueDays + '天' : (project.dueSoon ? '临期: ' + (project.expectedEndDate | date:'MM-dd') : '截止: ' + (project.expectedEndDate | date:'MM-dd')) }}</p>
                  </div>
                  <div class="project-card-footer">
                    <button (click)="viewProjectDetails(project.id); $event.stopPropagation()" class="btn-view">查看详情</button>
                    @if (project.currentStage === 'pendingAssignment') {
                      <button (click)="quickAssignProject(project.id); $event.stopPropagation()" class="btn-assign">分配</button>
                    }
                    <!-- 新增：质量评审快捷操作 -->
                    @if (project.currentStage === 'review' || project.currentStage === 'delivery') {
                      <div class="inline-actions">
                        <button class="btn-secondary" (click)="$event.stopPropagation(); reviewProjectQuality(project.id, 'excellent')">评为优秀</button>
                        <button class="btn-secondary" (click)="$event.stopPropagation(); reviewProjectQuality(project.id, 'qualified')">评为合格</button>
                        <button class="btn-secondary" (click)="$event.stopPropagation(); reviewProjectQuality(project.id, 'unqualified')">评为不合格</button>
                      </div>
                    }
                  </div>
                </div>
              }
              @if (getProjectsByCorePhase(core.id).length === 0) {
                <div class="empty-column">
                  <span class="empty-icon">📦</span>
                  <p>暂无项目</p>
                </div>
              }
            </div>
          }
        </div>
      </div>
    </div>
  </section>

  <!-- 待办任务优先级排序 -->
  <section class="todo-section">
    <div class="section-header">
      <h2>待办任务</h2>
      <!-- 新增：绩效与负载入口 -->
      <div class="section-actions">
        <button class="btn-link" (click)="viewPerformanceDetails()">查看绩效预警</button>
        <button class="btn-link" (click)="navigateToWorkloadCalendar()">打开负载日历</button>
      </div>
    </div>
    
    <div class="todo-list">
      @for (task of todoTasks; track task.id) {
        <div class="todo-item" [class.priority-high]="task.priority === 'high'" [class.priority-medium]="task.priority === 'medium'" [class.priority-low]="task.priority === 'low'">
          <div class="todo-header">
            <h3>{{ task.title }}</h3>
            <span class="task-priority">{{ getPriorityLabel(task.priority) }}</span>
          </div>
          <div class="todo-info">
            <p>{{ task.description }}</p>
            <p class="task-deadline">截止时间: {{ task.deadline | date:'yyyy-MM-dd HH:mm' }}</p>
          </div>
          <div class="todo-actions">
            <button (click)="navigateToTask(task)" class="btn-handle">处理任务</button>
          </div>
        </div>
      }
    </div>
  </section>

  <!-- 超期项目提醒 -->
  @if (showAlert && overdueProjects.length > 0) {
    <div class="overdue-alert">
      <div class="alert-content">
        <h3>⚠️ 超期项目提醒</h3>
        <ul>
          @for (project of overdueProjects.slice(0, 3); track $index) {
            <li>
              {{ project.name }} ({{ project.designerName }} 负责) - 超期{{ project.overdueDays }}天
            </li>
          }
        </ul>
        <div class="alert-actions">
          <button (click)="viewAllOverdueProjects()" class="btn-view-all">查看全部</button>
          <button (click)="closeAlert()" class="btn-close">关闭</button>
        </div>
      </div>
    </div>
  }
</main>