<template>
  <view class="catalog-container" v-if="show">
    <view class="catalog-header">
      <text class="title">目录</text>
      <text class="close-btn" @tap="onClose">×</text>
    </view>
    <scroll-view scroll-y class="chapter-list">
      <view 
        v-for="chapter in chapters" 
        :key="chapter.id" 
        class="chapter-item"
        :class="{ active: currentChapterId === chapter.id }"
        @tap="onSelect(chapter)"
      >
        <text>{{ chapter.title }}</text>
      </view>
    </scroll-view>
  </view>
</template>

<script>
export default {
  name: 'ReaderCatalog',
  props: {
    show: {
      type: Boolean,
      default: false
    },
    chapters: {
      type: Array,
      default: () => []
    },
    currentChapterId: {
      type: Number,
      default: 1
    }
  },
  methods: {
    onClose() {
      this.$emit('close')
    },
    onSelect(chapter) {
      this.$emit('select', chapter)
    }
  }
}
</script>

<style scoped>
.catalog-container {
  position: fixed;
  top: 0;
  left: 0;
  width: 80%;
  height: 100%;
  background-color: #fff;
  z-index: 300;
  display: flex;
  flex-direction: column;
  box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.catalog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 30rpx;
  border-bottom: 1px solid #eee;
}

.title {
  font-size: 36rpx;
  font-weight: bold;
}

.close-btn {
  font-size: 40rpx;
  padding: 0 20rpx;
}

.chapter-list {
  flex: 1;
  padding: 20rpx 0;
}

.chapter-item {
  padding: 30rpx;
  border-bottom: 1px solid #f5f5f5;
  font-size: 30rpx;
}

.chapter-item.active {
  color: #007aff;
  background-color: #f0f0f0;
}
</style>

