<template>
  <view class="admin-kefu-list">
    <!-- 顶部操作栏 -->
    <view class="page-top-bar">
      <view class="btn-primary" @click="handleAdd">
        <text class="btn-txt">添加客服</text>
      </view>
    </view>
    
    <!-- 数据表格 -->
    <view class="table-container border-shadow">
      <view class="table-header">
        <view class="th col-id"><text class="th-txt">ID</text></view>
        <view class="th col-avatar"><text class="th-txt">客服头像</text></view>
        <view class="th col-name"><text class="th-txt">客服名称</text></view>
        <view class="th col-status"><text class="th-txt">客服状态</text></view>
        <view class="th col-time"><text class="th-txt">添加时间</text></view>
        <view class="th col-op"><text class="th-txt">操作</text></view>
      </view>

      <view class="table-body">
        <view class="table-row" v-for="item in kefuList" :key="item.id">
          <view class="td col-id"><text class="td-txt">{{ item.id }}</text></view>
          <view class="td col-avatar">
            <image class="kefu-avatar" :src="item.avatar" mode="aspectFill"></image>
          </view>
          <view class="td col-name"><text class="td-txt">{{ item.name }}</text></view>
          <view class="td col-status">
            <view :class="['switch-btn', item.status ? 'switch-on' : 'switch-off']" @click="toggleStatus(item)">
              <view class="switch-inner">
                <text class="switch-txt">{{ item.status ? '开启' : '关闭' }}</text>
              </view>
              <view class="switch-dot"></view>
            </view>
          </view>
          <view class="td col-time"><text class="td-txt">{{ item.time }}</text></view>
          <view class="td col-op">
            <text class="btn-action">编辑</text>
            <view class="divider"></view>
            <text class="btn-action">删除</text>
            <view class="divider"></view>
            <text class="btn-action">进入工作台</text>
          </view>
        </view>
      </view>

      <!-- 分页栏 -->
      <view class="pagination-bar">
        <text class="page-total">共 {{ kefuList.length }} 条</text>
        <view class="page-size-select">
          <text class="size-txt">15条/页</text>
          <text class="arrow-down">▼</text>
        </view>
        <view class="page-nav">
          <view class="nav-prev"><text class="nav-icon"> < </text></view>
          <view class="nav-item active"><text class="nav-num">1</text></view>
          <view class="nav-next"><text class="nav-icon"> > </text></view>
        </view>
        <view class="page-jump">
          <text class="jump-txt">前往</text>
          <input class="jump-input" value="1" />
          <text class="jump-txt">页</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="uts">
import { ref } from 'vue'

interface KefuItem {
  id: string
  avatar: string
  name: string
  status: boolean
  time: string
}

const kefuList = ref<KefuItem[]>([
  { id: '167', avatar: '/static/logo.png', name: '客服', status: true, time: '2025-12-31 11:24:35' },
  { id: '166', avatar: '/static/logo.png', name: '测试', status: true, time: '2025-11-18 17:33:26' },
  { id: '165', avatar: '/static/logo.png', name: 'zhicheng', status: true, time: '2025-09-10 10:13:00' },
  { id: '164', avatar: '/static/logo.png', name: 'kefu', status: true, time: '2025-07-29 11:50:20' },
  { id: '162', avatar: '/static/logo.png', name: '呐呐', status: true, time: '2024-12-09 10:51:11' },
  { id: '153', avatar: '/static/logo.png', name: '小天', status: true, time: '2024-09-19 16:04:59' },
  { id: '152', avatar: '/static/logo.png', name: 'kk', status: true, time: '2024-09-16 00:05:22' }
])

const toggleStatus = (item: KefuItem) => {
  item.status = !item.status
}

const handleAdd = () => {
  console.log('Add Kefu')
}
</script>

<style scoped lang="scss">
.admin-kefu-list {
  padding: 20px;
  background-color: #f5f7fa;
  min-height: 100vh;
}

.border-shadow {
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.05);
}

.page-top-bar {
  margin-bottom: 20px;
}

.btn-primary {
  width: 100px;
  height: 36px;
  background-color: #2d8cf0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.btn-txt {
  color: #fff;
  font-size: 14px;
}

/* 表格样式 */
.table-container {
  display: flex;
  flex-direction: column;
}

.table-header {
  height: 50px;
  background-color: #e6f0ff;
  display: flex;
  flex-direction: row;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
}

.th {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}

.th-txt {
  font-size: 13px;
  color: #606266;
  font-weight: 500;
}

.table-row {
  height: 70px;
  display: flex;
  flex-direction: row;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
}

.table-row:hover {
  background-color: #f9fbff;
}

.td {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
}

.td-txt {
  font-size: 13px;
  color: #606266;
}

/* 列宽百分比对齐截图 */
.col-id { width: 80px; }
.col-avatar { width: 120px; }
.col-name { flex: 1; justify-content: flex-start; }
.col-status { width: 150px; }
.col-time { width: 220px; }
.col-op { 
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 250px; 
}

.kefu-avatar {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  background-color: #f0f0f0;
}

/* 开关组件 1:1 复刻 */
.switch-btn {
  width: 60px;
  height: 24px;
  border-radius: 12px;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 6px;
  cursor: pointer;
  transition: all 0.3s;
}

.switch-on { background-color: #2d8cf0; }
.switch-off { background-color: #ccc; }

.switch-inner {
  flex: 1;
  display: flex;
  justify-content: center;
}

.switch-txt {
  color: #fff;
  font-size: 11px;
}

.switch-dot {
  width: 18px;
  height: 18px;
  background-color: #fff;
  border-radius: 9px;
  position: absolute;
  top: 3px;
}

.switch-on .switch-dot { right: 3px; }
.switch-off .switch-dot { left: 3px; }

/* 操作按钮 */
.btn-action {
  font-size: 13px;
  color: #2d8cf0;
  cursor: pointer;
}

.divider {
  width: 1px;
  height: 12px;
  background-color: #e8eaec;
  margin: 0 12px;
}

/* 分页栏 */
.pagination-bar {
  padding: 20px 24px;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
}

.page-total { font-size: 13px; color: #606266; margin-right: 15px; }

.page-size-select {
  border: 1px solid #dcdee2;
  padding: 4px 10px;
  border-radius: 4px;
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-right: 15px;
}

.size-txt { font-size: 13px; color: #606266; margin-right: 8px; }
.arrow-down { font-size: 10px; color: #808695; }

.page-nav { display: flex; flex-direction: row; align-items: center; margin-right: 15px; }
.nav-prev, .nav-next {
  width: 32px;
  height: 32px;
  border: 1px solid #dcdee2;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  margin: 0 4px;
}

.nav-item {
  width: 32px;
  height: 32px;
  border: 1px solid #dcdee2;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  margin: 0 4px;
}

.active {
  background-color: #2d8cf0;
  border-color: #2d8cf0;
}

.active .nav-num { color: #fff; }
.nav-num, .nav-icon { font-size: 13px; color: #606266; }

.page-jump { display: flex; flex-direction: row; align-items: center; }
.jump-txt { font-size: 13px; color: #606266; }
.jump-input {
  width: 40px;
  height: 30px;
  border: 1px solid #dcdee2;
  border-radius: 4px;
  text-align: center;
  margin: 0 8px;
  font-size: 13px;
}
</style>
