using System;
using System.Collections.Generic;
using Monkey.Game;
using Monkey.Patching;

namespace Monkey.UI.Windows
{

    public class PluginWindow : Window
    {

        private static readonly List<(Action<float> onValueChangedAction, Func<float> getValueFunction, string description)> _femaleAppearanceOptions = new List<(Action<float> onValueChangedAction, Func<float> getValueFunction, string description)>()
        {
            { ((float faceYoung) => { FemaleCharacterAppearanceManager.FaceYoung = faceYoung; }, () => { return FemaleCharacterAppearanceManager.FaceYoung; }, "Young Face:") },
            { ((float faceOld) => { FemaleCharacterAppearanceManager.FaceOld = faceOld; }, () => { return FemaleCharacterAppearanceManager.FaceOld; }, "Old Face:") },
            { ((float bodyScale) => { FemaleCharacterAppearanceManager.BodyScale = bodyScale; }, () => { return FemaleCharacterAppearanceManager.BodyScale; }, "Body Scale:") },
            { ((float bodyFat) => { FemaleCharacterAppearanceManager.BodyFat = bodyFat; }, () => { return FemaleCharacterAppearanceManager.BodyFat; }, "Body Fat:") },
            { ((float breastsSize) => { FemaleCharacterAppearanceManager.BreastsSize = breastsSize; }, () => { return FemaleCharacterAppearanceManager.BreastsSize; }, "Breasts Size:") },
            { ((float buttocksSize) => { FemaleCharacterAppearanceManager.ButtocksSize = buttocksSize; }, () => { return FemaleCharacterAppearanceManager.ButtocksSize; }, "Buttocks Size:") },
            { ((float vaginaLabiaSize) => { FemaleCharacterAppearanceManager.VaginaLabiaSize = vaginaLabiaSize; }, () => { return FemaleCharacterAppearanceManager.VaginaLabiaSize; }, "Vagina Labia Size:") },
            { ((float vaginaHoleSize) => { FemaleCharacterAppearanceManager.VaginaHoleSize = vaginaHoleSize; }, () => { return FemaleCharacterAppearanceManager.VaginaHoleSize; }, "Vagina Hole Size:") },
            { ((float vaginaClitorisSize) => { FemaleCharacterAppearanceManager.VaginaClitorisSize = vaginaClitorisSize; }, () => { return FemaleCharacterAppearanceManager.VaginaClitorisSize; }, "Vagina Clitoris Size:") },
            { ((float anusSize) => { FemaleCharacterAppearanceManager.AnusSize = anusSize; }, () => { return FemaleCharacterAppearanceManager.AnusSize; }, "Anus Size:") }
        };

        private static readonly List<(Action<bool> onIsLockedChangedAction, Func<bool> getIsLockedFunction, Action<float> onValueChangedAction, Func<float> getValueFunction, string description)> _emotionOptions = new List<(Action<bool> onIsLockedChangedAction, Func<bool> getIsLockedFunction, Action<float> onValueChangedAction, Func<float> getValueFunction, string description)>()
        {
            {
                ((bool isFemaleAngerLocked) => { PatchManager.IsFemaleAngerLocked = isFemaleAngerLocked; },
                () => { return PatchManager.IsFemaleAngerLocked; },
                (float lockedFemaleAngerValue) => { PatchManager.LockedFemaleAngerValue = lockedFemaleAngerValue; },
                () => { return PatchManager.LockedFemaleAngerValue; },
                "Female Anger Locked")
            },
            {
                ((bool isFemaleArousalLocked) => { PatchManager.IsFemaleArousalLocked = isFemaleArousalLocked; },
                () => { return PatchManager.IsFemaleArousalLocked; },
                (float lockedFemaleArousalValue) => { PatchManager.LockedFemaleArousalValue = lockedFemaleArousalValue; },
                () => { return PatchManager.LockedFemaleArousalValue; },
                "Female Arousal Locked")
            },
            {
                ((bool isFemaleDisappointmentLocked) => { PatchManager.IsFemaleDisappointmentLocked = isFemaleDisappointmentLocked; },
                () => { return PatchManager.IsFemaleDisappointmentLocked; },
                (float lockedFemaleDisappointmentValue) => { PatchManager.LockedFemaleDisappointmentValue = lockedFemaleDisappointmentValue; },
                () => { return PatchManager.LockedFemaleDisappointmentValue; },
                "Female Disappointment Locked")
            },
            { 
                ((bool isFemaleConsentLocked) => { PatchManager.IsFemaleConsentLocked = isFemaleConsentLocked; },
                () => { return PatchManager.IsFemaleConsentLocked; },
                (float lockedFemaleConsentValue) => { PatchManager.LockedFemaleConsentValue = lockedFemaleConsentValue; },
                () => { return PatchManager.LockedFemaleConsentValue; },
                "Female Consent Locked") 
            },
            {
                ((bool isFemalePainLocked) => { PatchManager.IsFemalePainLocked = isFemalePainLocked; },
                () => { return PatchManager.IsFemalePainLocked; },
                (float lockedFemalePainValue) => { PatchManager.LockedFemalePainValue = lockedFemalePainValue; },
                () => { return PatchManager.LockedFemalePainValue; },
                "Female Pain Locked")
            },
            {
                ((bool isFemalePleasureLocked) => { PatchManager.IsFemalePleasureLocked = isFemalePleasureLocked; },
                () => { return PatchManager.IsFemalePleasureLocked; },
                (float lockedFemalePleasureValue) => { PatchManager.LockedFemalePleasureValue = lockedFemalePleasureValue; },
                () => { return PatchManager.LockedFemalePleasureValue; },
                "Female Pleasure Locked")
            },
            {
                ((bool isMaleDisgustLocked) => { PatchManager.IsMaleDisgustLocked = isMaleDisgustLocked; },
                () => { return PatchManager.IsMaleDisgustLocked; },
                (float lockedMaleDisgustValue) => { PatchManager.LockedMaleDisgustValue = lockedMaleDisgustValue; },
                () => { return PatchManager.LockedMaleDisgustValue; },
                "Male Disgust Locked")
            },
            {
                ((bool isMalePleasureLocked) => { PatchManager.IsMalePleasureLocked = isMalePleasureLocked; },
                () => { return PatchManager.IsMalePleasureLocked; },
                (float lockedMalePleasureValue) => { PatchManager.LockedMalePleasureValue = lockedMalePleasureValue; },
                () => { return PatchManager.LockedMalePleasureValue; },
                "Male Pleasure Locked")
            }
        };

        private UnityEngine.Vector2 scrollViewPosition;

        public PluginWindow(int identifier, string title, UnityEngine.Rect dimensions) : base(identifier, title, dimensions)
        {
            this.scrollViewPosition = UnityEngine.Vector2.zero;
        }

        protected override void DrawContent(int identifier)
        {
            this.scrollViewPosition =  UnityEngine.GUILayout.BeginScrollView(this.scrollViewPosition);

            this.DrawFemaleAppearanceOptions();
            this.DrawFemaleClothingOptions();
            this.DrawEmotionOptions();
            this.DrawQualityOptions();

            UnityEngine.GUILayout.EndScrollView();
        }

        private void DrawFemaleAppearanceOptions()
        {
            if (!FemaleCharacterManager.DoesFemaleCharacterExist())
                return;

            UIManager.DrawHeading("Female Appearance Options");

            for (int i = 0; i < _femaleAppearanceOptions.Count; i++)
            {
                (Action<float> onValueChangedAction, Func<float> getValueFunction, string description) = _femaleAppearanceOptions[i];

                UnityEngine.GUILayout.Label(description);

                UIManager.DrawHorizontalSlider(
                    onValueChangedAction,
                    getValueFunction(),
                    0f,
                    1f);
            }
        }

        private void DrawFemaleClothingOptions()
        {
            if (!FemaleCharacterManager.DoesFemaleCharacterExist())
                return;

            UIManager.DrawHeading("Female Clothing Options");

            List<Assets._ReusableScripts.CuchiCuchi.Ropa.PiezaDeRopaBase> clothings = FemaleCharacterClothingManager.GetClothings();

            for (int i = 0; i < clothings.Count; i++)
            {
                Assets._ReusableScripts.CuchiCuchi.Ropa.PiezaDeRopaBase clothing = clothings[i];

                UIManager.DrawToggle(
                    (bool isClothingEnabled) => { clothing.enabled = isClothingEnabled; FemaleCharacterClothingManager.GetClothingLoader().UpdateCubrindoPartes(); },
                    clothing.enabled,
                    clothing.name);
            }
        }

        private void DrawEmotionOptions()
        {
            if (!FemaleCharacterManager.DoesFemaleCharacterExist())
                return;

            UIManager.DrawHeading("Emotion Options");

            for (int i = 0; i < _emotionOptions.Count; i++)
            {
                (Action<bool> onIsLockedChangedAction, Func<bool> getIsLockedFunction, Action<float> onValueChangedAction, Func<float> getValueFunction, string description) = _emotionOptions[i];

                UIManager.DrawToggle(onIsLockedChangedAction, getIsLockedFunction(), description);

                if (getIsLockedFunction())
                    UIManager.DrawHorizontalSlider(onValueChangedAction, getValueFunction(), 0f, 100f);
            }
        }

        private void DrawQualityOptions()
        {
            UIManager.DrawHeading("Quality Options");

            UIManager.DrawToggle((bool isFogVolumeEnabled) => { QualityManager.IsFogVolumeEnabled = isFogVolumeEnabled; }, QualityManager.IsFogVolumeEnabled, "Fog Enabled");
            UIManager.DrawToggle((bool isAmbientOcclusionEnabled) => { QualityManager.IsAmbientOcclusionEnabled = isAmbientOcclusionEnabled; }, QualityManager.IsAmbientOcclusionEnabled, "Ambient Occlusion Enabled");
            UIManager.DrawToggle((bool isBloomEnabled) => { QualityManager.IsBloomEnabled = isBloomEnabled; }, QualityManager.IsBloomEnabled, "Bloom Enabled");
            UIManager.DrawToggle((bool isDepthOfFieldEnabled) => { QualityManager.IsDepthOfFieldEnabled = isDepthOfFieldEnabled; }, QualityManager.IsDepthOfFieldEnabled, "Depth Of Field Enabled");
            UIManager.DrawToggle((bool isMotionBlurEnabled) => { QualityManager.IsMotionBlurEnabled = isMotionBlurEnabled; }, QualityManager.IsMotionBlurEnabled, "Motion Blur Enabled");
        }

    }

}
