<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-800 dark:text-white">
        {{ title || '友情链接' }}
      </h2>
      <div class="sub-title">
        <p class="text-gray-400 text-sm dark:text-gray-400 py-3">
          {{ comments || 'Link' }}
        </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 hidden-sm-and-down">
        <nuxt-link :to="`${item.url}`" class="flex-1 cursor-pointer flex flex-col text-center" target="_blank">
          <el-card :body-style="{ padding: '0px' }" class="items-center flex justify-center" shadow="hover"
                   @mouseleave="hideMenu" @mouseover="showMenu(item)">
            <div class="flex-1 py-5 sm:p-4 !p-4">
              <el-space class="text-gray-700 dark:text-white text-base font-semibold h-[28px] flex justify-center items-center">
                <el-image v-if="item.icon" :alt="item.name" :src="item.icon" style="height: 30px"/>
                <span :title="item.name" class="line-clamp-1  text-sm lg:text-lg">{{ item.name }}</span>
              </el-space>
            </div>
          </el-card>
        </nuxt-link>
      </el-col>
      <el-col v-for="(item,index) in list" :key="index" :sm="6" :xs="12" class="left mb-2 hidden-sm-and-up">
        <nuxt-link :to="`${item.url}`" class="flex-1 cursor-pointer flex flex-col text-center" target="_blank">
          <el-card :body-style="{ padding: '0px' }" class="items-center flex justify-center" shadow="hover"
                   @mouseleave="hideMenu" @mouseover="showMenu(item)">
            <div class="flex-1 py-1 sm:p-0 !p-0">
              <el-space class="text-gray-700 dark:text-white text-base font-semibold h-[28px] flex justify-center items-center">
                <el-image v-if="item.icon" :alt="item.name" :src="item.icon" style="height: 30px"/>
                <span :title="item.name" class="line-clamp-1  text-sm lg:text-lg">{{ item.name }}</span>
              </el-space>
            </div>
          </el-card>
        </nuxt-link>
      </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";
import {pageCmsLink} from "~/api/cms/cmsLink";
import type {CmsLink} from "~/api/cms/cmsLink/model";

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<CmsLink[]>([]);
const id = ref<number>(0);

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

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

// 请求数据
const reload = async () => {
  pageCmsLink({limit: 36}).then(data => {
    list.value = data?.list || [];
  })
}
reload();
</script>
