<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 || '' }}
        </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">
        <nuxt-link :to="item.url" class="flex-1 cursor-pointer flex flex-col text-center" target="_blank">
          <img v-if="item.icon" :alt="item.name" :src="item.icon" class="w-full h-[60px]" />
          <el-card v-else :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">
                <span :title="item.name" class="text-lg line-clamp-1">{{ 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: 6}).then(data => {
    list.value = data?.list || [];
  })
}
reload();
</script>
