<!--

    Copyright © 2016-2017 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-edit-dialog>
    <form name="editDialog" ng-submit="submit()">
        <div layout="column" class="md-content" style="width: 400px;">
            <fieldset>
                <section layout="row">
                    <md-input-container flex="40" class="md-block">
                        <label translate>value.type</label>
                        <md-select ng-model="valueType">
                            <md-option ng-repeat="type in valueTypes" ng-value="type">
                                <md-icon md-svg-icon="{{ type.icon }}"></md-icon>
                                <span>{{type.name | translate}}</span>
                            </md-option>
                        </md-select>
                    </md-input-container>
                    <md-input-container ng-if="valueType===valueTypes.string" flex="60" class="md-block">
                        <label translate>value.string-value</label>
                        <input required name="value" ng-model="model.value">
                        <div ng-messages="editDialog.value.$error">
                            <div translate ng-message="required">attribute.value-required</div>
                        </div>
                    </md-input-container>
                    <md-input-container ng-if="valueType===valueTypes.integer" flex="60" class="md-block">
                        <label translate>value.integer-value</label>
                        <input required name="value" type="number" step="1" ng-pattern="/^-?[0-9]+$/" ng-model="model.value">
                        <div ng-messages="editDialog.value.$error">
                            <div translate ng-message="required">attribute.value-required</div>
                            <div translate ng-message="pattern">value.invalid-integer-value</div>
                        </div>
                    </md-input-container>
                    <md-input-container ng-if="valueType===valueTypes.double" flex="60" class="md-block">
                        <label translate>value.double-value</label>
                        <input required name="value" type="number" step="any" ng-model="model.value">
                        <div ng-messages="editDialog.value.$error">
                            <div translate ng-message="required">attribute.value-required</div>
                        </div>
                    </md-input-container>
                    <div layout="column" layout-align="center" flex="60" ng-if="valueType===valueTypes.boolean">
                        <md-checkbox ng-model="model.value" style="margin-bottom: 0px;">
                            {{ (model.value ? 'value.true' : 'value.false') | translate }}
                        </md-checkbox>
                    </div>
                </section>
            </fieldset>
        </div>
        <div layout="row" layout-align="end" class="md-actions">
            <md-button ng-click="dismiss()">{{ 'action.cancel' |
                translate }}
            </md-button>
            <md-button ng-disabled="editDialog.$invalid || !editDialog.$dirty" type="submit"
                       class="md-raised md-primary">
                {{ 'action.update' | translate }}
            </md-button>
        </div>
    </form>
</md-edit-dialog>