@using OurUmbraco.Release
@inherits UmbracoTemplatePage
@{
    Layout = "~/Views/Master.cshtml";
    var allReleases = Release.GetAllReleaseFromFile();
    var inProgress = allReleases.Where(x => x.inProgressRelease).ToList();

    var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
    var currentPage = umbracoHelper.TypedContent(umbracoHelper.UmbracoContext.PageId);
    var releaseLanding = currentPage.Parent.Children().FirstOrDefault(x => x.ContentType.Alias == "ReleaseLanding");
}

<div class="has-sidebar">
    <div class="page-content">

        <div class="sidebar-area">
            <div class="sidebar-content">
                <div class="content-wrapper">

                    <nav>
                        <ul class="level-1">
                            @foreach (var currentRelease in allReleases.Where(x => x.released && x.currentRelease))
                            {
                                <li>
                                    <a class="active" href="/contribute/releases/@(currentRelease.version.Replace(".", string.Empty))">
                                        <h3>Latest Release - v@(currentRelease.version)</h3>
                                    </a>
                                </li>
                            }
                            <li class="active open">
                                <a href="/contribute/progress">
                                    <h3>In Progress</h3>
                                </a>
                                <ul class="level-2">
                                    @foreach (var release in inProgress)
                                    {
                                        <li>
                                            <a href="/contribute/releases/@(release.version.Replace(".", string.Empty))">
                                                <h4>v@(release.version)</h4>
                                            </a>
                                        </li>
                                    }
                                </ul>
                            </li>
                            <li>
                                <a href="/contribute/releases">
                                    <h3>All Releases</h3>
                                </a>
                            </li>
                        </ul>
                    </nav>

                </div>
                <!-- .content-wrapper -->
            </div>
            <!-- .sidebar-content -->
        </div>
        <div class="main-area">
            <div class="main-content">
                <div class="content-wrapper">
                    <div style="margin-top: 25px;">
                        <umbraco:Macro linkToCurrent="1" Alias="Breadcrumb" runat="server"></umbraco:Macro>
                    </div>
                    <div class="markdown-syntax">
                        <h1>In progress</h1>
                        <p><em>Versions of Umbraco currently in production</em></p>
                    </div>
                    <!-- #markdown-docs -->
                    <div class="releaseTable row">
                        @foreach (var release in inProgress)
                        {

                            var completedIssues = release.issues.Count(x => x.state == "Fixed");
                            var totalIssues = release.issues.Count();
                            var percentComplete = Math.Round(((double)100 / totalIssues) * completedIssues);
                            var releaseDateParsed = DateTime.Now;
                            if (release.releaseDate != string.Empty)
                            {
                                releaseDateParsed = DateTime.Parse(release.releaseDate.Substring(3, 2) + "-" + release.releaseDate.Substring(0, 2) + "-" + release.releaseDate.Substring(6));
                            }

                            var releaseDate = release.releaseDate == "" ? "Not yet determined" : releaseDateParsed.ToString("dddd, MMMM d yyyy");
                            IPublishedContent releaseContent = null;
                            if (releaseLanding != null)
                            {
                                releaseContent = releaseLanding.Children().FirstOrDefault(x => x.Name.ToLowerInvariant() == release.version.ToLowerInvariant());
                                if (releaseContent != null)
                                {
                                    var overrideDescription = releaseContent.GetPropertyValue<bool>
                                        ("overrideYouTrackDescription");
                                    if (overrideDescription)
                                    {
                                        release.releaseDescription = releaseContent.GetPropertyValue<string>
                                            ("bodyText");
                                    }
                                    var overrideReleaseDate = releaseContent.GetPropertyValue<string>
                                        ("overrideYouTrackReleaseDate");
                                    if (string.IsNullOrWhiteSpace(overrideReleaseDate) == false)
                                    {
                                        releaseDate = overrideReleaseDate;
                                    }

                                }
                            }

                            <div class="inprogress">
                                <div class="col-xs-3">
                                    <span class="dot big progress">
                                        <div class="chart" data-percent="@percentComplete">
                                            <div class="percentage">@(percentComplete)%</div>
                                        </div>
                                        <span class="line v-line top" style="@(release == inProgress.First() == false ? " display: block;" : null)"></span>
                                        <span class="line v-line"></span>
                                        <span class="line h-line"></span>
                                    </span>
                                    <span class="dot small">
                                        <span class="line v-line" style="@(release == inProgress.Last() == false ? " display: block;" : null)"></span>
                                        <span class="line h-line"></span>
                                    </span>
                                </div>

                                <div class="col-xs-9">
                                    <div class="row explain">
                                        <div class="col-xs-12">
                                            <h4 class="text-right"><a href="/contribute/releases/@(release.version.Replace(".",""))">v@(release.version)</a></h4>
                                            <small><span>@Html.Raw(release.releaseDescription)</span></small>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="changes">
                                                <small>Features: <span>@(release.issues.Count(x => x.type.ToLowerInvariant().Contains("feature")))</span></small>
                                                <small>Issues: @(release.issues.Count(x => x.type.ToLowerInvariant().Contains("feature") == false && x.breaking == false))<span></span></small>
                                                <small>Breaking changes: <span>@(release.issues.Count(x => x.breaking))</span></small>
                                            </div>
                                        </div>
                                        <div class="col-xs-6">
                                            <div class="changes">
                                                <small>Release date:</small>
                                                <small>@releaseDate</small>
                                            </div>
                                        </div>

                                    </div>
                                </div>
                            </div>
                        }
                    </div>
                </div>
                <!-- .content-wrapper -->
            </div>
            <!-- .main-content -->
        </div>
        <!-- .main-area -->

    </div>
    <!-- .page-content -->
</div>


@section EndScripts {
    <script src="https://cdnjs.cloudflare.com/ajax/libs/easy-pie-chart/2.1.4/jquery.easypiechart.min.js"></script>
    <script type="text/javascript">
        setTimeout(function () {
            $('.chart').easyPieChart({
                size: 60,
                barColor: '#569327',
                scaleColor: false,
                trackColor: '#daf0c9'
            });
        }, 300);
    </script>
}