@using Groceries.Stores
@model StoreListModel
@{
    ViewBag.Title = "Stores";
}

<div class="row">
    <h1 class="row__fill">Stores</h1>
    <form method="get" data-controller="search-form" data-turbo-frame="table" data-turbo-action="advance">
        <input type="hidden" name="page" value="1" />
        <div class="form-field">
            <div class="form-field__control input input--leading-inset input--trailing-addon">
                <div class="input__inset">
                    @* Search icon *@
                    <svg class="icon icon--sm" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M0 0h24v24H0V0z" fill="none" /><path d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z" /></svg>
                </div>
                <input class="input__control" type="search" name="search" value="@Model.Search" placeholder="Search" autocomplete="off" data-action="search-form#input" />
                <button class="input__addon button" data-search-form-target="button">Search</button>
            </div>
        </div>
    </form>
    <a class="button button--primary" asp-action="NewStore" data-turbo-frame="modal">New store</a>
</div>

<turbo-frame id="table" target="_top">
    <section class="table">
        <table>
            <thead>
                <tr>
                    <th scope="col" class="table__header">Retailer</th>
                    <th scope="col" class="table__header" style="width: 100%">Name</th>
                    <th scope="col" class="table__header">Transactions</th>
                    <th scope="col" class="table__header"></th>
                </tr>
            </thead>
            <tbody>
                @foreach (var store in Model.Stores)
                {
                    <tr>
                        <td class="table__cell">@store.Retailer</td>
                        <td class="table__cell">@store.Name</td>
                        <td class="table__cell table__cell--numeric">@store.TotalTransactions</td>
                        <td class="table__cell">
                            <a class="link" asp-action="EditStore" asp-route-id="@store.Id" data-turbo-frame="modal">Edit</a>
                        </td>
                    </tr>
                }
            </tbody>
        </table>
        <partial name="_TablePaginator" model="Model.Stores" />
    </section>
</turbo-frame>