<!--

    Copyright © 2016 The Thingsboard Authors

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<md-content flex layout="column" class="tb-progress-cover" layout-align="center center"
   ng-show="(vm.loading() || vm.dashboardLoading) && !vm.isEdit">
	<md-progress-circular md-mode="indeterminate" class="md-warn" md-diameter="100"></md-progress-circular>
</md-content>
<md-content id="gridster-parent" class="tb-dashboard-content" flex layout-wrap>
	<div ng-style="vm.dashboardStyle" id="gridster-background" style="height: auto; min-height: 100%;">
		<div id="gridster-child" gridster="vm.gridsterOpts">
			<ul>
	<!-- 			    			ng-click="widgetClicked($event, widget)"  -->
				<li gridster-item="widget" ng-repeat="widget in vm.widgets">
					<div tb-expand-fullscreen expand-button-id="expand-button" on-fullscreen-changed="vm.onWidgetFullscreenChanged(expanded, widget)" layout="column" class="tb-widget md-whiteframe-4dp"
								ng-class="{'tb-highlighted': vm.isHighlighted(widget), 'tb-not-highlighted': vm.isNotHighlighted(widget)}"
								tb-mousedown="vm.widgetMouseDown($event, widget)"
								tb-mousemove="vm.widgetMouseMove($event, widget)"
								tb-mouseup="vm.widgetMouseUp($event, widget)"
						style="
						cursor: pointer;
						color: {{vm.widgetColor(widget)}};
						background-color: {{vm.widgetBackgroundColor(widget)}};
						padding: {{vm.widgetPadding(widget)}}
						">
						<div class="tb-widget-title" layout="column" ng-show="vm.showWidgetTitle(widget) || vm.hasTimewindow(widget)">
							<span ng-show="vm.showWidgetTitle(widget)" class="md-subhead">{{widget.config.title}}</span>
							<tb-timewindow ng-if="vm.hasTimewindow(widget)" ng-model="widget.config.timewindow"></tb-timewindow>
						</div>
						<div class="tb-widget-actions" layout="row" layout-align="start center">
							<md-button id="expand-button"
									   aria-label="{{ 'fullscreen.fullscreen' | translate }}"
									   class="md-icon-button md-primary"></md-button>
							<md-button ng-show="vm.isEditActionEnabled && !vm.isWidgetExpanded"
									   ng-disabled="vm.loading()"
									   class="md-icon-button md-primary"
									   ng-click="vm.editWidget($event, widget)"
									   aria-label="{{ 'widget.edit' | translate }}">
								<md-tooltip md-direction="top">
									{{ 'widget.edit' | translate }}
								</md-tooltip>
								<md-icon class="material-icons">
									edit
								</md-icon>
							</md-button>
							<md-button ng-show="vm.isRemoveActionEnabled && !vm.isWidgetExpanded"
								ng-disabled="vm.loading()"
								class="md-icon-button md-primary"
								ng-click="vm.removeWidget($event, widget)"
								aria-label="{{ 'widget.remove' | translate }}">
								<md-tooltip md-direction="top">
									{{ 'widget.remove' | translate }}
								</md-tooltip>
								<md-icon class="material-icons">
								  close
								</md-icon>
							</md-button>
						</div>
						<div flex layout="column" class="tb-widget-content">
							<div flex tb-widget
								 locals="{ visibleRect: vm.visibleRect, widget: widget, deviceAliasList: vm.deviceAliasList, isPreview: vm.isEdit }">
							</div>
						</div>
					</div>
				</li>
			</ul>
		</div>
	</div>
</md-content>