<div class="content-header">
    <div class="row">
        <div class="col-md-8">
            <h2>{{::vm.translate.get('Customers')}}</h2>
        </div>
        <div class="col-md-4 text-right">
            <a ui-sref="customer-create" class="btn btn-success"><span class="fa fa-plus"></span> {{::vm.translate.get('Create Customer')}}</a>
        </div>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card" st-pipe="vm.getCustomers" st-table="vm.customers">
                    <div class="card-header">
                        <div class="card-tools">
                            <st-date-range predicate="CreatedOn" before="query.before" after="query.after"></st-date-range>
                        </div>
                    </div>
                    <div class="card-body p-0 table-responsive">
                        <div class="table-responsive">
                            <table class="table table-striped">
                                <thead>
                                    <tr>
                                        <th st-sort="FullName" class="sortable">{{::vm.translate.get('FullName')}}</th>
                                        <th st-sort="Email" class="sortable">{{::vm.translate.get('Email')}}</th>
                                        <th>{{::vm.translate.get('Customer Groups')}}</th>
                                        <th st-sort="CreatedOn" class="sortable">{{::vm.translate.get('Created On')}}</th>
                                        <th>{{::vm.translate.get('Actions')}}</th>
                                    </tr>
                                    <tr>
                                        <th>
                                            <div class="form-group">
                                                <input class="form-control" st-search="FullName" />
                                            </div>
                                        </th>
                                        <th>
                                            <div class="form-group">
                                                <input class="form-control" st-search="Email" />
                                            </div>
                                        </th>
                                        <th>
                                            <div class="form-group">
                                                <select class="form-control" st-search="CustomerGroupId">
                                                    <option value="">{{::vm.translate.get('All')}}</option>
                                                    <option ng-repeat="group in vm.customerGroups" value="{{group.id}}">{{group.name}}</option>
                                                </select>
                                            </div>
                                        </th>
                                        <th></th>
                                        <th></th>
                                    </tr>
                                </thead>
                                <tbody ng-show="!vm.isLoading">
                                    <tr ng-repeat="customer in vm.customers">
                                        <td>{{customer.fullName}}</td>
                                        <td>{{customer.email}}</td>
                                        <td>{{customer.customerGroups.join(', ')}}</td>
                                        <td>{{customer.createdOn | date:'medium' }}</td>
                                        <td>
                                            <a ui-sref="customer-edit({id: customer.id})" title="Edit" class="btn btn-primary btn-xs"> <i class="fa fa-pen"></i></a>
                                            <button ng-click="vm.deleteCustomer(customer)" class="btn btn-danger btn-xs delete"> <i class="fas fa-times-circle"></i></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-content="50" st-displayed-contents="10" colspan="5"></td>
                                    </tr>
                                </tfoot>
                            </table>
                        </div>
                    </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>