import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';

// 定义仪表盘统计数据接口
export interface DashboardStats {
  totalProjects: number;
  activeProjects: number;
  completedProjects: number;
  totalDesigners: number;
  totalCustomers: number;
  totalRevenue: number;
  projectTrend: { name: string; value: number }[];
  revenueData: { name: string; value: number }[];
}

@Injectable({
  providedIn: 'root'
})
export class AdminDashboardService {
  constructor(private http: HttpClient) {}

  // 获取仪表盘统计数据
  getDashboardStats(): Observable<DashboardStats> {
    // 在实际应用中，这里会调用后端API
    // return this.http.get<DashboardStats>('/api/admin/dashboard/stats')
    //   .pipe(map(response => response));

    // 模拟API响应
    return of({
      totalProjects: 128,
      activeProjects: 86,
      completedProjects: 42,
      totalDesigners: 24,
      totalCustomers: 356,
      totalRevenue: 1258000,
      projectTrend: [
        { name: '1月', value: 18 },
        { name: '2月', value: 25 },
        { name: '3月', value: 32 },
        { name: '4月', value: 28 },
        { name: '5月', value: 42 },
        { name: '6月', value: 38 }
      ],
      revenueData: [
        { name: '第一季度', value: 350000 },
        { name: '第二季度', value: 420000 },
        { name: '第三季度', value: 488000 }
      ]
    });
  }

  // 获取最近活动记录
  getRecentActivities(): Observable<any[]> {
    // 模拟数据
    return of([
      {
        id: '1',
        user: '系统',
        action: '创建了新项目',
        target: '现代简约风格三居室设计',
        targetType: 'project',
        time: '今天 10:30'
      },
      {
        id: '2',
        user: '张设计师',
        action: '完成了任务',
        target: '设计初稿',
        targetType: 'task',
        time: '今天 09:15'
      },
      {
        id: '3',
        user: '客服小李',
        action: '新增了客户',
        target: '王先生',
        targetType: 'customer',
        time: '昨天 16:45'
      },
      {
        id: '4',
        user: '系统',
        action: '完成了项目',
        target: '北欧风格两居室设计',
        targetType: 'project',
        time: '昨天 15:30'
      }
    ]);
  }

  // 获取项目状态分布
  getProjectStatusDistribution(): Observable<any[]> {
    // 模拟数据
    return of([
      { name: '进行中', value: 86, color: '#165DFF' },
      { name: '已完成', value: 42, color: '#00B42A' },
      { name: '已暂停', value: 15, color: '#FF7D00' },
      { name: '已延期', value: 5, color: '#F53F3F' }
    ]);
  }

  // 获取设计师工作量统计
  getDesignerWorkloadStats(): Observable<any[]> {
    // 模拟数据
    return of([
      { name: '张设计师', completed: 18, inProgress: 8 },
      { name: '李设计师', completed: 15, inProgress: 6 },
      { name: '王设计师', completed: 12, inProgress: 5 },
      { name: '赵设计师', completed: 10, inProgress: 4 },
      { name: '陈设计师', completed: 9, inProgress: 3 }
    ]);
  }
}