
import {formatPPTDate} from '../utils/index'
import {bgList} from '../utils/config'
import {ref} from 'vue'
import Cover from '../template/Cover.vue'
import CustomCover from '../template/CustomCover.vue'
import Footer from '../template/Footer.vue'
import FormatOne from '../template/FormatOne.vue'
import FormatTwo from '../template/FormatTwo.vue'
import FormatThree from '../template/FormatThree.vue'
import FormatFour from '../template/FormatFour.vue'
import FormatFive from '../template/FormatFive.vue'
import FormatSix from '../template/FormatSix.vue'
import FormatSeven from '../template/FormatSeven.vue'
import FormatEight from '../template/FormatEight.vue'
import FormatNine from '../template/FormatNine.vue'
import FormatTen from '../template/FormatTen.vue'
import FormatEle from '../template/FormatEle.vue'
import FormatTwelve from '../template/FormatTwelve.vue'
import FormatThirteen from '../template/FormatThirteen.vue'
import ChartWrap from '../components/ChartWrap.vue'
import RichText from '../components/RichText.vue'
import ImageWrap from '../components/ImageWrap.vue'
import SheetWrap from '../components/SheetWrap.vue'

import RectShape from '../components/layers/RectShape.vue'
import LineShape from '../components/layers/LineShape.vue'
import TextShape from '../components/layers/TextShape.vue'

import { storeToRefs } from 'pinia'
import { useConfigSettingStore } from '@/store/modules/etaConfig'

export function getPPTConfig() {

    const lang=window.location.pathname.startsWith('/ppten')?'en':'zh'

    const { etaConfigInfo } = storeToRefs(useConfigSettingStore())

    const { CnPptCoverImgs,CnPptBackgroundImg,CnPptBottomImg,PptCompanyName,PptTeamName,PptFontColor,EnPptCoverImgs,EnPptBackgroundImg,EnPptBottomImg,PptCompanyNameEn,PptTeamNameEn,PptFontColorEn,CnPptSheetSize,EnPptSheetSize }  = etaConfigInfo.value
    return {
        pptCoverList: lang==='en' ? EnPptCoverImgs.split(',') : CnPptCoverImgs.split(','),
        pptBgImage: lang==='en' ? EnPptBackgroundImg : CnPptBackgroundImg,
        pptBackImage: lang==='en' ? EnPptBottomImg : CnPptBottomImg,
        pptCoverCompenyName: lang==='en' ? PptCompanyNameEn : PptCompanyName,
        pptCoverDepartName: lang==='en' ? PptTeamNameEn : PptTeamName,
        pptCoverTextColor: lang==='en' ? PptFontColorEn : PptFontColor,
        pptSheetSize: lang==='en' ? EnPptSheetSize : CnPptSheetSize
    }
}

/**
 * 格式化ppt内容
 * @param params ppt详情接口返回的数据
 * modelId 模板1-9 0代表封面 -1代表尾页
 */
export function createPPTContent(params){
    const lang=window.location.pathname.startsWith('/ppten')?'en':'zh'

    const {
        Content,
        Title,
        ReportType,
        BackgroundImg,
        PptDate,
        TemplateType,
        ReportId,
        ModifyTime,
        PublishTime,
        CoverContent
    }=params

    let arr=[]//ppt内容数组

    // 封面页数据
    const coverPageData={
        Title,
		ReportType,
		BackgroundImg,
		PptDate:formatPPTDate('zh',PptDate),
		TemplateType,
        BackIndex:TemplateType-1,
        imgLocalUrl:bgList[lang][TemplateType-1],
        modelId:0,
        id:0,
        CoverContent
    }
    arr.push(coverPageData)

    // ppt内容页数据
    const conArr=JSON.parse(Content)
    arr.push(...conArr)

    //ppt尾页数据
    const lastPageData={
        name:'back',
        modelId:-1,
        id:-1,
        //英文地址：https://hzstatic.hzinsights.com/static/ppt_m/ppt_last__img_en.png
        bgImg:lang=='zh'?'/pptImg/ppt_last_img.png':'/pptImg/ppt_last_img_en.png',
    }
    arr.push(lastPageData)
    
    return arr
}

/**
 * ppt模板Map
 * 根据modelId获取是哪个模板组件
 */
export function getTemplate(modelId){
    const modelMap=new Map([
        [0,CustomCover],
        [1,FormatOne],
        [2,FormatTwo],
        [3,FormatThree],
        [4,FormatFour],
        [5,FormatFive],
        [6,FormatSix],
        [7,FormatSeven],
        [8,FormatEight],
        [9,FormatNine],
        [10,FormatTen],
        [11,FormatEle],
        [12,FormatTwelve],
        [13,FormatThirteen],
        [-1,Footer],
    ])
    return modelMap.get(modelId)
}

/**
 * 获取ppt页面内部是哪种组件
 * @param position 该模板中哪个位置 
 * @param list 该ppt页的element数据
 */
export function getPPTContentType(position,list){
    const typeMap=new Map([
        ['chart',ChartWrap],
        ['text',RichText],
        ['image',ImageWrap],
        ['sheet',SheetWrap]
    ])
    // 查找出list中的position和position对应的类型
    let type=''
    list.forEach(item => {
        if(item.position===position){
            type=item.type
        }
    });
    return typeMap.get(type)
}

/**
 * 获取ppt页面中某模块的数据
 * @param position 该模板中哪个位置 
 * @param data 该ppt页的数据
 */
export function getPPTContentItemData(position,data){
    let obj={}
    data.elements.forEach(item => {
        if(item.position===position){
            obj=item
        }
    });
    return {...obj,pptPageIndex:data.pptPageIndex}
}

/**
 * 设置ppt每页中的layer图层类型
 */
export function getPPTLayerType(data){
    const typeMap=new Map([
        ['shape',RectShape],
        ['line',LineShape],
        ['text',TextShape]
    ])
    return typeMap.get(data.type)
}
