<template>
  <ScrollView :list="list" class="search-result-scroll" :scrollbar="true">
    <div class="scroll-result">
      <h1 class="title">
        {{ $t('pinpai') }}
        <div>
          <i>{{ $t('result') }}</i>
          <b>{{ list.length }}</b>
        </div>
      </h1>
      <TransitionGroup name="zoom" tag="div" class="list">
        <SearchResultItem :config="config" @click="handleShop" :shop="item" v-for="item of list" :key="item.shopId" />
      </TransitionGroup>
      <template v-if="activities.length">
        <h1 class="title">
          {{ $t('act') }}
        </h1>
        <div class="activity">
          <div class="activity-item" @click="handleActivity(item)" v-for="item of activities" :key="item.activityId">
            <div class="img-wrapper">
              <img class="img" :src="config.sourceUrl + item.fileUrl" alt="" />
            </div>
            <div class="flex">
              <p class="activity-name">{{ switchLanguage(item, 'activityName') }}</p>
              <p class="intro">{{ $t('youxiaoqi') }}：{{ item.endDate }}</p>
            </div>
          </div>
        </div>
      </template>
    </div>
  </ScrollView>
</template>

<script setup>
import { computed } from 'vue'
import ScrollView from '@/base/ScrollView/ScrollView.vue'
import SearchResultItem from '@/components/SearchResultItem/SearchResultItem.vue'

const props = defineProps({
  list: {
    type: Array,
    default: () => []
  },
  config: {
    type: Object,
    default: () => ({})
  }
})
const emits = defineEmits(['handle-shop', 'handle-activity'])

const shop = computed(() => props.list.filter(item => item.activityList?.length) ?? [])
const activities = computed(() => shop.value.map(item => item.activityList).flat(Infinity) ?? [])

function handleShop(item) {
  emits('handle-shop', item)
}

function handleActivity(item) {
  emits('handle-activity', item)
}
</script>

<style lang="scss" scoped>
.search-result-scroll {
  position: relative;
  height: 1118px;
  overflow: hidden;
  margin-left: 80px;
  .scroll-result {
    padding-bottom: 200px;
  }

  .list {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 44px;
  }
  .activity {
    display: flex;
    flex-wrap: wrap;
    .flex {
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }
    .pl-24 {
      padding-left: 24px;
    }
    .activity-item {
      display: flex;
      align-items: center;
      padding: 0 8px;

      width: 457px;
      height: 84px;
      background: rgba(255, 255, 255, 0.8);
      border-radius: 12px;
      margin-right: 6px;
      margin-bottom: 8px;
      .activity-name {
        font-weight: 700;
        font-size: 18px;
        color: rgba(0, 0, 0, 0.6);
        font-family: 'font_bold';
        padding-bottom: 16px;
      }
      .intro {
        color: rgba(0, 0, 0, 0.6);
        font-size: 14px;
      }
      .img-wrapper {
        width: 120px;
        height: 68px;
        margin-right: 24px;
        border-radius: 8px;

        .img {
          width: 100%;
          height: 100%;
          border-radius: 8px;
          object-fit: cover;
        }
      }
    }
  }
  .title {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    font-size: 24px;
    color: rgba(0, 0, 0, 0.6);
    font-family: 'font_bold';
    margin-bottom: 24px;
    padding-right: 80px;
    i {
      display: inline-block;
      font-weight: 700;
      color: rgba(0, 0, 0, 0.4);
      font-family: 'font_bold';
      font-size: 16px;
      padding-right: 18px;
    }
    b {
      display: inline-block;
      font-weight: 700;
      color: rgba(0, 0, 0, 0.6);
      font-family: 'font_bold';
      font-size: 24px;
    }
  }
  :deep(.bscroll-vertical-scrollbar) {
    width: 6px !important;
    background: rgba(0, 0, 0, 0.02) !important;
    border-radius: 6px !important;
    opacity: 1 !important;
    height: 176px !important;
    .bscroll-indicator {
      height: 95px !important;
      width: 6px !important;
      background: rgba(0, 0, 0, 0.1) !important;
      border-radius: 6px !important;
      border: none !important;
    }
  }
}
</style>
