<script lang="ts" setup>
/**
 * 分类仓储合并列：分区/分类 + 配送仓绑定 + 总仓是否入库
 * Tags 打开绑定列表；「新增绑定」直接走新增表单
 */
import { Tag } from 'ant-design-vue';

defineProps<{
  row: Record<string, any>;
}>();

const emit = defineEmits<{
  category: [row: Record<string, any>];
  bind: [row: Record<string, any>];
  bindCreate: [row: Record<string, any>];
  stockIn: [row: Record<string, any>];
}>();
</script>
<template>
  <div class="category-warehouse-cell">
    <div class="category-warehouse-cell__row">
      <span class="category-warehouse-cell__label">分区</span>
      <a
        class="text-primary cursor-pointer hover:underline"
        @click.stop="emit('category', row)"
      >
        {{ row.zone_name || '未设置' }}
      </a>
    </div>
    <div class="category-warehouse-cell__row">
      <span class="category-warehouse-cell__label">分类</span>
      <a
        class="text-primary cursor-pointer hover:underline"
        @click.stop="emit('category', row)"
      >
        {{ row.category_name || '未设置' }}
      </a>
    </div>
    <div class="category-warehouse-cell__row">
      <span class="category-warehouse-cell__label">配送仓</span>
      <div class="category-warehouse-cell__wh">
        <a
          class="text-primary cursor-pointer hover:underline"
          @click.stop="emit('bind', row)"
        >
          <template
            v-if="row.delivery_warehouses && row.delivery_warehouses.length"
          >
            <Tag
              v-for="w in row.delivery_warehouses"
              :key="w.id"
              class="mb-1 mr-1"
              color="blue"
            >
              {{ w.name }}
            </Tag>
          </template>
          <span v-else class="category-warehouse-cell__muted">未绑定</span>
        </a>
        <a
          class="text-primary cursor-pointer hover:underline category-warehouse-cell__add"
          @click.stop="emit('bindCreate', row)"
        >
          新增绑定
        </a>
      </div>
    </div>
    <div class="category-warehouse-cell__row">
      <span class="category-warehouse-cell__label">入库</span>
      <Tag v-if="row.in_central_warehouse" color="green">已入库</Tag>
      <a v-else @click.stop="emit('stockIn', row)">
        <Tag color="orange" class="cursor-pointer">未入库</Tag>
      </a>
    </div>
  </div>
</template>
<style scoped>
.category-warehouse-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px 0;
  font-size: 13px;
}
.category-warehouse-cell__row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}
.category-warehouse-cell__label {
  flex-shrink: 0;
  width: 42px;
  color: hsl(var(--muted-foreground));
}
.category-warehouse-cell__muted {
  color: hsl(var(--muted-foreground));
}
.category-warehouse-cell__wh {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.category-warehouse-cell__add {
  flex-shrink: 0;
  font-size: 12px;
}
</style>
