<!--

    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.

-->
<form name="theForm" ng-submit="vm.update()">
	<fieldset ng-disabled="loading">
		<section layout="column">
			<md-tabs ng-class="{'tb-headless': vm.historyOnly}" flex md-dynamic-height md-selected="vm.timewindow.selectedTab" md-border-bottom>
				<md-tab label="{{ 'timewindow.realtime' | translate }}">
					<md-content class="md-padding" layout="column">
						<span translate>timewindow.last</span>
						<tb-timeinterval
							ng-required="vm.timewindow.selectedTab === 0"
							ng-model="vm.timewindow.realtime.timewindowMs" style="padding-top: 8px;"></tb-timeinterval>
					</md-content>
				</md-tab>
				<md-tab label="{{ 'timewindow.history' | translate }}">
					<md-content class="md-padding" layout="column">
						<md-radio-group ng-model="vm.timewindow.history.historyType" class="md-primary">
							<md-radio-button ng-value=0 class="md-primary md-align-top-left md-radio-interactive">
								<section layout="column">
									<span translate>timewindow.last</span>
									<tb-timeinterval
										ng-required="vm.timewindow.selectedTab === 1 && vm.timewindow.history.historyType === 0"
										ng-show="vm.timewindow.history.historyType === 0"
										ng-model="vm.timewindow.history.timewindowMs" style="padding-top: 8px;"></tb-timeinterval>
								</section>	
							</md-radio-button>
							<md-radio-button ng-value=1 class="md-primary md-align-top-left md-radio-interactive">
								<section layout="column">
									<span translate>timewindow.time-period</span>
									<tb-datetime-period
											ng-required="vm.timewindow.selectedTab === 1 && vm.timewindow.history.historyType === 1"
											ng-show="vm.timewindow.history.historyType === 1"
											ng-model="vm.timewindow.history.fixedTimewindow" style="padding-top: 8px;"></tb-datetime-period>
								</section>	
							</md-radio-button>
						</md-radio-group>
					</md-content>
				</md-tab>
			</md-tabs>
			<section layout="row" layout-alignment="start center">
			      <span flex></span>
				  <md-button ng-disabled="loading || theForm.$invalid || !theForm.$dirty" type="submit" class="md-raised md-primary">
				  		{{ 'action.update' | translate }}
				  </md-button>
			      <md-button ng-disabled="loading" ng-click="vm.cancel()" style="margin-right:20px;">
					  {{ 'action.cancel' | translate }}
			      </md-button>
			</section> 
		</section>
	</fieldset>
</form>