<template>
  <div class="performance-score">
    <el-card shadow="never">
      <el-form :inline="true" :model="filters" class="filter-form">
        <el-form-item :label="$t('table.manager')">
          <el-input v-model="filters.name" :placeholder="$t('placeholder.search')" clearable style="width:160px" />
        </el-form-item>
        <el-form-item :label="$t('common.time')">
          <el-date-picker
            v-model="filters.month"
            type="month"
            :placeholder="$t('common.pleaseSelect')"
            value-format="YYYY-MM"
            style="width:160px"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="onSearch">{{ $t('btn.query') }}</el-button>
          <el-button @click="onReset">{{ $t('btn.reset') }}</el-button>
        </el-form-item>
      </el-form>

      <el-table :data="list" v-loading="loading" border stripe>
        <el-table-column :label="$t('points.points')" prop="rank" width="80" />
        <el-table-column :label="$t('table.manager')" prop="name" width="120" />
        <el-table-column :label="$t('label.dept')" prop="department" min-width="140" show-overflow-tooltip />
        <el-table-column :label="$t('points.title')" prop="totalScore" width="120">
          <template #default="{ row }">
            <span class="score-num">{{ row.totalScore }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('points.detail')" prop="monthScore" width="120" />
        <el-table-column :label="$t('stat.totalOrders')" prop="serviceCount" width="100" />
        <el-table-column :label="$t('stat.completed')" prop="satisfaction" width="160">
          <template #default="{ row }">
            <el-rate v-model="row.satisfaction" disabled show-score :colors="['#99A9BF', '#F7BA2A', '#FF9900']" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('table.action')" width="120" fixed="right">
          <template #default="{ row }">
            <el-button link type="primary" @click="onDetail(row)">{{ $t('points.detail') }}</el-button>
          </template>
        </el-table-column>
      </el-table>

      <div class="pagination">
        <el-pagination
          v-model:current-page="page"
          v-model:page-size="pageSize"
          :page-sizes="[10, 20, 50]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="loadList"
          @current-change="loadList"
        />
      </div>
    </el-card>
  </div>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import { ElMessage } from "element-plus";
import { useI18n } from "vue-i18n";

const { t: $t } = useI18n();

const MOCK_LIST = [
  { id: 1, rank: 1, name: "张三", department: "华东大区·上海组", totalScore: 2860, monthScore: 320, serviceCount: 28, satisfaction: 5 },
  { id: 2, rank: 2, name: "李四", department: "华北大区·北京组", totalScore: 2540, monthScore: 285, serviceCount: 33, satisfaction: 4 },
  { id: 3, rank: 3, name: "王五", department: "华南大区·广州组", totalScore: 2310, monthScore: 260, serviceCount: 25, satisfaction: 4 },
  { id: 4, rank: 4, name: "赵六", department: "华南大区·深圳组", totalScore: 2080, monthScore: 240, serviceCount: 22, satisfaction: 3 },
  { id: 5, rank: 5, name: "钱七", department: "华东大区·杭州组", totalScore: 1950, monthScore: 220, serviceCount: 19, satisfaction: 5 },
];

const list = ref([]);
const total = ref(0);
const page = ref(1);
const pageSize = ref(10);
const loading = ref(false);
const filters = reactive({ name: "", month: "" });

const loadList = async () => {
  loading.value = true;
  try {
    await new Promise((r) => setTimeout(r, 200));
    list.value = MOCK_LIST;
    total.value = MOCK_LIST.length;
  } finally {
    loading.value = false;
  }
};

const onSearch = () => { page.value = 1; loadList(); };
const onReset = () => { filters.name = ""; filters.month = ""; onSearch(); };
const onDetail = (row) => ElMessage.info(`${row.name} - ${$t('points.detail')}`);

onMounted(loadList);
</script>

<style scoped lang="scss">
.filter-form {
  margin-bottom: 12px;
}
.pagination {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}
.score-num {
  font-weight: 600;
  color: #f56c6c;
}
</style>
