<template>
  <Dialog @close="back">
    <div class="content" :class="{ active: shop.activityList.length || shop.thirdKouCode }">
      <div class="left">
        <div class="carousel">
          <EffectFade :list="shop.doorMaterialList">
            <template v-slot="{ item }">
              <div class="banner-wrapper">
                <img :src="config.sourceUrl + item" alt="" class="banner" />
              </div>
            </template>
          </EffectFade>
          <div class="like-wrapper" @click="setLike">
            <img :src="showLikeHeart ? require('@/assets/images/detail/like_active.svg') : require('@/assets/images/detail/like.svg')" class="like-icon" alt="" />
            <span class="like-num">{{ likeNumber }}</span>
          </div>
        </div>
        <div class="info-content">
          <div class="shop-info">
            <div class="logo-wrapper">
              <img :src="config.sourceUrl + shop.logoUrl" alt="" class="logo" />
            </div>
            <div class="group" v-if="shop.industryUrl?.length">
              <div class="icon-box">
                <img :src="config.sourceUrl + shop.industryUrl" alt="" />
              </div>
              <div class="group-right">
                <span class="tip-name">业态</span>
                <span class="name">{{ switchLanguage(shop, 'industryFatherName') }}</span>
              </div>
            </div>
            <div class="group" v-if="shop.houseNumber?.length">
              <div class="icon-box">
                <img src="../../assets/images/nav/detail-add.svg" alt="" />
              </div>
              <div class="group-right">
                <span class="tip-name">地址</span>
                <span class="name">{{ shop.houseNumber }}</span>
              </div>
            </div>
            <div class="group" v-if="shop.contact?.length">
              <div class="icon-box">
                <img src="../../assets/images/nav/phone.svg" alt="" />
              </div>
              <div class="group-right">
                <span class="tip-name">电话</span>
                <span class="name">{{ shop.contact }}</span>
              </div>
            </div>
            <div class="group" v-if="shop.businessHours?.length">
              <div class="icon-box">
                <img src="../../assets/images/nav/time.svg" alt="" />
              </div>
              <div class="group-right">
                <span class="tip-name">营业时间</span>
                <span class="name">{{ shop.businessHours }}</span>
              </div>
            </div>
          </div>
          <div class="shop-intro">
            <p class="shop-name">{{ switchLanguage(shop, 'shopName') }}</p>
            <ScrollView class="intro-scroll" scrollbar>
              <p class="intro">{{ switchLanguage(shop, 'intro') }}</p>
            </ScrollView>
          </div>
          <Go class="detail-go" @click="go" />
        </div>
        <div class="lineup-wrapper">
          <div class="lineup-left">
            <h1 class="title-tip">{{ $t('qiandengdai') }}</h1>
            <div class="flex align-center">
              <ScrollView class="lineup-scroll" scroll-x>
                <div class="lineup-content">
                  <div class="flex">
                    <div class="lineup-item" v-for="item of 10" :key="item">
                      <span class="number">12</span>
                      <span class="line-up-text">小桌</span>
                    </div>
                  </div>
                </div>
              </ScrollView>
              <div class="line"></div>
              <p class="abs-money">147<i>￥/人</i></p>
            </div>
          </div>
          <div class="lineup-btn" @click="handleLineupBtn">{{ $t('join') }}</div>
        </div>
      </div>
      <div class="right" v-if="shop.activityList.length || shop.thirdKouCode">
        <Tabs />
      </div>
      <Button class="btn" @click="back" />
      <ThumbQRCode class="thumbs" :title="$t('yuyue')" />
      <Transition enter-active-class="animate__animated animate__zoomIn" leave-active-class="animate__animated animate__zoomOut">
        <QRCode v-if="showLineupQr" @close="showLineupQr = false" />
      </Transition>
    </div>
  </Dialog>
</template>

<script setup>
import { ref, defineAsyncComponent } from 'vue'
import { storeToRefs } from 'pinia'
import { useRouter } from 'vue-router'
import { useStore } from '@/store/root'
import { getBrandLikesNumber, setBrandLikesNumber } from '@/http/api'
import Dialog from '@/layouts/Dialog.vue'
import Button from '@/base/Button/Button.vue'
import EffectFade from '@/components/EffectFade/EffectFade.vue'
import ScrollView from '@/base/ScrollView/ScrollView.vue'
import Go from '@/base/Go/Go.vue'
import ThumbQRCode from '@/base/ThumbQRCode/ThumbQRCode.vue'
import Tabs from './children/tabs.vue'
import { useStatistics } from '@/composables/useStatistics'
const QRCode = defineAsyncComponent(() => import('@/components/QRCode/QRCode.vue'))

const router = useRouter()
const store = useStore()
const { shop, config, showDetail, showSearch, showVoice } = storeToRefs(store)

useStatistics('shop')

const showLikeHeart = ref(false)
const likeNumber = ref(0)
getBrandLikesNumber(shop.value.shopId).then(({ data }) => {
  likeNumber.value = data ?? 0
})

function setLike() {
  setBrandLikesNumber(shop.value.shopId).then(() => {
    showLikeHeart.value = true
    likeNumber.value++
  })
}

const showLineupQr = ref(false)
function handleLineupBtn() {
  showLineupQr.value = true
}

async function go() {
  await router.push('/nav')
  showDetail.value && store.SET_SHOW_DETAIL(false)
  showSearch.value && store.SET_SHOW_SEARCH(false)
  showVoice.value && store.SET_SHOW_VOICE(false)
}

function back() {
  store.SET_SHOW_DETAIL(false)
}
</script>

<style lang="scss" scoped>
.content {
  position: absolute;
  top: 350px;
  left: 50%;
  transform: translate3d(-50%, 0, 0);
  z-index: 2;
  &.active {
    top: 100px;
  }
  &::before {
    content: '';
    position: absolute;
    top: 373px;
    left: 0;
    z-index: 2;
    width: 700px;
    height: 420px;
    background: linear-gradient(180deg, #ffbd35 0%, #ffd260 100%);
    border-radius: 12px;
  }
  .thumbs {
    position: absolute;
    top: 120px;
    right: -156px;
  }

  .detail-go {
    bottom: -90px;
  }
  .left {
    width: 700px;
    .carousel {
      position: relative;
      width: 700px;
      height: 393px;
      background-color: #fff;
      border-radius: 12px;
      overflow: hidden;
      .like-wrapper {
        position: absolute;
        left: 571px;
        top: 32px;
        height: 52px;
        display: flex;
        align-items: center;
        padding: 0 14px;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 54px;

        z-index: 1;
        .like-num {
          padding-left: 8px;
          font-weight: 700;
          font-size: 20px;
          font-family: 'font_bold';
          color: #ffffff;
        }
      }
      :deep(.swiper) {
        overflow: visible !important;
        z-index: auto;
      }
      :deep(.swiper-pagination) {
        right: 32px;
        left: auto;
        bottom: 5px;
        width: auto;
      }
      :deep(.swiper-pagination-bullet) {
        width: 16px !important;
        height: 3px !important;
        background: rgba(0, 0, 0, 0.1);
        border-radius: 3px !important;
        opacity: inherit !important;
        &.swiper-pagination-bullet-active {
          background: rgba(255, 255, 255, 1);
          border-radius: 3px !important;
        }
      }
    }
    .banner-wrapper {
      width: 700px;
      height: 393px;
      border-radius: 12px;
      .banner {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 12px;
      }
    }
    .info-content {
      position: relative;
      display: flex;
      align-items: stretch;
      width: 700px;
      height: 420px;
      margin-top: -20px;
    }
    .shop-info {
      position: relative;
      z-index: 3;
      width: 225px;
      background: rgba(0, 0, 0, 0.02);
      border-radius: 0px 0px 0px 12px;
      padding-left: 32px;
      .logo-wrapper {
        width: 160px;
        height: 160px;
        background: #ffffff;
        box-shadow: 0px 20px 30px rgba(221, 152, 55, 0.5);
        border-radius: 16px;
        padding: 20px;
        margin-bottom: 32px;
        margin-top: -51px;
        .logo {
          width: 100%;
          height: 100%;
          object-fit: contain;
        }
      }
      .group {
        display: flex;
        align-items: center;
        margin-bottom: 18px;
        .icon-box {
          width: 36px;
          height: 36px;
          background: rgba(0, 0, 0, 0.05);
          border-radius: 6px;
          margin-right: 12px;
          padding: 9px;
          img {
            width: 100%;
            height: 100%;
            object-fit: contain;
          }
        }
        .group-right {
          display: flex;
          flex-direction: column;
          justify-content: center;
          .tip-name {
            font-size: 12px;
            transform: scale(0.83);
            color: rgba(0, 0, 0, 0.4);
            padding-bottom: 6px;
          }
          .name {
            font-weight: 700;
            font-family: 'font_bold';
            font-size: 12px;
            line-height: 14px;
            color: rgba(0, 0, 0, 0.6);
          }
        }
      }
    }
    .shop-intro {
      position: relative;
      z-index: 3;
      flex: 1;
      padding-top: 58px;
      padding-left: 40px;
      .shop-name {
        font-weight: 700;
        font-size: 32px;
        line-height: 38px;
        text-align: justify;
        color: rgba(0, 0, 0, 0.8);
        font-family: 'font_bold';
        padding-bottom: 40px;
      }
      .intro-scroll {
        position: relative;
        overflow: hidden;
        height: 207px;
        margin-right: 16px;
        padding-right: 18px;
        .intro {
          font-size: 14px;
          line-height: 200%;
          text-align: justify;
          color: rgba(0, 0, 0, 0.6);
        }
        flex: 1;
        overflow: hidden;
        :deep(.bscroll-vertical-scrollbar) {
          width: 6px !important;
          background: rgba(0, 0, 0, 0.02) !important;
          border-radius: 6px !important;
          opacity: 1 !important;
          height: 200px !important;
          .bscroll-indicator {
            height: 95px !important;
            width: 6px !important;
            background: rgba(0, 0, 0, 0.1) !important;
            border-radius: 6px !important;
            border: none !important;
          }
        }
      }
    }
    .flex {
      display: flex;
    }
    .align-center {
      align-items: flex-end;
    }
    .lineup-wrapper {
      display: flex;
      align-items: flex-end;
      margin-top: -20px;
      padding: 79px 16px 16px 32px;
      background: #ffffff;
      border-radius: 12px;
      .lineup-left {
        flex: 1;
        .title-tip {
          font-weight: 700;
          font-size: 14px;
          font-family: 'font_bold';
          text-align: justify;
          color: rgba(0, 0, 0, 0.4);
          padding-bottom: 15px;
        }
      }
      .lineup-scroll {
        display: flex;
        width: 310px;
        overflow: hidden;
        margin-right: 40px;
        .lineup-content {
          display: inline-block;
          white-space: nowrap;

          .lineup-item {
            display: flex;
            align-items: flex-end;
            margin-right: 24px;
          }
          .number {
            font-weight: 700;
            font-size: 24px;
            line-height: 22px;
            color: rgba(0, 0, 0, 0.6);
            font-family: 'font_bold';
            padding-right: 4px;
          }
          .line-up-text {
            font-weight: 700;
            font-size: 14px;
            line-height: 16px;
            font-family: 'font_bold';
            color: rgba(0, 0, 0, 0.2);
          }
        }
      }
      .line {
        width: 1px;
        height: 20px;
        background: rgba(0, 0, 0, 0.1);
        margin-right: 40px;
      }
      .abs-money {
        font-weight: 700;
        font-family: 'font_bold';
        font-size: 24px;
        text-align: right;
        color: #f1b33e;
        i {
          font-size: 14px;
          color: rgba(0, 0, 0, 0.2);
        }
      }
      .lineup-btn {
        background: linear-gradient(90deg, #f6a62c 0%, #ffbc3f 100%);
        box-shadow: 0px 8px 20px rgba(221, 152, 55, 0.2);
        border-radius: 24px;
        width: 128px;
        height: 37px;
        font-weight: 700;
        font-family: 'font_bold';
        font-size: 14px;
        line-height: 37px;
        text-align: center;
        color: #fff;
      }
    }
  }
  .right {
    width: 700px;
    flex: 1;
    margin-top: 40px;
  }
  .btn {
    position: absolute;
    top: 0;
    right: -120px;
  }
}
</style>
