@using System.Linq
@using MrCMS.Helpers
@model MrCMS.Entities.Documents.Layout.LayoutArea
@{
    ViewBag.Title = "Edit | " + Model.AreaName;
}

@using (Html.BeginForm("Edit", "LayoutArea", FormMethod.Post, new {id = "edit-document"}))
{
    <fieldset>
        <legend>@Model.AreaName
            <span class="btn-group  display-inline  pull-right">
                @Html.ActionLink(Resource("Admin Layout Area Edit Back","Back to Layout"), "Edit", "Layout", new { id = Model.Layout.Id }, new { @class = "btn btn-default" })
                <a href="@Url.Action("Delete", "LayoutArea", new {id = Model.Id})" class="btn btn-danger" data-toggle="fb-modal">@Resource("Delete")</a>
                <button class="btn btn-primary">@Resource("Save")</button>
            </span>
        </legend>

        <div class="form-group">
            @Html.LabelFor(x => x.AreaName)
            @Html.TextBoxFor(x => x.AreaName, new { @class = "form-control" })
            @Html.ValidationMessageFor(x => x.AreaName, "", new { @class = "error" })
        </div>

        @{
            if (Model.GetWidgets().Any())
            {
                <table class="table table-condensed table-striped">
                    <thead>
                        <tr>
                            <th>@Resource("Name")
                            </th>
                            <th>@Resource("Type")
                            </th>
                            <th>@Resource("Actions")
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var widget in Model.GetWidgets())
                        {
                            <tr>
                                <td>@widget.Name</td>
                                <td>
                                    @widget.WidgetTypeFormatted
                                </td>
                                <td>
                                    <div class="btn-group">
                                        @Html.ActionLink(Resource("Edit"), "Edit", "Widget", new { id = widget.Id }, new { @class = "btn btn-default btn-xs", @data_toggle = "fb-modal" })
                                        <a href="@Url.Action(Resource("Delete"), "Widget", new {id = widget.Id})" class="btn btn-xs btn-danger" data-toggle="fb-modal">@Resource("Delete")</a>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            }
            else
            {
                @Html.InfoBlock(Resource("Heads up"), Resource("Admin Layout Area Widgets Info","Click add widget to add the first widget to this area."));
            }
        }
        
        <div class="btn-group">
            <a href="@Url.Action(Resource("Add"), "Widget", new {id = Model.Id, returnUrl = Request.Url})" class="btn btn-xs btn-default" data-toggle="fb-modal">@Resource("Admin Layout Area Add Widget", "Add widget")</a>
            @{
                if (Model.GetWidgets().Any())
                {
                    @Html.ActionLink(Resource("Sort"), "SortWidgets", "LayoutArea", new { id = Model.Id, returnUrl = Request.Url.ToString() }, new { @class = "btn btn-xs btn-default", @data_toggle = "fb-modal" })
                }
            }

        </div>

    </fieldset>
    
    <hr />
}