import {Module} from 'vuex'
import {RootState} from '../index'
import { message } from "ant-design-vue";
import { useI18n } from "vue-i18n";
import GO from '@/tool/GO';
interface UploadFiles{
	moodboard:any,
	disposeMoodboard:any,
    moodboardFiles:any,
	moodboardGenerateFiles:any,
	moodboardMaterialFiles:any,
	sketchboard:any,
    sketchboardFiles:any,
	sketchGenerateFiles:any,
	sketchMaterialFiles:any,
	showSketchboard:any,
	printboard:any,
    printboardFiles:any,
	printGenerateFiles:any,
	printMaterialFiles:any,
    colorBoards:any,
    marketingSketchFiles:any,
    allBoardData:any, //备份的所有数据，点finish之后备份
    moodTemplateId:any,
}

const UploadFilesModule : Module<UploadFiles,RootState> = {
    state:{
		moodboard:[],
		disposeMoodboard:[],
        moodboardFiles:[],
		moodboardGenerateFiles:[],
		moodboardMaterialFiles:[],
		sketchboard:[],
        sketchboardFiles:[],
		sketchGenerateFiles:[],
		sketchMaterialFiles:[],
		showSketchboard:[],
		printboard:[],
        printboardFiles:[],
		printGenerateFiles:[],
		printMaterialFiles:[],
        colorBoards:[],
        marketingSketchFiles:[],
        allBoardData:{},
        moodTemplateId:'',
		
    },
    mutations:{
		
        setMoodboardFile(state,files){
			state.moodboardFiles = files
			state.moodboard = [...state.moodboardFiles,...state.moodboardGenerateFiles,...state.moodboardMaterialFiles]	
        },
		setDisposeMoodboard(state,files){
			state.disposeMoodboard = [files]
        },
		setMoodboardGenerateFiles(state,files){
			state.moodboardGenerateFiles = files
			state.moodboard = [...state.moodboardFiles,...state.moodboardGenerateFiles,...state.moodboardMaterialFiles]	
        },
		setMoodboardMaterialFiles(state,files){
			state.moodboardMaterialFiles = files
			state.moodboard = [...state.moodboardFiles,...state.moodboardGenerateFiles,...state.moodboardMaterialFiles]	
        },
		addGenerateMaterialFils(state,data:any){
			let file
			let arr
			let maxImg = 8
			if(data.type_.type2 == 'Sketchboard'){
				maxImg = 20
			}else if(data.type_.type2 == 'Printboard'){
				maxImg = 16
			}
			if(data.type_.type1 == 'generate'){//判断是generate||library
				data.resData.designType = 'Generate'
				if(data.type_.type2 == 'Moodboard'){
					file = state.moodboardGenerateFiles
				}else if(data.type_.type2 == 'Sketchboard'){
					file = state.sketchGenerateFiles
				}else if(data.type_.type2 == 'Printboard'){
					file = state.printGenerateFiles
				}
			}else{
				data.resData.designType = 'Library'
				if(data.type_.type2 == 'Moodboard'){
					file = state.moodboardMaterialFiles
				}else if(data.type_.type2 == 'Sketchboard'){
					file = state.sketchMaterialFiles
				}else if(data.type_.type2 == 'Printboard'){
					file = state.printMaterialFiles
				}
			}
			if(data.type_.type2 == 'Moodboard'){//判断选中图片数量
				arr = state.moodboard
			}else if(data.type_.type2 == 'Sketchboard'){
				arr = state.sketchboard
			}else{
				arr = state.printboard
			}
			
			if(file.length == 0){
				if(arr.length >= maxImg){
					// message.warning(GO.jsContent1)
					message.warning(data.jsContent1)
				}else{
					data.collectionChecked = true
					file.push(data)
				}
			}else{
				let str = true
				for (let index = 0; index < file.length; index++) {
					if(file[index].id == data.id){
						// data.id_ = GO.id++
						str = false
					}
				}
				if(str){
					if(arr.length >= maxImg){
						message.warning(data.jsContent1)
					}else{
						data.collectionChecked = true
						file.push(data)
					}
				}else{
					data.collectionChecked = false
					file = file.filter((v:any)=> v.id != data.id)
					// if(data.id_){
					// 	data.checked = false
					// 	file = file.filter((v:any)=> v.id_ != data.id_)
					// }else{
					// 	data.checked = false
					// 	file = file.filter((v:any)=> v.id != data.id)
					// }
				}
			}
			if(data.type_.type1 == 'generate'){
				if(data.type_.type2 == 'Moodboard'){
					state.moodboardGenerateFiles = file 
				}else if(data.type_.type2 == 'Sketchboard'){
					state.sketchGenerateFiles = file 
				}else if(data.type_.type2 == 'Printboard'){
					state.printGenerateFiles = file
				}
			}else{
				if(data.type_.type2 == 'Moodboard'){
					state.moodboardMaterialFiles = file 
				}else if(data.type_.type2 == 'Sketchboard'){
					state.sketchMaterialFiles = file 
				}else if(data.type_.type2 == 'Printboard'){
					state.printMaterialFiles = file
				}
			}
			state.moodboard = [...state.moodboardFiles,...state.moodboardGenerateFiles,...state.moodboardMaterialFiles]	
			state.sketchboard = [...state.sketchboardFiles,...state.sketchGenerateFiles,...state.sketchMaterialFiles]	
			state.printboard = [...state.printboardFiles,...state.printGenerateFiles,...state.printMaterialFiles]	
        },
		setSketchboardFile(state,files){
            state.sketchboardFiles = files
			state.sketchboard = [...state.sketchboardFiles,...state.sketchGenerateFiles,...state.sketchMaterialFiles]	
        },
		setSketchboardGenerateFiles(state,files){
			state.sketchGenerateFiles = files
			state.sketchboard = [...state.sketchboardFiles,...state.sketchGenerateFiles,...state.sketchMaterialFiles]	
        },
		setSketchboardMaterialFiles(state,files){
			state.sketchMaterialFiles = files
			state.sketchboard = [...state.sketchboardFiles,...state.sketchGenerateFiles,...state.sketchMaterialFiles]	

        },
		setShowSketchboard(state,files){
			state.showSketchboard = files
		},
		clearShowSketchboard(state,files){
			state.showSketchboard = []
		},
		setPrintboardFile(state,files){
            state.printboardFiles = files
			state.printboard = [...state.printboardFiles,...state.printGenerateFiles,...state.printMaterialFiles]	
        },
		setPrintboardGenerateFiles(state,files){
			state.printGenerateFiles = files
			state.printboard = [...state.printboardFiles,...state.printGenerateFiles,...state.printMaterialFiles]	
        },
		setPrintboardMaterialFiles(state,files){
			state.printMaterialFiles = files
			state.printboard = [...state.printboardFiles,...state.printGenerateFiles,...state.printMaterialFiles]	
        },

        setColorboardList(state,colorBoards){
            state.colorBoards = colorBoards
        },
        setMarketingSketchFile(state,files){
            state.marketingSketchFiles = files
        },
        setAllBoardData(state){
            state.allBoardData = {
				disposeMoodboard:state.disposeMoodboard,
                moodboardFiles:state.moodboard,
                printboardFiles:state.printboard,
                colorBoards:state.colorBoards,
                sketchboardFiles:state.sketchboard,
                marketingSketchFiles:state.marketingSketchFiles,
                moodTemplateId:state.moodTemplateId,
            }
        },
        setAllBoardDataChoose(state,data){
            state.allBoardData = data
        },
        clearAllData(state){
            state.moodboard = []
            state.moodboardFiles = []
            state.moodboardGenerateFiles = []
            state.moodboardMaterialFiles = []
            state.sketchboard = []
			state.sketchboardFiles = []
            state.sketchGenerateFiles = []
            state.sketchMaterialFiles = []
			state.printboard = []
			state.printboardFiles = []
            state.printGenerateFiles = []
            state.printMaterialFiles = []
			state.colorBoards = []
            state.marketingSketchFiles = []
            state.moodTemplateId = ''
			state.disposeMoodboard = []
			// state.showSketchboard = []
        },
		clearAllId(state){
            state.moodboard.forEach((v:any) => {
				delete v.id_
			});
			state.sketchboard.forEach((v:any) => {
				delete v.id_
			});
			state.printboard.forEach((v:any) => {
				delete v.id_
			});
		},
        setMoodTemplateId(state,moodTemplateId){
            state.moodTemplateId = moodTemplateId
        },
        clearMoodTemplateId(state){
			state.disposeMoodboard = []
        },
    },
    actions:{

    }
}

export default UploadFilesModule