<template>
  <div class="agent-wrap">
    <a-input
      style="float: right; width: 300px"
      v-model="query.name"
      @blur="getData()"
      placeholder="搜索智能体"
      size="medium"
      allow-clear
    >
      <template #prefix>
        <icon-search />
      </template>
    </a-input>
    <div v-for="(item, index) in list" :key="index">
      <span class="span-title">{{ item.name }}</span>
      <a-row class="grid-demo" :gutter="24" v-if="item.agent_products.length > 0">
        <a-col :span="3" v-for="(product, k) in item.agent_products">
          <div class="card-container" @click="goDetail(product?.type, product?.id)">
            <div class="card-image-container">
              <img
                class="card-image"
                :src="product?.icon_url"
                style="width: 100%; height: 100%; object-fit: cover;"
              />
            </div>
            <div class="card-content">
              <div class="card-title">{{ product?.name }}</div>
              <div class="card-description">{{ product?.description }}</div>
            </div>

            <div class="card-footer">
              <div
                :class="['status-tag', product.type === 1 ? 'blue-tag' : 'red-tag']"
                :style="{ background: product.type === 1 ? 'var(--Functional-Blue-1, #E6F3FF)' : 'var(--Functional-Red-1, #FFE9E7)' }"
                data-size="mini-20px"
              >
                <img
                  class="status-icon"
                  :src="product.type === 2 ? workflowIcon : chatbotIcon"
                  alt="状态图标"
                />
                <div class="status-text">{{ product.type === 1 ? '对话式' : '工作流' }}</div>
              </div>
              <div class="usage-info">
                <div class="usage-count">{{ product.views }}</div>
                <div class="usage-label">次使用</div>
              </div>
            </div>
          </div>
        </a-col>
      </a-row>

      <NoData v-else />
    </div>
  </div>
</template>

<script setup lang="ts">
import { useRouter } from 'vue-router';
import { getAgentList } from '@/api/all/agent';
import workflowIcon from '@/assets/svg/workflow.svg';
import chatbotIcon from '@/assets/svg/chatbot.svg';
const router = useRouter();

const list = ref([]);
const getData = async () => {
  const { code, data } = await getAgentList(query);
  list.value = data;
};

const query = reactive({
  name: '',
});
const goDetail = (type: number, id: number) => {
  if (type === 1) {
    router.push({
      path: '/agent/chat',
      query: { id: id },
    });
  } else if (type === 2) {
    router.push({
      path: '/agent/workFlow',
      query: { id: id },
    });
  }
};

onMounted(() => {
  getData();
});
</script>

<style scoped lang="scss">
@import './style.scss';
</style>
