<template>
  <div :class="{ hidden: hidden }" class="pagination-container flex">
<!--    <div class="flex">-->
<!--      <div-->
<!--        class="myBtn"-->
<!--        :class="{ active: active===index }"-->
<!--        v-for="item,index in pageSizes"-->
<!--        :key="item"-->
<!--        @click="handleSizeChange(index)"-->
<!--      >-->
<!--        {{ item }}-->
<!--      </div>-->
<!--    </div>-->
<!--    <div>-->
      <el-pagination
        :background="background"
        :current-page.sync="currentPage"
        :page-size.sync="pageSize"
        :layout="layout"
        :page-sizes="pageSizes"
        :total="total"
        v-bind="$attrs"
        @current-change="handleCurrentChange"
      />
        <!-- @size-change="handleSizeChange" -->

    </div>
<!--  </div>-->
</template>

<script>
import { scrollTo } from "@/utils/scroll-to";

export default {
  name: "Pagination",
  props: {
    total: {
      required: true,
      type: Number,
    },
    page: {
      type: Number,
      default: 1,
    },
    limit: {
      type: Number,
      default: 20,
    },
    pageSizes: {
      type: Array,
      default() {
        return [10, 20, 30, 50];
      },
    },
    layout: {
      type: String,
      default: 'total, sizes, prev, pager, next, jumper'
      // default: "prev, pager, next",
    },
    background: {
      type: Boolean,
      default: false,
    },
    autoScroll: {
      type: Boolean,
      default: true,
    },
    hidden: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {active:0};
  },
  computed: {
    currentPage: {
      get() {
        return this.page;
      },
      set(val) {
        this.$emit("update:page", val);
      },
    },
    pageSize: {
      get() {
        return this.limit;
      },
      set(val) {
        this.$emit("update:limit", val);
      },
    },
  },
  methods: {
    handleSizeChange(val) {
      this.active =val;
      this.$emit("pagination", { page: this.currentPage, limit: this.pageSize });
      if (this.autoScroll) {
        scrollTo(0, 800);
      }
    },
    handleCurrentChange(val) {
      this.$emit("pagination", { page: val, limit: this.pageSize });
      if (this.autoScroll) {
        scrollTo(0, 800);
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.pagination-container {
  background: #fff;
  padding: 10px 0px !important;
  justify-content: space-between;
}
.pagination-container.hidden {
  display: none;
}
.myBtn {
  width: 42px;
  height: 29px;
  border-radius: 8px;
  color: #727a84;
  text-align: center;
  line-height: 29px;
  font-size: 14px;
  margin-right: 10px;
  cursor: pointer;
  &:hover{
    background: rgba(0, 122, 255,.5)
  }
  &.active {
    background: #007aff;
    color:#fff
  }
}
</style>
