<template>
  <div class="containers dark:!bg-[#060818]" v-loading="loading">
    <!-- 操作提示 -->
    <div class="tips-info dark:!bg-[#060818]" v-if="tips">
      <slot name="tips"></slot>
    </div>
    <!-- 工具栏 -->
    <div v-if="toolbar" class="toolbar dark:!bg-[#060818]">
      <slot name="toolbar"></slot>
    </div>
    <!-- 表格 -->
    <el-table
      :max-height="height"
      v-bind="$attrs"
      v-on="$attrs"
      ref="table"
      align="center"
      :data="tableData"
      :row-key="rowKey"
      :stripe="false"
      :header-cell-style="{ textAlign: 'center' }"
      :cell-style="{ textAlign: 'center' }"
      :style="{ width:'100%', minHeight: height + 'px' }"
      @selection-change="selectionChange"
      class="dark:!bg-[#060818]"
      highlight-current-row
    >
      <slot name="table-columns" class="dark:!bg-[#060818]"></slot>
    </el-table>
    <!-- 分页 -->
    <div v-if="pagination" class="pagination dark:!bg-[#060818] ">
      <div class="pagination-toolbar dark:!bg-[#060818]">
        <slot name="pagination-toolbar"></slot>
      </div>
      <slot name="pagination"></slot>
    </div>
  </div>
</template>

<script>
import { mapState } from 'vuex';
export default {
  name: 'ResponsiveTable',
  props: {
    /** 是否显示斑纹 */
    stripe: {
      type: Boolean,
      default: true,
    },
    /** 行数据的 Key */
    rowKey: {
      type: [String, Function],
      default: null,
    },
    /** 是否显示工具栏 */
    toolbar: {
      type: Boolean,
      default: true,
    },
    /** 是否显示操作提示 */
    tips: {
      type: Boolean,
      default: false,
    },
    /** 是否显示分页 */
    pagination: {
      type: Boolean,
      default: true,
    },
    /** 表格数据 */
    tableData: {
      default: function () {
        return [];
      },
    },
    /** 加载状态 */
    loading: {
      type: Boolean,
      default: false,
    },
    /** 当选择项发生变化 */
    selectionChange: {
      type: Function,
      default: function () {
        return [];
      },
    },
  },
  data() {
    return {
      height: `${document.body.clientHeight - 260}`,
    };
  },
  methods: {
    headerCellStyle() {
      return {
        backgroundColor: 'bg-[#060818]', // Tailwind CSS class
      };
    },
  },
};
</script>

<style scoped>
.el-table {
  background-color: transparent !important;
}
.containers {
  width: 100%;
  height: 100%;
  position: relative;
  background: #fff;
}

/** 工具栏样式 */
.toolbar {
  display: flex;
  align-items: center;
  height: 44px;
  border-bottom: 1px solid #e6ebf5;
  background-color: #fff;
}

.inner-toolbar {
  display: flex;
  width: 100%;
  justify-content: space-between;
  padding: 0 20px;
}

.toolbar-search {
  margin-right: 10px;
}

/** 分页样式 */
.pagination {
  display: flex;
  justify-content: space-between;
  padding: 5px 20px;
  text-align: right;
  background-color: #ffffff;
}
.pagination-toolbar {
  display: flex;
  align-items: center;
}

/** 操作提示样式 */
.tips-info {
  background: #fff;
  color: #31708f;
  padding: 1px 10px;
  margin-bottom: 10px;
  border-radius: 4px;
}
h4 {
  font-weight: 500;
  margin: 20px 0;
}

ul {
  margin: 20px 0;
  padding-left: 40px;
  display: block;
}
li {
  font-size: 12px;
  list-style-type: disc;
}
:deep(.el-table__header) {
  @apply dark:bg-[#060818];
}
.table-container {
  overflow-x: auto;
}

/* @media (max-width: 768px) {
  .el-table th, .el-table td {
    white-space: nowrap;
  }
} */
</style>