@using OurUmbraco.MarketPlace.Interfaces
@using OurUmbraco.Project
@using Umbraco.Core

@{
	System.Web.Helpers.AntiForgeryConfig.SuppressXFrameOptionsHeader = true;

    var id = int.Parse(Request.QueryString["category_id"]);
    var categoryProvider = new OurUmbraco.MarketPlace.Providers.UmbracoCategoryProvider();
    var category = categoryProvider.GetCategory(id);
    var fullversion = Request.QueryString["fullversion"];

    var version = "v45";
    if (Request.QueryString["version"] != null)
    {
        version = Request.QueryString["version"].ToLower();
    }

    if (!string.IsNullOrEmpty(fullversion) && fullversion.Substring(0, 1) == "7")
    {
        version = "v7";
    }

    var ProjectsProvider = new OurUmbraco.MarketPlace.NodeListing.NodeListingProvider();
    var qs = Request.RawUrl.Substring(Request.RawUrl.IndexOf('?') + 1).Replace("&category_id=" + id, "");

    const string uniqueWhatever = "254D2E95-4E57-4777-AC01-2F45B28E942C";
    var cacheKey = uniqueWhatever + "[" + category.Id + "]";
    var cache = ApplicationContext.Current.ApplicationCache.RuntimeCache;
    IEnumerable<IListingItem> projects = (IEnumerable<IListingItem>) cache.GetCacheItem(cacheKey, () =>
        ProjectsProvider
            .GetListingsByCategory(category, 0, 0, true, true)
            .Where(x => !x.NotAPackage && x.Approved &&
                        (string.Join("", x.UmbracoVerionsSupported).Contains("nan") ||
                         string.Join("", x.UmbracoVerionsSupported).Contains(version))),
        TimeSpan.FromMinutes(10));

    var pUrl = "/repo_viewproject?" + qs + "&project_id=";
}

<ul id="breadcrumb">
    <li><a href="/repo?@qs">Repository</a> &rarr;</li>
    <li>@category.Name</li>
</ul>


<div id="category">
    <h1>@category.Name</h1>

    <ul class="projects">
        @foreach (var project in projects)
        {
            <li class="clearfix">
                <div class="deliPackage">

                    <div class="brief">
                        @{
                            var screenShot = project.DefaultScreenshot;
                            var image = string.IsNullOrEmpty(screenShot) == false ? screenShot + "?bgcolor=fff&width=50&height=50&format=png" : "/css/img/package2.png";
                        }
                        <a rel="@project.ProjectGuid" href="@pUrl@project.Id" class="packageIcon" style="background: url('@image') no-repeat top left;">Package</a>

                        <h3><a href="@pUrl@project.Id">@project.Name</a></h3>

                        <div class="category">@project.Name</div>


                        <div class='commercialIndicator @project.ListingType'>@project.ListingType</div>
                    </div>

                    <div class="hiLite">

                        <p><a rel="@project.ProjectGuid" title="@project.Name" href="@pUrl@project.Id">@project.Name</a></p>

                    </div>

                    <div class="popularity">
                        <div class="karma">
                            @project.Karma
                            <small>Karma</small>
                        </div>
                        <div class="downloads">
                            @project.Downloads
                            <small>Downloads</small>
                        </div>
                    </div>
                </div>
            </li>

        }
    </ul>
</div>
