<template>
  <div class="hw-pagination">
    <div class="pagination-info" v-if="total > 0">
      <span>共 {{ total }} 条记录，当前第 {{ currentPage }}/{{ totalPages }} 页</span>
    </div>
    <div class="pagination-controls">
      <button @click="firstPage" :disabled="currentPage === 1" class="btn btn-sm btn-default">
        首页
      </button>
      <button @click="prevPage" :disabled="currentPage === 1" class="btn btn-sm btn-default">
        上一页
      </button>
      <button @click="nextPage" :disabled="currentPage === totalPages" class="btn btn-sm btn-default">
        下一页
      </button>
      <button @click="lastPage" :disabled="currentPage === totalPages" class="btn btn-sm btn-default">
        末页
      </button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'HwPagination',
  props: {
    total: {
      type: Number,
      default: 0
    },
    totalPages: {
      type: Number,
      default: 0
    },
    currentPage: {
      type: Number,
      default: 1
    }
  },
  methods: {
    firstPage() {
      if (this.currentPage !== 1) {
        this.$emit('page-change', 1);
      }
    },
    prevPage() {
      if (this.currentPage > 1) {
        this.$emit('page-change', this.currentPage - 1);
      }
    },
    nextPage() {
      if (this.currentPage < this.totalPages) {
        this.$emit('page-change', this.currentPage + 1);
      }
    },
    lastPage() {
      if (this.currentPage !== this.totalPages) {
        this.$emit('page-change', this.totalPages);
      }
    }
  }
}
</script>

<style scoped>
.hw-pagination {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 15px 0;
}

.pagination-info {
  margin-bottom: 10px;
  font-size: 14px;
}

.pagination-controls {
  display: flex;
  gap: 5px;
}

.btn {
  min-width: 60px;
}
</style>
