<div ng-controller="HomeController" data-ng-init="onInit()">

    <script type="text/ng-template" id="createRoomTemplate.html">
        <div class="modal-header">
            Create New Room
        </div>
        <div class="modal-body">
            <div>
                <label><input type="checkbox" ng-model="newRoom.isPublic"> Public Room</label>
            </div>
            <div>
                #<input size="32" ng-model="newRoom.alias" placeholder="Room Alias e.g. 'matrix' (optional)"/>:{{ config.user_domain }}
            </div>
        </div>
        <div class="modal-footer">
            <button ng-click="create()" type="button" class="btn btn-success">
                Create
            </button>
        </div>
    </script>

    <div id="wrapper">
    
    <div id="genericHeading">
        <a href ng-click="goToPage('/')"><img src="img/logo-small.png" width="100" height="43" alt="[matrix]"/></a>
    </div>
    
    <h1>Welcome to homeserver {{ config.user_domain }}</h1>
    
    <div>
        <div class="profile-avatar">
            <img ng-src="{{ (null !== profile.avatarUrl) ? httpUri(profile.avatarUrl, 320, 320) : 'img/default-profile.png' }}"/>
        </div>
        <div id="user-ids">
            <div id="user-displayname">{{ profile.displayName }}</div>
            <div>{{ config.user_id }}</div>
        </div>
    </div>
    <br/>
    <div class="home_controls">
        <form>
            <label for="newChat_user" style="width: 6em">
                Start chat:
            </label>
            <input id="newChat_user" size="40" ng-model="newChat.user" ng-enter="messageUser()" placeholder="e.g. @user:domain.com"/>
            <button ng-disabled="!newChat.user" ng-click="messageUser()">Start</button>
        </form>
    </div>    
    <div class="home_controls">
        <form>
            <label for="joinAlias_room_alias" style="width: 6em">
                Join room:
            </label>
            <input size="40" id="joinAlias_room_alias" ng-model="joinAlias.room_alias" ng-enter="joinAlias(joinAlias.room_alias)" placeholder="e.g. #foo:example.org"/>
            <button ng-disabled="!joinAlias.room_alias" ng-click="joinAlias(joinAlias.room_alias)">Join</button>
        </form>
    </div>
    <div class="home_controls">
        <p>
            <button ng-click="showCreateRoomDialog()">Create Room</button>
        </p>
    </div>
    <div class="feedback">{{ feedback }}</div>
        
    <h3>Recent conversations</h3>
        <div ng-include="'app/recents/recents.html'"></div>
    <br/>

    <h3>Public rooms</h3>
    <div class="spinner publicRoomSpinner" us-spinner ng-show="public_rooms === undefined"> </div>
    <table class="publicTable">
        <tbody ng-repeat="room in public_rooms | orderBy:('num_joined_members'):true"
               class="publicRoomEntry"
               ng-class="room.is_favourite ? 'roomHighlight' : ''">
            <tr>
                <td class="publicRoomEntry">
                    <a href="#/room/{{ room.room_alias ? room.room_alias : room.room_id }}"  >
                        {{ room.room_display_name }}
                    </a>
                </td>
                <td>
                    <div class="publicRoomJoinedUsers"
                         ng-show="room.num_joined_members">
                        {{ room.num_joined_members }} {{ room.num_joined_members == 1 ? 'user' : 'users' }}
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2" class="publicRoomTopic">
                    {{ room.topic }}
                </td>
            </tr>
        </tbody>
    </table>
    <br/>

    </div>    
</div>
