<template>
  <div id="app" style="width: 100vw">
    <keep-alive :include="['case']">
      <router-view />
      12312
    </keep-alive>
    <!-- 添加AI Call组件 -->
    <AICall
      :dialogVisible="showAICall"
      @close="onCloseAICall"
      @restore="onRestoreAICall"
    />
  </div>
</template>

<script>
  import { mapGetters, mapState } from 'vuex';
  import AICall from '@/views/portal/case/AICall.vue';

  export default{
    name:  'App',
    components: {
      AICall
    },
    computed: {
      ...mapGetters(['userInfo']),
      ...mapState('app', ['showAICall', 'showAICallMinimized'])
    },
    methods: {
      onCloseAICall() {
        // 通过Vuex关闭AI Call组件
        this.$store.dispatch('app/setShowAICall', false);
      },

      onRestoreAICall() {
        // 通过Vuex显示AI Call组件
        this.$store.dispatch('app/setShowAICall', true);
      },

      // 检查当前路由是否应该显示AI弹窗
      checkRouteForAICall() {
        const currentRoute = this.$route.name;
        // 只在case或caseDetail路由显示弹窗
        if (currentRoute === 'case' || currentRoute === 'caseDetail') {
          // 设置最小化窗口显示状态为true
          this.$store.dispatch('app/setShowAICallMinimized', true);
          // 注意：这里不再强制设置showAICall为true，保留用户之前的操作状态
        } else {
          // 其他路由关闭弹窗
          this.$store.dispatch('app/setShowAICall', false);
          // 设置最小化窗口显示状态为false
          this.$store.dispatch('app/setShowAICallMinimized', false);
        }
      }
    },
    mounted() {
      //从状态值中取,因为登录处理，所以移动watch中
      // console.log(this.userInfo);
      // if(this.userInfo && this.userInfo.name!=''){
      //   this.$watermark.set(this.userInfo.name+this.userInfo.loginName);
      // }

      // 初始化检查路由
      this.checkRouteForAICall();
    },
    watch: {
      // 监听路由变化
      $route(to, from) {
        this.checkRouteForAICall();
      }
    }
    // watch:{
    //   userInfo(newVal,oldVal){
    //     if(newVal && newVal.name!=''){
    //       this.$watermark.set(newVal.name+newVal.loginName);
    //     }
    //   }
    // }
  }
</script>
<style lang="scss">
  .u-page{
    padding: 10px;
  }
.text-tooltip{
    background: #efeff1 !important;
    border: 1px solid #e7e7e7 !important;
    box-shadow: 0px 1px 5px 1px rgba(92,98,111,.3);
}

#app {
  pointer-events: none;
}

#app > *:not(.case-expert-dialog) {
  pointer-events: auto;
}

.case-expert-dialog {
  pointer-events: auto;
}
</style>