<template>
  <div class="xl:w-screen-xl sm:flex xl:p-0 p-4 m-auto relative" v-infinite-scroll="load">
    <el-row :gutter="24" class="flex">
      <template v-for="(item,index) in list" :key="index">
        <el-col :span="8" class="mb-5 min-w-xs">
          <el-card shadow="hover" :body-style="{ padding: '0px' }" class="hover:bg-gray-50 cursor-pointer" @click="openSpmUrl(`/item`,item,item.appId,true)">
            <div class="flex-1 px-4 py-5 sm:p-6 !p-4">
              <div class="text-gray-700 dark:text-white flex items-center gap-2">
                <div class="avatar">
                  <el-avatar :src="item.appIcon" shape="square" :lazy="true" :size="48" />
                </div>
                <div class="app-name flex flex-col pb-2">
                  <span class="flex-1 text-xl font-bold">{{ item.appName }}</span>
                  <span class="text-gray-400 text-xs">{{ item.appUrl || item.appCode }}</span>
                </div>
              </div>
              <div class="flex items-center gap-1.5 py-2 text-gray-500 justify-between">
                <span class="text-gray-400 min-h-[50px] overflow-hidden">{{ item.comments }} </span>
              </div>
              <div class="button-group flex justify-center mt-3">
                <el-button class="w-full" @click.stop="addFavorite(item)">加入收藏</el-button>
                <el-button class="w-full" @click.stop="openSpmUrl(`/item`,item,item.appId,true)">查看详情</el-button>
                <el-button v-if="item.appUrl" class="w-full" @click="openSpmUrl(`https://${item.tenantCode}.websoft.top`,item,item.appId,true)">产品控制台</el-button>
                <el-button v-else class="w-full" @click="openSpmUrl(`https://${item.tenantCode}.websoft.top`,item,item.appId,true)">产品控制台</el-button>
              </div>
            </div>
          </el-card>
        </el-col>
      </template>
    </el-row>
  </div>
  <div v-if="disabled" class="px-1 text-center text-gray-500 min-h-xs">
    没有更多了
  </div>
</template>

<script setup lang="ts">
import {openSpmUrl} from "~/utils/common";
import dayjs from "dayjs";
import type {App} from "~/api/oa/app/model";

const props = withDefaults(
    defineProps<{
      list?: App[];
      disabled?: boolean;
    }>(),
    {}
);

const emit = defineEmits<{
  (e: 'done'): void;
}>();

const addFavorite = () => {

}

const load = () => {
  if(!props.disabled){
    emit('done')
  }
}
</script>
