/** 评分列表假数据，接口就绪后替换 */

export const EMPTY_REVIEW_TEXT = '该用户很懒，什么都没有留下'

export const CONTENT_COLLAPSE_LEN = 72

export const MOCK_RATING_LIST = [
	{
		id: 'r1',
		serviceName: '斯诺克技术指导-个性化陪练',
		score: 3.5,
		content:
			'教练很专业，讲解耐心，练了一下午进步明显。场地环境也不错，就是周末人有点多，建议提前预约时间段。教练会根据你的水平调整教学节奏，从基础走位到高级战术都有涉及，整体体验超出预期，下次还会再来。',
		avatar: '',
		nickName: '你用户昵称',
		createTime: '2025-05-01 12:25:00',
	},
	{
		id: 'r2',
		serviceName: '斯诺克技术指导-个性化陪练',
		score: 5,
		content: '',
		avatar: '',
		nickName: '你用户昵称',
		createTime: '2025-05-01 12:25:00',
	},
	{
		id: 'r3',
		serviceName: '斯诺克技术指导-个性化陪练',
		score: 3,
		content:
			'教练很专业，讲解耐心，练了一下午进步明显。场地环境也不错，就是周末人有点多，建议提前预约时间段。教练会根据你的水平调整教学节奏，从基础走位到高级战术都有涉及，整体体验超出预期，下次还会再来。',
		avatar: '',
		nickName: '你用户昵称',
		createTime: '2025-05-01 12:25:00',
	},
	{
		id: 'r4',
		serviceName: '斯诺克技术指导-个性化陪练',
		score: 2.0,
		content: '一般般吧，时间有点赶，希望下次能多留一点练习时间。',
		avatar: '',
		nickName: '路人甲',
		createTime: '2025-05-20 14:02:11',
	},
	{
		id: 'r5',
		serviceName: '中式八球进阶课程',
		score: 4.8,
		content:
			'技术细节讲得很到位，尤其是走位和防守思路，对我帮助很大。已经预约了下一节课，期待继续提升。',
		avatar: '',
		nickName: '老球友***2',
		createTime: '2025-05-01 12:25:00',
	},
]

export function parseTime(str) {
	if (!str) return 0
	if (/^\d+$/.test(String(str).trim())) {
		const num = Number(str)
		return str.length <= 10 ? num * 1000 : num
	}
	const normalized = String(str).trim().replace('T', ' ').replace(/-/g, '/')
	const ts = new Date(normalized).getTime()
	return Number.isFinite(ts) ? ts : 0
}

export function formatReviewTime(timeStr) {
	if (!timeStr) return ''
	if (/^\d+$/.test(String(timeStr).trim())) {
		const num = Number(timeStr)
		const d = new Date(timeStr.length <= 10 ? num * 1000 : num)
		if (Number.isFinite(d.getTime())) {
			return formatReviewTimeFromDate(d)
		}
	}
	const normalized = String(timeStr).trim().replace('T', ' ').replace(/-/g, '/')
	const d = new Date(normalized)
	if (!Number.isFinite(d.getTime())) return ''
	return formatReviewTimeFromDate(d)
}

function formatReviewTimeFromDate(d) {
	const m = d.getMonth() + 1
	const day = d.getDate()
	const hh = String(d.getHours()).padStart(2, '0')
	const mm = String(d.getMinutes()).padStart(2, '0')
	return `${m}月${day}日 ${hh}:${mm}`
}

export function formatScore(score) {
	const num = Number(score)
	if (!Number.isFinite(num)) return '0'
	if (Number.isInteger(num)) return String(num)
	return num.toFixed(1)
}

export function normalizeRatingItem(raw, index) {
	//raw.text='fjkdspajfpodjhdjksjf健康的死来哦安抚飞机第四哦是打飞机范德萨发的撒回复第撒谎覅哦爱佛教的死哦阿富汗都随阿飞hi哦的撒就哦范德萨覅哦哦大家萨芬绝对是阿凡达开始啦积分卡十分接近迪斯拉夫降低哦按实际分开了就是打飞机i哦的撒覅大厦覅偶是大家覅哦大厦覅哦大厦i欧派发动机撒附近的死哦按附件'
	const content = (raw.cContent || raw.content || raw.cText || raw.text || '').trim()
	return content.length > CONTENT_COLLAPSE_LEN
}

export function sortByTimeDesc(list) {
	return [...list].sort((a, b) => parseTime(b.createTime) - parseTime(a.createTime))
}
