@using MrCMS.Helpers
@model MrCMS.Web.Apps.NewsletterBuilder.Entities.NewsletterTemplate
@{
    ViewBag.Title = "Edit Newsletter Template";
    var templateDataOptions = ViewData["template-data-options"] as HashSet<Type> ?? new HashSet<Type>();
}
@using (Html.BeginForm("Edit", "NewsletterTemplate", FormMethod.Post))
{
    <fieldset>
        <legend>
            Edit Newsletter Template
            <span class="btn-group display-inline pull-right">
                @Html.ActionLink("Return to List", "Index", "NewsletterTemplate", null, new { @class = "btn btn-default" })
                <a href="@Url.Action("Delete", "NewsletterTemplate", new { id = Model.Id })" class="btn btn-danger" data-toggle="fb-modal">Delete</a>
                <input type="submit" class="btn btn-primary" value="Save" />
            </span>
        </legend>

        <div class="row">
            <div class="col-lg-12">
                <div class="form-group">
                    @Html.LabelFor(x => x.Name)
                    @Html.TextBoxFor(x => x.Name, new { @class = "form-control" })
                    @Html.ValidationMessageFor(x => x.Name)
                </div>
                <div class="form-group">
                    @Html.LabelFor(x => x.BaseTemplate)
                    @Html.TextAreaFor(x => x.BaseTemplate, new { @class = "form-control", rows = 6 })
                    @Html.ValidationMessageFor(x => x.BaseTemplate)
                </div>

                <div class="alert alert-info">
                    <strong>Available Tokens: </strong> [BodyContent]
                </div>

                <div class="form-group">
                    @Html.LabelFor(x => x.Divider)
                    @Html.TextAreaFor(x => x.Divider, new { @class = "form-control", rows = 6 })
                    @Html.ValidationMessageFor(x => x.Divider)
                </div>
                @if (templateDataOptions.Any())
                {
                    <h4>Content Items Templates</h4>
                    <table class="table table-condensed table-striped">
                        <thead>
                            <tr>
                                <th>
                                    Type
                                </th>
                                <th>
                                    Last Updated
                                </th>
                                <th>
                                    Actions
                                </th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (var type in templateDataOptions)
                            {
                                var existing = Model.ContentItemTemplateDatas.FirstOrDefault(data => data.GetType() == type);
                                <tr>
                                    <td>
                                        @type.Name.BreakUpString()
                                    </td>
                                    @if (existing == null)
                                    {
                                        <td>
                                            -
                                        </td>
                                        <td>
                                            @Html.ActionLink("Add", "Add", type.Name, new { templateId = Model.Id }, new { @class = "btn btn-xs btn-default" })
                                        </td>
                                    }
                                    else
                                    {
                                        <td>
                                            @existing.UpdatedOn
                                        </td>
                                        <td>
                                            @Html.ActionLink("Edit", "Edit", type.Name, new { id = existing.Id }, new { @class = "btn btn-xs btn-default" })
                                        </td>
                                    }
                                </tr>
                            }
                        </tbody>
                    </table>
                }
                @*<h4>Content Items Templates</h4>


                    <br />


                    <br />
                   
                    <br />
                *@
            </div>
        </div>
    </fieldset>
}

@{
    Html.IncludeScript("~/Apps/Ecommerce/Areas/Admin/Content/Scripts/custom/newsletter-ck.js");
}