<!--

    Copyright © 2016-2020 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.

-->
<div layout="column" layout-align="center center" class="tb-web-camera">
    <div ng-if="vm.isEntityDetected && vm.dataKeyDetected && vm.isCameraSupport && vm.isDeviceDetect" layout-fill>
        <div ng-show="!vm.isShowCamera" layout="column" layout-align="space-between center" layout-fill>
            <div class="tb-web-camera__last-photo" flex>
                <span ng-show="!vm.ctx.data[0].data[0][1]" class="tb-web-camera__last-photo_text" translate>widgets.input-widgets.no-image</span>
                <img ng-show="vm.ctx.data[0].data[0][1]" class="tb-web-camera__last-photo_img" ng-src="{{vm.ctx.data[0].data[0][1]}}" />
            </div>
            <md-button class="md-raised md-primary" ng-click="vm.takePhoto()"">{{ "widgets.input-widgets.take-photo" | translate }}</md-button>
        </div>
        <div ng-show="vm.isShowCamera" layout="column" layout-align="center center" id="photoCamera">
            <div class="camera" ng-show="!vm.isPreviewPhoto">
                <video autoplay muted playsinline id="videoStream" class="camera-stream"></video>
                <div class="camera-controls" layout="row" layout-wrap="" layout-align="space-between end">
                    <div flex></div>
                    <md-button class="md-fab md-primary md-mini" aria-label="{{ 'widgets.input-widgets.switch-camera' | translate }}"
                               ng-click="vm.switchWebCamera()" ng-disabled="{{vm.videoInput.length < 2}}">
                        <md-icon md-font-icon="switch_camera" aaria-label="{{ 'widgets.input-widgets.switch-camera' | translate }}">switch_camera</md-icon>
                    </md-button>
                    <md-button class="md-fab md-hue-2" aria-label="{{ 'widgets.input-widgets.take-photo' | translate }}" ng-click="vm.createPhoto()">
                        <md-icon md-font-icon="photo_camera" aria-label="Take Photo">photo_camera</md-icon>
                    </md-button>
                    <md-button class="md-fab md-primary md-mini" aria-label="{{ 'action.cancel' | translate }}" ng-click="vm.closeCamera()">
                        <md-icon md-font-icon="close" aria-label="{{ 'action.cancel' | translate }}">close</md-icon>
                    </md-button>
                    <div flex></div>
                </div>
            </div>
            <div class="camera" ng-show="vm.isPreviewPhoto">
                <img class="camera-stream" ng-src="{{vm.previewPhoto}}">
                <canvas style="display:none;"></canvas>
                <div class="camera-controls" layout="row" layout-wrap="" layout-align="space-between end">
                    <div flex></div>
                    <md-button class="md-fab md-primary" aria-label="{{ 'action.cancel' | translate }}" ng-click="vm.cancelPhoto()">
                        <md-icon md-font-icon="close" aria-label="{{ 'action.cancel' | translate }}">close</md-icon>
                    </md-button>
                    <md-button class="md-fab md-hue-2" aria-label="{{ 'action.save' | translate }}" ng-click="vm.savePhoto()">
                        <md-icon md-font-icon="check" aria-label="{{ 'action.save' | translate }}">check</md-icon>
                    </md-button>
                    <div flex></div>
                </div>
            </div>
        </div>
    </div>
    <div class="message-text" ng-hide="vm.isEntityDetected">
        {{ 'widgets.input-widgets.no-entity-selected' | translate }}
    </div>
    <div class="message-text" ng-if="vm.isEntityDetected && !vm.dataKeyDetected">
        {{ 'widgets.input-widgets.no-datakey-selected' | translate }}
    </div>
    <div class="message-text" ng-if="vm.isEntityDetected && vm.dataKeyDetected && !vm.isCameraSupport">
        {{ 'widgets.input-widgets.no-support-web-camera' | translate }}
    </div>
    <div class="message-text" ng-if="vm.isEntityDetected && vm.dataKeyDetected && vm.isCameraSupport && !vm.isDeviceDetect">
        {{ 'widgets.input-widgets.no-support-web-camera' | translate }}
    </div>
</div>
