<script setup lang="ts">
import NavList from './components/NavList.vue'
import ReadBook from './components/ReadBook.vue'

const navList = ref([
  {
    label: '全部图书',
    value: 1,
  },
  {
    label: '最近阅读',
    value: 2,
  },
])
const activeNave = ref(1) // nav栏

const bookList = ref([
  {
    id: 123,
    lexile: 1,
    alreadyReadPageNum: 0,
    alreadyReadPercent: 0,
    enName: 'Building with Blocks',
    pictureUrl:
      'https://reading-1313840333.cos.ap-guangzhou.myqcloud.com/%5CA%5CBR140L_Building%20with%20Blocks%5Cpage_00%5Cpage-0_xlarge.jpg',
    znName: '搭积木',
  },
])

function init() {
  for (let index = 0; index < 50; index++) {
    bookList.value.push({
      id: 123,
      lexile: 1,
      alreadyReadPageNum: 0,
      alreadyReadPercent: 100,
      enName: 'Building with Blocks',
      pictureUrl:
        'https://reading-1313840333.cos.ap-guangzhou.myqcloud.com/%5CA%5CBR140L_Building%20with%20Blocks%5Cpage_00%5Cpage-0_xlarge.jpg',
      znName: `搭积木${index}`,
    })
  }
}

onActivated(async () => {
  console.log('onActivated')
})

onMounted(() => {
  init()
})

function changeNav() {
  console.log('activeNave', activeNave.value)
  if (activeNave.value === 1) {
    init()
  } else {
    bookList.value = []
  }
}
</script>
<template>
  <div class="read">
    <div class="top">
      <BackBar />
    </div>
    <div class="banner">
      <NavList v-model="activeNave" :navList="navList" @onChange="changeNav"></NavList>
      <div class="content">
        <div v-if="bookList.length" class="book-list hidden_scroll">
          <ReadBook v-for="item in bookList" :key="item.id" :bookData="item"></ReadBook>
        </div>
        <div v-else class="empty">
          <Empty type="learn" content="还没阅读数据，快去阅读吧" />
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
//
.read {
  width: 100%;
  height: 100vh;
  background-size: cover;
  position: relative;
  @include main_bg;
  .top {
    position: absolute;
    left: 64px;
    top: 2.67vh;
  }
  .banner {
    padding-top: 3vh;
    .content {
      width: 1792px;
      height: 85.33vh;
      border-radius: 1.67vh;
      background-color: #fff;
      margin: 0 auto;
      margin-top: -0.17vh;
      padding: 3.33vh 32px;
      .book-list {
        height: 100%;
        overflow-y: scroll;
        display: flex;
        flex-wrap: wrap;
      }
    }
    .empty {
      height: 100%;
      display: flex;
      justify-content: center;
      align-items: center;
    }
  }
}
</style>
