<template>
  <div class="l-flex__none c-pagination">
    <el-pagination
      :current-page.sync="currentPage"
      :page-size="limit"
      :total="Number(total)"
      :layout="layout"
      background
      hide-on-single-page
      v-bind="$attrs"
      @current-change="onCurrentChange"
    />
  </div>
</template>

<script>
export default {
  name: 'Pagination',
  props: {
    total: {
      required: true,
      type: [Number, String]
    },
    page: {
      type: Number,
      default: 10
    },
    limit: {
      type: Number,
      default: 20
    },
    layout: {
      type: String,
      default: 'total,prev,pager,next,jumper'
    }
  },
  computed: {
    currentPage: {
      get () {
        return this.page
      },
      set (val) {
        this.$emit('update:page', val)
      }
    }
  },
  methods: {
    onCurrentChange (val) {
      this.$emit('pagination', { page: val, limit: this.limit })
    }
  }
}
</script>

<style lang="scss" scoped>
.c-pagination {
  padding-top: $spacing;
  text-align: center;

  &:empty {
    display: none;
  }

  ::v-deep .el-pagination.is-background .el-pager li:not(.disabled).active {
    background-color: $blue;
  }
}
</style>
