import {Module} from 'vuex'
import {RootState} from '../index'

interface DesignDetail{
    designCollectionList:any,
    likeDesignCollectionList:any,
    deleteDesignCollectionList:any,
    userGroupId:any,
    designCollectionId:any,
    templateId:any,
    templateImgUrl:any,
    designId:any,
	showSketchList:any,

	toProductImageList:any,// 产品图片
	relightList:any,// 灯光列表

	poseTransfer:any,// 姿态转换
	deReconstruction:any,// 拼贴
	patternMaking3D:any,//3d
	canvasData:any,// 拼贴canvas
}

const HomeStoreModule : Module<DesignDetail,RootState> = {
    state:{
        designCollectionList:[],
        likeDesignCollectionList:[],
        deleteDesignCollectionList:[],
        userGroupId:'',
        designCollectionId:'',
        templateId:'',
        templateImgUrl:'',
        designId:'',
		showSketchList:[],
		toProductImageList:[],
		relightList:[],
		poseTransfer:[],
		deReconstruction:[{
			isLike:false,
			url:'',
			category:'123',
			categoryValue:'23',
			categoryShow:false
		}],
		patternMaking3D:null,
		canvasData:{
			deReconstruction:null,
			canvas:null
		}
    },
    mutations:{
		setshowSketchList(state,data){
            state.showSketchList = data
        },
        setDesignCollectionList(state,data){
            state.designCollectionList = data
        },
        setLikeDesignCollectionList(state,data){
			data = data || []
            state.likeDesignCollectionList = data
        },
		setRelightList(state,data){
			if(data.str == 'add'){
	            state.relightList.unshift(...data.list)
			}else{
	            state.relightList.splice(data.index,1)
			}
        },
		setPoseTransfer(state,data){
			data.list.forEach((item:any) => {
				item.url = item.firstFrameUrl
			});
			if(data.str == 'add'){
	            state.poseTransfer.unshift(...data.list)
			}else{
	            state.poseTransfer.splice(data.index,1)
			}
        },
		setDeReconstruction(state,data){
			if(data.str == 'add'){
				state.deReconstruction = []
				let obj = {
					...data.list[0],
				}
	            state.deReconstruction.unshift(obj)
			}else{
	            state.deReconstruction.splice(data.index,1)
			}
        },
		setPatternMaking3D(state,data){
			state.patternMaking3D = data
		},
		setCanvasData(state,data){
			state.canvasData[data.type] = data.file
		},
		setToProductImage(state,data){
			if(data.str == 'add'){
	            state.toProductImageList.unshift(...data.list)
			}else{
	            state.toProductImageList.splice(data.index,1)
			}
        },
		setDeleteDesignCollectionList(state,data){
            let obj = state.designCollectionList.splice(data,1)
			// state.deleteDesignCollectionList.unshift(...obj)
        },
		cancelDeleteDesignCollectionList(state,data){
            let obj = state.deleteDesignCollectionList.splice(data,1)
			state.designCollectionList.unshift(...obj)
        },
        setSingleDesignCollectionList(state,data){
            state.designCollectionList[data.index] = data.design
        },
        setSingleLikeDesignCollectionList(state,data){
            state.likeDesignCollectionList[data.index] = data.design
        },
        addDesignCollectionList(state,data){
            state.designCollectionList.push(data)
        },
        addLikeDesignCollectionList(state,data){
            state.likeDesignCollectionList.unshift(data)
        },
        deleteDesignCollectionList(state,index){
            state.designCollectionList.splice(index,1)
        },
        deleteLikeDesignCollectionList(state,index){
            state.likeDesignCollectionList.splice(index,1)
        },
        setUserGroupId(state,data){
            state.userGroupId = data
        },
        deleteUserGroupId(state){
            state.userGroupId = ''
        },
        setDesignCollectionId(state,data){
            state.designCollectionId = data
        },
        deleteDesignCollectionId(state,data){
            state.designCollectionId = ''
        },
        setDesignId(state,data){
            state.designId = data
        },
        deleteDesignId(state){
            state.designId = ''
        },
        clearAllCollection(state){
            state.designCollectionList=[]
            state.likeDesignCollectionList = []
            state.designCollectionId = ''
			state.deleteDesignCollectionList = []
			state.relightList = []
			state.toProductImageList = []
			state.poseTransfer = []
			state.deReconstruction = null
			state.patternMaking3D = null
			state.canvasData = {
				deReconstruction:null,
				canvas:null
			}
        },
        setTemplateData(state,data){
            state.templateId=data.id
            state.templateImgUrl = data.url
        },
        clearTemplateData(state){
            state.templateId= ''
            state.templateImgUrl = ''
        },
		

        
    },
    actions:{

    }
}

export default HomeStoreModule