<template>
    <view class="scroll-container theme-light">
        <view class="bt-page" v-if="session">
            <MemberInfoSubNav title="训练详情" @back="onBack" />
            <view class="bt-page__body">
                <view class="bt-score-card">
                    <view class="bt-score-card__info">
                        <text class="bt-score-card__title">{{ session.title }}</text>
                        <text class="bt-score-card__date">{{ session.date }} {{ session.time }}</text>
                    </view>
                </view>
                <view class="bt-card">
                    <text class="bt-card__title">训练数据</text>
                    <view class="bt-metrics">
                        <view class="bt-metric"><text class="bt-metric__value">{{ session.duration }}</text><text class="bt-metric__label">时长</text></view>
                        <view class="bt-metric"><text class="bt-metric__value">{{ session.calories }}</text><text class="bt-metric__label">消耗(kcal)</text></view>
                        <view class="bt-metric"><text class="bt-metric__value">{{ session.heartRate }}</text><text class="bt-metric__label">平均心率</text></view>
                        <view class="bt-metric"><text class="bt-metric__value">{{ session.typeLabel }}</text><text class="bt-metric__label">类型</text></view>
                    </view>
                </view>
                <view class="bt-card">
                    <text class="bt-card__title">签到时间</text>
                    <text class="bt-card__desc">{{ session.checkInTime }}</text>
                </view>
                <view class="bt-card">
                    <text class="bt-card__title">教练评语</text>
                    <text class="bt-card__desc">{{ session.comment }}</text>
                </view>
            </view>
        </view>
    </view>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import MemberInfoSubNav from '@/components/memberInfo/MemberInfoSubNav.vue'
import { PAGE, goBackOrTab } from '@/common/constants/routes.js'
import { loadMemberStore } from '@/common/memberInfo/store.js'
import { getTrainingSessionById } from '@/common/memberInfo/moduleStore.js'

const session = ref(null)

onMounted(() => {
    const pages = getCurrentPages()
    const currentPage = pages[pages.length - 1]
    const options = currentPage?.options || {}
    session.value = getTrainingSessionById(loadMemberStore(), options?.id)
})

function onBack() {
    goBackOrTab(PAGE.TRAIN_REPORT)
}
</script>

<style lang="scss">
@import '@/common/style/base.css';
@import '@/common/style/memberInfo/pages/page-reset.css';
@import '@/common/style/memberInfo/pages/sub-page-base.css';
@import '@/common/style/memberInfo/member-info-sub-nav.css';
@import '@/common/style/memberInfo/pages/body-test-common.css';
</style>
