<template>
  <div class="xl:w-screen-xl m-auto py-4">
    <div v-if="title" class="text-center flex flex-col items-center z-100 relative">
      <h2 class="text-4xl font-bold tracking-tight text-gray-500 dark:text-white">
        {{ title }}
      </h2>
      <div class="sub-title">
        <p class="text-gray-500 dark:text-gray-400 py-3">
          {{ comments }}
        </p>
      </div>
    </div>
    <el-row :gutter="24" id="container" class="clearfix">
      <el-col v-for="(item,index) in list" :key="index" :span="6" class="left mb-8">
        <el-card shadow="hover" :body-style="{ padding: '0px' }" class="h-[200px] items-center flex justify-center" @mouseover="showMenu(item)" @mouseleave="hideMenu">
          <div class="flex-1 px-4 py-5 sm:p-4 !p-4">
            <div class="text-gray-700 dark:text-white text-base font-semibold  flex flex-col items-center gap-1.5">
              <el-avatar
                  :src="item.websiteLogo" shape="square" :size="55" style="background-color: white;"/>
              <div class="flex-1 cursor-pointer flex flex-col text-center">
                <nuxt-link :to="`https://${item.websiteCode}.websoft.top`" class="text-lg">{{ item.websiteName }}</nuxt-link>
                <div v-if="id == item.websiteId" class="flex text-gray-400 text-sm font-normal py2 justify-between items-center">
                  <div>
                    <nuxt-link :to="`https://websoft.top/docs?appid=${item.websiteId}`"><span class="text-gray-400 hover:text-green-700">开发文档</span></nuxt-link>
                    <el-divider direction="vertical" />
                    <nuxt-link :to="`https://websoft.top/docs?appid=${item.websiteId}`"><span class="text-gray-400 hover:text-green-700">社区</span></nuxt-link>
                    <el-divider direction="vertical" />
                    <nuxt-link :to="`https://websoft.top/market?appid=${item.websiteId}`"><span class="text-gray-400 hover:text-green-700">插件市场</span></nuxt-link>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
    </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 {navigateTo} from "#imports";
import type {CmsWebsite, CmsWebsiteParam} from "~/api/cms/cmsWebsite/model";
import {pageCmsWebsiteAll} from "~/api/cms/cmsWebsite";

const props = withDefaults(
    defineProps<{
      param?: CmsWebsiteParam;
      disabled?: boolean;
      title?: string;
      comments?: string;
      fit?: any;
    }>(),
    {
      fit: 'cover'
    }
);

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

const list = ref<CmsWebsite[]>([]);
const id = ref<number>(0);

const showMenu = (item: CmsWebsite) => {
  id.value = Number(item.websiteId);
};

const hideMenu = () => {
  id.value = 0;
};

// 请求数据
const reload = async () => {
  pageCmsWebsiteAll(props.param).then(data => {
    list.value = data?.list || [];
  })
}
reload();
</script>
