<template>
  <div class="home-container AI-Design-container">
    <div class="header" v-if="loginMode === 'codeLogin' || agentFrom === 'zhsc'">
      <van-nav-bar title="首页"></van-nav-bar>
    </div>
    <div class="header" v-if="loginMode === 'wxidLogin' && agentFrom !== 'zhsc'">
      <van-nav-bar title="首页" left-arrow @click-left="returnPage" @click-right="toHome">
        <template #right>
          <van-icon name="wap-home-o" color="#333" size="26" />
        </template>
      </van-nav-bar>
    </div>
    <!-- 顶部装饰背景图 -->
    <div class="top-bg">
      <img v-show="currentTab === 'inside'" src="@/assets/AIDesign/top-inside.jpg" class="bg-image" />
      <img v-show="currentTab === 'outside'" src="@/assets/AIDesign/top-outside.jpg" class="bg-image" />
    </div>

    <!-- 新版tab -->
    <div class="new-tab-wrapper" :class="currentTab === 'outside' ? 'outside-tab-bg' : 'inside-tab-bg'">
      <div class="tab-title" @click="currentTab = 'outside'"></div>
      <div class="tab-title" @click="currentTab = 'inside'"></div>
    </div>

    <!-- 外墙-功能卡片区域 -->
    <div class="feature-cards" v-show="currentTab === 'outside'">
      <!-- 我要设计 -->
      <div class="card card-design" @click="handleDesignClick('outside')">
        <div class="card-content">
          <div class="card-title" style="color: #512E79;">我要设计</div>
          <div class="card-desc" style="color: #7F639E;">AI在线生图，快速预览效果</div>
        </div>
        <div class="card-icon">
          <img src="@/assets/AIDesign/design-robot.png" alt="设计图标" />
        </div>
      </div>

      <!-- 一键诊断 -->
      <div class="card card-diagnosis" @click="handleDiagnosisClick('outside')">
        <div class="card-content">
          <div class="card-title" style="color: #2F655B;">一键诊断</div>
          <div class="card-desc" style="color: #6D9587;">AI诊断墙面问题，提供解决方案</div>
        </div>
        <div class="card-icon">
          <img src="@/assets/AIDesign/diagnosis-printer.png" alt="诊断图标" />
        </div>
      </div>

      <!-- 五行推荐 -->
      <!-- <div class="card card-five-element" @click="handleFiveElementClick">
        <div class="card-content">
          <div class="card-title" style="color: #635A30;">五行推荐(规划中)</div>
          <div class="card-desc" style="color: #8F865B;">根据五行推荐最适合的颜色</div>
        </div>
        <div class="card-icon">
          <img src="@/assets/AIDesign/five-element-planet.png" alt="五行图标" />
        </div>
      </div> -->
    </div>

    <!-- 内墙-功能卡片区域 -->
    <div class="feature-cards" v-show="currentTab === 'inside'">
      <!-- 我要设计 -->
      <div class="card card-design" @click="handleDesignClick('inside')">
        <div class="card-content">
          <div class="card-title" style="color: #512E79;">我要设计</div>
          <div class="card-desc" style="color: #7F639E;">AI在线生图，快速预览效果</div>
        </div>
        <div class="card-icon">
          <img src="@/assets/AIDesign/design-robot.png" alt="设计图标" />
        </div>
      </div>

      <!-- 一键诊断 -->
      <div class="card card-diagnosis" @click="handleDiagnosisClick('inside')">
        <div class="card-content">
          <div class="card-title" style="color: #2F655B;">一键诊断</div>
          <div class="card-desc" style="color: #6D9587;">AI诊断墙面问题，提供解决方案</div>
        </div>
        <div class="card-icon">
          <img src="@/assets/AIDesign/diagnosis-printer.png" alt="诊断图标" />
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { Component, Vue } from "vue-property-decorator";
import { toLBHome, getWxconfig, getWecomType, checkAndSaveUserWecomType } from '@/utils/index';
import axios from "axios";
declare let wx: any;
@Component
export default class extends Vue {
  private currentTab = 'outside';
    private agentFrom = '';
  // 入口新判断
  created() {
    getWxconfig();
    this.loginMode = window.localStorage.getItem("loginMode") || 'codeLogin';
    const agentFrom = window.localStorage.getItem('agentFrom');
    this.agentFrom = agentFrom;
    // 经销商随身邦，好邦手进去，默认在内墙空间;服务商进去，默认外墙空间
    if (agentFrom === 'ssb' || agentFrom === 'hbs') {
      this.currentTab = 'inside';
    } else {
      this.currentTab = 'outside';
    }
    checkAndSaveUserWecomType()
  }
  handleTabChange(tabType: 'outside' | 'inside'): void {
    this.currentTab = tabType;
  }
  returnPage() {
    toLBHome();
  }
  toHome() {
    toLBHome()
  }
  // 点击事件处理
  handleDesignClick(type) {
    if (type === 'outside') {
      // 外墙设计页
      this.$router.push("/AIDesign/design");
    } else if (type === 'inside') {
      // 内墙设计页
      this.$router.push("/AIDesign/insideDesign");
    }
  }

  handleDiagnosisClick(wallType) {
    // if (wallType === "outside") {
    //   this.$toast('规划中，敬请期待');
    //   return;
    // }
    this.$router.push({ path: '/AIDesign/diagnose', query: { wallType } });
  }

  handleFiveElementClick() {
    this.$toast('规划中，敬请期待');
    // this.$router.push("/AIDesign/five-element");
  }

}
</script>

<style scoped lang="scss">
.home-container {
  /* padding: 20px; */
  background-color: #f7f7f7;
  min-height: 100vh;
  flex-direction: column;
}

/* 顶部背景图 */
.top-bg {
  font-size: 0;
  line-height: 0;
  position: relative;

  .bg-image {
    width: 100%;
    height: auto;
    /* object-fit: cover; */
  }
}



/* 标题样式 */
.smart-space-title {
  padding: 0 20px;
  position: relative;
  font-size: 20px;
  font-weight: bold;
  color: #333;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.smart-space-title-new {
  display: flex;
  justify-content: space-between;
  // background-color: #dce0ea;
  background-color: #d9e0ef;
  height: 5.5rem;
  line-height: 5.5rem;
  margin-bottom: 3rem;
  padding-top: 1.8rem;
  position: relative;
  top: -2px;

  .tab-title {
    flex: 1;
    text-align: center;
    font-size: 20px;
    font-weight: bold;
    color: #333;
    position: relative;
    z-index: 0;
  }
}

.new-tab-wrapper {
  width: 100%;
  height: 60px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .tab-title {
    width: 50%;
    height: 100%;
  }
}

.outside-tab-bg {
  background: url('../../assets/AIDesign/tab1.png') no-repeat;
  background-size: 100% auto;
}

.inside-tab-bg {
  background: url('../../assets/AIDesign/tab2.png') no-repeat;
  background-size: 100% auto;
}

/* 功能卡片容器 */
.feature-cards {
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* 卡片通用样式 */
.card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-radius: 16px;
  cursor: pointer;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.card:hover {
  transform: translateY(-2px);
}

.card-content {
  flex: 1;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: #333;
}

.card-desc {
  font-size: 12px;
  color: #666;
  margin-top: 4px;
}

.card-icon {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon img {
  width: 80px;
  height: 80px;
}

/* 各卡片背景色 */
.card-design {
  background: linear-gradient(135deg, #e6e6ff, #f0f0ff);
  /* border: 1px solid #d0d0ff; */
}

.card-diagnosis {
  background: linear-gradient(135deg, #e6ffe6, #f0fff0);
  /* border: 1px solid #c0ffc0; */
}

.card-five-element {
  margin-bottom: 1rem;
  background: linear-gradient(135deg, #fff8e6, #fff0e6);
  /* border: 1px solid #ffd0c0; */
}

.header {
  /*height: 50px;*/
  /*line-height: 50px;*/
  /*text-align: center;*/
  /*background: #fff;*/
  border-bottom: 1px solid #f8f8f8;

  .van-nav-bar__title {
    font-size: 20px;
    color: #333;
  }

  .van-icon {
    font-size: 20px;
    color: #333 !important;
  }
}
</style>