﻿@using Meganium.Api.Entities
@using Meganium.Api.Trash
@using Meganium.Api.Entities
@using Meganium.Api.Trash
@using Meganium.Api.Resources
@model Meganium.Api.ViewModels.PostIndexVm
@{
    ViewBag.Title = String.Format(Resource.AdminCustomEntity, Model.PostType.PluralName);
    ViewBag.Icon = Model.PostType.IconId;
}
<div class="btn-toolbar">
    <a href="@Url.Action("Create", new { postTypeId = Model.PostType.Id })" class="btn btn-primary">@String.Format(Resource.CreateCustomEntity, Model.PostType.SingularName)</a>
</div>
@if (!Model.Posts.Any())
{
    <text>@Resource.ThereIsNothingToBeShowed</text>
    return;
}
<table class="table table-striped">
    <tr>
        <th></th>
        <th>
            @Resource.Title
        </th>
        <th>@Resource.CreatedBy
        </th>

        @if (Model.PostType.Behavior.HasFlag(PostType.BehaviorFlags.AllowPhotos))
        {
            <th>@Resource.PhotoCount
            </th>
        }
        @if (Model.PostType.Behavior.HasFlag(PostType.BehaviorFlags.AllowCategories))
        {
            <th>@Resource.Categories
            </th>
        }
        @if (Model.PostType.Behavior.HasFlag(PostType.BehaviorFlags.AllowHash))
        {
            <th>@Resource.Code
            </th>
        }
        <th>@Resource.PublishedAt
        </th>
        <th>@Resource.Actions
        </th>
    </tr>
    <tbody>
        @{
            foreach (var item in Model.Posts)
            {
            <tr>
                <td>
                    @if (item.FeaturedMediaFile != null)
                    {
                        @Url.DefaultThumbnail(item.FeaturedMediaFile)
                    }
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.Title)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.CreatedBy.DisplayName)
                </td>
                @if (Model.PostType.Behavior.HasFlag(PostType.BehaviorFlags.AllowPhotos))
                {
                    <td>@item.MediaFiles.Count
                    </td>
                }
                @if (Model.PostType.Behavior.HasFlag(PostType.BehaviorFlags.AllowCategories))
                {
                    <td>@item.CategoriesCsv
                    </td>
                }
                @if (Model.PostType.Behavior.HasFlag(PostType.BehaviorFlags.AllowHash))
                {
                    <td>@item.Hash
                    </td>
                }

                <td>
                    @Html.DateTimeSpan(item.PublishedAt)
                </td>
                <td>
                    @Html.ActionLink(Resource.Edit, "Edit", new { id = item.Id })
                    |
                    @Html.ActionLink(Resource.Delete, "Delete", new { id = item.Id }, new { @class = "delete-button" })
                </td>
            </tr>

            }
        }
    </tbody>
</table>
