<template>
  <AppCard :title="title" style="margin-top: 50px">
    <template #header-aside><nuxt-link :to="baseUrl" v-if="baseUrl">查看更多+</nuxt-link></template>
    <div :class="className ? className : 'project-list'">
      <div class="project-item" v-for="(item, index) in list" :key="index">
        <!-- <AppLink :data="item"><img :src="item.imgUrl"/></AppLink> -->
        <div
          class="project-item-pic"
          :style="
            isEn
              ? `background:url(${item.imgUrlEn}) no-repeat center / 100% 100%;`
              : `background:url(${item.imgUrl}) no-repeat center / 100% 100%; `
          ">
          <!-- <img :src="item.imgUrl" /> -->
          <ul class="tools">
            <li @click="handleSubmit(item)">{{ isEn ? 'Register' : '我要报名' }}</li>
            <li>
              <AppLink :data="item">{{ isEn ? 'Learn more' : '了解详情' }}</AppLink>
            </li>
          </ul>
        </div>

        <!-- <div class="tools">
          <el-button type="primary" @click="handleSubmit(item)">我要报名</el-button>
          <AppLink :data="item" style="margin-left:20px;">
            <el-button plain type="primary">了解详情</el-button>
          </AppLink>
        </div> -->
      </div>
    </div>
  </AppCard>
</template>
<script setup>
defineOptions({
  name: 'ProjectCard',
})

const props = defineProps({
  list: { type: Array, default: () => [] },
  title: String,
  baseUrl: String,
  className: String,
})

const { locale } = useI18n()
const isEn = computed(() => locale.value === 'en-US')

const handleSubmit = (data) => {
  if (data.onClick) {
    data.onClick()
  } else {
    const formEl = document.querySelector('#form')
    if (!formEl) return
    window.scrollTo(0, formEl.offsetTop)
  }
}
</script>

<style lang="scss" scoped>
.project-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  row-gap: 20px;
  column-gap: 20px;
  .project-item {
    background-color: #fff;
    .project-item-pic {
      height: 360px;
      overflow: hidden;
      position: relative;
    }
    img {
      width: 100%;
    }
    &:hover {
      box-shadow: 0px 3px 24px rgba(0, 0, 0, 0.3);
    }
    .tools {
      position: absolute;
      bottom: 20px;
      left: 0;
      display: flex;
      justify-content: center;
      width: 100%;

      li {
        flex: 1;
        font-size: 16px;
        font-weight: 400;
        color: #4d4d4d;
        text-align: center;
        cursor: pointer;
        // &:hover {
        //   font-weight: 500;
        //   color: #333333;
        // }
      }
      li:first-child {
        color: #af1c40;
      }
      li + li {
        border-left: 1px solid #c9c9c9;
      }
    }
  }
}
.project-list2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  row-gap: 37px;
  column-gap: 37px;
  .project-item {
    background-color: #fff;
    .project-item-pic {
      height: 230px;
      overflow: hidden;
      position: relative;
    }
    img {
      width: 100%;
    }
    &:hover {
      box-shadow: 0px 3px 24px rgba(0, 0, 0, 0.3);
    }
    .tools {
      position: absolute;
      bottom: 15px;
      right: 0;
      display: flex;
      justify-content: center;
      width: 350px;

      li {
        flex: 1;
        font-size: 16px;
        font-weight: 400;
        color: #4d4d4d;
        text-align: center;
        cursor: pointer;
        // &:hover {
        //   font-weight: 500;
        //   color: #333333;
        // }
      }
      li:first-child {
        color: #af1c40;
      }
      li + li {
        border-left: 1px solid #c9c9c9;
      }
    }
  }
}
</style>
