﻿using System;
using System.Globalization;
using System.Text;
using System.Web.Mvc;

namespace Wierszowki.Helpers
{
    public static class SelectExtension
    {
        public static string MonthSelect(this HtmlHelper helper, string id)
        {
            var sb = new StringBuilder();
            sb.AppendFormat("<select id=\"{0}\" name=\"{0}\">", id);
            for (var i = 1; i <= 12; i++)
            {
                sb.AppendFormat("<option value=\"{0}\"{2}>{1}</option>", i, new CultureInfo("pl-PL").DateTimeFormat.GetMonthName(i),
                                DateTime.Now.Month == i ? " selected=\"selected\"" : "");
            }
            sb.Append("</select>");
            
            return sb.ToString();
        }

        public static string YearSelect(this HtmlHelper helper, string id)
        {
            var sb = new StringBuilder();
            sb.AppendFormat("<select id=\"{0}\" name=\"{0}\">", id);
            sb.AppendFormat("<option value=\"{0}\">{0}</option>", DateTime.Now.AddYears(-1).Year);
            sb.AppendFormat("<option value=\"{0}\" selected=\"selected\">{0}</option>", DateTime.Now.Year);
            sb.AppendFormat("<option value=\"{0}\">{0}</option>", DateTime.Now.AddYears(1).Year);
            sb.Append("</select>");

            return sb.ToString();
        }
    }
}