using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Models.Identity;

namespace Services
{
    public static class Statics
    {
        public const string TableClass = "table table-striped table-bordered border";
        public enum CultureType
        {
            En,
            Fa
        }
        public static CultureType Culture = CultureType.Fa;
        public static string LoginTokenKey = "SignIn";
        public static string RefreshTokenKey = "RefreshToken";
        public static string Agent = "";
        public static string FcmToken = "RefreshToken";
        public static CheckLoginResponse CurrentLoginInfo { get; set; }
        public static DateTime? LastCheck { set; get; }


        public static string BaseAddress = "https://api.senso.farm/";
        public static string UploadFolder=$"{BaseAddress}UploadedFiles";
        //linux:
        //public static string BaseAddress = "https://localhost:5001/";
        //windows:
        //public static string BaseAddress = "https://localhost:44331/";
        public static string ReplaceNewLineWithBr(this string text)
        {
            var result = Regex.Replace(text, @"\r\n?|\n", "<br/>");
            result = result.Replace("<br/><br/><br/>", "<br/>").Replace("<br/><br/>", "<br/>");
            return result;
        }
        public static CultureInfo GetPersianCulture()
        {
            var culture = new CultureInfo("fa-IR");
            DateTimeFormatInfo formatInfo = culture.DateTimeFormat;
            formatInfo.AbbreviatedDayNames = new[] { "ی", "د", "س", "چ", "پ", "ج", "ش" };
            formatInfo.DayNames = new[] { "یکشنبه", "دوشنبه", "سه شنبه", "چهار شنبه", "پنجشنبه", "جمعه", "شنبه" };
            var monthNames = new[]
            {
                "فروردین", "اردیبهشت", "خرداد", "تیر", "مرداد", "شهریور", "مهر", "آبان", "آذر", "دی", "بهمن",
                "اسفند",
                "",
            };
            formatInfo.AbbreviatedMonthNames =
                formatInfo.MonthNames =
                    formatInfo.MonthGenitiveNames = formatInfo.AbbreviatedMonthGenitiveNames = monthNames;
            formatInfo.AMDesignator = "ق.ظ";
            formatInfo.PMDesignator = "ب.ظ";
            formatInfo.ShortDatePattern = "yyyy/MM/dd";
            formatInfo.LongDatePattern = "dddd, dd MMMM,yyyy";
            formatInfo.FirstDayOfWeek = DayOfWeek.Saturday;
            System.Globalization.Calendar cal = new PersianCalendar();
            FieldInfo fieldInfo = culture.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Instance);
            if (fieldInfo != null)
                fieldInfo.SetValue(culture, cal);
            FieldInfo info = formatInfo.GetType().GetField("calendar", BindingFlags.NonPublic | BindingFlags.Instance);
            if (info != null)
                info.SetValue(formatInfo, cal);
            culture.NumberFormat.NumberDecimalSeparator = "/";
            culture.NumberFormat.DigitSubstitution = DigitShapes.NativeNational;
            culture.NumberFormat.NumberNegativePattern = 0;
            return culture;
        }
    }
}
