using System;
using System.Net.Http;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace BeWoPlanerMobil.Util
{
	public static class HtmlHelperExtensions
	{
		public static IHtmlString GetPageUrl<TModel>(this HtmlHelper<TModel> htmlHelper, ViewContext viewContext)
		{
			var urlBuilder = new StringBuilder();
			urlBuilder.Append("data-url='");

			if (viewContext.HttpContext.Request.Url != null) 
				urlBuilder.Append(viewContext.HttpContext.Request.Url.GetComponents(UriComponents.Path, UriFormat.UriEscaped));
			else
				throw new HttpRequestException();

			urlBuilder.Append("'");
			return htmlHelper.Raw(urlBuilder.ToString());
		} 
	}
}