<ion-view view-title="Wildshield" hide-nav-bar="true">
    <ion-content>
          <ion-refresher
            pulling-text="Obnoviť..."
            on-refresh="vm.doRefresh()"
            spinner="ripple">
        </ion-refresher>
        <div ng-controller="SearchCtrl as vmm">
            <div class="finder" ng-class="!(vmm.chatSearchResults | isEmpty) ? 'noBottomBorder' : {}"> 
                <div>
                    <input type="text" placeholder="EVČ/prezývka..." ng-model="vmm.chatObject" style="width: 45%">
                    <button class="button button-assertive" ng-click="vmm.chatSearching(vmm.chatObject)" ng-disabled="!vmm.chatObject">
                        Hľadať
                    </button>
                </div>
                <i class="ion icon ion-close" ng-if="vmm.dirtyChat" ng-click="vmm.doClearChat()"></i>
            </div>
            <div class="finder_results list">
                <ion-spinner icon="ripple" ng-if="vmm.searchChatLoading"></ion-spinner>
                <div ng-if="!(vmm.chatSearchResults | isEmpty)">
                    <div class="item item-chat item-remove-animate item-avatar item-icon-right ink ink-dark" 
                         ng-controller="NewChatCtrl as vmmm"
                         ng-if="!vmm.chatSearchResults.notFound && !vmm.chatSearchResults.isItMe" 
                         ng-click="vmmm.newChat(vmm.chatSearchResults)">
                        <img ng-src="{{vmm.chatSearchResults.photo || 'img/user.png'}}">
                        <h2>{{vmm.chatSearchResults.evidenceNumber|| vmm.chatSearchResults.username}}</h2>
                        <p>{{vmm.chatSearchResults.evidenceNumber ? "vozidlo" : "užívateľ"}}</p>
                        <i class="icon ion-chevron-right" ng-if="!vmmm.creatingNewChat"></i>
                        <ion-spinner class="icon ion-chevron-right" icon="ripple" ng-if="vmmm.creatingNewChat"></ion-spinner>
                    </div>
                    <div class="error" ng-if="vmm.chatSearchResults.notFound">
                        <h2> Hľadaný užívateľ alebo vozidlo neexistuje.</h2>
                    </div>
                    <div class="error" ng-if="vmm.chatSearchResults.isItMe">
                        <h2> Nemôžete písať sám sebe :).</h2>
                    </div>
                </div>
            </div>
        </div>        
        <ion-list id="listOfChats">
            <h5>Carverzácie</h5>
            <ion-item
                ng-repeat="chat in vm.allChats"
                class="item-chat item-remove-animate item-avatar item-icon-right ink ink-dark"
                type="item-text-wrap"
                ng-class="{'newMessage' : chat.newMessage}"
                ng-click="vm.goToChat(chat.id, chat)">
                <img ng-src="{{chat.photoCar|| chat.photoUser}}">
                <h2>{{chat.username}}</h2>
                <p>od {{chat.created | date:"dd.MM.yyyy"}}</p>
                <i class="icon ion-chevron-right"></i>
                   {{chat}}
                <ion-option-button class="button-assertive" ng-click="vm.removeChat(chat.id)">
                    <i class="icon ion-trash-b"></i>
                </ion-option-button>
            </ion-item>
            <p ng-if="vm.allChats.length === 0 && !vm.loadingAllChats" class="noChat">Zatiaľ ste si s nikým nepísali</p>
            <div class="loadingAllChats" ng-if="vm.loadingAllChats">
                <ion-spinner icon="ripple"></ion-spinner>
            </div>
        </ion-list>
    </ion-content>
</ion-view>
