using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Text;
using System.Text.Encodings.Web;
using System.Text.Json;
using System.Text.Unicode;
using System.Threading.Tasks;
using CDSAE3_Lian_Lian_Kan.Boards;
using CDSAE3_Lian_Lian_Kan.Forms;
using CDSAE3_Lian_Lian_Kan.Forms.Interface;
using CDSAE3_Lian_Lian_Kan.Properties;
using CDSAE3_Lian_Lian_Kan.Sound;
namespace CDSAE3_Lian_Lian_Kan
{
    public static class Etcs
    {
        public class ThemeInfos
        {
            public IList<ThemeInfo>? Themes { get; set; }
        }
        public class ThemeInfo
        {
            public string Name { get; set; } = "";
            public bool AnimationUseImage { get; set; }
            public bool IsOutPicture { get; set; }
            public string? PictureName { get; set; }
            public bool PlayPanelUsePicture { get; set; }
            public bool PlayPanelPictureIsOutPicture { get; set; }
            public string? PlayPanelPictureName { get; set; }
            public IList<int>? ThemeColor { get; set; }
            public IList<int>? PlayAreaThemeColor { get; set; }
            public IList<int>? ButtonColor { get; set; }
            public IList<int>? ButtonSize { get; set; }
            public IList<int>? StartGamePos { get; set; }
            public IList<int>? ChallengeModePos { get; set; }
            public IList<int>? ScoreBoardPos { get; set; }
            public IList<int>? SettingsPos { get; set; }
            public IList<int>? FontBlockPos { get; set; }
            public IList<int>? FontBlockSize { get; set; }
            public IList<int>? FontColor { get; set; }
            public string? Font { get; set; }
            public string? FontSize { get; set; }
        }
        public class ScoreRecord
        {
            public IList<RecordInfo>? RecordInfos { get; set; }
        }
        public class RecordInfo
        {
            public string? Name { get; set; }
            public DateTimeOffset? Time { get; set; }
            public int? CostTime { get; set; }
            public int? Score { get; set; }
            public string? Difficulty { get; set; }

        }

        public static int left_time { get; set; } = 180;
        public static int search_left_time { get; set; } = 20;
        public enum Difficulty
        {
            easy = 0,
            normal = 1,
            hard = 2,
            custom = 3
        }
        public enum Theme
        {
            fruit = 0
        }
        public enum Direction
        {
            none = 0,
            up = 1,
            right = 2,
            down = 4,
            left = 8,
            up_down = 5,
            left_right = 10,
            up_right = 3,
            up_left = 9,
            down_right = 6,
            down_left = 12,
            up_down_right = 7,
            up_down_left = 13,
            up_left_right = 11,
            down_left_right = 14,
            up_down_left_right = 15
        }
        public enum break_music
        {
            breakA,
            breakB
        }
        public static Dictionary<int, double> decrease_per_level = new Dictionary<int, double> {
            {1,100.0/60 },
            {2,100.0/45 },
            {3,100.0/35 },
            {4,100.0/30 },
            {5,100.0/25 },
            {6,100.0/20 },
            {7,100.0/15 },
            {8,100.0/10 },
            {9,100.0/5 },
            {10,100.0/3 }};

        public static int cus_height = 1, cus_width = 1;
        public static Dictionary<string, ThemeInfo> themes { get; set; } = JsonSerializer.Deserialize<ThemeInfos>(File.ReadAllText("Resources\\sources.json"), new JsonSerializerOptions()
        {Encoder = JavaScriptEncoder.Create(UnicodeRanges.All)
        })!.Themes!.ToDictionary(x => x.Name);
        public static System.Timers.Timer hunderd_millsecond_timer { get; set; } = new System.Timers.Timer(100) { AutoReset = true, Enabled = true };
        public static Difficulty current_difficulty { get; set; } = Difficulty.normal;
        public static Theme current_block_theme { get; set; }
        public static ThemeInfo currentThemeInfo { get; set; } = themes["Fruit"];
        public static Image trans_Image { get; set; } = Resources.trans;
        public static (int, int) get_length_width() => current_difficulty != Difficulty.custom ? (7 * (1 + (int)current_difficulty), 4 * (1 + (int)current_difficulty)) : (cus_width, cus_height);
        public static List<Image> block_Images { get; set; } = new List<Image> { Resources.Apple, Resources.Banana, Resources.Beetroot, Resources.Cherry, Resources.Corn, Resources.Eggplant, Resources.Grape, Resources.Pear, Resources.Strawberry, Resources.Watermelon };
        public static List<Image> disappear_Images { get; set; } = new List<Image> { Resources.Gapple, Resources.Gbanana, Resources.Gbeetroot, Resources.Gcherry, Resources.Gcorn, Resources.Geggplant, Resources.Ggrape, Resources.Gpear, Resources.Gstrawberry, Resources.Gwatermelon };
        public static List<Image> direction_Images { get; set; } = new List<Image> { Resources.trans, Resources.u, Resources.r, Resources.ur, Resources.d, Resources.ud, Resources.dr, Resources.udr, Resources.l, Resources.ul, Resources.lr, Resources.ulr, Resources.dl, Resources.udl, Resources.dlr, Resources.udlr };
        public static List<Image> tip_direction_Image { get; set; } = new List<Image> { Resources.trans, Resources.tip_u, Resources.tip_r, Resources.tip_ur, Resources.tip_d, Resources.tip_ud, Resources.tip_dr, Resources.tip_udr, Resources.tip_l, Resources.tip_ul, Resources.tip_lr, Resources.tip_ulr, Resources.tip_dl, Resources.tip_udl, Resources.tip_dlr, Resources.tip_udlr };
        public static Image get_block_Image(int t) => block_Images[t];
        public static Image get_disappear_Images(int t) => disappear_Images[t];
        public static Image get_direction_Image(Direction direction) => direction_Images[(int)direction];
        public static int Images_size() => current_block_theme switch { Theme.fruit => 10, _ => 0, };
        public static Image get_tip_direction_Image(Direction direction) => tip_direction_Image[(int)direction];
        public static LianLianKan? form { get; set; }
        public static IGameControl? gameForm { get; set; }//gameBoard
        public static IGameMode? gameModeForm { get; set; }//entireGame
        public static IMenuForm? gameMenuForm { get; set; }//MenuForm
        public static Board board { get; set; } = new Board();
        public static Color def_Color { get; set; } = Color.FromArgb(0, 0, 0, 0);
        public static Color sel_Color { get; set; } = Color.FromArgb(0, 122, 204);
        public static Color mouse_upper_color { get; set; } = Color.FromArgb(97, 97, 108);
        public static Dictionary<string, List<string>> musics { get; set; } = new Dictionary<string, List<string>> { { "C418", new List<string> { "C418 - Beginning 2", "C418 - Floating Trees", "C418 - Moog City 2", "C418 - Mutation" } },
                                                                                                                     {"Sea Power",new List<string>{ "Sea Power - Advesperascit", "Sea Power - Burn, Baby, Burn", "Sea Power - Detective Arriving on the Scene", "Sea Power - Disco Elysium, Pt 1", "Sea Power - Disco Elysium, Pt 2", "Sea Power - Ecstatic Vibrations, Totally Transcendent", "Sea Power - Hope in Work and Joy in Leisure", "Sea Power - Ignus Nilsen Waltz", "Sea Power - Instrument of Surrender", "Sea Power - Krenel, Downwell, Somatosensor", "Sea Power - La Revacholiere", "Sea Power - Live With Me", "Sea Power - Martinaise, Terminal B", "Sea Power - Miss Oranje Disco Dancer", "Sea Power - Off We Go Into the Wild Pale Yonder", "Sea Power - Ployhedrons", "Sea Power - Precinct 41 Major Crime Unit", "Sea Power - Rue de Saint-Gislaine", "Sea Power - Saint-Brune 1147", "Sea Power - The Cryptozoologists", "Sea Power - The Doomed Commercial Area", "Sea Power - The Field Autopsy", "Sea Power - The Insulindian Miracle", "Sea Power - Tiger King", "Sea Power - We Are Not Checkmated", "Sea Power - Whirling In Rags 12Pm", "Sea Power - Whirling in Rags 8am", "Sea Power - Whirling in Rags 8pm", "Sea Power - Your Body Betrays Your Degeneracy", "Sea Power - Zaum" } } };
        public static Audio_res_manager audio_Res_Manager { get; set; } = new Audio_res_manager();
        public static Song_Audio_processer song_Audio_Processer { get; set; } = new Song_Audio_processer();
        public static Info_Audio_processer info_Audio_Processer { get; set; } = new Info_Audio_processer();
        public static ResourceManager res_Manager { get; set; } = new ResourceManager("CDSAE3_Lian_Lian_Kan.Properties.Resources", typeof(Resources).Assembly);
        public static CultureInfo res_Culture { get; set; } = new CultureInfo("en-US");
        public static Setting setting { get; set; } = new Setting();
        public static Charts charts { get; set; } = new Charts();
        public static int Song_Volume { get; set; } = 60;
        public static int Info_Volume { get; set; } = 60;
        public static bool loadFinished { get; set; } = true;

    }
}