/// <reference path="../../_system/time/listeners.ts" />
/// <reference path="../../playerCharacter/_submodules/appearance/AppearanceFunctions.ts" />
/// <reference path="../../playerCharacter/_submodules/appearance/Modificators.ts" />
/// <reference path="../../playerCharacter/_submodules/pain/pc_pain.ts" />
/// <reference path="../../playerCharacter/effects/activeEffect.ts" />
/// <reference path="../../playerCharacter/effects/effects.ts" />
/// <reference path="../../playerCharacter/skills/ESkillDifficulty.ts" />
/// <reference path="../../playerCharacter/skills/skills.ts" />
/// <reference path="../../_system/wardrobe/wardrobe.ts" />


const highHeelsDifficulty = [
	[0,1,2],
	[1,2,3],
	[2,3,4],
	[3,4,5],
	[4,5,6],
	[4,5,7],
	[5,6,7],
	[6,7,Infinity],
	[7,Infinity,Infinity],
	[Infinity,Infinity,Infinity],
]

setup.difficultyOfHighHeels = function(shoes: OutfitItemShoes=undefined,levelCategory:number=undefined){

	shoes ??= State.variables.wardrobe.shoes;

	if(!shoes.heels)
		return ESkillDifficulty.TRIVIAL;

	levelCategory ??= Math.clamp(
		Math.floor(
			State.variables.pc.skillLevel('highHeels') / 10
		),
		0,10
	);

	let heelHeight:number = shoes.heels;
	const [height_noProblem,height_gracefully,height_max] = highHeelsDifficulty[levelCategory];
	
	if(heelHeight > height_max)
		return ESkillDifficulty.IMPOSSIBE;
	if(heelHeight >= height_max)
		return ESkillDifficulty.HARD;
	if(heelHeight >= height_gracefully)
		return ESkillDifficulty.MEDIUM;
	if(heelHeight >= height_noProblem)
		return ESkillDifficulty.EASY;
	return ESkillDifficulty.TRIVIAL;
}

setup.skills.highHeels = {
    label: 'High Heels',
    e2s: (n=>Math.floor(n/100)),
    s2e: (n=>n*100),
	isDifficultyBased:true,
    image: 'pc/skills/highHeels.webp',
    description: 'The art of walking in shoes with high heels. This includes a physical component, as your feet get used to being forced into an unnatural pose. Also, you learn how to walk in high heels in a way that both looks well and goes easy on your feet. Finally, you learn little tricks, such as the clever use of plasters, silicone inserts and how to make even to most uncomfortable shoes bearable. The most effective way to increase this skill is to practice in slightly too high shoes in front of a mirror at your home, but just wearing them outdoors also increases the skill a little bit. Wearing too high heels will hurt your feet and you might be forced to rest if the pain gets unbearable. Wearing way too high heels might be impossible until your increase you skill further.',
    descibtionByLevel:{
        0: 'Your experience in walking in high heels is minimal to non-existing. You can wear no shoes with heels wihtout your feet hurting. Wearing 1 inch high heels gracefully is possible, but your feet would start to hurt after a while. 2 inches high heels are the highest shoes you\'d be able to wear, but your struggle to do so would be obvious.',
        1: 'You have walked in shoes with low heels a few times. You could wear 1 inch high heels the whole day long wihtout your feet hurting. Wearing 2 inches high heels gracefully is also possible, but your feet would start to hurt after a while. 3 inches high heels are the highest shoes you\'d be able to wear, but your struggle to do so would be obvious.',
        2: 'You could wear 2 inches high heels the whole day long wihtout your feet hurting. Wearing 3 inches high heels gracefully is also possible, but your feet would start to hurt after a while. 4 inches high heels are the highest shoes you\'d be able to wear, but your struggle to do so would be obvious.',
        3: 'You could wear 3 inches high heels the whole day long wihtout your feet hurting. Wearing 4 inches high heels gracefully is also possible, but your feet would start to hurt after a while. 5 inches high heels are the highest shoes you\'d be able to wear, but your struggle to do so would be obvious.',
        4: 'You are proficient at wearing high heels. You could wear 4 inches high heels the whole day long wihtout your feet hurting. Wearing 5 inches high heels gracefully is also possible, but your feet would start to hurt after a while. 6 inches high heels are the highest shoes you\'d be able to wear, but your struggle to do so would be obvious.',
        5: 'You are a specialist at wearing high heels. You could wear 4 inches high heels the whole day long wihtout your feet hurting. Wearing 5 inches high heels gracefully is also possible, but your feet would start to hurt after a while. 7 inches high heels are the highest shoes you\'d be able to wear, but your struggle to do so would be obvious.',
        6: 'You are a professional at wearing high heels. You could wear 5 inches high heels the whole day long wihtout your feet hurting. Wearing 6 inches high heels gracefully is also possible, but your feet would start to hurt after a while. 7 inches high heels are the highest shoes you\'d be able to wear, but your struggle to do so would be obvious.',
        7: 'You are a expert at wearing high heels. You could wear 6 inches high heels the whole day long wihtout your feet hurting. Wearing 7 inches high heels gracefully is also possible, but your feet would start to hurt after a while. You could wear even higher shoes, but your struggle to do so would be obvious.',
        8: 'You are a master at wearing high heels. You could wear 7 inches high heels the whole day long wihtout your feet hurting. You can wear even higher shoes gracefully, but your feet would start to hurt after a while.',
        9: 'You are a renowned master at wearing high heels. You could wear any shoes gracefully the whole day without your feet hurting.',
        10: 'You are a famous master at wearing high heels. You could wear any shoes more gracefully than almost everyone the whole day without your feet hurting.',
    },
	functions:{
		experienceGain: (minutes:number) => {
			const difficultyOfCurrentHeels = setup.difficultyOfHighHeels();
			let experiencePerHours:number= 0;
			switch(difficultyOfCurrentHeels){
				case ESkillDifficulty.TRIVIAL:		experiencePerHours = heelDifficultToExperience[0]; break;
				case ESkillDifficulty.EASY:			experiencePerHours = heelDifficultToExperience[1]; break;
				case ESkillDifficulty.MEDIUM:		experiencePerHours = heelDifficultToExperience[2]; break;
				case ESkillDifficulty.HARD:			experiencePerHours = heelDifficultToExperience[3]; break;
				case ESkillDifficulty.IMPOSSIBE:	experiencePerHours = heelDifficultToExperience[4]; break;
			}

			const experienceGained = experiencePerHours / 60 * minutes;
			return experienceGained;
		},
		painGain: (minutes:number) => {
			const difficultyOfCurrentHeels = setup.difficultyOfHighHeels();
			let painPerHour:number = 0;
			switch(difficultyOfCurrentHeels){
				case ESkillDifficulty.TRIVIAL:		painPerHour = heelDifficultToPain[0]; break;
				case ESkillDifficulty.EASY:			painPerHour = heelDifficultToPain[1]; break;
				case ESkillDifficulty.MEDIUM:		painPerHour = heelDifficultToPain[2]; break;
				case ESkillDifficulty.HARD:			painPerHour = heelDifficultToPain[3]; break;
				case ESkillDifficulty.IMPOSSIBE:	painPerHour = heelDifficultToPain[4]; break;
			}

			const painGained = minutes / 60 * painPerHour;
			return painGained;
		}
	}
}


/**
 * Pain in one hour.
 * 
 * Read: Trivial, Easy, Medium, Hard, Impossible.
 * 
 * Balanced to reach pain 50 after 8 hours.
 * @type {number[]}
 */
const heelDifficultToPain:number[] = [
	0, 		// No pain for wearing shoes you are perfectly comfortable in
	0,		// No pain for wearing shoes you are perfectly comfortable in
	6.25,	// Reach Pain 50 after 8 hours.
	25,		// Reach Pain 50 after 2 hours.
	50		// Reach Pain 50 after 1 hour.
];
const heelDifficultToExperience:number[] = [
	0,		// Wearing shoes you are perfectly trained in teaches you nothing.
	3.125,	// Wear low difficulty shoes for 32 hours to get one skill point.
	12.5,	// Wear medium difficulty shoes for 8 hours to get one skill point.
	25,		// Wear high difficulty shoes for 4 hours to get one skill point.
	0		// Too high shoes are too high too learn and therefore to learn in.
];

setup.listeners_timeUpdate['highheels'] = (minutes:number) => {
	const pc = State.variables.pc;
	if(pc.isSleeping)
		return;

	const wardrobe = State.variables.wardrobe;
	if(!wardrobe.isWearingShoes)
		return;

	const painGain:number = setup.skills.highHeels.functions.painGain(minutes);
	pc.painInc('feet','heels',painGain);

	const expGain:number  = setup.skills.highHeels.functions.experienceGain(minutes);
	pc.skillExperienceGain("highHeels",expGain,['highHeelsAutopractice']);
};
setup.wardrobeWearableFunctions['highheels'] = (outfitOwned:OutfitOwned) =>{
	if(outfitOwned.type != 'shoes')
		return '';
	if(setup.difficultyOfHighHeels(outfitOwned as OutfitItemShoes) == ESkillDifficulty.IMPOSSIBE)
		return 'These shoes are too high for you.';
	return '';
}

setup.effects.highHeelTraining = {
	painGain:{
		feet:2
	},
	skillGain:{
		highHeels: 4
	},
	skillTagGain:{
		highHeelsAutopractice: 0
	}
}

setup.appearanceFunctions.current.highHeels = (pc:PlayerCharacter) => {
	const shoes = pc.outfit.shoes;
	if(!shoes.heels ||!pc.isWearingShoes)
		return '';
	const difficultyOfHeels = setup.difficultyOfHighHeels(shoes);
	if(difficultyOfHeels == ESkillDifficulty.IMPOSSIBE || difficultyOfHeels == ESkillDifficulty.HARD)
		return 'highHeels_tooHigh';

	return `highHeels_h${shoes.heels}`;
}

setup.appearanceModificators.highHeels_tooHigh = {
		label: 'Insecure on high heels',
		desc: 'You are looking goofy wearing shoes with too high heels.',
		priority: 100,
		dec: 2
	}

setup.appearanceModificators.highHeels_h1 = {
		label: 'Very low heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 0.1
	}

setup.appearanceModificators.highHeels_h2 = {
		label: 'Low heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 0.2
	}

setup.appearanceModificators.highHeels_h3 = {
		label: 'Medium low heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 0.35
	}

setup.appearanceModificators.highHeels_h4 = {
		label: 'Medium heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 0.5
	}

setup.appearanceModificators.highHeels_h5 = {
		label: 'Medium high heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 0.65
	}

setup.appearanceModificators.highHeels_h6 = {
		label: 'Very high heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 0.8
	}

setup.appearanceModificators.highHeels_h7 = {
		label: 'Ultra high heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 1
	}

setup.appearanceModificators.highHeels_h8 = {
		label: 'Fetish heels',
		desc: 'The shoes you\'re wearing increase your appearance slightly.',
		priority: 100,
		inc: 1.5
	}

setup.painReasons.heels= {
		deterioration: 6.25, // Remove 50 pain in 8 hours.
		label: 'High Heels',
		description: 'You walked too long in too high heels.'
	}

setup.activeEffects.highHeelsPainRegenStopped = {
	isActive:(pc:PlayerCharacter)=>(pc.isWearingShoes && setup.difficultyOfHighHeels(pc.outfit.shoes) != ESkillDifficulty.TRIVIAL),
	effect:{
		painRegen:{feet:0}
	}
}