<loading-panel ng-if="loading"></loading-panel>
<div ng-if="!loading">
    <heading-bar heading="[[site.name]]">
        <button ng-if="admin"
            class="btn btn-info"
            data-toggle="modal"
            data-target="#updateSiteModal"
        >Update Site</button>
        <button ng-if="admin"
            class="btn btn-danger"
            data-toggle="modal"
            data-target="#deleteSiteModal"
        >Delete Site</button>
    </heading-bar>

    <nsot-modal title="Update Site" modal-id="updateSiteModal">
        <div class="modal-body">
            <div ng-if="updateError" class="alert alert-danger">
                [[updateError.code]] - [[updateError.message]]
            </div>
            <form novalidate name="siteForm" class="nsot-form">
                <div class="form-group" ng-class="{
                    'has-error' : siteForm.name.$invalid,
                    'has-success' : siteForm.name.$valid,
                }">
                    <input type="text"
                           class="form-control"
                           name="name"
                           placeholder="Name (required)"
                           ng-model="site.name"
                           ng-minlength="1"
                           required
                    >
                </div>
                <div class="form-group">
                    <textarea style="resize: vertical;"
                              class="form-control"
                              rows="5"
                              name="description"
                              placeholder="Description"
                              ng-model="site.description"
                    >
                    </textarea>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">
                Close
            </button>
            <button type="submit" ng-click="updateSite()"
                    class="btn btn-primary" ng-disabled="siteForm.$invalid"
            >
                Update
            </button>
        </div>
    </nsot-modal>

    <nsot-modal title="Delete Site" modal-id="deleteSiteModal">
        <div class="modal-body">
            <div ng-if="deleteError" class="alert alert-danger">
                [[deleteError.code]] - [[deleteError.message]]
            </div>
            Are you sure you want to delete this site?
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">
                Close
            </button>
            <button type="submit" ng-click="deleteSite()" class="btn btn-primary">
                Delete
            </button>
        </div>
    </nsot-modal>
</div>
