<template>
  <div class="xl:w-screen-xl m-auto py-4 px-4 sm:px-0">
    <div class="text-center flex flex-col items-center z-0 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-400 text-sm dark:text-gray-400 py-3">
          {{ comments || '官方开发的应用' }}
        </p>
      </div>
    </div>
    <el-row id="container" :gutter="24" class="clearfix">
      <el-col v-for="(item,index) in list" :key="index" :sm="6" :xs="12" class="left mb-8">
        <el-card :body-style="{ padding: '0px' }" class="h-[180px] items-center flex justify-center" shadow="hover" @mouseleave="hideMenu" @mouseover="showMenu(item)">
          <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">
              <nuxt-link :to="`https://${item.adminUrl}`" target="_blank">
                <el-avatar
                  :size="55" :src="item.websiteLogo" shape="square" style="background-color: white;"/>
              </nuxt-link>
              <div class="flex-1 cursor-pointer flex flex-col text-center">
                <nuxt-link :to="`https://${item.adminUrl}`" class="text-lg" target="_blank">{{ 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://${item.adminUrl}`" target="_blank"><span class="text-gray-400 hover:text-green-700">控制台</span></nuxt-link>
                    <el-divider direction="vertical" />
                    <nuxt-link :to="`/market/${item.websiteId}`"><span class="text-gray-400 hover:text-green-700">详情</span></nuxt-link>
                    <el-divider direction="vertical" />
                    <nuxt-link :to="`/market/${item.websiteId}`"><span class="text-gray-400 hover:text-green-700">评论</span></nuxt-link>
                    <el-divider direction="vertical" />
                    <nuxt-link :to="`/product/code/${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 lang="ts" setup>
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 | any;
      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({
    official: true,
    plugin: true,
    limit: 4,
    sort: 'websiteId',
    order: 'asc'
  }).then(data => {
    list.value = data?.list || [];
  })
}
reload();
</script>
