<div class="content-header">
    <div class="row">
        <div class="col-md-8">
            <h2>{{::vm.translate.get('Manage products')}}</h2>
        </div>
        <div class="col-md-4 text-right">
            
        </div>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <div class="card-header">
                        <h3 class="card-title">{{::vm.translate.get('Manage products for warehouse')}} <strong>{{ vm.selectedWarehouse.name }}</strong></h3>
                        <div class="card-tools">
                            <form>
                                <div class="form-row">
                                    <div class="col">
                                        <select class="form-control" ng-change="vm.wareHouseSelectChange()" ng-model="vm.selectedWarehouse"
                                                ng-options="warehouse as warehouse.name for warehouse in vm.warehouses"></select>
                                    </div>
                                    <div class="col">
                                        <button class="btn btn-success float-right" ng-click="vm.addAllProducts()">{{::vm.translate.get('Add All Products')}}</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                    <div class="card-body p-0 table-responsive">
                        <table ng-if="vm.selectedWarehouse" class="table table-striped" st-pipe="vm.getProducts" st-table="vm.products">
                            <thead>
                                <tr>
                                    <th st-sort="Id" class="sortable">Id</th>
                                    <th st-sort="Name" class="sortable">{{::vm.translate.get('Product Name')}}</th>
                                    <th st-sort="Sku" class="sortable">{{::vm.translate.get('Product Sku')}}</th>
                                    <th>{{::vm.translate.get('Exist')}}</th>
                                    <th>{{::vm.translate.get('Select to add')}}</th>
                                </tr>
                                <tr>
                                    <th></th>
                                    <th>
                                        <div class="form-group">
                                            <input class="form-control" st-search="ProductName" />
                                        </div>
                                    </th>
                                    <th>
                                        <div class="form-group">
                                            <input class="form-control" st-search="ProductSku" />
                                        </div>
                                    </th>
                                    <th>
                                        <div class="form-group">
                                            <select class="form-control" st-search="IsExistInWarehouse">
                                                <option value="">{{::vm.translate.get('All')}}</option>
                                                <option value="true">{{::vm.translate.get('Yes')}}</option>
                                                <option value="false">{{::vm.translate.get('No')}}</option>
                                            </select>
                                        </div>
                                    </th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody ng-show="!vm.isLoading">
                                <tr ng-repeat="item in vm.products">
                                    <td>{{item.id}}</td>
                                    <td>{{item.name}}</td>
                                    <td>{{item.sku}}</td>
                                    <td>{{item.isExistInWarehouse}}</td>
                                    <td><input type="checkbox" ng-disabled="item.isExistInWarehouse" class="productid-select" name="selectedProductIds" value="{{item.id}}"></td>
                                </tr>
                                <tr>
                                    <td colspan="2"><button ui-sref="stocks" class="btn btn-default">{{::vm.translate.get('Cancel')}}</button></td>
                                    <td colspan="3">
                                        <button class="btn btn-success float-right" ng-click="vm.addSelectedProducts()"><span class="fa fa-save"></span> 
                                            {{::vm.translate.get('Add selected products')}}
                                        </button>
                                    </td>
                                </tr>
                            </tbody>
                            <tbody ng-show="vm.isLoading">
                                <tr>
                                    <td colspan="5" class="text-center">Loading ... </td>
                                </tr>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <td class="text-center" st-pagination="" st-items-by-page="50" st-displayed-pages="10" colspan="5"></td>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="card-footer">
                        <div>
                            <div ng-show="!vm.isLoading" colspan="3">{{vm.tableStateRef.pagination.totalItemCount | number:0}} {{::vm.translate.get('records found')}}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>