<script lang="ts" setup>
import {ref, onMounted,watch,computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { dvMainStoreWithOut } from '@/store/modules/data-visualization/dvMain'
import { storeToRefs } from 'pinia'
import { useAppStoreWithOut } from '@/store/modules/app'
import { useEmbedded } from '@/store/modules/embedded'

const props = defineProps({
  projectInfo: {
    type: String,
    default: ''
  },
  treeInfo: {
    type: String,
    default: ''
  }
})
const treeInfo:any = ref({})
const appStore = useAppStoreWithOut()
const embeddedStore = useEmbedded()
const dvMainStore = dvMainStoreWithOut()
const { dvInfo } = storeToRefs(dvMainStore)
const isDataEaseBi = computed(() => appStore.getIsDataEaseBi)
const projectInfo:any=ref({
  
})
watch(() => props.projectInfo, (val:any) => {
  projectInfo.value = val
})

watch(() => props.treeInfo, (val:any) => {
  treeInfo.value = val
})


onMounted(()=>{
  projectInfo.value = props.projectInfo
})
function designClick(){
  console.log(treeInfo.value,projectInfo.value)
  if(treeInfo.value.type == '03'){
    window.open('/#/dvsCanvas?dvId=' + treeInfo.value.id+'&appId=' + projectInfo.value.id,  '_blank');
  }else if(treeInfo.value.type == '0301'){
    window.open('/#/dashboard?resourceId=' + treeInfo.value.id + '&appId='+projectInfo.value.id, '_blank');
  }else if(treeInfo.value.type == '04'||treeInfo.value.type == '05'||treeInfo.value.type == '06'|| treeInfo.value.type == '09'){
    window.open('/#/formcreatedesigner?moduleId=' +treeInfo.value.id + '&appId='+projectInfo.value.id,  '_blank');
  }else if(treeInfo.value.type == '01'){
    window.open('/#/editLogin?dvId=' +treeInfo.value.id + '&appId='+projectInfo.value.id+ '&name='+projectInfo.value.name+ '&appname='+projectInfo.value.name,  '_blank');
  }else if(treeInfo.value.type == '02'){
    window.open('/#/editNavbar?dvId=' +treeInfo.value.id + '&appId='+projectInfo.value.id+ '&name='+projectInfo.value.name+ '&appname='+projectInfo.value.name,  '_blank');
  }
}
//预览
const previewpage=()=>{
  if(dvInfo.value.id !== null){
    const baseUrl = isDataEaseBi.value ? embeddedStore.baseUrl : ''
    const url = baseUrl + '#/preview?dvId=' + dvInfo.value.id + '&ignoreParams=true'
    const newWindow = window.open(url, '_blank')
    initOpenHandler(newWindow)
  }
}
const openHandler = ref(null)
const initOpenHandler = newWindow => {
  if (openHandler?.value) {
    const pm = {
      methodName: 'initOpenHandler',
      args: newWindow
    }
    openHandler.value.invokeMethod(pm)
  }
}
</script>
<template>
<div class="project-header-box">
  <div class="project-header-left">
    <div class="return-box" @click="$router.go(-1)">
      <img src="@/assets/newimg/u594.png" alt="">
    </div>
    <img src="@/assets/newimg/logosmall.png" alt="" style="margin-left: 10px;">
    <div class="header-title">{{projectInfo.name  }}</div>
  </div>
  <div class="project-header-right">
    <div class="preview-button" @click="previewpage">预览</div>
    <div class="design-button" @click="designClick">设计</div>
  </div>
</div>
</template>

<style lang="less" scoped>
.project-header-box{
  width: 100%;
  height: 60px;
  background-color: rgba(37, 38, 38, 1);
  box-sizing: border-box;
  border-bottom: 1px solid rgba(79, 80, 82, 1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-sizing: border-box;
  padding: 0 10px;
  .project-header-left{
    display: flex;
    align-items: center;
  }
  .project-header-right{
    display: flex;
    align-items: center;
  }
  .return-box{
    display: flex;
    justify-content: center;
    align-items: center;
    width: 36px;
    height: 36px;
    cursor: pointer;
  }
  .return-box:hover{
    background-color: rgba(255, 255, 255, 0.1);
  }
  .header-title{
    font-family: 'Arial Negreta', 'Arial Normal', 'Arial';
    font-weight: 700;
    font-style: normal;
    font-size: 16px;
    color: #F2F4F5;
    padding-left: 14px;
  }
  .preview-button{
    width: 60px;
    height: 30px;
    line-height: 30px;
    background-color: rgba(54, 55, 56, 1);
    border: none;
    border-radius: 4px;
    font-family: 'Arial Normal', 'Arial';
    font-weight: 400;
    font-style: normal;
    font-size: 14px;
    color: #F2F4F5;
    text-align: center;
    cursor: pointer;
  }
  .design-button{
    width: 60px;
    height: 30px;
    line-height: 30px;
    background-color: rgba(0, 137, 255, 1);
    border: none;
    border-radius: 4px;
    font-family: 'Arial Normal', 'Arial';
    font-weight: 400;
    font-style: normal;
    font-size: 14px;
    color: #F2F4F5;
    text-align: center;
    margin-left: 10px;
    cursor: pointer;
  }
}
</style>
