<!--

    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 tb-expand-fullscreen="vm.widgetEditMode" hide-expand-button="vm.widgetEditMode">
    <!--section ng-show="!vm.isAddingWidget && !loading && !vm.widgetEditMode" layout="row" layout-wrap
             class="tb-header-buttons tb-top-header-buttons md-fab" ng-style="{'right': '50px'}">
        <md-button ng-if="vm.isTenantAdmin()" ng-show="vm.isEdit" ng-disabled="loading"
                   class="tb-btn-header md-accent md-hue-2 md-fab md-fab-bottom-right"
                   aria-label="{{ 'action.apply' | translate }}"
                   ng-click="vm.saveDashboard()">
            <md-tooltip md-direction="top">
                {{ 'action.apply-changes' | translate }}
            </md-tooltip>
            <ng-md-icon icon="done"></ng-md-icon>
        </md-button>
        <md-button ng-if="vm.isTenantAdmin()" ng-disabled="loading"
                   class="tb-btn-header md-accent md-hue-2 md-fab md-fab-bottom-right"
                   aria-label="{{ 'action.edit-mode' | translate }}"
                   ng-click="vm.toggleDashboardEditMode()">
            <md-tooltip md-direction="top">
                {{ (vm.isEdit ? 'action.decline-changes' : 'action.enter-edit-mode') | translate }}
            </md-tooltip>
            <ng-md-icon icon="{{vm.isEdit ? 'close' : 'edit'}}"
                        options='{"easing": "circ-in-out", "duration": 375, "rotation": "none"}'></ng-md-icon>
        </md-button>
    </section-->
    <section ng-show="!loading && vm.noData()" layout-align="center center"
             ng-class="{'tb-padded' : !vm.widgetEditMode}"
             style="text-transform: uppercase; display: flex; z-index: 1;"
             class="md-headline tb-absolute-fill">
	 <span translate ng-if="!vm.isEdit">
		 dashboard.no-widgets
	 </span>
        <md-button ng-if="vm.isEdit && !vm.widgetEditMode" class="tb-add-new-widget" ng-click="vm.addWidget($event)">
            <md-icon aria-label="{{ 'action.add' | translate }}" class="material-icons tb-md-96">add</md-icon>
            {{ 'dashboard.add-widget' | translate }}
        </md-button>
    </section>
    <section ng-if="!vm.widgetEditMode" class="tb-dashboard-title" layout="row" layout-align="center center">
        <h3 ng-show="!vm.isEdit && vm.displayTitle()">{{ vm.dashboard.title }}</h3>
        <md-input-container ng-show="vm.isEdit" class="md-block" style="height: 30px;">
            <label translate>dashboard.title</label>
            <input class="tb-dashboard-title" required name="title" ng-model="vm.dashboard.title">
        </md-input-container>
        <md-button class="md-raised" flex="none" ng-show="vm.isEdit" ng-click="vm.openDeviceAliases($event)">
            {{ 'device.aliases' | translate }}
        </md-button>
        <md-button class="md-raised" flex="none" ng-show="vm.isEdit" ng-click="vm.openDashboardSettings($event)">
            {{ 'dashboard.settings' | translate }}
        </md-button>
    </section>
    <div class="tb-absolute-fill"
         ng-class="{ 'tb-padded' : !vm.widgetEditMode && (vm.isEdit || vm.displayTitle()), 'tb-shrinked' : vm.isEditingWidget }">
        <tb-dashboard
                dashboard-style="{'background-color': vm.dashboard.configuration.gridSettings.backgroundColor,
                                  'background-image': 'url('+vm.dashboard.configuration.gridSettings.backgroundImageUrl+')',
                                  'background-repeat': 'no-repeat',
                                  'background-attachment': 'scroll',
                                  'background-size': '100%',
                                  'background-position': '0% 0%'}"
                widgets="vm.widgets"
                columns="vm.dashboard.configuration.gridSettings.columns"
                margins="vm.dashboard.configuration.gridSettings.margins"
                device-alias-list="vm.dashboard.configuration.deviceAliases"
                is-edit="vm.isEdit || vm.widgetEditMode"
                is-mobile="vm.forceDashboardMobileMode"
                is-mobile-disabled="vm.widgetEditMode"
                is-edit-action-enabled="vm.isEdit || vm.widgetEditMode"
                is-remove-action-enabled="vm.isEdit && !vm.widgetEditMode"
                on-edit-widget="vm.editWidget(event, widget)"
                on-widget-mouse-down="vm.widgetMouseDown(event, widget)"
                on-widget-clicked="vm.widgetClicked(event, widget)"
                on-widget-context-menu="vm.widgetContextMenu(event, widget)"
                prepare-dashboard-context-menu="vm.prepareDashboardContextMenu()"
                prepare-widget-context-menu="vm.prepareWidgetContextMenu(widget)"
                on-remove-widget="vm.removeWidget(event, widget)"
                load-widgets="vm.loadDashboard()"
                on-init="vm.dashboardInited(dashboard)"
                on-init-failed="vm.dashboardInitFailed(e)">
        </tb-dashboard>
    </div>
    <tb-details-sidenav class="tb-widget-details-sidenav"
                        header-title="vm.editingWidget.config.title"
                        header-subtitle="{{vm.editingWidgetSubtitle}}"
                        is-read-only="false"
                        is-open="vm.isEditingWidget"
                        is-always-edit="true"
                        on-close-details="vm.onEditWidgetClosed()"
                        on-toggle-details-edit-mode="vm.onRevertWidgetEdit(vm.widgetForm)"
                        on-apply-details="vm.saveWidget(vm.widgetForm)"
                        the-form="vm.widgetForm">
        <details-buttons tb-help="vm.helpLinkIdForWidgetType()" help-container-id="help-container">
            <div id="help-container"></div>
        </details-buttons>
        <form name="vm.widgetForm">
            <tb-edit-widget
                    dashboard="vm.dashboard"
                    widget="vm.editingWidget"
                    the-form="vm.widgetForm">
            </tb-edit-widget>
        </form>
    </tb-details-sidenav>
    <tb-details-sidenav ng-if="!vm.widgetEditMode" class="tb-select-widget-sidenav"
                        header-title="'dashboard.select-widget-title' | translate"
                        header-height-px="120"
                        is-read-only="true"
                        is-open="vm.isAddingWidget"
                        is-edit="false"
                        on-close-details="vm.onAddWidgetClosed()">
        <header-pane>
            <div layout="row">
                <span class="tb-details-subtitle">{{ 'widgets-bundle.current' | translate }}</span>
                <tb-widgets-bundle-select flex-offset="5"
                                          flex
                        ng-model="vm.widgetsBundle"
                        tb-required="true"
                        select-first-bundle="false">
                </tb-widgets-bundle-select>
            </div>
        </header-pane>
        <div>
            <md-tabs ng-if="vm.timeseriesWidgetTypes.length > 0 || vm.latestWidgetTypes.length > 0 ||
                            vm.rpcWidgetTypes.length > 0"
                     flex
                     class="tb-absolute-fill" md-border-bottom>
                <md-tab ng-if="vm.timeseriesWidgetTypes.length > 0" style="height: 100%;" label="{{ 'widget.timeseries' | translate }}">
                    <tb-dashboard
                            widgets="vm.timeseriesWidgetTypes"
                            is-edit="false"
                            is-mobile="true"
                            is-edit-action-enabled="false"
                            is-remove-action-enabled="false"
                            on-widget-clicked="vm.addWidgetFromType(event, widget)">
                    </tb-dashboard>
                </md-tab>
                <md-tab ng-if="vm.latestWidgetTypes.length > 0" style="height: 100%;" label="{{ 'widget.latest-values' | translate }}">
                    <tb-dashboard
                            widgets="vm.latestWidgetTypes"
                            is-edit="false"
                            is-mobile="true"
                            is-edit-action-enabled="false"
                            is-remove-action-enabled="false"
                            on-widget-clicked="vm.addWidgetFromType(event, widget)">
                    </tb-dashboard>
                </md-tab>
                <md-tab ng-if="vm.rpcWidgetTypes.length > 0" style="height: 100%;" label="{{ 'widget.rpc' | translate }}">
                    <tb-dashboard
                            widgets="vm.rpcWidgetTypes"
                            is-edit="false"
                            is-mobile="true"
                            is-edit-action-enabled="false"
                            is-remove-action-enabled="false"
                            on-widget-clicked="vm.addWidgetFromType(event, widget)">
                    </tb-dashboard>
                </md-tab>
            </md-tabs>
            <span translate ng-if="vm.timeseriesWidgetTypes.length === 0 && vm.latestWidgetTypes.length === 0 &&
                                   vm.rpcWidgetTypes.length === 0 && vm.widgetsBundle"
                  layout-align="center center"
                  style="text-transform: uppercase; display: flex;"
                  class="md-headline tb-absolute-fill">widgets-bundle.empty</span>
            <span translate ng-if="!vm.widgetsBundle"
                  layout-align="center center"
                  style="text-transform: uppercase; display: flex;"
                  class="md-headline tb-absolute-fill">widget.select-widgets-bundle</span>
        </div>
    </tb-details-sidenav>
    <!-- </section> -->
    <section layout="row" layout-wrap class="tb-footer-buttons md-fab">
        <md-button ng-disabled="loading" ng-show="!vm.isAddingWidget && vm.isEdit && !vm.widgetEditMode"
                   class="tb-btn-footer md-accent md-hue-2 md-fab" ng-click="vm.addWidget($event)"
                   aria-label="{{ 'dashboard.add-widget' | translate }}">
            <md-tooltip md-direction="top">
                {{ 'dashboard.add-widget' | translate }}
            </md-tooltip>
            <ng-md-icon icon="add"></ng-md-icon>
        </md-button>
        <md-button ng-if="vm.isTenantAdmin()" ng-show="vm.isEdit && !vm.isAddingWidget && !loading && !vm.widgetEditMode" ng-disabled="loading"
                   class="tb-btn-footer md-accent md-hue-2 md-fab"
                   aria-label="{{ 'action.apply' | translate }}"
                   ng-click="vm.saveDashboard()">
            <md-tooltip md-direction="top">
                {{ 'action.apply-changes' | translate }}
            </md-tooltip>
            <ng-md-icon icon="done"></ng-md-icon>
        </md-button>
        <md-button ng-show="!vm.isAddingWidget && !loading && !vm.widgetEditMode"
                   ng-if="vm.isTenantAdmin()" ng-disabled="loading"
                   class="tb-btn-footer md-accent md-hue-2 md-fab"
                   aria-label="{{ 'action.edit-mode' | translate }}"
                   ng-click="vm.toggleDashboardEditMode()">
            <md-tooltip md-direction="top">
                {{ (vm.isEdit ? 'action.decline-changes' : 'action.enter-edit-mode') | translate }}
            </md-tooltip>
            <ng-md-icon icon="{{vm.isEdit ? 'close' : 'edit'}}"
                        options='{"easing": "circ-in-out", "duration": 375, "rotation": "none"}'></ng-md-icon>
        </md-button>
    </section>
</md-content>
