<template>
  <section class="app-main">
    <router-view v-slot="{ Component, route }">
      <transition name="fade-transform" mode="out-in">
        <keep-alive :include="tagsViewStore.cachedViews">
          <component v-if="!route.meta.link" :is="Component" :key="route.path"/>
        </keep-alive>
      </transition>
    </router-view>
    <iframe-toggle />
    <el-link :underline="false" class="ai_chat_link" :style="{display: showDiv?'none':'block'}" @click="showDivClick">
      <img src="@/assets/images/aichat.gif"/>
    </el-link>
    <div class="ai_chat_div" v-if="showDiv" :style="aiChatDivStyle">
      <aichat-index :is_large="largeDiv"></aichat-index>
      <div class="ai_chat_div_operate">
        <el-link :underline="false" style="font-size: 20px;" :style="{display:largeDiv?'none':'block'}" @click="littleChatDiv"><i class="ri-collapse-diagonal-line"></i></el-link>
        <el-link :underline="false" style="font-size: 20px;" :style="{display:largeDiv?'block':'none'}" @click="largeChatDiv"><i class="ri-expand-diagonal-line"></i></el-link>
        <el-link :underline="false" style="margin-left: 15px;font-size: 20px" @click="closeChatDiv"><i class="ri-close-large-line"></i></el-link>
      </div>
    </div>
  </section>
</template>

<script setup>
import iframeToggle from "./IframeToggle/index"
import useTagsViewStore from '@/store/modules/tagsView'
import { ref, onMounted, reactive, nextTick, computed } from 'vue'
import AichatIndex from "../../views/aichat/index.vue";

const route = useRoute()
const tagsViewStore = useTagsViewStore()
const showDiv = ref(false)
const largeDiv = ref(true)
const aiChatDivStyle = ref({display: 'none',width: '450px',height: '100%',bottom: '0',right: '0'})


onMounted(() => {
  addIframe()
})

watchEffect((route) => {
  addIframe()
})

function addIframe() {
  if (route.meta.link) {
    useTagsViewStore().addIframeView(route)
  }
}

function largeChatDiv(){
  largeDiv.value = !largeDiv.value
  aiChatDivStyle.value = {display: 'block',width: '50%',height: '100%',bottom: '0',right: '0'}
}

function showDivClick(){
  showDiv.value = !showDiv.value
  aiChatDivStyle.value.display = 'block'
}

function littleChatDiv(){
  largeDiv.value = !largeDiv.value
  aiChatDivStyle.value = {display: 'block',width: '450px',height: '100%',bottom: '0',right: '0'}
}

function closeChatDiv(){
  showDiv.value = !showDiv.value
  aiChatDivStyle.value.display = 'none'
}
</script>

<style lang="scss" scoped>
.app-main {
  /* 50= navbar  50  */
  //min-height: calc(100vh - 50px);
  height: calc(100vh - 84px);
  width: 100%;
  position: relative;
  overflow: auto;
}

.fixed-header + .app-main {
  padding-top: 50px;
}

.hasTagsView {
  .app-main {
    /* 84 = navbar + tags-view = 50 + 34 */
    min-height: calc(100vh - 84px);
  }

  .fixed-header + .app-main {
    padding-top: 84px;
  }
}
</style>

<style lang="scss">
// fix css style bug in open el-dialog
.el-popup-parent--hidden {
  .fixed-header {
    padding-right: 6px;
  }
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background-color: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background-color: #c0c0c0;
  border-radius: 3px;
}
.ai_chat_link {
  position: fixed;
  right: 0;
  bottom: 30px;
  cursor: pointer;
  max-height: 500px;
  max-width: 500px;
  z-index: 10000;
}
.ai_chat_div {
  z-index: 10000;
  border-radius: 8px;
  border: 1px solid #ffffff;
  background: linear-gradient(188deg, rgba(235, 241, 255, 0.20) 39.6%, rgba(231, 249, 255, 0.20) 94.3%), #EFF0F1;
  box-shadow: 0 4px 8px 0 rgba(31, 35, 41, 0.10);
  position: fixed;
  overflow: hidden;
}
.ai_chat_div_operate {
  top: 18px;
  right: 15px;
  position: absolute;
  display: flex;
  align-items: center;
  z-index: 100;
}
</style>

