@using MrCMS.Helpers
@using MrCMS.Paging
@using MrCMS.Web.Apps.Ecommerce.Entities.GiftCards
@using MrCMS.Web.Apps.Ecommerce.Helpers
@model MrCMS.Web.Apps.Ecommerce.Areas.Admin.Models.GiftCardSearchQuery
@{
    var results = ViewData["results"] as IPagedList<GiftCard> ?? PagedList<GiftCard>.Empty;
}
@using (Html.BeginForm("Index", "GiftCard", FormMethod.Get, new { @class = "margin0" }))
{
    <fieldset>
        <legend>
            Gift Cards
            <span class="btn-group pull-right">
                @Html.ActionLink("Settings", "Index", "GiftCardSettings", null, new { @class = "btn btn-default" })
                @Html.ActionLink("Add", "Add", "GiftCard", null, new { @class = "btn btn-default", data_toggle = "fb-modal" })
                <input type="submit" value="Search" class="btn btn-primary"/>
            </span>
        </legend>

        <div class="row">
            <div class="col-lg-4">
                <div class="form-group">
                    @Html.LabelFor(x => x.Recipient)
                    @Html.TextBoxFor(x => x.Recipient, new { @class = "form-control" })
                </div>
            </div>

            <div class="col-lg-4">
                <div class="form-group">
                    @Html.LabelFor(x => x.Sender)
                    @Html.TextBoxFor(x => x.Sender, new { @class = "form-control" })
                </div>
            </div>

            <div class="col-lg-4">
                <div class="form-group">
                    @Html.LabelFor(x => x.GiftCode)
                    @Html.TextBoxFor(x => x.GiftCode, new { @class = "form-control" })
                </div>
            </div>
        </div>

        @if (results.Any())
        {
            <table class="table table-condensed table-striped">
                <thead>
                    <tr>
                        <th>
                            Recipient
                        </th>
                        <th>
                            Code
                        </th>
                        <th>
                            Value
                        </th>
                        <th>
                            Available Blance
                        </th>
                        <th>
                            Status
                        </th>
                        <th>
                            Actions
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in results)
                    {
                        <tr>
                            <td>
                                @item.RecipientEmail
                            </td>
                            <td>
                                @item.Code
                            </td>
                            <td>
                                @item.Value.ToCurrencyFormat()
                            </td>
                            <td>
                                @item.AvailableAmount.ToCurrencyFormat()
                            </td>
                            <td>
                                @item.Status
                            </td>
                            <td>
                                <div class="btn-group">
                                    @Html.ActionLink("Edit", "Edit", "GiftCard", new { id = item.Id }, new { @class = "btn btn-xs btn-default" })
                                    @Html.ActionLink("Delete", "Delete", "GiftCard", new { id = item.Id }, new { @class = "btn btn-xs btn-danger", data_toggle = "fb-modal" })
                                </div>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            @Html.Pager(results, "Index", page => new { page })
        }
        else
        {
            @:No giftcards created.
        }
    </fieldset>

}