<template>
  <div class="usage-monitor">
    <!-- 顶部 TabPane，居中显示 -->

    <el-tabs v-model="activeTab" class="tabs-wrapper">
      <el-tab-pane label="在售中" name="onSale" />
      <el-tab-pane label="未上架" name="offShelf" />
      <el-tab-pane label="已失效" name="expired" />
    </el-tabs>

    <!-- 列表内容 -->
    <div class="list-wrapper">
      <div v-for="(p, idx) in filteredProducts" :key="p.id" class="list-item" :class="{ 'has-border': idx > 0 }">
        <!-- 商品图 -->
        <img class="item-img" :src="p.img" alt="商品图" />

        <!-- 名称 + 月售/库存 -->
        <div class="item-info">
          <div class="item-name">{{ p.name }}</div>
          <div class="item-stats">月售 {{ p.monthlySales }} · 库存 {{ p.stock }}</div>
          <div class="item-price">¥ {{ p.price }} /kg</div>
        </div>

        <div class="item-buttom">
          <div class="item-status" :class="statusClass(activeTab)">
            {{ tabLabels[activeTab] }}
          </div>
          <div class="item-actions">
            <el-button size="large" class="button" @click="onInspect(p)">抽查</el-button>
            <el-button size="large" class="button" type="danger" @click="onRevoke(p)">取消授权</el-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue';
import { getAssetsFile } from '@/utils/index.js';
import { getMonitorList } from '@/apis/brand';

const activeTab = ref('onSale');

const tabLabels = {
  onSale: '在售中',
  offShelf: '未上架',
  expired: '已失效',
};

// 示例数据，替换为真实接口数据
const products = ref([
  {
    id: 1,
    name: '耿马镇沙疆西红柿',
    img: getAssetsFile('images/brand/product4.png'),
    monthlySales: 999,
    stock: 10000,
    price: 3.0,
    status: 'onSale',
  },
  {
    id: 2,
    name: '耿马镇沙疆土豆',
    img: getAssetsFile('images/brand/product6.png'),
    monthlySales: 123,
    stock: 5000,
    price: 2.5,
    status: 'onSale',
  },
  {
    id: 3,
    name: '彩椒南瓜混合',
    img: getAssetsFile('images/brand/product1.png'),
    monthlySales: 456,
    stock: 8000,
    price: 4.2,
    status: 'offShelf',
  },
  // … 更多数据
]);

// 根据当前 Tab 过滤
const filteredProducts = computed(() => products.value.filter((p) => p.status === activeTab.value));

// 操作回调
const onInspect = (p) => {
  console.log('抽查商品', p);
};
const onRevoke = (p) => {
  console.log('取消授权', p);
};

// 状态文字的颜色
const statusClass = (tab) => {
  if (tab === 'offShelf') return 'text-warning';
  if (tab === 'expired') return 'text-danger';
  return 'text-success';
};
</script>

<style scoped lang="scss">
.usage-monitor {
  padding: 20px;
  background: #fff;
  border-radius: 16px;
  height: 100%;

  .tabs-wrapper {
    width: 100%;
    display: flex;
    align-items: center;
    background-color: #fff;

    :deep(.el-tabs__item) {
      font-size: 24px;
      font-weight: 700;
      // border: 1 solid #f000;
    }
  }

  .list-wrapper {
    .list-item {
      display: flex;
      justify-content: start;
      align-items: center;
      padding: 20px 0;

      .item-img {
        width: 120px;
        height: 120px;
        object-fit: cover;
        border-radius: 8px;
      }

      .item-info {
        padding-left: 16px;
        // background-color: #909399;
        .item-name {
          font-size: 20px;
          font-weight: 700;
          margin-bottom: 8px;
        }
        .item-stats {
          color: #909399;
          font-size: 14px;
        }
      }

      .item-price {
        font-size: 28px;
        font-weight: 700;
        color: #67c23a;
        text-align: left;
        padding-top: 8px;
      }

      .item-buttom {
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        height: 110px;
        flex: 1;
      }

      .item-actions {
        display: flex;
        justify-content: flex-end;
        gap: 8px;

        .button {
          font-size: 20px;
          font-weight: 400;
          border-radius: 8px;
        }
      }

      .item-status {
        text-align: right;
        font-size: 20px;
        font-weight: 700;
        &.text-success {
          color: #67c23a;
        }
        &.text-warning {
          color: #e6a23c;
        }
        &.text-danger {
          color: #f56c6c;
        }
      }
    }
  }
}
</style>
