@using System.Collections.Generic
@using System.Linq
@using MrCMS.Entities.Resources
@using MrCMS.Helpers
@using MrCMS.Paging
@model MrCMS.Web.Areas.Admin.Models.StringResourceSearchQuery
@{
    var resources = ViewData["results"] as IPagedList<StringResource> ?? PagedList<StringResource>.Empty;
    var languageOptions = ViewData["language-options"] as List<SelectListItem> ?? new List<SelectListItem>();
    var siteOptions = ViewData["site-options"] as List<SelectListItem> ?? new List<SelectListItem>();
}

@using (Html.BeginForm("Index", "Resource", FormMethod.Get))
{
    <fieldset>
        <legend>
            @Resource("Admin Resources Title", "Resources")
            <span class="btn-group display-inline pull-right">
                @Html.ActionLink(Resource("Admin Resource Export", "Export All"), "Export", "ResourceUpdate", new { }, new { @class = "btn btn-default" })
                @Html.ActionLink(Resource("Admin Resource Export Filtered", "Export As Filtered"), "Export", "ResourceUpdate", new { Model.Key, Model.Value }, new { @class = "btn btn-default" })

                <input type="submit" class="btn btn-primary" value="@Resource("Filter")" />
            </span>
        </legend>

        <div class="row">
            <div class="col-sm-6 col-lg-3">
                <div class="form-group">
                    @Html.LabelFor(query => query.Key)
                    @Html.TextBoxFor(query => query.Key, new { @class = "form-control" })
                </div>
            </div>
            <div class="col-sm-6 col-lg-3">
                <div class="form-group">
                    @Html.LabelFor(query => query.Value)
                    @Html.TextBoxFor(query => query.Value, new { @class = "form-control" })
                </div>
            </div>
            <div class="col-sm-6 col-lg-3">
                <div class="form-group">
                    @Html.LabelFor(query => query.SiteId)
                    @Html.DropDownListFor(query => query.SiteId, siteOptions, new { @class = "form-control" })
                </div>
            </div>
            <div class="col-sm-6 col-lg-3">
                <div class="form-group">
                    @Html.LabelFor(query => query.Language)
                    @Html.DropDownListFor(query => query.Language, languageOptions, new { @class = "form-control" })
                </div>
            </div>
        </div>
    </fieldset>
}

@if (!resources.Any())
{
    @Resource("Admin Resources No Resources", "No resources")
}
else
{
    <table class="table table-striped table-condensed" style="overflow: scroll">
        <thead>
            <tr>
                <th>
                    @Resource("Key")
                </th>
                <th>
                    @Resource("Value")
                </th>
                <th>
                    @Resource("Site")
                </th>
                <th>
                    @Resource("Language")
                </th>
                <th>
                    @Resource("Actions")
                </th>
            </tr>
        </thead>
        <tbody>
            @foreach (var resource in resources)
            {
                <tr>
                    <td>
                        @resource.DisplayKey
                    </td>
                    <td>
                        @resource.Value
                    </td>
                    <td>
                        @resource.DisplaySite
                    </td>
                    <td>
                        @resource.DisplayUICulture
                    </td>
                    <td>
                        <div class="btn-group">
                            @Html.ActionLink("Edit", "Edit", "Resource", new { id = resource.Id }, new { @class = "btn btn-xs btn-default", data_toggle = "fb-modal" })
                            @if (resource.IsDefault)
                            {
                                @*<button type="button" class="btn btn-success btn-xs">Add override</button>
                                    <button type="button" class="btn btn-success dropdown-toggle btn-xs" data-toggle="dropdown" aria-expanded="false">
                                        <span class="caret"></span>
                                        <span class="sr-only">Toggle Dropdown</span>
                                    </button>*@
                                <button class="btn btn-success btn-xs dropdown-toggle" type="button" data-toggle="dropdown" aria-expanded="false">
                                    Add override <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li>
                                        @Html.ActionLink("Site", "ChooseSite", "Resource", new { resource.Key }, new { data_toggle = "fb-modal" })
                                        @Html.ActionLink("Language", "Add", "Resource", new { resource.Key, language = true }, new { data_toggle = "fb-modal" })
                                        @Html.ActionLink("Site & Language", "ChooseSite", "Resource", new { resource.Key, language = true }, new { data_toggle = "fb-modal" })
                                    </li>
                                </ul>
                            }
                            else
                            {
                                @Html.ActionLink("Delete", "Delete", "Resource", new { id = resource.Id }, new { @class = "btn btn-danger btn-xs", data_toggle = "fb-modal" })
                            }

                        </div>
                    </td>
                </tr>
            }
        </tbody>
    </table>
}
@Html.Pager(resources, "Index", i => new { page = i })

<fieldset>
    <legend>
        @Resource("Admin Resources Import Resources", "Import Resources")
    </legend>
    @using (Html.BeginForm("Import", "ResourceUpdate", FormMethod.Post, new { enctype = "multipart/form-data" }))
    {
        <div class="input-group">
            <input type="file" name="file" class="form-control" />
            <span class="input-group-btn">
                <button class="btn btn-default">@Resource("Admin Resources Import Button", "Import")</button>
            </span>
        </div>
    }
</fieldset>
