<div class="content-header">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-6">
                <h2>{{::vm.translate.get('District')}}</h2>
            </div>
            <div class="col-md-6">
                <div class="row" ng-show="vm.stateOrProvinceId">
                    <div class="col-md-12 text-right">
                        <a ui-sref="district-create({stateOrProvinceId: vm.stateOrProvinceId})" class="btn btn-success">
                            <span class="fa fa-plus"></span> {{::vm.translate.get('Create District')}}
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<section class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card" st-pipe="vm.getDistricts" st-table="vm.districts">
                    <div class="card-header">
                        <div class="row">
                            <div class="col-md-8">
                                <h3 class="card-title">{{::vm.translate.get('District')}}</h3><br />
                                <small>{{::vm.translate.get('Select Country and State or Province to add for that State or Province.')}}</small>
                            </div>
                            <div class="col-md-4">
                                <div class="card-tools">
                                    <div class="form-group row">
                                        <div class="col-sm-6">
                                            <select class="form-control" ng-model="vm.countryId" 
                                                    ng-change="vm.onCountrySelected(vm.countryId)" 
                                                    ng-options="''+ country.id as country.name for country in vm.countries">
                                                <option></option>
                                            </select>
                                        </div>
                                        <div class="col-sm-6">
                                            <select class="form-control" ng-model="vm.stateOrProvinceId" 
                                                    ng-change="vm.onStateOrProvinceSelected(vm.stateOrProvinceId)" 
                                                    ng-options="''+ stateOrProvince.id as stateOrProvince.name for stateOrProvince in vm.stateOrProvinces">
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="card-body p-0 table-responsive">
                        <table class="table table-striped">
                            <thead>
                                <tr>
                                    <th st-sort="Name" class="sortable">{{::vm.translate.get('Name')}}</th>
                                    <th st-sort="Code" class="sortable">{{::vm.translate.get('Type')}}</th>
                                    <th st-sort="CountryId" class="sortable">{{::vm.translate.get('State Or Province Id')}}</th>
                                    <th>{{::vm.translate.get('Actions')}}</th>
                                </tr>
                                <tr>
                                    <th>
                                        <div class="form-group">
                                            <input class="form-control" st-search="Name" />
                                        </div>
                                    </th>
                                    <th></th>
                                    <th></th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr ng-repeat="district in vm.districts">
                                    <td>{{district.name}}</td>
                                    <td>{{district.type}}</td>
                                    <td>{{district.stateOrProvinceId}}</td>
                                    <td>
                                        <a ui-sref="district-edit({id: district.id, stateOrProvinceId: vm.stateOrProvinceId})" title="Edit" class="btn btn-primary btn-xs"> <i class="fa fa-pen"></i></a>
                                        <button ng-click="vm.deleteDistrict(district)" title="Delete" 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="4" 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="4"></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>