<template>
    <div class="watching">
        <img src="@/assets/png-zhuiju-bg.png" class="top-bg !absolute w-full h-[200px] top-0 left-0 !z-0" alt="" />
        <div class="watching-content">
            <van-sticky @change="changeSticky">
                <van-nav-bar
                    :class="{ isFixed: isFixed }"
                    title="觀看歷史"
                    left-text=""
                    left-arrow
                    @click-left="back"
                />
            </van-sticky>

            <div class="pb-6 px-[18px]">
                <van-empty description="暂无记录" v-if="histories.length == 0 && !loading" />

                <div class="hot-list" v-else>
                    <video-line
                        v-for="(item, index) in histories"
                        :key="index"
                        :info="item.series"
                        history
                        :episodeNum="item.episode.episodeNum"
                    ></video-line>
                </div>
            </div>
        </div>
    </div>
</template>
<script setup>
import VideoLine from '../components/VideoLine.vue'
import { useRouter } from 'vue-router'
import { ref } from 'vue'
import { http } from '@/plugins/http'

const router = useRouter()
function back() {
    router.back()
}

const isFixed = ref(false)
function changeSticky(fixed) {
    isFixed.value = fixed
}

const histories = ref([])
const loading = ref(true)
http.get('/api/playHistories').then(res => {
    histories.value = res.data
    loading.value = false
})
</script>

<style lang="less" scoped>
.watching {
    .watching-content {
        position: relative;
        z-index: 1;
    }
}

.hot-list {
    padding: 14px 0;

    .video-info + .video-info {
        margin-top: 14px;
    }
}

.van-nav-bar {
    --van-nav-bar-background: transparent;
    --van-border-width: 0;
    --van-nav-bar-title-text-color: #fff;
    --van-nav-bar-icon-color: #fff;

    &.isFixed {
        --van-nav-bar-background: #11131e;
    }
}
</style>
