<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="8" :xs="24" class="left mb-8">
        <el-card :body-style="{ padding: '0px' }" class="cursor-pointer" shadow="hover">
          <nuxt-link :to="`/market/${item.websiteId}`">
            <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 gap-1.5">
                <el-avatar
                  :size="55" :src="item.websiteLogo" shape="square" style="background-color: white;"/>
                <div class="flex-1 text-lg cursor-pointer flex flex-col">
                  {{ item.websiteName }}
                  <div class="flex justify-between items-center">
                    <sapn class="text-xs text-gray-400 font-normal line-clamp-1">
                      {{ id == item.websiteId ? item.domain : item.comments || '暂无描述' }}
                    </sapn>
                    <el-button round size="small">获取</el-button>
                  </div>
                </div>
              </div>
              <div class="item-image pt-3 overflow-hidden">
                <el-image v-if="item.files" :src="`${JSON.parse(item.files)[0]}`" class="w-full h-1/2 max-h-[220px] transition-transform duration-300 ease-in-out hover:scale-110"/>
                <el-image v-else class="w-full h-[220px]"/>
              </div>
            </div>
          </nuxt-link>
        </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: false,
    plugin: true,
    limit: 8,
    sort: 'websiteId',
    order: 'asc'
  }).then(data => {
    list.value = data?.list || [];
  })
}
reload();
</script>
