/**
 * 检测分割记录 / 媒体库 列表模拟数据
 *
 * 启用方式：在 bridge-disease-frontend-main 目录创建 `.env.local`（或 `.env.development`）写入：
 *   VITE_USE_LIST_MOCK=true
 * 然后重启 `npm run dev`。`resourceStore` 将走本地分页，不再请求后端列表接口。
 *
 * 预览图/结果图仍请求 `request.defaults.baseURL + '/file/' + path`，若无对应文件会显示裂图，属预期。
 */

function iso(d) {
  return new Date(d).toISOString()
}

/** 全量检测分割记录（分页前） */
export const MOCK_DETECTIONS = [
  {
    detection_id: 10001,
    model_id: 201,
    model_name: 'BridgeSeg-YOLOv8-L',
    media_id: 301,
    media_name: '主跨箱梁底板_S12.jpg',
    status: 'COMPLETED',
    disease_severity_score: 0.38,
    disease_grade: 'MODERATE',
    result_path: 'results/2026/04/r10001_mask.png',
    media_type: 'jpeg',
    updated_at: iso('2026-04-12T09:15:00'),
    owner_id: 2,
    owner_username: '巡检员A',
    disease_count: 9,
    disease_perimeter: 1620,
    disease_area: 48200,
    shape_complexity: 0.41,
    texture_roughness: 165,
    crack_width: 5.1,
    avg_hue: 108,
    detection_duration: 2280,
    avg_frame_detection_duration: 38,
  },
  {
    detection_id: 10002,
    model_id: 202,
    model_name: 'CrackNet-Res50',
    media_name: 'Pier3_立面_北.mp4',
    media_id: 302,
    status: 'COMPLETED',
    disease_severity_score: 0.62,
    disease_grade: 'SEVERE',
    result_path: null,
    media_type: 'mp4',
    updated_at: iso('2026-04-11T16:40:22'),
    owner_id: 2,
    owner_username: '巡检员A',
    disease_count: 21,
    disease_perimeter: 3100,
    disease_area: 91000,
    shape_complexity: 0.55,
    texture_roughness: 240,
    crack_width: 9.4,
    avg_hue: 95,
    detection_duration: 8120,
    avg_frame_detection_duration: 55,
  },
  {
    detection_id: 10003,
    model_id: 201,
    model_name: 'BridgeSeg-YOLOv8-L',
    media_name: '伸缩缝_J03.png',
    media_id: 303,
    status: 'IN_PROGRESS',
    disease_severity_score: 0.22,
    disease_grade: 'MILD',
    result_path: null,
    media_type: 'png',
    updated_at: iso('2026-04-11T11:05:00'),
    owner_id: 3,
    owner_username: '结构所_李工',
    disease_count: 3,
    disease_perimeter: 420,
    disease_area: 8900,
    shape_complexity: 0.19,
    texture_roughness: 88,
    crack_width: 2.0,
    avg_hue: 120,
    detection_duration: null,
    avg_frame_detection_duration: null,
  },
  {
    detection_id: 10004,
    model_id: 203,
    model_name: 'SegFormer-BridgeTiny',
    media_name: '桥面铺装_DRONE_01.jpg',
    media_id: 304,
    status: 'PENDING',
    disease_severity_score: null,
    disease_grade: null,
    result_path: null,
    media_type: 'jpeg',
    updated_at: iso('2026-04-10T08:00:00'),
    owner_id: 3,
    owner_username: '结构所_李工',
    disease_count: null,
    disease_perimeter: null,
    disease_area: null,
    shape_complexity: null,
    texture_roughness: null,
    crack_width: null,
    avg_hue: null,
    detection_duration: null,
    avg_frame_detection_duration: null,
  },
  {
    detection_id: 10005,
    model_id: 202,
    model_name: 'CrackNet-Res50',
    media_name: '索塔锚室_内窥.jpg',
    media_id: 305,
    status: 'FAILED',
    disease_severity_score: null,
    disease_grade: null,
    result_path: null,
    media_type: 'jpeg',
    updated_at: iso('2026-04-09T19:22:11'),
    owner_id: 4,
    owner_username: '养护中心',
    disease_count: 0,
    disease_perimeter: 0,
    disease_area: 0,
    shape_complexity: 0,
    texture_roughness: 0,
    crack_width: 0,
    avg_hue: 0,
    detection_duration: 120,
    avg_frame_detection_duration: 0,
  },
  {
    detection_id: 10006,
    model_id: 201,
    model_name: 'BridgeSeg-YOLOv8-L',
    media_name: '钢箱梁_U肋焊缝区.png',
    media_id: 306,
    status: 'COMPLETED',
    disease_severity_score: 0.71,
    disease_grade: 'CRITICAL',
    result_path: 'results/2026/04/r10006_mask.png',
    media_type: 'png',
    updated_at: iso('2026-04-09T10:00:00'),
    owner_id: 4,
    owner_username: '养护中心',
    disease_count: 34,
    disease_perimeter: 5200,
    disease_area: 128000,
    shape_complexity: 0.68,
    texture_roughness: 310,
    crack_width: 12.8,
    avg_hue: 88,
    detection_duration: 3100,
    avg_frame_detection_duration: 48,
  },
  {
    detection_id: 10007,
    model_id: 204,
    model_name: 'DeepLabV3-Deck',
    media_name: '引桥T梁_腹板裂缝.jpg',
    media_id: 307,
    status: 'COMPLETED',
    disease_severity_score: 0.29,
    disease_grade: 'MILD',
    result_path: null,
    media_type: 'jpeg',
    updated_at: iso('2026-04-08T14:30:00'),
    owner_id: 2,
    owner_username: '巡检员A',
    disease_count: 5,
    disease_perimeter: 890,
    disease_area: 21000,
    shape_complexity: 0.28,
    texture_roughness: 120,
    crack_width: 3.2,
    avg_hue: 102,
    detection_duration: 1890,
    avg_frame_detection_duration: 35,
  },
  {
    detection_id: 10008,
    model_id: 202,
    model_name: 'CrackNet-Res50',
    media_name: '夜间补光_护栏根部.mp4',
    media_id: 308,
    status: 'IN_PROGRESS',
    disease_severity_score: 0.45,
    disease_grade: 'MODERATE',
    result_path: null,
    media_type: 'mp4',
    updated_at: iso('2026-04-08T06:12:00'),
    owner_id: 5,
    owner_username: '夜间班组',
    disease_count: 11,
    disease_perimeter: 2100,
    disease_area: 56000,
    shape_complexity: 0.44,
    texture_roughness: 200,
    crack_width: 6.0,
    avg_hue: 70,
    detection_duration: null,
    avg_frame_detection_duration: null,
  },
  {
    detection_id: 10009,
    model_id: 201,
    model_name: 'BridgeSeg-YOLOv8-L',
    media_name: '支座垫石_俯视.jpg',
    media_id: 309,
    status: 'COMPLETED',
    disease_severity_score: 0.51,
    disease_grade: 'SEVERE',
    result_path: null,
    media_type: 'jpeg',
    updated_at: iso('2026-04-07T13:45:00'),
    owner_id: 5,
    owner_username: '夜间班组',
    disease_count: 16,
    disease_perimeter: 2680,
    disease_area: 72000,
    shape_complexity: 0.5,
    texture_roughness: 255,
    crack_width: 8.1,
    avg_hue: 99,
    detection_duration: 2650,
    avg_frame_detection_duration: 41,
  },
  {
    detection_id: 10010,
    model_id: 203,
    model_name: 'SegFormer-BridgeTiny',
    media_name: '人行道板_渗水.jpg',
    media_id: 310,
    status: 'PENDING',
    disease_severity_score: null,
    disease_grade: null,
    result_path: null,
    media_type: 'jpeg',
    updated_at: iso('2026-04-06T09:00:00'),
    owner_id: 3,
    owner_username: '结构所_李工',
    disease_count: null,
    disease_perimeter: null,
    disease_area: null,
    shape_complexity: null,
    texture_roughness: null,
    crack_width: null,
    avg_hue: null,
    detection_duration: null,
    avg_frame_detection_duration: null,
  },
]

/** 全量媒体库（分页前） */
export const MOCK_MEDIAS = [
  {
    media_id: 50001,
    media_name: '主跨底板_巡检S1.jpg',
    description: '主跨区段箱梁底板高清照，含排水孔周边',
    file_type: 'jpeg',
    media_path: 'medias/2026/04/m50001.jpg',
    updated_at: iso('2026-04-12T10:00:00'),
    owner_id: 2,
    owner_username: '巡检员A',
  },
  {
    media_id: 50002,
    media_name: '墩顶航拍_东向.mp4',
    description: '4K 无人机东向推进，覆盖墩顶与支座',
    file_type: 'mp4',
    media_path: 'medias/2026/04/m50002.mp4',
    updated_at: iso('2026-04-12T09:30:00'),
    owner_id: 2,
    owner_username: '巡检员A',
  },
  {
    media_id: 50003,
    media_name: '伸缩缝_J03.png',
    description: '伸缩缝钢纤维混凝土局部剥落',
    file_type: 'png',
    media_path: 'medias/2026/04/m50003.png',
    updated_at: iso('2026-04-11T15:20:00'),
    owner_id: 3,
    owner_username: '结构所_李工',
  },
  {
    media_id: 50004,
    media_name: '索塔锚室_内窥.jpg',
    description: '内窥镜进入锚室，弱光增强',
    file_type: 'jpeg',
    media_path: 'medias/2026/04/m50004.jpg',
    updated_at: iso('2026-04-11T12:00:00'),
    owner_id: 3,
    owner_username: '结构所_李工',
  },
  {
    media_id: 50005,
    media_name: '桥面铺装_DRONE_01.jpg',
    description: '正射拼图切片之一',
    file_type: 'jpeg',
    media_path: 'medias/2026/04/m50005.jpg',
    updated_at: iso('2026-04-10T18:00:00'),
    owner_id: 4,
    owner_username: '养护中心',
  },
  {
    media_id: 50006,
    media_name: '护栏根部_渗水.jpg',
    description: '护栏与桥面交接长期渗水痕迹',
    file_type: 'jpg',
    media_path: 'medias/2026/04/m50006.jpg',
    updated_at: iso('2026-04-10T11:11:00'),
    owner_id: 4,
    owner_username: '养护中心',
  },
  {
    media_id: 50007,
    media_name: 'U肋焊缝_磁粉复检.jpg',
    description: '焊缝区磁粉复检后留档',
    file_type: 'jpeg',
    media_path: 'medias/2026/04/m50007.jpg',
    updated_at: iso('2026-04-09T16:45:00'),
    owner_id: 5,
    owner_username: '夜间班组',
  },
  {
    media_id: 50008,
    media_name: '引桥T梁_腹板.mp4',
    description: '车载云台沿引桥慢速采集',
    file_type: 'mp4',
    media_path: 'medias/2026/04/m50008.mp4',
    updated_at: iso('2026-04-09T08:00:00'),
    owner_id: 2,
    owner_username: '巡检员A',
  },
  {
    media_id: 50009,
    media_name: '支座垫石_俯视.jpg',
    description: '垫石开裂与脱空疑似区域',
    file_type: 'jpeg',
    media_path: 'medias/2026/04/m50009.jpg',
    updated_at: iso('2026-04-08T14:00:00'),
    owner_id: 3,
    owner_username: '结构所_李工',
  },
  {
    media_id: 50010,
    media_name: '人行道板_积水.jpg',
    description: '雨后积水反光，用于铺装隐患对比',
    file_type: 'jpeg',
    media_path: 'medias/2026/04/m50010.jpg',
    updated_at: iso('2026-04-07T17:30:00'),
    owner_id: 4,
    owner_username: '养护中心',
  },
  {
    media_id: 50011,
    media_name: '夜间补光_护栏.mp4',
    description: '补光灯固定机位 30s',
    file_type: 'mp4',
    media_path: 'medias/2026/04/m50011.mp4',
    updated_at: iso('2026-04-07T03:15:00'),
    owner_id: 5,
    owner_username: '夜间班组',
  },
  {
    media_id: 50012,
    media_name: '检修道栏杆_锈蚀.png',
    description: '栏杆立柱锈蚀等级标注样张',
    file_type: 'png',
    media_path: 'medias/2026/04/m50012.png',
    updated_at: iso('2026-04-06T09:45:00'),
    owner_id: 2,
    owner_username: '巡检员A',
  },
]

export function paginateMock(list, page, perPage) {
  const p = Math.max(1, Number(page) || 1)
  const size = Math.max(1, Number(perPage) || 10)
  const start = (p - 1) * size
  return {
    items: list.slice(start, start + size),
    total: list.length,
  }
}

export function getMockDetectionsPage(page, perPage) {
  const { items, total } = paginateMock(MOCK_DETECTIONS, page, perPage)
  return { detections: items, total }
}

export function getMockMediasPage(page, perPage) {
  const { items, total } = paginateMock(MOCK_MEDIAS, page, perPage)
  return { medias: items, total }
}
