@{
    ViewData["Title"] = "Shop addons";
}

@model ICollection<ShopOrderViewModel>

<link href="~/administration/vendor/datatables/dataTables.bootstrap4.min.css" rel="stylesheet">

<partial name="_TempDataPartial" /><div class="container-fluid">
    <h1 class="h3 mb-2 text-gray-800">All Shop Orders</h1>
    <hr />
    <div class="card shadow mb-4">
        <div class="card-header py-3">
            <h6 class="m-0 font-weight-bold text-primary">Shop list all existing orders</h6>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
                    <thead>
                        <tr>
                            <th>Full Name</th>
                            <th>Email</th>
                            <th>Phone Number</th>
                            <th>Address</th>
                            <th>Zip Code</th>
                            <th>Aditional Information</th>
                            <th>All Products</th>
                            <th>Total Price</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tfoot>
                        <tr>
                            <th>Full Name</th>
                            <th>Email</th>
                            <th>Phone Number</th>
                            <th>Address</th>
                            <th>Zip Code</th>
                            <th>Aditional Information</th>
                            <th>All Products</th>
                            <th>Total Price</th>
                            <th>Actions</th>
                        </tr>
                    </tfoot>
                    <tbody>
                        @foreach (var order in Model)
                        {
                            <tr onmouseover="markTableRow()">
                                <td width="50">
                                    @order.UserFullName
                                </td>
                                <td width="30">
                                    <div>
                                        @order.Email
                                    </div>
                                </td>
                                <td width="70">
                                    <div>
                                        @order.PhoneNumber
                                    </div>
                                </td>
                                <td width="80">
                                    <div>
                                        @order.Address
                                    </div>
                                </td>
                                <td width="40">
                                    <div>
                                        @order.ZipCode
                                    </div>
                                </td>
                                <td width="80" height="120">
                                    <div style="height: 120px; overflow: auto">
                                        @Html.Raw(order.AditionalInformation)
                                    </div>
                                </td>
                                <td width="450">
                                    <div style="height: 120px; overflow: auto" id="@order.Id-orderDetails">
                                        @foreach (var product in order.Products)
                                        {
                                            <div>@product.Name</div>
                                            <div>Single Price: <strong>@product.Price</strong></div>
                                            <div>Available Quantity: <b>@product.AvailableQuantity</b></div>
                                            <div>Total product price: <b>@product.TotalProductPrice (X @product.WantedQuantity)</b></div>
                                            <hr />
                                        }
                                    </div>
                                </td>
                                <td width="40">
                                    <div>
                                        @order.TotalPrice
                                    </div>
                                </td>
                                <td width="160">
                                    <div class="row">
                                        <div class="col-md-6">
                                            <button class="btn btn-info" data-toggle="modal" data-target="#editOrderStatusModal" onclick="setOrderIdAndStatus('@order.Id')">
                                                <i class="fas fa-dolly"></i>
                                            </button>
                                        </div>
                                        <div class="col-md-6">
                                            <button class="btn btn-success" data-toggle="modal" data-target="#viewOrder" onclick="viewOrder('@order.Id')">
                                                <i class="fas fa-glasses"></i>
                                            </button>
                                        </div>
                                    </div>
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
        <input id="targetOrderId" type="hidden" />
    </div>
</div>
<div class="modal fade" id="editOrderStatusModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Ready to Edit order status?</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">Please edit order status. Select some of the drop-down options.</div>
            <div class="row">
                <div class="modal-body">
                    <select id="editStatusSelect" asp-items="Html.GetEnumSelectList<OrderStatus>()" class="form-control">
                        <option selected="selected" disabled value="">Please select</option>
                    </select>
                </div>
            </div>
            <div class="row">
                <div class="modal-body" id="messageStatus">
                </div>
            </div>
            <div class="modal-footer">
                <button id="cancelEditStatusButton" class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                <button id="editStatusButton" onclick="changeOrderStatus()" class="btn btn-primary" disabled>Edit status</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="viewOrder" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Ready to inspect order?</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="row">
                <div class="modal-body" id="orderDetails">
                </div>
            </div>
            <div class="modal-footer">
                <button id="cancelEditStatusButton" class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
            </div>
        </div>
    </div>
</div>

@section Scripts{
    <script src="~/administration/vendor/datatables/jquery.dataTables.min.js"></script>
    <script src="~/administration/vendor/datatables/dataTables.bootstrap4.min.js"></script>
    <script src="~/administration/js/demo/datatables-demo.js"></script>
    <script src="~/administration/js/editOrderStatus.js"></script>
    <script src="~/administration/js/orderDetails.js"></script>
    <script src="~/administration/js/dataTableScripts.js"></script>
}