<!-- Localization completed -->
<div ng-show='errorMessage' class='modal-header'>
    <div ng-show='errorMessage' class='error'><span>{{errorMessage}}</span></div>
</div>
<div ng-show='successMessage' class='modal-header'>
    <div ng-show='successMessage' class='success'><span>{{successMessage}}</span></div>
</div>
<div class='modal-body'>
    <form class='form-horizontal'>

        <div class='form-group'>
            <label class='col-sm-4 control-label' for="applicationType" localized>form.application.type</label>
            <div class='col-sm-8'>
                <select class="form-control" ng-model='application.type' id="applicationType" ng-disabled="!isNewApp">
                    <option ng-value="'app'" ng-selected="application.type === 'app'"
                            localized>form.application.type.option.app</option>
                    <option ng-value="'web'" ng-selected="application.type === 'web'"
                            localized>form.application.type.option.web</option>
                    <option ng-value="'intent'" ng-selected="application.type === 'intent'"
                            localized>form.application.type.option.intent</option>
                </select>
            </div>
        </div>

        <div class='form-group' ng-if="!fileSelected && application.type === 'app'">
            <label class='col-sm-4 control-label' for="applicationPkg" localized>form.application.pkg</label>
            <div class='col-sm-8'>
                <input localized-title="form.application.pkg.title" ng-model='application.pkg' type='text'
                       class='form-control' id="applicationPkg" localized-placeholder="form.application.pkg.placeholder"/>
            </div>
        </div>

        <div class='form-group' ng-if="fileSelected && application.type === 'app'">
            <label class='col-sm-4 control-label' for="applicationPkg2" localized>form.application.pkg</label>
            <div class='col-sm-8'>
                <input disabled ng-model='appdesc.pkg' type='text' class='form-control'
                       id="applicationPkg2"/>
            </div>
        </div>

        <div class='form-group'>
            <label class='col-sm-4 control-label' for="applicationName" localized>form.application.name</label>
            <div class='col-sm-8'>
                <input localized-title="form.application.name.title" ng-model='application.name' type='text'
                       class='form-control' id="applicationName" localized-placeholder="form.application.name.placeholder"/>
            </div>
        </div>

        <div class='form-group' ng-if="!fileSelected && application.type === 'app'">
            <label class='col-sm-4 control-label' for="applicationVersion" localized>form.application.version</label>
            <div class='col-sm-8'>
                <input localized-title="form.application.version.title" ng-model='application.version' type='text'
                       class='form-control' ng-disabled="application.id" id="applicationVersion"
                       localized-placeholder="form.application.version.placeholder"/>
            </div>
        </div>

        <div class='form-group' ng-if="fileSelected && application.type === 'app'">
            <label class='col-sm-4 control-label' for="applicationVersion2" localized>form.application.version</label>
            <div class='col-sm-8'>
                <input disabled type='text' class='form-control' id="applicationVersion2"
                       ng-model='appdesc.version'/>
            </div>
        </div>

        <div class='form-group' ng-if="application.type === 'app'">
            <label class='col-sm-4 control-label' for="applicationArch" localized>form.application.arch</label>
            <div class='col-sm-8'>
                <select class="form-control" ng-model='application.arch' id="applicationArch" ng-if="!application.id">
                    <option ng-value="''" ng-selected="application.arch === null || application.arch === ''"
                            localized>form.application.arch.universal</option>
                    <option ng-value="'armeabi'" ng-selected="application.arch === 'armeabi'"
                            localized>form.application.arch.armeabi</option>
                    <option ng-value="'arm64'" ng-selected="application.arch === 'arm64'"
                            localized>form.application.arch.arm64</option>
                </select>
                <div class="field-hint warning-font" ng-show="appTypeWarning">{{appTypeWarning}}</div>
                <div class="field-hint success-font" ng-show="appTypeSuccess">{{appTypeSuccess}}</div>
                <input ng-if="application.id"
                       localized-placeholder="form.application.disabled.arch"
                       localized-title="form.application.disabled.arch.title"
                       type='text'
                       class='form-control'
                       disabled>
            </div>
        </div>

        <div class='form-group' ng-if="application.type === 'app'">
            <label class='col-sm-4 control-label' for="applicationSystem" localized>form.application.system</label>
            <div class='col-sm-2'>
                <input localized-title="form.application.system.title" ng-model='application.system' type='checkbox'
                       class='form-control' id="applicationSystem"/>
            </div>
        </div>

        <div class='form-group' ng-if="application.type === 'app'">
            <label class='col-sm-4 control-label' for="applicationRunAfterInstall"
                   localized>form.application.run.after.install</label>
            <div class='col-sm-2'>
                <input localized-title="form.application.run.after.install.title" ng-model='application.runAfterInstall'
                       ng-disabled="application.system" type='checkbox' class='form-control' id="applicationRunAfterInstall"/>
            </div>

            <label class='col-sm-4 control-label' for="applicationRunAtBoot"
                   localized>form.application.run.at.boot</label>
            <div class='col-sm-2'>
                <input localized-title="form.application.run.at.boot.title" ng-model='application.runAtBoot'
                       ng-disabled="application.system" type='checkbox' class='form-control' id="applicationRunAtBoot"/>
            </div>
        </div>

        <div class='form-group' ng-if="application.type === 'app' || application.type === 'web'">
            <label class='col-sm-4 control-label' for="applicationUrl" localized>form.application.url</label>
            <div class='col-sm-8'>
                <!-- We enable editing the URL for better user experience. The URL changes will be applied
                to the latest app version. Only apps without split APKs could be edited -->
                <input title="{{localization.localize(application.split ? 'form.application.url.disabled' : 'form.application.url.title')}}"
                       ng-model='application.url' type='text'
                       class='form-control' id="applicationUrl"
                       ng-disabled="(application.system || (application.id && application.split))">
            </div>
            <div class="col-sm-4">&nbsp;</div>
            <div class="col-sm-8 field-hint" localized>form.application.url.hint</div>
        </div>

        <div class='form-group' ng-if="application.type === 'intent'">
            <label class='col-sm-4 control-label' for="applicationIntent" localized>form.application.intent</label>
            <div class='col-sm-8'>
                <input-dropdown
                        id="applicationIntent"
                        allow-custom-input="true"
                        input-required="true"
                        input-value="application.intent"
                        input-placeholder="{{intentPlaceholder}}"
                        selected-item="application.intent"
                        filter-list-method="filterIntents(userInput)"
                        default-dropdown-items="intentOptions">
                </input-dropdown>
            </div>
        </div>

        <div class='form-group' ng-if="isNewApp && application.type === 'app'">
            <label class='col-sm-4 control-label' localized>form.application.file</label>
            <div class='col-sm-8'>
                <div class="btn btn-default full-width btn-upload" ng-if="!file.path"
                     file-input-disabler input-disabled="{{application.system}}"
                     upload-button
                     url="rest/private/web-ui-files"
                     on-upload="onStartedUpload(files)"
                     on-progress="onUploadProgress(progress)"
                     on-success="fileUploaded(response)"></div>
                <span ng-if="file.path && !invalidFile">{{fileName}}</span>
                <button class="btn btn-default" ng-if="file.path" ng-click="clearFile()" localized>button.cleanup</button>
                <div ng-if="availableSpace" class="field-hint" style="margin-bottom: 0">{{availableSpace}}</div>
            </div>
        </div>

        <div class='form-group'>
            <label class='col-sm-4 control-label' for="showLabelBox" localized>form.application.showLabel</label>
            <div class='col-sm-2'>
                <input localized-title="form.application.showLabel.title" ng-model='application.showIcon'
                       type='checkbox' class='form-control' id="showLabelBox"/>
            </div>

            <div ng-if="application.type === 'app' && application.autoUpdateDisplayed">
                <label class='col-sm-4 control-label' for="autoUpdateBox" localized>form.application.auto.update</label>
                <div class='col-sm-2'>
                    <input localized-title="form.application.auto.update.title" ng-model='application.autoUpdate'
                           type='checkbox' class='form-control' id="autoUpdateBox"/>
                </div>
            </div>

            <div ng-if="application.type === 'web'">
                <label class='col-sm-4 control-label' for="useKioskBox" localized>form.application.use.kiosk</label>
                <div class='col-sm-2'>
                    <input localized-title="form.application.use.kiosk.title" ng-model='application.useKiosk'
                           type='checkbox' class='form-control' id="useKioskBox"/>
                </div>
            </div>

        </div>

        <div class='form-group' ng-if="application.showIcon">
            <label class='col-sm-4 control-label' for="iconTextInput" localized>form.application.iconText</label>
            <div class='col-sm-8'>
                <input ng-model='application.iconText' type='text' class='form-control' id="iconTextInput"
                       localized-placeholder="form.application.iconText.placeholder"
                       maxlength="256"/>
            </div>
        </div>

        <div class='form-group' ng-if="application.showIcon">
            <label class='col-sm-4 control-label' for="iconInput" localized>form.application.icon</label>
            <div class='col-sm-5'>
                <select ng-options="icon.id as icon.name for icon in icons" name="icon"
                        ng-model='application.iconId' class='form-control' id="iconInput">
                </select>
            </div>
            <dic class="col-sm-3 align-right">
                <button class="btn btn-default" type="button" ng-click="addNewIcon()" localized>button.add.icon</button>
            </dic>
        </div>


        <div class='form-group'>
            <div class='col-sm-offset-4 col-sm-8'>
                <button type='submit' class='btn btn-default' ng-click='save()' ng-disabled="loading" localized>button.save</button>
                <button type='button' class='btn btn-default' ng-click='closeModal()' ng-disabled="loading" localized >button.cancel</button>
                <button type='button' class='btn btn-default' ng-click='manageConfigurations()' ng-disabled="loading"
                        ng-if="!isNewApp" localized>button.configurations</button>
            </div>
        </div>
    </form>
</div>
