<template>
  <div class="pptist-editor">
    <EditorHeader class="layout-header" />
    <div class="layout-content">
      <Thumbnails class="layout-content-left" />
      <div class="layout-content-center">
        <CanvasTool class="center-top" />
        <!-- :style="{ height: `calc(100% - ${remarkHeight + 40}px)` }" -->
        <Canvas class="center-body" :style="{ height: `calc(100% - 40px)`}" />
        <!-- <Remark
          class="center-bottom" 
          v-model:height="remarkHeight" 
          :style="{ height: `${remarkHeight}px` }"
        /> -->
        <DataaSource/>
      </div>
      <Toolbar class="layout-content-right" />
    </div>
  </div>

  <SelectPanel v-if="showSelectPanel" />
  <SearchPanel v-if="showSearchPanel" />

  <Modal
    :visible="!!dialogForExport" 
    :width="680"
    @closed="closeExportDialog()"
  >
    <ExportDialog />
  </Modal>
</template>

<script lang="ts" setup>
import { ref, reactive, provide, watch, inject } from 'vue'
import { storeToRefs } from 'pinia'
import { useMainStore, useSlidesStore, useScreenStore } from '@/store'
import useGlobalHotkey from '@/hooks/useGlobalHotkey'
import usePasteEvent from '@/hooks/usePasteEvent'
import { injectKeyDataSource, injectKeyTemplate } from '@/types/injectKey'

import EditorHeader from './EditorHeader/index.vue'
import Canvas from './Canvas/index.vue'
import CanvasTool from './CanvasTool/index.vue'
import Thumbnails from './Thumbnails/index.vue'
import Toolbar from './Toolbar/index.vue'
import Remark from './Remark/index.vue'
import ExportDialog from './ExportDialog/index.vue'
import SelectPanel from './SelectPanel.vue'
import SearchPanel from './SearchPanel.vue'
import Modal from '@/components/Modal.vue'
import DataaSource from './DataaSource/index.vue'
import ConfigService from '@/services/ConfigService'

const slidesStore = useSlidesStore()
const TemplateTypeStore = useScreenStore()
const TempDataSourceStore = useScreenStore()
const { slides, slideIndex } = storeToRefs(slidesStore)
const { TemplateType, ConfigId, TempId} = storeToRefs(TemplateTypeStore)
const pageTypesList = ref([] as any)
const searchData = ref({} as any)
searchData.value = inject(injectKeyTemplate)

let TempIds = 0
if(TempId.value&&!searchData.value.TempId) TempIds = TempId.value
if(searchData.value.TempId) TempIds = searchData.value.TempId
const datas = reactive({
    DataSource:{
        FeatureImgList: [],
        ConfigId: ConfigId.value?ConfigId.value:0,
        pageType: 1,//1基础 2酒店 3景 4餐
        DataSourceOverlay: false,
        DataSourceList:[],
        queryObj:{
          TempId: TempIds,//编号(新增传0)	是	[int]
          LineId: null,//线路Id	是	[int]
          LineName: '',//线路名称	是	[string]
          LtId: null,//系列Id	是	[int]
          Title: '',//名称	是	[string]
          TempData: null,//模板数据	是	[json]
          CoverImg: '',//封面图	是	[string]
          CountryName: null,//国家	是	[string]
          SeasonName: '',//季节	是	[string]
          ColorName: '',//颜色名称	是	[string]
          ColorStr: null,//颜色值	是	[string]
          TempType: 1,//	版面类型(1-横版，2-竖版)
          TagJsonStr: '',// 标签
        }
    },

})

watch(() => datas.DataSource, () => {
  provide(injectKeyDataSource,datas.DataSource)
})
// 数据源
const GetTripFiled = async () =>{
    try {
        let TemplateRes = await ConfigService.TemplateGetTripFiled();
        if (TemplateRes.data.resultCode == 1) {
          TemplateRes.data.data.forEach(x=>{
            let obj = pageTypesList.value.findIndex(z=>{
              return z.FiledType==x.FiledType
            })
            if(obj==-1){
                let object = {
                  FiledType: x.FiledType,
                  Name: x.FiledTypeStr
                }
                pageTypesList.value.push(object)
            }
          })
          TemplateTypeStore.setTemplateType(pageTypesList.value)
          TempDataSourceStore.setTemplateDataSource(TemplateRes.data.data)
        }
    } catch (error) {
        console.log("TemplateGetTripFiled", error);
    }
}
GetTripFiled()

const mainStore = useMainStore()
const { dialogForExport, showSelectPanel, showSearchPanel } = storeToRefs(mainStore)
const closeExportDialog = () => mainStore.setDialogForExport('')

const remarkHeight = ref(40)


useGlobalHotkey()
usePasteEvent()

provide(injectKeyDataSource,datas.DataSource)

</script>

<style lang="scss" scoped>
.pptist-editor {
  height: 100%;
}
.layout-header {
  height: 40px;
}
.layout-content {
  height: calc(100% - 40px);
  display: flex;
}
.layout-content-left {
  width: 160px;
  height: 100%;
  flex-shrink: 0;
}
.layout-content-center {
  width: calc(100% - 160px - 260px);

  .center-top {
    height: 40px;
  }
}
.layout-content-right {
  width: 260px;
  height: 100%;
}
</style>