using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Helpers
{
    public static class MonthComboBoxDataHelper
    {

        public static IEnumerable<MonthComboBoxData> GetMonthComboBoxData(int monthsNeeded)
        {
            var retval = new List<MonthComboBoxData>();
            var currentYear = DateTime.Now.Year;
            var currentMonth = DateTime.Now.Month;
            var previousYear = currentYear - 1;

            var culture = new CultureInfo("cs-CZ");

            var previousYearMonthsNeeded = monthsNeeded - currentMonth;

            if (previousYearMonthsNeeded > 0)
            {
                for(int i = 12; i > 12 - previousYearMonthsNeeded; i--)
                {
                    var monthData = new MonthComboBoxData();
                    monthData.Year = previousYear;
                    monthData.Month = i;
                    monthData.DisplayName = $"{culture.DateTimeFormat.GetMonthName(i)} {previousYear}";
                    retval.Add(monthData);
                }
            }

            retval.Reverse();

            var currentYearMonths = new List<MonthComboBoxData>();
            for(int i = currentMonth; i > 0; i--)
            {
                var monthData = new MonthComboBoxData();
                monthData.Year = currentYear;
                monthData.Month = i;
                monthData.DisplayName = $"{culture.DateTimeFormat.GetMonthName(i)} {currentYear}";
                currentYearMonths.Add(monthData);
            }

            currentYearMonths.Reverse();
            retval.AddRange(currentYearMonths);
            retval.Reverse();
            return retval;

        }
    }
}
