/**
 * 机构端统一 mock 数据源
 * 
 * 开关说明：
 *   USE_MOCK = true  → 各页面使用此文件数据，不请求 Supabase
 *   USE_MOCK = false → 各页面走原有 Supabase 请求逻辑
 * 
 * 联动锚点（改动此处会自动同步各页面）：
 *   待接单订单数      = PENDING_SHIPMENT_COUNT  = 3
 *   退款中订单数      = REFUND_COUNT            = 2
 *   低库存商品数      = LOW_STOCK_COUNT         = 3
 *   已售罄商品数      = OUT_OF_STOCK_COUNT      = 2
 *   未回复评价数      = PENDING_REVIEW_COUNT    = 4
 */

// ─── Mock 总开关 ───────────────────────────────────────────────
export const USE_MOCK = true

// ─── 稳定 mock merchantId（无登录时使用） ──────────────────────
export const MOCK_MERCHANT_ID = 'mock-merchant-0001-0000-000000000001'

// ─── 联动锚点常量 ───────────────────────────────────────────────
export const PENDING_SHIPMENT_COUNT = 3
export const REFUND_COUNT = 2
export const LOW_STOCK_COUNT = 3
export const OUT_OF_STOCK_COUNT = 2
export const PENDING_REVIEW_COUNT = 4


// ════════════════════════════════════════════════════════════
// 一、店铺信息
// ════════════════════════════════════════════════════════════
export type MockShopInfoType = {
	id: string
	merchant_id: string
	shop_name: string
	shop_logo: string
	shop_banner: string
	description: string
	contact_name: string
	contact_phone: string
	rating_avg: number
	total_sales: number
	status: number
}

export const MOCK_SHOP_INFO: MockShopInfoType = {
	id: 'mock-shop-0001',
	merchant_id: MOCK_MERCHANT_ID,
	shop_name: '骅锋医养综合服务中心',
	shop_logo: '/static/images/default-shop.png',
	shop_banner: '/static/images/default-banner.png',
	description: '专注居家养老、慢病管理与康复护理一体化服务',
	contact_name: '李医师',
	contact_phone: '020-88888888',
	rating_avg: 4.8,
	total_sales: 386,
	status: 1
}

export const MOCK_TODAY_STATS = {
	orders: 7,
	sales: 2340.00,
	visitors: 42,
	conversion: 17
}

export const MOCK_PENDING_COUNTS = {
	pending_shipment: PENDING_SHIPMENT_COUNT,
	refund_requests: REFUND_COUNT,
	low_stock: LOW_STOCK_COUNT,
	pending_reviews: PENDING_REVIEW_COUNT
}


// ════════════════════════════════════════════════════════════
// 二、订单 mock 数据
// ════════════════════════════════════════════════════════════
export type MockOrderItemType = {
	id: string
	order_id: string
	product_id: string
	sku_id: string
	product_name: string
	sku_name: string
	price: number
	quantity: number
	image_url: string
	sku_snapshot: string
}

export type MockOrderType = {
	id: string
	order_no: string
	user_id: string
	merchant_id: string
	order_status: number
	total_amount: number
	product_amount: number
	shipping_fee: number
	paid_amount: number
	shipping_address: string
	remark: string
	created_at: string
	updated_at: string
	items: MockOrderItemType[]
}

// 服务订单 mock（status: 2=待接单/待上门, 3=服务中, 4=已完成）
// 其中 待接单=3条, 服务中=4条, 已完成=8条 → tab计数对齐
export const MOCK_ORDERS: MockOrderType[] = [
	// ── 待接单 3 条 ──────────────────────────────────────────
	{
		id: 'order-001', order_no: 'SV2026041300001',
		user_id: 'user-001', merchant_id: MOCK_MERCHANT_ID,
		order_status: 2, total_amount: 380.00, product_amount: 380.00,
		shipping_fee: 0, paid_amount: 380.00,
		shipping_address: '广州市天河区天河路123号 李奶奶',
		remark: '老人行动不便，请护士上午到访',
		created_at: '2026-04-13T08:15:00+08:00', updated_at: '2026-04-13T08:15:00+08:00',
		items: [{
			id: 'item-001-1', order_id: 'order-001', product_id: 'prod-001',
			sku_id: '', product_name: '居家上门护理（半日）', sku_name: '标准护理套餐',
			price: 380.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-002', order_no: 'SV2026041300002',
		user_id: 'user-002', merchant_id: MOCK_MERCHANT_ID,
		order_status: 2, total_amount: 260.00, product_amount: 260.00,
		shipping_fee: 0, paid_amount: 260.00,
		shipping_address: '广州市越秀区东风东路456号 张爷爷',
		remark: '高血压患者，需携带血压计',
		created_at: '2026-04-13T09:30:00+08:00', updated_at: '2026-04-13T09:30:00+08:00',
		items: [
			{
				id: 'item-002-1', order_id: 'order-002', product_id: 'prod-002',
				sku_id: '', product_name: '血压血糖监测服务', sku_name: '',
				price: 180.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
			},
			{
				id: 'item-002-2', order_id: 'order-002', product_id: 'prod-003',
				sku_id: '', product_name: '慢病随访服务', sku_name: '',
				price: 80.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
			}
		]
	},
	{
		id: 'order-003', order_no: 'SV2026041300003',
		user_id: 'user-003', merchant_id: MOCK_MERCHANT_ID,
		order_status: 2, total_amount: 520.00, product_amount: 520.00,
		shipping_fee: 0, paid_amount: 520.00,
		shipping_address: '广州市海珠区工业大道789号 王阿姨',
		remark: '术后第7天，需换药处理',
		created_at: '2026-04-13T10:00:00+08:00', updated_at: '2026-04-13T10:00:00+08:00',
		items: [{
			id: 'item-003-1', order_id: 'order-003', product_id: 'prod-004',
			sku_id: '', product_name: '术后伤口护理', sku_name: '标准换药套餐',
			price: 260.00, quantity: 2, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},

	// ── 服务中 4 条 ──────────────────────────────────────────
	{
		id: 'order-004', order_no: 'SV2026041200004',
		user_id: 'user-004', merchant_id: MOCK_MERCHANT_ID,
		order_status: 3, total_amount: 1200.00, product_amount: 1200.00,
		shipping_fee: 0, paid_amount: 1200.00,
		shipping_address: '广州市番禺区市桥街101号 陈老先生',
		remark: '每周三次康复训练',
		created_at: '2026-04-12T14:00:00+08:00', updated_at: '2026-04-12T14:30:00+08:00',
		items: [{
			id: 'item-004-1', order_id: 'order-004', product_id: 'prod-005',
			sku_id: '', product_name: '上门康复护理（月套餐）', sku_name: '基础康复12次',
			price: 1200.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-005', order_no: 'SV2026041200005',
		user_id: 'user-005', merchant_id: MOCK_MERCHANT_ID,
		order_status: 3, total_amount: 450.00, product_amount: 450.00,
		shipping_fee: 0, paid_amount: 450.00,
		shipping_address: '广州市白云区棠景街202号 刘奶奶',
		remark: '糖尿病足护理，注意消毒',
		created_at: '2026-04-12T09:00:00+08:00', updated_at: '2026-04-12T11:00:00+08:00',
		items: [
			{
				id: 'item-005-1', order_id: 'order-005', product_id: 'prod-006',
				sku_id: '', product_name: '糖尿病足专项护理', sku_name: '',
				price: 280.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
			},
			{
				id: 'item-005-2', order_id: 'order-005', product_id: 'prod-002',
				sku_id: '', product_name: '血压血糖监测服务', sku_name: '',
				price: 170.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
			}
		]
	},
	{
		id: 'order-006', order_no: 'SV2026041100006',
		user_id: 'user-006', merchant_id: MOCK_MERCHANT_ID,
		order_status: 3, total_amount: 680.00, product_amount: 680.00,
		shipping_fee: 0, paid_amount: 680.00,
		shipping_address: '广州市荔湾区荔湾路303号 赵大伯',
		remark: '卒中后遗症，肢体功能训练',
		created_at: '2026-04-11T10:30:00+08:00', updated_at: '2026-04-11T14:00:00+08:00',
		items: [{
			id: 'item-006-1', order_id: 'order-006', product_id: 'prod-005',
			sku_id: '', product_name: '上门康复护理（月套餐）', sku_name: '进阶康复8次',
			price: 680.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-007', order_no: 'SV2026041100007',
		user_id: 'user-007', merchant_id: MOCK_MERCHANT_ID,
		order_status: 3, total_amount: 320.00, product_amount: 320.00,
		shipping_fee: 0, paid_amount: 320.00,
		shipping_address: '广州市黄埔区科学城404号 孙阿姨',
		remark: '鼻饲护理，按时喂食',
		created_at: '2026-04-11T08:00:00+08:00', updated_at: '2026-04-11T08:00:00+08:00',
		items: [{
			id: 'item-007-1', order_id: 'order-007', product_id: 'prod-007',
			sku_id: '', product_name: '鼻饲营养护理', sku_name: '',
			price: 320.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},

	// ── 已完成 8 条 ──────────────────────────────────────────
	{
		id: 'order-008', order_no: 'SV2026041000008',
		user_id: 'user-001', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 180.00, product_amount: 180.00,
		shipping_fee: 0, paid_amount: 180.00,
		shipping_address: '广州市天河区天河路123号 李奶奶',
		remark: '', created_at: '2026-04-10T09:00:00+08:00', updated_at: '2026-04-10T12:00:00+08:00',
		items: [{
			id: 'item-008-1', order_id: 'order-008', product_id: 'prod-002',
			sku_id: '', product_name: '血压血糖监测服务', sku_name: '',
			price: 180.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-009', order_no: 'SV2026040900009',
		user_id: 'user-008', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 560.00, product_amount: 560.00,
		shipping_fee: 0, paid_amount: 560.00,
		shipping_address: '广州市增城区荔城街505号 郑爷爷',
		remark: '', created_at: '2026-04-09T10:00:00+08:00', updated_at: '2026-04-09T15:00:00+08:00',
		items: [{
			id: 'item-009-1', order_id: 'order-009', product_id: 'prod-008',
			sku_id: '', product_name: '术后营养指导（4次）', sku_name: '',
			price: 280.00, quantity: 2, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-010', order_no: 'SV2026040800010',
		user_id: 'user-009', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 260.00, product_amount: 260.00,
		shipping_fee: 0, paid_amount: 260.00,
		shipping_address: '广州市从化区街口街606号 吴阿姨',
		remark: '', created_at: '2026-04-08T14:00:00+08:00', updated_at: '2026-04-08T16:30:00+08:00',
		items: [{
			id: 'item-010-1', order_id: 'order-010', product_id: 'prod-003',
			sku_id: '', product_name: '慢病随访服务', sku_name: '',
			price: 130.00, quantity: 2, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-011', order_no: 'SV2026040700011',
		user_id: 'user-010', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 980.00, product_amount: 980.00,
		shipping_fee: 0, paid_amount: 980.00,
		shipping_address: '广州市南沙区南沙街707号 何老先生',
		remark: '', created_at: '2026-04-07T09:00:00+08:00', updated_at: '2026-04-07T17:00:00+08:00',
		items: [
			{
				id: 'item-011-1', order_id: 'order-011', product_id: 'prod-001',
				sku_id: '', product_name: '居家上门护理（半日）', sku_name: '',
				price: 380.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
			},
			{
				id: 'item-011-2', order_id: 'order-011', product_id: 'prod-008',
				sku_id: '', product_name: '术后营养指导（4次）', sku_name: '',
				price: 300.00, quantity: 2, image_url: '/static/images/default-product.png', sku_snapshot: ''
			}
		]
	},
	{
		id: 'order-012', order_no: 'SV2026040600012',
		user_id: 'user-002', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 430.00, product_amount: 430.00,
		shipping_fee: 0, paid_amount: 430.00,
		shipping_address: '广州市越秀区东风东路456号 张爷爷',
		remark: '', created_at: '2026-04-06T10:00:00+08:00', updated_at: '2026-04-06T12:30:00+08:00',
		items: [{
			id: 'item-012-1', order_id: 'order-012', product_id: 'prod-009',
			sku_id: '', product_name: '中医调理推拿（3次）', sku_name: '',
			price: 430.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-013', order_no: 'SV2026040500013',
		user_id: 'user-011', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 350.00, product_amount: 350.00,
		shipping_fee: 0, paid_amount: 350.00,
		shipping_address: '广州市花都区新华街808号 冯奶奶',
		remark: '', created_at: '2026-04-05T14:30:00+08:00', updated_at: '2026-04-05T16:00:00+08:00',
		items: [{
			id: 'item-013-1', order_id: 'order-013', product_id: 'prod-006',
			sku_id: '', product_name: '糖尿病足专项护理', sku_name: '',
			price: 350.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-014', order_no: 'SV2026040400014',
		user_id: 'user-012', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 480.00, product_amount: 480.00,
		shipping_fee: 0, paid_amount: 480.00,
		shipping_address: '广州市番禺区大石街909号 蒋大伯',
		remark: '', created_at: '2026-04-04T09:00:00+08:00', updated_at: '2026-04-04T14:00:00+08:00',
		items: [{
			id: 'item-014-1', order_id: 'order-014', product_id: 'prod-004',
			sku_id: '', product_name: '术后伤口护理', sku_name: '',
			price: 240.00, quantity: 2, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-015', order_no: 'SV2026040300015',
		user_id: 'user-003', merchant_id: MOCK_MERCHANT_ID,
		order_status: 4, total_amount: 680.00, product_amount: 680.00,
		shipping_fee: 0, paid_amount: 680.00,
		shipping_address: '广州市海珠区工业大道789号 王阿姨',
		remark: '', created_at: '2026-04-03T10:00:00+08:00', updated_at: '2026-04-03T15:30:00+08:00',
		items: [{
			id: 'item-015-1', order_id: 'order-015', product_id: 'prod-005',
			sku_id: '', product_name: '上门康复护理（月套餐）', sku_name: '',
			price: 680.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	}
]

// 售后订单 mock（status: 0=退款中, 6=退款完成）
// 退款中=2条, 退款完成=3条
export const MOCK_AFTERSALE_ORDERS: MockOrderType[] = [
	{
		id: 'order-ref-001', order_no: 'SV2026041300R01',
		user_id: 'user-004', merchant_id: MOCK_MERCHANT_ID,
		order_status: 0, total_amount: 380.00, product_amount: 380.00,
		shipping_fee: 0, paid_amount: 380.00,
		shipping_address: '广州市番禺区市桥街101号 陈老先生',
		remark: '家属临时有事，申请取消本次上门服务',
		created_at: '2026-04-13T07:00:00+08:00', updated_at: '2026-04-13T07:30:00+08:00',
		items: [{
			id: 'item-ref-001-1', order_id: 'order-ref-001', product_id: 'prod-001',
			sku_id: '', product_name: '居家上门护理（半日）', sku_name: '',
			price: 380.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-ref-002', order_no: 'SV2026041200R02',
		user_id: 'user-005', merchant_id: MOCK_MERCHANT_ID,
		order_status: 0, total_amount: 180.00, product_amount: 180.00,
		shipping_fee: 0, paid_amount: 180.00,
		shipping_address: '广州市白云区棠景街202号 刘奶奶',
		remark: '重复下单需退一单',
		created_at: '2026-04-12T16:00:00+08:00', updated_at: '2026-04-12T16:10:00+08:00',
		items: [{
			id: 'item-ref-002-1', order_id: 'order-ref-002', product_id: 'prod-002',
			sku_id: '', product_name: '血压血糖监测服务', sku_name: '',
			price: 180.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-ref-003', order_no: 'SV2026041000R03',
		user_id: 'user-008', merchant_id: MOCK_MERCHANT_ID,
		order_status: 6, total_amount: 260.00, product_amount: 260.00,
		shipping_fee: 0, paid_amount: 260.00,
		shipping_address: '广州市增城区荔城街505号 郑爷爷',
		remark: '服务已退款', created_at: '2026-04-10T10:00:00+08:00', updated_at: '2026-04-11T09:00:00+08:00',
		items: [{
			id: 'item-ref-003-1', order_id: 'order-ref-003', product_id: 'prod-003',
			sku_id: '', product_name: '慢病随访服务', sku_name: '',
			price: 130.00, quantity: 2, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-ref-004', order_no: 'SV2026040800R04',
		user_id: 'user-009', merchant_id: MOCK_MERCHANT_ID,
		order_status: 6, total_amount: 430.00, product_amount: 430.00,
		shipping_fee: 0, paid_amount: 430.00,
		shipping_address: '广州市从化区街口街606号 吴阿姨',
		remark: '', created_at: '2026-04-08T09:00:00+08:00', updated_at: '2026-04-09T10:00:00+08:00',
		items: [{
			id: 'item-ref-004-1', order_id: 'order-ref-004', product_id: 'prod-009',
			sku_id: '', product_name: '中医调理推拿（3次）', sku_name: '',
			price: 430.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	},
	{
		id: 'order-ref-005', order_no: 'SV2026040600R05',
		user_id: 'user-010', merchant_id: MOCK_MERCHANT_ID,
		order_status: 6, total_amount: 320.00, product_amount: 320.00,
		shipping_fee: 0, paid_amount: 320.00,
		shipping_address: '广州市南沙区南沙街707号 何老先生',
		remark: '', created_at: '2026-04-06T14:00:00+08:00', updated_at: '2026-04-07T09:00:00+08:00',
		items: [{
			id: 'item-ref-005-1', order_id: 'order-ref-005', product_id: 'prod-007',
			sku_id: '', product_name: '鼻饲营养护理', sku_name: '',
			price: 320.00, quantity: 1, image_url: '/static/images/default-product.png', sku_snapshot: ''
		}]
	}
]

// 最近5条订单（供 profile 使用，复用上面 MOCK_ORDERS 前5条数据结构）
export type MockProfileOrderType = {
	id: string
	order_no: string
	order_status: number
	total_amount: number
	created_at: string
	items: MockOrderItemType[]
}

export function getMockRecentOrders() : MockProfileOrderType[] {
	const result: MockProfileOrderType[] = []
	const src = MOCK_ORDERS
	const cnt = src.length < 5 ? src.length : 5
	for (let i = 0; i < cnt; i++) {
		result.push({
			id: src[i].id,
			order_no: src[i].order_no,
			order_status: src[i].order_status,
			total_amount: src[i].total_amount,
			created_at: src[i].created_at,
			items: src[i].items
		} as MockProfileOrderType)
	}
	return result
}

// 订单 tab 计数（由 MOCK_ORDERS 推导，不手写）
export function getMockOrderTabCounts() : { pending: number, inprogress: number, completed: number, total: number } {
	let pending = 0, inprogress = 0, completed = 0
	for (let i = 0; i < MOCK_ORDERS.length; i++) {
		const s = MOCK_ORDERS[i].order_status
		if (s === 2) pending++
		else if (s === 3) inprogress++
		else if (s === 4) completed++
	}
	return { pending, inprogress, completed, total: MOCK_ORDERS.length }
}

// 售后 tab 计数
export function getMockAftersaleTabCounts() : { refunding: number, refunded: number, total: number } {
	let refunding = 0, refunded = 0
	for (let i = 0; i < MOCK_AFTERSALE_ORDERS.length; i++) {
		const s = MOCK_AFTERSALE_ORDERS[i].order_status
		if (s === 0) refunding++
		else if (s === 6) refunded++
	}
	return { refunding, refunded, total: MOCK_AFTERSALE_ORDERS.length }
}


// ════════════════════════════════════════════════════════════
// 三、库存 mock 数据
// ════════════════════════════════════════════════════════════
export type MockInventoryProductType = {
	id: string
	name: string
	main_image_url: string
	total_stock: number
	warning_stock: number
}

// 12条，覆盖正常/低库存/售罄
// 低库存3条（stock<=warning_stock且>0），售罄2条（stock=0）
export const MOCK_INVENTORY_PRODUCTS: MockInventoryProductType[] = [
	{ id: 'prod-001', name: '居家上门护理（半日）', main_image_url: '/static/images/default-product.png', total_stock: 20, warning_stock: 5 },
	{ id: 'prod-002', name: '血压血糖监测服务', main_image_url: '/static/images/default-product.png', total_stock: 30, warning_stock: 8 },
	{ id: 'prod-003', name: '慢病随访服务', main_image_url: '/static/images/default-product.png', total_stock: 25, warning_stock: 5 },
	{ id: 'prod-004', name: '术后伤口护理', main_image_url: '/static/images/default-product.png', total_stock: 4, warning_stock: 5 },   // 低库存1
	{ id: 'prod-005', name: '上门康复护理（月套餐）', main_image_url: '/static/images/default-product.png', total_stock: 8, warning_stock: 10 }, // 低库存2
	{ id: 'prod-006', name: '糖尿病足专项护理', main_image_url: '/static/images/default-product.png', total_stock: 3, warning_stock: 5 },  // 低库存3
	{ id: 'prod-007', name: '鼻饲营养护理', main_image_url: '/static/images/default-product.png', total_stock: 0, warning_stock: 3 },     // 售罄1
	{ id: 'prod-008', name: '术后营养指导（4次）', main_image_url: '/static/images/default-product.png', total_stock: 0, warning_stock: 3 },  // 售罄2
	{ id: 'prod-009', name: '中医调理推拿（3次）', main_image_url: '/static/images/default-product.png', total_stock: 15, warning_stock: 5 },
	{ id: 'prod-010', name: '老年心理疏导服务', main_image_url: '/static/images/default-product.png', total_stock: 18, warning_stock: 5 },
	{ id: 'prod-011', name: '居家药品管理服务', main_image_url: '/static/images/default-product.png', total_stock: 22, warning_stock: 5 },
	{ id: 'prod-012', name: '紧急呼叫响应服务', main_image_url: '/static/images/default-product.png', total_stock: 50, warning_stock: 10 }
]

// 从 mock 推导 stats（与页面 loadStats 逻辑完全一致）
export function getMockInventoryStats() : { totalProducts: number, lowStock: number, outOfStock: number } {
	let total = 0, low = 0, out = 0
	for (let i = 0; i < MOCK_INVENTORY_PRODUCTS.length; i++) {
		const p = MOCK_INVENTORY_PRODUCTS[i]
		total++
		if (p.total_stock === 0) out++
		else if (p.total_stock <= p.warning_stock) low++
	}
	return { totalProducts: total, lowStock: low, outOfStock: out }
}


// ════════════════════════════════════════════════════════════
// 四、评价 mock 数据
// ════════════════════════════════════════════════════════════
export type MockReviewType = {
	id: string
	product_id: string
	product_name: string
	user_id: string
	user_name: string
	user_avatar: string
	rating: number
	content: string
	images: string  // JSON 字符串数组，与 parseImages() 兼容
	reply: string
	created_at: string
}

// 10条，4条待回复（reply=''），6条已回复（reply非空）
// PENDING_REVIEW_COUNT = 4 与此处一致
export const MOCK_REVIEWS: MockReviewType[] = [
	// ── 待回复 4 条 ──
	{
		id: 'review-001', product_id: 'prod-001', product_name: '居家上门护理（半日）',
		user_id: 'user-001', user_name: '李*敏', user_avatar: '',
		rating: 5, content: '护士非常专业，老人很配合，感谢！态度好服务细心，以后还会预约。',
		images: '[]', reply: '', created_at: '2026-04-13T11:00:00+08:00'
	},
	{
		id: 'review-002', product_id: 'prod-005', product_name: '上门康复护理（月套餐）',
		user_id: 'user-006', user_name: '赵*强', user_avatar: '',
		rating: 4, content: '康复师技术不错，父亲恢复得挺好，就是希望每次时长能再长一点。',
		images: '[]', reply: '', created_at: '2026-04-12T16:00:00+08:00'
	},
	{
		id: 'review-003', product_id: 'prod-002', product_name: '血压血糖监测服务',
		user_id: 'user-007', user_name: '孙*华', user_avatar: '',
		rating: 5, content: '每次都准时上门，测量数据详细，还会给我们讲解注意事项，非常满意。',
		images: '[]', reply: '', created_at: '2026-04-11T09:30:00+08:00'
	},
	{
		id: 'review-004', product_id: 'prod-009', product_name: '中医调理推拿（3次）',
		user_id: 'user-002', user_name: '张*国', user_avatar: '',
		rating: 4, content: '推拿师手法到位，推完肩颈轻松很多，就是预约时间有点难排。',
		images: '[]', reply: '', created_at: '2026-04-10T14:00:00+08:00'
	},
	// ── 已回复 6 条 ──
	{
		id: 'review-005', product_id: 'prod-004', product_name: '术后伤口护理',
		user_id: 'user-003', user_name: '王*兰', user_avatar: '',
		rating: 5, content: '术后第一次用这个服务，护士很专业，换药很痛但很快，恢复良好。',
		images: '[]', reply: '感谢您的信任！我们护理团队会继续为您提供专业服务，祝恢复顺利！',
		created_at: '2026-04-09T10:00:00+08:00'
	},
	{
		id: 'review-006', product_id: 'prod-006', product_name: '糖尿病足专项护理',
		user_id: 'user-005', user_name: '刘*珍', user_avatar: '',
		rating: 5, content: '护士很有耐心，每次都会叮嘱注意事项，妈妈的伤口恢复得很好。',
		images: '["\/static\/images\/default-product.png"]',
		reply: '您好！感谢反馈，糖尿病足护理需要长期坚持，我们会持续陪伴您和家人。',
		created_at: '2026-04-08T11:00:00+08:00'
	},
	{
		id: 'review-007', product_id: 'prod-008', product_name: '术后营养指导（4次）',
		user_id: 'user-009', user_name: '吴*秀', user_avatar: '',
		rating: 5, content: '营养师给出的饮食方案很合理，家人按方案调整饮食后状态好多了！',
		images: '[]', reply: '谢谢您的认可！合理饮食是术后恢复的关键，有任何问题随时联系我们。',
		created_at: '2026-04-07T09:00:00+08:00'
	},
	{
		id: 'review-008', product_id: 'prod-003', product_name: '慢病随访服务',
		user_id: 'user-008', user_name: '郑*明', user_avatar: '',
		rating: 4, content: '随访很规律，每次记录都很详细，给老人建立了完整的健康档案。',
		images: '[]', reply: '感谢您的评价！定期随访是管理慢性病的重要手段，我们会继续做好记录工作。',
		created_at: '2026-04-06T14:00:00+08:00'
	},
	{
		id: 'review-009', product_id: 'prod-007', product_name: '鼻饲营养护理',
		user_id: 'user-011', user_name: '冯*莲', user_avatar: '',
		rating: 5, content: '护士操作非常规范，每次来都会检查设备是否正常，很放心。',
		images: '[]', reply: '您好！鼻饲护理需要严格操作规范，感谢您的信任，我们会坚持做好每一次服务。',
		created_at: '2026-04-05T10:00:00+08:00'
	},
	{
		id: 'review-010', product_id: 'prod-001', product_name: '居家上门护理（半日）',
		user_id: 'user-012', user_name: '蒋*华', user_avatar: '',
		rating: 5, content: '服务很贴心，护士会提前电话确认时间，上门也十分准时，赞！',
		images: '[]', reply: '感谢您的五星好评！准时守约是我们的基本承诺，期待下次继续为您服务。',
		created_at: '2026-04-04T15:00:00+08:00'
	}
]

// filter 逻辑（与页面 currentFilter 对齐）
export function getMockReviews(filter: string) : MockReviewType[] {
	if (filter === 'pending') {
		const result: MockReviewType[] = []
		for (let i = 0; i < MOCK_REVIEWS.length; i++) {
			if (MOCK_REVIEWS[i].reply === '') result.push(MOCK_REVIEWS[i])
		}
		return result
	}
	if (filter === 'replied') {
		const result: MockReviewType[] = []
		for (let i = 0; i < MOCK_REVIEWS.length; i++) {
			if (MOCK_REVIEWS[i].reply !== '') result.push(MOCK_REVIEWS[i])
		}
		return result
	}
	return MOCK_REVIEWS
}


// ════════════════════════════════════════════════════════════
// 五、统计 mock 数据
// ════════════════════════════════════════════════════════════
export type MockTrendItemType = {
	day: string
	amount: number
}

// 趋势数据：today/week/month 三档
export const MOCK_TREND_TODAY: MockTrendItemType[] = [
	{ day: '08时', amount: 260 }, { day: '09时', amount: 380 },
	{ day: '10时', amount: 520 }, { day: '11时', amount: 180 },
	{ day: '14时', amount: 350 }, { day: '15时', amount: 430 },
	{ day: '16时', amount: 220 }
]

export const MOCK_TREND_WEEK: MockTrendItemType[] = [
	{ day: '周一', amount: 680 }, { day: '周二', amount: 1200 },
	{ day: '周三', amount: 980 }, { day: '周四', amount: 1560 },
	{ day: '周五', amount: 2340 }, { day: '周六', amount: 800 },
	{ day: '周日', amount: 420 }
]

export const MOCK_TREND_MONTH: MockTrendItemType[] = [
	{ day: '4/1', amount: 2100 }, { day: '4/2', amount: 1800 },
	{ day: '4/3', amount: 2680 }, { day: '4/4', amount: 3200 },
	{ day: '4/5', amount: 1950 }, { day: '4/6', amount: 2460 },
	{ day: '4/7', amount: 980 }
]

// 热门服务（ID与inventory对齐，由orders中统计派生）
export type MockStatProductType = {
	id: string
	name: string
	image: string
	sales: number
	revenue: number
}

export const MOCK_HOT_PRODUCTS: MockStatProductType[] = [
	{ id: 'prod-005', name: '上门康复护理（月套餐）', image: '/static/images/default-product.png', sales: 38, revenue: 45600 },
	{ id: 'prod-001', name: '居家上门护理（半日）', image: '/static/images/default-product.png', sales: 52, revenue: 19760 },
	{ id: 'prod-002', name: '血压血糖监测服务', image: '/static/images/default-product.png', sales: 67, revenue: 12060 },
	{ id: 'prod-004', name: '术后伤口护理', image: '/static/images/default-product.png', sales: 29, revenue: 13920 },
	{ id: 'prod-009', name: '中医调理推拿（3次）', image: '/static/images/default-product.png', sales: 24, revenue: 10320 }
]

// 统计概览（today/week/month 三档）
export function getMockStats(range: string) : { todaySales: string, todayOrders: number, todayVisitors: number, conversionRate: number } {
	if (range === 'today') {
		return { todaySales: '2340.00', todayOrders: 7, todayVisitors: 42, conversionRate: 17 }
	}
	if (range === 'week') {
		return { todaySales: '7980.00', todayOrders: 28, todayVisitors: 165, conversionRate: 17 }
	}
	// month
	return { todaySales: '31250.00', todayOrders: 98, todayVisitors: 620, conversionRate: 16 }
}

export function getMockTrendData(range: string) : MockTrendItemType[] {
	if (range === 'today') return MOCK_TREND_TODAY
	if (range === 'week') return MOCK_TREND_WEEK
	return MOCK_TREND_MONTH
}


// ════════════════════════════════════════════════════════════
// 六、结算 mock 数据
// ════════════════════════════════════════════════════════════
export type MockRecordType = {
	id: string
	title: string
	amount: number
	type: string  // 'order'=收支记录, 'withdraw'=结算/补贴记录
	created_at: string
}

export const MOCK_BALANCE = '12680.50'

export const MOCK_FINANCE_STATS = {
	todayRevenue: '2340.00',
	monthRevenue: '31250.00',
	pendingWithdraw: '4200.00'
}

export const MOCK_FINANCE_RECORDS: MockRecordType[] = [
	// ── type=order 收支记录 ──
	{ id: 'rec-001', title: '订单收入 SV2026041300001', amount: 380.00, type: 'order', created_at: '2026-04-13T08:20:00+08:00' },
	{ id: 'rec-002', title: '订单收入 SV2026041300002', amount: 260.00, type: 'order', created_at: '2026-04-13T09:35:00+08:00' },
	{ id: 'rec-003', title: '订单收入 SV2026041300003', amount: 520.00, type: 'order', created_at: '2026-04-13T10:05:00+08:00' },
	{ id: 'rec-004', title: '退款扣减 SV2026041300R01', amount: -380.00, type: 'order', created_at: '2026-04-13T07:35:00+08:00' },
	{ id: 'rec-005', title: '退款扣减 SV2026041200R02', amount: -180.00, type: 'order', created_at: '2026-04-12T16:15:00+08:00' },
	{ id: 'rec-006', title: '订单收入 SV2026041200004', amount: 1200.00, type: 'order', created_at: '2026-04-12T14:05:00+08:00' },
	{ id: 'rec-007', title: '订单收入 SV2026041200005', amount: 450.00, type: 'order', created_at: '2026-04-12T09:05:00+08:00' },
	{ id: 'rec-008', title: '订单收入 SV2026041100006', amount: 680.00, type: 'order', created_at: '2026-04-11T10:35:00+08:00' },
	// ── type=withdraw 结算/补贴记录 ──
	{ id: 'rec-009', title: '长者关怀补贴拨付', amount: 2000.00, type: 'withdraw', created_at: '2026-04-10T09:00:00+08:00' },
	{ id: 'rec-010', title: '月度服务结算', amount: 8600.00, type: 'withdraw', created_at: '2026-04-01T10:00:00+08:00' },
	{ id: 'rec-011', title: '医保结算入账', amount: 3200.00, type: 'withdraw', created_at: '2026-03-28T14:00:00+08:00' },
	{ id: 'rec-012', title: '申请提现', amount: -5000.00, type: 'withdraw', created_at: '2026-03-25T09:00:00+08:00' },
	{ id: 'rec-013', title: '医保结算入账', amount: 2800.00, type: 'withdraw', created_at: '2026-03-15T10:00:00+08:00' }
]

// tab 过滤：record 或 withdraw
export function getMockFinanceRecords(tab: string) : MockRecordType[] {
	if (tab === 'record') {
		const result: MockRecordType[] = []
		for (let i = 0; i < MOCK_FINANCE_RECORDS.length; i++) {
			if (MOCK_FINANCE_RECORDS[i].type === 'order') result.push(MOCK_FINANCE_RECORDS[i])
		}
		return result
	}
	if (tab === 'withdraw') {
		const result: MockRecordType[] = []
		for (let i = 0; i < MOCK_FINANCE_RECORDS.length; i++) {
			if (MOCK_FINANCE_RECORDS[i].type === 'withdraw') result.push(MOCK_FINANCE_RECORDS[i])
		}
		return result
	}
	return MOCK_FINANCE_RECORDS
}


// ════════════════════════════════════════════════════════════
// 七、促销活动 mock 数据
// ════════════════════════════════════════════════════════════
export type MockPromotionType = {
	id: string
	name: string
	type: string  // 'coupon' | 'seckill' | 'group'（与 tab 对应）
	discount_text: string
	start_time: string
	end_time: string
	status: number  // 0=未开始, 1=进行中, 2=已结束
	received_count: number
}

export const MOCK_PROMOTIONS: MockPromotionType[] = [
	// ── coupon 护理套餐券 ──
	{ id: 'promo-001', name: '居家护理体验满减券', type: 'coupon', discount_text: '满300减50', start_time: '2026-04-01T00:00:00+08:00', end_time: '2026-04-30T23:59:59+08:00', status: 1, received_count: 42 },
	{ id: 'promo-002', name: '康复护理月套餐优惠券', type: 'coupon', discount_text: '满1000减120', start_time: '2026-04-10T00:00:00+08:00', end_time: '2026-05-10T23:59:59+08:00', status: 1, received_count: 18 },
	{ id: 'promo-003', name: '护理新人首单优惠', type: 'coupon', discount_text: '首单立减80元', start_time: '2026-03-01T00:00:00+08:00', end_time: '2026-03-31T23:59:59+08:00', status: 2, received_count: 156 },
	// ── seckill 康复体验 ──
	{ id: 'promo-004', name: '上门康复体验特惠', type: 'seckill', discount_text: '原价380，限时198', start_time: '2026-04-13T10:00:00+08:00', end_time: '2026-04-13T22:00:00+08:00', status: 1, received_count: 7 },
	{ id: 'promo-005', name: '血压血糖检测体验价', type: 'seckill', discount_text: '9.9元体验', start_time: '2026-04-15T09:00:00+08:00', end_time: '2026-04-15T18:00:00+08:00', status: 0, received_count: 0 },
	{ id: 'promo-006', name: '长者推拿体验', type: 'seckill', discount_text: '原价150，体验价59', start_time: '2026-03-20T09:00:00+08:00', end_time: '2026-03-20T20:00:00+08:00', status: 2, received_count: 23 },
	// ── group 慢病管理服务包 ──
	{ id: 'promo-007', name: '高血压慢病三人拼团包', type: 'group', discount_text: '3人拼团享8.5折', start_time: '2026-04-05T00:00:00+08:00', end_time: '2026-04-20T23:59:59+08:00', status: 1, received_count: 9 },
	{ id: 'promo-008', name: '糖尿病管理服务季包', type: 'group', discount_text: '2人拼团9折', start_time: '2026-04-20T00:00:00+08:00', end_time: '2026-05-20T23:59:59+08:00', status: 0, received_count: 0 },
	{ id: 'promo-009', name: '慢病管理年度健康计划', type: 'group', discount_text: '3人拼团享7折', start_time: '2026-02-01T00:00:00+08:00', end_time: '2026-03-31T23:59:59+08:00', status: 2, received_count: 34 }
]

// tab 过滤（与 currentTab 对应）
export function getMockPromotions(tab: string) : MockPromotionType[] {
	const result: MockPromotionType[] = []
	for (let i = 0; i < MOCK_PROMOTIONS.length; i++) {
		if (MOCK_PROMOTIONS[i].type === tab) result.push(MOCK_PROMOTIONS[i])
	}
	return result
}

// 订单筛选（供 orders.uvue 使用）
export function getMockOrdersByStatus(status: number) : MockOrderType[] {
	if (status === -2) return MOCK_ORDERS  // 全部
	const result: MockOrderType[] = []
	for (let i = 0; i < MOCK_ORDERS.length; i++) {
		if (MOCK_ORDERS[i].order_status === status) result.push(MOCK_ORDERS[i])
	}
	return result
}

export function getMockAftersaleByStatus(status: number) : MockOrderType[] {
	if (status === -3) return MOCK_AFTERSALE_ORDERS  // 全部售后
	const result: MockOrderType[] = []
	for (let i = 0; i < MOCK_AFTERSALE_ORDERS.length; i++) {
		if (MOCK_AFTERSALE_ORDERS[i].order_status === status) result.push(MOCK_AFTERSALE_ORDERS[i])
	}
	return result
}


// ════════════════════════════════════════════════════════════
// 八、关怀等级 & 服务对象 mock 数据
// ════════════════════════════════════════════════════════════
export type MockMemberLevelType = {
	id: string
	name: string
	discount_rate: number
	level_rank: number
}

export type MockUserInfoType = {
	id: string
	username: string
	email: string
	nickname: string | null
	avatar_url: string | null
	phone: string | null
	tier_id: string | null
	tier_name: string | null
}

// 关怀等级 4 档
export const MOCK_MEMBER_LEVELS: MockMemberLevelType[] = [
	{ id: 'level-001', name: '普通关怀', discount_rate: 1.0, level_rank: 1 },
	{ id: 'level-002', name: '银发关怀', discount_rate: 0.95, level_rank: 2 },
	{ id: 'level-003', name: '金牌关怀', discount_rate: 0.90, level_rank: 3 },
	{ id: 'level-004', name: '白金尊享', discount_rate: 0.85, level_rank: 4 }
]

// 服务对象 12 人：4 人有等级（tier_id 非空），8 人暂无等级
// tier_name 通过 tier_id 与 MOCK_MEMBER_LEVELS 对应
export const MOCK_SERVICE_USERS: MockUserInfoType[] = [
	// ── 已设置关怀等级 4 人（排在前面） ──
	{
		id: 'user-001', username: 'li_min',
		email: 'limin@example.com',
		nickname: '李敏奶奶',
		avatar_url: '',
		phone: '13800000001',
		tier_id: 'level-004',
		tier_name: '白金尊享'
	},
	{
		id: 'user-004', username: 'chen_lao',
		email: '',
		nickname: '陈伯伯',
		avatar_url: '',
		phone: '13800000004',
		tier_id: 'level-003',
		tier_name: '金牌关怀'
	},
	{
		id: 'user-005', username: 'liu_zhen',
		email: '',
		nickname: '刘珍阿姨',
		avatar_url: '',
		phone: '13800000005',
		tier_id: 'level-002',
		tier_name: '银发关怀'
	},
	{
		id: 'user-006', username: 'zhao_qiang',
		email: 'zhaoqiang@example.com',
		nickname: '赵强大伯',
		avatar_url: '',
		phone: '13800000006',
		tier_id: 'level-001',
		tier_name: '普通关怀'
	},
	// ── 未设置关怀等级 8 人 ──
	{
		id: 'user-002', username: 'zhang_guo',
		email: '',
		nickname: '张国爷爷',
		avatar_url: '',
		phone: '13800000002',
		tier_id: null,
		tier_name: null
	},
	{
		id: 'user-003', username: 'wang_lan',
		email: '',
		nickname: '王兰阿姨',
		avatar_url: '',
		phone: '13800000003',
		tier_id: null,
		tier_name: null
	},
	{
		id: 'user-007', username: 'sun_hua',
		email: 'sunhua@example.com',
		nickname: '孙华叔叔',
		avatar_url: '',
		phone: '13800000007',
		tier_id: null,
		tier_name: null
	},
	{
		id: 'user-008', username: 'zheng_ming',
		email: '',
		nickname: '郑明爷爷',
		avatar_url: '',
		phone: '13800000008',
		tier_id: null,
		tier_name: null
	},
	{
		id: 'user-009', username: 'wu_xiu',
		email: '',
		nickname: '吴秀奶奶',
		avatar_url: '',
		phone: '13800000009',
		tier_id: null,
		tier_name: null
	},
	{
		id: 'user-010', username: 'he_lao',
		email: '',
		nickname: '何老先生',
		avatar_url: '',
		phone: '13800000010',
		tier_id: null,
		tier_name: null
	},
	{
		id: 'user-011', username: 'feng_lian',
		email: '',
		nickname: '冯莲奶奶',
		avatar_url: '',
		phone: '13800000011',
		tier_id: null,
		tier_name: null
	},
	{
		id: 'user-012', username: 'jiang_hua',
		email: '',
		nickname: '蒋华大伯',
		avatar_url: '',
		phone: '13800000012',
		tier_id: null,
		tier_name: null
	}
]
