<template>
  <div class="index-container">
    <div class="header">
      <div class="hot-search">
        <h1 class="title">{{ $t('hotSearch') }}</h1>
        <div class="row">
          <div class="item" v-for="(item, i) of hotRecommend" :key="item.shopId" @click="handleHot(item)">
            <img class="medal" v-if="i === 0" src="./fir.svg" />
            <img class="medal" v-if="i === 1" src="./sec.svg" />
            <img class="medal" v-if="i === 2" src="./thi.svg" />
            <div class="text">{{ item.shopName }}</div>
          </div>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="r1">
        <div class="guide" @click="goPage({ title: '地图导览', path: '/guide' })">
          <div class="top">
            <div class="title">找店</div>
            <div class="meta">{{ guideDesc }}</div>
            <img src="./guideImg.svg" />
          </div>
          <div class="meta1">当前位置<img src="./pos.svg" /></div>
          <div class="meta2">{{ bf }}</div>
          <div class="bottom-right"></div>
        </div>
      </div>
      <div class="r2">
        <div class="item" v-for="tab of sidebarList" :key="tab.title" @click="goPage(tab)">
          <div class="icon"><img :src="tab.icon" /></div>
          <div class="title">{{ switchLanguage(tab, 'title') }}</div>
        </div>
      </div>
      <!-- <div class="cards pos">
        <div class="card" @click="handleCard(item)" v-for="item of cardsList" :key="item.moduleType">
          <h1 class="name">{{ item.name }}</h1>
          <h1 class="sub-title">{{ item.nameEn }}</h1>
          <p class="introduce">{{ switchLanguage(item, 'introduce') }}</p>
          <img :src="config.sourceUrl + item.crossFileUrl" alt="" class="bg" />
        </div>
      </div> -->
    </div>

    <router-view />
  </div>
</template>

<script setup>
import { computed, ref } from 'vue'
import { useRouter } from 'vue-router'
import { storeToRefs } from 'pinia'
import { useStore } from '@/store/root'
import { getBrandList } from '@/http/brand/api'

const router = useRouter()
const store = useStore()
const { indexList, currentFloor, buildingList, shopList, sidebarList, selectedModule } = storeToRefs(store)
const guideDesc = ref('')

const hotRecommend = computed(() => indexList.value.hotSearch.slice(0, 5) ?? [])
const cardsList = computed(() => indexList.value.columnList ?? [])
const bf = computed(() => (buildingList.length > 1 ? currentFloor.value.building + '-' : '') + currentFloor.value.floor)

getBrandList().then(({ data: { allShopNum, industryFatherList } }) => {
  const spFormat = industryFatherList.find(({ isSpecial }) => isSpecial)
  guideDesc.value = `全场${allShopNum}个品牌${spFormat ? `，其中${spFormat.shopNum}个${spFormat.industryName}品牌` : ''}`
})

const goPage = item => {
  store.SET_SELECTED_MODULE(item.title)
  router.push(item.path)
}

function handleCard(item) {
  router.push('/index/waterfall?type=' + item.moduleType)
}

function handleHot(item) {
  const shop = shopList.value.find(_shop => _shop.shopId === item.shopId)
  store.SET_SHOP(shop)
  store.SET_SHOW_DETAIL(true)
}
</script>

<style lang="scss" scoped>
.index-container {
  display: flex;
  flex-direction: column;
  height: 1920px;
  position: relative;
  .header {
    width: 100%;
    height: 515px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, rgba(255, 255, 255, 0.5) 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.8);
    padding: 392px 0 0 68px;
    .hot-search {
      .title {
        font-style: normal;
        font-weight: 900;
        font-size: 20px;
        line-height: 23px;
        color: rgba(0, 0, 0, 0.8);
      }
      .row {
        margin-top: 16px;
        .item {
          position: relative;
          display: inline-block;
          width: 176px;
          height: 52px;

          background: rgba(255, 255, 255, 0.8);
          border-radius: 100px;
          .text {
            text-align: center;
            font-weight: 900;
            font-size: 16px;
            line-height: 52px;
            color: rgba(0, 0, 0, 0.6);
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
            padding: 0 32px;
          }

          .medal {
            position: absolute;
            width: 32px;
            height: 32px;
            left: 4px;
            top: -10px;
          }
        }
        .item + .item {
          margin-left: 24px;
        }
      }
    }
  }
  .content {
    width: 100%;
    flex: 1;
    background: #dee6f6;
    padding: 40px 68px 0 68px;
    .r1 {
      display: flex;
      height: 557px;
      .guide {
        position: relative;
        width: 339px;
        height: 557px;
        background: linear-gradient(99.5deg, #f0b92b 0%, #f9d556 100%);
        border-radius: 32px;
        overflow: hidden;
        padding: 460px 0 0 40px;

        .top {
          position: absolute;
          top: 0;
          left: 0;
          width: 100%;
          height: 432px;
          background: linear-gradient(180deg, #435acd 0%, #749cf3 100%);
          border-radius: 32px;
          padding: 40px;
          z-index: 1;
          .title {
            font-style: normal;
            font-weight: 900;
            font-size: 56px;
            line-height: 66px;
            color: #ffffff;
          }
          .meta {
            margin-top: 8px;
            font-style: normal;
            font-weight: 700;
            font-size: 16px;
            line-height: 19px;
            color: rgba(255, 255, 255, 0.8);
          }
          img {
            margin-top: 40px;
            width: 259px;
          }
        }
        .bottom-right {
          position: absolute;
          width: 108px;
          height: 156px;
          right: 0;
          bottom: 0;
          background: rgba(255, 255, 255, 0.2);
        }
        .meta1 {
          display: inline-flex;
          font-weight: 700;
          font-size: 20px;
          line-height: 23px;
          color: rgba(0, 0, 0, 0.6);
          margin-bottom: 6px;
          img {
            width: 20px;
            height: 20px;
            margin-left: 4px;
          }
        }
        .meta2 {
          font-weight: 900;
          font-size: 32px;
          line-height: 38px;
          color: #000000;
        }
      }
    }
    .r2 {
      display: flex;
      margin-top: 40px;
      .item {
        display: flex;
        flex-direction: column;
        flex: 1;
        height: 151px;
        justify-content: space-between;
        .icon {
          display: flex;
          justify-content: center;
          align-items: center;
          height: 118px;
          background: #ffffff;
          border-radius: 24px;
          img {
            width: 80px;
            height: 80px;
          }
        }
        .title {
          font-weight: 700;
          font-size: 18px;
          line-height: 21px;
          text-align: center;
          color: rgba(0, 0, 0, 0.8);
        }
      }
      .item + .item {
        margin-left: 24px;
      }
    }
  }

  .text {
    font-size: 88px;
    font-weight: 700;
    font-family: 'font_bold';
    color: var(--color-white-opacity);
    text-transform: uppercase;
    i {
      font-size: 60px;
    }
  }
  .text-en {
    font-size: 117px;
    color: var(--color-white-opacity);
    font-weight: 700;
    text-transform: uppercase;
    font-family: 'font_bold';
  }
  .top-left {
    margin-bottom: 110px;
  }

  .scroll {
    height: 59px;
    overflow: hidden;
    margin-bottom: 89px;
    border-radius: 50px;
    .scroll-content {
      display: inline-block;
      white-space: nowrap;
      .recommend-item {
        display: inline-block;
        height: 59px;
        padding: 0 32px;
        font-weight: 700;
        font-family: 'font_bold';
        font-size: 16px;
        line-height: 59px;
        text-align: center;
        color: var(--color-black-opacity-6);
        background: var(--color-white-opacity);
        border-radius: 50px;
        margin-right: 16px;
      }
    }
  }
  .cards {
    display: flex;
    justify-content: center;
    .card {
      position: relative;
      margin-right: 23px;
      padding: 56px 0 0 40px;
      width: 275px;
      height: 564px;
      background: #ffffff;
      box-shadow: 0px 40px 60px rgba(0, 0, 0, 0.04);
      border-radius: 24px;

      .name {
        font-weight: 700;
        font-size: 40px;
        line-height: 47px;
        font-family: 'font_bold';
        color: var(--color-black-opacity-8);
        padding-bottom: 8px;
      }
      .sub-title {
        font-weight: 700;
        font-family: 'font_bold';
        font-size: 24px;
        line-height: 28px;
        text-transform: uppercase;
        color: var(--color-black-opacity-4);
        padding-bottom: 49px;
      }
      .introduce {
        font-size: 18px;
        line-height: 150%;
        color: var(--color-black-opacity-4);
      }
      .bg {
        position: absolute;
        bottom: 0;
        right: 0;
        width: 279px;
      }
    }
  }
}
</style>
