import {Module} from 'vuex'
import {RootState} from '../index'
import { Https } from "@/tool/https";
interface UserHabit{
    clothingType:any,
	credits:any,
    // devise:any,
    // deviseType:any,
    // system_per:any,
    // model:any,
	printType:any,
	designElementsType:any,
	FemalePosition:any,
	MalePosition:any,
	Position:any,
	systemUser:any,
}

const userHabit : Module<UserHabit,RootState> = {
    state:{
        clothingType:[],
		credits:{
			value:0
		},
		printType:[{
			name:'Pattern',
			value:'Pattern'
		},{
			name:'Slogan',
			value:'Slogan'
		},{
			name:'Logo',
			value:'Logo'
		},],
		designElementsType:[],
		FemalePosition:[],
		MalePosition:[],
		Position:[],
		systemUser:{
			value : -1
		},

    },
    mutations:{
        res_clothingType(state,data){
            state.clothingType = data
        },
		setCredits(state,data){
			state.credits.value = data
		},
		setPrintType(state,data){
			state.printType = data
		},
		setDesignElementsType(state,data){
			state.designElementsType = data
		},
		setFemalePosition(state,data){
			state.FemalePosition = data
		},
		setMalePosition(state,data){
			state.MalePosition = data
		},
		setPosition(state,data){
			if(data == 'Female'){
				state.Position = state.FemalePosition
			}else{
				state.Position = state.MalePosition
			}
		},
		setSystemUser(state,data){
			state.systemUser.value = data
		},
		clearSystemUser(state){
			state.systemUser.value = -1
		},
    },

    actions:{
		get_clothingType(context){
			var arr = [{
				id:11,
				name:"nv"
			},{
				id:22,
				name:"nan",
			}]
			context.commit('res_clothingType',arr)

			// Https.axiosGet(url)
			// 	.then((rv: any) => {
			// 		context.commit('res_clothingType',rv)
			// 	})
			// 	.catch((rv) => {
			// 	});
		},
		getCredits(context){
			return new Promise( async (resolve) => {
				await Https.axiosGet(Https.httpUrls.getCredits,).then((rv) => {
					context.commit('setCredits',rv)
					resolve(true)
				}).catch((res) => {
					resolve(true)
				});
			})
		},
		getLangType(context){
			let allPromise = [];
			let getList = ['DesignElementsEnum','PrintboardLevel2TypeEnum','FemalePosition','MalePosition']
			let axiosGet = (item:any)=>{
				return new Promise((resolve) => {
			        Https.axiosGet(Https.httpUrls.workspaceenumValues,{params:{enumName:item}}).then((rv: any) => {
						if (rv) {
							rv.forEach((item:any) => {
								let name = item.name
								item.name = item.value
								item.value = name
							});
							if(item == 'DesignElementsEnum'){
								context.commit('setDesignElementsType',rv)
							}else if(item == 'PrintboardLevel2TypeEnum'){
								context.commit('setPrintType',rv)
							}else if(item == 'FemalePosition'){
								context.commit('setFemalePosition',rv)
							}else if(item == 'MalePosition'){
							    context.commit('setMalePosition',rv)
								context.commit('setPosition','MalePosition')
							}
							resolve('')
						}
					})
			    })
			}
			return Promise.all(getList.map(item => axiosGet(item)))
			// Https.axiosGet(Https.httpUrls.workspaceenumValues,{params:{enumName:'DesignElementsEnum'}}).then((rv: any) => {
			// 	if (rv) {
			// 		rv.forEach((item:any) => {
			// 			let name = item.name
			// 			item.name = item.value
			// 			item.value = name
			// 		});
			// 		context.commit('setDesignElementsType',rv)
			// 	}
			// })
			// Https.axiosGet(Https.httpUrls.workspaceenumValues,{params:{enumName:'PrintboardLevel2TypeEnum'}}).then((rv: any) => {
			// 	if (rv) {
			// 		rv.forEach((item:any) => {
			// 			let name = item.name
			// 			item.name = item.value
			// 			item.value = name
			// 		});
			// 		context.commit('setPrintType',rv)
			// 	}
			// })
			// Https.axiosGet(Https.httpUrls.workspaceenumValues,{params:{enumName:'FemalePosition'}}).then((rv: any) => {
			// 	if (rv) {
			// 		rv.forEach((item:any) => {
			// 			let name = item.name
			// 			item.name = item.value
			// 			item.value = name
			// 		});
			// 		context.commit('setFemalePosition',rv)
			// 	}
			// })
			// Https.axiosGet(Https.httpUrls.workspaceenumValues,{params:{enumName:'MalePosition'}}).then((rv: any) => {
			// 	if (rv) {
			// 		rv.forEach((item:any) => {
			// 			let name = item.name
			// 			item.name = item.value
			// 			item.value = name
			// 		});
			// 		context.commit('setMalePosition',rv)
			// 		context.commit('setPosition','MalePosition')
			// 	}
			// })
		}
    }
}

export default userHabit