<template>
	<view class="call-end-container">
		<view class="call-info-card">
			<image class="avatar" :src="contactAvatar" mode="aspectFill"></image>
			<view class="call-info">
				<text class="title">{{ status }}</text>
				<text class="contact-name">{{ contactName }}</text>
				<view class="duration-info" v-if="status === '通话已结束' && duration > 0">
					<text>通话时长: {{ formatDuration(duration) }}</text>
				</view>
			</view>
		</view>

		<button class="return-btn" @click="goToHomePage">返回首页</button>
	</view>
</template>

<script>
import { goToMainTab } from '@/utils/navigation'

export default {
	data() {
		return {
			contactName: '家庭设备',
			contactAvatar: '/static/logo.png',
			duration: 0,
			status: '通话已结束'
		}
	},
	onLoad(options) {
		if (options) {
			this.contactName = decodeURIComponent(options.name || '') || '家庭设备'
			this.contactAvatar = decodeURIComponent(options.avatar || '') || '/static/logo.png'
			this.duration = parseInt(options.duration || 0, 10)
			this.status = decodeURIComponent(options.status || '') || '通话已结束'
		}
	},
	methods: {
		formatDuration(seconds) {
			if (!seconds || seconds <= 0) return '00:00'
			const minutes = Math.floor(seconds / 60)
			const remainingSeconds = seconds % 60
			return `${String(minutes).padStart(2, '0')}:${String(remainingSeconds).padStart(2, '0')}`
		},
		goToHomePage() {
			goToMainTab('my')
		}
	}
}
</script>

<style>
.call-end-container {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	padding: 40rpx;
	min-height: 100vh;
	background-color: #f5f5f5;
}

.call-info-card {
	width: 90%;
	background-color: #fff;
	border-radius: 16rpx;
	padding: 40rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
	box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
	margin-bottom: 60rpx;
}

.avatar {
	width: 160rpx;
	height: 160rpx;
	border-radius: 50%;
	margin-bottom: 30rpx;
	border: 4rpx solid #f0f0f0;
}

.call-info {
	display: flex;
	flex-direction: column;
	align-items: center;
	width: 100%;
}

.title {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
	margin-bottom: 20rpx;
}

.contact-name {
	font-size: 48rpx;
	color: #000;
	margin-bottom: 30rpx;
	font-weight: 500;
}

.duration-info {
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 32rpx;
	color: #666;
	margin-top: 20rpx;
}

.return-btn {
	background-color: #07c160;
	color: #fff;
	font-size: 36rpx;
	padding: 20rpx 0;
	width: 90%;
	border-radius: 12rpx;
	margin-top: 60rpx;
}

@media screen and (orientation: landscape) {
	.call-info-card {
		flex-direction: row;
		align-items: center;
		text-align: left;
		padding: 30rpx 40rpx;
	}

	.avatar {
		margin-right: 40rpx;
		margin-bottom: 0;
	}

	.call-info {
		align-items: flex-start;
	}
}
</style>
